Search in sources :

Example 31 with OperationResourceInfo

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

the class JAXRSUtilsTest method testAcceptTypesMatch.

@Test
public void testAcceptTypesMatch() throws Exception {
    Method m = Customer.class.getMethod("test", new Class[] {});
    ClassResourceInfo cr = new ClassResourceInfo(Customer.class);
    assertTrue("text/xml can not be matched", JAXRSUtils.matchMimeTypes(JAXRSUtils.ALL_TYPES, new MediaType("text", "xml"), new OperationResourceInfo(m, cr)));
    assertTrue("text/xml can not be matched", JAXRSUtils.matchMimeTypes(JAXRSUtils.ALL_TYPES, new MediaType("text", "*"), new OperationResourceInfo(m, cr)));
    assertTrue("text/xml can not be matched", JAXRSUtils.matchMimeTypes(JAXRSUtils.ALL_TYPES, new MediaType("*", "*"), new OperationResourceInfo(m, cr)));
    assertFalse("text/plain was matched", JAXRSUtils.matchMimeTypes(JAXRSUtils.ALL_TYPES, new MediaType("text", "plain"), new OperationResourceInfo(m, cr)));
}
Also used : ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) MediaType(javax.ws.rs.core.MediaType) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 32 with OperationResourceInfo

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

the class JAXRSUtilsTest method testCustomerParameter.

@Test
public void testCustomerParameter() throws Exception {
    Message messageImpl = createMessage();
    ServerProviderFactory.getInstance(messageImpl).registerUserProvider(new CustomerParameterHandler());
    Class<?>[] argType = { Customer.class, Customer[].class, Customer2.class };
    Method m = Customer.class.getMethod("testCustomerParam", argType);
    messageImpl.put(Message.QUERY_STRING, "p1=Fred&p2=Barry&p3=Jack&p4=John");
    List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
    assertEquals(3, params.size());
    Customer c = (Customer) params.get(0);
    assertEquals("Fred", c.getName());
    Customer c2 = ((Customer[]) params.get(1))[0];
    assertEquals("Barry", c2.getName());
    Customer2 c3 = (Customer2) params.get(2);
    assertEquals("Jack", c3.getName());
    try {
        messageImpl.put(Message.QUERY_STRING, "p3=noName");
        JAXRSUtils.processParameters(new OperationResourceInfo(m, null), null, messageImpl);
        fail("Customer2 constructor does not accept names starting with lower-case chars");
    } catch (Exception ex) {
    // expected
    }
}
Also used : Message(org.apache.cxf.message.Message) Customer2(org.apache.cxf.jaxrs.Customer2) Customer(org.apache.cxf.jaxrs.Customer) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Method(java.lang.reflect.Method) WebApplicationException(javax.ws.rs.WebApplicationException) CustomerParameterHandler(org.apache.cxf.jaxrs.CustomerParameterHandler) Test(org.junit.Test)

Example 33 with OperationResourceInfo

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

the class JAXRSUtilsTest method testQueryParametersIntegerArrayValueIsColection.

@Test
public void testQueryParametersIntegerArrayValueIsColection() throws Exception {
    Class<?>[] argType = { Integer[].class };
    Method m = Customer.class.getMethod("testQueryIntegerArray", argType);
    Message messageImpl = createMessage();
    messageImpl.put("parse.query.value.as.collection", true);
    messageImpl.put(Message.QUERY_STRING, "query=1&query=2,3");
    List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
    assertEquals(1, params.size());
    Integer[] intValues = (Integer[]) params.get(0);
    assertEquals(3, intValues.length);
    assertEquals(1, (int) intValues[0]);
    assertEquals(2, (int) intValues[1]);
    assertEquals(3, (int) intValues[2]);
}
Also used : Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 34 with OperationResourceInfo

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

the class JAXRSUtilsTest method testXmlAdapterBean2.

@Test
public void testXmlAdapterBean2() throws Exception {
    Class<?>[] argType = { Customer.CustomerBean.class };
    Method m = Customer.class.getMethod("testXmlAdapter2", argType);
    Message messageImpl = createMessage();
    messageImpl.put(Message.QUERY_STRING, "a=aValue");
    List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
    assertEquals(1, params.size());
    Customer.CustomerBean bean = (Customer.CustomerBean) params.get(0);
    assertEquals("aValue", bean.getA());
}
Also used : 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) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 35 with OperationResourceInfo

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

the class JAXRSUtilsTest method testQueryParameter.

@Test
public void testQueryParameter() throws Exception {
    Message messageImpl = createMessage();
    ProviderFactory.getInstance(messageImpl).registerUserProvider(new GenericObjectParameterHandler());
    Class<?>[] argType = { Query.class };
    Method m = Customer.class.getMethod("testGenericObjectParam", argType);
    messageImpl.put(Message.QUERY_STRING, "p1=thequery");
    List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
    assertEquals(1, params.size());
    @SuppressWarnings("unchecked") Query<String> query = (Query<String>) params.get(0);
    assertEquals("thequery", query.getEntity());
}
Also used : Message(org.apache.cxf.message.Message) Query(org.apache.cxf.jaxrs.Customer.Query) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) Method(java.lang.reflect.Method) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Test(org.junit.Test)

Aggregations

OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)130 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)105 Message (org.apache.cxf.message.Message)72 Test (org.junit.Test)70 Method (java.lang.reflect.Method)53 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)40 Customer (org.apache.cxf.jaxrs.Customer)22 ArrayList (java.util.ArrayList)13 List (java.util.List)13 Endpoint (org.apache.cxf.endpoint.Endpoint)13 MessageImpl (org.apache.cxf.message.MessageImpl)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)11 Response (javax.ws.rs.core.Response)11 URITemplate (org.apache.cxf.jaxrs.model.URITemplate)11 Exchange (org.apache.cxf.message.Exchange)11 MediaType (javax.ws.rs.core.MediaType)10 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)10 MethodDispatcher (org.apache.cxf.jaxrs.model.MethodDispatcher)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)7