use of com.thoughtworks.go.domain.materials.git.GitMaterialInstance in project gocd by gocd.
the class ValueStreamMapServiceTest method shouldPopulateErrorCorrectly_VSMForMaterial.
@Test
public void shouldPopulateErrorCorrectly_VSMForMaterial() throws Exception {
/*
git --> p1
*/
String groupName = "g1";
String pipelineName = "p1";
String userName = "looser";
GitMaterial gitMaterial = new GitMaterial("git");
MaterialConfig gitConfig = gitMaterial.config();
GitMaterialInstance gitMaterialInstance = new GitMaterialInstance("url", "branch", "submodule", "flyweight");
PipelineConfigs groups = new BasicPipelineConfigs(groupName, new Authorization(), PipelineConfigMother.pipelineConfig(pipelineName, new MaterialConfigs(gitConfig)));
CruiseConfig cruiseConfig = new BasicCruiseConfig(groups);
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
when(goConfigService.groups()).thenReturn(new PipelineGroups(groups));
when(securityService.hasViewPermissionForGroup(userName, groupName)).thenReturn(false);
// unknown material
valueStreamMapService.getValueStreamMap("unknown-material", "r1", new Username(new CaseInsensitiveString(userName)), result);
assertResult(SC_NOT_FOUND, "MATERIAL_CONFIG_WITH_FINGERPRINT_NOT_FOUND");
// unauthorized
valueStreamMapService.getValueStreamMap(gitMaterial.getFingerprint(), "r1", new Username(new CaseInsensitiveString(userName)), result);
assertResult(SC_UNAUTHORIZED, "MATERIAL_CANNOT_VIEW");
// material config exists but no material instance
when(securityService.hasViewPermissionForGroup(userName, groupName)).thenReturn(true);
when(materialRepository.findMaterialInstance(gitConfig)).thenReturn(null);
valueStreamMapService.getValueStreamMap(gitMaterial.getFingerprint(), "r1", new Username(new CaseInsensitiveString(userName)), result);
assertResult(SC_NOT_FOUND, "MATERIAL_INSTANCE_WITH_FINGERPRINT_NOT_FOUND");
// modification (revision) doesn't exist
when(materialRepository.findMaterialInstance(gitConfig)).thenReturn(gitMaterialInstance);
when(materialRepository.findModificationWithRevision(gitMaterial, "r1")).thenReturn(null);
valueStreamMapService.getValueStreamMap(gitMaterial.getFingerprint(), "r1", new Username(new CaseInsensitiveString(userName)), result);
assertResult(SC_NOT_FOUND, "MATERIAL_MODIFICATION_NOT_FOUND");
// internal error
when(goConfigService.groups()).thenThrow(new RuntimeException("just for fun"));
valueStreamMapService.getValueStreamMap(gitMaterial.getFingerprint(), "r1", new Username(new CaseInsensitiveString(userName)), result);
assertResult(SC_INTERNAL_SERVER_ERROR, "VSM_INTERNAL_SERVER_ERROR_FOR_MATERIAL");
}
use of com.thoughtworks.go.domain.materials.git.GitMaterialInstance 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.git.GitMaterialInstance in project gocd by gocd.
the class PipelineSqlMapDaoCachingTest method shouldCacheEmptyPipelineInstancesTriggeredOutOfMaterialRevision.
@Test
public void shouldCacheEmptyPipelineInstancesTriggeredOutOfMaterialRevision() throws Exception {
GitMaterialInstance materialInstance = new GitMaterialInstance("url", "branch", "submodule", "flyweight");
String cacheKey = pipelineDao.cacheKeyForPipelineInstancesTriggeredWithDependencyMaterial("p1", materialInstance.getFingerprint(), "r1");
when(mockTemplate.queryForList(eq("pipelineInstancesTriggeredOffOfMaterialRevision"), anyString())).thenReturn(new ArrayList());
List<PipelineIdentifier> actual = pipelineDao.getPipelineInstancesTriggeredWithDependencyMaterial("p1", materialInstance, "r1");
assertThat(actual, hasSize(0));
assertThat(goCache.get(cacheKey), is(actual));
}
use of com.thoughtworks.go.domain.materials.git.GitMaterialInstance in project gocd by gocd.
the class PipelineSqlMapDaoCachingTest method shouldInvalidateCacheOfPipelineInstancesTriggeredWithMaterialRevision.
@Test
public void shouldInvalidateCacheOfPipelineInstancesTriggeredWithMaterialRevision() 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, hasSize(1));
assertThat((List<PipelineIdentifier>) goCache.get(cacheKey), hasSize(1));
MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(new GitMaterial("url", "branch"), new Modification("user", "comment", "email", new Date(), "r1")));
Pipeline pipeline = new Pipeline("p1", BuildCause.createWithModifications(materialRevisions, ""));
pipelineDao.save(pipeline);
assertThat(goCache.get(cacheKey), is(Matchers.nullValue()));
}
use of com.thoughtworks.go.domain.materials.git.GitMaterialInstance in project gocd by gocd.
the class PipelineSqlMapDaoCachingTest method shouldCachePipelineInstancesTriggeredOutOfMaterialRevision.
@Test
public void shouldCachePipelineInstancesTriggeredOutOfMaterialRevision() throws Exception {
GitMaterialInstance materialInstance = new GitMaterialInstance("url", "branch", "submodule", "flyweight");
List<PipelineIdentifier> results = Arrays.asList(new PipelineIdentifier("p1", 1));
String cacheKey = pipelineDao.cacheKeyForPipelineInstancesTriggeredWithDependencyMaterial("p1", materialInstance.getFingerprint(), "r1");
when(mockTemplate.queryForList(eq("pipelineInstancesTriggeredOffOfMaterialRevision"), anyString())).thenReturn(results);
assertThat(goCache.get(cacheKey), is(Matchers.nullValue()));
List<PipelineIdentifier> actual = pipelineDao.getPipelineInstancesTriggeredWithDependencyMaterial("p1", materialInstance, "r1");
//Query second time should return from cache
pipelineDao.getPipelineInstancesTriggeredWithDependencyMaterial("p1".toUpperCase(), materialInstance, "r1");
assertThat(goCache.get(cacheKey), is(actual));
verify(mockTemplate, times(1)).queryForList(eq("pipelineInstancesTriggeredOffOfMaterialRevision"), anyString());
}
Aggregations