Search in sources :

Example 21 with Parameter

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
}
Also used : UserOperation(org.apache.cxf.jaxrs.model.UserOperation) Parameter(org.apache.cxf.jaxrs.model.Parameter)

Example 22 with Parameter

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());
}
Also used : UserApplication(org.apache.cxf.jaxrs.model.UserApplication) UserOperation(org.apache.cxf.jaxrs.model.UserOperation) UserResource(org.apache.cxf.jaxrs.model.UserResource) Parameter(org.apache.cxf.jaxrs.model.Parameter) Test(org.junit.Test)

Example 23 with Parameter

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());
}
Also used : UserApplication(org.apache.cxf.jaxrs.model.UserApplication) UserOperation(org.apache.cxf.jaxrs.model.UserOperation) UserResource(org.apache.cxf.jaxrs.model.UserResource) Parameter(org.apache.cxf.jaxrs.model.Parameter) Test(org.junit.Test)

Example 24 with Parameter

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;
}
Also used : Parameter(org.apache.cxf.jaxrs.model.Parameter) Endpoint(org.apache.cxf.endpoint.Endpoint)

Example 25 with Parameter

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);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ParameterType(org.apache.cxf.jaxrs.model.ParameterType) MediaType(javax.ws.rs.core.MediaType) XmlType(javax.xml.bind.annotation.XmlType) ParameterType(org.apache.cxf.jaxrs.model.ParameterType) Type(java.lang.reflect.Type) Parameter(org.apache.cxf.jaxrs.model.Parameter) Method(java.lang.reflect.Method) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Annotation(java.lang.annotation.Annotation)

Aggregations

Parameter (org.apache.cxf.jaxrs.model.Parameter)38 UserOperation (org.apache.cxf.jaxrs.model.UserOperation)13 Method (java.lang.reflect.Method)12 ParameterType (org.apache.cxf.jaxrs.model.ParameterType)10 Endpoint (org.apache.cxf.endpoint.Endpoint)9 UserResource (org.apache.cxf.jaxrs.model.UserResource)9 LinkedHashMap (java.util.LinkedHashMap)8 HashMap (java.util.HashMap)7 UserApplication (org.apache.cxf.jaxrs.model.UserApplication)7 MediaType (javax.ws.rs.core.MediaType)6 Annotation (java.lang.annotation.Annotation)5 Type (java.lang.reflect.Type)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)5 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)5 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)5 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)5 LinkedList (java.util.LinkedList)4 Test (org.junit.Test)4