use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class MaterialDatabaseDependencyUpdaterTest method shouldReturnLatestPipelineIfThereHasBeenANewOne.
@Test
public void shouldReturnLatestPipelineIfThereHasBeenANewOne() 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();
stubStageServiceGetHistoryAfter(null, 9, stages(10));
updater.updateMaterial(dependencyMaterial);
List<Modification> newModifications = materialRepository.findModificationsSince(dependencyMaterial, new MaterialRevision(dependencyMaterial, modification));
assertThat(newModifications.size(), is(1));
assertThat(newModifications.get(0).getRevision(), is("pipeline-name/10/stage-name/0"));
assertThat(newModifications.get(0).getPipelineLabel(), is("LABEL-10"));
}
use of com.thoughtworks.go.domain.materials.Modification 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.domain.materials.Modification in project gocd by gocd.
the class PluggableSCMMaterialUpdaterIntegrationTest method shouldUpdateMaterialInstanceWhenPluginIsUpgraded.
@Test
public void shouldUpdateMaterialInstanceWhenPluginIsUpgraded() throws Exception {
final PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
final MaterialInstance materialInstance = material.createMaterialInstance();
materialRepository.saveOrUpdate(materialInstance);
addMetadata(material, "fieldX", false);
material.getScmConfig().getConfiguration().addNewConfiguration("fieldX", true);
final List<Modification> modifications = ModificationsMother.multipleModificationList();
doNothing().when(scmMaterialUpdater).insertLatestOrNewModifications(material, materialInstance, new File(""), new Modifications(modifications));
transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus transactionStatus) {
pluggableSCMMaterialUpdater.insertLatestOrNewModifications(material, materialInstance, new File(""), new Modifications(modifications));
return null;
}
});
MaterialInstance actualInstance = materialRepository.findMaterialInstance(material);
assertThat(actualInstance.getConfiguration(), is(material.createMaterialInstance().getConfiguration()));
}
use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class PluggableSCMMaterialUpdaterIntegrationTest method shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModificationsSince.
@Test
public void shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModificationsSince() throws Exception {
final PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
final MaterialInstance materialInstance = material.createMaterialInstance();
Map<String, String> oldData = new HashMap<>();
oldData.put("k1", "v1");
materialInstance.setAdditionalData(new GsonBuilder().create().toJson(oldData));
materialRepository.saveOrUpdate(materialInstance);
Map<String, String> newData = new HashMap<>(oldData);
newData.put("k2", "v2");
when(scmExtension.latestModificationSince(any(String.class), any(SCMPropertyConfiguration.class), any(Map.class), any(String.class), any(SCMRevision.class))).thenReturn(new MaterialPollResult(newData, new SCMRevision()));
mockSCMExtensionInPoller();
scmMaterialUpdater = new ScmMaterialUpdater(materialRepository, materialChecker, subprocessExecutionContext, materialService);
pluggableSCMMaterialUpdater = new PluggableSCMMaterialUpdater(materialRepository, scmMaterialUpdater, transactionTemplate);
transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus transactionStatus) {
pluggableSCMMaterialUpdater.insertLatestOrNewModifications(material, materialInstance, new File(""), new Modifications(new Modification()));
return null;
}
});
MaterialInstance actualInstance = materialRepository.findMaterialInstance(material);
assertThat(actualInstance.getAdditionalDataMap(), is(newData));
}
use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class TestBaseForDatabaseUpdater method shouldUpdateWithChanges.
@Test
public void shouldUpdateWithChanges() throws Exception {
List<Modification> modifications = testRepo.checkInOneFile("test.txt", "This is a new checkin");
updater.updateMaterial(material);
Modification modification = materialRepository.findLatestModification(material).getMaterialRevision(0).getModification(0);
assertEquals(modifications.get(0), modification);
}
Aggregations