use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class MaterialDatabaseDependencyUpdaterTest method shouldInsertAllHistoricRunsOfUpstreamStageTheFirstTime.
@Test
public void shouldInsertAllHistoricRunsOfUpstreamStageTheFirstTime() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
stubStageServiceGetHistory(null, stages(9, 10, 11), stages(12, 13));
updater.updateMaterial(dependencyMaterial);
for (Integer revision : new int[] { 9, 10, 11, 12, 13 }) {
String stageLocator = String.format("pipeline-name/%s/stage-name/0", revision);
Modification modification = materialRepository.findModificationWithRevision(dependencyMaterial, stageLocator);
assertThat(modification.getRevision(), is(stageLocator));
assertThat(modification.getPipelineLabel(), is(String.format("LABEL-%s", revision)));
}
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class MaterialDatabaseDependencyUpdaterTest method shouldUpdateMaterialCorrectlyIfCaseOfPipelineNameIsDifferentInConfigurationOfDependencyMaterial.
@Test
public void shouldUpdateMaterialCorrectlyIfCaseOfPipelineNameIsDifferentInConfigurationOfDependencyMaterial() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("PIPEline-name"), new CaseInsensitiveString("STAge-name"));
stubStageServiceGetHistory(dependencyMaterial, stages(1));
// create the material instance
updater.updateMaterial(dependencyMaterial);
stubStageServiceGetHistoryAfter(dependencyMaterial, 1, stages(2));
// update first time & should mark cache as updated
updater.updateMaterial(dependencyMaterial);
Stage stage = stage(3);
ReflectionUtil.setField(stage, "result", StageResult.Passed);
// update subsequently should hit database
updater.updateMaterial(dependencyMaterial);
Mockito.verify(dependencyMaterialSourceDao, times(2)).getPassedStagesAfter(any(String.class), any(DependencyMaterial.class), any(Pagination.class));
Mockito.verify(dependencyMaterialSourceDao, times(2)).getPassedStagesByName(any(DependencyMaterial.class), any(Pagination.class));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class MaterialDatabaseDependencyUpdaterTest method shouldCreateEntriesForCompletedPipelines.
@Test
public void shouldCreateEntriesForCompletedPipelines() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
stubStageServiceGetHistory(null, stages(9));
updater.updateMaterial(dependencyMaterial);
List<Modification> modification = materialRepository.findLatestModification(dependencyMaterial).getMaterialRevision(0).getModifications();
assertThat(modification.size(), is(1));
assertThat(modification.get(0).getRevision(), is("pipeline-name/9/stage-name/0"));
assertThat(modification.get(0).getPipelineLabel(), is("LABEL-9"));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class MaterialDatabaseDependencyUpdaterTest method shouldUpdateServerHealthIfCheckFails.
@Test
public void shouldUpdateServerHealthIfCheckFails() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
RuntimeException runtimeException = new RuntimeException("Description of error");
Mockito.when(dependencyMaterialSourceDao.getPassedStagesByName(new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name")), Pagination.pageStartingAt(0, null, MaterialDatabaseUpdater.STAGES_PER_PAGE))).thenThrow(runtimeException);
try {
updater.updateMaterial(dependencyMaterial);
fail("should have thrown exception " + runtimeException.getMessage());
} catch (Exception e) {
assertSame(e, runtimeException);
}
HealthStateType scope = HealthStateType.general(HealthStateScope.forMaterial(dependencyMaterial));
ServerHealthState state = ServerHealthState.error("Modification check failed for material: pipeline-name", "Description of error", scope);
Mockito.verify(healthService).update(state);
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class MaterialDatabaseDependencyUpdaterTest method shouldClearServerHealthIfCheckSucceeds.
@Test
public void shouldClearServerHealthIfCheckSucceeds() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
Mockito.when(dependencyMaterialSourceDao.getPassedStagesByName(new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name")), Pagination.pageStartingAt(0, null, MaterialDatabaseUpdater.STAGES_PER_PAGE))).thenReturn(new ArrayList<>());
updater.updateMaterial(dependencyMaterial);
Mockito.verify(healthService).removeByScope(HealthStateScope.forMaterial(dependencyMaterial));
}
Aggregations