Search in sources :

Example 1 with ElementBuilder

use of com.thoughtworks.go.server.domain.xml.builder.ElementBuilder in project gocd by gocd.

the class JobPlanXmlRepresenter method populateJob.

public void populateJob(ElementBuilder builder, XmlWriterContext ctx, WaitingJobPlan waitingJobPlan) {
    JobPlan jobPlan = waitingJobPlan.jobPlan();
    builder.attr("name", jobPlan.getName()).link(ctx.jobXmlLink(jobPlan.getIdentifier()), "self").link(ctx.jobDetailsLink(jobPlan.getIdentifier()), "alternate", jobPlan.getName() + " Job Detail", "text/html").textNode("buildLocator", jobPlan.getIdentifier().buildLocator());
    if (isNotBlank(waitingJobPlan.envName())) {
        builder.textNode("environment", waitingJobPlan.envName());
    }
    if (!jobPlan.getResources().isEmpty()) {
        builder.node("resources", rb -> jobPlan.getResources().forEach(resource -> {
            rb.cdataNode("resource", resource.getName());
        }));
    }
    if (!jobPlan.getVariables().isEmpty()) {
        builder.node("environmentVariables", eb -> jobPlan.getVariables().forEach(variable -> {
            eb.node("variable", vb -> vb.attr("name", variable.getName()).text(variable.getDisplayValue()));
        }));
    }
}
Also used : Document(org.dom4j.Document) List(java.util.List) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) ElementBuilder(com.thoughtworks.go.server.domain.xml.builder.ElementBuilder) DocumentBuilder(com.thoughtworks.go.server.domain.xml.builder.DocumentBuilder) JobPlan(com.thoughtworks.go.domain.JobPlan) WaitingJobPlan(com.thoughtworks.go.domain.WaitingJobPlan) XmlRepresentable(com.thoughtworks.go.domain.XmlRepresentable) JobPlan(com.thoughtworks.go.domain.JobPlan) WaitingJobPlan(com.thoughtworks.go.domain.WaitingJobPlan)

Example 2 with ElementBuilder

use of com.thoughtworks.go.server.domain.xml.builder.ElementBuilder in project gocd by gocd.

the class MaterialXmlRepresenter method toXml.

@Override
public Document toXml(XmlWriterContext ctx) {
    DOMElement rootElement = new DOMElement("material");
    ElementBuilder builder = new ElementBuilder(rootElement);
    populateMaterial(ctx, materialRevision.getMaterial(), builder);
    return new DOMDocument(rootElement);
}
Also used : ElementBuilder(com.thoughtworks.go.server.domain.xml.builder.ElementBuilder) DOMDocument(org.dom4j.dom.DOMDocument) DOMElement(org.dom4j.dom.DOMElement)

Example 3 with ElementBuilder

use of com.thoughtworks.go.server.domain.xml.builder.ElementBuilder in project gocd by gocd.

the class DependencyMaterialXmlRepresenterTest method shouldRepresentDependencyMaterial.

@ParameterizedTest
@FileSource(files = "/feeds/materials/dependency-material.xml")
void shouldRepresentDependencyMaterial(String expectedXML) {
    Date date = DateUtils.parseISO8601("2019-12-31T15:31:49+05:30");
    DependencyMaterial material = MaterialsMother.dependencyMaterial();
    material.setId(60);
    MaterialRevision revision = new MaterialRevision(material, new Modification(date, "acceptance/63/twist-plugins/2", null, null));
    DOMElement root = new DOMElement("materials");
    ElementBuilder builder = new ElementBuilder(root);
    StageFinder stageFinder = getStageFinder(100L);
    XmlWriterContext context = new XmlWriterContext("https://test.host/go", null, null, stageFinder, new SystemEnvironment());
    new DependencyMaterialXmlRepresenter("up42", 1, revision).populate(builder, context);
    assertThat(root.asXML()).and(expectedXML).ignoreWhitespace().areIdentical();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Modification(com.thoughtworks.go.domain.materials.Modification) ElementBuilder(com.thoughtworks.go.server.domain.xml.builder.ElementBuilder) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) DOMElement(org.dom4j.dom.DOMElement) Date(java.util.Date) FileSource(com.thoughtworks.go.junit5.FileSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ElementBuilder

use of com.thoughtworks.go.server.domain.xml.builder.ElementBuilder in project gocd by gocd.

the class PackageMaterialXmlRepresenterTest method shouldRepresentDependencyMaterial.

@ParameterizedTest
@FileSource(files = "/feeds/materials/package-material.xml")
void shouldRepresentDependencyMaterial(String expectedXML) {
    Date date = DateUtils.parseISO8601("2019-12-31T15:31:49+05:30");
    PackageMaterial material = MaterialsMother.packageMaterial();
    material.setId(60);
    Modification modification = new Modification("Bob", "Release new package", null, date, "1");
    MaterialRevision revision = new MaterialRevision(material, modification);
    DOMElement root = new DOMElement("materials");
    ElementBuilder builder = new ElementBuilder(root);
    XmlWriterContext context = new XmlWriterContext("https://test.host/go", null, null, null, new SystemEnvironment());
    new PackageMaterialXmlRepresenter("up42", 1, revision).populate(builder, context);
    assertThat(root.asXML()).and(expectedXML).ignoreWhitespace().areIdentical();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Modification(com.thoughtworks.go.domain.materials.Modification) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) ElementBuilder(com.thoughtworks.go.server.domain.xml.builder.ElementBuilder) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) DOMElement(org.dom4j.dom.DOMElement) Date(java.util.Date) FileSource(com.thoughtworks.go.junit5.FileSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with ElementBuilder

use of com.thoughtworks.go.server.domain.xml.builder.ElementBuilder in project gocd by gocd.

the class ScmMaterialXmlRepresenterTest method shouldGenerateXmlFromMaterialRevision.

@ParameterizedTest
@FileSource(files = "/feeds/materials/git-material.xml")
void shouldGenerateXmlFromMaterialRevision(String expectedXML) {
    GitMaterial gitMaterial = gitMaterial("https://material/example.git");
    gitMaterial.setId(100);
    MaterialRevision materialRevision = new MaterialRevision(gitMaterial, modifications());
    DOMElement root = new DOMElement("materials");
    ElementBuilder builder = new ElementBuilder(root);
    XmlWriterContext context = new XmlWriterContext("https://test.host/go", null, null, null, new SystemEnvironment());
    new ScmMaterialXmlRepresenter("up42", 1, materialRevision).populate(builder, context);
    assertThat(root.asXML()).and(expectedXML).ignoreWhitespace().areIdentical();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) ElementBuilder(com.thoughtworks.go.server.domain.xml.builder.ElementBuilder) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) DOMElement(org.dom4j.dom.DOMElement) FileSource(com.thoughtworks.go.junit5.FileSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ElementBuilder (com.thoughtworks.go.server.domain.xml.builder.ElementBuilder)5 DOMElement (org.dom4j.dom.DOMElement)4 XmlWriterContext (com.thoughtworks.go.domain.XmlWriterContext)3 FileSource (com.thoughtworks.go.junit5.FileSource)3 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)2 Modification (com.thoughtworks.go.domain.materials.Modification)2 Date (java.util.Date)2 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)1 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)1 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)1 JobPlan (com.thoughtworks.go.domain.JobPlan)1 WaitingJobPlan (com.thoughtworks.go.domain.WaitingJobPlan)1 XmlRepresentable (com.thoughtworks.go.domain.XmlRepresentable)1 DocumentBuilder (com.thoughtworks.go.server.domain.xml.builder.DocumentBuilder)1 List (java.util.List)1 StringUtils.isNotBlank (org.apache.commons.lang3.StringUtils.isNotBlank)1 Document (org.dom4j.Document)1 DOMDocument (org.dom4j.dom.DOMDocument)1