use of com.devonfw.cobigen.api.to.MatcherTo in project cobigen by devonfw.
the class InputResolverImpl method resolveContainerElements.
@Cached
@Override
public List<Object> resolveContainerElements(Object input, Trigger trigger) {
List<Object> inputObjects = new ArrayList<>();
if (this.inputInterpreter.combinesMultipleInputs(input)) {
TriggerInterpreter triggerInterpreter = PluginRegistry.getTriggerInterpreter(trigger.getType());
InputReader inputReader = triggerInterpreter.getInputReader();
// check whether the inputs should be retrieved recursively
boolean retrieveInputsRecursively = false;
for (ContainerMatcher containerMatcher : trigger.getContainerMatchers()) {
MatcherTo matcherTo = new MatcherTo(containerMatcher.getType(), containerMatcher.getValue(), input);
if (triggerInterpreter.getMatcher().matches(matcherTo)) {
if (!retrieveInputsRecursively) {
retrieveInputsRecursively = containerMatcher.isRetrieveObjectsRecursively();
} else {
break;
}
}
}
if (retrieveInputsRecursively) {
inputObjects = inputReader.getInputObjectsRecursively(input, trigger.getInputCharset());
} else {
inputObjects = inputReader.getInputObjects(input, trigger.getInputCharset());
}
// Remove non matching inputs
Iterator<Object> it = inputObjects.iterator();
while (it.hasNext()) {
Object next = it.next();
if (!this.matcherEvaluator.matches(next, trigger.getMatcher(), triggerInterpreter)) {
it.remove();
}
}
} else {
inputObjects.add(input);
}
return inputObjects;
}
use of com.devonfw.cobigen.api.to.MatcherTo in project cobigen by devonfw.
the class OpenAPIMatcherTest method testInvalidComponentDefMatching.
/**
* Test non valid {@link ComponentDef} matching
*/
@Test
public void testInvalidComponentDefMatching() {
ComponentDef componentDef = new ComponentDef();
componentDef.setName("Tablemanagement");
OpenAPIMatcher matcher = new OpenAPIMatcher();
boolean matches = matcher.matches(new MatcherTo("element", "ComponentDefs", componentDef));
assertThat(matches).isFalse();
}
use of com.devonfw.cobigen.api.to.MatcherTo in project cobigen by devonfw.
the class OpenAPIMatcherTest method testMissingXRootPackageVariableNotMandatory.
/**
* Test if the generation is successful and the report contains warnings, if a requested but not mandatory variable
* isn't given.
*/
@Test
public void testMissingXRootPackageVariableNotMandatory() {
ComponentDef componentDef = new ComponentDef();
componentDef.setName("Tablemanagement");
OpenAPIMatcher matcher = new OpenAPIMatcher();
GenerationReportTo report = new GenerationReportTo();
List<VariableAssignmentTo> vaOptionalXRootPackage = new ArrayList<>();
vaOptionalXRootPackage.add(new VariableAssignmentTo("extension", "rootPackage", "x-rootpackage", false));
matcher.resolveVariables(new MatcherTo("element", "ComponentDef", componentDef), vaOptionalXRootPackage, report);
assertThat(report.getWarnings().get(0)).containsSequence(Constants.getMandatoryMessage(false, "x-rootpackage"));
List<VariableAssignmentTo> vaMandatoryXRootPackage = new ArrayList<>();
vaMandatoryXRootPackage.add(new VariableAssignmentTo("extension", "rootpackage", "x-rootpackage", true));
matcher.resolveVariables(new MatcherTo("element", "ComponentDef", componentDef), vaMandatoryXRootPackage, report);
assertThat(report.getErrors().get(0).getMessage()).containsSequence(Constants.getMandatoryMessage(true, "x-rootpackage"));
}
use of com.devonfw.cobigen.api.to.MatcherTo in project cobigen by devonfw.
the class OpenAPIMatcherTest method testValidEntityDefMatching.
/**
* Test valid {@link EntityDef} matching
*/
@Test
public void testValidEntityDefMatching() {
EntityDef entityDef = new EntityDef();
entityDef.setComponentName("Tablemanagement");
OpenAPIMatcher matcher = new OpenAPIMatcher();
boolean matches = matcher.matches(new MatcherTo("element", "EntityDef", entityDef));
assertThat(matches).isTrue();
}
use of com.devonfw.cobigen.api.to.MatcherTo in project cobigen by devonfw.
the class OpenAPIMatcherTest method testValidComponentDefMatching.
/**
* Test valid {@link ComponentDef} matching
*/
@Test
public void testValidComponentDefMatching() {
ComponentDef componentDef = new ComponentDef();
componentDef.setName("Tablemanagement");
OpenAPIMatcher matcher = new OpenAPIMatcher();
boolean matches = matcher.matches(new MatcherTo("element", "ComponentDef", componentDef));
assertThat(matches).isTrue();
}
Aggregations