Search in sources :

Example 1 with Customer2

use of org.apache.cxf.jaxrs.Customer2 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)

Aggregations

Method (java.lang.reflect.Method)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Customer (org.apache.cxf.jaxrs.Customer)1 Customer2 (org.apache.cxf.jaxrs.Customer2)1 CustomerParameterHandler (org.apache.cxf.jaxrs.CustomerParameterHandler)1 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)1 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)1 Message (org.apache.cxf.message.Message)1 Test (org.junit.Test)1