use of com.devonfw.cobigen.impl.config.entity.Trigger in project cobigen by devonfw.
the class TemplatesConfigurationReaderTest method testIncrementRefOutsideCurrentFile.
/**
* Tests the correct resolution of incrementsRef from outside the current templates file. (Issue #678)
*/
@Test
public void testIncrementRefOutsideCurrentFile() {
// given
Trigger trigger = new Trigger("testingTrigger", "asdf", "valid_external_incrementref", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
Path config = Paths.get(new File(testFileRootPath).toURI());
ConfigurationHolder configurationHolder = new ConfigurationHolder(config.toUri());
TemplatesConfiguration templatesConfiguration = configurationHolder.readTemplatesConfiguration(trigger);
Map<String, Increment> increments = templatesConfiguration.getIncrements();
// validation
assertThat(templatesConfiguration.getTrigger().getId()).isEqualTo("testingTrigger");
assertThat(increments).containsOnlyKeys("3", "4", "5");
Increment incrementThree = increments.get("3").getDependentIncrements().get(0);
assertThat(incrementThree.getName()).isEqualTo("0");
assertThat(incrementThree.getTemplates().size()).isEqualTo(1);
Increment incrementFour = increments.get("4").getDependentIncrements().get(0);
assertThat(incrementFour.getName()).isEqualTo("1");
assertThat(incrementFour.getTemplates().size()).isEqualTo(4);
Increment incrementFive = increments.get("5").getDependentIncrements().get(0);
assertThat(incrementFive.getName()).isEqualTo("2");
assertThat(incrementFive.getTemplates().size()).isEqualTo(4);
}
use of com.devonfw.cobigen.impl.config.entity.Trigger in project cobigen by devonfw.
the class TemplatesConfigurationReaderTest method testTemplateScanDoesNotOverwriteExplicitTemplateDeclarations.
/**
* Tests that the template-scan mechanism does not overwrite an explicit template declaration with the defaults
*
* @throws Exception test fails
*/
@Test
public void testTemplateScanDoesNotOverwriteExplicitTemplateDeclarations() throws Exception {
// given
TemplatesConfigurationReader target = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "valid");
Trigger trigger = new Trigger("", "asdf", "", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
// when
Map<String, Template> templates = target.loadTemplates(trigger);
// this one is a predefined template and shall not be overwritten by scan...
String templateIdFoo2Class = "prefix_Foo2Class.java";
Template templateFoo2Class = templates.get(templateIdFoo2Class);
assertThat(templateFoo2Class).isNotNull();
assertThat(templateFoo2Class.getName()).isEqualTo(templateIdFoo2Class);
assertThat(templateFoo2Class.getRelativeTemplatePath()).isEqualTo("foo/Foo2Class.java.ftl");
assertThat(templateFoo2Class.getUnresolvedTargetPath()).isEqualTo("src/main/java/foo/Foo2Class${variable}.java");
assertThat(templateFoo2Class.getMergeStrategy()).isEqualTo("javamerge");
String templateIdBarClass = "prefix_BarClass.java";
Template templateBarClass = templates.get(templateIdBarClass);
assertThat(templateBarClass).isNotNull();
assertThat(templateBarClass.getName()).isEqualTo(templateIdBarClass);
assertThat(templateBarClass.getRelativeTemplatePath()).isEqualTo("foo/bar/BarClass.java.ftl");
assertThat(templateBarClass.getUnresolvedTargetPath()).isEqualTo("src/main/java/foo/bar/BarClass.java");
assertThat(templateBarClass.getMergeStrategy()).isNull();
}
use of com.devonfw.cobigen.impl.config.entity.Trigger in project cobigen by devonfw.
the class TemplatesConfigurationReaderTest method testEmptyTemplateExtensionDeclarationDoesNotOverrideAnyDefaults.
/**
* Tests an empty templateExtensions does not override any defaults
*
* @throws Exception test fails
*/
@Test
public void testEmptyTemplateExtensionDeclarationDoesNotOverrideAnyDefaults() throws Exception {
// given
TemplatesConfigurationReader target = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "valid");
Trigger trigger = new Trigger("", "asdf", "", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
// when
Map<String, Template> templates = target.loadTemplates(trigger);
// validation
String templateIdFooClass = "prefix2_Foo2Class.java";
Template templateFooClass = templates.get(templateIdFooClass);
assertThat(templateFooClass).isNotNull();
// template-scan defaults
assertThat(templateFooClass.getName()).isEqualTo(templateIdFooClass);
assertThat(templateFooClass.getRelativeTemplatePath()).isEqualTo("bar/Foo2Class.java.ftl");
assertThat(templateFooClass.getUnresolvedTargetPath()).isEqualTo("src/main/java/bar/Foo2Class.java");
assertThat(templateFooClass.getMergeStrategy()).isNull();
assertThat(templateFooClass.getTargetCharset()).isEqualTo("UTF-8");
}
use of com.devonfw.cobigen.impl.config.entity.Trigger in project cobigen by devonfw.
the class TemplatesConfigurationReaderTest method testTemplatesOfAPackageRetrieval.
/**
* Tests whether all templates of a template package could be retrieved successfully.
*
* @throws Exception test fails
*/
@Test
public void testTemplatesOfAPackageRetrieval() throws Exception {
TemplatesConfigurationReader target = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "valid");
Trigger trigger = new Trigger("", "asdf", "", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
Template templateMock = mock(Template.class);
HashMap<String, Template> templates = new HashMap<>();
templates.put("resources_resources_spring_common", templateMock);
target.loadIncrements(templates, trigger);
}
use of com.devonfw.cobigen.impl.config.entity.Trigger in project cobigen by devonfw.
the class TemplatesConfigurationReaderTest method testCorrectResolutionOfTemplateScanReferences.
/**
* Tests the correct resolution of template scan references in increments.
*
* @throws InvalidConfigurationException test fails
*/
@Test
public void testCorrectResolutionOfTemplateScanReferences() throws InvalidConfigurationException {
// given
TemplatesConfigurationReader reader = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "valid_template_scan_references");
Trigger trigger = new Trigger("", "asdf", "", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
// when
Map<String, Template> templates = reader.loadTemplates(trigger);
Map<String, Increment> increments = reader.loadIncrements(templates, trigger);
// validation
assertThat(templates).containsOnlyKeys("prefix_foo_BarClass.java", "prefix_bar_Foo2Class.java", "prefix_foo_FooClass.java");
assertThat(increments).containsOnlyKeys("test");
assertThat(increments.get("test").getTemplates()).extracting("name").containsOnly("prefix_foo_BarClass.java", "prefix_foo_FooClass.java");
}
Aggregations