use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class TemplateScanTest method testCorrectDestinationResoution_emptyPathElements.
/**
* Tests the correct destination resolution for resources obtained by template-scans in the case of multiple empty
* path elements
*
* @throws Exception test fails
*/
@Test
public void testCorrectDestinationResoution_emptyPathElements() throws Exception {
Object input = PluginMockFactory.createSimpleJavaConfigurationMock();
File generationRootFolder = this.tmpFolder.newFolder("generationRootFolder");
// Useful to see generates if necessary, comment the generationRootFolder above then
// File generationRootFolder = new File(testFileRootPath + "generates");
// pre-processing
File templatesFolder = new File(testFileRootPath);
CobiGen target = CobiGenFactory.create(templatesFolder.toURI());
List<TemplateTo> templates = target.getMatchingTemplates(input);
assertThat(templates).isNotNull();
TemplateTo targetTemplate = getTemplateById(templates, "prefix_MultiEmpty.java");
assertThat(targetTemplate).isNotNull();
// Execution
GenerationReportTo report = target.generate(input, targetTemplate, Paths.get(generationRootFolder.toURI()), false);
assertThat(report).isSuccessful();
// Validation
assertThat(new File(generationRootFolder.getAbsolutePath() + SystemUtils.FILE_SEPARATOR + "src" + SystemUtils.FILE_SEPARATOR + "main" + SystemUtils.FILE_SEPARATOR + "java" + SystemUtils.FILE_SEPARATOR + "base" + SystemUtils.FILE_SEPARATOR + "MultiEmpty.java")).exists();
}
use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class TemplateScanTest method testScanTemplatesFromArchivFile.
/**
* Test template scan within an archive file.
*
* @throws Exception test fails
*/
@Test
public void testScanTemplatesFromArchivFile() throws Exception {
// pre-processing: mocking
Object input = PluginMockFactory.createSimpleJavaConfigurationMock();
// test processing
CobiGen cobigen = CobiGenFactory.create(new File(testFileRootPath + "valid.zip").toURI());
List<TemplateTo> templates = cobigen.getMatchingTemplates(input);
// checking
assertThat(templates, notNullValue());
assertThat(templates.size(), equalTo(6));
}
use of com.devonfw.cobigen.api.CobiGen 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;
}
use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class TriggerActivationTest method testNoActivation_1Of2AND_1OR_MatcherMatches.
/**
* Tests that a trigger will not be activated in case of one of two AND Matchers and one OR matcher matches.
*
* @throws Exception test fails
* @author mbrunnli (22.02.2015)
*/
@Test
@SuppressWarnings("unchecked")
public void testNoActivation_1Of2AND_1OR_MatcherMatches() throws Exception {
Object input = new Object();
// Pre-processing: Mocking
GeneratorPluginActivator activator = mock(GeneratorPluginActivator.class);
TriggerInterpreter triggerInterpreter = mock(TriggerInterpreter.class);
MatcherInterpreter matcher = mock(MatcherInterpreter.class);
InputReader inputReader = mock(InputReader.class);
when(triggerInterpreter.getType()).thenReturn("test");
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
when(inputReader.isValidInput(any())).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and1"), ANY, sameInstance(input))))).thenReturn(false);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and2"), ANY, sameInstance(input))))).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(input))))).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(input))))).thenReturn(false);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
// execution
CobiGen cobigen = CobiGenFactory.create(new File(testFileRootPath + "templates").toURI());
List<String> matchingTriggerIds = cobigen.getMatchingTriggerIds(input);
assertThat(matchingTriggerIds, not(hasItem("triggerId")));
}
use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class TriggerActivationTest method testActivation_2Of2AND_MatcherMatches.
/**
* Tests that a trigger will be activated in case of two of two AND Matchers matches.
*
* @throws Exception test fails
* @author mbrunnli (22.02.2015)
*/
@Test
@SuppressWarnings("unchecked")
public void testActivation_2Of2AND_MatcherMatches() throws Exception {
Object input = new Object();
// Pre-processing: Mocking
GeneratorPluginActivator activator = mock(GeneratorPluginActivator.class);
TriggerInterpreter triggerInterpreter = mock(TriggerInterpreter.class);
MatcherInterpreter matcher = mock(MatcherInterpreter.class);
InputReader inputReader = mock(InputReader.class);
when(triggerInterpreter.getType()).thenReturn("test");
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
when(inputReader.isValidInput(any())).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and1"), ANY, sameInstance(input))))).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and2"), ANY, sameInstance(input))))).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(input))))).thenReturn(false);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(input))))).thenReturn(false);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
// execution
CobiGen cobigen = CobiGenFactory.create(new File(testFileRootPath + "templates").toURI());
List<String> matchingTriggerIds = cobigen.getMatchingTriggerIds(input);
assertThat(matchingTriggerIds, hasItem("triggerId"));
}
Aggregations