use of com.devonfw.cobigen.impl.config.entity.Matcher 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.Matcher 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.Matcher 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.Matcher 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