Search in sources :

Example 6 with SvnMaterial

use of com.thoughtworks.go.config.materials.svn.SvnMaterial in project gocd by gocd.

the class BuildCauseProducerServiceTest method shouldHandleNoModificationExceptionThrownByAutoBuild.

@Test
public void shouldHandleNoModificationExceptionThrownByAutoBuild() {
    String pipelineName = "pipeline";
    ServerHealthStateOperationResult result = new ServerHealthStateOperationResult();
    PipelineConfig config = PipelineConfigMother.pipelineConfig(pipelineName);
    Material svnMaterial = MaterialsMother.defaultMaterials().get(0);
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("up"), new CaseInsensitiveString("s1"));
    config.materialConfigs().clear();
    config.addMaterialConfig(svnMaterial.config());
    config.addMaterialConfig(dependencyMaterial.config());
    when(pipelineService.getRevisionsBasedOnDependencies(Matchers.<MaterialRevisions>any(), Matchers.<BasicCruiseConfig>any(), Matchers.<CaseInsensitiveString>any())).thenThrow(new NoModificationsPresentForDependentMaterialException("P/1/S/1"));
    when(pipelineScheduleQueue.mostRecentScheduled(pipelineName)).thenReturn(BuildCause.createNeverRun());
    Modification modification = ModificationsMother.checkinWithComment("r", "c", new Date(), "f1");
    when(materialRepository.findLatestModification(svnMaterial)).thenReturn(ModificationsMother.createSvnMaterialWithMultipleRevisions(1, modification));
    when(materialRepository.findLatestModification(dependencyMaterial)).thenReturn(new MaterialRevisions(ModificationsMother.changedDependencyMaterialRevision("up", 1, "1", "s", 1, new Date())));
    when(specificMaterialRevisionFactory.create(Matchers.<String>any(), Matchers.<Map<String, String>>any())).thenReturn(MaterialRevisions.EMPTY);
    when(goConfigService.upstreamDependencyGraphOf(Matchers.<String>any(), Matchers.<BasicCruiseConfig>any())).thenReturn(new PipelineConfigDependencyGraph(config));
    MaterialConfigs knownMaterialConfigs = new MaterialConfigs(svnMaterial.config(), dependencyMaterial.config());
    Materials materials = new Materials(svnMaterial, dependencyMaterial);
    when(materialConfigConverter.toMaterials(config.materialConfigs())).thenReturn(materials);
    when(materialExpansionService.expandMaterialConfigsForScheduling(config.materialConfigs())).thenReturn(knownMaterialConfigs);
    when(materialConfigConverter.toMaterials(knownMaterialConfigs)).thenReturn(materials);
    AutoBuild autoBuild = new AutoBuild(goConfigService, pipelineService, pipelineName, new SystemEnvironment(), null, mockServerHealthService);
    ServerHealthState serverHealthState = buildCauseProducerService.newProduceBuildCause(config, autoBuild, result, 12345);
    assertThat(serverHealthState.isSuccess(), is(true));
}
Also used : AutoBuild(com.thoughtworks.go.server.service.AutoBuild) Modification(com.thoughtworks.go.domain.materials.Modification) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) NoModificationsPresentForDependentMaterialException(com.thoughtworks.go.server.service.NoModificationsPresentForDependentMaterialException) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) Test(org.junit.Test)

Example 7 with SvnMaterial

use of com.thoughtworks.go.config.materials.svn.SvnMaterial in project gocd by gocd.

the class BuildCauseProducerServiceTest method shouldScheduleAfterAllMaterialsAreUpdated.

@Test
public void shouldScheduleAfterAllMaterialsAreUpdated() throws Exception {
    HgMaterial hgMaterial = new HgMaterial("url", null);
    HgMaterialConfig hgMaterialConfig = new HgMaterialConfig("url", null);
    SvnMaterial svnMaterial = new SvnMaterial("url", null, null, false);
    SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig("url", null, null, false);
    pipelineConfig.addMaterialConfig(hgMaterialConfig);
    pipelineConfig.addMaterialConfig(svnMaterialConfig);
    GoConfigService service = mock(GoConfigService.class);
    when(service.pipelineConfigNamed(pipelineConfig.name())).thenReturn(pipelineConfig);
    when(materialConfigConverter.toMaterial(hgMaterialConfig)).thenReturn(hgMaterial);
    when(materialConfigConverter.toMaterial(svnMaterialConfig)).thenReturn(svnMaterial);
    MaterialUpdateStatusNotifier notifier = new MaterialUpdateStatusNotifier(mock(MaterialUpdateCompletedTopic.class));
    buildCauseProducerService = spy(createBuildCauseProducerService(notifier));
    buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(), new ServerHealthStateOperationResult());
    final HashMap<String, String> stringStringHashMap = new HashMap<>();
    doReturn(ServerHealthState.success(healthStateType)).when(buildCauseProducerService).newProduceBuildCause(eq(pipelineConfig), any(ManualBuild.class), new ScheduleOptions(eq(EMPTY_REVISIONS), stringStringHashMap, new HashMap<>()), any(ServerHealthStateOperationResult.class), eq(12345L));
    assertThat(notifier.hasListenerFor(pipelineConfig), is(true));
    notifier.onMessage(new MaterialUpdateSuccessfulMessage(hgMaterial, 1111L));
    assertThat(notifier.hasListenerFor(pipelineConfig), is(true));
    notifier.onMessage(new MaterialUpdateSuccessfulMessage(svnMaterial, 2222L));
    assertThat(notifier.hasListenerFor(pipelineConfig), is(false));
    verify(buildCauseProducerService).newProduceBuildCause(eq(pipelineConfig), any(ManualBuild.class), eq(new ScheduleOptions()), any(ServerHealthStateOperationResult.class), eq(2222L));
}
Also used : HashMap(java.util.HashMap) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) ManualBuild(com.thoughtworks.go.server.service.ManualBuild) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) MaterialUpdateStatusNotifier(com.thoughtworks.go.server.materials.MaterialUpdateStatusNotifier) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) MaterialUpdateCompletedTopic(com.thoughtworks.go.server.materials.MaterialUpdateCompletedTopic) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) MaterialUpdateSuccessfulMessage(com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage) Test(org.junit.Test)

Example 8 with SvnMaterial

use of com.thoughtworks.go.config.materials.svn.SvnMaterial in project gocd by gocd.

the class EnvironmentVariableContextTest method shouldPopulateEnvironmentForMaterialUsingDest.

@Test
public void shouldPopulateEnvironmentForMaterialUsingDest() {
    SvnMaterial svn = MaterialsMother.svnMaterial();
    svn.setFolder("svn-dir");
    MaterialRevision revision = new MaterialRevision(svn, ModificationsMother.oneModifiedFile("revision1"));
    MaterialRevisions materialRevisions = new MaterialRevisions(revision);
    EnvironmentVariableContext context = new EnvironmentVariableContext();
    context.setProperty("GO_SERVER_URL", SystemEnvironment.getProperty("serviceUrl"), false);
    jobIdentifier().populateEnvironmentVariables(context);
    materialRevisions.populateEnvironmentVariables(context, WORKING_DIR);
    assertThat(context.getProperty("GO_REVISION_SVN_DIR"), is("revision1"));
}
Also used : MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 9 with SvnMaterial

use of com.thoughtworks.go.config.materials.svn.SvnMaterial in project gocd by gocd.

the class SvnExternalTest method shouldGetLatestRevision.

@Test
public void shouldGetLatestRevision() {
    SvnMaterial svn = svnMaterial(svnRepo.projectRepositoryUrl(), null);
    SvnMaterial svnExt = svnMaterial(svnRepo.externalRepositoryUrl(), "end2end");
    final Materials materials = new Materials(svn, svnExt);
    final MaterialRevisions materialRevisions = materials.latestModification(svnRepo.workingFolder(), new TestSubprocessExecutionContext());
    assertThat(materialRevisions.numberOfRevisions(), is(2));
    MaterialRevision main = materialRevisions.getRevisions().get(0);
    assertThat(main.getMaterial(), is(svn));
    assertThat(main.getModifications().size(), is(1));
    assertThat(main.getRevision().getRevision(), is("5"));
    MaterialRevision external = materialRevisions.getRevisions().get(1);
    assertThat(external.getMaterial(), is(svnExt));
    assertThat(external.getRevision().getRevision(), is("4"));
    assertThat(external.getModifications().size(), is(1));
}
Also used : MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) TestSubprocessExecutionContext(com.thoughtworks.go.domain.materials.TestSubprocessExecutionContext) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) Materials(com.thoughtworks.go.config.materials.Materials) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Test(org.junit.Test)

Example 10 with SvnMaterial

use of com.thoughtworks.go.config.materials.svn.SvnMaterial in project gocd by gocd.

the class SvnExternalTest method shouldGetLatestRevisionFromExpandedSvnExternalRepository.

@Test
public void shouldGetLatestRevisionFromExpandedSvnExternalRepository() {
    MaterialRevisions materialRevisions = new MaterialRevisions();
    Material svnExt = svnMaterial(svnRepo.externalRepositoryUrl(), "end2end");
    List<Modification> modifications = ((SvnMaterial) svnExt).latestModification(svnRepo.workingFolder(), new TestSubprocessExecutionContext());
    materialRevisions.addRevision(svnExt, modifications);
    assertThat(materialRevisions.numberOfRevisions(), is(1));
    MaterialRevision materialRevision = materialRevisions.getRevisions().get(0);
    assertThat(materialRevision.getMaterial(), is(svnExt));
    assertThat(materialRevision.getRevision().getRevision(), is("4"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) TestSubprocessExecutionContext(com.thoughtworks.go.domain.materials.TestSubprocessExecutionContext) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) Material(com.thoughtworks.go.domain.materials.Material) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) MaterialsMother.svnMaterial(com.thoughtworks.go.helper.MaterialsMother.svnMaterial) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Test(org.junit.Test)

Aggregations

SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)136 Test (org.junit.Test)113 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)44 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)37 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)21 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)20 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)19 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)19 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)18 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)17 Material (com.thoughtworks.go.domain.materials.Material)16 Modification (com.thoughtworks.go.domain.materials.Modification)16 Date (java.util.Date)14 Materials (com.thoughtworks.go.config.materials.Materials)13 Username (com.thoughtworks.go.server.domain.Username)9 File (java.io.File)9 P4Material (com.thoughtworks.go.config.materials.perforce.P4Material)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)7 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)7