Search in sources :

Example 16 with Parameter

use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.

the class ClientProxyImpl method handleMultipart.

private List<Attachment> handleMultipart(MultivaluedMap<ParameterType, Parameter> map, OperationResourceInfo ori, Object[] params) {
    List<Attachment> atts = new LinkedList<Attachment>();
    List<Parameter> fm = getParameters(map, ParameterType.REQUEST_BODY);
    for (Parameter p : fm) {
        Multipart part = getMultipart(ori, p.getIndex());
        if (part != null) {
            Object partObject = params[p.getIndex()];
            if (partObject != null) {
                atts.add(new Attachment(part.value(), part.type(), partObject));
            }
        }
    }
    return atts;
}
Also used : Multipart(org.apache.cxf.jaxrs.ext.multipart.Multipart) Parameter(org.apache.cxf.jaxrs.model.Parameter) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) LinkedList(java.util.LinkedList)

Example 17 with Parameter

use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.

the class OpenApiParseUtils method getUserApplicationFromJson.

public static UserApplication getUserApplicationFromJson(String json, ParseConfiguration cfg) {
    JsonMapObjectReaderWriter reader = new JsonMapObjectReaderWriter();
    Map<String, Object> map = reader.fromJson(json);
    UserApplication app = new UserApplication();
    app.setBasePath("/");
    List<Map<String, Object>> servers = CastUtils.cast((List<?>) map.get("servers"));
    if (servers != null && !servers.isEmpty()) {
        final String url = (String) servers.get(0).get("url");
        if (url != null) {
            app.setBasePath(url);
        }
    }
    Map<String, List<UserOperation>> userOpsMap = new LinkedHashMap<String, List<UserOperation>>();
    Set<String> tags = new HashSet<>();
    List<Map<String, Object>> tagsProp = CastUtils.cast((List<?>) map.get("tags"));
    if (tagsProp != null) {
        for (Map<String, Object> tagProp : tagsProp) {
            tags.add((String) tagProp.get("name"));
        }
    } else {
        tags.add("");
    }
    for (String tag : tags) {
        userOpsMap.put(tag, new LinkedList<UserOperation>());
    }
    Map<String, Map<String, Object>> paths = CastUtils.cast((Map<?, ?>) map.get("paths"));
    for (Map.Entry<String, Map<String, Object>> pathEntry : paths.entrySet()) {
        String operPath = pathEntry.getKey();
        Map<String, Object> operations = pathEntry.getValue();
        for (Map.Entry<String, Object> operEntry : operations.entrySet()) {
            UserOperation userOp = new UserOperation();
            userOp.setVerb(operEntry.getKey().toUpperCase());
            Map<String, Object> oper = CastUtils.cast((Map<?, ?>) operEntry.getValue());
            userOp.setPath(operPath);
            userOp.setName((String) oper.get("operationId"));
            Map<String, Object> responses = CastUtils.cast((Map<?, ?>) oper.get("responses"));
            if (responses != null) {
                userOp.setProduces(listToString(responses.entrySet().stream().map(entry -> CastUtils.cast((Map<?, ?>) entry.getValue())).map(value -> CastUtils.cast((Map<?, ?>) value.get("content"))).filter(Objects::nonNull).flatMap(content -> content.keySet().stream().map(type -> (String) type)).collect(Collectors.toList())));
            }
            Map<String, Object> payloads = CastUtils.cast((Map<?, ?>) oper.get("requestBody"));
            if (payloads != null) {
                userOp.setConsumes(listToString(payloads.entrySet().stream().map(entry -> CastUtils.cast((Map<?, ?>) entry.getValue())).map(value -> CastUtils.cast((Map<?, ?>) value.get("content"))).filter(Objects::nonNull).flatMap(content -> content.keySet().stream().map(type -> (String) type)).collect(Collectors.toList())));
            }
            List<Parameter> userOpParams = new LinkedList<Parameter>();
            List<Map<String, Object>> params = CastUtils.cast((List<?>) oper.get("parameters"));
            if (params != null) {
                for (Map<String, Object> param : params) {
                    String name = (String) param.get("name");
                    // "query", "header", "path" or "cookie".
                    String paramType = (String) param.get("in");
                    ParameterType pType = null;
                    if ("query".equals(paramType)) {
                        pType = ParameterType.QUERY;
                    } else if ("header".equals(paramType)) {
                        pType = ParameterType.HEADER;
                    } else if ("path".equals(paramType)) {
                        pType = ParameterType.PATH;
                    } else if ("cookie".equals(paramType)) {
                        pType = ParameterType.COOKIE;
                    } else {
                        pType = ParameterType.REQUEST_BODY;
                    }
                    Parameter userParam = new Parameter(pType, name);
                    setJavaType(userParam, (String) param.get("type"));
                    userOpParams.add(userParam);
                }
            }
            if (!userOpParams.isEmpty()) {
                userOp.setParameters(userOpParams);
            }
            List<String> opTags = CastUtils.cast((List<?>) oper.get("tags"));
            if (opTags == null) {
                opTags = Collections.singletonList("");
            }
            for (String opTag : opTags) {
                userOpsMap.get(opTag).add(userOp);
            }
        }
    }
    List<UserResource> resources = new LinkedList<UserResource>();
    for (Map.Entry<String, List<UserOperation>> entry : userOpsMap.entrySet()) {
        UserResource ur = new UserResource();
        ur.setPath("/");
        ur.setOperations(entry.getValue());
        ur.setName(entry.getKey());
        resources.add(ur);
    }
    app.setResources(resources);
    return app;
}
Also used : Bus(org.apache.cxf.Bus) UserApplication(org.apache.cxf.jaxrs.model.UserApplication) HashMap(java.util.HashMap) UserResource(org.apache.cxf.jaxrs.model.UserResource) Parameter(org.apache.cxf.jaxrs.model.Parameter) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ParameterType(org.apache.cxf.jaxrs.model.ParameterType) LogUtils(org.apache.cxf.common.logging.LogUtils) Map(java.util.Map) ResourceUtils(org.apache.cxf.jaxrs.utils.ResourceUtils) LinkedList(java.util.LinkedList) UserOperation(org.apache.cxf.jaxrs.model.UserOperation) CastUtils(org.apache.cxf.helpers.CastUtils) IOUtils(org.apache.cxf.helpers.IOUtils) Set(java.util.Set) IOException(java.io.IOException) Logger(java.util.logging.Logger) ClassLoaderUtils(org.apache.cxf.common.classloader.ClassLoaderUtils) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) BusFactory(org.apache.cxf.BusFactory) Collections(java.util.Collections) InputStream(java.io.InputStream) JsonMapObjectReaderWriter(org.apache.cxf.jaxrs.json.basic.JsonMapObjectReaderWriter) LinkedHashMap(java.util.LinkedHashMap) LinkedList(java.util.LinkedList) List(java.util.List) HashSet(java.util.HashSet) ParameterType(org.apache.cxf.jaxrs.model.ParameterType) JsonMapObjectReaderWriter(org.apache.cxf.jaxrs.json.basic.JsonMapObjectReaderWriter) UserResource(org.apache.cxf.jaxrs.model.UserResource) LinkedList(java.util.LinkedList) UserApplication(org.apache.cxf.jaxrs.model.UserApplication) UserOperation(org.apache.cxf.jaxrs.model.UserOperation) Objects(java.util.Objects) Parameter(org.apache.cxf.jaxrs.model.Parameter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 18 with Parameter

use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.

the class SwaggerParseUtils method getUserApplicationFromJson.

public static UserApplication getUserApplicationFromJson(String json, ParseConfiguration cfg) {
    JsonMapObjectReaderWriter reader = new JsonMapObjectReaderWriter();
    Map<String, Object> map = reader.fromJson(json);
    UserApplication app = new UserApplication();
    String relativePath = (String) map.get("basePath");
    app.setBasePath(StringUtils.isEmpty(relativePath) ? "/" : relativePath);
    Map<String, List<UserOperation>> userOpsMap = new LinkedHashMap<String, List<UserOperation>>();
    Set<String> tags = new HashSet<>();
    List<Map<String, Object>> tagsProp = CastUtils.cast((List<?>) map.get("tags"));
    if (tagsProp != null) {
        for (Map<String, Object> tagProp : tagsProp) {
            tags.add((String) tagProp.get("name"));
        }
    } else {
        tags.add("");
    }
    for (String tag : tags) {
        userOpsMap.put(tag, new LinkedList<UserOperation>());
    }
    Map<String, Map<String, Object>> paths = CastUtils.cast((Map<?, ?>) map.get("paths"));
    for (Map.Entry<String, Map<String, Object>> pathEntry : paths.entrySet()) {
        String operPath = pathEntry.getKey();
        Map<String, Object> operations = pathEntry.getValue();
        for (Map.Entry<String, Object> operEntry : operations.entrySet()) {
            UserOperation userOp = new UserOperation();
            userOp.setVerb(operEntry.getKey().toUpperCase());
            Map<String, Object> oper = CastUtils.cast((Map<?, ?>) operEntry.getValue());
            userOp.setPath(operPath);
            userOp.setName((String) oper.get("operationId"));
            List<String> opProduces = CastUtils.cast((List<?>) oper.get("produces"));
            userOp.setProduces(listToString(opProduces));
            List<String> opConsumes = CastUtils.cast((List<?>) oper.get("consumes"));
            userOp.setConsumes(listToString(opConsumes));
            List<Parameter> userOpParams = new LinkedList<Parameter>();
            List<Map<String, Object>> params = CastUtils.cast((List<?>) oper.get("parameters"));
            for (Map<String, Object> param : params) {
                String name = (String) param.get("name");
                // "query", "header", "path", "formData" or "body"
                String paramType = (String) param.get("in");
                ParameterType pType = "body".equals(paramType) ? ParameterType.REQUEST_BODY : "formData".equals(paramType) ? ParameterType.FORM : ParameterType.valueOf(paramType.toUpperCase());
                Parameter userParam = new Parameter(pType, name);
                setJavaType(userParam, (String) param.get("type"));
                userOpParams.add(userParam);
            }
            if (!userOpParams.isEmpty()) {
                userOp.setParameters(userOpParams);
            }
            List<String> opTags = CastUtils.cast((List<?>) oper.get("tags"));
            if (opTags == null) {
                opTags = Collections.singletonList("");
            }
            for (String opTag : opTags) {
                userOpsMap.get(opTag).add(userOp);
            }
        }
    }
    List<UserResource> resources = new LinkedList<UserResource>();
    for (Map.Entry<String, List<UserOperation>> entry : userOpsMap.entrySet()) {
        UserResource ur = new UserResource();
        ur.setPath("/");
        ur.setOperations(entry.getValue());
        ur.setName(entry.getKey());
        resources.add(ur);
    }
    app.setResources(resources);
    return app;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) LinkedList(java.util.LinkedList) List(java.util.List) HashSet(java.util.HashSet) ParameterType(org.apache.cxf.jaxrs.model.ParameterType) JsonMapObjectReaderWriter(org.apache.cxf.jaxrs.json.basic.JsonMapObjectReaderWriter) UserResource(org.apache.cxf.jaxrs.model.UserResource) LinkedList(java.util.LinkedList) UserApplication(org.apache.cxf.jaxrs.model.UserApplication) UserOperation(org.apache.cxf.jaxrs.model.UserOperation) Parameter(org.apache.cxf.jaxrs.model.Parameter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 19 with Parameter

use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.

the class SwaggerParseUtilsTest method verifyPetResource.

// CHECKSTYLE:OFF
private void verifyPetResource(UserResource ur) {
    assertNotNull(ur);
    assertEquals("/", ur.getPath());
    assertEquals(8, ur.getOperations().size());
    // POST /pet
    UserOperation addPet = ur.getOperations().get(0);
    assertEquals("addPet", addPet.getName());
    assertEquals("/pet", addPet.getPath());
    assertEquals("POST", addPet.getVerb());
    assertEquals("application/xml,application/json", addPet.getProduces());
    assertEquals("application/json,application/xml", addPet.getConsumes());
    assertEquals(1, addPet.getParameters().size());
    Parameter addPetParam1 = addPet.getParameters().get(0);
    assertEquals("body", addPetParam1.getName());
    assertEquals(ParameterType.REQUEST_BODY, addPetParam1.getType());
    // TODO: check that addPetParam1 refers to Pet model
    // TODO: check default response type: JAX-RS Response ?
    // PUT /pet
    UserOperation putPet = ur.getOperations().get(1);
    assertEquals("updatePet", putPet.getName());
    assertEquals("/pet", putPet.getPath());
    assertEquals("PUT", putPet.getVerb());
    assertEquals("application/xml,application/json", addPet.getProduces());
    assertEquals("application/json,application/xml", addPet.getConsumes());
    assertEquals(1, putPet.getParameters().size());
    Parameter putPetParam1 = putPet.getParameters().get(0);
    assertEquals("body", putPetParam1.getName());
    assertEquals(ParameterType.REQUEST_BODY, putPetParam1.getType());
    // TODO: check that putPetParam1 refers to Pet model
    // TODO: check default response type: JAX-RS Response ?
    // GET /pet/findByStatus
    UserOperation findPetsByStatus = ur.getOperations().get(2);
    assertEquals("findPetsByStatus", findPetsByStatus.getName());
    assertEquals("/pet/findByStatus", findPetsByStatus.getPath());
    assertEquals("GET", findPetsByStatus.getVerb());
    assertEquals("application/xml,application/json", findPetsByStatus.getProduces());
    assertNull(findPetsByStatus.getConsumes());
    assertEquals(1, findPetsByStatus.getParameters().size());
    Parameter findPetsByStatusParam1 = findPetsByStatus.getParameters().get(0);
    assertEquals("status", findPetsByStatusParam1.getName());
    assertEquals(ParameterType.QUERY, findPetsByStatusParam1.getType());
    // TODO: check that findPetsByStatusParam1 refers to List of String
    // TODO: check that response refers to List of Pets
    // GET /pet/findByTag
    UserOperation findPetsByTags = ur.getOperations().get(3);
    assertEquals("findPetsByTags", findPetsByTags.getName());
    assertEquals("/pet/findByTags", findPetsByTags.getPath());
    assertEquals("GET", findPetsByTags.getVerb());
    assertEquals("application/xml,application/json", findPetsByTags.getProduces());
    assertNull(findPetsByTags.getConsumes());
    assertEquals(1, findPetsByTags.getParameters().size());
    Parameter findPetsByTagsParam1 = findPetsByTags.getParameters().get(0);
    assertEquals("tags", findPetsByTagsParam1.getName());
    assertEquals(ParameterType.QUERY, findPetsByTagsParam1.getType());
    // TODO: check that findPetsByTagsParam1 refers to List of String
    // TODO: check that response refers to List of Pets
    // GET /pet/{petId}
    UserOperation getPetById = ur.getOperations().get(4);
    assertEquals("getPetById", getPetById.getName());
    assertEquals("/pet/{petId}", getPetById.getPath());
    assertEquals("GET", getPetById.getVerb());
    assertEquals("application/xml,application/json", getPetById.getProduces());
    assertNull(getPetById.getConsumes());
    assertEquals(1, getPetById.getParameters().size());
    Parameter getPetByIdParam1 = getPetById.getParameters().get(0);
    assertEquals("petId", getPetByIdParam1.getName());
    assertEquals(ParameterType.PATH, getPetByIdParam1.getType());
    assertEquals(long.class, getPetByIdParam1.getJavaType());
    // POST /pet/{petId}
    UserOperation updatePetWithForm = ur.getOperations().get(5);
    assertEquals("updatePetWithForm", updatePetWithForm.getName());
    assertEquals("/pet/{petId}", updatePetWithForm.getPath());
    assertEquals("POST", updatePetWithForm.getVerb());
    assertEquals("application/xml,application/json", updatePetWithForm.getProduces());
    assertEquals("application/x-www-form-urlencoded", updatePetWithForm.getConsumes());
    assertEquals(3, updatePetWithForm.getParameters().size());
    Parameter updatePetWithFormParam1 = updatePetWithForm.getParameters().get(0);
    assertEquals("petId", updatePetWithFormParam1.getName());
    assertEquals(ParameterType.PATH, updatePetWithFormParam1.getType());
    assertEquals(long.class, updatePetWithFormParam1.getJavaType());
    Parameter updatePetWithFormParam2 = updatePetWithForm.getParameters().get(1);
    assertEquals("name", updatePetWithFormParam2.getName());
    assertEquals(ParameterType.FORM, updatePetWithFormParam2.getType());
    assertEquals(String.class, updatePetWithFormParam2.getJavaType());
    Parameter updatePetWithFormParam3 = updatePetWithForm.getParameters().get(2);
    assertEquals("status", updatePetWithFormParam3.getName());
    assertEquals(ParameterType.FORM, updatePetWithFormParam3.getType());
    assertEquals(String.class, updatePetWithFormParam3.getJavaType());
    // DELETE /pet/{petId}
    UserOperation deletePet = ur.getOperations().get(6);
    assertEquals("deletePet", deletePet.getName());
    assertEquals("/pet/{petId}", deletePet.getPath());
    assertEquals("DELETE", deletePet.getVerb());
    assertEquals("application/xml,application/json", deletePet.getProduces());
    assertNull(deletePet.getConsumes());
    assertEquals(2, deletePet.getParameters().size());
    Parameter deletePetParam1 = deletePet.getParameters().get(0);
    assertEquals("api_key", deletePetParam1.getName());
    assertEquals(ParameterType.HEADER, deletePetParam1.getType());
    assertEquals(String.class, deletePetParam1.getJavaType());
    Parameter deletePetParam2 = deletePet.getParameters().get(1);
    assertEquals("petId", deletePetParam2.getName());
    assertEquals(ParameterType.PATH, deletePetParam2.getType());
    assertEquals(long.class, deletePetParam2.getJavaType());
    // POST /pet/{petId}/uploadImage
    UserOperation uploadFile = ur.getOperations().get(7);
    assertEquals("uploadFile", uploadFile.getName());
    assertEquals("/pet/{petId}/uploadImage", uploadFile.getPath());
    assertEquals("POST", uploadFile.getVerb());
    assertEquals("application/json", uploadFile.getProduces());
    assertEquals("multipart/form-data", uploadFile.getConsumes());
    assertEquals(3, uploadFile.getParameters().size());
    Parameter uploadFileParam1 = uploadFile.getParameters().get(0);
    assertEquals("petId", uploadFileParam1.getName());
    assertEquals(ParameterType.PATH, uploadFileParam1.getType());
    assertEquals(long.class, uploadFileParam1.getJavaType());
    Parameter uploadFileParam2 = uploadFile.getParameters().get(1);
    assertEquals("additionalMetadata", uploadFileParam2.getName());
    assertEquals(ParameterType.FORM, uploadFileParam2.getType());
    assertEquals(String.class, uploadFileParam2.getJavaType());
    Parameter uploadFileParam3 = uploadFile.getParameters().get(2);
    assertEquals("file", uploadFileParam3.getName());
    assertEquals(ParameterType.FORM, uploadFileParam3.getType());
    assertEquals(InputStream.class, uploadFileParam3.getJavaType());
}
Also used : UserOperation(org.apache.cxf.jaxrs.model.UserOperation) Parameter(org.apache.cxf.jaxrs.model.Parameter)

Example 20 with Parameter

use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.

the class SwaggerParseUtilsTest method verifyPetUserResource.

// CHECKSTYLE:ON
// CHECKSTYLE:OFF
private void verifyPetUserResource(UserResource ur) {
    assertNotNull(ur);
    assertEquals("/", ur.getPath());
    assertEquals(8, ur.getOperations().size());
    // POST /user
    UserOperation createUser = ur.getOperations().get(0);
    assertEquals("createUser", createUser.getName());
    assertEquals("/user", createUser.getPath());
    assertEquals("POST", createUser.getVerb());
    assertEquals("application/xml,application/json", createUser.getProduces());
    assertNull(createUser.getConsumes());
    assertEquals(1, createUser.getParameters().size());
    Parameter createUserParam1 = createUser.getParameters().get(0);
    assertEquals("body", createUserParam1.getName());
    assertEquals(ParameterType.REQUEST_BODY, createUserParam1.getType());
    // TODO: check that createUserParam1 refers to User model
    // TODO: check default response type: JAX-RS Response ?
    // POST /user/createWithArray
    UserOperation createWithArray = ur.getOperations().get(1);
    assertEquals("createUsersWithArrayInput", createWithArray.getName());
    assertEquals("/user/createWithArray", createWithArray.getPath());
    assertEquals("POST", createUser.getVerb());
    assertEquals("application/xml,application/json", createUser.getProduces());
    assertNull(createWithArray.getConsumes());
    assertEquals(1, createUser.getParameters().size());
    Parameter createWithArrayParam1 = createUser.getParameters().get(0);
    assertEquals("body", createWithArrayParam1.getName());
    assertEquals(ParameterType.REQUEST_BODY, createWithArrayParam1.getType());
    // TODO: check that createUserParam1 refers to an array of User model
    // TODO: check default response type: JAX-RS Response ?
    // POST /user/createWithList
    UserOperation createWithList = ur.getOperations().get(2);
    assertEquals("createUsersWithListInput", createWithList.getName());
    assertEquals("/user/createWithList", createWithList.getPath());
    assertEquals("POST", createWithList.getVerb());
    assertEquals("application/xml,application/json", createWithList.getProduces());
    assertNull(createWithList.getConsumes());
    assertEquals(1, createWithList.getParameters().size());
    Parameter createWithListParam1 = createWithList.getParameters().get(0);
    assertEquals("body", createWithListParam1.getName());
    assertEquals(ParameterType.REQUEST_BODY, createWithListParam1.getType());
    // TODO: check that createUserParam1 refers to an array of User model
    // TODO: check default response type: JAX-RS Response ?
    // GET /user/login
    UserOperation loginUser = ur.getOperations().get(3);
    assertEquals("loginUser", loginUser.getName());
    assertEquals("/user/login", loginUser.getPath());
    assertEquals("GET", loginUser.getVerb());
    assertEquals("application/xml,application/json", loginUser.getProduces());
    assertNull(loginUser.getConsumes());
    assertEquals(2, loginUser.getParameters().size());
    Parameter loginUserParam1 = loginUser.getParameters().get(0);
    assertEquals("username", loginUserParam1.getName());
    assertEquals(ParameterType.QUERY, loginUserParam1.getType());
    assertEquals(String.class, loginUserParam1.getJavaType());
    Parameter loginUserParam2 = loginUser.getParameters().get(1);
    assertEquals("password", loginUserParam2.getName());
    assertEquals(ParameterType.QUERY, loginUserParam2.getType());
    assertEquals(String.class, loginUserParam2.getJavaType());
    // TODO: check 200 response type
    // GET /user/logout
    UserOperation logoutUser = ur.getOperations().get(4);
    assertEquals("logoutUser", logoutUser.getName());
    assertEquals("/user/logout", logoutUser.getPath());
    assertEquals("GET", loginUser.getVerb());
    assertEquals("application/xml,application/json", logoutUser.getProduces());
    assertNull(logoutUser.getConsumes());
    assertEquals(0, logoutUser.getParameters().size());
    // TODO: check 200 response type
    // GET /user/{username}
    UserOperation getUserByName = ur.getOperations().get(5);
    assertEquals("getUserByName", getUserByName.getName());
    assertEquals("/user/{username}", getUserByName.getPath());
    assertEquals("GET", getUserByName.getVerb());
    assertEquals("application/xml,application/json", getUserByName.getProduces());
    assertNull(getUserByName.getConsumes());
    assertEquals(1, getUserByName.getParameters().size());
    Parameter getUserByNameParam1 = getUserByName.getParameters().get(0);
    assertEquals("username", getUserByNameParam1.getName());
    assertEquals(ParameterType.PATH, getUserByNameParam1.getType());
    assertEquals(String.class, getUserByNameParam1.getJavaType());
    // TODO: check 200 response type
    // PUT /user/{username}
    UserOperation updateUser = ur.getOperations().get(6);
    assertEquals("updateUser", updateUser.getName());
    assertEquals("/user/{username}", updateUser.getPath());
    assertEquals("PUT", updateUser.getVerb());
    assertEquals("application/xml,application/json", updateUser.getProduces());
    assertNull(updateUser.getConsumes());
    assertEquals(2, updateUser.getParameters().size());
    Parameter updateUserParam1 = updateUser.getParameters().get(0);
    assertEquals("username", updateUserParam1.getName());
    assertEquals(ParameterType.PATH, updateUserParam1.getType());
    assertEquals(String.class, updateUserParam1.getJavaType());
    Parameter updateUserParam2 = updateUser.getParameters().get(1);
    assertEquals("body", updateUserParam2.getName());
    assertEquals(ParameterType.REQUEST_BODY, updateUserParam2.getType());
    // TODO: check that createUserParam1 refers to an array of User model
    // TODO: check 200 response type
    // DELETE /user/{username}
    UserOperation deleteUser = ur.getOperations().get(7);
    assertEquals("deleteUser", deleteUser.getName());
    assertEquals("/user/{username}", deleteUser.getPath());
    assertEquals("DELETE", deleteUser.getVerb());
    assertEquals("application/xml,application/json", deleteUser.getProduces());
    assertNull(deleteUser.getConsumes());
    assertEquals(1, deleteUser.getParameters().size());
    Parameter deleteUserParam1 = deleteUser.getParameters().get(0);
    assertEquals("username", deleteUserParam1.getName());
    assertEquals(ParameterType.PATH, deleteUserParam1.getType());
    assertEquals(String.class, deleteUserParam1.getJavaType());
}
Also used : UserOperation(org.apache.cxf.jaxrs.model.UserOperation) Parameter(org.apache.cxf.jaxrs.model.Parameter)

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