Search in sources :

Example 16 with ContainerMatcher

use of com.devonfw.cobigen.impl.config.entity.ContainerMatcher 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();
}
Also used : Trigger(com.devonfw.cobigen.impl.config.entity.Trigger) ContainerMatcher(com.devonfw.cobigen.impl.config.entity.ContainerMatcher) Matcher(com.devonfw.cobigen.impl.config.entity.Matcher) ContainerMatcher(com.devonfw.cobigen.impl.config.entity.ContainerMatcher) TemplatesConfigurationReader(com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader) File(java.io.File) Template(com.devonfw.cobigen.impl.config.entity.Template) AbstractUnitTest(com.devonfw.cobigen.unittest.config.common.AbstractUnitTest) Test(org.junit.Test)

Example 17 with ContainerMatcher

use of com.devonfw.cobigen.impl.config.entity.ContainerMatcher 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");
}
Also used : Trigger(com.devonfw.cobigen.impl.config.entity.Trigger) ContainerMatcher(com.devonfw.cobigen.impl.config.entity.ContainerMatcher) Matcher(com.devonfw.cobigen.impl.config.entity.Matcher) ContainerMatcher(com.devonfw.cobigen.impl.config.entity.ContainerMatcher) TemplatesConfigurationReader(com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader) File(java.io.File) Template(com.devonfw.cobigen.impl.config.entity.Template) AbstractUnitTest(com.devonfw.cobigen.unittest.config.common.AbstractUnitTest) Test(org.junit.Test)

Example 18 with ContainerMatcher

use of com.devonfw.cobigen.impl.config.entity.ContainerMatcher 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);
}
Also used : Trigger(com.devonfw.cobigen.impl.config.entity.Trigger) ContainerMatcher(com.devonfw.cobigen.impl.config.entity.ContainerMatcher) Matcher(com.devonfw.cobigen.impl.config.entity.Matcher) ContainerMatcher(com.devonfw.cobigen.impl.config.entity.ContainerMatcher) HashMap(java.util.HashMap) TemplatesConfigurationReader(com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader) File(java.io.File) Template(com.devonfw.cobigen.impl.config.entity.Template) AbstractUnitTest(com.devonfw.cobigen.unittest.config.common.AbstractUnitTest) Test(org.junit.Test)

Example 19 with ContainerMatcher

use of com.devonfw.cobigen.impl.config.entity.ContainerMatcher 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");
}
Also used : Trigger(com.devonfw.cobigen.impl.config.entity.Trigger) ContainerMatcher(com.devonfw.cobigen.impl.config.entity.ContainerMatcher) Matcher(com.devonfw.cobigen.impl.config.entity.Matcher) ContainerMatcher(com.devonfw.cobigen.impl.config.entity.ContainerMatcher) Increment(com.devonfw.cobigen.impl.config.entity.Increment) TemplatesConfigurationReader(com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader) File(java.io.File) Template(com.devonfw.cobigen.impl.config.entity.Template) AbstractUnitTest(com.devonfw.cobigen.unittest.config.common.AbstractUnitTest) Test(org.junit.Test)

Aggregations

ContainerMatcher (com.devonfw.cobigen.impl.config.entity.ContainerMatcher)19 Trigger (com.devonfw.cobigen.impl.config.entity.Trigger)18 Matcher (com.devonfw.cobigen.impl.config.entity.Matcher)17 AbstractUnitTest (com.devonfw.cobigen.unittest.config.common.AbstractUnitTest)17 File (java.io.File)17 Test (org.junit.Test)17 Template (com.devonfw.cobigen.impl.config.entity.Template)16 TemplatesConfigurationReader (com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader)15 ConfigurationHolder (com.devonfw.cobigen.impl.config.ConfigurationHolder)4 Increment (com.devonfw.cobigen.impl.config.entity.Increment)4 Path (java.nio.file.Path)4 Cached (com.devonfw.cobigen.api.annotation.Cached)2 TriggerInterpreter (com.devonfw.cobigen.api.extension.TriggerInterpreter)2 MatcherTo (com.devonfw.cobigen.api.to.MatcherTo)2 TemplatesConfiguration (com.devonfw.cobigen.impl.config.TemplatesConfiguration)2 ContextConfigurationReader (com.devonfw.cobigen.impl.config.reader.ContextConfigurationReader)2 InputReader (com.devonfw.cobigen.api.extension.InputReader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1