use of com.devonfw.cobigen.api.to.TemplateTo in project cobigen by devonfw.
the class AnnotationQueryingTest method testAnnotationWithObjectArraysAsValues.
/**
* Tests whether annotations with object array values are correctly accessible within the templates
*
* @throws Exception test fails
*/
@Test
public void testAnnotationWithObjectArraysAsValues() 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/unittest/inputreader/TestClassWithAnnotationsContainingObjectArrays.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("annotationQuerying.txt")) {
GenerationReportTo report = cobiGen.generate(input, template, Paths.get(tmpFolderCobiGen.getAbsolutePath()), false);
File expectedFile = new File(tmpFolderCobiGen.getAbsoluteFile() + SystemUtils.FILE_SEPARATOR + "annotationQuerying.txt");
assertThat(report).isSuccessful();
assertThat(expectedFile).exists();
assertThat(expectedFile).hasContent("TestClassWithAnnotationsContainingObjectArrays.class,TestClassWithAnnotations.class,");
methodTemplateFound = true;
break;
}
}
if (!methodTemplateFound) {
throw new AssertionFailedError("Test template not found");
}
}
use of com.devonfw.cobigen.api.to.TemplateTo in project cobigen by devonfw.
the class VariablesResolutionTest method testSuccessfulPathResolution_variableEqNull.
/**
* Tests that the path resolution is performed successfully in case of including path variables derived from variable
* assignments retrieved by regex groups, which have been resolved to null. This bug has been introduced by changing
* the model building from DOM to Bean model. The latter required to explicitly not to set <code>null</code> as a
* value for variable resolution. Basically, this is odd, but we have to comply with backward compatibility and the
* issue that we cannot encode unary-operators like ?? in a file path sufficiently.
*
* @throws Exception test fails
*/
@Test
public void testSuccessfulPathResolution_variableEqNull() 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/SampleEntity.java").toPath(), Charset.forName("UTF-8"));
List<TemplateTo> templates = cobiGen.getMatchingTemplates(input);
boolean methodTemplateFound = false;
for (TemplateTo template : templates) {
if (template.getId().equals("${variables.entityName}.java")) {
GenerationReportTo report = cobiGen.generate(input, template, Paths.get(tmpFolderCobiGen.getAbsolutePath()), false);
assertThat(report).isSuccessful();
methodTemplateFound = true;
break;
}
}
if (!methodTemplateFound) {
throw new AssertionFailedError("Test template not found");
}
}
use of com.devonfw.cobigen.api.to.TemplateTo in project cobigen by devonfw.
the class CheckStateListener method checkStateChanged.
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
MDC.put(InfrastructureConstants.CORRELATION_ID, UUID.randomUUID().toString());
LOG.info("Increment selection changed. Calculating generation preview file tree...");
try {
CheckboxTreeViewer resourcesTree = this.page.getResourcesTree();
CheckboxTreeViewer incrementSelector = this.page.getPackageSelector();
if (event.getSource().equals(resourcesTree)) {
resourcesTree.setSubtreeChecked(event.getElement(), event.getChecked());
((SelectFileLabelProvider) resourcesTree.getLabelProvider()).setSelectedResources(resourcesTree.getCheckedElements());
refreshNodes(event);
} else if (event.getSource().equals(incrementSelector)) {
performCheckLogic(event, incrementSelector);
Set<Object> checkedElements = new HashSet<>(Arrays.asList(incrementSelector.getCheckedElements()));
performCheckLogicForALLIncrement(incrementSelector, checkedElements);
Map<String, Set<TemplateTo>> paths = this.cobigenWrapper.getTemplateDestinationPaths(this.selectedIncrements);
Set<String> workspaceExternalPaths = Sets.newHashSet();
for (String path : paths.keySet()) {
if (this.cobigenWrapper.isWorkspaceExternalPath(path)) {
workspaceExternalPaths.add(path);
}
}
List<OffWorkspaceResourceTreeNode> offScopeResourceTree = buildOffScopeResourceTree(workspaceExternalPaths);
((SelectFileContentProvider) resourcesTree.getContentProvider()).filter(paths.keySet(), offScopeResourceTree);
this.page.setDisplayedfilePathToTemplateMapping(paths);
resourcesTree.setCheckedElements(new Object[0]);
resourcesTree.refresh();
resourcesTree.expandAll();
if (!this.batch) {
selectNewResources();
selectMergeableResources();
selectOverridingResources();
} else {
selectAllResources(paths.keySet());
}
}
checkPageComplete();
} catch (Throwable e) {
ExceptionHandler.handle(e, null);
}
LOG.info("Calculating of changed preview file tree finished.");
MDC.remove(InfrastructureConstants.CORRELATION_ID);
}
use of com.devonfw.cobigen.api.to.TemplateTo in project cobigen by devonfw.
the class XmlPluginIntegrationTest method testSimpleUmlEntityExtraction.
/**
* Tests simple extraction of entities out of XMI UML.
*
* @throws Exception test fails
*/
@Test
public void testSimpleUmlEntityExtraction() throws Exception {
// arrange
Path configFolder = new File(testFileRootPath + "uml-classdiag").toPath();
File xmlFile = configFolder.resolve("completeUmlXmi.xml").toFile();
CobiGen cobigen = CobiGenFactory.create(configFolder.toUri());
Object doc = cobigen.read(xmlFile.toPath(), UTF_8);
File targetFolder = this.tmpFolder.newFolder("testSimpleUmlEntityExtraction");
// act
List<TemplateTo> matchingTemplates = cobigen.getMatchingTemplates(doc);
List<TemplateTo> templateOfInterest = matchingTemplates.stream().filter(e -> e.getId().equals("${className}.txt")).collect(Collectors.toList());
assertThat(templateOfInterest).hasSize(1);
GenerationReportTo generate = cobigen.generate(doc, templateOfInterest, targetFolder.toPath());
// assert
assertThat(generate).isSuccessful();
File[] files = targetFolder.listFiles();
assertThat(files).extracting(e -> e.getName()).containsExactlyInAnyOrder("Student.txt", "User.txt", "Marks.txt", "Teacher.txt");
assertThat(targetFolder.toPath().resolve("Student.txt")).hasContent("public Student EAID_4509184A_D724_495f_AAEB_1ACE1AD90879");
assertThat(targetFolder.toPath().resolve("User.txt")).hasContent("public User EAID_C2E366C0_510F_4145_B650_110537B98360");
assertThat(targetFolder.toPath().resolve("Marks.txt")).hasContent("public Marks EAID_1D7DCE81_651D_40f2_A6E5_A522CF6E0C64");
assertThat(targetFolder.toPath().resolve("Teacher.txt")).hasContent("public Teacher EAID_6EA6FC61_FB9B_4e8e_98A1_30BD386AEA9A");
}
use of com.devonfw.cobigen.api.to.TemplateTo in project cobigen by devonfw.
the class XPathGenerationTest method testXpathAccess.
/**
* Testing basic Xpath Access
*
* @throws Exception test fails
*/
@Test
public void testXpathAccess() throws Exception {
Path cobigenConfigFolder = new File("src/test/resources/testdata/integrationtest/uml-basic-test").toPath();
Path input = cobigenConfigFolder.resolve("uml.xml");
CobiGen cobigen = CobiGenFactory.create(cobigenConfigFolder.toUri());
Object compliantInput = cobigen.read(input, Charset.forName("UTF-8"));
List<TemplateTo> matchingTemplates = cobigen.getMatchingTemplates(compliantInput);
assertThat(matchingTemplates).isNotNull().hasSize(1);
File targetFolder = this.tmpFolder.newFolder("testXpathAccess");
GenerationReportTo report = cobigen.generate(compliantInput, matchingTemplates.get(0), targetFolder.toPath());
assertThat(report).isSuccessful();
assertThat(targetFolder.toPath().resolve("DocXPath.txt")).hasContent("Bill");
}
Aggregations