use of com.zimbra.soap.admin.message.AuthResponse in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method stringElemAndZimbraJsonlongAttr.
/**
* Desired JSON :
* {
* "authToken": [{
* "_content": "authenticationtoken"
* }],
* "lifetime": 3000,
* "_jsns": "urn:zimbraAdmin"
* }
*/
@Test
public void stringElemAndZimbraJsonlongAttr() throws Exception {
final long lifetime = 3000;
final String lifetimeStr = new Long(lifetime).toString();
final String authToken = "authenticationtoken";
AuthResponse tstr = new AuthResponse();
tstr.setAuthToken(authToken);
tstr.setLifetime(lifetime);
Element xmlElem = JaxbUtil.jaxbToElement(tstr, Element.XMLElement.mFactory, true, false);
AuthResponse roundtrippedX = JaxbUtil.elementToJaxb(xmlElem, AuthResponse.class);
Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(tstr);
AuthResponse roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, AuthResponse.class);
logDebug("XmlElement (for comparison) ---> prettyPrint\n%1$s", xmlElem.prettyPrint());
logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
Assert.assertEquals("JSONElement lifetime", lifetimeStr, jsonJaxbElem.getAttribute("lifetime"));
Assert.assertEquals("JSONElement authToken", authToken, jsonJaxbElem.getElement("authToken").getText());
Assert.assertEquals("roundtripped lifetime", lifetime, roundtripped.getLifetime());
Assert.assertEquals("roundtripped authToken", authToken, roundtripped.getAuthToken());
Assert.assertEquals("roundtrippedX lifetime", lifetime, roundtrippedX.getLifetime());
Assert.assertEquals("roundtrippedX authToken", authToken, roundtrippedX.getAuthToken());
}
Aggregations