use of com.devonfw.cobigen.api.CobiGen 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.CobiGen in project cobigen by devonfw.
the class InputReaderMatcherTest method testBasicElementMatcher_oneComponent_matchRegex.
/**
* Tests the correct basic retrieval of ComponentDef inputs
*
* @throws Exception test fails
*/
@Test
public void testBasicElementMatcher_oneComponent_matchRegex() throws Exception {
CobiGen cobigen = CobiGenFactory.create(Paths.get(testdataRoot, "templates-regex").toUri());
Object openApiFile = cobigen.read(Paths.get(testdataRoot, "one-component.yaml"), TestConstants.UTF_8);
assertThat(openApiFile).isNotNull();
List<Object> resolveContainers = cobigen.resolveContainers(openApiFile);
assertThat(resolveContainers).hasSize(1).first().isInstanceOf(EntityDef.class).extracting(e -> ((EntityDef) e).getName()).containsExactly("Table");
List<TemplateTo> matchingTemplates = resolveContainers.stream().flatMap(e -> cobigen.getMatchingTemplates(e).stream()).collect(Collectors.toList());
assertThat(matchingTemplates).extracting(TemplateTo::getId).containsExactly("table_template.txt");
}
use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class InputReaderMatcherTest method testVariableAssignment_attribute.
/**
* Tests variable assignment resolution of ATTRIBUTE type, thus that the user can define any custom variables inside
* the schema of OpenAPI files. <br>
* <br>
* The input test file contains one attribute per entity. We are testing here that both attributes are correctly
* generated
*
* @throws Exception test fails
*/
@Test
public void testVariableAssignment_attribute() throws Exception {
CobiGen cobigen = CobiGenFactory.create(Paths.get(testdataRoot, "templates").toUri());
Object openApiFile = cobigen.read(Paths.get(testdataRoot, "two-components.yaml"), TestConstants.UTF_8);
// Previous version: List<Object> inputObjects = cobigen.getInputObjects(openApiFile,
// TestConstants.UTF_8);
List<Object> inputObjects = cobigen.resolveContainers(openApiFile);
String templateName = "testVariableAssignment_attribute.txt";
TemplateTo template = findTemplate(cobigen, inputObjects.get(0), templateName);
File targetFolder = this.tmpFolder.newFolder();
GenerationReportTo report = cobigen.generate(inputObjects.get(0), template, targetFolder.toPath());
assertThat(report).isSuccessful();
assertThat(targetFolder.toPath().resolve("testVariableAssignment_attribute.txt").toFile()).exists().hasContent("testingAttributeTableiChangeGlobalVariable");
template = findTemplate(cobigen, inputObjects.get(1), templateName);
targetFolder = this.tmpFolder.newFolder();
report = cobigen.generate(inputObjects.get(1), template, targetFolder.toPath());
assertThat(report).isSuccessful();
assertThat(targetFolder.toPath().resolve("testVariableAssignment_attribute.txt").toFile()).exists().hasContent("testingAttributeSalesitIsGlobal");
}
use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class InputReaderMatcherTest method testBasicElementMatcher_oneComponent.
/**
* Tests the correct basic retrieval of ComponentDef inputs
*
* @throws Exception test fails
*/
@Test
public void testBasicElementMatcher_oneComponent() throws Exception {
CobiGen cobigen = CobiGenFactory.create(Paths.get(testdataRoot, "templates").toUri());
Object openApiFile = cobigen.read(Paths.get(testdataRoot, "one-component.yaml"), TestConstants.UTF_8);
assertThat(openApiFile).isNotNull();
List<Object> inputObjects = cobigen.resolveContainers(openApiFile);
assertThat(inputObjects).isNotNull().hasSize(1);
}
use of com.devonfw.cobigen.api.CobiGen in project cobigen by devonfw.
the class InputReaderMatcherTest method testVariableAssignment_rootPackage.
/**
* Tests variable assignment resolution of ROOTPACKAGE type, thus that the user can define the root package in the
* "info" part of the OpenAPI file
*
* @throws Exception test fails
*/
@Test
public void testVariableAssignment_rootPackage() throws Exception {
CobiGen cobigen = CobiGenFactory.create(Paths.get(testdataRoot, "templates").toUri());
Object openApiFile = cobigen.read(Paths.get(testdataRoot, "root-package.yaml"), TestConstants.UTF_8);
// Previous version: List<Object> inputObjects = cobigen.getInputObjects(openApiFile,
// TestConstants.UTF_8);
List<Object> inputObjects = cobigen.resolveContainers(openApiFile);
String templateName = "testVariableAssignment_rootPackage.txt";
TemplateTo template = findTemplate(cobigen, inputObjects.get(0), templateName);
File targetFolder = this.tmpFolder.newFolder();
GenerationReportTo report = cobigen.generate(inputObjects.get(0), template, targetFolder.toPath());
assertThat(report).isSuccessful();
assertThat(targetFolder.toPath().resolve("testVariableAssignment_rootPackage.txt").toFile()).exists().hasContent("testingRootName");
}
Aggregations