Search in sources :

Example 1 with OpenAPIMatcher

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

Example 2 with OpenAPIMatcher

use of com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher 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"));
}
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 3 with OpenAPIMatcher

use of com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher 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();
}
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 4 with OpenAPIMatcher

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

Example 5 with OpenAPIMatcher

use of com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher 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)

Aggregations

MatcherTo (com.devonfw.cobigen.api.to.MatcherTo)7 OpenAPIMatcher (com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher)7 Test (org.junit.Test)7 ComponentDef (com.devonfw.cobigen.openapiplugin.model.ComponentDef)5 GenerationReportTo (com.devonfw.cobigen.api.to.GenerationReportTo)3 VariableAssignmentTo (com.devonfw.cobigen.api.to.VariableAssignmentTo)3 ArrayList (java.util.ArrayList)3 EntityDef (com.devonfw.cobigen.openapiplugin.model.EntityDef)2