use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSUtilsTest method testArrayParamNoProvider.
@Test
public void testArrayParamNoProvider() throws Exception {
Message messageImpl = createMessage();
Class<?>[] argType = { String[].class };
Method m = Customer.class.getMethod("testCustomerParam2", argType);
messageImpl.put(Message.QUERY_STRING, "p1=Fred&p1=Barry");
List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
assertEquals(1, params.size());
String[] values = (String[]) params.get(0);
assertEquals("Fred", values[0]);
assertEquals("Barry", values[1]);
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSUtilsTest method doTestFormParameters.
@SuppressWarnings("unchecked")
private void doTestFormParameters(boolean useMediaType) throws Exception {
Class<?>[] argType = { String.class, List.class };
Method m = Customer.class.getMethod("testFormParam", argType);
Message messageImpl = createMessage();
String body = "p1=hello%2bworld&p2=2&p2=3";
messageImpl.put(Message.REQUEST_URI, "/foo");
MultivaluedMap<String, String> headers = new MetadataMap<>();
if (useMediaType) {
headers.putSingle("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
}
messageImpl.put(Message.PROTOCOL_HEADERS, headers);
messageImpl.setContent(InputStream.class, new ByteArrayInputStream(body.getBytes()));
List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
assertEquals("2 form params should've been identified", 2, params.size());
assertEquals("First Form Parameter not matched correctly", "hello+world", params.get(0));
List<String> list = (List<String>) params.get(1);
assertEquals(2, list.size());
assertEquals("2", list.get(0));
assertEquals("3", list.get(1));
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSUtilsTest method testDefaultValueOnField.
@Test
public void testDefaultValueOnField() 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();
m.put(Message.QUERY_STRING, "");
JAXRSUtils.injectParameters(ori, c, m);
assertEquals("bQuery", c.getB());
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSUtilsTest method testFromStringParameters.
@Test
public void testFromStringParameters() throws Exception {
Class<?>[] argType = { UUID.class, CustomerGender.class, CustomerGender.class };
Method m = Customer.class.getMethod("testFromStringParam", argType);
UUID u = UUID.randomUUID();
Message messageImpl = createMessage();
messageImpl.put(Message.QUERY_STRING, "p1=" + u.toString() + "&p2=1&p3=2");
List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
assertEquals(3, params.size());
assertEquals("Query UUID Parameter was not matched correctly", u.toString(), params.get(0).toString());
assertSame(CustomerGender.FEMALE, params.get(1));
assertSame(CustomerGender.MALE, params.get(2));
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSUtilsTest method testXmlAdapterBean.
@Test
public void testXmlAdapterBean() throws Exception {
Class<?>[] argType = { Customer.CustomerBean.class };
Method m = Customer.class.getMethod("testXmlAdapter", 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());
}
Aggregations