use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.
the class PackageMaterialUpdaterIntegrationTest method shouldUpdateMaterialInstanceWhenPluginIsUpgraded.
@Test
public void shouldUpdateMaterialInstanceWhenPluginIsUpgraded() throws Exception {
final PackageMaterial material = MaterialsMother.packageMaterial();
final MaterialInstance materialInstance = material.createMaterialInstance();
materialRepository.saveOrUpdate(materialInstance);
addMetadata(material, "fieldX", false);
material.getPackageDefinition().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) {
packageMaterialUpdater.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.MaterialInstance in project gocd by gocd.
the class PluggableSCMMaterialUpdaterIntegrationTest method shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModification.
@Test
public void shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModification() throws Exception {
final PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
final MaterialInstance materialInstance = material.createMaterialInstance();
materialRepository.saveOrUpdate(materialInstance);
Map<String, String> data = new HashMap<>();
data.put("k1", "v1");
when(scmExtension.getLatestRevision(any(String.class), any(SCMPropertyConfiguration.class), any(Map.class), any(String.class))).thenReturn(new MaterialPollResult(data, 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());
return null;
}
});
MaterialInstance actualInstance = materialRepository.findMaterialInstance(material);
assertThat(actualInstance.getAdditionalDataMap(), is(data));
}
use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.
the class TestFailureSetup method setupPipelineInstnace.
private SavedStage setupPipelineInstnace(final boolean failStage, final String overriddenLabel, final List<Modification> modifications, final TestResultsStubbing test, final Date latestTransitionDate) {
return (SavedStage) transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
MaterialInstance materialInstance = materialRepository.findOrCreateFrom(hgMaterial);
for (Modification mod : modifications) {
mod.setMaterialInstance(materialInstance);
}
MaterialRevision rev = new MaterialRevision(hgMaterial, modifications);
materialRepository.saveMaterialRevision(rev);
Pipeline pipeline = PipelineMother.schedule(pipelineConfig, BuildCause.createManualForced(new MaterialRevisions(rev), new Username(new CaseInsensitiveString("loser"))));
if (overriddenLabel != null) {
pipeline.setLabel(overriddenLabel);
}
for (JobInstance instance : pipeline.getStages().get(0).getJobInstances()) {
for (JobStateTransition jobStateTransition : instance.getTransitions()) {
jobStateTransition.setStateChangeTime(latestTransitionDate);
}
}
dbHelper.save(pipeline);
Stage barStage = pipeline.getFirstStage();
if (failStage) {
dbHelper.failStage(barStage, latestTransitionDate);
}
test.stub(barStage);
pipelineTimeline.update();
return new SavedStage(pipeline);
}
});
}
use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.
the class ModificationIntegrationTest method shouldPersistAdditionalDataIntoModificationsTable.
@Test
public void shouldPersistAdditionalDataIntoModificationsTable() throws Exception {
String revision = "revision";
HashMap<String, String> additionalDataMap = new HashMap<>();
additionalDataMap.put("key", "value");
String additionalData = JsonHelper.toJsonString(additionalDataMap);
final Modification modification = new Modification("user", "comment", "foo@bar.fooadsf", new Date(), revision, additionalData);
final GitMaterial git = new GitMaterial("url", "branch");
transactionTemplate.executeWithExceptionHandling(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) throws Exception {
MaterialInstance gitInstance = materialRepository.findOrCreateFrom(git);
materialRepository.saveModification(gitInstance, modification);
return null;
}
});
Modification actual = materialRepository.findModificationWithRevision(git, revision);
/*
Checking if time are the same, because actual has SQLTime whereas we send in java.util.Date. No idea how we were testing this ever
because Modification#equals fails instance check (ShilpaG & Sachin)
*/
assertThat(actual.getModifiedTime().getTime(), is(modification.getModifiedTime().getTime()));
assertThat(actual.getAdditionalData(), is(additionalData));
assertThat(actual.getAdditionalDataMap(), is(additionalDataMap));
}
use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.
the class TfsMaterialPersistenceTest method shouldBeAbleToConvertAMaterialInstanceObjectToTfsMaterialObject.
@Test
public void shouldBeAbleToConvertAMaterialInstanceObjectToTfsMaterialObject() {
TfsMaterial tfsCfg = new TfsMaterial(new GoCipher(), new UrlArgument("url"), "loser", "CORPORATE", "password", "/dev/null");
tfsCfg.setFolder("folder");
tfsCfg.setName(new CaseInsensitiveString("materialName"));
MaterialInstance tfsInstance = materialRepository.findOrCreateFrom(tfsCfg);
Material material = tfsInstance.toOldMaterial("materialName", "folder", "password");
assertThat(material, is(tfsCfg));
}
Aggregations