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"));
}
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")));
}
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);
}
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());
}
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")));
}
Aggregations