Search in sources :

Example 11 with InputReader

use of com.devonfw.cobigen.api.extension.InputReader 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"));
}
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 12 with InputReader

use of com.devonfw.cobigen.api.extension.InputReader 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 13 with InputReader

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

the class TypeScriptInputReaderTest method testValidInput.

/**
 * Sends a fileEto containing only the path of the file that needs to be parsed. Checks whether it is a valid input.
 *
 * @test fails
 */
@Test
public void testValidInput() {
    // arrange
    InputReader tsInputReader = this.activator.bindTriggerInterpreter().stream().map(e -> e.getInputReader()).findFirst().get();
    File baseFile = new File(testFileRootPath + "baseFile.ts");
    boolean isValidInput = tsInputReader.isValidInput(baseFile);
    assertTrue(isValidInput);
}
Also used : InputReader(com.devonfw.cobigen.api.extension.InputReader) File(java.io.File) Test(org.junit.Test)

Example 14 with InputReader

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

the class TypeScriptInputReaderTest method testGetInputObjects.

/**
 * Testing the extraction of the first class or interface.
 *
 * @test fails
 */
@Test
public void testGetInputObjects() {
    // arrange
    InputReader tsInputReader = this.activator.bindTriggerInterpreter().stream().map(e -> e.getInputReader()).findFirst().get();
    File baseFile = new File(testFileRootPath + "baseFile.ts");
    List<Object> tsInputObjects = tsInputReader.getInputObjects(baseFile, Charset.defaultCharset());
    LinkedHashMap<String, Object> inputObject = castToHashMap(tsInputObjects.get(0));
    assertNotNull(inputObject);
    assertEquals(inputObject.get("identifier"), "a");
    assertNotNull(inputObject.get("methods"));
    LOG.debug(inputObject.toString());
}
Also used : InputReader(com.devonfw.cobigen.api.extension.InputReader) File(java.io.File) Test(org.junit.Test)

Example 15 with InputReader

use of com.devonfw.cobigen.api.extension.InputReader 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)

Aggregations

InputReader (com.devonfw.cobigen.api.extension.InputReader)22 File (java.io.File)17 Test (org.junit.Test)16 TriggerInterpreter (com.devonfw.cobigen.api.extension.TriggerInterpreter)14 GeneratorPluginActivator (com.devonfw.cobigen.api.extension.GeneratorPluginActivator)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 VariableAssignmentToMatcher (com.devonfw.cobigen.api.matchers.VariableAssignmentToMatcher)3 GenerationReportTo (com.devonfw.cobigen.api.to.GenerationReportTo)3 MatcherTo (com.devonfw.cobigen.api.to.MatcherTo)3 Charset (java.nio.charset.Charset)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 TemplateTo (com.devonfw.cobigen.api.to.TemplateTo)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Cached (com.devonfw.cobigen.api.annotation.Cached)1