Search in sources :

Example 21 with GenerationReportTo

use of com.devonfw.cobigen.api.to.GenerationReportTo in project cobigen by devonfw.

the class ModelCreationTest method testCorrectGenericTypeExtraction.

/**
 * Tests the correct reading and writing of parametric types as found in the input sources.
 *
 * @throws Exception test fails
 */
@Test
public void testCorrectGenericTypeExtraction() throws Exception {
    CobiGen cobiGen = CobiGenFactory.create(this.cobigenConfigFolder.toURI());
    File tmpFolderCobiGen = this.tmpFolder.newFolder("cobigen_output");
    Object input = cobiGen.read(new File("src/test/resources/testdata/integrationtest/javaSources/ModelCreationTest.java").toPath(), Charset.forName("UTF-8"), getClass().getClassLoader());
    List<TemplateTo> templates = cobiGen.getMatchingTemplates(input);
    boolean methodTemplateFound = false;
    for (TemplateTo template : templates) {
        if (template.getId().equals("genericTypes.txt")) {
            GenerationReportTo report = cobiGen.generate(input, template, Paths.get(tmpFolderCobiGen.getAbsolutePath()), false);
            assertThat(report).isSuccessful();
            File expectedFile = new File(tmpFolderCobiGen.getAbsoluteFile() + SystemUtils.FILE_SEPARATOR + "genericTypes.txt");
            assertThat(expectedFile).exists();
            assertThat(expectedFile).hasContent("List<String> testField");
            methodTemplateFound = true;
            break;
        }
    }
    if (!methodTemplateFound) {
        throw new AssertionFailedError("Test template not found");
    }
}
Also used : 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) Test(org.junit.Test) AbstractIntegrationTest(com.devonfw.cobigen.javaplugin.integrationtest.common.AbstractIntegrationTest)

Example 22 with GenerationReportTo

use of com.devonfw.cobigen.api.to.GenerationReportTo in project cobigen by devonfw.

the class ModelCreationTest method testCorrectAnnotationValueExtraction.

/**
 * Tests that annotation string values for methods are not quoted. See issue #251
 *
 * @throws Exception test fails
 */
@Test
public void testCorrectAnnotationValueExtraction() throws Exception {
    CobiGen cobiGen = CobiGenFactory.create(this.cobigenConfigFolder.toURI());
    File tmpFolderCobiGen = this.tmpFolder.newFolder("cobigen_output");
    Object input = cobiGen.read(new File("src/test/resources/testdata/integrationtest/javaSources/ModelCreationTest.java").toPath(), StandardCharsets.UTF_8, getClass().getClassLoader());
    List<TemplateTo> templates = cobiGen.getMatchingTemplates(input);
    boolean methodTemplateFound = false;
    for (TemplateTo template : templates) {
        if (template.getId().equals("correctAnnotationValueExtraction.txt")) {
            GenerationReportTo report = cobiGen.generate(input, template, Paths.get(tmpFolderCobiGen.getAbsolutePath()), false);
            assertThat(report).isSuccessful();
            Path expectedFile = tmpFolderCobiGen.toPath().resolve("correctAnnotationValueExtraction.txt");
            assertThat(expectedFile).exists();
            assertThat(expectedFile).hasContent("\"/foo/{id}/\"");
            methodTemplateFound = true;
            break;
        }
    }
    if (!methodTemplateFound) {
        throw new AssertionFailedError("Test template not found");
    }
}
Also used : Path(java.nio.file.Path) 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) Test(org.junit.Test) AbstractIntegrationTest(com.devonfw.cobigen.javaplugin.integrationtest.common.AbstractIntegrationTest)

Example 23 with GenerationReportTo

use of com.devonfw.cobigen.api.to.GenerationReportTo in project cobigen by devonfw.

the class OpenAPIMatcherTest method testXRootPackageVariableAssigned.

/**
 * Test if the generation is successful and without warnings, if a requested variable is assigned
 */
@Test
public void testXRootPackageVariableAssigned() {
    ComponentDef componentDef = new ComponentDef();
    componentDef.setName("Tablemanagement");
    componentDef.setUserProperty("x-rootpackage", "com.devonfw");
    OpenAPIMatcher matcher = new OpenAPIMatcher();
    GenerationReportTo report = new GenerationReportTo();
    List<VariableAssignmentTo> va = new ArrayList<>();
    va.add(new VariableAssignmentTo("extension", "rootPackage", "x-rootpackage", false));
    matcher.resolveVariables(new MatcherTo("element", "ComponentDef", componentDef), va, report);
    assertThat(report.getWarnings().size()).isEqualTo(0);
}
Also used : ComponentDef(com.devonfw.cobigen.openapiplugin.model.ComponentDef) VariableAssignmentTo(com.devonfw.cobigen.api.to.VariableAssignmentTo) GenerationReportTo(com.devonfw.cobigen.api.to.GenerationReportTo) OpenAPIMatcher(com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher) ArrayList(java.util.ArrayList) MatcherTo(com.devonfw.cobigen.api.to.MatcherTo) Test(org.junit.Test)

Example 24 with GenerationReportTo

use of com.devonfw.cobigen.api.to.GenerationReportTo in project cobigen by devonfw.

the class OpenAPIMatcherTest method testMissingXRootPackageVariableMandatory.

/**
 * Test if the generation isn't successful and the report contains errors, if a mandatory variable isn't given
 */
@Test
public void testMissingXRootPackageVariableMandatory() {
    ComponentDef componentDef = new ComponentDef();
    componentDef.setName("Tablemanagement");
    OpenAPIMatcher matcher = new OpenAPIMatcher();
    GenerationReportTo report = new GenerationReportTo();
    List<VariableAssignmentTo> vaMandatoryXRootPackage = new ArrayList<>();
    vaMandatoryXRootPackage.add(new VariableAssignmentTo("extension", "rootPackage", "x-rootpackage", true));
    matcher.resolveVariables(new MatcherTo("element", "ComponentDef", componentDef), vaMandatoryXRootPackage, report);
    assertThat(report.getErrors().get(0).getMessage()).containsSequence(Constants.getMandatoryMessage(true, "x-rootpackage"));
}
Also used : ComponentDef(com.devonfw.cobigen.openapiplugin.model.ComponentDef) VariableAssignmentTo(com.devonfw.cobigen.api.to.VariableAssignmentTo) GenerationReportTo(com.devonfw.cobigen.api.to.GenerationReportTo) OpenAPIMatcher(com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher) ArrayList(java.util.ArrayList) MatcherTo(com.devonfw.cobigen.api.to.MatcherTo) Test(org.junit.Test)

Example 25 with GenerationReportTo

use of com.devonfw.cobigen.api.to.GenerationReportTo in project cobigen by devonfw.

the class VelocityTemplateEngineIntegrationTest method testBasicGeneration.

/**
 * Tests a basic generation integrated with cobigen-core
 *
 * @throws Exception test fails
 */
@Test
public void testBasicGeneration() throws Exception {
    CobiGen cobigen = CobiGenFactory.create(new File("src/test/resources/systemtest").toURI());
    Object input = cobigen.read(new File("src/test/java/com/devonfw/cobigen/tempeng/velocity/systemtest/testobjects/Input.java").toPath(), Charset.forName("UTF-8"), getClass().getClassLoader());
    List<IncrementTo> increments = cobigen.getMatchingIncrements(input);
    assertThat(increments).hasSize(1);
    assertThat(increments.get(0).getTemplates()).hasSize(1);
    File targetFolder = this.tempFolderRule.newFolder("cobigen-");
    GenerationReportTo report = cobigen.generate(Input.class, increments.get(0), targetFolder.toPath());
    assertThat(report).isSuccessful();
    assertThat(targetFolder.toPath().resolve("velocityTest.txt")).exists().hasContent("String,int,");
}
Also used : IncrementTo(com.devonfw.cobigen.api.to.IncrementTo) GenerationReportTo(com.devonfw.cobigen.api.to.GenerationReportTo) CobiGen(com.devonfw.cobigen.api.CobiGen) File(java.io.File) Test(org.junit.Test)

Aggregations

GenerationReportTo (com.devonfw.cobigen.api.to.GenerationReportTo)33 CobiGen (com.devonfw.cobigen.api.CobiGen)27 Test (org.junit.Test)26 File (java.io.File)25 TemplateTo (com.devonfw.cobigen.api.to.TemplateTo)24 AbstractApiTest (com.devonfw.cobigen.systemtest.common.AbstractApiTest)9 Path (java.nio.file.Path)9 AssertionFailedError (junit.framework.AssertionFailedError)8 List (java.util.List)7 TriggerInterpreter (com.devonfw.cobigen.api.extension.TriggerInterpreter)5 MatcherTo (com.devonfw.cobigen.api.to.MatcherTo)5 Paths (java.nio.file.Paths)5 GenerationReportToAssert (com.devonfw.cobigen.api.assertj.GenerationReportToAssert)4 CobiGenRuntimeException (com.devonfw.cobigen.api.exception.CobiGenRuntimeException)4 IncrementTo (com.devonfw.cobigen.api.to.IncrementTo)4 AbstractIntegrationTest (com.devonfw.cobigen.javaplugin.integrationtest.common.AbstractIntegrationTest)4 Charset (java.nio.charset.Charset)4 CobiGenAsserts.assertThat (com.devonfw.cobigen.api.assertj.CobiGenAsserts.assertThat)3 PluginNotAvailableException (com.devonfw.cobigen.api.exception.PluginNotAvailableException)3 GeneratorPluginActivator (com.devonfw.cobigen.api.extension.GeneratorPluginActivator)3