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));
}
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"));
}
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"));
}
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"));
}
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));
}
Aggregations