Search in sources :

Example 1 with MyType

use of org.apache.cxf.jaxrs.Customer.MyType in project cxf by apache.

the class JAXRSUtilsTest method testQueryParamAsListWithDefaultValue.

@SuppressWarnings("unchecked")
@Test
public void testQueryParamAsListWithDefaultValue() throws Exception {
    Class<?>[] argType = { List.class, List.class, List.class, Integer[].class, List.class, List.class, List.class, List.class, List.class };
    Method m = Customer.class.getMethod("testQueryAsList", argType);
    Message messageImpl = createMessage();
    ProviderFactory.getInstance(messageImpl).registerUserProvider(new MyTypeParamConverterProvider());
    messageImpl.put(Message.QUERY_STRING, "query2=query2Value&query2=query2Value2&query3=1&query3=2&query4=");
    List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
    assertEquals(9, params.size());
    List<String> queryList = (List<String>) params.get(0);
    assertNotNull(queryList);
    assertEquals(1, queryList.size());
    assertEquals("default", queryList.get(0));
    List<String> queryList2 = (List<String>) params.get(1);
    assertNotNull(queryList2);
    assertEquals(2, queryList2.size());
    assertEquals("query2Value", queryList2.get(0));
    assertEquals("query2Value2", queryList2.get(1));
    List<Integer> queryList3 = (List<Integer>) params.get(2);
    assertNotNull(queryList3);
    assertEquals(2, queryList3.size());
    assertEquals(Integer.valueOf(1), queryList3.get(0));
    assertEquals(Integer.valueOf(2), queryList3.get(1));
    Integer[] queryList3Array = (Integer[]) params.get(3);
    assertNotNull(queryList3Array);
    assertEquals(2, queryList3Array.length);
    assertEquals(Integer.valueOf(1), queryList3Array[0]);
    assertEquals(Integer.valueOf(2), queryList3Array[1]);
    List<String> queryList4 = (List<String>) params.get(4);
    assertNotNull(queryList4);
    assertEquals(1, queryList4.size());
    assertEquals("", queryList4.get(0));
    List<String> queryList5 = (List<String>) params.get(5);
    assertNotNull(queryList5);
    assertEquals(0, queryList5.size());
    List<MyType<Integer>> queryList6 = (List<MyType<Integer>>) params.get(6);
    assertNotNull(queryList6);
    assertEquals(2, queryList6.size());
    assertEquals(Integer.valueOf(1), queryList6.get(0).get());
    assertEquals(Integer.valueOf(2), queryList6.get(1).get());
    List<Long> queryList7 = (List<Long>) params.get(7);
    assertNotNull(queryList7);
    assertEquals(2, queryList7.size());
    assertEquals(1L, queryList7.get(0).longValue());
    assertEquals(2L, queryList7.get(1).longValue());
    List<Double> queryList8 = (List<Double>) params.get(8);
    assertNotNull(queryList8);
    assertEquals(2, queryList8.size());
    assertEquals(1., queryList8.get(0), 0.);
    assertEquals(2., queryList8.get(1), 0.);
}
Also used : Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) Method(java.lang.reflect.Method) MyType(org.apache.cxf.jaxrs.Customer.MyType) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MyType (org.apache.cxf.jaxrs.Customer.MyType)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