Search in sources :

Example 11 with MockHttpServletRequest

use of com.zimbra.cs.service.MockHttpServletRequest 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)11 HashMap (java.util.HashMap)10 Test (org.junit.Test)10 URL (java.net.URL)9 RemoteIP (com.zimbra.common.util.RemoteIP)5 MockSoapEngine (com.zimbra.soap.MockSoapEngine)3 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)3 Element (com.zimbra.common.soap.Element)2 Account (com.zimbra.cs.account.Account)2 MockServer (com.zimbra.cs.account.MockServer)2 Server (com.zimbra.cs.account.Server)2 MockHttpServletResponse (com.zimbra.cs.service.MockHttpServletResponse)2 ArrayList (java.util.ArrayList)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Folder (com.zimbra.cs.mailbox.Folder)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 OperationContext (com.zimbra.cs.mailbox.OperationContext)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Ignore (org.junit.Ignore)1