Search in sources :

Example 6 with FileSource

use of com.thoughtworks.go.junit5.FileSource in project gocd by gocd.

the class JobXmlRepresenterTest method shouldGenerateDocumentForJob.

@ParameterizedTest
@FileSource(files = "/feeds/job.xml")
void shouldGenerateDocumentForJob(String expectedXML) throws IllegalArtifactLocationException {
    ArtifactUrlReader urlReader = mock(ArtifactUrlReader.class);
    JobInstance jobInstance = JobInstanceMother.failed("unit-test");
    JobIdentifier identifier = new JobIdentifier("up42", 1, "UP42", "unit-tests", "1", "unit");
    jobInstance.setIdentifier(identifier);
    JobPlanLoader jobPlanLoader = mock(JobPlanLoader.class);
    JobPlan jobPlan = mock(JobPlan.class);
    when(urlReader.findArtifactUrl(identifier)).thenReturn("artifact-url");
    when(urlReader.findArtifactRoot(identifier)).thenReturn("artifact-root-url");
    when(jobPlanLoader.loadOriginalJobPlan(jobInstance.getIdentifier())).thenReturn(jobPlan);
    when(jobPlan.getArtifactPlansOfType(ArtifactPlanType.unit)).thenReturn(Collections.singletonList(new ArtifactPlan(ArtifactPlanType.unit, "source", "destination")));
    XmlWriterContext context = new XmlWriterContext("https://go-server/go", urlReader, jobPlanLoader, null, new SystemEnvironment());
    Document document = new JobXmlRepresenter(jobInstance).toXml(context);
    assertThat(document.asXML()).and(expectedXML).ignoreWhitespace().areIdentical();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Document(org.dom4j.Document) FileSource(com.thoughtworks.go.junit5.FileSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with FileSource

use of com.thoughtworks.go.junit5.FileSource 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)

Example 8 with FileSource

use of com.thoughtworks.go.junit5.FileSource in project gocd by gocd.

the class FeedEntriesRepresenterTest method shouldGenerateXmlWithoutEntryWhenEmpty.

@ParameterizedTest
@FileSource(files = "/feeds/stages-with-no-entries.xml")
void shouldGenerateXmlWithoutEntryWhenEmpty(String expectedXML) {
    String pipelineName = "up42";
    XmlWriterContext context = new XmlWriterContext("https://go-server/go", null, null, null, new SystemEnvironment());
    FeedEntries feedEntries = mock(FeedEntries.class);
    when(feedEntries.lastUpdatedDate()).thenReturn(DateUtils.parseISO8601("2019-12-31T07:28:30+05:30"));
    Document document = new FeedEntriesRepresenter(pipelineName, feedEntries).toXml(context);
    XmlAssert.assertThat(document.asXML()).and(expectedXML).ignoreWhitespace().areIdentical();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) Document(org.dom4j.Document) FileSource(com.thoughtworks.go.junit5.FileSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with FileSource

use of com.thoughtworks.go.junit5.FileSource in project gocd by gocd.

the class FeedEntriesRepresenterTest method shouldGenerateFeedXml.

@ParameterizedTest
@FileSource(files = "/feeds/stages-with-entries.xml")
void shouldGenerateFeedXml(String expectedXML) {
    String pipelineName = "up42";
    StageFeedEntry entryOne = cancelled();
    StageFeedEntry entryTwo = passed();
    entryOne.getAuthors().add(new Author("bob", "bob@gocd.org"));
    entryTwo.getAuthors().add(new Author("joe <joe@gocd.org>", null));
    XmlWriterContext context = new XmlWriterContext("https://go-server/go", null, null, null, new SystemEnvironment());
    FeedEntriesRepresenter representable = new FeedEntriesRepresenter(pipelineName, new FeedEntries(entryOne, entryTwo));
    Document document = representable.toXml(context);
    XmlAssert.assertThat(document.asXML()).and(expectedXML).ignoreWhitespace().areIdentical();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) Author(com.thoughtworks.go.domain.feed.Author) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) Document(org.dom4j.Document) StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) FileSource(com.thoughtworks.go.junit5.FileSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with FileSource

use of com.thoughtworks.go.junit5.FileSource in project gocd by gocd.

the class PipelineXmlRepresenterTest method shouldGeneratePipelineXml.

@ParameterizedTest
@FileSource(files = "/feeds/pipeline.xml")
void shouldGeneratePipelineXml(String expectedXML) {
    Document document = new PipelineXmlRepresenter(model).toXml(context);
    assertThat(document.asXML()).and(expectedXML).ignoreWhitespace().areIdentical();
}
Also used : Document(org.dom4j.Document) FileSource(com.thoughtworks.go.junit5.FileSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

FileSource (com.thoughtworks.go.junit5.FileSource)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)9 Document (org.dom4j.Document)7 XmlWriterContext (com.thoughtworks.go.domain.XmlWriterContext)6 ElementBuilder (com.thoughtworks.go.server.domain.xml.builder.ElementBuilder)3 DOMElement (org.dom4j.dom.DOMElement)3 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)2 FeedEntries (com.thoughtworks.go.domain.feed.FeedEntries)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 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)1 Stage (com.thoughtworks.go.domain.Stage)1 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)1 Author (com.thoughtworks.go.domain.feed.Author)1 StageFeedEntry (com.thoughtworks.go.domain.feed.stage.StageFeedEntry)1 PipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel)1