use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class ContainerMatcherTest method testContextVariableResolvingOnGeneration.
/**
* Tests whether variable resolving works for a contains's children during generation
*
* @throws Exception test fails
*/
@Test
public void testContextVariableResolvingOnGeneration() throws Exception {
// Mocking
Object containerInput = createTestDataAndConfigureMock(true);
File generationRootFolder = this.tmpFolder.newFolder("generationRootFolder");
// pre-processing
File templatesFolder = new File(testFileRootPath + "templates");
CobiGen target = CobiGenFactory.create(templatesFolder.toURI());
List<TemplateTo> templates = target.getMatchingTemplates(containerInput);
// Execution
GenerationReportTo report = target.generate(containerInput, templates.get(0), Paths.get(generationRootFolder.toURI()), false);
// assertion
assertThat(report).isSuccessful();
}
use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class ContainerMatcherTest method testContainerChildrenWillIndividuallyBeMatched.
/**
* Create a new {@link ContainerMatcher}, which contains two children which do not match the same trigger.
*
* @throws Exception test fails
*/
@Test
@SuppressWarnings("unchecked")
public void testContainerChildrenWillIndividuallyBeMatched() throws Exception {
Object container = new Object() {
@Override
public String toString() {
return "container";
}
};
Object child1 = new Object() {
@Override
public String toString() {
return "child1";
}
};
Object child2 = new Object() {
@Override
public String toString() {
return "child2";
}
};
// 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);
// Simulate container children resolution of any plug-in
when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(child1))), anyList(), any())).thenReturn(ImmutableMap.<String, String>builder().put("variable", "child1").build());
when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(child2))), anyList(), any())).thenReturn(ImmutableMap.<String, String>builder().put("variable", "child2").build());
when(inputReader.getInputObjects(any(), any(Charset.class))).thenReturn(Lists.newArrayList(child1, child2));
// match container
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("container"), ANY, sameInstance(container))))).thenReturn(true);
// do not match first child
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(child1))))).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(child1))))).thenReturn(true);
// match second child
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(child2))))).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(child2))))).thenReturn(false);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
// create CobiGen instance
File templatesFolder = new File(testFileRootPath + "selectiveContainerGeneration");
CobiGen target = CobiGenFactory.create(templatesFolder.toURI());
File folder = this.tmpFolder.newFolder();
// Execution
GenerationReportTo report = target.generate(container, target.getMatchingTemplates(container), Paths.get(folder.toURI()), false);
assertThat(report).isSuccessful();
// Verification
assertNotNull(folder.list());
assertEquals(1, folder.list().length);
assertEquals("child2.txt", folder.list()[0]);
}
use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class ContainerMatcherTest method testContextVariableResolving.
/**
* Tests whether variable resolving works for a container's children as the container itself does not include any
* variable resolving
*
* @throws Exception test fails
*/
@Test
public void testContextVariableResolving() throws Exception {
// Mocking
Object containerInput = createTestDataAndConfigureMock(true);
// Execution
File templatesFolder = new File(testFileRootPath + "templates");
CobiGen target = CobiGenFactory.create(templatesFolder.toURI());
List<TemplateTo> matchingTemplates = target.getMatchingTemplates(containerInput);
// Verification
Assert.assertNotNull(matchingTemplates);
}
use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class ContainerMatcherTest method testGetAllIncrements.
/**
* Tests whether the increments can be correctly retrieved for container matchers
*
* @throws Exception test fails
*/
@Test
public void testGetAllIncrements() throws Exception {
// Mocking
Object containerInput = createTestDataAndConfigureMock(true, true);
// pre-processing
File templatesFolder = new File(testFileRootPath + "templates");
CobiGen target = CobiGenFactory.create(templatesFolder.toURI());
// Execution
List<IncrementTo> increments = target.getMatchingIncrements(containerInput);
// Verification
Assert.assertNotNull(increments);
Assert.assertTrue(increments.size() > 0);
}
use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class ContainerMatcherTest method testMultipleTriggerWithDifferentContainerMatchersAccumulationType.
/**
* Tests whether a single trigger will be activated if two triggers with different container matchers (different
* accumulationTypes) were provided <br/>
* <a href="https://github.com/devonfw/cobigen/issues/1299">(Bug #1299)</a>
*
* @throws Exception test fails
*/
@Test
public void testMultipleTriggerWithDifferentContainerMatchersAccumulationType() throws Exception {
// Mocking
Object containerInput = createTestDataAndConfigureMock(true, false);
// pre-processing
File templatesFolder = new File(testFileRootPath + "accumulationType");
CobiGen target = CobiGenFactory.create(templatesFolder.toURI());
// Execution
List<String> triggerIds = target.getMatchingTriggerIds(containerInput);
// Verification
Assert.assertNotNull(triggerIds);
Assert.assertEquals(1, triggerIds.size());
}
Aggregations