Search in sources :

Example 1 with TemplatesConfigurationReader

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

Example 2 with TemplatesConfigurationReader

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

Example 3 with TemplatesConfigurationReader

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();
}
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 4 with TemplatesConfigurationReader

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);
}
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 5 with TemplatesConfigurationReader

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");
}
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)

Aggregations

TemplatesConfigurationReader (com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader)20 AbstractUnitTest (com.devonfw.cobigen.unittest.config.common.AbstractUnitTest)20 File (java.io.File)20 Test (org.junit.Test)20 ContainerMatcher (com.devonfw.cobigen.impl.config.entity.ContainerMatcher)15 Matcher (com.devonfw.cobigen.impl.config.entity.Matcher)15 Template (com.devonfw.cobigen.impl.config.entity.Template)15 Trigger (com.devonfw.cobigen.impl.config.entity.Trigger)15 ConfigurationHolder (com.devonfw.cobigen.impl.config.ConfigurationHolder)2 Increment (com.devonfw.cobigen.impl.config.entity.Increment)2 ContextConfigurationReader (com.devonfw.cobigen.impl.config.reader.ContextConfigurationReader)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)1