use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class TriggerActivationTest method testNoActivation_1OR_0AND_MatcherMatches.
/**
* Tests that a trigger will not be activated in case of one OR matcher but no AND matcher matches.
*
* @throws Exception test fails
* @author mbrunnli (22.02.2015)
*/
@Test
@SuppressWarnings("unchecked")
public void testNoActivation_1OR_0AND_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(false);
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 testNoActivation_1Of2AND_MatcherMatches.
/**
* Tests that a trigger will not be activated in case of one of two AND Matchers matches.
*
* @throws Exception test fails
* @author mbrunnli (22.02.2015)
*/
@Test
@SuppressWarnings("unchecked")
public void testNoActivation_1Of2AND_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(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, not(hasItem("triggerId")));
}
use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class ContainerMatcherTest method testContainerMatcherDoesNotMatchWithoutMatcher.
/**
* Tests whether a container matcher will not match iff there are no other matchers
*
* @throws Exception test fails
*/
@Test
public void testContainerMatcherDoesNotMatchWithoutMatcher() throws Exception {
// Mocking
Object containerInput = createTestDataAndConfigureMock(false);
// Execution
File templatesFolder = new File(testFileRootPath + "templates");
CobiGen target = CobiGenFactory.create(templatesFolder.toURI());
List<String> matchingTriggerIds = target.getMatchingTriggerIds(containerInput);
// Verification
Assert.assertNotNull(matchingTriggerIds);
Assert.assertEquals(0, matchingTriggerIds.size());
}
use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class ContainerMatcherTest method testContainerMatcherMatches.
/**
* Tests whether a container matcher will match iff there are matchers matching the child resources
*
* @throws Exception test fails
*/
@Test
public void testContainerMatcherMatches() throws Exception {
// Mocking
Object containerInput = createTestDataAndConfigureMock(true);
// Execution
File templatesFolder = new File(testFileRootPath + "templates");
CobiGen target = CobiGenFactory.create(templatesFolder.toURI());
List<String> matchingTriggerIds = target.getMatchingTriggerIds(containerInput);
// Verification
Assert.assertNotNull(matchingTriggerIds);
Assert.assertTrue(matchingTriggerIds.size() > 0);
}
use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class ContainerMatcherTest method testMultipleTriggerWithContainerMatchers.
/**
* Tests whether multiple triggers will be activated if their container matcher matches a given input. <br/>
* <a href="https://github.com/devonfw/cobigen/issues/57">(Bug #57)</a>
*
* @throws Exception test fails
*/
@Test
public void testMultipleTriggerWithContainerMatchers() throws Exception {
// Mocking
Object containerInput = createTestDataAndConfigureMock(true, false);
// pre-processing
File templatesFolder = new File(testFileRootPath + "templates");
CobiGen target = CobiGenFactory.create(templatesFolder.toURI());
// Execution
List<String> triggerIds = target.getMatchingTriggerIds(containerInput);
// Verification
Assert.assertNotNull(triggerIds);
Assert.assertEquals(2, triggerIds.size());
}
Aggregations