public ACLWithVersion apply(MailboxACL.ACLCommand command) { try { return new ACLWithVersion(version, mailboxACL.apply(command)); } catch (UnsupportedRightException exception) { throw new RuntimeException(exception); } } }
public ACLDiff updateACL(CassandraId cassandraId, MailboxACL.ACLCommand command) throws MailboxException { MailboxACL replacement = MailboxACL.EMPTY.apply(command); ACLDiff aclDiff = updateAcl(cassandraId, aclWithVersion -> aclWithVersion.apply(command), replacement); return userMailboxRightsDAO.update(cassandraId, aclDiff) .thenApply(any -> aclDiff) .join(); }
@Test public void applyShouldNotThrowWhenRemovingANonExistingEntry() throws Exception { assertThat(MailboxACL.EMPTY .apply(MailboxACL.command().forUser("bob").noRights().asReplacement())) .isEqualTo(MailboxACL.EMPTY); }
@Test public void removedEntriesShouldReturnEmptyWhenAddedEntry() throws Exception { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY, MailboxACL.EMPTY.apply( MailboxACL.command() .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition())); assertThat(positiveUserAclDiff.removedEntries()) .isEmpty(); }
@Test public void changedEntriesShouldReturnEmptyWhenAddedEntry() throws Exception { ACLDiff aclDiff = ACLDiff.computeDiff( MailboxACL.EMPTY, MailboxACL.EMPTY.apply( MailboxACL.command() .key(ENTRY_KEY) .rights(RIGHTS) .asAddition())); assertThat(aclDiff.changedEntries()) .isEmpty(); }
@Test public void changedEntriesShouldReturnEmptyWhenSameNonEmptyACL() throws UnsupportedRightException { MailboxACL mailboxACL = MailboxACL.EMPTY.apply( MailboxACL.command() .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition()); PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff(mailboxACL, mailboxACL); assertThat(positiveUserAclDiff.changedEntries()).isEmpty(); }
@Test public void addedEntriesShouldReturnEmptyWhenRemovedEntry() throws Exception { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY.apply( MailboxACL.command() .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition()), MailboxACL.EMPTY); assertThat(positiveUserAclDiff.addedEntries()) .isEmpty(); }
@Test public void changedEntriesShouldReturnEmptyWhenRemovedEntry() throws Exception { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY.apply( MailboxACL.command() .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition()), MailboxACL.EMPTY); assertThat(positiveUserAclDiff.changedEntries()) .isEmpty(); }
@Test public void removedEntriesShouldReturnEmptyWhenSameNonEmptyACL() throws UnsupportedRightException { MailboxACL mailboxACL = MailboxACL.EMPTY.apply( MailboxACL.command() .key(ENTRY_KEY) .rights(RIGHTS) .asAddition()); ACLDiff aclDiff = ACLDiff.computeDiff(mailboxACL, mailboxACL); assertThat(aclDiff.removedEntries()).isEmpty(); }
@Test public void removedEntriesShouldReturnEmptyWhenAddedEntry() throws Exception { ACLDiff aclDiff = ACLDiff.computeDiff( MailboxACL.EMPTY, MailboxACL.EMPTY.apply( MailboxACL.command() .key(ENTRY_KEY) .rights(RIGHTS) .asAddition())); assertThat(aclDiff.removedEntries()) .isEmpty(); }
@Test public void addedEntriesShouldFilterNegativeUserEntryKey() throws Exception { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY, MailboxACL.EMPTY.apply( MailboxACL.command() .key(NEGATIVE_USER_ENTRY_KEY) .rights(RIGHTS) .asAddition())); assertThat(positiveUserAclDiff.addedEntries()) .isEmpty(); }
@Test public void changedEntriesShouldReturnEmptyWhenSameNonEmptyACL() throws UnsupportedRightException { MailboxACL mailboxACL = MailboxACL.EMPTY.apply( MailboxACL.command() .key(ENTRY_KEY) .rights(RIGHTS) .asAddition()); ACLDiff acldiff = ACLDiff.computeDiff(mailboxACL, mailboxACL); assertThat(acldiff.changedEntries()).isEmpty(); }
@Test public void addedEntriesShouldReturnEmptyWhenRemovedEntry() throws Exception { ACLDiff aclDiff = ACLDiff.computeDiff( MailboxACL.EMPTY.apply( MailboxACL.command() .key(ENTRY_KEY) .rights(RIGHTS) .asAddition()), MailboxACL.EMPTY); assertThat(aclDiff.addedEntries()) .isEmpty(); }
@Test public void changedEntriesShouldReturnEmptyWhenRemovedEntry() throws Exception { ACLDiff aclDiff = ACLDiff.computeDiff( MailboxACL.EMPTY.apply( MailboxACL.command() .key(ENTRY_KEY) .rights(RIGHTS) .asAddition()), MailboxACL.EMPTY); assertThat(aclDiff.changedEntries()) .isEmpty(); }
@Test public void changedEntriesShouldReturnEmptyWhenAddedEntry() throws Exception { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY, MailboxACL.EMPTY.apply( MailboxACL.command() .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition())); assertThat(positiveUserAclDiff.changedEntries()) .isEmpty(); }
@Test public void addedEntriesShouldReturnEmptyWhenSameNonEmptyACL() throws UnsupportedRightException { MailboxACL mailboxACL = MailboxACL.EMPTY.apply( MailboxACL.command() .key(ENTRY_KEY) .rights(RIGHTS) .asAddition()); ACLDiff aclDiff = ACLDiff.computeDiff(mailboxACL, mailboxACL); assertThat(aclDiff.addedEntries()).isEmpty(); }
@Test public void addedEntriesShouldReturnNewEntryWhenAddedEntry() throws Exception { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY, MailboxACL.EMPTY.apply( MailboxACL.command() .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition())); assertThat(positiveUserAclDiff.addedEntries()) .containsOnly(new Entry(USER_ENTRY_KEY, RIGHTS)); }
@Test public void removedEntriesShouldReturnEntryWhenRemovedEntry() throws Exception { ACLDiff aclDiff = ACLDiff.computeDiff( MailboxACL.EMPTY.apply( MailboxACL.command() .key(ENTRY_KEY) .rights(RIGHTS) .asAddition()), MailboxACL.EMPTY); assertThat(aclDiff.removedEntries()) .containsOnly(new MailboxACL.Entry(ENTRY_KEY, RIGHTS)); }
@Test public void removedEntriesShouldReturnEntryWhenRemovedEntry() throws Exception { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY.apply( MailboxACL.command() .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition()), MailboxACL.EMPTY); assertThat(positiveUserAclDiff.removedEntries()) .containsOnly(new Entry(USER_ENTRY_KEY, RIGHTS)); }
@Test public void addedEntriesShouldReturnNewEntryWhenAddedEntry() throws Exception { ACLDiff aclDiff = ACLDiff.computeDiff( MailboxACL.EMPTY, MailboxACL.EMPTY.apply( MailboxACL.command() .key(ENTRY_KEY) .rights(RIGHTS) .asAddition())); assertThat(aclDiff.addedEntries()) .containsOnly(new MailboxACL.Entry(ENTRY_KEY, RIGHTS)); }