Search in sources :

Example 6 with GenerationReportToAssert

use of com.devonfw.cobigen.api.assertj.GenerationReportToAssert in project cobigen by devonfw.

the class XmlPluginIntegrationTest method testMergeStrategyDefined_xmlmerge_override_attachTexts_validate.

/**
 * Tests the merge strategy xmlmerge_override_attachTexts_validate to exist and being registered.
 *
 * @throws Exception test fails
 */
@Test
public void testMergeStrategyDefined_xmlmerge_override_attachTexts_validate() throws Exception {
    generateTemplateAndTestOutput("xmlTestTemplate_SingleChildValidate", "xmlTestOutput_SingleChild.txt", null);
    GenerationReportToAssert asserts = generateTemplateAndTestOutput("xmlTestTemplate_SingleChildValidate", "xmlTestOutput_SingleChild.txt", null);
    asserts.notContainsException(PluginNotAvailableException.class);
}
Also used : GenerationReportToAssert(com.devonfw.cobigen.api.assertj.GenerationReportToAssert) Test(org.junit.Test)

Example 7 with GenerationReportToAssert

use of com.devonfw.cobigen.api.assertj.GenerationReportToAssert in project cobigen by devonfw.

the class XmlPluginIntegrationTest method testMergeStrategyDefined_xmlmerge.

/**
 * Tests the merge strategy xmlmerge to exist and being registered.
 *
 * @throws Exception test fails
 */
@Test
public void testMergeStrategyDefined_xmlmerge() throws Exception {
    generateTemplateAndTestOutput("xmlTestTemplate_ChildList", "xmlTestOutput_ChildList.txt", null);
    GenerationReportToAssert asserts = generateTemplateAndTestOutput("xmlTestTemplate_ChildList", "xmlTestOutput_ChildList.txt", null);
    asserts.notContainsException(PluginNotAvailableException.class);
}
Also used : GenerationReportToAssert(com.devonfw.cobigen.api.assertj.GenerationReportToAssert) Test(org.junit.Test)

Example 8 with GenerationReportToAssert

use of com.devonfw.cobigen.api.assertj.GenerationReportToAssert in project cobigen by devonfw.

the class XmlPluginIntegrationTest method generateTemplateAndTestOutput.

/**
 * Generates the template with the given templateId and reads the generated File with the outputFileName. It will be
 * asserted, that this file has the expectedFileContents passed as parameter.
 *
 * @param templateId Template to generate
 * @param outputFileName file name of the generated output File
 * @param expectedFileContents generated contents to be expected (asserted)
 * @return the resulting report
 * @throws Exception if anything fails.
 */
private GenerationReportToAssert generateTemplateAndTestOutput(String templateId, String outputFileName, String expectedFileContents) throws Exception {
    CobiGen cobiGen = CobiGenFactory.create(this.cobigenConfigFolder.toURI());
    // wenn der temporäre Output Ordner breits existiert, dann wird dieser wiederverwendet.
    File tmpFolderCobiGen = new File(this.tmpFolder.getRoot().getAbsolutePath() + File.separator + "cobigen_output");
    if (!tmpFolderCobiGen.exists()) {
        tmpFolderCobiGen = this.tmpFolder.newFolder("cobigen_output");
    }
    // read xml File as Document
    Object inputDocument = cobiGen.read(this.testinput.toPath(), Charset.forName("UTF-8"));
    // find matching templates and use test template for generation
    List<TemplateTo> templates = cobiGen.getMatchingTemplates(inputDocument);
    boolean templateFound = false;
    GenerationReportToAssert asserts = null;
    for (TemplateTo template : templates) {
        if (template.getId().equals(templateId)) {
            GenerationReportTo report = cobiGen.generate(inputDocument, template, Paths.get(tmpFolderCobiGen.getAbsolutePath()), false, (taskname, progress) -> {
            });
            asserts = assertThat(report);
            File expectedFile = new File(tmpFolderCobiGen.getAbsoluteFile() + File.separator + outputFileName);
            Assert.assertTrue(expectedFile.exists());
            // validate results if expected file contents are defined
            if (expectedFileContents != null) {
                Assert.assertEquals(expectedFileContents, FileUtils.readFileToString(expectedFile, StandardCharsets.UTF_8));
            }
            templateFound = true;
            break;
        }
    }
    if (!templateFound) {
        throw new AssertionFailedError("Test template not found");
    }
    return asserts;
}
Also used : GenerationReportToAssert(com.devonfw.cobigen.api.assertj.GenerationReportToAssert) GenerationReportTo(com.devonfw.cobigen.api.to.GenerationReportTo) CobiGen(com.devonfw.cobigen.api.CobiGen) AssertionFailedError(junit.framework.AssertionFailedError) File(java.io.File) TemplateTo(com.devonfw.cobigen.api.to.TemplateTo)

Example 9 with GenerationReportToAssert

use of com.devonfw.cobigen.api.assertj.GenerationReportToAssert in project cobigen by devonfw.

the class XmlPluginIntegrationTest method testMergeStrategyDefined_xmlmerge_attachTexts.

/**
 * Tests the merge strategy xmlmerge_attachTexts to exist and being registered.
 *
 * @throws Exception test fails
 */
@Test
public void testMergeStrategyDefined_xmlmerge_attachTexts() throws Exception {
    generateTemplateAndTestOutput("xmlTestTemplate_TextNodes", "xmlTestOutput_TextNodes.txt", null);
    GenerationReportToAssert asserts = generateTemplateAndTestOutput("xmlTestTemplate_TextNodes", "xmlTestOutput_TextNodes.txt", null);
    asserts.notContainsException(PluginNotAvailableException.class);
}
Also used : GenerationReportToAssert(com.devonfw.cobigen.api.assertj.GenerationReportToAssert) Test(org.junit.Test)

Example 10 with GenerationReportToAssert

use of com.devonfw.cobigen.api.assertj.GenerationReportToAssert in project cobigen by devonfw.

the class XmlPluginIntegrationTest method testMergeStrategyDefined_xmlmerge_override.

/**
 * Tests the merge strategy xmlmerge_override to exist and being registered.
 *
 * @throws Exception test fails
 */
@Test
public void testMergeStrategyDefined_xmlmerge_override() throws Exception {
    generateTemplateAndTestOutput("xmlTestTemplate_VariablesConstant", "xmlTestOutput_VariablesConstant.txt", null);
    GenerationReportToAssert asserts = generateTemplateAndTestOutput("xmlTestTemplate_VariablesConstant", "xmlTestOutput_VariablesConstant.txt", null);
    asserts.notContainsException(PluginNotAvailableException.class);
}
Also used : GenerationReportToAssert(com.devonfw.cobigen.api.assertj.GenerationReportToAssert) Test(org.junit.Test)

Aggregations

GenerationReportToAssert (com.devonfw.cobigen.api.assertj.GenerationReportToAssert)10 Test (org.junit.Test)9 CobiGen (com.devonfw.cobigen.api.CobiGen)1 GenerationReportTo (com.devonfw.cobigen.api.to.GenerationReportTo)1 TemplateTo (com.devonfw.cobigen.api.to.TemplateTo)1 File (java.io.File)1 AssertionFailedError (junit.framework.AssertionFailedError)1