Search in sources :

Example 36 with TagVO2

use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.

the class JAXBElementProviderTest method doReadQualifiedCollection.

@SuppressWarnings("unchecked")
public void doReadQualifiedCollection(String data, boolean isArray) throws Exception {
    @SuppressWarnings("rawtypes") JAXBElementProvider provider = new JAXBElementProvider();
    Method m = null;
    if (!isArray) {
        m = CollectionsResource.class.getMethod("setTags", new Class[] { List.class });
    } else {
        m = CollectionsResource.class.getMethod("setTagsArray", new Class[] { TagVO2[].class });
    }
    ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
    Object o = provider.readFrom(m.getParameterTypes()[0], m.getGenericParameterTypes()[0], new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, String>(), is);
    assertNotNull(o);
    TagVO2 t1 = null;
    TagVO2 t2 = null;
    if (!isArray) {
        assertEquals(2, ((List<?>) o).size());
        t1 = (TagVO2) ((List<?>) o).get(0);
        t2 = (TagVO2) ((List<?>) o).get(1);
    } else {
        assertEquals(2, ((Object[]) o).length);
        t1 = (TagVO2) ((Object[]) o)[0];
        t2 = (TagVO2) ((Object[]) o)[1];
    }
    assertEquals("A", t1.getName());
    assertEquals("B", t1.getGroup());
    assertEquals("C", t2.getName());
    assertEquals("D", t2.getGroup());
}
Also used : TagVO2(org.apache.cxf.jaxrs.resources.TagVO2) ByteArrayInputStream(java.io.ByteArrayInputStream) CollectionsResource(org.apache.cxf.jaxrs.resources.CollectionsResource) List(java.util.List) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method)

Example 37 with TagVO2

use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.

the class JAXBElementProviderTest method testWriteQualifiedCollection.

@Test
public void testWriteQualifiedCollection() throws Exception {
    JAXBElementProvider<List<TagVO2>> provider = new JAXBElementProvider<List<TagVO2>>();
    provider.setCollectionWrapperName("{http://tags}tags");
    List<TagVO2> tags = new ArrayList<>();
    tags.add(new TagVO2("A", "B"));
    tags.add(new TagVO2("C", "D"));
    Method m = CollectionsResource.class.getMethod("getTags", new Class[0]);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    provider.writeTo(tags, m.getReturnType(), m.getGenericReturnType(), new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
    doReadQualifiedCollection(bos.toString(), false);
}
Also used : TagVO2(org.apache.cxf.jaxrs.resources.TagVO2) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 38 with TagVO2

use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.

the class JAXBElementProviderTest method readTagVO2AfterTransform.

private void readTagVO2AfterTransform(String data, String keyValue) throws Exception {
    JAXBElementProvider<TagVO2> provider = new JAXBElementProvider<TagVO2>();
    Map<String, String> map = new HashMap<>();
    map.put(keyValue, "{http://tags}thetag");
    provider.setInTransformElements(map);
    ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
    Object o = provider.readFrom(TagVO2.class, TagVO2.class, new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, String>(), is);
    TagVO2 tag2 = (TagVO2) o;
    assertEquals("A", tag2.getName());
    assertEquals("B", tag2.getGroup());
}
Also used : TagVO2(org.apache.cxf.jaxrs.resources.TagVO2) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

TagVO2 (org.apache.cxf.jaxrs.resources.TagVO2)38 Test (org.junit.Test)31 ByteArrayOutputStream (java.io.ByteArrayOutputStream)28 HashMap (java.util.HashMap)27 LinkedHashMap (java.util.LinkedHashMap)13 ByteArrayInputStream (java.io.ByteArrayInputStream)10 ArrayList (java.util.ArrayList)9 List (java.util.List)7 Method (java.lang.reflect.Method)4 LinkedList (java.util.LinkedList)3 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 MediaType (javax.ws.rs.core.MediaType)2 XmlType (javax.xml.bind.annotation.XmlType)2 CollectionsResource (org.apache.cxf.jaxrs.resources.CollectionsResource)2 ParameterizedCollectionType (org.apache.cxf.jaxrs.utils.ParameterizedCollectionType)2 OutputStream (java.io.OutputStream)1 XmlAccessType (javax.xml.bind.annotation.XmlAccessType)1 XmlAccessorType (javax.xml.bind.annotation.XmlAccessorType)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1