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