use of com.zimbra.soap.jaxb.StringAttribIntValue in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method elementRefHandling.
/**
* XmlElementRef handling. Note that slightly counter-intuitively, any name specified is ignored (unless
* type=JAXBElement.class)
* <pre>
* @XmlElementRef(name="ignored-name-root-elem-name-used-instead", type=StringAttribIntValue.class)
* private StringAttribIntValue byRef;
* </pre>
* Desired JSON :
* {
* "string-attr-int-value": [{
* "attr1": "my string",
* "_content": 321
* }],
* "_jsns": "urn:zimbraTest"
* }
*/
@Test
public void elementRefHandling() throws Exception {
String str = "my string";
int num = 321;
ElementRefTester jaxb = new ElementRefTester();
StringAttribIntValue inner = new StringAttribIntValue(str, num);
jaxb.setByRef(inner);
Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(jaxb);
Element xmlElem = JaxbUtil.jaxbToElement(jaxb, Element.XMLElement.mFactory, true, false);
logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
logDebug("XmlElement (for comparison) ---> prettyPrint\n%1$s", xmlElem.prettyPrint());
ElementRefTester roundtrippedX = JaxbUtil.elementToJaxb(xmlElem, ElementRefTester.class);
ElementRefTester roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, ElementRefTester.class);
StringAttribIntValue rtByRef = roundtripped.getByRef();
StringAttribIntValue rtXmlByRef = roundtrippedX.getByRef();
Assert.assertEquals("roundtrippedX str", str, rtXmlByRef.getAttrib1());
Assert.assertEquals("roundtrippedX num", num, rtXmlByRef.getMyValue());
Assert.assertEquals("roundtripped str", str, rtByRef.getAttrib1());
Assert.assertEquals("roundtripped num", num, rtByRef.getMyValue());
}
use of com.zimbra.soap.jaxb.StringAttribIntValue in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method uniqeElementHandling.
/**
* A JSON element added via {@code addNonUniqueElement} is always serialized as an array, because there could be
* further {@code addNonUniqueElement} calls with the same element name. On the other hand, a JSON element added via
* {@code addUniqueElement} won't be serialized as an array as their is an implicit assumption that there will
* be only one element with that name.
* Desired JSON :
* {
* "unique-str-elem": {
* "_content": "Unique element ONE",
* "_jsns": "urn:zimbraTest1"
* },
* "non-unique-elem": [{
* "_content": "Unique element ONE",
* "_jsns": "urn:zimbraTest1"
* }],
* "unique-complex-elem": {
* "attr1": "Attribute ONE",
* "_content": "3"
* },
* "_jsns": "urn:zimbraTest"
* }
*/
@Test
public void uniqeElementHandling() throws Exception {
final String elem1 = "Unique element ONE";
final String attrib1 = "Attribute ONE";
final int value = 3;
final String valueStr = new Integer(value).toString();
Element jsonElem = JSONElement.mFactory.createElement(QName.get("unique-tester", "urn:zimbraTest"));
jsonElem.addUniqueElement(QName.get("unique-str-elem", "urn:zimbraTest1")).setText(elem1);
jsonElem.addNonUniqueElement(QName.get("non-unique-elem", "urn:zimbraTest1")).setText(elem1);
jsonElem.addUniqueElement("unique-complex-elem").addAttribute("attr1", attrib1).setText(valueStr);
logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
UniqueTester tstr = new UniqueTester();
tstr.setUniqueStrElem(elem1);
tstr.setNonUniqueStrElem(elem1);
StringAttribIntValue complex = new StringAttribIntValue(attrib1, value);
tstr.setUniqueComplexElem(complex);
Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(tstr);
logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
UniqueTester roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, UniqueTester.class);
Assert.assertEquals("roundtripped non-unique elem", elem1, roundtripped.getNonUniqueStrElem());
Assert.assertEquals("roundtripped unique elem", elem1, roundtripped.getUniqueStrElem());
StringAttribIntValue roundtrippedComplex = tstr.getUniqueComplexElem();
Assert.assertEquals("roundtripped complex attrib1", attrib1, roundtrippedComplex.getAttrib1());
Assert.assertEquals("roundtripped complex value", value, roundtrippedComplex.getMyValue());
}
use of com.zimbra.soap.jaxb.StringAttribIntValue in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method stringAttrintValue.
/**
* Desired JSON :
* {
* "attr1": "Attribute ONE",
* "_content": "3",
* "_jsns": "urn:zimbraTest"
* }
*/
@Test
public void stringAttrintValue() throws Exception {
final String attrib1 = "Attribute ONE";
final int value = 3;
final String valueStr = new Integer(value).toString();
Element jsonElem = JSONElement.mFactory.createElement(QName.get("string-attr-int-value", "urn:zimbraTest"));
jsonElem.addAttribute("attr1", attrib1);
jsonElem.addText(valueStr);
StringAttribIntValue tstr = new StringAttribIntValue(attrib1, value);
Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(tstr);
StringAttribIntValue roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, StringAttribIntValue.class);
logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
Assert.assertEquals("attr1", attrib1, jsonJaxbElem.getAttribute("attr1"));
Assert.assertEquals("XmlValue", valueStr, jsonJaxbElem.getText());
Assert.assertEquals("roundtripped attrib1", attrib1, roundtripped.getAttrib1());
Assert.assertEquals("roundtripped value", value, roundtripped.getMyValue());
}
use of com.zimbra.soap.jaxb.StringAttribIntValue in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method elementRefsHandling.
/**
* XmlElementRefs handling
* Desired JSON :
* {
* "string-attr-int-value": [{
* "attr1": "my string",
* "_content": 321
* }],
* "enumEttribs": [{
* "fold1": "chat",
* "fold2": "remote folder"
* }],
* "_jsns": "urn:zimbraTest"
* }
*/
@Test
public void elementRefsHandling() throws Exception {
String str = "my string";
int num = 321;
List<Object> elems = Lists.newArrayList();
ElementRefsTester jaxb = new ElementRefsTester();
StringAttribIntValue inner = new StringAttribIntValue(str, num);
elems.add(inner);
EnumAttribs ea = new EnumAttribs();
ea.setFold1(ViewEnum.CHAT);
ea.setFold2(ViewEnum.REMOTE_FOLDER);
elems.add(ea);
jaxb.setElems(elems);
Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(jaxb);
Element xmlElem = JaxbUtil.jaxbToElement(jaxb, Element.XMLElement.mFactory, true, false);
logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
logDebug("XmlElement (for comparison) ---> prettyPrint\n%1$s", xmlElem.prettyPrint());
ElementRefsTester roundtrippedX = JaxbUtil.elementToJaxb(xmlElem, ElementRefsTester.class);
ElementRefsTester roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, ElementRefsTester.class);
Assert.assertEquals("roundtrippedX num elems", 2, roundtrippedX.getElems().size());
Assert.assertEquals("roundtripped num elems", 2, roundtripped.getElems().size());
StringAttribIntValue rtByRef = (StringAttribIntValue) roundtripped.getElems().get(0);
StringAttribIntValue rtXmlByRef = (StringAttribIntValue) roundtrippedX.getElems().get(0);
Assert.assertEquals("roundtrippedX str", str, rtXmlByRef.getAttrib1());
Assert.assertEquals("roundtrippedX num", num, rtXmlByRef.getMyValue());
Assert.assertEquals("roundtripped str", str, rtByRef.getAttrib1());
Assert.assertEquals("roundtripped num", num, rtByRef.getMyValue());
EnumAttribs rtea = (EnumAttribs) roundtripped.getElems().get(1);
Assert.assertEquals("roundtripped fold1", ViewEnum.CHAT, rtea.getFold1());
Assert.assertEquals("roundtripped fold2", ViewEnum.REMOTE_FOLDER, rtea.getFold2());
}
use of com.zimbra.soap.jaxb.StringAttribIntValue in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method mixedHandlingWithJaxbAndNoText.
/**
* {@link XmlMixed} handling
* In the places we use XmlMixed, we have either just text or just elements
* This tests where we have something that maps to a JAXB object.
* Side note: Also tests out case for {@link XmlElementRef} where name is derived from root element.
*/
@Test
public void mixedHandlingWithJaxbAndNoText() throws Exception {
String str = "my string";
int num = 321;
List<Object> elems = Lists.newArrayList();
MixedTester jaxb = new MixedTester();
StringAttribIntValue inner = new StringAttribIntValue(str, num);
elems.add(inner);
jaxb.setElems(elems);
Element xmlElem = JaxbUtil.jaxbToElement(jaxb, Element.XMLElement.mFactory, true, false);
logDebug("XmlElement (for comparison) [Mixed has element] ---> prettyPrint\n%1$s", xmlElem.prettyPrint());
MixedTester roundtrippedX = JaxbUtil.elementToJaxb(xmlElem, MixedTester.class);
Assert.assertEquals("roundtrippedX num elems", 1, roundtrippedX.getElems().size());
StringAttribIntValue rtXmlByRef = (StringAttribIntValue) roundtrippedX.getElems().get(0);
Assert.assertEquals("roundtrippedX [Mixed has element] str", str, rtXmlByRef.getAttrib1());
Assert.assertEquals("roundtrippedX [Mixed has element] num", num, rtXmlByRef.getMyValue());
Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(jaxb);
logDebug("JSONElement from JAXB [Mixed has element] ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
MixedTester roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, MixedTester.class);
Assert.assertEquals("roundtripped [Mixed has element] num elems", 1, roundtripped.getElems().size());
StringAttribIntValue rtByRef = (StringAttribIntValue) roundtripped.getElems().get(0);
Assert.assertEquals("roundtripped [Mixed has element] str", str, rtByRef.getAttrib1());
Assert.assertEquals("roundtripped [Mixed has element] num", num, rtByRef.getMyValue());
}
Aggregations