Search in sources :

Example 26 with GitMaterial

use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.

the class GitPostCommitHookImplementerTest method shouldReturnFalseForEmptyURLFieldWithAuth.

@Test
public void shouldReturnFalseForEmptyURLFieldWithAuth() throws Exception {
    boolean isEqual = implementer.isUrlEqual("http://repo-url.git", new GitMaterial("http://user:password@"));
    assertThat(isEqual, is(false));
}
Also used : GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) Test(org.junit.Test)

Example 27 with GitMaterial

use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.

the class GitPostCommitHookImplementerTest method shouldReturnListOfMaterialMatchingThePayloadURL.

@Test
public void shouldReturnListOfMaterialMatchingThePayloadURL() throws Exception {
    GitMaterial material1 = mock(GitMaterial.class);
    when(material1.getUrlArgument()).thenReturn(new UrlArgument("https://other_repo.local.git"));
    GitMaterial material2 = mock(GitMaterial.class);
    when(material2.getUrlArgument()).thenReturn(new UrlArgument("https://other_repo.local.git"));
    GitMaterial material3 = mock(GitMaterial.class);
    when(material3.getUrlArgument()).thenReturn(new UrlArgument("https://machine.local.git"));
    GitMaterial material4 = mock(GitMaterial.class);
    when(material4.getUrlArgument()).thenReturn(new UrlArgument("https://machine.local.git"));
    Set<Material> materials = new HashSet<>(Arrays.asList(material1, material2, material3, material4));
    HashMap params = new HashMap();
    params.put(GitPostCommitHookImplementer.REPO_URL_PARAM_KEY, "https://machine.local.git");
    Set<Material> actual = implementer.prune(materials, params);
    assertThat(actual.size(), is(2));
    assertThat(actual, hasItem(material3));
    assertThat(actual, hasItem(material4));
    verify(material1).getUrlArgument();
    verify(material2).getUrlArgument();
    verify(material3).getUrlArgument();
    verify(material4).getUrlArgument();
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) Material(com.thoughtworks.go.domain.materials.Material) Test(org.junit.Test)

Example 28 with GitMaterial

use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.

the class MercurialPostCommitHookImplementerTest method shouldPruneMercurialMaterialsWhichMatchIncomingURL.

@Test
public void shouldPruneMercurialMaterialsWhichMatchIncomingURL() throws Exception {
    HgMaterial material1 = mock(HgMaterial.class);
    when(material1.getUrlArgument()).thenReturn(new UrlArgument("http://repo1.something.local"));
    HgMaterial material2 = mock(HgMaterial.class);
    when(material2.getUrlArgument()).thenReturn(new UrlArgument("http://repo1.something.local"));
    HgMaterial material3 = mock(HgMaterial.class);
    when(material3.getUrlArgument()).thenReturn(new UrlArgument("ssh://repo1.something.local"));
    GitMaterial material4 = mock(GitMaterial.class);
    when(material4.getUrlArgument()).thenReturn(new UrlArgument("http://repo1.something.local"));
    Set<Material> materials = new HashSet<>(Arrays.asList(material1, material2, material3, material4));
    Map params = new HashMap();
    params.put(MercurialPostCommitHookImplementer.REPO_URL_PARAM_KEY, "http://repo1.something.local");
    Set<Material> actual = implementer.prune(materials, params);
    assertThat(actual.size(), is(2));
    assertThat(actual, hasItem(material1));
    assertThat(actual, hasItem(material2));
    verify(material1).getUrlArgument();
    verify(material2).getUrlArgument();
    verify(material3).getUrlArgument();
    verify(material4, times(0)).getUrlArgument();
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) Material(com.thoughtworks.go.domain.materials.Material) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Test(org.junit.Test)

Example 29 with GitMaterial

use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.

the class MaterialExpansionServiceTest method shouldNotExpandGitSubmodulesIntoMultipleMaterialsWhenExpandingGitMaterialForScheduling.

@Test
public void shouldNotExpandGitSubmodulesIntoMultipleMaterialsWhenExpandingGitMaterialForScheduling() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    submoduleRepos.addSubmodule("submodule-1", "sub1");
    GitMaterial gitMaterial = new GitMaterial(submoduleRepos.mainRepo().getUrl());
    when(materialConfigConverter.toMaterials(new MaterialConfigs(gitMaterial.config()))).thenReturn(new Materials(gitMaterial));
    Materials materials = new Materials();
    materialExpansionService.expandForScheduling(gitMaterial, materials);
    assertThat(materials.size(), is(1));
    assertThat(materials.get(0), is(gitMaterial));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) Materials(com.thoughtworks.go.config.materials.Materials)

Example 30 with GitMaterial

use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.

the class SvnPostCommitHookImplementerTest method shouldPruneListToGiveOutOnlySvnMaterials.

@Test
public void shouldPruneListToGiveOutOnlySvnMaterials() {
    final Material svnMaterial1 = mock(SvnMaterial.class);
    final Material svnMaterial2 = mock(SvnMaterial.class);
    final Material svnMaterial3 = mock(SvnMaterial.class);
    final Material hgMaterial = mock(HgMaterial.class);
    final Material gitMaterial = mock(GitMaterial.class);
    final Material p4Material = mock(P4Material.class);
    final Material tfsMaterial = mock(TfsMaterial.class);
    final Material dependencyMaterial = mock(DependencyMaterial.class);
    final HashSet<Material> allMaterials = new HashSet<>(Arrays.asList(svnMaterial1, svnMaterial2, svnMaterial3, gitMaterial, hgMaterial, p4Material, tfsMaterial, dependencyMaterial));
    final SvnPostCommitHookImplementer spy = spy(implementer);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return Boolean.TRUE;
        }
    }).when(spy).isQualified(anyString(), any(SvnMaterial.class), any(HashMap.class));
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return new HashMap();
        }
    }).when(spy).createUrlToRemoteUUIDMap(allMaterials);
    final HashMap params = new HashMap();
    params.put(SvnPostCommitHookImplementer.UUID, "some uuid");
    final Set<Material> prunedList = spy.prune(allMaterials, params);
    assertThat(prunedList.size(), is(3));
    assertThat(prunedList, hasItems(svnMaterial1, svnMaterial2, svnMaterial3));
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) HashMap(java.util.HashMap) InvocationOnMock(org.mockito.invocation.InvocationOnMock) 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)

Aggregations

GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)146 Test (org.junit.Test)137 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)70 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)55 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)33 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)31 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)20 ValueStreamMapPresentationModel (com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel)20 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)19 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)13 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)11 Modification (com.thoughtworks.go.domain.materials.Modification)11 File (java.io.File)11 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)10 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)10 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)10 ScheduleTestUtil (com.thoughtworks.go.server.service.ScheduleTestUtil)10 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)9 Material (com.thoughtworks.go.domain.materials.Material)8 Materials (com.thoughtworks.go.config.materials.Materials)7