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