Search in sources :

Example 81 with BuildCause

use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.

the class ManualBuildTest method shouldPopulateProducedBuildCauseApproverForOnModificationBuildCause.

@Test
public void shouldPopulateProducedBuildCauseApproverForOnModificationBuildCause() throws Exception {
    BuildCause buildCause = manualBuild.onModifications(materialRevisions, false, null);
    assertThat(buildCause.getApprover(), is("cruise-user"));
}
Also used : BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 82 with BuildCause

use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.

the class AutoBuildCauseTest method shouldUpdateRecomputedMaterialRevisionsChangedStatus.

@Test
public void shouldUpdateRecomputedMaterialRevisionsChangedStatus() throws Exception {
    PipelineConfigDependencyGraph dependencyGraph = dependencyGraphOfDepthOne(MaterialConfigsMother.hgMaterialConfig(), MaterialConfigsMother.svnMaterialConfig());
    String targetPipeline = dependencyGraph.getCurrent().name().toLower();
    MaterialRevisions revisions = createHgMaterialWithMultipleRevisions(1, oneModifiedFile("2"), oneModifiedFile("1"));
    MaterialRevisions revisionsForMaterial2 = multipleRevisions(MaterialsMother.svnMaterial(), 10, oneModifiedFile("svn2"));
    MaterialRevision dependencyRevision = dependencyMaterialRevision("upstream", 1, "label", "first", 1, new Date());
    revisions.addRevision(dependencyRevision);
    revisions.addAll(revisionsForMaterial2);
    for (MaterialRevision revision : revisions) {
        revision.markAsChanged();
    }
    MaterialRevisions expectedRevisions = createHgMaterialWithMultipleRevisions(1, oneModifiedFile("1"));
    expectedRevisions.getMaterialRevision(0).markAsChanged();
    MaterialRevisions expectedForMaterial2 = multipleRevisions(MaterialsMother.svnMaterial(), 10, oneModifiedFile("svn1"));
    expectedForMaterial2.getMaterialRevision(0).markAsNotChanged();
    expectedRevisions.addRevision(dependencyRevision);
    expectedRevisions.addAll(expectedForMaterial2);
    when(goConfigService.upstreamDependencyGraphOf(targetPipeline, cruiseConfig)).thenReturn(dependencyGraph);
    when(pipelineService.getRevisionsBasedOnDependencies(eq(revisions), eq(cruiseConfig), eq(dependencyGraph.getCurrent().name()))).thenReturn(expectedRevisions);
    BuildCause buildCause = new AutoBuild(goConfigService, pipelineService, targetPipeline, new SystemEnvironment(), materialChecker).onModifications(revisions, false, null);
    MaterialRevisions finalRevisions = buildCause.getMaterialRevisions();
    assertThat(finalRevisions.numberOfRevisions(), is(expectedRevisions.numberOfRevisions()));
    for (int i = 0; i < expectedRevisions.numberOfRevisions(); i++) {
        MaterialRevision finalRev = finalRevisions.getMaterialRevision(i);
        MaterialRevision expectedRev = expectedRevisions.getMaterialRevision(i);
        assertThat(finalRev, is(expectedRev));
        assertThat(finalRev.isChanged(), is(expectedRev.isChanged()));
    }
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Date(java.util.Date) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 83 with BuildCause

use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.

the class AutoBuildCauseTest method shouldReturnNullIfUpstreamMaterialHasChangedButNoFirstOrderMaterialHas_WithFaninOff.

@Test
public void shouldReturnNullIfUpstreamMaterialHasChangedButNoFirstOrderMaterialHas_WithFaninOff() throws Exception {
    HgMaterialConfig hg = MaterialConfigsMother.hgMaterialConfig();
    PipelineConfig third = PipelineConfigMother.pipelineConfig("third", MaterialConfigsMother.dependencyMaterialConfig("second", "mingle"), new JobConfigs());
    PipelineConfig second = PipelineConfigMother.pipelineConfig("second", MaterialConfigsMother.dependencyMaterialConfig("first", "mingle"), new JobConfigs());
    PipelineConfig first = PipelineConfigMother.pipelineConfig("first", hg, new JobConfigs());
    PipelineConfigDependencyGraph dependencyGraph = new PipelineConfigDependencyGraph(third, new PipelineConfigDependencyGraph(second, new PipelineConfigDependencyGraph(first)), new PipelineConfigDependencyGraph(first));
    MaterialRevisions revisions = new MaterialRevisions();
    MaterialRevision firstRev = dependencyMaterialRevision("first", 1, "label", "mingle", 1, new Date());
    firstRev.markAsChanged();
    MaterialRevision secondRev = dependencyMaterialRevision("second", 1, "label", "mingle", 1, new Date());
    secondRev.markAsNotChanged();
    revisions.addRevision(secondRev);
    revisions.addRevision(firstRev);
    when(goConfigService.upstreamDependencyGraphOf("third", cruiseConfig)).thenReturn(dependencyGraph);
    when(systemEnvironment.enforceRevisionCompatibilityWithUpstream()).thenReturn(false);
    AutoBuild build = new AutoBuild(goConfigService, pipelineService, "third", systemEnvironment, materialChecker);
    BuildCause cause = build.onModifications(revisions, false, null);
    assertThat(cause, is(nullValue()));
}
Also used : PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Date(java.util.Date) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 84 with BuildCause

use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.

the class AutoBuildTriangleDependencyTest method should_useTriangleDependencyResolution_whenFainInIsOptedOut.

@Test
public void should_useTriangleDependencyResolution_whenFainInIsOptedOut() throws Exception {
    SystemEnvironment systemEnvironment = mock(SystemEnvironment.class);
    when(systemEnvironment.enforceRevisionCompatibilityWithUpstream()).thenReturn(false);
    String pipelineName = "downstream";
    PipelineConfigDependencyGraph dependencyGraph = mock(PipelineConfigDependencyGraph.class);
    MaterialRevisions originalRevisions = mock(MaterialRevisions.class);
    MaterialRevisions recomputedRevisions = mock(MaterialRevisions.class);
    when(originalRevisions.isEmpty()).thenReturn(false);
    when(originalRevisions.hasDependencyMaterials()).thenReturn(true);
    when(goConfigService.upstreamDependencyGraphOf(pipelineName, cruiseConfig)).thenReturn(dependencyGraph);
    when(pipelineService.getRevisionsBasedOnDependencies(dependencyGraph, originalRevisions)).thenReturn(recomputedRevisions);
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline"), new CaseInsensitiveString("stage"));
    when(dependencyGraph.unsharedMaterialConfigs()).thenReturn(new MaterialConfigs(dependencyMaterial.config()));
    when(originalRevisions.findRevisionFor(dependencyMaterial)).thenReturn(new MaterialRevision(dependencyMaterial, new Modification()));
    AutoBuild autoBuild = new AutoBuild(goConfigService, pipelineService, pipelineName, systemEnvironment, materialChecker);
    AutoBuild spyAutoBuild = spy(autoBuild);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return true;
        }
    }).when(spyAutoBuild).hasAnyUnsharedMaterialChanged(dependencyGraph, originalRevisions);
    BuildCause buildCause = spyAutoBuild.onModifications(originalRevisions, false, null);
    verify(pipelineService).getRevisionsBasedOnDependencies(dependencyGraph, originalRevisions);
    verify(pipelineService, never()).getRevisionsBasedOnDependencies(any(MaterialRevisions.class), any(BasicCruiseConfig.class), any(CaseInsensitiveString.class));
    assertThat(buildCause.getMaterialRevisions(), is(recomputedRevisions));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Modification(com.thoughtworks.go.domain.materials.Modification) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Test(org.junit.Test)

Example 85 with BuildCause

use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.

the class PipelineSqlMapDaoCachingTest method buildCauseForPipelineIdentifiedByNameAndCounter_shouldUseCacheAndBeCaseInsensitive.

@Test
public void buildCauseForPipelineIdentifiedByNameAndCounter_shouldUseCacheAndBeCaseInsensitive() throws Exception {
    Pipeline expected = PipelineMother.pipeline("pipeline");
    expected.setId(3);
    MaterialRevisions originalMaterialRevisions = ModificationsMother.createHgMaterialRevisions();
    when(repository.findMaterialRevisionsForPipeline(3)).thenReturn(originalMaterialRevisions);
    when(mockTemplate.queryForObject("findPipelineByNameAndCounter", m("name", "pipeline", "counter", 15))).thenReturn(expected);
    BuildCause buildCause = pipelineDao.findBuildCauseOfPipelineByNameAndCounter("pipeline", 15);
    verify(mockTemplate).queryForObject("findPipelineByNameAndCounter", m("name", "pipeline", "counter", 15));
    verify(repository).findMaterialRevisionsForPipeline(3);
    assertThat(buildCause.getMaterialRevisions(), is(originalMaterialRevisions));
    buildCause = pipelineDao.findBuildCauseOfPipelineByNameAndCounter("pipeline".toUpperCase(), 15);
    assertThat(buildCause.getMaterialRevisions(), is(originalMaterialRevisions));
    verifyNoMoreInteractions(mockTemplate, repository);
}
Also used : BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Aggregations

BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)158 Test (org.junit.Test)115 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)33 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)32 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)31 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)31 TimeProvider (com.thoughtworks.go.util.TimeProvider)28 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)21 Modification (com.thoughtworks.go.domain.materials.Modification)21 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)16 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)16 ValueStreamMapPresentationModel (com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel)16 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)14 Date (java.util.Date)14 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)13 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)12 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)11 Username (com.thoughtworks.go.server.domain.Username)10 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)10 Builder (com.thoughtworks.go.domain.builder.Builder)9