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