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