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
}
}
Aggregations