Search in sources :

Example 1 with TagActionResponse

use of com.zimbra.soap.mail.message.TagActionResponse in project zm-mailbox by Zimbra.

the class TestPurge method testTagRetentionPolicy.

@Test
public void testTagRetentionPolicy() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    ZTag tag = mbox.createTag(NAME_PREFIX + "-testTagRetentionPolicy", null);
    // Set user keep policy for folder.
    TagActionSelector action = new TagActionSelector(tag.getId(), "retentionpolicy");
    RetentionPolicy rp = new RetentionPolicy(Arrays.asList(Policy.newUserPolicy("30d")), null);
    action.setRetentionPolicy(rp);
    TagActionRequest req = new TagActionRequest(action);
    TagActionResponse res = mbox.invokeJaxb(req);
    Assert.assertEquals("retentionpolicy", res.getAction().getOperation());
    Assert.assertEquals(tag.getId(), res.getAction().getSuccesses());
    // Make sure that the retention policy is now set.
    tag = mbox.getTagById(tag.getId());
    rp = tag.getRetentionPolicy();
    Assert.assertEquals(1, rp.getKeepPolicy().size());
    Assert.assertEquals(0, rp.getPurgePolicy().size());
    Policy p = rp.getKeepPolicy().get(0);
    Assert.assertEquals(Policy.Type.USER, p.getType());
    Assert.assertEquals("30d", p.getLifetime());
    // Turn off keep policy and set purge policy.
    action = new TagActionSelector(tag.getId(), "retentionpolicy");
    rp = new RetentionPolicy(null, Arrays.asList(Policy.newUserPolicy("45d")));
    action.setRetentionPolicy(rp);
    req = new TagActionRequest(action);
    res = mbox.invokeJaxb(req);
    Assert.assertEquals("retentionpolicy", res.getAction().getOperation());
    Assert.assertEquals(tag.getId(), res.getAction().getSuccesses());
    // Make sure that the retention policy is now set.
    tag = mbox.getTagById(tag.getId());
    rp = tag.getRetentionPolicy();
    Assert.assertEquals(0, rp.getKeepPolicy().size());
    Assert.assertEquals(1, rp.getPurgePolicy().size());
    p = rp.getPurgePolicy().get(0);
    Assert.assertEquals(Policy.Type.USER, p.getType());
    Assert.assertEquals("45d", p.getLifetime());
    // Start a new session and make sure that the retention policy is still returned.
    mbox = TestUtil.getZMailbox(USER_NAME);
    tag = mbox.getTagById(tag.getId());
    Assert.assertTrue(tag.getRetentionPolicy().isSet());
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) ZMailbox(com.zimbra.client.ZMailbox) TagActionResponse(com.zimbra.soap.mail.message.TagActionResponse) TagActionRequest(com.zimbra.soap.mail.message.TagActionRequest) ZTag(com.zimbra.client.ZTag) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) TagActionSelector(com.zimbra.soap.mail.type.TagActionSelector) Test(org.junit.Test)

Aggregations

ZMailbox (com.zimbra.client.ZMailbox)1 ZTag (com.zimbra.client.ZTag)1 TagActionRequest (com.zimbra.soap.mail.message.TagActionRequest)1 TagActionResponse (com.zimbra.soap.mail.message.TagActionResponse)1 Policy (com.zimbra.soap.mail.type.Policy)1 RetentionPolicy (com.zimbra.soap.mail.type.RetentionPolicy)1 TagActionSelector (com.zimbra.soap.mail.type.TagActionSelector)1 Test (org.junit.Test)1