Search in sources :

Example 1 with WrappedRequired

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

the class JaxbToJsonTest method missingRequiredWrappedAndInt.

/**
 * Permissive handling - if required things are not present, users need to handle this
 */
@Test
public void missingRequiredWrappedAndInt() throws Exception {
    WrappedRequired tstr = new WrappedRequired();
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(tstr);
    WrappedRequired roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, WrappedRequired.class);
    logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    try {
        jsonJaxbElem.getElement("wrapper");
    } catch (ServiceException svcE) {
        Assert.assertEquals("JSONElement exception when getting missing wrapper:", ServiceException.INVALID_REQUEST, svcE.getCode());
    }
    try {
        jsonJaxbElem.getAttributeInt("required-int");
    } catch (ServiceException svcE) {
        Assert.assertEquals("JSONElement exception when getting missing int:", ServiceException.INVALID_REQUEST, svcE.getCode());
    }
    try {
        jsonJaxbElem.getAttributeInt("required-bool");
    } catch (ServiceException svcE) {
        Assert.assertEquals("JSONElement exception when getting missing bool:", ServiceException.INVALID_REQUEST, svcE.getCode());
    }
    try {
        jsonJaxbElem.getAttributeInt("required-complex");
    } catch (ServiceException svcE) {
        Assert.assertEquals("JSONElement exception when getting missing complex element:", ServiceException.INVALID_REQUEST, svcE.getCode());
    }
    Assert.assertEquals("roundtripped entries", 0, roundtripped.getEntries().size());
    Assert.assertEquals("roundtripped required int", 0, roundtripped.getRequiredInt());
    Assert.assertEquals("roundtripped required ZmBoolean", null, roundtripped.getRequiredBool());
    Assert.assertEquals("roundtripped required complex", null, roundtripped.getRequiredComplex());
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) WrappedRequired(com.zimbra.soap.jaxb.WrappedRequired) 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) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)1 Element (com.zimbra.common.soap.Element)1 JSONElement (com.zimbra.common.soap.Element.JSONElement)1 XMLElement (com.zimbra.common.soap.Element.XMLElement)1 WrappedRequired (com.zimbra.soap.jaxb.WrappedRequired)1 FilterTest (com.zimbra.soap.mail.type.FilterTest)1 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 Test (org.junit.Test)1