use of com.devonfw.cobigen.api.CobiGen 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");
}
}
use of com.devonfw.cobigen.api.CobiGen 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");
}
}
use of com.devonfw.cobigen.api.CobiGen 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,");
}
use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class InputReaderMatcherTest method testBasicElementMatcher_twoComponents_matchRegex.
/**
* Tests the correct basic retrieval of ComponentDef inputs
*
* @throws Exception test fails
*/
@Test
public void testBasicElementMatcher_twoComponents_matchRegex() throws Exception {
CobiGen cobigen = CobiGenFactory.create(Paths.get(testdataRoot, "templates-regex").toUri());
Object openApiFile = cobigen.read(Paths.get(testdataRoot, "two-components.yaml"), TestConstants.UTF_8);
assertThat(openApiFile).isNotNull();
List<TemplateTo> matchingTemplates = cobigen.getMatchingTemplates(openApiFile);
assertThat(matchingTemplates).extracting(TemplateTo::getId).containsExactly("sales_template.txt", "table_template.txt");
}
use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class InputReaderMatcherTest method testVariableAssignment_rootComponent.
/**
* Tests variable assignment resolution of ROOTPACKAGE type, thus that the user can define the root package in the
* "info" part of the OpenAPI file
*
* @throws Exception test fails
*/
@Test
public void testVariableAssignment_rootComponent() throws Exception {
CobiGen cobigen = CobiGenFactory.create(Paths.get(testdataRoot, "templates").toUri());
Object openApiFile = cobigen.read(Paths.get(testdataRoot, "root-package.yaml"), TestConstants.UTF_8);
// Previous version: List<Object> inputObjects = cobigen.getInputObjects(openApiFile,
// TestConstants.UTF_8);
List<Object> inputObjects = cobigen.resolveContainers(openApiFile);
String templateName = "testModel_rootComponentProperty.txt";
TemplateTo template = findTemplate(cobigen, inputObjects.get(0), templateName);
File targetFolder = this.tmpFolder.newFolder();
GenerationReportTo report = cobigen.generate(inputObjects.get(0), template, targetFolder.toPath());
assertThat(report).isSuccessful();
assertThat(targetFolder.toPath().resolve(templateName).toFile()).exists().hasContent("tablemanagement");
}
Aggregations