use of com.devonfw.cobigen.openapiplugin.model.ComponentDef 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.openapiplugin.model.ComponentDef 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.openapiplugin.model.ComponentDef in project cobigen by devonfw.
the class OpenAPIInputReader method extractComponentsFromPaths.
/**
* Get a list of components defined at the paths part with the x-component tag. Returns a list of
* {@link ComponentDef}'s
*
* @param paths the paths of the OpenApi3 file
* @param astOpenApi OpenApi3 object which is the AST of the file
* @return a list of {@link ComponentDef}'s for each path that contains x-component tag
*/
private List<ComponentDef> extractComponentsFromPaths(List<Path> paths, OpenApi3 astOpenApi) {
for (Path path : paths) {
if (path.getExtensions().get(Constants.COMPONENT_EXT) != null) {
String componentName = path.getExtensions().get(Constants.COMPONENT_EXT).toString();
if (componentName != null && !componentName.isEmpty()) {
// items on a list are passed by reference, we can change it
ComponentDef componentDef = getComponent(componentName);
// If the component has no name, it means no component was found
if (componentDef.getName() == null) {
componentDef.setName(componentName);
componentDef.setPaths(extractPaths(astOpenApi.getPaths(), componentName));
setExtensionsToComponent(astOpenApi, componentDef);
this.components.add(componentDef);
} else {
setExtensionsToComponent(astOpenApi, componentDef);
}
}
}
}
return this.components;
}
use of com.devonfw.cobigen.openapiplugin.model.ComponentDef in project cobigen by devonfw.
the class OpenAPIInputReaderTest method testResponse.
@Test
public void testResponse() throws Exception {
List<Object> inputObjects = getInputs("componentResponseType.yaml");
boolean found = false;
for (Object o : inputObjects) {
if (isEntityDef(o)) {
EntityDef e = (EntityDef) o;
ComponentDef c = e.getComponent();
for (PathDef p : c.getPaths()) {
if (p.getPathURI().equals("/sampledata/customSearch/")) {
for (OperationDef op : p.getOperations()) {
for (ResponseDef r : op.getResponses()) {
assertThat(r.getType()).isEqualTo("SampleData");
found = true;
}
}
}
}
}
}
assertThat(found).isTrue();
}
use of com.devonfw.cobigen.openapiplugin.model.ComponentDef in project cobigen by devonfw.
the class OpenAPIInputReaderTest method testRetrieveOperationsOfPath.
@Test
public void testRetrieveOperationsOfPath() throws Exception {
List<Object> inputObjects = getInputs("two-components.yaml");
List<ComponentDef> cmps = new LinkedList<>();
for (Object o : inputObjects) {
if (isComponentDef(o)) {
cmps.add((ComponentDef) o);
} else {
cmps.add(((EntityDef) o).getComponent());
}
}
List<OperationDef> operations = new LinkedList<>();
for (ComponentDef cmp : cmps) {
for (PathDef path : cmp.getPaths()) {
for (OperationDef op : path.getOperations()) {
operations.add(op);
}
}
}
assertThat(operations).extracting("type").hasSize(10);
assertThat(operations).extracting("type").containsExactly("get", "post", "get", "get", "post", "get", "post", "get", "get", "post");
}
Aggregations