use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JAXBElementProviderTest method testWriteCollectionWithCustomPrefixes.
@Test
public void testWriteCollectionWithCustomPrefixes() throws Exception {
JAXBElementProvider<List<TagVO2>> provider = new JAXBElementProvider<List<TagVO2>>();
provider.setNamespacePrefixes(Collections.singletonMap("http://tags", "prefix"));
TagVO2 tag = new TagVO2("a", "b");
List<TagVO2> tags = Collections.singletonList(tag);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
provider.writeTo(tags, List.class, new ParameterizedCollectionType(TagVO2.class), new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
assertTrue(bos.toString().contains("prefix:thetag"));
assertFalse(bos.toString().contains("ns1:thetag"));
}
use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JAXBElementProviderTest method testWriteWithCustomPrefixes.
@Test
public void testWriteWithCustomPrefixes() throws Exception {
JAXBElementProvider<TagVO2> provider = new JAXBElementProvider<TagVO2>();
provider.setNamespacePrefixes(Collections.singletonMap("http://tags", "prefix"));
TagVO2 tag = new TagVO2("a", "b");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
provider.writeTo(tag, TagVO2.class, TagVO2.class, new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
assertTrue(bos.toString().contains("prefix:thetag"));
}
use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JAXBElementProviderTest method testOutElementsMapLocalNsToLocalWildcard2.
@Test
public void testOutElementsMapLocalNsToLocalWildcard2() throws Exception {
JAXBElementProvider<TagVO2Holder> provider = new JAXBElementProvider<TagVO2Holder>();
Map<String, String> prefixes = new HashMap<>();
prefixes.put("http://tags", "ns2");
provider.setNamespacePrefixes(prefixes);
Map<String, String> map = new HashMap<>();
map.put("{http://tags}*", "{http://tags2}*");
provider.setOutTransformElements(map);
TagVO2 tag = new TagVO2("A", "B");
TagVO2Holder holder = new TagVO2Holder();
holder.setTag(tag);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
provider.writeTo(holder, TagVO2Holder.class, TagVO2Holder.class, new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
String expected = "<?xml version='1.0' encoding='UTF-8'?>" + "<ns2:tagholder xmlns:ns2=\"http://tags2\" attr=\"attribute\"><ns2:thetag><group>B</group>" + "<name>A</name></ns2:thetag></ns2:tagholder>";
assertEquals(expected, bos.toString());
}
use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JAXBElementProviderTest method testInNsElementsFromLocalsWildcard.
@Test
public void testInNsElementsFromLocalsWildcard() throws Exception {
String data = "<?xml version='1.0' encoding='UTF-8'?>" + "<tagholder><thetag><group>B</group><name>A</name></thetag></tagholder>";
JAXBElementProvider<TagVO2Holder> provider = new JAXBElementProvider<TagVO2Holder>();
Map<String, String> map = new LinkedHashMap<String, String>();
map.put("group", "group");
map.put("name", "name");
map.put("*", "{http://tags}*");
provider.setInTransformElements(map);
ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
Object o = provider.readFrom(TagVO2Holder.class, TagVO2Holder.class, new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, String>(), is);
TagVO2Holder holder = (TagVO2Holder) o;
TagVO2 tag2 = holder.getTagValue();
assertEquals("A", tag2.getName());
assertEquals("B", tag2.getGroup());
}
use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JSONProviderTest method testOutElementsMapLocalNsToLocalNs.
@Test
public void testOutElementsMapLocalNsToLocalNs() throws Exception {
JSONProvider<TagVO2> provider = new JSONProvider<TagVO2>();
Map<String, String> namespaceMap = new HashMap<>();
namespaceMap.put("http://tags", "ns2");
provider.setNamespaceMap(namespaceMap);
Map<String, String> map = new HashMap<>();
map.put("{http://tags}thetag", "{http://tagsvo2}t");
provider.setOutTransformElements(map);
TagVO2 tag = new TagVO2("A", "B");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
provider.writeTo(tag, TagVO2.class, TagVO2.class, new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
String expected = "{\"ns2.t\":{\"group\":\"B\",\"name\":\"A\"}}";
assertEquals(expected, bos.toString());
}
Aggregations