Repository: james-project Updated Branches: refs/heads/master 5ceee7866 -> b539779b2
MAILBOX-316 New ACLDiff which compare all kind of Entry and later on the PositiveUserACLDiff rely on that Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/806a52bc Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/806a52bc Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/806a52bc Branch: refs/heads/master Commit: 806a52bc8626d412f7928cef54be10882f01a364 Parents: 8bd1d09 Author: quynhn <[email protected]> Authored: Mon Nov 6 15:59:25 2017 +0700 Committer: quynhn <[email protected]> Committed: Wed Nov 15 09:22:18 2017 +0700 ---------------------------------------------------------------------- .../org/apache/james/mailbox/acl/ACLDiff.java | 96 ++++++++ .../james/mailbox/acl/PositiveUserACLDiff.java | 45 ++-- .../apache/james/mailbox/acl/ACLDiffTest.java | 235 +++++++++++++++++++ .../mailbox/acl/PositiveUserACLDiffTest.java | 133 +++++++++-- 4 files changed, 460 insertions(+), 49 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/806a52bc/mailbox/api/src/main/java/org/apache/james/mailbox/acl/ACLDiff.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/acl/ACLDiff.java b/mailbox/api/src/main/java/org/apache/james/mailbox/acl/ACLDiff.java new file mode 100644 index 0000000..7631261 --- /dev/null +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/acl/ACLDiff.java @@ -0,0 +1,96 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.mailbox.acl; + +import java.util.Map; +import java.util.Objects; +import java.util.stream.Stream; + +import org.apache.james.mailbox.model.MailboxACL; + +public class ACLDiff { + + public static ACLDiff computeDiff(MailboxACL oldACL, MailboxACL newACL) { + return new ACLDiff(oldACL, newACL); + } + + private final MailboxACL oldACL; + private final MailboxACL newACL; + + public ACLDiff(MailboxACL oldACL, MailboxACL newACL) { + this.oldACL = oldACL; + this.newACL = newACL; + } + + public Stream<MailboxACL.Entry> addedEntries() { + return newACL.getEntries() + .entrySet() + .stream() + .filter(entry -> !oldACL.getEntries().containsKey(entry.getKey())) + .map(entry -> new MailboxACL.Entry(entry.getKey(), entry.getValue())); + } + + public Stream<MailboxACL.Entry> removedEntries() { + return oldACL.getEntries() + .entrySet() + .stream() + .filter(entry -> !newACL.getEntries().containsKey(entry.getKey())) + .map(entry -> new MailboxACL.Entry(entry.getKey(), entry.getValue())); + } + + public Stream<MailboxACL.Entry> changedEntries() { + Map<MailboxACL.EntryKey, MailboxACL.Rfc4314Rights> oldEntries = oldACL.getEntries(); + + return newACL.getEntries() + .entrySet() + .stream() + .filter(entry -> hasKeyWithDifferentValue(oldEntries, entry)) + .map(entry -> new MailboxACL.Entry(entry.getKey(), entry.getValue())); + } + + private boolean hasKeyWithDifferentValue(Map<MailboxACL.EntryKey, MailboxACL.Rfc4314Rights> oldEntries, + Map.Entry<MailboxACL.EntryKey, MailboxACL.Rfc4314Rights> entry) { + return oldEntries.containsKey(entry.getKey()) + && !oldEntries.get(entry.getKey()).equals(entry.getValue()); + } + + public MailboxACL getOldACL() { + return oldACL; + } + + public MailboxACL getNewACL() { + return newACL; + } + + @Override + public final boolean equals(Object o) { + if (o instanceof ACLDiff) { + ACLDiff aclDiff = (ACLDiff) o; + + return Objects.equals(this.oldACL, aclDiff.oldACL) + && Objects.equals(this.newACL, aclDiff.newACL); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(oldACL, newACL); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/806a52bc/mailbox/api/src/main/java/org/apache/james/mailbox/acl/PositiveUserACLDiff.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/acl/PositiveUserACLDiff.java b/mailbox/api/src/main/java/org/apache/james/mailbox/acl/PositiveUserACLDiff.java index 065ef67..062a6a1 100644 --- a/mailbox/api/src/main/java/org/apache/james/mailbox/acl/PositiveUserACLDiff.java +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/acl/PositiveUserACLDiff.java @@ -18,53 +18,38 @@ ****************************************************************/ package org.apache.james.mailbox.acl; -import java.util.Map; import java.util.stream.Stream; import org.apache.james.mailbox.model.MailboxACL; public class PositiveUserACLDiff { + private final ACLDiff aclDiff; - public static PositiveUserACLDiff computeDiff(MailboxACL oldACL, MailboxACL newACL) { - return new PositiveUserACLDiff(oldACL, newACL); + private PositiveUserACLDiff(ACLDiff aclDiff) { + this.aclDiff = aclDiff; } - private final MailboxACL oldACL; - private final MailboxACL newACL; - - private PositiveUserACLDiff(MailboxACL oldACL, MailboxACL newACL) { - this.oldACL = oldACL; - this.newACL = newACL; + public static PositiveUserACLDiff computeDiff(MailboxACL oldACL, MailboxACL newACL) { + return new PositiveUserACLDiff(ACLDiff.computeDiff(oldACL, newACL)); } public Stream<MailboxACL.Entry> addedEntries() { - Map<MailboxACL.EntryKey, MailboxACL.Rfc4314Rights> oldEntries = oldACL.ofPositiveNameType(MailboxACL.NameType.user); - - return newACL.ofPositiveNameType(MailboxACL.NameType.user) - .entrySet() - .stream() - .filter(entry -> !oldEntries.containsKey(entry.getKey())) - .map(entry -> new MailboxACL.Entry(entry.getKey(), entry.getValue())); + return aclDiff.addedEntries() + .filter(this::hasPositiveUserKey); } public Stream<MailboxACL.Entry> removedEntries() { - Map<MailboxACL.EntryKey, MailboxACL.Rfc4314Rights> newEntries = newACL.ofPositiveNameType(MailboxACL.NameType.user); - - return oldACL.ofPositiveNameType(MailboxACL.NameType.user) - .entrySet() - .stream() - .filter(entry -> !newEntries.containsKey(entry.getKey())) - .map(entry -> new MailboxACL.Entry(entry.getKey(), entry.getValue())); + return aclDiff.removedEntries() + .filter(this::hasPositiveUserKey); } public Stream<MailboxACL.Entry> changedEntries() { - Map<MailboxACL.EntryKey, MailboxACL.Rfc4314Rights> oldEntries = oldACL.ofPositiveNameType(MailboxACL.NameType.user); + return aclDiff.changedEntries() + .filter(this::hasPositiveUserKey); + } - return newACL.ofPositiveNameType(MailboxACL.NameType.user) - .entrySet() - .stream() - .filter(entry -> oldEntries.containsKey(entry.getKey()) - && !oldEntries.get(entry.getKey()).equals(entry.getValue())) - .map(entry -> new MailboxACL.Entry(entry.getKey(), entry.getValue())); + private boolean hasPositiveUserKey(MailboxACL.Entry entry) { + return !entry.getKey().isNegative() + && entry.getKey().getNameType().equals(MailboxACL.NameType.user); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/806a52bc/mailbox/api/src/test/java/org/apache/james/mailbox/acl/ACLDiffTest.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/acl/ACLDiffTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/acl/ACLDiffTest.java new file mode 100644 index 0000000..8a4ec8d --- /dev/null +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/acl/ACLDiffTest.java @@ -0,0 +1,235 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mailbox.acl; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.james.mailbox.exception.UnsupportedRightException; +import org.apache.james.mailbox.model.MailboxACL; +import org.junit.Test; + +public class ACLDiffTest { + private static final MailboxACL.EntryKey ENTRY_KEY = MailboxACL.EntryKey.createGroupEntryKey("any", false); + private static final MailboxACL.Rfc4314Rights RIGHTS = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Administer); + + @Test + public void addedEntriesShouldReturnEmptyWhenSameACL() { + ACLDiff aclDiff = ACLDiff.computeDiff( + MailboxACL.EMPTY, + MailboxACL.EMPTY); + + assertThat(aclDiff.addedEntries()).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 removedEntriesShouldReturnEmptyWhenSameACL() { + ACLDiff aclDiff = ACLDiff.computeDiff( + MailboxACL.EMPTY, + MailboxACL.EMPTY); + + assertThat(aclDiff.removedEntries()).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 changedEntriesShouldReturnEmptyWhenSameACL() { + ACLDiff aclDiff = ACLDiff.computeDiff( + MailboxACL.EMPTY, + MailboxACL.EMPTY); + + assertThat(aclDiff.changedEntries()).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 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)); + } + + @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 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 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 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 removedEntriesShouldReturnEmptyWhenChangedEntry() throws Exception { + ACLDiff aclDiff = ACLDiff.computeDiff( + MailboxACL.EMPTY.apply( + MailboxACL.command() + .key(ENTRY_KEY) + .rights(RIGHTS) + .asAddition()), + MailboxACL.EMPTY.apply( + MailboxACL.command() + .key(ENTRY_KEY) + .rights(MailboxACL.Right.Lookup) + .asAddition())); + + assertThat(aclDiff.removedEntries()) + .isEmpty(); + } + + @Test + public void addedEntriesShouldReturnEmptyWhenChangedEntry() throws Exception { + ACLDiff aclDiff = ACLDiff.computeDiff( + MailboxACL.EMPTY.apply( + MailboxACL.command() + .key(ENTRY_KEY) + .rights(RIGHTS) + .asAddition()), + MailboxACL.EMPTY.apply( + MailboxACL.command() + .key(ENTRY_KEY) + .rights(MailboxACL.Right.Lookup) + .asAddition())); + + assertThat(aclDiff.addedEntries()) + .isEmpty(); + } + + @Test + public void changedEntriesShouldReturnEntryWhenChangedEntry() throws Exception { + ACLDiff aclDiff = ACLDiff.computeDiff( + MailboxACL.EMPTY.apply( + MailboxACL.command() + .key(ENTRY_KEY) + .rights(MailboxACL.Right.Administer) + .asAddition()), + MailboxACL.EMPTY.apply( + MailboxACL.command() + .key(ENTRY_KEY) + .rights(MailboxACL.Right.Lookup) + .asAddition())); + + assertThat(aclDiff.changedEntries()) + .containsOnly(new MailboxACL.Entry(ENTRY_KEY, new MailboxACL.Rfc4314Rights(MailboxACL.Right.Lookup))); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/806a52bc/mailbox/api/src/test/java/org/apache/james/mailbox/acl/PositiveUserACLDiffTest.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/acl/PositiveUserACLDiffTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/acl/PositiveUserACLDiffTest.java index 1b81080..999f8c4 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/acl/PositiveUserACLDiffTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/acl/PositiveUserACLDiffTest.java @@ -30,7 +30,9 @@ import org.junit.Test; public class PositiveUserACLDiffTest { - private static final EntryKey ENTRY_KEY = EntryKey.createUserEntryKey("user"); + private static final EntryKey USER_ENTRY_KEY = EntryKey.createUserEntryKey("user"); + private static final EntryKey NEGATIVE_USER_ENTRY_KEY = EntryKey.createUserEntryKey("user", true); + private static final EntryKey GROUP_ENTRY_KEY = EntryKey.createGroupEntryKey("group"); private static final Rfc4314Rights RIGHTS = new Rfc4314Rights(Right.Administer); @Test @@ -46,7 +48,7 @@ public class PositiveUserACLDiffTest { public void addedEntriesShouldReturnEmptyWhenSameNonEmptyACL() throws UnsupportedRightException { MailboxACL mailboxACL = MailboxACL.EMPTY.apply( MailboxACL.command() - .key(ENTRY_KEY) + .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition()); @@ -68,7 +70,7 @@ public class PositiveUserACLDiffTest { public void removedEntriesShouldReturnEmptyWhenSameNonEmptyACL() throws UnsupportedRightException { MailboxACL mailboxACL = MailboxACL.EMPTY.apply( MailboxACL.command() - .key(ENTRY_KEY) + .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition()); @@ -90,7 +92,7 @@ public class PositiveUserACLDiffTest { public void changedEntriesShouldReturnEmptyWhenSameNonEmptyACL() throws UnsupportedRightException { MailboxACL mailboxACL = MailboxACL.EMPTY.apply( MailboxACL.command() - .key(ENTRY_KEY) + .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition()); @@ -98,18 +100,47 @@ public class PositiveUserACLDiffTest { assertThat(positiveUserAclDiff.changedEntries()).isEmpty(); } + @Test public void addedEntriesShouldReturnNewEntryWhenAddedEntry() throws Exception { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY, MailboxACL.EMPTY.apply( MailboxACL.command() - .key(ENTRY_KEY) + .key(USER_ENTRY_KEY) + .rights(RIGHTS) + .asAddition())); + + assertThat(positiveUserAclDiff.addedEntries()) + .containsOnly(new Entry(USER_ENTRY_KEY, RIGHTS)); + } + + @Test + public void addedEntriesShouldFilterNonUserEntryKey() throws Exception { + PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( + MailboxACL.EMPTY, + MailboxACL.EMPTY.apply( + MailboxACL.command() + .key(GROUP_ENTRY_KEY) + .rights(RIGHTS) + .asAddition())); + + assertThat(positiveUserAclDiff.addedEntries()) + .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()) - .containsOnly(new Entry(ENTRY_KEY, RIGHTS)); + .isEmpty(); } @Test @@ -118,7 +149,7 @@ public class PositiveUserACLDiffTest { MailboxACL.EMPTY, MailboxACL.EMPTY.apply( MailboxACL.command() - .key(ENTRY_KEY) + .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition())); @@ -132,7 +163,7 @@ public class PositiveUserACLDiffTest { MailboxACL.EMPTY, MailboxACL.EMPTY.apply( MailboxACL.command() - .key(ENTRY_KEY) + .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition())); @@ -145,7 +176,7 @@ public class PositiveUserACLDiffTest { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY.apply( MailboxACL.command() - .key(ENTRY_KEY) + .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition()), MailboxACL.EMPTY); @@ -159,7 +190,7 @@ public class PositiveUserACLDiffTest { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY.apply( MailboxACL.command() - .key(ENTRY_KEY) + .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition()), MailboxACL.EMPTY); @@ -173,13 +204,41 @@ public class PositiveUserACLDiffTest { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY.apply( MailboxACL.command() - .key(ENTRY_KEY) + .key(USER_ENTRY_KEY) + .rights(RIGHTS) + .asAddition()), + MailboxACL.EMPTY); + + assertThat(positiveUserAclDiff.removedEntries()) + .containsOnly(new Entry(USER_ENTRY_KEY, RIGHTS)); + } + + @Test + public void removedEntriesShouldFilterNonUserEntry() throws Exception { + PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( + MailboxACL.EMPTY.apply( + MailboxACL.command() + .key(GROUP_ENTRY_KEY) .rights(RIGHTS) .asAddition()), MailboxACL.EMPTY); assertThat(positiveUserAclDiff.removedEntries()) - .containsOnly(new Entry(ENTRY_KEY, RIGHTS)); + .isEmpty(); + } + + @Test + public void removedEntriesShouldFilterNegativeUserEntry() throws Exception { + PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( + MailboxACL.EMPTY.apply( + MailboxACL.command() + .key(NEGATIVE_USER_ENTRY_KEY) + .rights(RIGHTS) + .asAddition()), + MailboxACL.EMPTY); + + assertThat(positiveUserAclDiff.removedEntries()) + .isEmpty(); } @Test @@ -187,12 +246,12 @@ public class PositiveUserACLDiffTest { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY.apply( MailboxACL.command() - .key(ENTRY_KEY) + .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition()), MailboxACL.EMPTY.apply( MailboxACL.command() - .key(ENTRY_KEY) + .key(USER_ENTRY_KEY) .rights(Right.Lookup) .asAddition())); @@ -205,12 +264,12 @@ public class PositiveUserACLDiffTest { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY.apply( MailboxACL.command() - .key(ENTRY_KEY) + .key(USER_ENTRY_KEY) .rights(RIGHTS) .asAddition()), MailboxACL.EMPTY.apply( MailboxACL.command() - .key(ENTRY_KEY) + .key(USER_ENTRY_KEY) .rights(Right.Lookup) .asAddition())); @@ -223,16 +282,52 @@ public class PositiveUserACLDiffTest { PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( MailboxACL.EMPTY.apply( MailboxACL.command() - .key(ENTRY_KEY) + .key(USER_ENTRY_KEY) .rights(Right.Administer) .asAddition()), MailboxACL.EMPTY.apply( MailboxACL.command() - .key(ENTRY_KEY) + .key(USER_ENTRY_KEY) .rights(Right.Lookup) .asAddition())); assertThat(positiveUserAclDiff.changedEntries()) - .containsOnly(new Entry(ENTRY_KEY, new Rfc4314Rights(MailboxACL.Right.Lookup))); + .containsOnly(new Entry(USER_ENTRY_KEY, new Rfc4314Rights(MailboxACL.Right.Lookup))); + } + + @Test + public void changedEntriesShouldFilterNonUserEntry() throws Exception { + PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( + MailboxACL.EMPTY.apply( + MailboxACL.command() + .key(GROUP_ENTRY_KEY) + .rights(Right.Administer) + .asAddition()), + MailboxACL.EMPTY.apply( + MailboxACL.command() + .key(GROUP_ENTRY_KEY) + .rights(Right.Lookup) + .asAddition())); + + assertThat(positiveUserAclDiff.changedEntries()) + .isEmpty(); + } + + @Test + public void changedEntriesShouldFilterNegativeUserEntry() throws Exception { + PositiveUserACLDiff positiveUserAclDiff = PositiveUserACLDiff.computeDiff( + MailboxACL.EMPTY.apply( + MailboxACL.command() + .key(NEGATIVE_USER_ENTRY_KEY) + .rights(Right.Administer) + .asAddition()), + MailboxACL.EMPTY.apply( + MailboxACL.command() + .key(NEGATIVE_USER_ENTRY_KEY) + .rights(Right.Lookup) + .asAddition())); + + assertThat(positiveUserAclDiff.changedEntries()) + .isEmpty(); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
