use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.
the class MaterialDatabaseGitUpdaterTest method shouldRemoveFlyweightWhenConfiguredBranchDoesNotExist.
@Test
public void shouldRemoveFlyweightWhenConfiguredBranchDoesNotExist() throws Exception {
File flyweightDir = new File("pipelines", "flyweight");
FileUtils.deleteQuietly(flyweightDir);
material = new GitMaterial(testRepo.projectRepositoryUrl(), "bad-bad-branch");
try {
updater.updateMaterial(material);
fail("material update should have failed as given branch does not exist in repository");
} catch (Exception e) {
//ignore
}
MaterialInstance materialInstance = materialRepository.findMaterialInstance(material);
assertThat(materialInstance, is(nullValue()));
//no flyweight dir left behind
assertThat(FileUtil.listFiles(flyweightDir).length, is(0));
}
use of com.thoughtworks.go.domain.MaterialInstance 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.MaterialInstance 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.MaterialInstance in project gocd by gocd.
the class DownstreamInstancePopulatorIntegrationTest method shouldPopulateInstancesBuiltFromCurrentMaterial.
@Test
public void shouldPopulateInstancesBuiltFromCurrentMaterial() {
/*
g1 -> P -> P2 --> P4
| \ /
| + P3 +
+-> Q
|
+-> R
*/
GitMaterial g1 = u.wf(new GitMaterial("g1"), "folder3");
u.checkinInOrder(g1, "g_1", "g_2");
ScheduleTestUtil.AddedPipeline p = u.saveConfigWith("p", u.m(g1));
ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWith("p2", u.m(p));
ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWith("p3", u.m(p2));
ScheduleTestUtil.AddedPipeline p4 = u.saveConfigWith("p4", u.m(p2), u.m(p3));
ScheduleTestUtil.AddedPipeline q = u.saveConfigWith("q", u.m(g1));
ScheduleTestUtil.AddedPipeline r = u.saveConfigWith("r", u.m(g1));
String p_1 = u.runAndPass(p, "g_1");
String p2_1 = u.runAndPass(p2, p_1);
String p3_1 = u.runAndPass(p3, p2_1);
String p4_1 = u.runAndPass(p4, p2_1, p3_1);
String q_1 = u.runAndPass(q, "g_1");
String q_2 = u.runAndPass(q, "g_1");
MaterialInstance g1Instance = materialRepository.findMaterialInstance(g1);
Modification g1Modification = materialRepository.findModificationWithRevision(g1, "g_1");
ValueStreamMap valueStreamMap = new ValueStreamMap(g1, g1Instance, g1Modification);
Node gitNode = valueStreamMap.getCurrentMaterial();
Node nodep1 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p", "p"), gitNode.getId());
Node nodep2 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p2", "p2"), "p");
Node nodep3 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p3", "p3"), "p2");
Node nodep4 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p4", "p4"), "p3");
valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p4", "p4"), "p2");
Node nodep5 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("q", "q"), gitNode.getId());
Node nodep6 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("r", "r"), gitNode.getId());
downstreamInstancePopulator.apply(valueStreamMap);
assertInstances(nodep1, "p", 1);
assertInstances(nodep2, "p2", 1);
assertInstances(nodep3, "p3", 1);
assertInstances(nodep4, "p4", 1);
assertInstances(nodep5, "q", 1, 2);
assertThat(nodep6.revisions().size(), is(0));
}
use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.
the class TransactionCacheInterceptorTest method savedHg.
private MaterialInstance savedHg() {
MaterialInstance materialInstance = hgInstance();
hibernateDaoSupport.getHibernateTemplate().save(materialInstance);
return materialInstance;
}
Aggregations