Search in sources :

Example 81 with SvnMaterial

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

the class PipelineInstanceModelTest method shouldReturnIfAnyMaterialHasModifications.

@Test
public void shouldReturnIfAnyMaterialHasModifications() {
    final SvnMaterial svnMaterial = svnMaterial("http://svnurl");
    final HgMaterial hgMaterial = hgMaterial("http://hgurl", "hgdir");
    MaterialRevisions currentRevisions = ModificationsMother.getMaterialRevisions(new HashMap<Material, String>() {

        {
            put(svnMaterial, "1");
            put(hgMaterial, "a");
        }
    });
    MaterialRevisions latestRevisions = ModificationsMother.getMaterialRevisions(new HashMap<Material, String>() {

        {
            put(svnMaterial, "1");
            put(hgMaterial, "b");
        }
    });
    MaterialConfigs materialConfigs = new MaterialConfigs();
    materialConfigs.add(svnMaterial.config());
    materialConfigs.add(hgMaterial.config());
    StageInstanceModels stages = new StageInstanceModels();
    stages.addStage("unit1", JobHistory.withJob("test", JobState.Completed, JobResult.Passed, new Date()));
    stages.addFutureStage("unit2", false);
    PipelineInstanceModel model = PipelineInstanceModel.createPipeline("pipeline", -1, "label", BuildCause.createWithModifications(currentRevisions, ""), stages);
    model.setLatestRevisions(latestRevisions);
    model.setMaterialConfigs(materialConfigs);
    assertThat("svnMaterial hasNewRevisions", model.hasNewRevisions(svnMaterial.config()), is(false));
    assertThat("hgMaterial hasNewRevisions", model.hasNewRevisions(hgMaterial.config()), is(true));
    assertThat("all materials hasNewRevisions", model.hasNewRevisions(), is(true));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) MaterialsMother.hgMaterial(com.thoughtworks.go.helper.MaterialsMother.hgMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) MaterialsMother.svnMaterial(com.thoughtworks.go.helper.MaterialsMother.svnMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) Test(org.junit.Test)

Example 82 with SvnMaterial

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

the class EnvironmentVariableContextTest method shouldPopulateEnvironmentForMaterialUsingMaterialName.

@Test
public void shouldPopulateEnvironmentForMaterialUsingMaterialName() throws IOException {
    SvnMaterial svn = MaterialsMother.svnMaterial();
    svn.setName(new CaseInsensitiveString("svn"));
    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, temporaryFolder.newFolder());
    assertThat(context.getProperty("GO_REVISION_SVN"), is("revision1"));
    assertThat(context.getProperty("GO_MATERIAL_SVN_HAS_CHANGED"), is("false"));
}
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) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 83 with SvnMaterial

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

the class SvnCommandTest method shouldGetSvnInfoAndReturnMapOfUrlToUUID.

@Test
public void shouldGetSvnInfoAndReturnMapOfUrlToUUID() {
    final String svnInfoOutput = "<?xml version=\"1.0\"?>\n" + "<info>\n" + "<entry\n" + "   kind=\"dir\"\n" + "   path=\"project1\"\n" + "   revision=\"27\">\n" + "<url>http://localhost/svn/project1</url>\n" + "<repository>\n" + "<root>http://localhost/svn/project1</root>\n" + "<uuid>b51fe673-20c0-4205-a07b-5deb54bb09f3</uuid>\n" + "</repository>\n" + "<commit\n" + "   revision=\"27\">\n" + "<author>anthill</author>\n" + "<date>2012-10-18T07:54:06.487895Z</date>\n" + "</commit>\n" + "</entry>\n" + "</info>";
    final SvnMaterial svnMaterial = mock(SvnMaterial.class);
    when(svnMaterial.getUrl()).thenReturn("http://localhost/svn/project1");
    when(svnMaterial.getUserName()).thenReturn("user");
    when(svnMaterial.getPassword()).thenReturn("password");
    final ConsoleResult consoleResult = mock(ConsoleResult.class);
    when(consoleResult.outputAsString()).thenReturn(svnInfoOutput);
    final HashSet<SvnMaterial> svnMaterials = new HashSet<>();
    svnMaterials.add(svnMaterial);
    final SvnCommand spy = spy(subversion);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            final CommandLine commandLine = (CommandLine) invocation.getArguments()[0];
            assertThat(commandLine.toString(), containsString("svn info --xml --username user --password ****** http://localhost/svn/project1"));
            return consoleResult;
        }
    }).when(spy).executeCommand(any(CommandLine.class));
    final HashMap<String, String> urlToRemoteUUIDMap = spy.createUrlToRemoteUUIDMap(svnMaterials);
    assertThat(urlToRemoteUUIDMap.size(), is(1));
    assertThat(urlToRemoteUUIDMap.get("http://localhost/svn/project1"), is("b51fe673-20c0-4205-a07b-5deb54bb09f3"));
}
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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 84 with SvnMaterial

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

the class SvnCommandTest method shouldRecogniseSvnAsTheSameIfURLContainsChineseCharacters.

@Test
@RunIf(value = EnhancedOSChecker.class, arguments = { DO_NOT_RUN_ON, WINDOWS })
public void shouldRecogniseSvnAsTheSameIfURLContainsChineseCharacters() throws Exception {
    File working = temporaryFolder.newFolder("shouldRecogniseSvnAsTheSameIfURLContainsSpaces");
    SvnTestRepo repo = new SvnTestRepo(temporaryFolder, "a directory with 司徒空在此");
    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();
    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 85 with SvnMaterial

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

the class SvnCommandTest method shouldGetSvnInfoForMultipleMaterialsAndReturnMapOfUrlToUUID.

@Test
public void shouldGetSvnInfoForMultipleMaterialsAndReturnMapOfUrlToUUID() {
    final SvnMaterial svnMaterial1 = mock(SvnMaterial.class);
    when(svnMaterial1.getUrl()).thenReturn("http://localhost/svn/project1");
    final SvnMaterial svnMaterial2 = mock(SvnMaterial.class);
    when(svnMaterial2.getUrl()).thenReturn("http://foo.bar");
    final HashSet<SvnMaterial> svnMaterials = new HashSet<>();
    svnMaterials.add(svnMaterial1);
    svnMaterials.add(svnMaterial2);
    final 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);
            final CommandLine commandLine = (CommandLine) invocation.getArguments()[0];
            if (commandLine.toString().contains("http://localhost/svn/project1")) {
                return consoleResult;
            } else {
                throw new RuntimeException("Some thing crapped out");
            }
        }
    }).when(spy).executeCommand(any(CommandLine.class));
    HashMap<String, String> urlToRemoteUUIDMap = null;
    try {
        urlToRemoteUUIDMap = spy.createUrlToRemoteUUIDMap(svnMaterials);
    } catch (Exception e) {
        fail("Should not have failed although exception was thrown " + e);
    }
    assertThat(urlToRemoteUUIDMap.size(), is(1));
    assertThat(urlToRemoteUUIDMap.get("http://localhost/svn/project1"), is("b51fe673-20c0-4205-a07b-5deb54bb09f3"));
    verify(spy, times(2)).executeCommand(any(CommandLine.class));
}
Also used : SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IOException(java.io.IOException) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HashSet(java.util.HashSet) 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