use of com.zimbra.soap.admin.message.CreateXMbxSearchRequest in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method keyValuePairMbxSearch.
/**
* CreateXMbxSearchRequest currently extends AdminKeyValuePairs which uses the {@link ZimbraKeyValuePairs}
* annotation.
*
* Want JSON for KeyValuePairs to look something like :
* "_attrs": {
* "query": "Kitchen",
* "accounts": "*"
* },
*/
@Test
public void keyValuePairMbxSearch() throws Exception {
final String notifMsg = "Search task %taskId% completed with status %status%. \nImported: %numMsgs% messages. \nSearch query used: %query%.";
Element legacyElem = JSONElement.mFactory.createElement(XMbxSearchConstants.CREATE_XMBX_SEARCH_REQUEST);
legacyElem.addKeyValuePair("query", "Kitchen");
legacyElem.addKeyValuePair("accounts", "*");
legacyElem.addKeyValuePair("limit", "0");
legacyElem.addKeyValuePair("notificationMessage", notifMsg);
logDebug("CreateXmbxSearchRequest JSONElement ---> prettyPrint\n%1$s", legacyElem.prettyPrint());
// CreateXMbxSearchRequest extends AdminKeyValuePairs which uses ZimbraKeyValuePairs annotation to flag need
// for special handling required when serializing to JSON:
// @ZimbraKeyValuePairs
// @XmlElement(name=AdminConstants.E_A /* a */, required=false)
// private List<KeyValuePair> keyValuePairs;
CreateXMbxSearchRequest jaxb = new CreateXMbxSearchRequest();
jaxb.addKeyValuePair(new KeyValuePair("query", "Kitchen"));
jaxb.addKeyValuePair(new KeyValuePair("accounts", "*"));
jaxb.addKeyValuePair(new KeyValuePair("limit", "0"));
jaxb.addKeyValuePair(new KeyValuePair("notificationMessage", notifMsg));
Element elem = JacksonUtil.jaxbToJSONElement(jaxb, XMbxSearchConstants.CREATE_XMBX_SEARCH_REQUEST);
logDebug("CreateXmbxSearchRequest JSONElement from JAXB ---> prettyPrint\n%1$s", elem.prettyPrint());
List<Element.KeyValuePair> kvps = elem.listKeyValuePairs();
Assert.assertEquals("Number of keyValuePairs ", 4, kvps.size());
Element.KeyValuePair kvp4 = kvps.get(3);
Assert.assertEquals("KeyValuePair notificationMessage key", "notificationMessage", kvp4.getKey());
Assert.assertEquals("KeyValuePair notificationMessage value", notifMsg, kvp4.getValue());
}
use of com.zimbra.soap.admin.message.CreateXMbxSearchRequest in project zm-mailbox by Zimbra.
the class JaxbToElementTest method KeyValuePairs.
@Test
public void KeyValuePairs() throws Exception {
try (InputStream is = JaxbToElementTest.class.getResourceAsStream("CreateXMbxSearchRequest.xml")) {
// String soapXml = streamToString(is, Charsets.UTF_8);
JAXBContext jaxb = JAXBContext.newInstance(CreateXMbxSearchRequest.class);
Unmarshaller kvpunmarshaller = jaxb.createUnmarshaller();
JAXBElement<CreateXMbxSearchRequest> jaxbElem = kvpunmarshaller.unmarshal(new StreamSource(is), CreateXMbxSearchRequest.class);
Assert.assertNotNull("JAXBElement resulting from unmarshal", jaxbElem);
CreateXMbxSearchRequest soapObj = jaxbElem.getValue();
Assert.assertNotNull("Unmarshal soap object", soapObj);
Assert.assertEquals("Number of attributes", 10, soapObj.getKeyValuePairs().size());
}
}
Aggregations