use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.
the class ValueStreamMapServiceIntegrationTest method shouldReturnNullIfThePipelineHasNeverEverRun.
@Test
public void shouldReturnNullIfThePipelineHasNeverEverRun() {
GitMaterial git = new GitMaterial("git");
String pipeline = "NewlyCreated";
u.saveConfigWith("P1", u.m(git));
assertThat(valueStreamMapService.getValueStreamMap(pipeline, 1, username, result), is(IsNull.nullValue()));
assertThat(result.isSuccessful(), is(false));
assertThat(result.httpCode(), is(SC_NOT_FOUND));
assertThat(result.message(localizer), is("Pipeline 'NewlyCreated' with counter '1' not found."));
}
use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.
the class ValueStreamMapServiceIntegrationTest method shouldDrawPDGForCrissCrossDependencies.
// Scenario: #7192
@Test
public void shouldDrawPDGForCrissCrossDependencies() {
/*
+--------------------------------------------+
| +--------------------------------+ |
| + v v
G1 -----> P2----->P3------------------------->C5
| +---> + +--------------+ ^ ^ ^
| | | | | | |
| | | +--------------+ | | | |
| | ---)--------+ | V | | |
| | | | |---->P4--------+ | |
| | | | | | |
|--)----+ | | | +--------+ |
| | | | | +---)--+ |
| | | | | | | |
| | | | | +---+ | |
+--)----)---)---------)---------)------)----+ |
| | | | | | | |
| | | +-------->C4--+ | | |
| | | ^ | | | |
| | | | | | | |
| | | +-------------+ | | | |
+---+ | | | | | | |
| | | | | | | |
+ v +-+ | v +--->v |
G2 ----->C2------>c3------------------------>P5 |
| | ^ ^ |
| +---------------------------------+ | |
| | |
+-------+------------------------------------+ |
| |
|-----------------------------------------------+
*/
int i = 0;
GitMaterial g1 = u.wf(new GitMaterial("git-1"), "folder3");
u.checkinInOrder(g1, u.d(i++), "g1-1");
GitMaterial g2 = u.wf(new GitMaterial("git-2"), "folder4");
u.checkinInOrder(g2, u.d(i++), "g2-1");
ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWith("P2", u.m(g1), u.m(g2));
ScheduleTestUtil.AddedPipeline c2 = u.saveConfigWith("C2", u.m(g1), u.m(g2));
ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWith("P3", u.m(p2));
ScheduleTestUtil.AddedPipeline c3 = u.saveConfigWith("C3", u.m(c2));
ScheduleTestUtil.AddedPipeline c4 = u.saveConfigWith("C4", u.m(c3), u.m(p2));
ScheduleTestUtil.AddedPipeline p4 = u.saveConfigWith("P4", u.m(p3), u.m(c2));
ScheduleTestUtil.AddedPipeline c5 = u.saveConfigWith("C5", u.m(p3), u.m(p2), u.m(g1), u.m(p4), u.m(c4), u.m(g2));
ScheduleTestUtil.AddedPipeline p5 = u.saveConfigWith("P5", u.m(c3), u.m(c2), u.m(g1), u.m(p4), u.m(c4), u.m(g2));
String p2_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p2, u.d(i++), "g1-1", "g2-1");
String c2_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(c2, u.d(i++), "g1-1", "g2-1");
String p3_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p3, u.d(i++), p2_1);
String c3_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(c3, u.d(i++), c2_1);
String c4_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(c4, u.d(i++), c3_1, p2_1);
String p4_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p4, u.d(i++), p3_1, c2_1);
String c5_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(c5, u.d(i++), p3_1, p2_1, "g1-1", p4_1, c4_1, "g2-1");
String p5_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p5, u.d(i++), c3_1, c2_1, "g1-1", p4_1, c4_1, "g2-1");
// PDG for C5
ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap(pipelineName(c5), 1, username, result);
List<List<Node>> nodesAtEachLevel = graph.getNodesAtEachLevel();
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(4), 0, pipelineName(c5));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(3), 4, pipelineName(p4), pipelineName(c4));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(2), 5, pipelineName(p3), pipelineName(c3));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(1), 2, pipelineName(p2), pipelineName(c2));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(0), 0, g1.getFingerprint(), g2.getFingerprint());
VSMTestHelper.assertDepth(graph, pipelineName(c5), 1);
VSMTestHelper.assertDepth(graph, pipelineName(p4), 4);
VSMTestHelper.assertDepth(graph, pipelineName(c4), 5);
VSMTestHelper.assertDepth(graph, pipelineName(p3), 2);
VSMTestHelper.assertDepth(graph, pipelineName(c3), 6);
VSMTestHelper.assertDepth(graph, pipelineName(p2), 2);
VSMTestHelper.assertDepth(graph, pipelineName(c2), 4);
VSMTestHelper.assertDepth(graph, g1.getFingerprint(), 1);
VSMTestHelper.assertDepth(graph, g2.getFingerprint(), 2);
// PDG for C4
graph = valueStreamMapService.getValueStreamMap(pipelineName(c4), 1, username, result);
nodesAtEachLevel = valueStreamMapService.getValueStreamMap(pipelineName(c4), 1, username, result).getNodesAtEachLevel();
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(4), 0, pipelineName(c5), pipelineName(p5));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(3), 0, pipelineName(c4));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(2), 0, pipelineName(c3), pipelineName(p2));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(1), 2, pipelineName(c2));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(0), 0, g1.getFingerprint(), g2.getFingerprint());
VSMTestHelper.assertDepth(graph, pipelineName(p5), 1);
VSMTestHelper.assertDepth(graph, pipelineName(c5), 2);
VSMTestHelper.assertDepth(graph, pipelineName(c4), 1);
VSMTestHelper.assertDepth(graph, pipelineName(c3), 1);
VSMTestHelper.assertDepth(graph, pipelineName(p2), 2);
VSMTestHelper.assertDepth(graph, pipelineName(c2), 1);
VSMTestHelper.assertDepth(graph, g1.getFingerprint(), 1);
VSMTestHelper.assertDepth(graph, g2.getFingerprint(), 2);
// PDG for p3
nodesAtEachLevel = valueStreamMapService.getValueStreamMap(pipelineName(p3), 1, username, result).getNodesAtEachLevel();
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(4), 0, pipelineName(c5), pipelineName(p5));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(3), 1, pipelineName(p4));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(2), 0, pipelineName(p3));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(1), 0, pipelineName(p2));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(0), 0, g1.getFingerprint(), g2.getFingerprint());
}
use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.
the class PipelineRepositoryIntegrationTest method shouldConsider_firstRevision_forAFlyweight_asInDb_whilePickingFromMultipleDeclarations.
@Test
public void shouldConsider_firstRevision_forAFlyweight_asInDb_whilePickingFromMultipleDeclarations() {
ScheduleTestUtil u = new ScheduleTestUtil(transactionTemplate, materialRepository, dbHelper, configHelper);
int i = 1;
GitMaterial git1 = u.wf(new GitMaterial("git"), "folder1");
u.checkinInOrder(git1, "g1");
GitMaterial git2 = u.wf(new GitMaterial("git"), "folder2");
ScheduleTestUtil.AddedPipeline p = u.saveConfigWith("P", u.m(git1), u.m(git2));
CruiseConfig cruiseConfig = goConfigDao.load();
u.checkinInOrder(git1, u.d(i++), "g2");
u.runAndPass(p, "g1", "g2");
u.runAndPass(p, "g2", "g1");
PipelineTimeline timeline = new PipelineTimeline(pipelineRepository, transactionTemplate, transactionSynchronizationManager);
timeline.updateTimelineOnInit();
List<PipelineTimelineEntry> timelineEntries = new ArrayList<>(timeline.getEntriesFor("P"));
assertThat(timelineEntries.get(0).getPipelineLocator().getCounter(), is(1));
assertThat(timelineEntries.get(0).naturalOrder(), is(1.0));
List<PipelineTimelineEntry.Revision> flyweightsRevs = new ArrayList<>(timelineEntries.get(0).revisions().values()).get(0);
assertThat(flyweightsRevs.get(0).revision, is("g1"));
assertThat(flyweightsRevs.get(1).revision, is("g2"));
assertThat(timelineEntries.get(1).getPipelineLocator().getCounter(), is(2));
assertThat(timelineEntries.get(1).naturalOrder(), is(2.0));
flyweightsRevs = new ArrayList<>(timelineEntries.get(1).revisions().values()).get(0);
assertThat(flyweightsRevs.get(0).revision, is("g2"));
assertThat(flyweightsRevs.get(1).revision, is("g1"));
MaterialConfigs materials = CLONER.deepClone(p.config.materialConfigs());
Collections.reverse(materials);
configHelper.setMaterialConfigForPipeline("P", materials.toArray(new MaterialConfig[0]));
goConfigDao.load();
timeline = new PipelineTimeline(pipelineRepository, transactionTemplate, transactionSynchronizationManager);
timeline.updateTimelineOnInit();
timelineEntries = new ArrayList<>(timeline.getEntriesFor("P"));
assertThat(timelineEntries.get(0).getPipelineLocator().getCounter(), is(1));
assertThat(timelineEntries.get(0).naturalOrder(), is(1.0));
flyweightsRevs = new ArrayList<>(timelineEntries.get(0).revisions().values()).get(0);
assertThat(flyweightsRevs.get(0).revision, is("g1"));
assertThat(flyweightsRevs.get(1).revision, is("g2"));
assertThat(timelineEntries.get(1).getPipelineLocator().getCounter(), is(2));
assertThat(timelineEntries.get(1).naturalOrder(), is(2.0));
flyweightsRevs = new ArrayList<>(timelineEntries.get(1).revisions().values()).get(0);
assertThat(flyweightsRevs.get(0).revision, is("g2"));
assertThat(flyweightsRevs.get(1).revision, is("g1"));
}
use of com.thoughtworks.go.config.materials.git.GitMaterial 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.config.materials.git.GitMaterial in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method shouldAllowSavingModificationsIfRevisionsAcrossDifferentMaterialsHappenToBeSame.
@Test
public void shouldAllowSavingModificationsIfRevisionsAcrossDifferentMaterialsHappenToBeSame() {
final MaterialInstance materialInstance1 = repo.findOrCreateFrom(new GitMaterial(UUID.randomUUID().toString(), "branch"));
final MaterialInstance materialInstance2 = repo.findOrCreateFrom(new GitMaterial(UUID.randomUUID().toString(), "branch"));
final ArrayList<Modification> modificationsForFirstMaterial = getModifications(3);
transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
repo.saveModifications(materialInstance1, modificationsForFirstMaterial);
return null;
}
});
assertThat(repo.getModificationsFor(materialInstance1, Pagination.pageByNumber(1, 10, 10)).size(), is(3));
final ArrayList<Modification> modificationsForSecondMaterial = getModifications(3);
transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
repo.saveModifications(materialInstance2, modificationsForSecondMaterial);
return null;
}
});
Modifications modificationsFromDb = repo.getModificationsFor(materialInstance2, Pagination.pageByNumber(1, 10, 10));
assertThat(modificationsFromDb.size(), is(3));
for (Modification modification : modificationsForSecondMaterial) {
assertThat(modificationsFromDb.containsRevisionFor(modification), is(true));
}
}
Aggregations