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();
}
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);
}
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"));
}
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() + "')");
}
Aggregations