Search in sources :

Example 11 with MetadataMap

use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.

the class JAXRSUtilsTest method testPathParametersBean.

@Test
public void testPathParametersBean() throws Exception {
    Class<?>[] argType = { Customer.CustomerBean.class };
    Method m = Customer.class.getMethod("testPathBean", argType);
    MultivaluedMap<String, String> pathTemplates = new MetadataMap<String, String>();
    pathTemplates.add("a", "aValue");
    pathTemplates.add("b", "123");
    MultivaluedMap<String, String> complexPathTemplates = new MetadataMap<String, String>();
    complexPathTemplates.add("c", "1");
    complexPathTemplates.add("a", "A");
    complexPathTemplates.add("b", "123");
    complexPathTemplates.add("c", "2");
    complexPathTemplates.add("c", "3");
    complexPathTemplates.add("d.c", "4");
    complexPathTemplates.add("d.a", "B");
    complexPathTemplates.add("d.b", "456");
    complexPathTemplates.add("d.c", "5");
    complexPathTemplates.add("d.c", "6");
    complexPathTemplates.add("e.c", "41");
    complexPathTemplates.add("e.a", "B1");
    complexPathTemplates.add("e.b", "457");
    complexPathTemplates.add("e.c", "51");
    complexPathTemplates.add("e.c", "61");
    complexPathTemplates.add("e.c", "42");
    complexPathTemplates.add("e.a", "B2");
    complexPathTemplates.add("e.b", "458");
    complexPathTemplates.add("e.c", "52");
    complexPathTemplates.add("e.c", "62");
    complexPathTemplates.add("d.d.c", "7");
    complexPathTemplates.add("d.d.a", "C");
    complexPathTemplates.add("d.d.b", "789");
    complexPathTemplates.add("d.d.c", "8");
    complexPathTemplates.add("d.d.c", "9");
    complexPathTemplates.add("d.e.c", "71");
    complexPathTemplates.add("d.e.a", "C1");
    complexPathTemplates.add("d.e.b", "790");
    complexPathTemplates.add("d.e.c", "81");
    complexPathTemplates.add("d.e.c", "91");
    complexPathTemplates.add("d.e.c", "72");
    complexPathTemplates.add("d.e.a", "C2");
    complexPathTemplates.add("d.e.b", "791");
    complexPathTemplates.add("d.e.c", "82");
    complexPathTemplates.add("d.e.c", "92");
    verifyParametersBean(m, pathTemplates, createMessage(), complexPathTemplates, createMessage());
}
Also used : MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Customer(org.apache.cxf.jaxrs.Customer) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 12 with MetadataMap

use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.

the class JAXRSUtilsTest method testFindTargetResourceClassWithSubResource.

@Test
public void testFindTargetResourceClassWithSubResource() throws Exception {
    JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
    sf.setResourceClasses(org.apache.cxf.jaxrs.resources.BookStore.class);
    sf.create();
    List<ClassResourceInfo> resources = ((JAXRSServiceImpl) sf.getService()).getClassResourceInfos();
    String contentTypes = "*/*";
    OperationResourceInfo ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/books/sub/123", "GET", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));
    assertNotNull(ori);
    assertEquals("getBook", ori.getMethodToInvoke().getName());
    ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/books/123/true/chapter/1", "GET", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));
    assertNotNull(ori);
    assertEquals("getNewBook", ori.getMethodToInvoke().getName());
    ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/books", "POST", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));
    assertNotNull(ori);
    assertEquals("addBook", ori.getMethodToInvoke().getName());
    ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/books", "PUT", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));
    assertNotNull(ori);
    assertEquals("updateBook", ori.getMethodToInvoke().getName());
    ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/books/123", "DELETE", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));
    assertNotNull(ori);
    assertEquals("deleteBook", ori.getMethodToInvoke().getName());
}
Also used : JAXRSServiceFactoryBean(org.apache.cxf.jaxrs.JAXRSServiceFactoryBean) JAXRSServiceImpl(org.apache.cxf.jaxrs.JAXRSServiceImpl) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Test(org.junit.Test)

Example 13 with MetadataMap

use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.

the class JAXRSUtilsTest method testParamAnnotationOnMethod.

@Test
public void testParamAnnotationOnMethod() throws Exception {
    ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
    Customer c = new Customer();
    OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0], cri);
    Message m = createMessage();
    MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
    headers.add("AHeader2", "theAHeader2");
    m.put(Message.PROTOCOL_HEADERS, headers);
    m.put(Message.QUERY_STRING, "a_value=aValue&query2=b");
    JAXRSUtils.injectParameters(ori, c, m);
    assertEquals("aValue", c.getQueryParam());
    assertEquals("theAHeader2", c.getAHeader2());
}
Also used : MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Message(org.apache.cxf.message.Message) Customer(org.apache.cxf.jaxrs.Customer) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Test(org.junit.Test)

Example 14 with MetadataMap

use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.

the class JAXRSUtilsTest method testParamAnnotationOnField.

@Test
public void testParamAnnotationOnField() throws Exception {
    ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
    Customer c = new Customer();
    OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0], cri);
    Message m = createMessage();
    MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
    headers.add("AHeader", "theAHeader");
    m.put(Message.PROTOCOL_HEADERS, headers);
    m.put(Message.QUERY_STRING, "b=bValue");
    JAXRSUtils.injectParameters(ori, c, m);
    assertEquals("bValue", c.getB());
    assertEquals("theAHeader", c.getAHeader());
}
Also used : MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Message(org.apache.cxf.message.Message) Customer(org.apache.cxf.jaxrs.Customer) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Test(org.junit.Test)

Example 15 with MetadataMap

use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.

the class JAXRSUtilsTest method testConversion.

@Test
public void testConversion() throws Exception {
    ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
    OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethod("testConversion", new Class[] { PathSegmentImpl.class, SimpleFactory.class }), cri);
    ori.setHttpMethod("GET");
    ori.setURITemplate(new URITemplate("{id1}/{id2}"));
    MultivaluedMap<String, String> values = new MetadataMap<String, String>();
    values.putSingle("id1", "1");
    values.putSingle("id2", "2");
    Message m = createMessage();
    List<Object> params = JAXRSUtils.processParameters(ori, values, m);
    PathSegment ps = (PathSegment) params.get(0);
    assertEquals("1", ps.getPath());
    SimpleFactory sf = (SimpleFactory) params.get(1);
    assertEquals(2, sf.getId());
}
Also used : Message(org.apache.cxf.message.Message) Customer(org.apache.cxf.jaxrs.Customer) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) URITemplate(org.apache.cxf.jaxrs.model.URITemplate) SimpleFactory(org.apache.cxf.jaxrs.SimpleFactory) PathSegment(javax.ws.rs.core.PathSegment) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) PathSegmentImpl(org.apache.cxf.jaxrs.impl.PathSegmentImpl) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Test(org.junit.Test)

Aggregations

MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)80 Test (org.junit.Test)43 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)36 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)34 ByteArrayInputStream (java.io.ByteArrayInputStream)25 Message (org.apache.cxf.message.Message)25 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)15 List (java.util.List)13 Method (java.lang.reflect.Method)12 ArrayList (java.util.ArrayList)11 Map (java.util.Map)10 Endpoint (org.apache.cxf.endpoint.Endpoint)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 LinkedHashMap (java.util.LinkedHashMap)9 Customer (org.apache.cxf.jaxrs.Customer)9 WebClient (org.apache.cxf.jaxrs.client.WebClient)9 Annotation (java.lang.annotation.Annotation)8 HashMap (java.util.HashMap)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 URITemplate (org.apache.cxf.jaxrs.model.URITemplate)7