Search in sources :

Example 46 with SvnMaterial

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

the class SvnCommandTest method shouldUseCorrectCredentialsPerSvnMaterialWhenQueryingForInfo.

@Test
public void shouldUseCorrectCredentialsPerSvnMaterialWhenQueryingForInfo() throws Exception {
    final String svnMaterial1Url = "http://localhost/svn/project1";
    final String svnMaterial1User = "svnMaterial1_user";
    final String svnMaterial1Password = "svnMaterial1_password";
    final SvnMaterial svnMaterial1 = buildMockSvnMaterial(svnMaterial1Url, svnMaterial1User, svnMaterial1Password);
    String svnMaterial2Url = "http://localhost/svn/project2";
    SvnMaterial svnMaterial2 = buildMockSvnMaterial(svnMaterial2Url, null, null);
    HashSet<SvnMaterial> svnMaterials = new HashSet<>();
    svnMaterials.add(svnMaterial1);
    svnMaterials.add(svnMaterial2);
    SvnCommand spy = spy(subversion);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            final ConsoleResult consoleResult = mock(ConsoleResult.class);
            when(consoleResult.outputAsString()).thenReturn(svnInfoOutput);
            verifyCommandLine((CommandLine) invocation.getArguments()[0]);
            return consoleResult;
        }

        private void verifyCommandLine(CommandLine commandLine) {
            String commandString = commandLine.toStringForDisplay();
            if (commandString.contains(svnMaterial1User)) {
                List<CommandArgument> arguments = commandLine.getArguments();
                for (CommandArgument argument : arguments) {
                    if (argument instanceof PasswordArgument) {
                        assertThat(argument.forCommandline(), is(svnMaterial1Password));
                    }
                }
            } else {
                assertThat(commandString, not(Matchers.containsString("--username")));
                assertThat(commandString, not(Matchers.containsString("password")));
            }
        }
    }).when(spy).executeCommand(any(CommandLine.class));
    HashMap<String, String> result = spy.createUrlToRemoteUUIDMap(svnMaterials);
    verify(svnMaterial1).getUserName();
    verify(svnMaterial1).getPassword();
    verify(svnMaterial2).getUserName();
    verify(svnMaterial2).getPassword();
}
Also used : SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) List(java.util.List) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 47 with SvnMaterial

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

the class SvnCommandTest method shouldRecogniseSvnAsTheSameIfURLContainsSpaces.

@Test
@RunIf(value = EnhancedOSChecker.class, arguments = { DO_NOT_RUN_ON, WINDOWS })
public void shouldRecogniseSvnAsTheSameIfURLContainsSpaces() throws Exception {
    File working = temporaryFolder.newFolder("shouldRecogniseSvnAsTheSameIfURLContainsSpaces");
    SvnTestRepo repo = new SvnTestRepo(temporaryFolder, "a directory with spaces");
    SvnMaterial material = repo.material();
    assertThat(material.getUrl(), containsString("%20"));
    InMemoryStreamConsumer output = new InMemoryStreamConsumer();
    material.freshCheckout(output, new SubversionRevision("3"), working);
    assertThat(output.getAllOutput(), containsString("Checked out revision 3"));
    InMemoryStreamConsumer output2 = new InMemoryStreamConsumer();
    material.updateTo(output2, working, new RevisionContext(new SubversionRevision("4")), new TestSubprocessExecutionContext());
    assertThat(output2.getAllOutput(), containsString("Updated to revision 4"));
}
Also used : SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) SvnTestRepo(com.thoughtworks.go.helper.SvnTestRepo) File(java.io.File) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 48 with SvnMaterial

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

the class SvnCommandTest method shouldRecogniseSvnAsTheSameIfURLUsesFileProtocol.

@Test
@RunIf(value = EnhancedOSChecker.class, arguments = { DO_NOT_RUN_ON, WINDOWS })
public void shouldRecogniseSvnAsTheSameIfURLUsesFileProtocol() throws Exception {
    SvnTestRepo repo = new SvnTestRepo(temporaryFolder);
    File working = temporaryFolder.newFolder("someDir");
    SvnMaterial material = repo.material();
    InMemoryStreamConsumer output = new InMemoryStreamConsumer();
    material.freshCheckout(output, new SubversionRevision("3"), working);
    assertThat(output.getAllOutput(), containsString("Checked out revision 3"));
    InMemoryStreamConsumer output2 = new InMemoryStreamConsumer();
    updateMaterial(material, new SubversionRevision("4"), working, output2);
    assertThat(output2.getAllOutput(), containsString("Updated to revision 4"));
}
Also used : SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) SvnTestRepo(com.thoughtworks.go.helper.SvnTestRepo) File(java.io.File) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 49 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)

Example 50 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)

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