use of com.zimbra.soap.jaxb.NamespaceDeltaElem in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method elemsInDiffNamespace.
/**
* Desired JSON :
* {
* "strAttrStrElem": [{
* "attribute-1": "My attribute ONE",
* "element1": [{
* "_content": "My element ONE",
* "_jsns": "urn:ZimbraTest3"
* }],
* "_jsns": "urn:ZimbraTest5"
* }],
* "_jsns": "urn:ZimbraTest4"
* }
*/
@Test
public void elemsInDiffNamespace() throws Exception {
final String attr1Val = "My attribute ONE";
final String elem1Val = "My element ONE";
Element jsonElem = JSONElement.mFactory.createElement(QName.get("ns-delta", "urn:ZimbraTest4"));
Element saseElem = jsonElem.addNonUniqueElement(QName.get("strAttrStrElem", "urn:ZimbraTest5"));
saseElem.addAttribute("attribute-1", attr1Val);
saseElem.addNonUniqueElement(QName.get("element1", "urn:ZimbraTest3")).addText(elem1Val);
logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
NamespaceDeltaElem tstr = new NamespaceDeltaElem();
StringAttrStringElem tstrSase = new StringAttrStringElem();
tstrSase.setAttr1(attr1Val);
tstrSase.setElem1(elem1Val);
tstr.setSase(tstrSase);
Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(tstr);
logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
NamespaceDeltaElem roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, NamespaceDeltaElem.class);
Element saseJsonJaxbElem = jsonJaxbElem.getElement(QName.get("strAttrStrElem", "urn:ZimbraTest5"));
Assert.assertEquals("JSONElement attr1", attr1Val, saseJsonJaxbElem.getAttribute("attribute-1"));
Assert.assertEquals("JSONElement elem1", elem1Val, saseJsonJaxbElem.getElement("element1").getText());
logDebug("roundtripped attr1=%1$s", roundtripped.getSase().getAttr1());
logDebug("roundtripped elem1=%1$s", roundtripped.getSase().getElem1());
Assert.assertEquals("roundtripped attr1", attr1Val, roundtripped.getSase().getAttr1());
Assert.assertEquals("roundtripped elem1", elem1Val, roundtripped.getSase().getElem1());
Assert.assertEquals("prettyPrint", jsonElem.prettyPrint(), jsonJaxbElem.prettyPrint());
}
Aggregations