use of com.devonfw.cobigen.api.to.MatcherTo in project cobigen by devonfw.
the class OpenAPIMatcherTest method testXRootPackageVariableAssigned.
/**
* Test if the generation is successful and without warnings, if a requested variable is assigned
*/
@Test
public void testXRootPackageVariableAssigned() {
ComponentDef componentDef = new ComponentDef();
componentDef.setName("Tablemanagement");
componentDef.setUserProperty("x-rootpackage", "com.devonfw");
OpenAPIMatcher matcher = new OpenAPIMatcher();
GenerationReportTo report = new GenerationReportTo();
List<VariableAssignmentTo> va = new ArrayList<>();
va.add(new VariableAssignmentTo("extension", "rootPackage", "x-rootpackage", false));
matcher.resolveVariables(new MatcherTo("element", "ComponentDef", componentDef), va, report);
assertThat(report.getWarnings().size()).isEqualTo(0);
}
use of com.devonfw.cobigen.api.to.MatcherTo in project cobigen by devonfw.
the class OpenAPIMatcherTest method testInvalidEntityDefMatching.
/**
* Test non valid {@link EntityDef} matching
*/
@Test
public void testInvalidEntityDefMatching() {
EntityDef entityDef = new EntityDef();
entityDef.setComponentName("Tablemanagement");
OpenAPIMatcher matcher = new OpenAPIMatcher();
boolean matches = matcher.matches(new MatcherTo("element", "EntityDefs", entityDef));
assertThat(matches).isFalse();
}
use of com.devonfw.cobigen.api.to.MatcherTo in project cobigen by devonfw.
the class OpenAPIMatcherTest method testMissingXRootPackageVariableMandatory.
/**
* Test if the generation isn't successful and the report contains errors, if a mandatory variable isn't given
*/
@Test
public void testMissingXRootPackageVariableMandatory() {
ComponentDef componentDef = new ComponentDef();
componentDef.setName("Tablemanagement");
OpenAPIMatcher matcher = new OpenAPIMatcher();
GenerationReportTo report = new GenerationReportTo();
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 MatcherToMatcher method describeMismatch.
@Override
public void describeMismatch(Object item, Description mismatchDescription) {
if (this.type == null || this.value == null || this.target == null) {
mismatchDescription.appendText("One of the parameter matcher has been null. Please use AnyOf matchers instead.");
return;
}
MatcherTo matchedMatcherTo = (MatcherTo) item;
mismatchDescription.appendText("MatcherTo does not match!\nShould be MatcherTo(");
this.type.describeTo(mismatchDescription);
mismatchDescription.appendText(", ");
this.value.describeTo(mismatchDescription);
mismatchDescription.appendText(", ");
this.target.describeTo(mismatchDescription);
mismatchDescription.appendText(")\nWas MatcherTo('" + matchedMatcherTo.getType() + "', '" + matchedMatcherTo.getValue() + "', '" + matchedMatcherTo.getTarget() + "')");
}
use of com.devonfw.cobigen.api.to.MatcherTo in project cobigen by devonfw.
the class MatcherEvaluatorImpl method matches.
@Cached
@Override
public boolean matches(Object matcherInput, List<Matcher> matcherList, TriggerInterpreter triggerInterpreter) {
boolean matcherSetMatches = false;
LOG.debug("Check matchers for TriggerInterpreter[type='{}'] ...", triggerInterpreter.getType());
MATCHER_LOOP: for (Matcher matcher : matcherList) {
MatcherTo matcherTo = new MatcherTo(matcher.getType(), matcher.getValue(), matcherInput);
LOG.trace("Check {} ...", matcherTo);
if (triggerInterpreter.getMatcher().matches(matcherTo)) {
switch(matcher.getAccumulationType()) {
case NOT:
LOG.trace("NOT Matcher matches -> trigger match fails.");
matcherSetMatches = false;
break MATCHER_LOOP;
case OR:
case AND:
LOG.trace("Matcher matches.");
matcherSetMatches = true;
break;
default:
}
} else {
if (matcher.getAccumulationType() == AccumulationType.AND) {
LOG.trace("AND Matcher does not match -> trigger match fails.");
matcherSetMatches = false;
break MATCHER_LOOP;
}
}
}
LOG.debug("Matcher declarations " + (matcherSetMatches ? "match the input." : "do not match the input."));
return matcherSetMatches;
}
Aggregations