use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class PurgeTest method completeCosRetentionPolicy.
@Test
public void completeCosRetentionPolicy() throws Exception {
RetentionPolicyManager mgr = RetentionPolicyManager.getInstance();
Config config = Provisioning.getInstance().getConfig();
Policy keep1 = mgr.createSystemKeepPolicy(config, "keep1", "300d");
Map<String, Object> attrs = new HashMap<String, Object>();
Cos cos = Provisioning.getInstance().createCos("testcos2", attrs);
Policy keep2 = mgr.createSystemKeepPolicy(cos, "keep2", "600d");
// Assign cos to the account
getAccount().setCOSId(cos.getId());
// Create mailbox policy that references the system policy, and confirm that
// lookup returns the latest values.
RetentionPolicy mboxRP1 = new RetentionPolicy(Arrays.asList(Policy.newSystemPolicy(keep2.getId())), null);
RetentionPolicy completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP1);
Policy latest = completeRP.getKeepPolicy().get(0);
assertEquals(keep2, latest);
// Modify cos policy and confirm that the accessor returns the latest values.
mgr.modifySystemPolicy(cos, keep2.getId(), "new keep2", "301d");
completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP1);
latest = completeRP.getKeepPolicy().get(0);
assertFalse(keep2.equals(latest));
assertEquals(keep2.getId(), latest.getId());
assertEquals("new keep2", latest.getName());
assertEquals("301d", latest.getLifetime());
// Make sure system policy does not apply to this user.
RetentionPolicy mboxRP2 = new RetentionPolicy(Arrays.asList(Policy.newSystemPolicy(keep1.getId())), null);
completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP2);
assertTrue(completeRP.getKeepPolicy().isEmpty());
// remove cos retention policy
mgr.deleteSystemPolicy(cos, keep2.getId());
// make sure account retention policy is empty
completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP1);
assertTrue(completeRP.getKeepPolicy().isEmpty());
// make sure system policy is applicable now
completeRP = mgr.getCompleteRetentionPolicy(getAccount(), mboxRP2);
latest = completeRP.getKeepPolicy().get(0);
assertTrue(keep1.equals(latest));
assertEquals(keep1.getId(), latest.getId());
assertEquals("keep1", latest.getName());
assertEquals("300d", latest.getLifetime());
}
use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class PurgeTest method folderPurgePolicy.
@Test
public void folderPurgePolicy() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
// Create folder and test messages.
Folder folder = mbox.createFolder(null, "/folderPurgePolicy", new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
Message older = TestUtil.addMessage(mbox, folder.getId(), "test1", System.currentTimeMillis() - (60 * Constants.MILLIS_PER_MINUTE));
Message newer = TestUtil.addMessage(mbox, folder.getId(), "test2", System.currentTimeMillis() - (30 * Constants.MILLIS_PER_MINUTE));
folder = mbox.getFolderById(null, folder.getId());
// Run purge with default settings and make sure nothing was deleted.
mbox.purgeMessages(null);
folder = mbox.getFolderById(null, folder.getId());
assertEquals(2, folder.getSize());
// Add retention policy.
Policy p = Policy.newUserPolicy("45m");
RetentionPolicy purgePolicy = new RetentionPolicy(null, Arrays.asList(p));
mbox.setRetentionPolicy(null, folder.getId(), MailItem.Type.FOLDER, purgePolicy);
// Purge the folder cache and make sure that purge policy is reloaded from metadata.
mbox.purge(MailItem.Type.FOLDER);
folder = mbox.getFolderById(null, folder.getId());
List<Policy> purgeList = folder.getRetentionPolicy().getPurgePolicy();
assertEquals(1, purgeList.size());
assertEquals("45m", purgeList.get(0).getLifetime());
// Run purge and make sure one of the messages was deleted.
mbox.purgeMessages(null);
assertEquals(1, folder.getSize());
mbox.getMessageById(null, newer.getId());
try {
mbox.getMessageById(null, older.getId());
fail("Older message was not purged.");
} catch (NoSuchItemException e) {
// Older message was purged.
}
// Remove purge policy and verify that the folder state was properly updated.
mbox.setRetentionPolicy(null, folder.getId(), MailItem.Type.FOLDER, null);
mbox.purge(MailItem.Type.FOLDER);
folder = mbox.getFolderById(null, folder.getId());
assertEquals(0, folder.getRetentionPolicy().getKeepPolicy().size());
assertEquals(0, folder.getRetentionPolicy().getPurgePolicy().size());
}
use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class PurgeTest method setUp.
@Before
public void setUp() throws Exception {
MailboxTestUtil.clearData();
Provisioning prov = Provisioning.getInstance();
prov.deleteAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
prov.createAccount("test@zimbra.com", "secret", new HashMap<String, Object>());
Config config = Provisioning.getInstance().getConfig();
RetentionPolicyManager mgr = RetentionPolicyManager.getInstance();
RetentionPolicy rp = mgr.getSystemRetentionPolicy(config);
List<Policy> keep = rp.getKeepPolicy();
if (keep != null) {
for (Policy policy : keep) {
mgr.deleteSystemPolicy(config, policy.getId());
}
}
List<Policy> purge = rp.getPurgePolicy();
if (purge != null) {
for (Policy policy : purge) {
mgr.deleteSystemPolicy(config, policy.getId());
}
}
}
use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class PurgeTest method purgeWithSystemPolicy.
@Test
public void purgeWithSystemPolicy() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
// Create folder and test messages.
Folder folder = mbox.createFolder(null, "/purgeWithSystemPolicy", new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
Message older = TestUtil.addMessage(mbox, folder.getId(), "older", System.currentTimeMillis() - (60 * Constants.MILLIS_PER_MINUTE));
Message newer = TestUtil.addMessage(mbox, folder.getId(), "newer", System.currentTimeMillis() - (30 * Constants.MILLIS_PER_MINUTE));
folder = mbox.getFolderById(null, folder.getId());
// Add user and system retention policy.
Config config = Provisioning.getInstance().getConfig();
Policy system = RetentionPolicyManager.getInstance().createSystemPurgePolicy(config, "system", "45m");
Policy p1 = Policy.newUserPolicy("90m");
Policy p2 = Policy.newSystemPolicy(system.getId());
RetentionPolicy purgePolicy = new RetentionPolicy(null, Arrays.asList(p1, p2));
mbox.setRetentionPolicy(null, folder.getId(), MailItem.Type.FOLDER, purgePolicy);
// Run purge and make sure one of the messages was deleted.
mbox.purgeMessages(null);
folder = mbox.getFolderById(folder.getId());
assertEquals(1, folder.getSize());
mbox.getMessageById(null, newer.getId());
try {
mbox.getMessageById(null, older.getId());
fail("Older message was not purged.");
} catch (NoSuchItemException e) {
}
// Update system policy, rerun purge, and make sure the older message was deleted.
RetentionPolicyManager.getInstance().modifySystemPolicy(config, system.getId(), system.getName(), "20m");
mbox.purgeMessages(null);
folder = mbox.getFolderById(folder.getId());
assertEquals(0, folder.getSize());
try {
mbox.getMessageById(null, newer.getId());
fail("Newer message was not purged.");
} catch (NoSuchItemException e) {
}
}
use of com.zimbra.soap.mail.type.RetentionPolicy in project zm-mailbox by Zimbra.
the class PurgeTest method modifySystemPolicy.
@Test
public void modifySystemPolicy() throws Exception {
Config config = Provisioning.getInstance().getConfig();
RetentionPolicyManager mgr = RetentionPolicyManager.getInstance();
Policy keep1 = mgr.createSystemKeepPolicy(config, "keep1", "300d");
Policy keep2 = mgr.createSystemKeepPolicy(config, "keep2", "400d");
Policy purge1 = mgr.createSystemPurgePolicy(config, "purge1", "500d");
Policy purge2 = mgr.createSystemPurgePolicy(config, "purge2", "500d");
assertEquals(keep1, mgr.getPolicyById(config, keep1.getId()));
assertEquals(keep2, mgr.getPolicyById(config, keep2.getId()));
assertEquals(purge1, mgr.getPolicyById(config, purge1.getId()));
assertEquals(purge2, mgr.getPolicyById(config, purge2.getId()));
// Test modify.
mgr.modifySystemPolicy(config, keep1.getId(), "new keep1", "301d");
Policy newKeep1 = mgr.getPolicyById(config, keep1.getId());
assertFalse(keep1.equals(newKeep1));
assertEquals(keep1.getId(), newKeep1.getId());
assertEquals("new keep1", newKeep1.getName());
assertEquals("301d", newKeep1.getLifetime());
// Test delete.
assertTrue(mgr.deleteSystemPolicy(config, purge2.getId()));
assertNull(mgr.getPolicyById(config, purge2.getId()));
RetentionPolicy rp = mgr.getSystemRetentionPolicy(config);
assertEquals(2, rp.getKeepPolicy().size());
assertEquals(1, rp.getPurgePolicy().size());
}
Aggregations