Search in sources :

Example 76 with SvnMaterial

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

the class SvnPostCommitHookImplementerTest method shouldReturnEmptyListWhenUUIDIsNotPresent.

@Test
public void shouldReturnEmptyListWhenUUIDIsNotPresent() {
    final SvnMaterial svnMaterial1 = mock(SvnMaterial.class);
    final HashSet<Material> allMaterials = new HashSet<>();
    allMaterials.add(svnMaterial1);
    final SvnPostCommitHookImplementer spy = spy(implementer);
    final Set<Material> prunedList = spy.prune(allMaterials, new HashMap());
    assertThat(prunedList.size(), is(0));
    verify(spy, never()).isQualified(anyString(), any(SvnMaterial.class), any(HashMap.class));
}
Also used : HashMap(java.util.HashMap) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) Material(com.thoughtworks.go.domain.materials.Material) P4Material(com.thoughtworks.go.config.materials.perforce.P4Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) TfsMaterial(com.thoughtworks.go.config.materials.tfs.TfsMaterial) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 77 with SvnMaterial

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

the class SvnPostCommitHookImplementerTest method shouldCreateRemoteUrlToRemoteUUIDMap.

@Test
public void shouldCreateRemoteUrlToRemoteUUIDMap() {
    final SvnPostCommitHookImplementer spy = spy(implementer);
    final SvnCommand svnCommand = mock(SvnCommand.class);
    final Material svnMaterial1 = mock(SvnMaterial.class);
    final Material hgMaterial1 = mock(HgMaterial.class);
    final HashSet<Material> allMaterials = new HashSet<>(Arrays.asList(svnMaterial1, hgMaterial1));
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return svnCommand;
        }
    }).when(spy).getEmptySvnCommand();
    spy.createUrlToRemoteUUIDMap(allMaterials);
    verify(svnCommand).createUrlToRemoteUUIDMap(new HashSet<>(Arrays.asList((SvnMaterial) svnMaterial1)));
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SvnCommand(com.thoughtworks.go.domain.materials.svn.SvnCommand) Material(com.thoughtworks.go.domain.materials.Material) P4Material(com.thoughtworks.go.config.materials.perforce.P4Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) TfsMaterial(com.thoughtworks.go.config.materials.tfs.TfsMaterial) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 78 with SvnMaterial

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

the class SvnPostCommitHookImplementerTest method shouldPruneListToGiveOutOnlySvnMaterialsWhichMatchTheRepositoryUUID.

@Test
public void shouldPruneListToGiveOutOnlySvnMaterialsWhichMatchTheRepositoryUUID() {
    final SvnMaterial svnMaterial1 = mock(SvnMaterial.class);
    final SvnMaterial svnMaterial2 = mock(SvnMaterial.class);
    final SvnMaterial svnMaterial3 = mock(SvnMaterial.class);
    final HashSet<Material> allMaterials = new HashSet<>(Arrays.asList(svnMaterial1, svnMaterial2, svnMaterial3));
    final HashMap<Object, Object> params = new HashMap<>();
    final String uuid = "12345";
    params.put(SvnPostCommitHookImplementer.UUID, uuid);
    final SvnPostCommitHookImplementer spy = spy(implementer);
    final HashMap<String, String> map = new HashMap<>();
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            map.put("url1", "12345");
            map.put("url2", "54321");
            return map;
        }
    }).when(spy).createUrlToRemoteUUIDMap(allMaterials);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return Boolean.FALSE;
        }
    }).when(spy).isQualified(uuid, svnMaterial1, map);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return Boolean.TRUE;
        }
    }).when(spy).isQualified(uuid, svnMaterial2, map);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return Boolean.FALSE;
        }
    }).when(spy).isQualified(uuid, svnMaterial3, map);
    final Set<Material> prunedList = spy.prune(allMaterials, params);
    assertThat(prunedList.size(), is(1));
    verify(spy, times(1)).createUrlToRemoteUUIDMap(allMaterials);
}
Also used : HashMap(java.util.HashMap) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) Material(com.thoughtworks.go.domain.materials.Material) P4Material(com.thoughtworks.go.config.materials.perforce.P4Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) TfsMaterial(com.thoughtworks.go.config.materials.tfs.TfsMaterial) Matchers.anyString(org.mockito.Matchers.anyString) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 79 with SvnMaterial

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

the class BuildCauseProducerServiceTest method shouldCheckForModificationsWhenManuallyScheduling.

@Test
public void shouldCheckForModificationsWhenManuallyScheduling() throws Exception {
    HgMaterialConfig hgMaterialConfig = new HgMaterialConfig("url", null);
    HgMaterial hgMaterial = new HgMaterial("url", null);
    SvnMaterial svnMaterial = new SvnMaterial("url", null, null, false);
    SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig("url", null, null, false);
    pipelineConfig.addMaterialConfig(hgMaterialConfig);
    pipelineConfig.addMaterialConfig(svnMaterialConfig);
    when(materialConfigConverter.toMaterial(hgMaterialConfig)).thenReturn(hgMaterial);
    when(materialConfigConverter.toMaterial(svnMaterialConfig)).thenReturn(svnMaterial);
    ServerHealthStateOperationResult result = new ServerHealthStateOperationResult();
    buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(), result);
    assertThat(result.getServerHealthState().isSuccess(), is(true));
    verify(mockMaterialUpdateService, times(2)).updateMaterial(any(Material.class));
    verify(mockMaterialUpdateStatusNotifier).registerListenerFor(eq(pipelineConfig), any(MaterialUpdateStatusListener.class));
}
Also used : SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) 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) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) Test(org.junit.Test)

Example 80 with SvnMaterial

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

the class BuildCauseProducerServiceTest method shouldBeAbleToPassInSpecificRevisionForMaterialsAndScheduleABuild.

@Test
public void shouldBeAbleToPassInSpecificRevisionForMaterialsAndScheduleABuild() throws Exception {
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("upstream-pipeline"), new CaseInsensitiveString("stage"));
    SvnMaterial svnMaterial = new SvnMaterial("url", null, null, false);
    pipelineConfig.addMaterialConfig(dependencyMaterial.config());
    pipelineConfig.addMaterialConfig(svnMaterial.config());
    List<Modification> svnModifications = ModificationsMother.multipleModificationList();
    MaterialConfigs knownMaterialConfigs = new MaterialConfigs(pipelineConfig.materialConfigs());
    MaterialRevision specificMaterialRevision = new MaterialRevision(dependencyMaterial, new Modification(new Date(), "upstream-pipeline/2/stage/1", "MOCK_LABEL-12", null));
    when(specificMaterialRevisionFactory.create(eq("pipeline"), eq(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/2/stage/1")))).thenReturn(new MaterialRevisions(specificMaterialRevision));
    when(pipelineScheduleQueue.mostRecentScheduled("pipeline")).thenReturn(BuildCause.createNeverRun());
    when(materialRepository.findLatestModification(svnMaterial)).thenReturn(new MaterialRevisions(new MaterialRevision(svnMaterial, svnModifications)));
    when(materialConfigConverter.toMaterials(pipelineConfig.materialConfigs())).thenReturn(new Materials(dependencyMaterial, svnMaterial));
    when(materialExpansionService.expandMaterialConfigsForScheduling(pipelineConfig.materialConfigs())).thenReturn(knownMaterialConfigs);
    when(materialConfigConverter.toMaterials(knownMaterialConfigs)).thenReturn(new Materials(dependencyMaterial, svnMaterial));
    ManualBuild buildType = new ManualBuild(Username.ANONYMOUS);
    final HashMap<String, String> stringStringHashMap = new HashMap<>();
    buildCauseProducerService.newProduceBuildCause(pipelineConfig, buildType, new ScheduleOptions(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/2/stage/1"), stringStringHashMap, new HashMap<>()), new ServerHealthStateOperationResult(), 12345);
    verify(pipelineScheduleQueue).schedule(eq("pipeline"), argThat(containsRevisions(new MaterialRevision(svnMaterial, svnModifications), specificMaterialRevision)));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) Materials(com.thoughtworks.go.config.materials.Materials) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Test(org.junit.Test)

Aggregations

SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)140 Test (org.junit.Test)111 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)44 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)39 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)22 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)21 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)20 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)20 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)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 Materials (com.thoughtworks.go.config.materials.Materials)13 Date (java.util.Date)11 Username (com.thoughtworks.go.server.domain.Username)10 P4Material (com.thoughtworks.go.config.materials.perforce.P4Material)9 File (java.io.File)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)7 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)7