Search in sources :

Example 61 with Material

use of com.thoughtworks.go.domain.materials.Material 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 62 with Material

use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.

the class BuildCauseProducerServiceTest method shouldUpdateOnlyOnceIfThereAreTwoMaterialsWithSameFingerPrintButDifferentDest.

@Test
public void shouldUpdateOnlyOnceIfThereAreTwoMaterialsWithSameFingerPrintButDifferentDest() {
    HgMaterial material1 = new HgMaterial("url", null);
    HgMaterial material2 = new HgMaterial("url", null);
    HgMaterialConfig materialConfig1 = new HgMaterialConfig("url", null);
    HgMaterialConfig materialConfig2 = new HgMaterialConfig("url", null);
    material1.setFolder("folder1");
    material2.setFolder("folder2");
    assertThat(material1.getFingerprint(), is(material2.getFingerprint()));
    pipelineConfig.addMaterialConfig(materialConfig1);
    pipelineConfig.addMaterialConfig(materialConfig2);
    Material[] materials = new Material[] { material1, material2 };
    when(materialConfigConverter.toMaterial(materialConfig1)).thenReturn(material1);
    when(materialConfigConverter.toMaterial(materialConfig2)).thenReturn(material2);
    buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(new HashMap<>(), new HashMap<>(), new HashMap<>()), new ServerHealthStateOperationResult());
    verify(mockMaterialUpdateService, times(1)).updateMaterial(any(Material.class));
    MaterialUpdateStatusListener statusListener = extractMaterialListenerInstanceFromRegisterCall();
    statusListener.onMaterialUpdate(new MaterialUpdateFailedMessage(materials[0], 0, new Exception("Cannot connect to repo")));
    verify(mockMaterialUpdateStatusNotifier).removeListenerFor(pipelineConfig);
}
Also used : HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) 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) Test(org.junit.Test)

Example 63 with Material

use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.

the class BuildCauseProducerServiceTest method shouldAllowRetriggeringIfThePreviousTriggerFailed.

@Test
public void shouldAllowRetriggeringIfThePreviousTriggerFailed() throws Exception {
    GitMaterialConfig materialConfig = MaterialConfigsMother.gitMaterialConfig();
    PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("pipeline"), new MaterialConfigs(materialConfig));
    Material material = new MaterialConfigConverter().toMaterial(materialConfig);
    buildCauseProducerService.manualSchedulePipeline(Username.CRUISE_TIMER, pipelineConfig.name(), new ScheduleOptions(), errorResult());
    HttpOperationResult result = new HttpOperationResult();
    when(materialConfigConverter.toMaterial(materialConfig)).thenReturn(material);
    when(materialExpansionService.expandMaterialConfigsForScheduling(pipelineConfig.materialConfigs())).thenReturn(pipelineConfig.materialConfigs());
    when(materialConfigConverter.toMaterials(pipelineConfig.materialConfigs())).thenReturn(new Materials(material));
    when(goConfigService.pipelineConfigNamed(pipelineConfig.name())).thenReturn(pipelineConfig);
    buildCauseProducerService.manualSchedulePipeline(Username.CRUISE_TIMER, pipelineConfig.name(), new ScheduleOptions(), result);
    assertThat(result.httpCode(), is(202));
    assertThat(result.fullMessage(), is("Request to schedule pipeline pipeline accepted"));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) 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) Test(org.junit.Test)

Example 64 with Material

use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.

the class MagicalMaterialAndMaterialConfigConversionTest method shouldBeSameObject_WhenConversionIsDoneFromMaterialConfigToMaterialAndBack.

@Theory
public void shouldBeSameObject_WhenConversionIsDoneFromMaterialConfigToMaterialAndBack(MaterialConfig materialConfig) throws Exception {
    Material materialFromConfig = materialConfigConverter.toMaterial(materialConfig);
    MaterialConfig materialConfigConvertedBackFromMaterial = materialFromConfig.config();
    assertThat(materialConfigConvertedBackFromMaterial, is(materialConfig));
    assertTrue(message("Material <-> MaterialConfig conversion failed.", materialConfigConvertedBackFromMaterial, materialConfig), reflectionEquals(materialConfigConvertedBackFromMaterial, materialConfig));
    assertThat(materialFromConfig.getFingerprint(), is(materialConfig.getFingerprint()));
    assertThat(materialFromConfig.isAutoUpdate(), is(materialConfig.isAutoUpdate()));
    assertThat(materialConfigConvertedBackFromMaterial.getFingerprint(), is(materialConfig.getFingerprint()));
    assertPasswordIsCorrect(materialConfig);
    assertPasswordIsCorrect(materialFromConfig);
    assertPasswordIsCorrect(materialConfigConvertedBackFromMaterial);
}
Also used : PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) TfsMaterialConfig(com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) Material(com.thoughtworks.go.domain.materials.Material) PasswordAwareMaterial(com.thoughtworks.go.config.materials.PasswordAwareMaterial) Theory(org.junit.experimental.theories.Theory)

Example 65 with Material

use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.

the class MagicalMaterialAndMaterialConfigConversionTest method shouldBeSameObject_WhenConversionIsDoneFromMaterialToMaterialInstanceAndBack.

@Theory
public void shouldBeSameObject_WhenConversionIsDoneFromMaterialToMaterialInstanceAndBack(MaterialConfig materialConfig) throws Exception {
    Material material = materialConfigConverter.toMaterial(materialConfig);
    MaterialInstance materialInstance = material.createMaterialInstance();
    Material materialConvertedBackFromInstance = materialInstance.toOldMaterial(materialConfig.getName().toString(), materialConfig.getFolder(), "pass");
    assertTrue(message("Material <-> MaterialInstance conversion failed.", material, materialConvertedBackFromInstance), reflectionEquals(material, materialConvertedBackFromInstance, fieldsWhichShouldBeIgnoredWhenSavedInDbAndGotBack.get(materialConfig.getClass())));
    assertThat(materialInstance.getFingerprint(), is(material.getFingerprint()));
    assertThat(materialConvertedBackFromInstance.getFingerprint(), is(materialInstance.getFingerprint()));
    assertPasswordIsCorrect(material);
    assertPasswordIsCorrect(materialConvertedBackFromInstance);
}
Also used : Material(com.thoughtworks.go.domain.materials.Material) PasswordAwareMaterial(com.thoughtworks.go.config.materials.PasswordAwareMaterial) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) Theory(org.junit.experimental.theories.Theory)

Aggregations

Material (com.thoughtworks.go.domain.materials.Material)95 Test (org.junit.Test)59 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)39 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)39 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)23 Modification (com.thoughtworks.go.domain.materials.Modification)20 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)18 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)16 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)14 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)14 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)14 Materials (com.thoughtworks.go.config.materials.Materials)11 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)10 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)9 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)9 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)8 Date (java.util.Date)8 HashSet (java.util.HashSet)8 P4Material (com.thoughtworks.go.config.materials.perforce.P4Material)7 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)7