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());
}
Aggregations