Search in sources :

Example 1 with MixedTester

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

the class JaxbToJsonTest method mixedHandlingJustText.

/**
 * {@link XmlMixed} handling
 * In the places we use XmlMixed, we typically have either just text or just elements
 * This tests where we have just text.
 */
@Test
public void mixedHandlingJustText() throws Exception {
    String textStr = "text string";
    List<Object> elems = Lists.newArrayList();
    MixedTester jaxb = new MixedTester();
    elems.add(textStr);
    jaxb.setElems(elems);
    Element xmlElem = JaxbUtil.jaxbToElement(jaxb, Element.XMLElement.mFactory, true, false);
    xmlElem = JaxbUtil.jaxbToElement(jaxb, Element.XMLElement.mFactory, true, false);
    logDebug("XmlElement (for comparison) [Mixed has just text] ---> prettyPrint\n%1$s", xmlElem.prettyPrint());
    MixedTester roundtrippedX = JaxbUtil.elementToJaxb(xmlElem, MixedTester.class);
    Assert.assertEquals("roundtrippedX [Mixed has just text] num elems", 1, roundtrippedX.getElems().size());
    Assert.assertEquals("roundtrippedX [Mixed has just text] str", textStr, (String) roundtrippedX.getElems().get(0));
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(jaxb);
    logDebug("JSONElement from JAXB [Mixed has just text] ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    MixedTester roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, MixedTester.class);
    Assert.assertEquals("roundtripped [Mixed has just text] num elems", 1, roundtripped.getElems().size());
    Assert.assertEquals("roundtripped [Mixed has just text] str", textStr, (String) roundtripped.getElems().get(0));
}
Also used : MixedTester(com.zimbra.soap.jaxb.MixedTester) 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)

Example 2 with MixedTester

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

the class JaxbToJsonTest method mixedHandlingWithJaxbAndNoText.

/**
 * {@link XmlMixed} handling
 * In the places we use XmlMixed, we have either just text or just elements
 * This tests where we have something that maps to a JAXB object.
 * Side note:  Also tests out case for {@link XmlElementRef} where name is derived from root element.
 */
@Test
public void mixedHandlingWithJaxbAndNoText() throws Exception {
    String str = "my string";
    int num = 321;
    List<Object> elems = Lists.newArrayList();
    MixedTester jaxb = new MixedTester();
    StringAttribIntValue inner = new StringAttribIntValue(str, num);
    elems.add(inner);
    jaxb.setElems(elems);
    Element xmlElem = JaxbUtil.jaxbToElement(jaxb, Element.XMLElement.mFactory, true, false);
    logDebug("XmlElement (for comparison) [Mixed has element] ---> prettyPrint\n%1$s", xmlElem.prettyPrint());
    MixedTester roundtrippedX = JaxbUtil.elementToJaxb(xmlElem, MixedTester.class);
    Assert.assertEquals("roundtrippedX num elems", 1, roundtrippedX.getElems().size());
    StringAttribIntValue rtXmlByRef = (StringAttribIntValue) roundtrippedX.getElems().get(0);
    Assert.assertEquals("roundtrippedX [Mixed has element] str", str, rtXmlByRef.getAttrib1());
    Assert.assertEquals("roundtrippedX [Mixed has element] num", num, rtXmlByRef.getMyValue());
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(jaxb);
    logDebug("JSONElement from JAXB [Mixed has element] ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    MixedTester roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, MixedTester.class);
    Assert.assertEquals("roundtripped [Mixed has element] num elems", 1, roundtripped.getElems().size());
    StringAttribIntValue rtByRef = (StringAttribIntValue) roundtripped.getElems().get(0);
    Assert.assertEquals("roundtripped [Mixed has element] str", str, rtByRef.getAttrib1());
    Assert.assertEquals("roundtripped [Mixed has element] num", num, rtByRef.getMyValue());
}
Also used : MixedTester(com.zimbra.soap.jaxb.MixedTester) StringAttribIntValue(com.zimbra.soap.jaxb.StringAttribIntValue) 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

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