Search in sources :

Example 6 with GeneratorPluginActivator

use of com.devonfw.cobigen.api.extension.GeneratorPluginActivator in project cobigen by devonfw.

the class TriggerActivationTest method testNoActivation_1OR_1NOT_MatcherMatches.

/**
 * Tests that a trigger will not be activated in case of one OR matcher and one NOT matcher matches.
 *
 * @throws Exception test fails
 * @author mbrunnli (22.02.2015)
 */
@Test
@SuppressWarnings("unchecked")
public void testNoActivation_1OR_1NOT_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(true);
    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")));
}
Also used : TriggerInterpreter(com.devonfw.cobigen.api.extension.TriggerInterpreter) MatcherToMatcher(com.devonfw.cobigen.api.matchers.MatcherToMatcher) InputReader(com.devonfw.cobigen.api.extension.InputReader) MatcherInterpreter(com.devonfw.cobigen.api.extension.MatcherInterpreter) CobiGen(com.devonfw.cobigen.api.CobiGen) File(java.io.File) GeneratorPluginActivator(com.devonfw.cobigen.api.extension.GeneratorPluginActivator) Test(org.junit.Test) AbstractApiTest(com.devonfw.cobigen.systemtest.common.AbstractApiTest)

Example 7 with GeneratorPluginActivator

use of com.devonfw.cobigen.api.extension.GeneratorPluginActivator in project cobigen by devonfw.

the class TriggerActivationTest method testNoActivation_2Of2AND_1NOT_MatcherMatches.

/**
 * Tests that a trigger will not be activated in case of two of two AND matchers and one NOT matcher matches.
 *
 * @throws Exception test fails
 * @author mbrunnli (22.02.2015)
 */
@Test
@SuppressWarnings("unchecked")
public void testNoActivation_2Of2AND_1NOT_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(true);
    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")));
}
Also used : TriggerInterpreter(com.devonfw.cobigen.api.extension.TriggerInterpreter) MatcherToMatcher(com.devonfw.cobigen.api.matchers.MatcherToMatcher) InputReader(com.devonfw.cobigen.api.extension.InputReader) MatcherInterpreter(com.devonfw.cobigen.api.extension.MatcherInterpreter) CobiGen(com.devonfw.cobigen.api.CobiGen) File(java.io.File) GeneratorPluginActivator(com.devonfw.cobigen.api.extension.GeneratorPluginActivator) Test(org.junit.Test) AbstractApiTest(com.devonfw.cobigen.systemtest.common.AbstractApiTest)

Example 8 with GeneratorPluginActivator

use of com.devonfw.cobigen.api.extension.GeneratorPluginActivator in project cobigen by devonfw.

the class TriggerActivationTest method testActivation_1OR_MatcherMatches.

/**
 * Tests that a trigger will be activated in case of one OR matcher matches.
 *
 * @throws Exception test fails
 * @author mbrunnli (22.02.2015)
 */
@Test
@SuppressWarnings("unchecked")
public void testActivation_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("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, hasItem("triggerId2"));
}
Also used : TriggerInterpreter(com.devonfw.cobigen.api.extension.TriggerInterpreter) MatcherToMatcher(com.devonfw.cobigen.api.matchers.MatcherToMatcher) InputReader(com.devonfw.cobigen.api.extension.InputReader) MatcherInterpreter(com.devonfw.cobigen.api.extension.MatcherInterpreter) CobiGen(com.devonfw.cobigen.api.CobiGen) File(java.io.File) GeneratorPluginActivator(com.devonfw.cobigen.api.extension.GeneratorPluginActivator) Test(org.junit.Test) AbstractApiTest(com.devonfw.cobigen.systemtest.common.AbstractApiTest)

Example 9 with GeneratorPluginActivator

use of com.devonfw.cobigen.api.extension.GeneratorPluginActivator 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")));
}
Also used : TriggerInterpreter(com.devonfw.cobigen.api.extension.TriggerInterpreter) MatcherToMatcher(com.devonfw.cobigen.api.matchers.MatcherToMatcher) InputReader(com.devonfw.cobigen.api.extension.InputReader) MatcherInterpreter(com.devonfw.cobigen.api.extension.MatcherInterpreter) CobiGen(com.devonfw.cobigen.api.CobiGen) File(java.io.File) GeneratorPluginActivator(com.devonfw.cobigen.api.extension.GeneratorPluginActivator) Test(org.junit.Test) AbstractApiTest(com.devonfw.cobigen.systemtest.common.AbstractApiTest)

Example 10 with GeneratorPluginActivator

use of com.devonfw.cobigen.api.extension.GeneratorPluginActivator 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")));
}
Also used : TriggerInterpreter(com.devonfw.cobigen.api.extension.TriggerInterpreter) MatcherToMatcher(com.devonfw.cobigen.api.matchers.MatcherToMatcher) InputReader(com.devonfw.cobigen.api.extension.InputReader) MatcherInterpreter(com.devonfw.cobigen.api.extension.MatcherInterpreter) CobiGen(com.devonfw.cobigen.api.CobiGen) File(java.io.File) GeneratorPluginActivator(com.devonfw.cobigen.api.extension.GeneratorPluginActivator) Test(org.junit.Test) AbstractApiTest(com.devonfw.cobigen.systemtest.common.AbstractApiTest)

Aggregations

GeneratorPluginActivator (com.devonfw.cobigen.api.extension.GeneratorPluginActivator)15 TriggerInterpreter (com.devonfw.cobigen.api.extension.TriggerInterpreter)15 InputReader (com.devonfw.cobigen.api.extension.InputReader)13 MatcherInterpreter (com.devonfw.cobigen.api.extension.MatcherInterpreter)13 MatcherToMatcher (com.devonfw.cobigen.api.matchers.MatcherToMatcher)13 CobiGen (com.devonfw.cobigen.api.CobiGen)10 AbstractApiTest (com.devonfw.cobigen.systemtest.common.AbstractApiTest)10 File (java.io.File)10 Test (org.junit.Test)10 HashMap (java.util.HashMap)4 VariableAssignmentToMatcher (com.devonfw.cobigen.api.matchers.VariableAssignmentToMatcher)3 GenerationReportTo (com.devonfw.cobigen.api.to.GenerationReportTo)3 Charset (java.nio.charset.Charset)3 List (java.util.List)3 CobiGenRuntimeException (com.devonfw.cobigen.api.exception.CobiGenRuntimeException)2 Merger (com.devonfw.cobigen.api.extension.Merger)2 MatcherTo (com.devonfw.cobigen.api.to.MatcherTo)2 TemplateTo (com.devonfw.cobigen.api.to.TemplateTo)2 Path (java.nio.file.Path)2 Activation (com.devonfw.cobigen.api.annotation.Activation)1