Search in sources :

Example 16 with TemplatesConfigurationReader

use of com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader in project cobigen by devonfw.

the class TemplatesConfigurationReaderTest method testErrorOnUnhookedTemplateExtensionDeclaration.

/**
 * Tests whether a template extension with an id-reference, which does not point on any template, will cause an
 * {@link InvalidConfigurationException}
 *
 * @throws InvalidConfigurationException expected
 */
@Test(expected = InvalidConfigurationException.class)
public void testErrorOnUnhookedTemplateExtensionDeclaration() throws InvalidConfigurationException {
    TemplatesConfigurationReader reader = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "faulty_unhooked_template_extension");
    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 17 with TemplatesConfigurationReader

use of com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader in project cobigen by devonfw.

the class TemplatesConfigurationReaderTest method testErrorOnDuplicateTemplateExtensionDeclaration.

/**
 * Tests whether a duplicate template extension declaration will result in an {@link InvalidConfigurationException}
 *
 * @throws InvalidConfigurationException expected
 */
@Test(expected = InvalidConfigurationException.class)
public void testErrorOnDuplicateTemplateExtensionDeclaration() throws InvalidConfigurationException {
    TemplatesConfigurationReader reader = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "faulty_duplicate_template_extension");
    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 18 with TemplatesConfigurationReader

use of com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader in project cobigen by devonfw.

the class TemplatesConfigurationReaderTest method testErrorOnInvalidTemplateScanReference.

/**
 * Tests the correct detection of invalid template scan references.
 *
 * @throws InvalidConfigurationException expected
 */
@Test(expected = InvalidConfigurationException.class)
public void testErrorOnInvalidTemplateScanReference() throws InvalidConfigurationException {
    TemplatesConfigurationReader reader = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "faulty_invalid_template_scan_ref");
    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 19 with TemplatesConfigurationReader

use of com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader 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 20 with TemplatesConfigurationReader

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

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