Search in sources :

Example 6 with VariableAssignmentTo

use of com.devonfw.cobigen.api.to.VariableAssignmentTo in project cobigen by devonfw.

the class JavaMatcherTests method resolveEmptyRegexVariable.

/**
 * Test method for
 * {@link com.devonfw.cobigen.javaplugin.matcher.JavaMatcher#getResolvedVariables(com.devonfw.cobigen.javaplugin.matcher.JavaMatcher.MatcherType, java.lang.String, java.lang.String, java.util.List)}
 * . Tests if the algorithm handles empty variables correctly
 */
@SuppressWarnings("javadoc")
@Test
public void resolveEmptyRegexVariable() {
    List<VariableAssignmentTo> variables = new LinkedList<>();
    VariableAssignmentTo rootPackage = new VariableAssignmentTo("regex", "rootPackage", "1");
    VariableAssignmentTo domain = new VariableAssignmentTo("regex", "domain", "3");
    VariableAssignmentTo component = new VariableAssignmentTo("regex", "component", "4");
    VariableAssignmentTo detail = new VariableAssignmentTo("regex", "detail", "5");
    VariableAssignmentTo typeName = new VariableAssignmentTo("regex", "typeName", "6");
    variables.add(rootPackage);
    variables.add(domain);
    variables.add(component);
    variables.add(detail);
    variables.add(typeName);
    String inputValue = "de.tukl.abc.project.standard.datatype.common.api.LongText";
    String regex = "((.+\\.)?([^.]+))\\.(datatype)\\.common\\.api(\\..*)?\\.([^.]+)";
    Map<String, String> result = this.javaMatcher.getResolvedVariables(null, regex, inputValue, variables);
    assertThat(result.get("detail")).as("value of detail").isEmpty();
}
Also used : VariableAssignmentTo(com.devonfw.cobigen.api.to.VariableAssignmentTo) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 7 with VariableAssignmentTo

use of com.devonfw.cobigen.api.to.VariableAssignmentTo 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 8 with VariableAssignmentTo

use of com.devonfw.cobigen.api.to.VariableAssignmentTo 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 VariableAssignmentTo

use of com.devonfw.cobigen.api.to.VariableAssignmentTo in project cobigen by devonfw.

the class VariableAssignmentToMatcher method describeMismatch.

@Override
public void describeMismatch(Object item, Description mismatchDescription) {
    if (this.type == null || this.value == null || this.varName == null) {
        mismatchDescription.appendText("One of the parameter matcher has been null. Please use AnyOf matchers instead.");
        return;
    }
    VariableAssignmentTo varAssignTo = (VariableAssignmentTo) item;
    mismatchDescription.appendText("VariableAssignmentTo does not match!\nShould be VariableAssignmentTo(");
    this.type.describeTo(mismatchDescription);
    mismatchDescription.appendText(", ");
    this.varName.describeTo(mismatchDescription);
    mismatchDescription.appendText(", ");
    this.value.describeTo(mismatchDescription);
    mismatchDescription.appendText(", ");
    this.mandatory.describeTo(mismatchDescription);
    mismatchDescription.appendText(")\nWas       VariableAssignmentTo('" + varAssignTo.getType() + "', '" + varAssignTo.getVarName() + "', '" + varAssignTo.getValue() + "')");
}
Also used : VariableAssignmentTo(com.devonfw.cobigen.api.to.VariableAssignmentTo)

Aggregations

VariableAssignmentTo (com.devonfw.cobigen.api.to.VariableAssignmentTo)9 Test (org.junit.Test)5 GenerationReportTo (com.devonfw.cobigen.api.to.GenerationReportTo)3 MatcherTo (com.devonfw.cobigen.api.to.MatcherTo)3 OpenAPIMatcher (com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher)3 ComponentDef (com.devonfw.cobigen.openapiplugin.model.ComponentDef)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)2 CobiGenRuntimeException (com.devonfw.cobigen.api.exception.CobiGenRuntimeException)1 InvalidConfigurationException (com.devonfw.cobigen.api.exception.InvalidConfigurationException)1 Field (java.lang.reflect.Field)1