use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class PipelineSqlMapDaoCachingTest method shouldNotInvalidateCacheOfPipelineInstancesTriggeredWithDependencyMaterial_WhenADifferentPipelineInstanceIsCreatedWithDifferentRevision.
@Test
public void shouldNotInvalidateCacheOfPipelineInstancesTriggeredWithDependencyMaterial_WhenADifferentPipelineInstanceIsCreatedWithDifferentRevision() throws Exception {
String cacheKey = (PipelineSqlMapDao.class + "_cacheKeyForPipelineInstancesWithDependencyMaterial_" + "p1_p_1").intern();
List<PipelineIdentifier> result = Arrays.asList(new PipelineIdentifier("p1", 1, "1"));
when(mockTemplate.queryForList(eq("pipelineInstancesTriggeredOutOfDependencyMaterial"), anyString())).thenReturn(result);
List<PipelineIdentifier> actual = pipelineDao.getPipelineInstancesTriggeredWithDependencyMaterial("p1", new PipelineIdentifier("p", 1));
assertThat(actual, Matchers.is(result));
assertThat(goCache.get(cacheKey), is(result));
MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(new DependencyMaterial(new CaseInsensitiveString("p"), new CaseInsensitiveString("s")), new Modification("u", "comment", "email", new Date(), "p/2/s/1")));
Pipeline pipeline = new Pipeline("p1", BuildCause.createWithModifications(materialRevisions, ""));
pipelineDao.save(pipeline);
assertThat(goCache.get(cacheKey), is(result));
}
use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class PipelineSqlMapDaoCachingTest method shouldNotInvalidateCacheOfPipelineInstancesTriggeredWithMaterialRevision_WhenAPipelineInstanceIsCreatedWithDifferentMaterial.
@Test
public void shouldNotInvalidateCacheOfPipelineInstancesTriggeredWithMaterialRevision_WhenAPipelineInstanceIsCreatedWithDifferentMaterial() throws Exception {
GitMaterialInstance materialInstance = new GitMaterialInstance("url", "branch", "submodule", "flyweight");
String cacheKey = pipelineDao.cacheKeyForPipelineInstancesTriggeredWithDependencyMaterial("p1", materialInstance.getFingerprint(), "r1");
List<PipelineIdentifier> result = Arrays.asList(new PipelineIdentifier("p1", 1, "1"));
when(mockTemplate.queryForList(eq("pipelineInstancesTriggeredOffOfMaterialRevision"), anyString())).thenReturn(result);
List<PipelineIdentifier> actual = pipelineDao.getPipelineInstancesTriggeredWithDependencyMaterial("p1", materialInstance, "r1");
assertThat(actual, Matchers.is(result));
assertThat(goCache.get(cacheKey), is(result));
MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(new GitMaterial("url", "branch"), new Modification("user", "comment", "email", new Date(), "r2")));
Pipeline pipeline = new Pipeline("p1", BuildCause.createWithModifications(materialRevisions, ""));
pipelineDao.save(pipeline);
assertThat(goCache.get(cacheKey), is(result));
}
use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class PipelineSqlMapDaoCachingTest method shouldInvalidateCacheOfPipelineInstancesTriggeredWithDependencyMaterial.
@Test
public void shouldInvalidateCacheOfPipelineInstancesTriggeredWithDependencyMaterial() throws Exception {
String cacheKey = (PipelineSqlMapDao.class + "_cacheKeyForPipelineInstancesWithDependencyMaterial_" + "p1_p_1").intern();
List<PipelineIdentifier> result = Arrays.asList(new PipelineIdentifier("p1", 1, "1"));
when(mockTemplate.queryForList(eq("pipelineInstancesTriggeredOutOfDependencyMaterial"), anyString())).thenReturn(new ArrayList());
List<PipelineIdentifier> actual = pipelineDao.getPipelineInstancesTriggeredWithDependencyMaterial("p1", new PipelineIdentifier("p", 1));
assertThat(actual, hasSize(0));
assertThat((List<PipelineIdentifier>) goCache.get(cacheKey), hasSize(0));
MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(new DependencyMaterial(new CaseInsensitiveString("p"), new CaseInsensitiveString("s")), new Modification("u", "comment", "email", new Date(), "p/1/s/1")));
Pipeline pipeline = new Pipeline("p1", BuildCause.createWithModifications(materialRevisions, ""));
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((TransactionSynchronizationAdapter) invocation.getArguments()[0]).afterCommit();
return null;
}
}).when(transactionSynchronizationManager).registerSynchronization(any(TransactionSynchronization.class));
when(transactionTemplate.execute(any(TransactionCallback.class))).then(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((TransactionCallback) invocation.getArguments()[0]).doInTransaction(new SimpleTransactionStatus());
return null;
}
});
pipelineDao.save(pipeline);
assertThat(goCache.get(cacheKey), is(Matchers.nullValue()));
}
use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class StageNotificationServiceTest method stubPipelineAndStage.
private void stubPipelineAndStage(Date date) {
final PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("go", "dev", "compile", "test", "twist");
final Modification svnModification = new Modification("lgao", "Fixing the not checked in files", "jez@cruise.com", date, "123");
svnModification.createModifiedFile("build.xml", "some_dir", ModifiedAction.added);
svnModification.createModifiedFile("some.xml", "other_dir", ModifiedAction.deleted);
Pipeline pipeline = instanceFactory.createPipelineInstance(pipelineConfig, new ManualBuild(new Username(new CaseInsensitiveString("loser"))).onModifications(new MaterialRevisions(new MaterialRevision(new MaterialConfigConverter().toMaterials(pipelineConfig.materialConfigs()).get(0), svnModification)), false, null), new DefaultSchedulingContext("loser"), "md5-test", new TimeProvider());
Stage stage = pipeline.getStages().get(0);
when(stageService.findStageWithIdentifier(stageIdentifier)).thenReturn(stage);
stage.setPipelineId(100L);
when(pipelineService.fullPipelineById(100)).thenReturn(pipeline);
}
use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class AutoBuildCauseTest method shouldSetApproverToCruiseForTheProducedBuildCause.
@Test
public void shouldSetApproverToCruiseForTheProducedBuildCause() throws Exception {
SvnMaterial material = new SvnMaterial("http://foo.bar/baz", "user", "pass", false);
MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(material, new Modification(new Date(), "1234", "MOCK_LABEL-12", null)));
when(goConfigService.upstreamDependencyGraphOf("foo", cruiseConfig)).thenReturn(new PipelineConfigDependencyGraph(null));
when(pipelineService.getRevisionsBasedOnDependencies(materialRevisions, cruiseConfig, new CaseInsensitiveString("foo"))).thenReturn(materialRevisions);
BuildCause buildCause = new AutoBuild(goConfigService, pipelineService, "foo", new SystemEnvironment(), materialChecker).onModifications(materialRevisions, false, null);
assertThat(buildCause.getApprover(), is(GoConstants.DEFAULT_APPROVED_BY));
}
Aggregations