Search in sources :

Example 1 with AuthResponse

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());
}
Also used : 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) AuthResponse(com.zimbra.soap.admin.message.AuthResponse) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Aggregations

Element (com.zimbra.common.soap.Element)1 JSONElement (com.zimbra.common.soap.Element.JSONElement)1 XMLElement (com.zimbra.common.soap.Element.XMLElement)1 AuthResponse (com.zimbra.soap.admin.message.AuthResponse)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