Search in sources :

Example 1 with ContextConfigurationReader

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

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

the class ContextConfigurationReaderTest method testOldConfiguration.

/**
 * Tests that exactly one v2.1 context configuration is read
 *
 * Backward Compatibility test, remove when monolithic context.xml is deprecated.
 */
@Test
public void testOldConfiguration() {
    ContextConfigurationReader context = new ContextConfigurationReader(Paths.get(testFileRootPath + "valid_source_folder"));
    assertThat(context.getContextFiles().size()).isEqualTo(1);
}
Also used : ContextConfigurationReader(com.devonfw.cobigen.impl.config.reader.ContextConfigurationReader) Test(org.junit.Test) AbstractUnitTest(com.devonfw.cobigen.unittest.config.common.AbstractUnitTest)

Example 3 with ContextConfigurationReader

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

the class TemplatesConfigurationReaderTest method testInvalidIncrementRefOutsideCurrentFile.

/**
 * Tests the correct detection of invalid external increment reference.
 *
 * @throws InvalidConfigurationException expected
 */
@Test(expected = InvalidConfigurationException.class)
public void testInvalidIncrementRefOutsideCurrentFile() {
    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_incrementref", 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 4 with ContextConfigurationReader

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

the class ContextConfiguration method readConfiguration.

/**
 * Reads the configuration from the given path
 *
 * @param configRoot CobiGen configuration root path
 * @throws InvalidConfigurationException thrown if the {@link File} is not valid with respect to the context.xsd
 */
private void readConfiguration(Path configRoot) throws InvalidConfigurationException {
    ContextConfigurationReader reader = new ContextConfigurationReader(configRoot);
    this.configurationPath = reader.getContextRoot();
    this.triggers = reader.loadTriggers();
}
Also used : ContextConfigurationReader(com.devonfw.cobigen.impl.config.reader.ContextConfigurationReader)

Example 5 with ContextConfigurationReader

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

the class ContextConfigurationReaderTest method testNewConfiguration.

/**
 * Tests if multiple (2) templates are found with v2.2 context configuration
 */
@Test
public void testNewConfiguration() {
    ContextConfigurationReader context = new ContextConfigurationReader(Paths.get(testFileRootPath + "valid_new"));
    assertThat(context.getContextFiles().size()).isEqualTo(2);
}
Also used : ContextConfigurationReader(com.devonfw.cobigen.impl.config.reader.ContextConfigurationReader) Test(org.junit.Test) AbstractUnitTest(com.devonfw.cobigen.unittest.config.common.AbstractUnitTest)

Aggregations

ContextConfigurationReader (com.devonfw.cobigen.impl.config.reader.ContextConfigurationReader)5 AbstractUnitTest (com.devonfw.cobigen.unittest.config.common.AbstractUnitTest)4 Test (org.junit.Test)4 ConfigurationHolder (com.devonfw.cobigen.impl.config.ConfigurationHolder)2 ContainerMatcher (com.devonfw.cobigen.impl.config.entity.ContainerMatcher)2 Matcher (com.devonfw.cobigen.impl.config.entity.Matcher)2 Template (com.devonfw.cobigen.impl.config.entity.Template)2 Trigger (com.devonfw.cobigen.impl.config.entity.Trigger)2 TemplatesConfigurationReader (com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader)2 File (java.io.File)2 Path (java.nio.file.Path)2