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)));
}
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
}
}
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]);
}
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());
}
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());
}
Aggregations