Search in sources :

Example 46 with CobiGen

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")));
}
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 47 with CobiGen

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")));
}
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 48 with CobiGen

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());
}
Also used : CobiGen(com.devonfw.cobigen.api.CobiGen) File(java.io.File) AbstractApiTest(com.devonfw.cobigen.systemtest.common.AbstractApiTest) Test(org.junit.Test)

Example 49 with CobiGen

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);
}
Also used : CobiGen(com.devonfw.cobigen.api.CobiGen) File(java.io.File) AbstractApiTest(com.devonfw.cobigen.systemtest.common.AbstractApiTest) Test(org.junit.Test)

Example 50 with CobiGen

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());
}
Also used : CobiGen(com.devonfw.cobigen.api.CobiGen) File(java.io.File) AbstractApiTest(com.devonfw.cobigen.systemtest.common.AbstractApiTest) Test(org.junit.Test)

Aggregations

CobiGen (com.devonfw.cobigen.api.CobiGen)55 File (java.io.File)45 Test (org.junit.Test)45 TemplateTo (com.devonfw.cobigen.api.to.TemplateTo)31 GenerationReportTo (com.devonfw.cobigen.api.to.GenerationReportTo)28 AbstractApiTest (com.devonfw.cobigen.systemtest.common.AbstractApiTest)26 GeneratorPluginActivator (com.devonfw.cobigen.api.extension.GeneratorPluginActivator)10 InputReader (com.devonfw.cobigen.api.extension.InputReader)10 MatcherInterpreter (com.devonfw.cobigen.api.extension.MatcherInterpreter)10 TriggerInterpreter (com.devonfw.cobigen.api.extension.TriggerInterpreter)10 MatcherToMatcher (com.devonfw.cobigen.api.matchers.MatcherToMatcher)10 List (java.util.List)10 Path (java.nio.file.Path)9 AssertionFailedError (junit.framework.AssertionFailedError)9 IncrementTo (com.devonfw.cobigen.api.to.IncrementTo)7 Paths (java.nio.file.Paths)7 CobiGenFactory (com.devonfw.cobigen.impl.CobiGenFactory)5 AbstractIntegrationTest (com.devonfw.cobigen.javaplugin.integrationtest.common.AbstractIntegrationTest)5 Collectors (java.util.stream.Collectors)5 CobiGenAsserts.assertThat (com.devonfw.cobigen.api.assertj.CobiGenAsserts.assertThat)4