Search in sources :

Example 1 with MockSoapEngine

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

the class GetContactBackupListTest method testGetContactBackupListJSON.

@Test
public void testGetContactBackupListJSON() throws Exception {
    Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    Folder folder = mbox.createFolder(null, "Briefcase/ContactsBackup", new Folder.FolderOptions().setDefaultView(MailItem.Type.DOCUMENT));
    OperationContext octxt = new OperationContext(acct);
    // Upload the contacts backup file to ContactsBackup folder in briefcase
    mbox.createDocument(octxt, folder.getId(), "backup_dummy_test1.tgz", MimeConstants.CT_APPLICATION_ZIMBRA_DOC, "author", "description", new ByteArrayInputStream("dummy data".getBytes()));
    mbox.createDocument(octxt, folder.getId(), "backup_dummy_test2.tgz", MimeConstants.CT_APPLICATION_ZIMBRA_DOC, "author", "description", new ByteArrayInputStream("dummy data".getBytes()));
    Element request = new Element.JSONElement(MailConstants.E_GET_CONTACT_BACKUP_LIST_REQUEST);
    Map<String, Object> context = new HashMap<String, Object>();
    context.put(SoapEngine.ZIMBRA_CONTEXT, new ZimbraSoapContext(AuthProvider.getAuthToken(acct), acct.getId(), SoapProtocol.Soap12, SoapProtocol.SoapJS));
    context.put(SoapServlet.SERVLET_REQUEST, new MockHttpServletRequest("test".getBytes("UTF-8"), new URL("http://localhost:7070/service/FooRequest"), ""));
    context.put(SoapEngine.ZIMBRA_ENGINE, new MockSoapEngine(new MailService()));
    Element response = new GetContactBackupList().handle(request, context);
    String expectedResponse = "{\n" + "  \"backups\": [{\n" + "      \"backup\": [\n" + "        {\n" + "          \"_content\": \"backup_dummy_test1.tgz\"\n" + "        },\n" + "        {\n" + "          \"_content\": \"backup_dummy_test2.tgz\"\n" + "        }]\n" + "    }],\n" + "  \"_jsns\": \"urn:zimbraMail\"\n" + "}";
    Assert.assertEquals("GetContactBackupListResponse is not as expected", expectedResponse, response.prettyPrint());
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) MockSoapEngine(com.zimbra.soap.MockSoapEngine) HashMap(java.util.HashMap) MockHttpServletRequest(com.zimbra.cs.service.MockHttpServletRequest) Element(com.zimbra.common.soap.Element) Folder(com.zimbra.cs.mailbox.Folder) URL(java.net.URL) Mailbox(com.zimbra.cs.mailbox.Mailbox) ByteArrayInputStream(java.io.ByteArrayInputStream) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Test(org.junit.Test)

Example 2 with MockSoapEngine

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

the class ServiceTestUtil method getRequestContext.

public static Map<String, Object> getRequestContext(Account authAcct, Account targetAcct, DocumentService service) throws Exception {
    Map<String, Object> context = new HashMap<String, Object>();
    context.put(SoapEngine.ZIMBRA_CONTEXT, new ZimbraSoapContext(AuthProvider.getAuthToken(authAcct), targetAcct.getId(), SoapProtocol.Soap12, SoapProtocol.Soap12));
    context.put(SoapServlet.SERVLET_REQUEST, new MockHttpServletRequest("test".getBytes("UTF-8"), new URL("http://localhost:7070/service/FooRequest"), ""));
    context.put(SoapEngine.ZIMBRA_ENGINE, new MockSoapEngine(service));
    context.put(SoapServlet.SERVLET_RESPONSE, new MockHttpServletResponse());
    return context;
}
Also used : MockSoapEngine(com.zimbra.soap.MockSoapEngine) HashMap(java.util.HashMap) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) MockHttpServletRequest(com.zimbra.cs.service.MockHttpServletRequest) URL(java.net.URL) MockHttpServletResponse(com.zimbra.cs.service.MockHttpServletResponse)

Example 3 with MockSoapEngine

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

the class GetFilterRulesTest method testBug71036_SingleRuleSimpleNestedIfwithJSON.

@Test
public void testBug71036_SingleRuleSimpleNestedIfwithJSON() throws Exception {
    Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    // set One rule with one nested if
    RuleManager.clearCachedRules(acct);
    acct.setMailSieveScript("# test2\nif anyof header :is \"Subject\" \"important\" {\nif anyof header :contains \"Subject\" \"confidential\" { flag \"priority\"; }}");
    // ZimbraLog.filter.info(acct.getMailSieveScript());
    // first, test the default setup (full tree)
    Map<String, Object> context = new HashMap<String, Object>();
    context.put(SoapEngine.ZIMBRA_CONTEXT, new ZimbraSoapContext(AuthProvider.getAuthToken(acct), acct.getId(), SoapProtocol.Soap12, SoapProtocol.SoapJS));
    context.put(SoapServlet.SERVLET_REQUEST, new MockHttpServletRequest("test".getBytes("UTF-8"), new URL("http://localhost:7070/service/FooRequest"), ""));
    context.put(SoapEngine.ZIMBRA_ENGINE, new MockSoapEngine(new MailService()));
    // return context;
    Element request = new Element.XMLElement(MailConstants.GET_FILTER_RULES_REQUEST);
    Element response = new GetFilterRules().handle(request, context);
    String expectedJson = "{\n";
    expectedJson += "  \"filterRule\": [{\n";
    expectedJson += "      \"name\": \"test2\",\n";
    expectedJson += "      \"active\": true,\n";
    expectedJson += "      \"filterTests\": [{\n";
    expectedJson += "          \"condition\": \"anyof\",\n";
    expectedJson += "          \"headerTest\": [{\n";
    expectedJson += "              \"index\": 0,\n";
    expectedJson += "              \"header\": \"Subject\",\n";
    expectedJson += "              \"stringComparison\": \"is\",\n";
    expectedJson += "              \"value\": \"important\"\n";
    expectedJson += "            }]\n";
    expectedJson += "        }],\n";
    // expectedJson += "      \"filterActions\": [{}],\n";
    expectedJson += "      \"nestedRule\": [{\n";
    expectedJson += "          \"filterTests\": [{\n";
    expectedJson += "              \"condition\": \"anyof\",\n";
    expectedJson += "              \"headerTest\": [{\n";
    expectedJson += "                  \"index\": 0,\n";
    expectedJson += "                  \"header\": \"Subject\",\n";
    expectedJson += "                  \"stringComparison\": \"contains\",\n";
    expectedJson += "                  \"value\": \"confidential\"\n";
    expectedJson += "                }]\n";
    expectedJson += "            }],\n";
    expectedJson += "          \"filterActions\": [{\n";
    expectedJson += "              \"actionFlag\": [{\n";
    expectedJson += "                  \"flagName\": \"priority\",\n";
    expectedJson += "                  \"index\": 0\n";
    expectedJson += "                }]\n";
    expectedJson += "            }]\n";
    expectedJson += "        }]\n";
    expectedJson += "    }]\n";
    expectedJson += "}";
    Element rules = response.getOptionalElement(MailConstants.E_FILTER_RULES);
    // ZimbraLog.filter.info(rules.prettyPrint());
    // ZimbraLog.filter.info(expectedJson);
    Assert.assertEquals(expectedJson, rules.prettyPrint());
}
Also used : Account(com.zimbra.cs.account.Account) MockSoapEngine(com.zimbra.soap.MockSoapEngine) HashMap(java.util.HashMap) MockHttpServletRequest(com.zimbra.cs.service.MockHttpServletRequest) Element(com.zimbra.common.soap.Element) URL(java.net.URL) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Test(org.junit.Test)

Aggregations

MockHttpServletRequest (com.zimbra.cs.service.MockHttpServletRequest)3 MockSoapEngine (com.zimbra.soap.MockSoapEngine)3 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)3 URL (java.net.URL)3 HashMap (java.util.HashMap)3 Element (com.zimbra.common.soap.Element)2 Account (com.zimbra.cs.account.Account)2 Test (org.junit.Test)2 Folder (com.zimbra.cs.mailbox.Folder)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 OperationContext (com.zimbra.cs.mailbox.OperationContext)1 MockHttpServletResponse (com.zimbra.cs.service.MockHttpServletResponse)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1