Search in sources :

Example 6 with MatcherTo

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);
}
Also used : ComponentDef(com.devonfw.cobigen.openapiplugin.model.ComponentDef) VariableAssignmentTo(com.devonfw.cobigen.api.to.VariableAssignmentTo) GenerationReportTo(com.devonfw.cobigen.api.to.GenerationReportTo) OpenAPIMatcher(com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher) ArrayList(java.util.ArrayList) MatcherTo(com.devonfw.cobigen.api.to.MatcherTo) Test(org.junit.Test)

Example 7 with MatcherTo

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();
}
Also used : OpenAPIMatcher(com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher) MatcherTo(com.devonfw.cobigen.api.to.MatcherTo) EntityDef(com.devonfw.cobigen.openapiplugin.model.EntityDef) Test(org.junit.Test)

Example 8 with MatcherTo

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"));
}
Also used : ComponentDef(com.devonfw.cobigen.openapiplugin.model.ComponentDef) VariableAssignmentTo(com.devonfw.cobigen.api.to.VariableAssignmentTo) GenerationReportTo(com.devonfw.cobigen.api.to.GenerationReportTo) OpenAPIMatcher(com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher) ArrayList(java.util.ArrayList) MatcherTo(com.devonfw.cobigen.api.to.MatcherTo) Test(org.junit.Test)

Example 9 with MatcherTo

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() + "')");
}
Also used : MatcherTo(com.devonfw.cobigen.api.to.MatcherTo)

Example 10 with MatcherTo

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;
}
Also used : Matcher(com.devonfw.cobigen.impl.config.entity.Matcher) MatcherTo(com.devonfw.cobigen.api.to.MatcherTo) Cached(com.devonfw.cobigen.api.annotation.Cached)

Aggregations

MatcherTo (com.devonfw.cobigen.api.to.MatcherTo)12 OpenAPIMatcher (com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher)7 Test (org.junit.Test)7 ComponentDef (com.devonfw.cobigen.openapiplugin.model.ComponentDef)5 ArrayList (java.util.ArrayList)4 Cached (com.devonfw.cobigen.api.annotation.Cached)3 GenerationReportTo (com.devonfw.cobigen.api.to.GenerationReportTo)3 VariableAssignmentTo (com.devonfw.cobigen.api.to.VariableAssignmentTo)3 TriggerInterpreter (com.devonfw.cobigen.api.extension.TriggerInterpreter)2 ContainerMatcher (com.devonfw.cobigen.impl.config.entity.ContainerMatcher)2 Matcher (com.devonfw.cobigen.impl.config.entity.Matcher)2 EntityDef (com.devonfw.cobigen.openapiplugin.model.EntityDef)2 InvalidConfigurationException (com.devonfw.cobigen.api.exception.InvalidConfigurationException)1 InputReader (com.devonfw.cobigen.api.extension.InputReader)1 Trigger (com.devonfw.cobigen.impl.config.entity.Trigger)1 Variables (com.devonfw.cobigen.impl.config.entity.Variables)1 PluginProcessingException (com.devonfw.cobigen.impl.exceptions.PluginProcessingException)1 List (java.util.List)1