use of com.devonfw.cobigen.api.to.TemplateTo in project cobigen by devonfw.
the class TemplateScanTest method testCorrectDestinationResoution_emptyPathElements.
/**
* Tests the correct destination resolution for resources obtained by template-scans in the case of multiple empty
* path elements
*
* @throws Exception test fails
*/
@Test
public void testCorrectDestinationResoution_emptyPathElements() throws Exception {
Object input = PluginMockFactory.createSimpleJavaConfigurationMock();
File generationRootFolder = this.tmpFolder.newFolder("generationRootFolder");
// Useful to see generates if necessary, comment the generationRootFolder above then
// File generationRootFolder = new File(testFileRootPath + "generates");
// pre-processing
File templatesFolder = new File(testFileRootPath);
CobiGen target = CobiGenFactory.create(templatesFolder.toURI());
List<TemplateTo> templates = target.getMatchingTemplates(input);
assertThat(templates).isNotNull();
TemplateTo targetTemplate = getTemplateById(templates, "prefix_MultiEmpty.java");
assertThat(targetTemplate).isNotNull();
// Execution
GenerationReportTo report = target.generate(input, targetTemplate, Paths.get(generationRootFolder.toURI()), false);
assertThat(report).isSuccessful();
// Validation
assertThat(new File(generationRootFolder.getAbsolutePath() + SystemUtils.FILE_SEPARATOR + "src" + SystemUtils.FILE_SEPARATOR + "main" + SystemUtils.FILE_SEPARATOR + "java" + SystemUtils.FILE_SEPARATOR + "base" + SystemUtils.FILE_SEPARATOR + "MultiEmpty.java")).exists();
}
use of com.devonfw.cobigen.api.to.TemplateTo in project cobigen by devonfw.
the class TemplateScanTest method testScanTemplatesFromArchivFile.
/**
* Test template scan within an archive file.
*
* @throws Exception test fails
*/
@Test
public void testScanTemplatesFromArchivFile() throws Exception {
// pre-processing: mocking
Object input = PluginMockFactory.createSimpleJavaConfigurationMock();
// test processing
CobiGen cobigen = CobiGenFactory.create(new File(testFileRootPath + "valid.zip").toURI());
List<TemplateTo> templates = cobigen.getMatchingTemplates(input);
// checking
assertThat(templates, notNullValue());
assertThat(templates.size(), equalTo(6));
}
use of com.devonfw.cobigen.api.to.TemplateTo in project cobigen by devonfw.
the class InputReaderMatcherTest method testBasicElementMatcher_oneComponent_matchRegex.
/**
* Tests the correct basic retrieval of ComponentDef inputs
*
* @throws Exception test fails
*/
@Test
public void testBasicElementMatcher_oneComponent_matchRegex() throws Exception {
CobiGen cobigen = CobiGenFactory.create(Paths.get(testdataRoot, "templates-regex").toUri());
Object openApiFile = cobigen.read(Paths.get(testdataRoot, "one-component.yaml"), TestConstants.UTF_8);
assertThat(openApiFile).isNotNull();
List<Object> resolveContainers = cobigen.resolveContainers(openApiFile);
assertThat(resolveContainers).hasSize(1).first().isInstanceOf(EntityDef.class).extracting(e -> ((EntityDef) e).getName()).containsExactly("Table");
List<TemplateTo> matchingTemplates = resolveContainers.stream().flatMap(e -> cobigen.getMatchingTemplates(e).stream()).collect(Collectors.toList());
assertThat(matchingTemplates).extracting(TemplateTo::getId).containsExactly("table_template.txt");
}
use of com.devonfw.cobigen.api.to.TemplateTo in project cobigen by devonfw.
the class InputReaderMatcherTest method testVariableAssignment_attribute.
/**
* Tests variable assignment resolution of ATTRIBUTE type, thus that the user can define any custom variables inside
* the schema of OpenAPI files. <br>
* <br>
* The input test file contains one attribute per entity. We are testing here that both attributes are correctly
* generated
*
* @throws Exception test fails
*/
@Test
public void testVariableAssignment_attribute() throws Exception {
CobiGen cobigen = CobiGenFactory.create(Paths.get(testdataRoot, "templates").toUri());
Object openApiFile = cobigen.read(Paths.get(testdataRoot, "two-components.yaml"), TestConstants.UTF_8);
// Previous version: List<Object> inputObjects = cobigen.getInputObjects(openApiFile,
// TestConstants.UTF_8);
List<Object> inputObjects = cobigen.resolveContainers(openApiFile);
String templateName = "testVariableAssignment_attribute.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("testVariableAssignment_attribute.txt").toFile()).exists().hasContent("testingAttributeTableiChangeGlobalVariable");
template = findTemplate(cobigen, inputObjects.get(1), templateName);
targetFolder = this.tmpFolder.newFolder();
report = cobigen.generate(inputObjects.get(1), template, targetFolder.toPath());
assertThat(report).isSuccessful();
assertThat(targetFolder.toPath().resolve("testVariableAssignment_attribute.txt").toFile()).exists().hasContent("testingAttributeSalesitIsGlobal");
}
use of com.devonfw.cobigen.api.to.TemplateTo in project cobigen by devonfw.
the class InputReaderMatcherTest method testVariableAssignment_rootPackage.
/**
* 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_rootPackage() 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 = "testVariableAssignment_rootPackage.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("testVariableAssignment_rootPackage.txt").toFile()).exists().hasContent("testingRootName");
}
Aggregations