use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.
the class SwaggerParseUtilsTest method verifyPetStoreResource.
// CHECKSTYLE:ON
private void verifyPetStoreResource(UserResource ur) {
assertNotNull(ur);
assertEquals("/", ur.getPath());
assertEquals(4, ur.getOperations().size());
// GET /store/inventory
UserOperation getInv = ur.getOperations().get(0);
assertEquals("getInventory", getInv.getName());
assertEquals("/store/inventory", getInv.getPath());
assertEquals("GET", getInv.getVerb());
assertEquals("application/json", getInv.getProduces());
assertNull(getInv.getConsumes());
assertEquals(0, getInv.getParameters().size());
// TODO: check 200 response type
// POST /store/inventory
UserOperation placeOrder = ur.getOperations().get(1);
assertEquals("placeOrder", placeOrder.getName());
assertEquals("/store/order", placeOrder.getPath());
assertEquals("POST", placeOrder.getVerb());
assertEquals("application/xml,application/json", placeOrder.getProduces());
assertNull(placeOrder.getConsumes());
assertEquals(1, placeOrder.getParameters().size());
Parameter placeOrderParam1 = placeOrder.getParameters().get(0);
assertEquals("body", placeOrderParam1.getName());
assertEquals(ParameterType.REQUEST_BODY, placeOrderParam1.getType());
// TODO: check that placeOrderParam1 refers to Order model
// TODO: check 200 response type
// GET /store/order/{orderId}
UserOperation getOrderById = ur.getOperations().get(2);
assertEquals("getOrderById", getOrderById.getName());
assertEquals("/store/order/{orderId}", getOrderById.getPath());
assertEquals("GET", getOrderById.getVerb());
assertEquals("application/xml,application/json", getOrderById.getProduces());
assertNull(getOrderById.getConsumes());
assertEquals(1, getOrderById.getParameters().size());
Parameter getOrderByIdParam1 = getOrderById.getParameters().get(0);
assertEquals("orderId", getOrderByIdParam1.getName());
assertEquals(ParameterType.PATH, getOrderByIdParam1.getType());
assertEquals(long.class, getOrderByIdParam1.getJavaType());
// TODO: check 200 response type
// DELETE /store/order/{orderId}
UserOperation deleteOrder = ur.getOperations().get(3);
assertEquals("deleteOrder", deleteOrder.getName());
assertEquals("/store/order/{orderId}", deleteOrder.getPath());
assertEquals("DELETE", deleteOrder.getVerb());
assertEquals("application/xml,application/json", deleteOrder.getProduces());
assertNull(deleteOrder.getConsumes());
assertEquals(1, getOrderById.getParameters().size());
Parameter deleteOrderParam1 = deleteOrder.getParameters().get(0);
assertEquals("orderId", deleteOrderParam1.getName());
assertEquals(ParameterType.PATH, deleteOrderParam1.getType());
assertEquals(long.class, deleteOrderParam1.getJavaType());
// TODO: check 200 response type
}
use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.
the class SwaggerParseUtilsTest method testConvertSimpleDocTagAndPathMismatchToUserApp.
@Test
public void testConvertSimpleDocTagAndPathMismatchToUserApp() {
UserApplication ap = SwaggerParseUtils.getUserApplication("/swagger20TagsPathsMismatch.json");
assertNotNull(ap);
assertEquals("/services/helloservice", ap.getBasePath());
Map<String, UserResource> map = ap.getResourcesAsMap();
assertEquals(2, map.size());
UserResource ur = map.get("sayHello");
assertNotNull(ur);
assertEquals("/", ur.getPath());
assertEquals(1, ur.getOperations().size());
UserOperation op = ur.getOperations().get(0);
assertEquals("sayHello", op.getName());
assertEquals("/sayHi/{a}", op.getPath());
assertEquals("GET", op.getVerb());
assertEquals("text/plain", op.getProduces());
assertEquals(1, op.getParameters().size());
Parameter param1 = op.getParameters().get(0);
assertEquals("a", param1.getName());
assertEquals(ParameterType.PATH, param1.getType());
assertEquals(String.class, param1.getJavaType());
UserResource ur2 = map.get("sayHello2");
assertNotNull(ur2);
assertEquals("/", ur2.getPath());
assertEquals(1, ur2.getOperations().size());
UserOperation op2 = ur2.getOperations().get(0);
assertEquals("sayHello", op2.getName());
assertEquals("/sayHi2/{a}", op2.getPath());
assertEquals("GET", op2.getVerb());
assertEquals("text/plain", op2.getProduces());
assertEquals(1, op2.getParameters().size());
Parameter param2 = op.getParameters().get(0);
assertEquals("a", param2.getName());
assertEquals(ParameterType.PATH, param2.getType());
assertEquals(String.class, param2.getJavaType());
}
use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.
the class SwaggerParseUtilsTest method testConvertSimpleDocNoTagsToUserApp.
@Test
public void testConvertSimpleDocNoTagsToUserApp() {
UserApplication ap = SwaggerParseUtils.getUserApplication("/swagger20NoTags.json");
assertNotNull(ap);
assertEquals("/services/helloservice", ap.getBasePath());
Map<String, UserResource> map = ap.getResourcesAsMap();
assertEquals(1, map.size());
UserResource ur = map.get("");
assertNotNull(ur);
assertEquals("/", ur.getPath());
assertEquals(2, ur.getOperations().size());
UserOperation op = ur.getOperations().get(0);
assertEquals("sayHello", op.getName());
assertEquals("/sayHello/{a}", op.getPath());
assertEquals("GET", op.getVerb());
assertEquals("text/plain", op.getProduces());
assertEquals(1, op.getParameters().size());
Parameter param1 = op.getParameters().get(0);
assertEquals("a", param1.getName());
assertEquals(ParameterType.PATH, param1.getType());
assertEquals(String.class, param1.getJavaType());
UserOperation op2 = ur.getOperations().get(1);
assertEquals("sayHello2", op2.getName());
assertEquals("/sayHello2/{a}", op2.getPath());
assertEquals("GET", op2.getVerb());
assertEquals("text/plain", op2.getProduces());
assertEquals(1, op2.getParameters().size());
Parameter param2 = op.getParameters().get(0);
assertEquals("a", param2.getName());
assertEquals(ParameterType.PATH, param2.getType());
assertEquals(String.class, param2.getJavaType());
}
use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.
the class WadlGenerator method compareOperations.
protected boolean compareOperations(OperationResourceInfo ori1, OperationResourceInfo ori2) {
if (ori1 == null || ori2 == null || !ori1.getURITemplate().getValue().equals(ori2.getURITemplate().getValue()) || ori1.getHttpMethod() != null && ori2.getHttpMethod() == null || ori2.getHttpMethod() != null && ori1.getHttpMethod() == null) {
return false;
}
if (usePathParamsToCompareOperations) {
int ori1PathParams = 0;
int ori1MatrixParams = 0;
for (Parameter p : ori1.getParameters()) {
if (p.getType() == ParameterType.PATH) {
ori1PathParams++;
} else if (p.getType() == ParameterType.MATRIX) {
ori1MatrixParams++;
}
}
int ori2PathParams = 0;
int ori2MatrixParams = 0;
for (Parameter p : ori2.getParameters()) {
if (p.getType() == ParameterType.PATH) {
ori2PathParams++;
} else if (p.getType() == ParameterType.MATRIX) {
ori2MatrixParams++;
}
}
return ori1PathParams == ori2PathParams && ori1MatrixParams == ori2MatrixParams;
}
return true;
}
use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.
the class WadlGenerator method doHandleClassParams.
protected void doHandleClassParams(OperationResourceInfo ori, StringBuilder sb, Map<Parameter, Object> params, boolean isJson, ParameterType... pType) {
Set<ParameterType> pTypes = new LinkedHashSet<>(Arrays.asList(pType));
for (Map.Entry<Parameter, Object> entry : params.entrySet()) {
Parameter pm = entry.getKey();
Object obj = entry.getValue();
if (pTypes.contains(pm.getType())) {
Class<?> cls = obj instanceof Method ? ((Method) obj).getParameterTypes()[0] : ((Field) obj).getType();
Type type = obj instanceof Method ? ((Method) obj).getGenericParameterTypes()[0] : ((Field) obj).getGenericType();
Annotation[] ann = obj instanceof Method ? ((Method) obj).getParameterAnnotations()[0] : ((Field) obj).getAnnotations();
doWriteParam(ori, sb, pm, cls, type, pm.getName(), ann, isJson);
}
}
}
Aggregations