use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JAXBElementProviderTest method testOutAppendElementsDiffNs.
@Test
public void testOutAppendElementsDiffNs() throws Exception {
JAXBElementProvider<TagVO2> provider = new JAXBElementProvider<TagVO2>();
Map<String, String> prefixes = new HashMap<>();
prefixes.put("http://tags", "ns2");
provider.setNamespacePrefixes(prefixes);
Map<String, String> map = new HashMap<>();
map.put("{http://tags}thetag", "{http://tagsvo2}t");
provider.setOutAppendElements(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 = "<?xml version='1.0' encoding='UTF-8'?><ps1:t xmlns:ps1=\"http://tagsvo2\">" + "<ns2:thetag xmlns:ns2=\"http://tags\"><group>B</group><name>A</name></ns2:thetag></ps1:t>";
assertEquals(expected, bos.toString());
}
use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JAXBElementProviderTest method testOutElementsMapLocalNsToLocalNs.
@Test
public void testOutElementsMapLocalNsToLocalNs() throws Exception {
JAXBElementProvider<TagVO2> provider = new JAXBElementProvider<TagVO2>();
Map<String, String> prefixes = new HashMap<>();
prefixes.put("http://tags", "ns2");
provider.setNamespacePrefixes(prefixes);
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 = "<?xml version='1.0' encoding='UTF-8'?>" + "<ns2:t xmlns:ns2=\"http://tagsvo2\"><group>B</group><name>A</name></ns2:t>";
assertEquals(expected, bos.toString());
}
use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JAXBElementProviderTest method testInNsElementsFromLocals.
@Test
public void testInNsElementsFromLocals() 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 HashMap<>();
map.put("tagholder", "{http://tags}tagholder");
map.put("thetag", "{http://tags}thetag");
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 JAXBElementProviderTest method testOutAttributesAsElements.
@Test
public void testOutAttributesAsElements() throws Exception {
JAXBElementProvider<TagVO2Holder> provider = new JAXBElementProvider<TagVO2Holder>();
Map<String, String> map = new HashMap<>();
map.put("{http://tags}thetag", "thetag");
map.put("{http://tags}tagholder", "tagholder");
provider.setOutTransformElements(map);
provider.setAttributesToElements(true);
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'?><tagholder><attr>attribute</attr>" + "<thetag><group>B</group><name>A</name></thetag></tagholder>";
assertEquals(expected, bos.toString());
}
use of org.apache.cxf.jaxrs.resources.TagVO2 in project cxf by apache.
the class JAXBElementProviderTest method testOutElementsMapLocalNsToLocal.
@Test
public void testOutElementsMapLocalNsToLocal() throws Exception {
JAXBElementProvider<TagVO2> provider = new JAXBElementProvider<TagVO2>();
Map<String, String> map = new HashMap<>();
map.put("{http://tags}thetag", "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 = "<?xml version='1.0' encoding='UTF-8'?>" + "<t><group>B</group><name>A</name></t>";
assertEquals(expected, bos.toString());
}
Aggregations