use of com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader in project cobigen by devonfw.
the class TemplatesConfigurationReaderTest method testErrorOnDuplicateTemplateScanNames.
/**
* Tests the correct detection of duplicate template scan names.
*
* @throws InvalidConfigurationException expected
*/
@Test(expected = InvalidConfigurationException.class)
public void testErrorOnDuplicateTemplateScanNames() throws InvalidConfigurationException {
TemplatesConfigurationReader reader = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "faulty_duplicate_template_scan_name");
reader.loadTemplates(null);
}
use of com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader in project cobigen by devonfw.
the class TemplatesConfigurationReaderTest method testInvalidTemplateRefOutsideCurrentFile.
/**
* Tests the correct detection of invalid external increment reference.
*
* @throws InvalidConfigurationException expected
*/
@Test(expected = InvalidConfigurationException.class)
public void testInvalidTemplateRefOutsideCurrentFile() {
Path config = Paths.get(new File(testFileRootPath).toURI());
new ContextConfigurationReader(config);
// given
ConfigurationHolder configurationHolder = new ConfigurationHolder(config.toUri());
TemplatesConfigurationReader target = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "faulty_invalid_external_templateref", configurationHolder);
Trigger trigger = new Trigger("", "asdf", "", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
// when
Map<String, Template> templates = target.loadTemplates(trigger);
target.loadIncrements(templates, trigger);
}
use of com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader in project cobigen by devonfw.
the class TemplatesConfigurationReaderTest method testTemplatesSourceFolder.
@Test
public void testTemplatesSourceFolder() {
// given
TemplatesConfigurationReader target = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "valid_source_folder");
Trigger trigger = new Trigger("", "asdf", "", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
// when
Map<String, Template> templates = target.loadTemplates(trigger);
// then
assertThat(templates).isNotNull().hasSize(6);
String templateIdFooClass = "prefix_FooClass.java";
Template templateFooClass = templates.get(templateIdFooClass);
assertThat(templateFooClass).isNotNull();
assertThat(templateFooClass.getName()).isEqualTo(templateIdFooClass);
assertThat(templateFooClass.getRelativeTemplatePath()).isEqualTo("foo/FooClass.java.ftl");
assertThat(templateFooClass.getUnresolvedTargetPath()).isEqualTo("src/main/java/foo/FooClass.java");
assertThat(templateFooClass.getMergeStrategy()).isNull();
}
use of com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader in project cobigen by devonfw.
the class TemplatesConfigurationReaderTest method testRelocate_withTemplateFilenameEnding.
/**
* Test relocate while the template is defined with the template file ending, which should be removed on destination
* path resolution.
*/
@Test
public void testRelocate_withTemplateFilenameEnding() {
// given
String templatesConfigurationRoot = testFileRootPath + "valid_relocate_template_fileending/";
TemplatesConfigurationReader target = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "valid_relocate_template_fileending/");
Trigger trigger = new Trigger("id", "type", "valid_relocate", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
// when
Map<String, Template> templates = target.loadTemplates(trigger);
// validation
assertThat(templates).hasSize(1);
String staticRelocationPrefix = "../server/";
String templateName = "$_Component_$Impl.java";
Template template = templates.get(templateName);
assertThat(template).isNotNull();
String pathWithName = "$_rootpackage_$/$_component_$/logic/impl/" + templateName;
assertThat(template.getRelativeTemplatePath()).isEqualTo("templates/" + pathWithName + ".ftl");
assertThat(template.getAbsoluteTemplatePath().toString().replace('\\', '/')).isEqualTo(templatesConfigurationRoot + "templates/" + pathWithName + ".ftl");
assertThat(template.getUnresolvedTemplatePath()).isEqualTo("src/main/java/" + pathWithName);
assertThat(template.getUnresolvedTargetPath()).isEqualTo(staticRelocationPrefix + pathWithName);
}
use of com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader in project cobigen by devonfw.
the class TemplatesConfigurationReaderTest method testRelocate_propertiesResolution.
/**
* Tests the correct property inheritance and resolution of cobigen.properties within a template set read by a
* template scan.
*/
@Test
public void testRelocate_propertiesResolution() {
// arrange
TemplatesConfigurationReader target = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "valid_relocate_propertiesresolution/");
Trigger trigger = new Trigger("id", "type", "valid_relocate", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
// act
Map<String, Template> templates = target.loadTemplates(trigger);
assertThat(templates).hasSize(2);
// assert
Template template = templates.get("$_Component_$.java");
assertThat(template).isNotNull();
assertThat(template.getVariables().asMap()).isNotNull().containsEntry("foo", "root").containsEntry("bar", "barValue");
template = templates.get("$_EntityName_$Eto.java");
assertThat(template).isNotNull();
assertThat(template.getVariables().asMap()).isNotNull().containsEntry("relocate", "../api2/${cwd}").containsEntry("foo", "logic.api.to").containsEntry("bar", "barValue").containsEntry("local", "localValue");
}
Aggregations