use of com.zimbra.soap.jaxb.EnumElemList in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method enumElemList.
/**
* Testing form:
* {@code @XmlElement(name="enum-entry", required=false)
* private List<ViewEnum> entries = Lists.newArrayList();}
* Desired JSON :
* {
* "enum-entry": [
* {
* "_content": "appointment"
* },
* {
* "_content": ""
* },
* {
* "_content": "document"
* }],
* "_jsns": "urn:zimbraTest"
*/
@Test
public void enumElemList() throws Exception {
Element jsonElem = JSONElement.mFactory.createElement(QName.get("enum-elem-list", "urn:zimbraTest"));
jsonElem.addElement("enum-entry").addText(ViewEnum.APPOINTMENT.toString());
jsonElem.addElement("enum-entry").addText(ViewEnum.UNKNOWN.toString());
jsonElem.addElement("enum-entry").addText(ViewEnum.DOCUMENT.toString());
logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
EnumElemList tstr = new EnumElemList();
tstr.addEntry(ViewEnum.APPOINTMENT);
tstr.addEntry(ViewEnum.UNKNOWN);
tstr.addEntry(ViewEnum.DOCUMENT);
Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(tstr);
EnumElemList roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, EnumElemList.class);
logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
List<Element> jsonElems = jsonJaxbElem.listElements();
List<ViewEnum> entries = roundtripped.getEntries();
Assert.assertEquals("jsonElems num", 3, jsonElems.size());
Assert.assertEquals("entries num", 3, entries.size());
Assert.assertTrue("has APPOINTMENT", entries.contains(ViewEnum.APPOINTMENT));
Assert.assertTrue("has UNKNOWN", entries.contains(ViewEnum.UNKNOWN));
Assert.assertTrue("has DOCUMENT", entries.contains(ViewEnum.DOCUMENT));
}
use of com.zimbra.soap.jaxb.EnumElemList in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method emptyEnumElemList.
/**
* Desired JSON :
* {
* "_jsns": "urn:zimbraTest"
* }
*/
@Test
public void emptyEnumElemList() throws Exception {
EnumElemList tstr = new EnumElemList();
Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(tstr);
logDebug("JSONElement from JAXB FOR EMPTY LIST ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
EnumElemList roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, EnumElemList.class);
List<Element> jsonElems = jsonJaxbElem.listElements();
List<ViewEnum> entries = roundtripped.getEntries();
Assert.assertEquals("jsonElems num", 0, jsonElems.size());
Assert.assertEquals("entries num", 0, entries.size());
}
Aggregations