use of com.zimbra.soap.mail.message.NoOpResponse in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method booleanMarshal.
/**
* By default JAXB renders true and false in XML as "true" and "false"
* For Zimbra SOAP the XML flavor uses "1" and "0"
* The JSON flavor uses "true" and "false"
* @throws Exception
*/
@Test
public void booleanMarshal() throws Exception {
Element legacy0Elem = JSONElement.mFactory.createElement(MailConstants.NO_OP_RESPONSE);
legacy0Elem.addAttribute(MailConstants.A_WAIT_DISALLOWED, false);
logDebug("NoOpResponse JSONElement ---> prettyPrint\n%1$s", legacy0Elem.prettyPrint());
Element legacy1Elem = JSONElement.mFactory.createElement(MailConstants.NO_OP_RESPONSE);
legacy1Elem.addAttribute(MailConstants.A_WAIT_DISALLOWED, true);
Element legacyFalseElem = JSONElement.mFactory.createElement(MailConstants.NO_OP_RESPONSE);
legacyFalseElem.addAttribute(MailConstants.A_WAIT_DISALLOWED, "false");
Element legacyTrueElem = JSONElement.mFactory.createElement(MailConstants.NO_OP_RESPONSE);
legacyTrueElem.addAttribute(MailConstants.A_WAIT_DISALLOWED, "true");
// NoOpResponse has:
// @XmlAttribute(name=MailConstants.A_WAIT_DISALLOWED, required=false)
// private ZmBoolean waitDisallowed;
NoOpResponse jaxb = NoOpResponse.create(false);
Element xmlElem = JaxbUtil.jaxbToElement(jaxb, Element.XMLElement.mFactory);
logDebug("XMLElement from JAXB (false)---> prettyPrint\n%1$s", xmlElem.prettyPrint());
Assert.assertEquals("false Value of 'waitDisallowed'", "0", xmlElem.getAttribute(MailConstants.A_WAIT_DISALLOWED));
Element jsonElem = JacksonUtil.jaxbToJSONElement(jaxb, MailConstants.NO_OP_RESPONSE);
logDebug("NoOpResponse JSONElement from JAXB (false)---> prettyPrint\n%1$s", jsonElem.prettyPrint());
Assert.assertEquals("false Value of 'waitDisallowed'", "false", jsonElem.getAttribute(MailConstants.A_WAIT_DISALLOWED));
// ensure that marshaling where Boolean has value true works
jaxb.setWaitDisallowed(true);
xmlElem = JaxbUtil.jaxbToElement(jaxb, Element.XMLElement.mFactory);
logDebug("XMLElement from JAXB (true) ---> prettyPrint\n%1$s", xmlElem.prettyPrint());
Assert.assertEquals("true Value of 'waitDisallowed'", "1", xmlElem.getAttribute(MailConstants.A_WAIT_DISALLOWED));
jsonElem = JacksonUtil.jaxbToJSONElement(jaxb, MailConstants.NO_OP_RESPONSE);
logDebug("NoOpResponse JSONElement from JAXB (true) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
Assert.assertEquals("true Value of 'waitDisallowed'", "true", jsonElem.getAttribute(MailConstants.A_WAIT_DISALLOWED));
// ensure that unmarshaling where XML Boolean representation is "1" for true works
jaxb = JaxbUtil.elementToJaxb(legacy1Elem);
Assert.assertEquals("legacy1Elem waitDisallowed value", Boolean.TRUE, jaxb.getWaitDisallowed());
// ensure that unmarshaling where XML Boolean representation is "0" for false works
jaxb = JaxbUtil.elementToJaxb(legacy0Elem);
Assert.assertEquals("legacy0Elem waitDisallowed value", Boolean.FALSE, jaxb.getWaitDisallowed());
// ensure that unmarshaling where XML Boolean representation is "false" works
jaxb = JaxbUtil.elementToJaxb(legacyFalseElem);
Assert.assertEquals("legacyFalseElem waitDisallowed value", Boolean.FALSE, jaxb.getWaitDisallowed());
// ensure that unmarshaling where XML Boolean representation is "true" works
jaxb = JaxbUtil.elementToJaxb(legacyTrueElem);
Assert.assertEquals("legacyTrueElem waitDisallowed value", Boolean.TRUE, jaxb.getWaitDisallowed());
}
Aggregations