Search in sources :

Example 1 with CreateXMbxSearchRequest

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());
}
Also used : KeyValuePair(com.zimbra.soap.type.KeyValuePair) CreateXMbxSearchRequest(com.zimbra.soap.admin.message.CreateXMbxSearchRequest) 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 CreateXMbxSearchRequest

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());
    }
}
Also used : CreateXMbxSearchRequest(com.zimbra.soap.admin.message.CreateXMbxSearchRequest) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Aggregations

CreateXMbxSearchRequest (com.zimbra.soap.admin.message.CreateXMbxSearchRequest)2 Test (org.junit.Test)2 Element (com.zimbra.common.soap.Element)1 JSONElement (com.zimbra.common.soap.Element.JSONElement)1 XMLElement (com.zimbra.common.soap.Element.XMLElement)1 FilterTest (com.zimbra.soap.mail.type.FilterTest)1 KeyValuePair (com.zimbra.soap.type.KeyValuePair)1 InputStream (java.io.InputStream)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 StreamSource (javax.xml.transform.stream.StreamSource)1