Search in sources :

Example 6 with ConfigurationHolder

use of com.devonfw.cobigen.impl.config.ConfigurationHolder in project cobigen by devonfw.

the class TemplatesConfigurationReaderTest method testIncrementRefOutsideCurrentFile.

/**
 * Tests the correct resolution of incrementsRef from outside the current templates file. (Issue #678)
 */
@Test
public void testIncrementRefOutsideCurrentFile() {
    // given
    Trigger trigger = new Trigger("testingTrigger", "asdf", "valid_external_incrementref", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
    Path config = Paths.get(new File(testFileRootPath).toURI());
    ConfigurationHolder configurationHolder = new ConfigurationHolder(config.toUri());
    TemplatesConfiguration templatesConfiguration = configurationHolder.readTemplatesConfiguration(trigger);
    Map<String, Increment> increments = templatesConfiguration.getIncrements();
    // validation
    assertThat(templatesConfiguration.getTrigger().getId()).isEqualTo("testingTrigger");
    assertThat(increments).containsOnlyKeys("3", "4", "5");
    Increment incrementThree = increments.get("3").getDependentIncrements().get(0);
    assertThat(incrementThree.getName()).isEqualTo("0");
    assertThat(incrementThree.getTemplates().size()).isEqualTo(1);
    Increment incrementFour = increments.get("4").getDependentIncrements().get(0);
    assertThat(incrementFour.getName()).isEqualTo("1");
    assertThat(incrementFour.getTemplates().size()).isEqualTo(4);
    Increment incrementFive = increments.get("5").getDependentIncrements().get(0);
    assertThat(incrementFive.getName()).isEqualTo("2");
    assertThat(incrementFive.getTemplates().size()).isEqualTo(4);
}
Also used : Path(java.nio.file.Path) 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) ConfigurationHolder(com.devonfw.cobigen.impl.config.ConfigurationHolder) File(java.io.File) TemplatesConfiguration(com.devonfw.cobigen.impl.config.TemplatesConfiguration) AbstractUnitTest(com.devonfw.cobigen.unittest.config.common.AbstractUnitTest) Test(org.junit.Test)

Example 7 with ConfigurationHolder

use of com.devonfw.cobigen.impl.config.ConfigurationHolder in project cobigen by devonfw.

the class TemplateClassTest method testResolveUtilClassesFromTemplatesFolder.

/**
 * Tests if the template utility classes can be loaded from a configuration folder
 *
 * @throws IOException test fails
 */
@Test
public void testResolveUtilClassesFromTemplatesFolder() throws IOException {
    String filename = "folder";
    Path path = Paths.get(TEST_FILES_ROOT_PATH + filename);
    List<Class<?>> classes = ConfigurationClassLoaderUtil.resolveUtilClasses(new ConfigurationHolder(path.toUri()), null);
    assertThat(classes.get(0).getName()).contains("IDGenerator");
}
Also used : TemplatePath(com.devonfw.cobigen.impl.config.entity.TemplatePath) Path(java.nio.file.Path) ConfigurationHolder(com.devonfw.cobigen.impl.config.ConfigurationHolder) Test(org.junit.Test) AbstractUnitTest(com.devonfw.cobigen.unittest.config.common.AbstractUnitTest)

Example 8 with ConfigurationHolder

use of com.devonfw.cobigen.impl.config.ConfigurationHolder in project cobigen by devonfw.

the class TemplateClassTest method testResolveUtilClassesFromFolderFirst.

/**
 * Tests if the template utility classes get loaded from a folder when both sources are available
 *
 * @throws IOException test fails
 */
@Test
public void testResolveUtilClassesFromFolderFirst() throws IOException {
    Path pathArchive = Paths.get(TEST_FILES_ROOT_PATH + "archive" + File.separator + "templates.jar");
    Path pathFolder = Paths.get(TEST_FILES_ROOT_PATH + "folder");
    ClassLoader inputClassLoader = URLClassLoader.newInstance(new URL[] { pathArchive.toUri().toURL(), pathFolder.toUri().toURL() }, getClass().getClassLoader());
    List<Class<?>> classes = ConfigurationClassLoaderUtil.resolveUtilClasses(new ConfigurationHolder(pathFolder.toUri()), inputClassLoader);
    assertThat(classes.get(0).getName()).contains("IDGenerator");
}
Also used : TemplatePath(com.devonfw.cobigen.impl.config.entity.TemplatePath) Path(java.nio.file.Path) URLClassLoader(java.net.URLClassLoader) ConfigurationHolder(com.devonfw.cobigen.impl.config.ConfigurationHolder) Test(org.junit.Test) AbstractUnitTest(com.devonfw.cobigen.unittest.config.common.AbstractUnitTest)

Aggregations

ConfigurationHolder (com.devonfw.cobigen.impl.config.ConfigurationHolder)8 AbstractUnitTest (com.devonfw.cobigen.unittest.config.common.AbstractUnitTest)7 Path (java.nio.file.Path)7 Test (org.junit.Test)7 ContainerMatcher (com.devonfw.cobigen.impl.config.entity.ContainerMatcher)4 Matcher (com.devonfw.cobigen.impl.config.entity.Matcher)4 Trigger (com.devonfw.cobigen.impl.config.entity.Trigger)4 File (java.io.File)4 Template (com.devonfw.cobigen.impl.config.entity.Template)3 TemplatePath (com.devonfw.cobigen.impl.config.entity.TemplatePath)3 TemplatesConfiguration (com.devonfw.cobigen.impl.config.TemplatesConfiguration)2 Increment (com.devonfw.cobigen.impl.config.entity.Increment)2 ContextConfigurationReader (com.devonfw.cobigen.impl.config.reader.ContextConfigurationReader)2 TemplatesConfigurationReader (com.devonfw.cobigen.impl.config.reader.TemplatesConfigurationReader)2 URLClassLoader (java.net.URLClassLoader)2 CobiGen (com.devonfw.cobigen.api.CobiGen)1 BeanFactory (com.devonfw.cobigen.impl.aop.BeanFactory)1 LinkedList (java.util.LinkedList)1