Search in sources :

Example 1 with ViewEnum

use of com.zimbra.soap.jaxb.ViewEnum 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));
}
Also used : EnumElemList(com.zimbra.soap.jaxb.EnumElemList) WrappedEnumElemList(com.zimbra.soap.jaxb.WrappedEnumElemList) XmlAnyElement(javax.xml.bind.annotation.XmlAnyElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) XmlElement(javax.xml.bind.annotation.XmlElement) ViewEnum(com.zimbra.soap.jaxb.ViewEnum) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Example 2 with ViewEnum

use of com.zimbra.soap.jaxb.ViewEnum 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());
}
Also used : EnumElemList(com.zimbra.soap.jaxb.EnumElemList) WrappedEnumElemList(com.zimbra.soap.jaxb.WrappedEnumElemList) XmlAnyElement(javax.xml.bind.annotation.XmlAnyElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) XmlElement(javax.xml.bind.annotation.XmlElement) ViewEnum(com.zimbra.soap.jaxb.ViewEnum) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Example 3 with ViewEnum

use of com.zimbra.soap.jaxb.ViewEnum in project zm-mailbox by Zimbra.

the class JaxbToJsonTest method wrappedEnumElemList.

/**
     *  Testing form:
     *      {@code @XmlElementWrapper(name="wrapper", required=false)
     *      @XmlElement(name="enum-entry", required=false)
     *      private List<ViewEnum> entries = Lists.newArrayList();}
     * Desired JSON :
     *      {
     *        "wrapper": [{
     *            "enum-entry": [
     *              {
     *                "_content": "appointment"
     *              },
     *              {
     *                "_content": "document"
     *              }]
     *          }],
     *        "_jsns": "urn:zimbraTest"
     *      }
     */
@Test
public void wrappedEnumElemList() throws Exception {
    Element jsonElem = JSONElement.mFactory.createElement(QName.get("wrapped-enum-elem-list", "urn:zimbraTest"));
    Element wrapElem = jsonElem.addElement("wrapper");
    wrapElem.addElement("enum-entry").addText(ViewEnum.APPOINTMENT.toString());
    wrapElem.addElement("enum-entry").addText(ViewEnum.DOCUMENT.toString());
    logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
    WrappedEnumElemList tstr = new WrappedEnumElemList();
    tstr.addEntry(ViewEnum.APPOINTMENT);
    tstr.addEntry(ViewEnum.DOCUMENT);
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(tstr);
    WrappedEnumElemList roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, WrappedEnumElemList.class);
    logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    Element wElem = jsonJaxbElem.getElement("wrapper");
    List<Element> jsonElems = wElem.listElements();
    List<ViewEnum> entries = roundtripped.getEntries();
    Assert.assertEquals("jsonElems num", 2, jsonElems.size());
    Assert.assertEquals("entries num", 2, entries.size());
    Assert.assertTrue("has APPOINTMENT", entries.contains(ViewEnum.APPOINTMENT));
    Assert.assertTrue("has DOCUMENT", entries.contains(ViewEnum.DOCUMENT));
}
Also used : WrappedEnumElemList(com.zimbra.soap.jaxb.WrappedEnumElemList) XmlAnyElement(javax.xml.bind.annotation.XmlAnyElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) XmlElement(javax.xml.bind.annotation.XmlElement) ViewEnum(com.zimbra.soap.jaxb.ViewEnum) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Aggregations

Element (com.zimbra.common.soap.Element)3 JSONElement (com.zimbra.common.soap.Element.JSONElement)3 XMLElement (com.zimbra.common.soap.Element.XMLElement)3 ViewEnum (com.zimbra.soap.jaxb.ViewEnum)3 WrappedEnumElemList (com.zimbra.soap.jaxb.WrappedEnumElemList)3 FilterTest (com.zimbra.soap.mail.type.FilterTest)3 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)3 XmlElement (javax.xml.bind.annotation.XmlElement)3 Test (org.junit.Test)3 EnumElemList (com.zimbra.soap.jaxb.EnumElemList)2