Search in sources :

Example 81 with DependencyMaterial

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.

the class FaninDependencyResolutionTest method shouldResolveDiamondDependencyWithChildrenDependingOnDifferentStageDependency.

@Test
public void shouldResolveDiamondDependencyWithChildrenDependingOnDifferentStageDependency() throws Exception {
    /*
               +---> P3 ---+
               |           v
        pkg -> P2          P5
               |           ^
               +--> P4 ----+
        */
    GitMaterial git = u.wf(new GitMaterial("git"), "f");
    u.checkinInOrder(git, "g1");
    ScheduleTestUtil.AddedPipeline p2_s1 = u.saveConfigWith("p2", "s1", u.m(git));
    ScheduleTestUtil.AddedPipeline p2_s2 = u.addStageToPipeline(p2_s1.config.name(), "s2");
    ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWith("p3", u.m(new DependencyMaterial(p2_s1.config.name(), new CaseInsensitiveString("s1"))));
    ScheduleTestUtil.AddedPipeline p4 = u.saveConfigWith("p4", u.m(new DependencyMaterial(p2_s1.config.name(), new CaseInsensitiveString("s2"))));
    ScheduleTestUtil.AddedPipeline p5 = u.saveConfigWith("p5", u.m(p3), u.m(p4));
    String p2_s1_1 = u.runAndPass(p2_s1, "g1");
    String p2_s2_1 = u.runAndPass(p2_s2, "g1");
    String p3_1 = u.runAndPass(p3, p2_s1_1);
    String p4_1 = u.runAndPass(p4, p2_s2_1);
    MaterialRevisions given = u.mrs(u.mr(p3, true, p3_1), u.mr(p4, true, p4_1));
    MaterialRevisions revisionsBasedOnDependencies = getRevisionsBasedOnDependencies(p5, goConfigDao.load(), given);
    assertThat(revisionsBasedOnDependencies, is(given));
}
Also used : GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 82 with DependencyMaterial

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.

the class FaninDependencyResolutionTest method shouldComputeRevisionCorrectlyWhenUpstreamPipelineHasModifications_ForDifferentStages.

@Test
public void shouldComputeRevisionCorrectlyWhenUpstreamPipelineHasModifications_ForDifferentStages() throws Exception {
    /*
             /-->P1------\    p2(s1) --> p4
           git           P3
             \-->P2(S2)--/

        */
    GitMaterial git = u.wf(new GitMaterial("git"), "f");
    ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWith("p1", u.m(git));
    ScheduleTestUtil.AddedPipeline p2_s1 = u.saveConfigWith("p2", "s1", u.m(git));
    ScheduleTestUtil.AddedPipeline p2_s2 = u.addStageToPipeline(p2_s1.config.name(), "s2");
    ScheduleTestUtil.MaterialDeclaration p2_material = u.m(new DependencyMaterial(p2_s1.config.name(), new CaseInsensitiveString("s2")));
    ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWith("p3", p2_material, u.m(p1));
    ScheduleTestUtil.AddedPipeline p4 = u.saveConfigWith("p4", u.m(new DependencyMaterial(p2_s1.config.name(), new CaseInsensitiveString("s1"))));
    u.checkinInOrder(git, "g1");
    String p1_1 = u.runAndPass(p1, "g1");
    String p2_s2_1 = u.runAndPass(p2_s2, "g1");
    MaterialRevisions given = u.mrs(u.mr(p1, true, p1_1), u.mr(p2_s2, true, p2_s2_1));
    MaterialRevisions revisionsBasedOnDependencies = getRevisionsBasedOnDependencies(p3, goConfigDao.load(), given);
    assertThat(revisionsBasedOnDependencies, is(given));
}
Also used : GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 83 with DependencyMaterial

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.

the class MaterialDatabaseDependencyUpdaterIntegrationTest method shouldInsertAllRunsAfterLastKnownOfUpstreamStage.

@Test
public void shouldInsertAllRunsAfterLastKnownOfUpstreamStage() throws Exception {
    PipelineConfig mingleConfig = PipelineConfigMother.createPipelineConfig("acceptance", "stage-name", "job");
    goConfigService.addPipeline(mingleConfig, "pipeline-group");
    Pipeline passed1 = dbHelper.schedulePipeline(mingleConfig, new TimeProvider());
    dbHelper.passStage(passed1.getStages().get(0));
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("acceptance"), new CaseInsensitiveString("stage-name"));
    String revision1 = String.format("acceptance/%s/stage-name/1", passed1.getCounter());
    updater.updateMaterial(dependencyMaterial);
    assertThat(materialRepository.findModificationWithRevision(dependencyMaterial, revision1), is(not(nullValue())));
    Pipeline cancelledPipeline = dbHelper.schedulePipeline(mingleConfig, new TimeProvider());
    dbHelper.cancelStage(cancelledPipeline.getStages().get(0));
    Pipeline passed2 = dbHelper.schedulePipeline(mingleConfig, new TimeProvider());
    dbHelper.passStage(passed2.getStages().get(0));
    updater.updateMaterial(dependencyMaterial);
    assertThat(materialRepository.findModificationWithRevision(dependencyMaterial, String.format("acceptance/%s/stage-name/1", cancelledPipeline.getCounter())), is(nullValue()));
    Modification modification1 = materialRepository.findModificationWithRevision(dependencyMaterial, revision1);
    assertThat(modification1, is(not(nullValue())));
    assertThat(modification1.getRevision(), is(revision1));
    assertThat(modification1.getPipelineLabel(), is(passed1.getCounter().toString()));
    assertThat(modification1.getPipelineId(), is(passed1.getId()));
    String revision2 = String.format("acceptance/%s/stage-name/1", passed2.getCounter());
    Modification modification2 = materialRepository.findModificationWithRevision(dependencyMaterial, revision2);
    assertThat(modification2, is(not(nullValue())));
    assertThat(modification2.getRevision(), is(revision2));
    assertThat(modification2.getPipelineLabel(), is(passed2.getCounter().toString()));
    assertThat(modification2.getPipelineId(), is(passed2.getId()));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) TimeProvider(com.thoughtworks.go.util.TimeProvider) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 84 with DependencyMaterial

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.

the class MaterialDatabaseDependencyUpdaterTest method shouldReturnNoNewModificationsIfPipelineHasNeverBeenScheduled.

@Test
public void shouldReturnNoNewModificationsIfPipelineHasNeverBeenScheduled() throws Exception {
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
    stubStageServiceGetHistory(null);
    updater.updateMaterial(dependencyMaterial);
    MaterialRevisions materialRevisions = materialRepository.findLatestModification(dependencyMaterial);
    assertThat("materialRevisions.isEmpty()", materialRevisions.isEmpty(), is(true));
}
Also used : MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 85 with DependencyMaterial

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.

the class MaterialDatabaseDependencyUpdaterTest method stubStageServiceGetHistoryAfter.

private void stubStageServiceGetHistoryAfter(DependencyMaterial material, int pipelineCounter, Stages... stageses) {
    if (material == null) {
        material = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
    }
    StageIdentifier identifier = new StageIdentifier(String.format("%s/%s/%s/0", material.getPipelineName().toString(), pipelineCounter, material.getStageName().toString()));
    for (int i = 0; i < stageses.length; i++) {
        Stages stages = stageses[i];
        List<Modification> mods = new ArrayList<>();
        for (Stage stage : stages) {
            StageIdentifier id = stage.getIdentifier();
            mods.add(new Modification(stage.completedDate(), id.stageLocator(), id.getPipelineLabel(), stage.getPipelineId()));
        }
        Mockito.when(dependencyMaterialSourceDao.getPassedStagesAfter(identifier.stageLocator(), material, Pagination.pageStartingAt(i * MaterialDatabaseUpdater.STAGES_PER_PAGE, null, MaterialDatabaseUpdater.STAGES_PER_PAGE))).thenReturn(mods);
    }
    when(dependencyMaterialSourceDao.getPassedStagesAfter(identifier.stageLocator(), material, Pagination.pageStartingAt(MaterialDatabaseUpdater.STAGES_PER_PAGE * stageses.length, null, MaterialDatabaseUpdater.STAGES_PER_PAGE))).thenReturn(new ArrayList<>());
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) Modification(com.thoughtworks.go.domain.materials.Modification) Stages(com.thoughtworks.go.domain.Stages) ArrayList(java.util.ArrayList) Stage(com.thoughtworks.go.domain.Stage) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Aggregations

DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)97 Test (org.junit.Test)75 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)64 Modification (com.thoughtworks.go.domain.materials.Modification)30 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)29 Date (java.util.Date)22 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)19 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)17 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)16 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)15 Stage (com.thoughtworks.go.domain.Stage)14 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)13 Materials (com.thoughtworks.go.config.materials.Materials)12 Username (com.thoughtworks.go.server.domain.Username)12 Pipeline (com.thoughtworks.go.domain.Pipeline)11 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)11 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)10 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)10 P4Material (com.thoughtworks.go.config.materials.perforce.P4Material)9