use of com.devonfw.cobigen.impl.config.ConfigurationHolder in project cobigen by devonfw.
the class TemplatesConfigurationReaderTest method testTemplateRefOutsideCurrentFile.
/**
* Tests the correct resolution of TemplateRef from outside the current templates file.
*/
@Test
public void testTemplateRefOutsideCurrentFile() {
// given
Trigger trigger = new Trigger("testingTrigger", "asdf", "valid_external_templateref", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
Path configPath = Paths.get(new File(testFileRootPath).toURI());
ConfigurationHolder configurationHolder = new ConfigurationHolder(configPath.toUri());
TemplatesConfiguration templatesConfiguration = configurationHolder.readTemplatesConfiguration(trigger);
Map<String, Increment> increments = templatesConfiguration.getIncrements();
assertThat(templatesConfiguration.getTrigger().getId()).isEqualTo("testingTrigger");
// validation
Increment incrementThree = increments.get("3");
LinkedList<String> templateNamesThree = new LinkedList<>();
for (Template tmplate : incrementThree.getTemplates()) {
templateNamesThree.add(tmplate.getName());
}
assertThat(templateNamesThree).containsExactly("templateDecl");
Increment incrementFour = increments.get("4");
LinkedList<String> templateNamesFour = new LinkedList<>();
for (Template tmplate : incrementFour.getTemplates()) {
templateNamesFour.add(tmplate.getName());
}
assertThat(templateNamesFour).containsExactly("ExplicitlyDefined");
}
use of com.devonfw.cobigen.impl.config.ConfigurationHolder 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);
}
use of com.devonfw.cobigen.impl.config.ConfigurationHolder 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);
}
use of com.devonfw.cobigen.impl.config.ConfigurationHolder in project cobigen by devonfw.
the class TemplateClassTest method testResolveUtilClassesFromJarArchive.
/**
* Tests if the template utility classes can be loaded from a jar archive
*
* @throws IOException test fails
*/
@Test
public void testResolveUtilClassesFromJarArchive() throws IOException {
String filename = "archive";
Path path = Paths.get(TEST_FILES_ROOT_PATH + filename + File.separator + "templates.jar");
ClassLoader inputClassLoader = URLClassLoader.newInstance(new URL[] { path.toUri().toURL() }, getClass().getClassLoader());
List<Class<?>> classes = ConfigurationClassLoaderUtil.resolveUtilClasses(new ConfigurationHolder(path.toUri()), inputClassLoader);
assertThat(classes).isNotEmpty();
assertThat(classes.get(0).getName()).contains("IDGenerator");
}
use of com.devonfw.cobigen.impl.config.ConfigurationHolder in project cobigen by devonfw.
the class CobiGenFactory method create.
/**
* Creates a new {@link CobiGen} while searching a valid configuration at the given path
*
* @param configFileOrFolder the root folder containing the context.xml and all templates, configurations etc.
* @return a new instance of {@link CobiGen}
* @throws InvalidConfigurationException if the context configuration could not be read properly.
*/
public static CobiGen create(URI configFileOrFolder) throws InvalidConfigurationException {
Objects.requireNonNull(configFileOrFolder, "The URI pointing to the configuration could not be null.");
ConfigurationHolder configurationHolder = new ConfigurationHolder(configFileOrFolder);
BeanFactory beanFactory = new BeanFactory();
beanFactory.addManuallyInitializedBean(configurationHolder);
CobiGen createBean = beanFactory.createBean(CobiGen.class);
// Notifies all plugins of new template root path
PluginRegistry.notifyPlugins(configurationHolder.getConfigurationPath());
return createBean;
}
Aggregations