JAMES-2121 Rewrite RRT test to not swallow exceptions in booleans
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/e30e0174 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/e30e0174 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/e30e0174 Branch: refs/heads/master Commit: e30e0174d6743879711a8ee77021ec8c6e4e37d0 Parents: 589f347 Author: Raphael Ouazana <raphael.ouaz...@linagora.com> Authored: Thu Aug 31 15:13:56 2017 +0200 Committer: benwa <btell...@linagora.com> Committed: Fri Sep 1 17:26:22 2017 +0700 ---------------------------------------------------------------------- .../CassandraRecipientRewriteTableTest.java | 72 +++++++++---------- .../rrt/file/XMLRecipientRewriteTableTest.java | 17 ++--- .../hbase/HBaseRecipientRewriteTableTest.java | 71 +++++++++--------- .../rrt/jdbc/JDBCRecipientRewriteTableTest.java | 75 +++++++++----------- .../rrt/jpa/JPARecipientRewriteTableTest.java | 66 +++++++++-------- .../lib/AbstractRecipientRewriteTableTest.java | 66 +++++++++-------- .../InMemoryRecipientRewriteTableTest.java | 73 +++++++++---------- 7 files changed, 204 insertions(+), 236 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/e30e0174/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableTest.java b/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableTest.java index 122161c..171dd71 100644 --- a/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableTest.java +++ b/server/data/data-cassandra/src/test/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTableTest.java @@ -56,50 +56,42 @@ public class CassandraRecipientRewriteTableTest extends AbstractRecipientRewrite } @Override - protected boolean addMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException { - try { - switch (type) { - case ERROR_TYPE: - virtualUserTable.addErrorMapping(user, domain, mapping); - return true; - case REGEX_TYPE: - virtualUserTable.addRegexMapping(user, domain, mapping); - return true; - case ADDRESS_TYPE: - virtualUserTable.addAddressMapping(user, domain, mapping); - return true; - case ALIASDOMAIN_TYPE: - virtualUserTable.addAliasDomainMapping(domain, mapping); - return true; - default: - return false; - } - } catch (RecipientRewriteTableException e) { - return false; + protected void addMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException { + switch (type) { + case ERROR_TYPE: + virtualUserTable.addErrorMapping(user, domain, mapping); + break; + case REGEX_TYPE: + virtualUserTable.addRegexMapping(user, domain, mapping); + break; + case ADDRESS_TYPE: + virtualUserTable.addAddressMapping(user, domain, mapping); + break; + case ALIASDOMAIN_TYPE: + virtualUserTable.addAliasDomainMapping(domain, mapping); + break; + default: + throw new RuntimeException("Invalid mapping type: " + type); } } @Override - protected boolean removeMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException { - try { - switch (type) { - case ERROR_TYPE: - virtualUserTable.removeErrorMapping(user, domain, mapping); - return true; - case REGEX_TYPE: - virtualUserTable.removeRegexMapping(user, domain, mapping); - return true; - case ADDRESS_TYPE: - virtualUserTable.removeAddressMapping(user, domain, mapping); - return true; - case ALIASDOMAIN_TYPE: - virtualUserTable.removeAliasDomainMapping(domain, mapping); - return true; - default: - return false; - } - } catch (RecipientRewriteTableException e) { - return false; + protected void removeMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException { + switch (type) { + case ERROR_TYPE: + virtualUserTable.removeErrorMapping(user, domain, mapping); + break; + case REGEX_TYPE: + virtualUserTable.removeRegexMapping(user, domain, mapping); + break; + case ADDRESS_TYPE: + virtualUserTable.removeAddressMapping(user, domain, mapping); + break; + case ALIASDOMAIN_TYPE: + virtualUserTable.removeAliasDomainMapping(domain, mapping); + break; + default: + throw new RuntimeException("Invalid mapping type: " + type); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/e30e0174/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java b/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java index 0a11783..b5a5771 100644 --- a/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java +++ b/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java @@ -61,7 +61,7 @@ public class XMLRecipientRewriteTableTest extends AbstractRecipientRewriteTableT } @Override - protected boolean addMapping(String user, String domain, String mapping, int type) throws + protected void addMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException { Mappings mappings = virtualUserTable.getUserDomainMappings(user, domain); @@ -91,21 +91,21 @@ public class XMLRecipientRewriteTableTest extends AbstractRecipientRewriteTableT try { virtualUserTable.configure(defaultConfiguration); } catch (Exception e) { - return updatedMappings.size() <= 0; + if (updatedMappings.size() > 0) { + throw new RecipientRewriteTableException("Error update mapping", e); + } } - return true; - } @Override - protected boolean removeMapping(String user, String domain, String mapping, int type) throws + protected void removeMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException { Mappings mappings = virtualUserTable.getUserDomainMappings(user, domain); if (mappings == null) { - return false; + throw new RecipientRewriteTableException("Cannot remove from null mappings"); } removeMappingsFromConfig(user, domain, mappings); @@ -127,9 +127,10 @@ public class XMLRecipientRewriteTableTest extends AbstractRecipientRewriteTableT try { virtualUserTable.configure(defaultConfiguration); } catch (Exception e) { - return mappings.size() <= 0; + if (mappings.size() > 0) { + throw new RecipientRewriteTableException("Error update mapping", e); + } } - return true; } private void removeMappingsFromConfig(String user, String domain, Mappings mappings) { http://git-wip-us.apache.org/repos/asf/james-project/blob/e30e0174/server/data/data-hbase/src/test/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTableTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-hbase/src/test/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTableTest.java b/server/data/data-hbase/src/test/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTableTest.java index 04dc114..e8769ca 100644 --- a/server/data/data-hbase/src/test/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTableTest.java +++ b/server/data/data-hbase/src/test/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTableTest.java @@ -53,50 +53,43 @@ public class HBaseRecipientRewriteTableTest extends AbstractRecipientRewriteTabl return rrt; } - /** - */ @Override - protected boolean addMapping(String user, String domain, String mapping, int type) throws - RecipientRewriteTableException { - try { - if (type == ERROR_TYPE) { - virtualUserTable.addErrorMapping(user, domain, mapping); - } else if (type == REGEX_TYPE) { - virtualUserTable.addRegexMapping(user, domain, mapping); - } else if (type == ADDRESS_TYPE) { - virtualUserTable.addAddressMapping(user, domain, mapping); - } else if (type == ALIASDOMAIN_TYPE) { - virtualUserTable.addAliasDomainMapping(domain, mapping); - } else { - return false; - } - return true; - } catch (RecipientRewriteTableException e) { - return false; + protected void addMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException { + switch (type) { + case ERROR_TYPE: + virtualUserTable.addErrorMapping(user, domain, mapping); + break; + case REGEX_TYPE: + virtualUserTable.addRegexMapping(user, domain, mapping); + break; + case ADDRESS_TYPE: + virtualUserTable.addAddressMapping(user, domain, mapping); + break; + case ALIASDOMAIN_TYPE: + virtualUserTable.addAliasDomainMapping(domain, mapping); + break; + default: + throw new RuntimeException("Invalid mapping type: " + type); } } - /** - * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest#removeMapping(String, String, String, int) - */ @Override - protected boolean removeMapping(String user, String domain, String mapping, int type) throws - RecipientRewriteTableException { - try { - if (type == ERROR_TYPE) { - virtualUserTable.removeErrorMapping(user, domain, mapping); - } else if (type == REGEX_TYPE) { - virtualUserTable.removeRegexMapping(user, domain, mapping); - } else if (type == ADDRESS_TYPE) { - virtualUserTable.removeAddressMapping(user, domain, mapping); - } else if (type == ALIASDOMAIN_TYPE) { - virtualUserTable.removeAliasDomainMapping(domain, mapping); - } else { - return false; - } - return true; - } catch (RecipientRewriteTableException e) { - return false; + protected void removeMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException { + switch (type) { + case ERROR_TYPE: + virtualUserTable.removeErrorMapping(user, domain, mapping); + break; + case REGEX_TYPE: + virtualUserTable.removeRegexMapping(user, domain, mapping); + break; + case ADDRESS_TYPE: + virtualUserTable.removeAddressMapping(user, domain, mapping); + break; + case ALIASDOMAIN_TYPE: + virtualUserTable.removeAliasDomainMapping(domain, mapping); + break; + default: + throw new RuntimeException("Invalid mapping type: " + type); } } } http://git-wip-us.apache.org/repos/asf/james-project/blob/e30e0174/server/data/data-jdbc/src/test/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTableTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-jdbc/src/test/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTableTest.java b/server/data/data-jdbc/src/test/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTableTest.java index a2caeed..bd5d614 100644 --- a/server/data/data-jdbc/src/test/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTableTest.java +++ b/server/data/data-jdbc/src/test/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTableTest.java @@ -57,54 +57,43 @@ public class JDBCRecipientRewriteTableTest extends AbstractRecipientRewriteTable return ds; } - /** - * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest#addMapping(java.lang.String, - * java.lang.String, java.lang.String, int) - */ @Override - protected boolean addMapping(String user, String domain, String mapping, int type) throws - RecipientRewriteTableException { - try { - if (type == ERROR_TYPE) { - virtualUserTable.addErrorMapping(user, domain, mapping); - } else if (type == REGEX_TYPE) { - virtualUserTable.addRegexMapping(user, domain, mapping); - } else if (type == ADDRESS_TYPE) { - virtualUserTable.addAddressMapping(user, domain, mapping); - } else if (type == ALIASDOMAIN_TYPE) { - virtualUserTable.addAliasDomainMapping(domain, mapping); - } else { - return false; - } - } catch (RecipientRewriteTableException ex) { - return false; + protected void addMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException { + switch (type) { + case ERROR_TYPE: + virtualUserTable.addErrorMapping(user, domain, mapping); + break; + case REGEX_TYPE: + virtualUserTable.addRegexMapping(user, domain, mapping); + break; + case ADDRESS_TYPE: + virtualUserTable.addAddressMapping(user, domain, mapping); + break; + case ALIASDOMAIN_TYPE: + virtualUserTable.addAliasDomainMapping(domain, mapping); + break; + default: + throw new RuntimeException("Invalid mapping type: " + type); } - return true; } - /** - * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest#removeMapping(java.lang.String, - * java.lang.String, java.lang.String, int) - */ @Override - protected boolean removeMapping(String user, String domain, String mapping, int type) throws - RecipientRewriteTableException { - try { - - if (type == ERROR_TYPE) { - virtualUserTable.removeErrorMapping(user, domain, mapping); - } else if (type == REGEX_TYPE) { - virtualUserTable.removeRegexMapping(user, domain, mapping); - } else if (type == ADDRESS_TYPE) { - virtualUserTable.removeAddressMapping(user, domain, mapping); - } else if (type == ALIASDOMAIN_TYPE) { - virtualUserTable.removeAliasDomainMapping(domain, mapping); - } else { - return false; - } - } catch (RecipientRewriteTableException ex) { - return false; + protected void removeMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException { + switch (type) { + case ERROR_TYPE: + virtualUserTable.removeErrorMapping(user, domain, mapping); + break; + case REGEX_TYPE: + virtualUserTable.removeRegexMapping(user, domain, mapping); + break; + case ADDRESS_TYPE: + virtualUserTable.removeAddressMapping(user, domain, mapping); + break; + case ALIASDOMAIN_TYPE: + virtualUserTable.removeAliasDomainMapping(domain, mapping); + break; + default: + throw new RuntimeException("Invalid mapping type: " + type); } - return true; } } http://git-wip-us.apache.org/repos/asf/james-project/blob/e30e0174/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPARecipientRewriteTableTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPARecipientRewriteTableTest.java b/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPARecipientRewriteTableTest.java index e82f506..5b49a8a 100644 --- a/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPARecipientRewriteTableTest.java +++ b/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPARecipientRewriteTableTest.java @@ -42,44 +42,42 @@ public class JPARecipientRewriteTableTest extends AbstractRecipientRewriteTableT } @Override - protected boolean addMapping(String user, String domain, String mapping, int type) throws - RecipientRewriteTableException { - try { - if (type == ERROR_TYPE) { - virtualUserTable.addErrorMapping(user, domain, mapping); - } else if (type == REGEX_TYPE) { - virtualUserTable.addRegexMapping(user, domain, mapping); - } else if (type == ADDRESS_TYPE) { - virtualUserTable.addAddressMapping(user, domain, mapping); - } else if (type == ALIASDOMAIN_TYPE) { - virtualUserTable.addAliasDomainMapping(domain, mapping); - } else { - return false; - } - return true; - } catch (RecipientRewriteTableException e) { - return false; + protected void addMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException { + switch (type) { + case ERROR_TYPE: + virtualUserTable.addErrorMapping(user, domain, mapping); + break; + case REGEX_TYPE: + virtualUserTable.addRegexMapping(user, domain, mapping); + break; + case ADDRESS_TYPE: + virtualUserTable.addAddressMapping(user, domain, mapping); + break; + case ALIASDOMAIN_TYPE: + virtualUserTable.addAliasDomainMapping(domain, mapping); + break; + default: + throw new RuntimeException("Invalid mapping type: " + type); } } @Override - protected boolean removeMapping(String user, String domain, String mapping, int type) throws - RecipientRewriteTableException { - try { - if (type == ERROR_TYPE) { - virtualUserTable.removeErrorMapping(user, domain, mapping); - } else if (type == REGEX_TYPE) { - virtualUserTable.removeRegexMapping(user, domain, mapping); - } else if (type == ADDRESS_TYPE) { - virtualUserTable.removeAddressMapping(user, domain, mapping); - } else if (type == ALIASDOMAIN_TYPE) { - virtualUserTable.removeAliasDomainMapping(domain, mapping); - } else { - return false; - } - return true; - } catch (RecipientRewriteTableException e) { - return false; + protected void removeMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException { + switch (type) { + case ERROR_TYPE: + virtualUserTable.removeErrorMapping(user, domain, mapping); + break; + case REGEX_TYPE: + virtualUserTable.removeRegexMapping(user, domain, mapping); + break; + case ADDRESS_TYPE: + virtualUserTable.removeAddressMapping(user, domain, mapping); + break; + case ALIASDOMAIN_TYPE: + virtualUserTable.removeAliasDomainMapping(domain, mapping); + break; + default: + throw new RuntimeException("Invalid mapping type: " + type); } } } http://git-wip-us.apache.org/repos/asf/james-project/blob/e30e0174/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java index f481102..67a414d 100644 --- a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java +++ b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java @@ -29,7 +29,9 @@ import org.apache.james.rrt.api.RecipientRewriteTable.ErrorMappingException; import org.apache.james.rrt.api.RecipientRewriteTableException; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; /** * The abstract test for the virtual user table. Contains tests related to @@ -38,6 +40,8 @@ import org.junit.Test; */ public abstract class AbstractRecipientRewriteTableTest { + @Rule public ExpectedException expectedException = ExpectedException.none(); + protected AbstractRecipientRewriteTable virtualUserTable; protected final static int REGEX_TYPE = 0; protected final static int ERROR_TYPE = 1; @@ -92,11 +96,11 @@ public abstract class AbstractRecipientRewriteTableTest { assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull(); - assertThat(addMapping(user, domain, regex, REGEX_TYPE)).describedAs("Added virtual mapping").isTrue(); - assertThat(addMapping(user, domain, regex2, REGEX_TYPE)).describedAs("Added virtual mapping").isTrue(); + addMapping(user, domain, regex, REGEX_TYPE); + addMapping(user, domain, regex2, REGEX_TYPE); assertThat(virtualUserTable.getMappings(user, domain)).describedAs("Two mappings").hasSize(2); assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1); - assertThat(removeMapping(user, domain, regex, REGEX_TYPE)).describedAs("remove virtual mapping").isTrue(); + removeMapping(user, domain, regex, REGEX_TYPE); try { virtualUserTable.addRegexMapping(user, domain, invalidRegex); @@ -105,7 +109,7 @@ public abstract class AbstractRecipientRewriteTableTest { } assertThat(catched).describedAs("Invalid Mapping throw exception").isTrue(); - assertThat(removeMapping(user, domain, regex2, REGEX_TYPE)).describedAs("remove virtual mapping").isTrue(); + removeMapping(user, domain, regex2, REGEX_TYPE); assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull(); @@ -130,13 +134,13 @@ public abstract class AbstractRecipientRewriteTableTest { assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull(); - assertThat(addMapping(user, domain, address, ADDRESS_TYPE)).describedAs("Added virtual mapping").isTrue(); - assertThat(addMapping(user, domain, address2, ADDRESS_TYPE)).describedAs("Added virtual mapping").isTrue(); + addMapping(user, domain, address, ADDRESS_TYPE); + addMapping(user, domain, address2, ADDRESS_TYPE); assertThat(virtualUserTable.getMappings(user, domain)).describedAs("Two mappings").hasSize(2); assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1); - assertThat(removeMapping(user, domain, address, ADDRESS_TYPE)).describedAs("remove virtual mapping").isTrue(); + removeMapping(user, domain, address, ADDRESS_TYPE); /* * TEMPORARILY REMOVE JDBC specific test String invalidAddress= @@ -149,7 +153,7 @@ public abstract class AbstractRecipientRewriteTableTest { */ - assertThat(removeMapping(user, domain, address2, ADDRESS_TYPE)).describedAs("remove virtual mapping").isTrue(); + removeMapping(user, domain, address2, ADDRESS_TYPE); assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull(); assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isNull(); @@ -171,7 +175,7 @@ public abstract class AbstractRecipientRewriteTableTest { try { assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull(); - assertThat(addMapping(user, domain, error, ERROR_TYPE)).describedAs("Added virtual mapping").isTrue(); + addMapping(user, domain, error, ERROR_TYPE); assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1); try { @@ -181,7 +185,7 @@ public abstract class AbstractRecipientRewriteTableTest { } assertThat(catched).describedAs("Error Mapping throw exception").isTrue(); - assertThat(removeMapping(user, domain, error, ERROR_TYPE)).describedAs("remove virtual mapping").isTrue(); + removeMapping(user, domain, error, ERROR_TYPE); assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull(); assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isNull(); @@ -205,14 +209,14 @@ public abstract class AbstractRecipientRewriteTableTest { assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull(); - assertThat(addMapping(RecipientRewriteTable.WILDCARD, domain, address, ADDRESS_TYPE)).describedAs("Added virtual mapping").isTrue(); - assertThat(addMapping(user, domain, address2, ADDRESS_TYPE)).describedAs("Added virtual mapping").isTrue(); + addMapping(RecipientRewriteTable.WILDCARD, domain, address, ADDRESS_TYPE); + addMapping(user, domain, address2, ADDRESS_TYPE); assertThat(virtualUserTable.getMappings(user, domain)).describedAs("One mappings").hasSize(1); assertThat(virtualUserTable.getMappings(user2, domain)).describedAs("One mappings").hasSize(1); - assertThat(removeMapping(user, domain, address2, ADDRESS_TYPE)).describedAs("remove virtual mapping").isTrue(); - assertThat(removeMapping(RecipientRewriteTable.WILDCARD, domain, address, ADDRESS_TYPE)).describedAs("remove virtual mapping").isTrue(); + removeMapping(user, domain, address2, ADDRESS_TYPE); + removeMapping(RecipientRewriteTable.WILDCARD, domain, address, ADDRESS_TYPE); assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull(); assertThat(virtualUserTable.getMappings(user2, domain)).describedAs("No mapping").isNull(); @@ -239,10 +243,10 @@ public abstract class AbstractRecipientRewriteTableTest { try { assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isNull(); - assertThat(addMapping(user1, domain1, user2 + "@" + domain2, ADDRESS_TYPE)).describedAs("Added mapping").isTrue(); - assertThat(addMapping(user2, domain2, user3 + "@" + domain3, ADDRESS_TYPE)).describedAs("Added mapping").isTrue(); + addMapping(user1, domain1, user2 + "@" + domain2, ADDRESS_TYPE); + addMapping(user2, domain2, user3 + "@" + domain3, ADDRESS_TYPE); assertThat(virtualUserTable.getMappings(user1, domain1)).containsOnly(MappingImpl.address(user3 + "@" + domain3)); - assertThat(addMapping(user3, domain3, user1 + "@" + domain1, ADDRESS_TYPE)).describedAs("Added mapping").isTrue(); + addMapping(user3, domain3, user1 + "@" + domain1, ADDRESS_TYPE); try { virtualUserTable.getMappings(user1, domain1); @@ -272,20 +276,16 @@ public abstract class AbstractRecipientRewriteTableTest { try { - assertThat(addMapping(RecipientRewriteTable.WILDCARD, aliasDomain, user2 + "@" + domain, - ADDRESS_TYPE)).describedAs("Add mapping").isTrue(); - assertThat(addMapping(RecipientRewriteTable.WILDCARD, aliasDomain, domain, - ALIASDOMAIN_TYPE)).describedAs("Add aliasDomain mapping").isTrue(); + addMapping(RecipientRewriteTable.WILDCARD, aliasDomain, user2 + "@" + domain, ADDRESS_TYPE); + addMapping(RecipientRewriteTable.WILDCARD, aliasDomain, domain, ALIASDOMAIN_TYPE); assertThat(virtualUserTable.getMappings(user, aliasDomain)) .describedAs("Domain mapped as first, Address mapped as second") .containsExactly(MappingImpl.address(user + "@" + domain), MappingImpl.address(user2 + "@" + domain)); - assertThat(removeMapping(RecipientRewriteTable.WILDCARD, aliasDomain, user2 + "@" + domain, - ADDRESS_TYPE)).describedAs("Remove mapping").isTrue(); + removeMapping(RecipientRewriteTable.WILDCARD, aliasDomain, user2 + "@" + domain, ADDRESS_TYPE); - assertThat(removeMapping(RecipientRewriteTable.WILDCARD, aliasDomain, domain, - ALIASDOMAIN_TYPE)).describedAs("Remove aliasDomain mapping").isTrue(); + removeMapping(RecipientRewriteTable.WILDCARD, aliasDomain, domain, ALIASDOMAIN_TYPE); } catch (IllegalArgumentException e) { fail("Storing failed"); @@ -334,8 +334,10 @@ public abstract class AbstractRecipientRewriteTableTest { String domain = "localhost"; String address = "test@localhost2"; - assertThat(addMapping(user, domain, address, ADDRESS_TYPE)).isTrue(); - assertThat(addMapping(user, domain, address, ADDRESS_TYPE)).isFalse(); + expectedException.expect(RecipientRewriteTableException.class); + + addMapping(user, domain, address, ADDRESS_TYPE); + addMapping(user, domain, address, ADDRESS_TYPE); } @Test @@ -344,16 +346,18 @@ public abstract class AbstractRecipientRewriteTableTest { String domain = "localhost"; String address = "test@localhost2"; - assertThat(addMapping(user, domain, address, ADDRESS_TYPE)).isTrue(); - assertThat(addMapping(user, domain, address, ERROR_TYPE)).isTrue(); + addMapping(user, domain, address, ADDRESS_TYPE); + addMapping(user, domain, address, REGEX_TYPE); + + assertThat(virtualUserTable.getMappings(user, domain)).hasSize(2); } protected abstract AbstractRecipientRewriteTable getRecipientRewriteTable() throws Exception; - protected abstract boolean addMapping(String user, String domain, String mapping, int type) throws + protected abstract void addMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException; - protected abstract boolean removeMapping(String user, String domain, String mapping, int type) throws + protected abstract void removeMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException; private void removeMapping(String user, String domain, String rawMapping) throws RecipientRewriteTableException { http://git-wip-us.apache.org/repos/asf/james-project/blob/e30e0174/server/data/data-memory/src/test/java/org/apache/james/rrt/memory/InMemoryRecipientRewriteTableTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-memory/src/test/java/org/apache/james/rrt/memory/InMemoryRecipientRewriteTableTest.java b/server/data/data-memory/src/test/java/org/apache/james/rrt/memory/InMemoryRecipientRewriteTableTest.java index 210e56f..de089c2 100644 --- a/server/data/data-memory/src/test/java/org/apache/james/rrt/memory/InMemoryRecipientRewriteTableTest.java +++ b/server/data/data-memory/src/test/java/org/apache/james/rrt/memory/InMemoryRecipientRewriteTableTest.java @@ -34,51 +34,42 @@ public class InMemoryRecipientRewriteTableTest extends AbstractRecipientRewriteT } @Override - protected boolean addMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException { - try { - switch (type) { - case ERROR_TYPE: - virtualUserTable.addErrorMapping(user, domain, mapping); - return true; - case REGEX_TYPE: - virtualUserTable.addRegexMapping(user, domain, mapping); - return true; - case ADDRESS_TYPE: - virtualUserTable.addAddressMapping(user, domain, mapping); - return true; - case ALIASDOMAIN_TYPE: - virtualUserTable.addAliasDomainMapping(domain, mapping); - return true; - default: - return false; - } - } catch (RecipientRewriteTableException e) { - return false; + protected void addMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException { + switch (type) { + case ERROR_TYPE: + virtualUserTable.addErrorMapping(user, domain, mapping); + break; + case REGEX_TYPE: + virtualUserTable.addRegexMapping(user, domain, mapping); + break; + case ADDRESS_TYPE: + virtualUserTable.addAddressMapping(user, domain, mapping); + break; + case ALIASDOMAIN_TYPE: + virtualUserTable.addAliasDomainMapping(domain, mapping); + break; + default: + throw new RuntimeException("Invalid mapping type: " + type); } } @Override - protected boolean removeMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException { - try { - switch (type) { - case ERROR_TYPE: - virtualUserTable.removeErrorMapping(user, domain, mapping); - return true; - case REGEX_TYPE: - virtualUserTable.removeRegexMapping(user, domain, mapping); - return true; - case ADDRESS_TYPE: - virtualUserTable.removeAddressMapping(user, domain, mapping); - return true; - case ALIASDOMAIN_TYPE: - virtualUserTable.removeAliasDomainMapping(domain, mapping); - return true; - default: - return false; - } - } catch (RecipientRewriteTableException e) { - return false; + protected void removeMapping(String user, String domain, String mapping, int type) throws RecipientRewriteTableException { + switch (type) { + case ERROR_TYPE: + virtualUserTable.removeErrorMapping(user, domain, mapping); + break; + case REGEX_TYPE: + virtualUserTable.removeRegexMapping(user, domain, mapping); + break; + case ADDRESS_TYPE: + virtualUserTable.removeAddressMapping(user, domain, mapping); + break; + case ALIASDOMAIN_TYPE: + virtualUserTable.removeAliasDomainMapping(domain, mapping); + break; + default: + throw new RuntimeException("Invalid mapping type: " + type); } } - } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org