use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSUtilsTest method verifyParametersBean.
private void verifyParametersBean(Method m, MultivaluedMap<String, String> simpleValues, Message simpleMessageImpl, MultivaluedMap<String, String> complexValues, Message complexMessageImpl) throws Exception {
List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), simpleValues, simpleMessageImpl);
assertEquals("Bean should be created", 1, params.size());
Customer.CustomerBean cb = (Customer.CustomerBean) params.get(0);
assertNotNull(cb);
assertEquals("aValue", cb.getA());
assertEquals(Long.valueOf(123), cb.getB());
params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), complexValues, complexMessageImpl);
assertEquals("Bean should be created", 1, params.size());
Customer.CustomerBean cb1 = (Customer.CustomerBean) params.get(0);
assertNotNull(cb1);
assertEquals("A", cb1.getA());
assertEquals(Long.valueOf(123), cb1.getB());
List<String> list1 = cb1.getC();
assertEquals(3, list1.size());
assertEquals("1", list1.get(0));
assertEquals("2", list1.get(1));
assertEquals("3", list1.get(2));
Customer.CustomerBean cb2 = cb1.getD();
assertNotNull(cb2);
assertEquals("B", cb2.getA());
assertEquals(Long.valueOf(456), cb2.getB());
List<String> list2 = cb2.getC();
assertEquals(3, list2.size());
assertEquals("4", list2.get(0));
assertEquals("5", list2.get(1));
assertEquals("6", list2.get(2));
List<Customer.CustomerBean> cb2List = cb1.e;
assertEquals(2, cb2List.size());
int idx = 1;
for (Customer.CustomerBean cb2E : cb2List) {
assertNotNull(cb2E);
assertEquals("B" + idx, cb2E.getA());
assertEquals(Long.valueOf(456 + idx), cb2E.getB());
// ensure C was stripped properly since lists within lists are not supported
assertNull(cb2E.getC());
assertNull(cb2E.getD());
assertNull(cb2E.e);
idx++;
}
Customer.CustomerBean cb3 = cb2.getD();
assertNotNull(cb3);
assertEquals("C", cb3.getA());
assertEquals(Long.valueOf(789), cb3.getB());
List<String> list3 = cb3.getC();
assertEquals(3, list3.size());
assertEquals("7", list3.get(0));
assertEquals("8", list3.get(1));
assertEquals("9", list3.get(2));
List<Customer.CustomerBean> cb3List = cb2.e;
assertEquals(2, cb3List.size());
idx = 1;
for (Customer.CustomerBean cb3E : cb3List) {
assertNotNull(cb3E);
assertEquals("C" + idx, cb3E.getA());
assertEquals(Long.valueOf(789 + idx), cb3E.getB());
// ensure C was stripped properly since lists within lists are not supported
assertNull(cb3E.getC());
assertNull(cb3E.getD());
assertNull(cb3E.e);
idx++;
}
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSUtilsTest method testXmlAdapterString.
@Test
public void testXmlAdapterString() throws Exception {
Method m = Customer.class.getMethod("testXmlAdapter4", String.class);
Message messageImpl = createMessage();
messageImpl.put(Message.QUERY_STRING, "a=3");
List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
assertEquals(1, params.size());
String ret = (String) params.get(0);
assertEquals("Val: 3", ret);
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo 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<>();
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());
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSUtilsTest method invokeCustomerMethod.
private void invokeCustomerMethod(ClassResourceInfo cri, Customer customer, Server server) throws Exception {
OperationResourceInfo ori = cri.getMethodDispatcher().getOperationResourceInfo(Customer.class.getMethod("test", new Class[] {}));
JAXRSInvoker invoker = new JAXRSInvoker();
Exchange exc = new ExchangeImpl();
exc.put(Endpoint.class, server.getEndpoint());
Message inMessage = new MessageImpl();
exc.setInMessage(inMessage);
exc.put(OperationResourceInfo.class, ori);
invoker.invoke(exc, Collections.emptyList(), customer);
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSUtilsTest method testContextResolverParam.
@Test
public void testContextResolverParam() throws Exception {
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethod("testContextResolvers", new Class[] { ContextResolver.class }), cri);
ori.setHttpMethod("GET");
Message m = createMessage();
ContextResolver<JAXBContext> cr = new JAXBContextProvider();
ProviderFactory.getInstance(m).registerUserProvider(cr);
m.put(Message.BASE_PATH, "/");
List<Object> params = JAXRSUtils.processParameters(ori, new MetadataMap<String, String>(), m);
assertEquals("1 parameters expected", 1, params.size());
assertSame(cr.getClass(), params.get(0).getClass());
}
Aggregations