private static Map<EntryKey, Rfc4314Rights> toMap(Properties props) throws UnsupportedRightException { ImmutableMap.Builder<EntryKey, Rfc4314Rights> builder = ImmutableMap.builder(); if (props != null) { for (Map.Entry<?, ?> prop : props.entrySet()) { builder.put(EntryKey.deserialize((String) prop.getKey()), Rfc4314Rights.fromSerializedRfc4314Rights((String) prop.getValue())); } } return builder.build(); }
@Test public void testNegativeGroup() throws UnsupportedRightException { assertThat(EntryKey.deserialize(String.valueOf(MailboxACL.DEFAULT_NEGATIVE_MARKER) + MailboxACL.DEFAULT_GROUP_MARKER + GROUP_1)) .isEqualTo(new EntryKey(GROUP_1, NameType.group, true)); }
@Test public void testGroup() throws UnsupportedRightException { assertThat(EntryKey.deserialize(MailboxACL.DEFAULT_GROUP_MARKER + GROUP_1)) .isEqualTo(new EntryKey(GROUP_1, NameType.group, false)); }
public Entry(String key, String value) throws UnsupportedRightException { this(EntryKey.deserialize(key), Rfc4314Rights.fromSerializedRfc4314Rights(value)); }
public Entry(String key, Right... rights) throws UnsupportedRightException { this(EntryKey.deserialize(key), new Rfc4314Rights(rights)); }
@Override public Object deserializeKey(String key, DeserializationContext deserializationContext) throws IOException { return MailboxACL.EntryKey.deserialize(key); } }
@Test public void testNegativeAuthenticated() throws UnsupportedRightException { assertThat(EntryKey.deserialize(MailboxACL.DEFAULT_NEGATIVE_MARKER + SpecialName.authenticated.toString())) .isEqualTo(new EntryKey(SpecialName.authenticated.toString(), NameType.special, true)); }
@Test public void testAnybody() throws UnsupportedRightException { assertThat(EntryKey.deserialize(SpecialName.anybody.toString())) .isEqualTo(new EntryKey(SpecialName.anybody.toString(), NameType.special, false)); }
@Test public void testOwner() throws UnsupportedRightException { assertThat(EntryKey.deserialize(SpecialName.owner.toString())) .isEqualTo(new EntryKey(SpecialName.owner.toString(), NameType.special, false)); }
@Test public void testUser() throws UnsupportedRightException { assertThat(EntryKey.deserialize(USER_1)) .isEqualTo(new EntryKey(USER_1, NameType.user, false)); }
@Test public void testExceptACLExisting() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.put(EntryKey.deserialize(USER_1), Rfc4314Rights.fromSerializedRfc4314Rights(ik)); MailboxACL toRemove = new MailboxACL(new Entry(USER_1, ae)); MailboxACL result = u1u2g1g2ACL.except(toRemove); Map<EntryKey, Rfc4314Rights> foundEntries = result.getEntries(); assertThat(foundEntries).isEqualTo(expectedEntries); }
@Test public void testUnionACLExisting() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.put(EntryKey.deserialize(USER_1), Rfc4314Rights.fromSerializedRfc4314Rights(aeik + lprs)); MailboxACL toAdd = new MailboxACL(new Entry(USER_1, lprs)); MailboxACL result = u1u2g1g2ACL.union(toAdd); Map<EntryKey, Rfc4314Rights> foundEntries = result.getEntries(); assertThat(expectedEntries).isEqualTo(foundEntries); }
@Test public void testNegativeAnybody() throws UnsupportedRightException { assertThat(EntryKey.deserialize(MailboxACL.DEFAULT_NEGATIVE_MARKER + SpecialName.anybody.toString())) .isEqualTo(new EntryKey(SpecialName.anybody.toString(), NameType.special, true)); }
@Test public void testNegativeOwner() throws UnsupportedRightException { assertThat(EntryKey.deserialize(MailboxACL.DEFAULT_NEGATIVE_MARKER + SpecialName.owner.toString())) .isEqualTo(new EntryKey(SpecialName.owner.toString(), NameType.special, true)); }
@Test public void testExceptACLFull() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.remove(EntryKey.deserialize(USER_1)); MailboxACL toRemove = new MailboxACL(new Entry(USER_1, MailboxACL.FULL_RIGHTS.serialize())); MailboxACL result = u1u2g1g2ACL.except(toRemove); Map<EntryKey, Rfc4314Rights> foundEntries = result.getEntries(); assertThat(foundEntries).isEqualTo(expectedEntries); }
@Test public void testAuthenticated() throws UnsupportedRightException { assertThat(EntryKey.deserialize(SpecialName.authenticated.toString())) .isEqualTo(new EntryKey(SpecialName.authenticated.toString(), NameType.special, false)); }
@Test public void testNegativeUser() throws UnsupportedRightException { assertThat(EntryKey.deserialize(MailboxACL.DEFAULT_NEGATIVE_MARKER + USER_1)) .isEqualTo(new EntryKey(USER_1, NameType.user, true)); }
@Test public void testExceptEntryFull() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.remove(EntryKey.deserialize(USER_1)); MailboxACL result = u1u2g1g2ACL.except(EntryKey.deserialize(USER_1), MailboxACL.FULL_RIGHTS); Map<EntryKey, Rfc4314Rights> foundEntries = result.getEntries(); assertThat(foundEntries).isEqualTo(expectedEntries); }
@Test public void testUnionEntryExisting() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.put(EntryKey.deserialize(USER_1), Rfc4314Rights.fromSerializedRfc4314Rights(aeik + lprs)); MailboxACL result = u1u2g1g2ACL.union(EntryKey.deserialize(USER_1), Rfc4314Rights.fromSerializedRfc4314Rights(lprs)); Map<EntryKey, Rfc4314Rights> foundEntries = result.getEntries(); assertThat(foundEntries).isEqualTo(expectedEntries); }
@Test public void testExceptEntryExisting() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.put(EntryKey.deserialize(USER_1), Rfc4314Rights.fromSerializedRfc4314Rights(ik)); MailboxACL result = u1u2g1g2ACL.except(EntryKey.deserialize(USER_1), Rfc4314Rights.fromSerializedRfc4314Rights(ae)); Map<EntryKey, Rfc4314Rights> foundEntries = result.getEntries(); assertThat(foundEntries).isEqualTo(expectedEntries); }