use of com.thoughtworks.go.domain.XmlWriterContext in project gocd by gocd.
the class JobPlanXmlViewModelTest method shouldConvertJobPlanToXmlDocument.
@Test
public void shouldConvertJobPlanToXmlDocument() throws IOException, DocumentException {
EnvironmentVariableConfig secureEnvVariable = new EnvironmentVariableConfig(new GoCipher(), "secureVariable", "value2", true);
DefaultJobPlan jobPlan1 = JobInstanceMother.jobPlan("job-1", 1);
jobPlan1.setJobId(10);
EnvironmentVariablesConfig variables = new EnvironmentVariablesConfig();
variables.add("some_var", "blah");
variables.add(secureEnvVariable);
jobPlan1.setVariables(variables);
DefaultJobPlan jobPlan2 = JobInstanceMother.jobPlan("job-2", 1);
jobPlan2.setJobId(11);
JobPlanXmlViewModel jobPlanXmlViewModel = new JobPlanXmlViewModel(ArrayUtil.asList(new WaitingJobPlan(jobPlan1, "envName"), new WaitingJobPlan(jobPlan2, null)));
String expectedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<scheduledJobs>" + "<job name=\"job-1\" id=\"10\">" + "<link rel=\"self\" href=\"http://baseurl/go/tab/build/detail/pipeline/1/stage/1/job-1\"/>" + "<buildLocator>pipeline/1/stage/1/job-1</buildLocator>" + "<environment>envName</environment>" + "<resources><resource><![CDATA[foo]]></resource><resource><![CDATA[bar]]></resource></resources>" + "<environmentVariables><variable name=\"some_var\">blah</variable><variable name=\"secureVariable\">****</variable></environmentVariables>" + "</job>" + "<job name=\"job-2\" id=\"11\">" + "<link rel=\"self\" href=\"http://baseurl/go/tab/build/detail/pipeline/1/stage/1/job-2\"/>" + "<buildLocator>pipeline/1/stage/1/job-2</buildLocator>" + "<resources><resource><![CDATA[foo]]></resource><resource><![CDATA[bar]]></resource></resources>" + "</job>" + "</scheduledJobs>";
Document document = jobPlanXmlViewModel.toXml(new XmlWriterContext("http://baseurl/go", null, null, null, null));
assertEquals(expectedXml, document.asXML());
}
use of com.thoughtworks.go.domain.XmlWriterContext in project gocd by gocd.
the class JobXmlViewModelTest method setUp.
@Before
public void setUp() {
xmlWriterContext = mock(XmlWriterContext.class);
jobPlan = mock(JobPlan.class);
defaultJob = JobInstanceMother.completed("defaultJob");
when(xmlWriterContext.planFor(defaultJob.getIdentifier())).thenReturn(jobPlan);
when(xmlWriterContext.propertiesForJob(defaultJob.getId())).thenReturn(new Properties());
jobXmlViewModel = new JobXmlViewModel(defaultJob);
}
use of com.thoughtworks.go.domain.XmlWriterContext in project gocd by gocd.
the class PackageXmlViewModelTest method shouldPopulateModificationDetailsForPackageMaterial.
@Test
public void shouldPopulateModificationDetailsForPackageMaterial() {
String userName = "user";
String comment = "comments";
Date checkinDate = new Date(System.currentTimeMillis());
String revision = "package-1.0.0.rpm";
Element modificationsTag = DocumentHelper.createDocument().addElement("modifications");
Modifications modifications = new Modifications(new Modification(userName, comment, null, checkinDate, revision));
XmlWriterContext writerContext = mock(XmlWriterContext.class);
when(writerContext.getBaseUrl()).thenReturn("http://someurl:8153/go");
new PipelineXmlViewModel.PackageXmlViewModel(MaterialsMother.packageMaterial()).populateXmlForModifications(modifications, writerContext, modificationsTag);
Element changeSet = modificationsTag.element("changeset");
assertThat(changeSet, is(not(IsNull.nullValue())));
assertThat(changeSet.attributeValue("changesetUri"), is("http://someurl:8153/go/api/materials/1/changeset/package-1.0.0.rpm.xml"));
assertThat(changeSet.element("user").getText(), is(userName));
assertThat(changeSet.element("revision").getText(), is(revision));
assertThat(changeSet.element("checkinTime").getText(), is(DateUtils.formatISO8601(checkinDate)));
assertThat(changeSet.element("message").getText(), is(comment));
}
use of com.thoughtworks.go.domain.XmlWriterContext in project gocd by gocd.
the class SCMXmlViewModelTest method shouldPopulateModificationDetailsForPluggableSCMMaterial.
@Test
public void shouldPopulateModificationDetailsForPluggableSCMMaterial() {
String userName = "user";
String comment = "comment-1";
Date checkinDate = new Date(System.currentTimeMillis());
String revision = "revision-1";
Modification modification = new Modification(userName, comment, null, checkinDate, revision);
modification.setModifiedFiles(new ArrayList<>(asList(new ModifiedFile("f1", null, ModifiedAction.added), new ModifiedFile("f2", null, ModifiedAction.deleted))));
Modifications modifications = new Modifications(modification);
XmlWriterContext writerContext = mock(XmlWriterContext.class);
when(writerContext.getBaseUrl()).thenReturn("http://someurl:8153/go");
Element modificationsTag = DocumentHelper.createDocument().addElement("modifications");
new PipelineXmlViewModel.ScmXmlViewModel(MaterialsMother.pluggableSCMMaterial()).populateXmlForModifications(modifications, writerContext, modificationsTag);
Element changeSet = modificationsTag.element("changeset");
assertThat(changeSet, is(not(IsNull.nullValue())));
assertThat(changeSet.attributeValue("changesetUri"), is("http://someurl:8153/go/api/materials/1/changeset/revision-1.xml"));
assertThat(changeSet.element("user").getText(), is(userName));
assertThat(changeSet.element("revision").getText(), is(revision));
assertThat(changeSet.element("checkinTime").getText(), is(DateUtils.formatISO8601(checkinDate)));
assertThat(changeSet.element("message").getText(), is(comment));
Element file1 = (Element) changeSet.elements("file").get(0);
assertThat(file1.attributeValue("name"), is("f1"));
assertThat(file1.attributeValue("action"), is("added"));
Element file2 = (Element) changeSet.elements("file").get(1);
assertThat(file2.attributeValue("name"), is("f2"));
assertThat(file2.attributeValue("action"), is("deleted"));
}
use of com.thoughtworks.go.domain.XmlWriterContext in project gocd by gocd.
the class JobResourceImporterTest method setup.
@Before
public void setup() {
transformerRegistry = new XSLTTransformerRegistry();
xmlWriterContext = mock(XmlWriterContext.class);
baseUri = "https://localhost:8154/go";
xmlApiService = mock(XmlApiService.class);
}
Aggregations