Search in sources :

Example 1 with XmlWriterContext

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());
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) DefaultJobPlan(com.thoughtworks.go.domain.DefaultJobPlan) GoCipher(com.thoughtworks.go.security.GoCipher) EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) WaitingJobPlan(com.thoughtworks.go.domain.WaitingJobPlan) Document(org.dom4j.Document) Test(org.junit.Test)

Example 2 with XmlWriterContext

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);
}
Also used : JobPlan(com.thoughtworks.go.domain.JobPlan) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) Properties(com.thoughtworks.go.domain.Properties) Before(org.junit.Before)

Example 3 with XmlWriterContext

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));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) Modification(com.thoughtworks.go.domain.materials.Modification) Element(org.dom4j.Element) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) Date(java.util.Date) Test(org.junit.Test)

Example 4 with XmlWriterContext

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"));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) Modification(com.thoughtworks.go.domain.materials.Modification) Element(org.dom4j.Element) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) Date(java.util.Date) Test(org.junit.Test)

Example 5 with XmlWriterContext

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);
}
Also used : XmlApiService(com.thoughtworks.go.server.service.XmlApiService) XSLTTransformerRegistry(com.thoughtworks.studios.shine.semweb.grddl.XSLTTransformerRegistry) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) Before(org.junit.Before)

Aggregations

XmlWriterContext (com.thoughtworks.go.domain.XmlWriterContext)5 Test (org.junit.Test)3 Modification (com.thoughtworks.go.domain.materials.Modification)2 Modifications (com.thoughtworks.go.domain.materials.Modifications)2 Date (java.util.Date)2 Element (org.dom4j.Element)2 Before (org.junit.Before)2 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)1 EnvironmentVariablesConfig (com.thoughtworks.go.config.EnvironmentVariablesConfig)1 DefaultJobPlan (com.thoughtworks.go.domain.DefaultJobPlan)1 JobPlan (com.thoughtworks.go.domain.JobPlan)1 Properties (com.thoughtworks.go.domain.Properties)1 WaitingJobPlan (com.thoughtworks.go.domain.WaitingJobPlan)1 ModifiedFile (com.thoughtworks.go.domain.materials.ModifiedFile)1 GoCipher (com.thoughtworks.go.security.GoCipher)1 XmlApiService (com.thoughtworks.go.server.service.XmlApiService)1 XSLTTransformerRegistry (com.thoughtworks.studios.shine.semweb.grddl.XSLTTransformerRegistry)1 Document (org.dom4j.Document)1