Author: matthieu Date: Mon Nov 2 14:54:04 2015 New Revision: 1712027 URL: http://svn.apache.org/viewvc?rev=1712027&view=rev Log: JAMES-1587 Improve domain list tests
Contributed by Benoit Tellier and Raphael Ouazana Modified: james/project/trunk/server/data/data-hbase/pom.xml james/project/trunk/server/data/data-hbase/src/test/java/org/apache/james/domainlist/hbase/HBaseDomainListTest.java james/project/trunk/server/data/data-jpa/pom.xml james/project/trunk/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java Modified: james/project/trunk/server/data/data-hbase/pom.xml URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-hbase/pom.xml?rev=1712027&r1=1712026&r2=1712027&view=diff ============================================================================== --- james/project/trunk/server/data/data-hbase/pom.xml (original) +++ james/project/trunk/server/data/data-hbase/pom.xml Mon Nov 2 14:54:04 2015 @@ -168,6 +168,10 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + </dependency> + <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <scope>test</scope> Modified: james/project/trunk/server/data/data-hbase/src/test/java/org/apache/james/domainlist/hbase/HBaseDomainListTest.java URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-hbase/src/test/java/org/apache/james/domainlist/hbase/HBaseDomainListTest.java?rev=1712027&r1=1712026&r2=1712027&view=diff ============================================================================== --- james/project/trunk/server/data/data-hbase/src/test/java/org/apache/james/domainlist/hbase/HBaseDomainListTest.java (original) +++ james/project/trunk/server/data/data-hbase/src/test/java/org/apache/james/domainlist/hbase/HBaseDomainListTest.java Mon Nov 2 14:54:04 2015 @@ -20,11 +20,13 @@ package org.apache.james.domainlist.hbas import java.io.IOException; import org.apache.james.domainlist.api.DomainList; +import org.apache.james.domainlist.api.DomainListException; import org.apache.james.domainlist.lib.AbstractDomainListTest; import org.apache.james.mailbox.hbase.HBaseClusterSingleton; import org.apache.james.system.hbase.TablePool; -import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; import org.slf4j.LoggerFactory; /** @@ -54,4 +56,11 @@ public class HBaseDomainListTest extends domainList.setAutoDetectIP(false); return domainList; } + + @Ignore + @Test + @Override + public void removeDomainShouldThrowIfTheDomainIsAbsent() throws DomainListException { + + } } Modified: james/project/trunk/server/data/data-jpa/pom.xml URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-jpa/pom.xml?rev=1712027&r1=1712026&r2=1712027&view=diff ============================================================================== --- james/project/trunk/server/data/data-jpa/pom.xml (original) +++ james/project/trunk/server/data/data-jpa/pom.xml Mon Nov 2 14:54:04 2015 @@ -124,6 +124,10 @@ <type>test-jar</type> </dependency> <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + </dependency> + <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <scope>test</scope> Modified: james/project/trunk/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java?rev=1712027&r1=1712026&r2=1712027&view=diff ============================================================================== --- james/project/trunk/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java (original) +++ james/project/trunk/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java Mon Nov 2 14:54:04 2015 @@ -18,125 +18,161 @@ ****************************************************************/ package org.apache.james.domainlist.lib; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.fail; + import java.net.InetAddress; import java.net.UnknownHostException; import org.apache.james.dnsservice.api.DNSService; import org.apache.james.dnsservice.api.mock.MockDNSService; import org.apache.james.domainlist.api.DomainList; import org.apache.james.domainlist.api.DomainListException; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.*; +import org.junit.After; import org.junit.Before; import org.junit.Test; -/** - * Test the implementation of the DomainList. - */ public abstract class AbstractDomainListTest { - // Domains we will play with. private final String DOMAIN_1 = "domain1.tld"; private final String DOMAIN_2 = "domain2.tld"; private final String DOMAIN_3 = "domain3.tld"; private final String DOMAIN_4 = "domain4.tld"; private final String DOMAIN_5 = "domain5.tld"; - /** - * The JPA DomainList service. - */ + private final String DOMAIN_UPPER_5 = "Domain5.tld"; + private DomainList domainList; @Before public void setUp() throws Exception { domainList = createDomainList(); + } + + @After + public void tearDown() throws Exception { deleteAll(); } - /** - * Add 3 domains and list them. - * - * @throws DomainListException - */ @Test public void createListDomains() throws DomainListException { domainList.addDomain(DOMAIN_3); domainList.addDomain(DOMAIN_4); domainList.addDomain(DOMAIN_5); - assertEquals(3, domainList.getDomains().length); + assertThat(domainList.getDomains()).containsOnly(DOMAIN_3, DOMAIN_4, DOMAIN_5); } - /** - * Add a domain and check it is present. - * - * @throws DomainListException - */ @Test - public void testAddContainsDomain() throws DomainListException { + public void domainsShouldBeListedInLowerCase() throws DomainListException { + domainList.addDomain(DOMAIN_UPPER_5); + assertThat(domainList.getDomains()).containsOnly(DOMAIN_5); + } + + @Test + public void containShouldReturnTrueWhenThereIsADomain() throws DomainListException { domainList.addDomain(DOMAIN_2); - domainList.containsDomain(DOMAIN_2); + assertThat(domainList.containsDomain(DOMAIN_2)).isTrue(); + } + + @Test + public void containShouldBeCaseSensitive() throws DomainListException { + domainList.addDomain(DOMAIN_5); + assertThat(domainList.containsDomain(DOMAIN_UPPER_5)).isTrue(); + } + + @Test + public void listDomainsShouldReturnNullWhenThereIsNoDomains() throws DomainListException { + assertThat(domainList.getDomains()).isNull(); } - /** - * Add and remove a domain, and check database is empty. - * - * @throws DomainListException - */ @Test public void testAddRemoveContainsSameDomain() throws DomainListException { domainList.addDomain(DOMAIN_1); domainList.removeDomain(DOMAIN_1); - assertThat(domainList.getDomains(), nullValue()); + assertThat(domainList.getDomains()).isNull(); + } + + @Test(expected = DomainListException.class) + public void addShouldBeCaseSensitive() throws DomainListException { + try { + domainList.addDomain(DOMAIN_5); + } catch (Exception e) { + fail(e.getMessage()); + } + domainList.addDomain(DOMAIN_UPPER_5); } - /** - * Add two same domains with different cases, and check we've got an exception. - * - * @throws DomainListException - */ @Test - public void testUpperCaseSameDomain() throws DomainListException { + public void deletingADomainShouldNotDeleteOtherDomains() throws DomainListException { domainList.addDomain(DOMAIN_1); - assertEquals(1, domainList.getDomains().length); try { - String DOMAIN_1_UPPER_CASE = "Domain1.tld"; - domainList.addDomain(DOMAIN_1_UPPER_CASE); - fail("We should not be able to insert same domains, even with different cases"); - } catch (DomainListException domainListException) { - assertTrue(domainListException.getMessage().contains(DOMAIN_1)); + domainList.removeDomain(DOMAIN_2); + } catch (DomainListException e) { + } + assertThat(domainList.getDomains()).containsOnly(DOMAIN_1); + } + + @Test + public void containShouldReturnFalseWhenThereIsNoDomain() throws DomainListException { + assertThat(domainList.containsDomain(DOMAIN_1)).isFalse(); + } + + @Test + public void ContainsShouldReturnFalseWhenDomainIsRemoved() throws DomainListException { + domainList.addDomain(DOMAIN_1); + domainList.removeDomain(DOMAIN_1); + assertThat(domainList.containsDomain(DOMAIN_1)).isFalse(); } - /** - * Add a domain and remove another domain, and check first domain is still - * present. - * - * @throws DomainListException - */ @Test - public void testAddRemoveContainsDifferentDomain() throws DomainListException { + public void RemoveShouldRemoveDomainsUsingUpperCases() throws DomainListException { + domainList.addDomain(DOMAIN_UPPER_5); + domainList.removeDomain(DOMAIN_UPPER_5); + assertThat(domainList.containsDomain(DOMAIN_UPPER_5)).isFalse(); + } + + @Test + public void RemoveShouldRemoveDomainsUsingLowerCases() throws DomainListException { + domainList.addDomain(DOMAIN_UPPER_5); + domainList.removeDomain(DOMAIN_5); + assertThat(domainList.containsDomain(DOMAIN_UPPER_5)).isFalse(); + } + + @Test(expected = DomainListException.class) + public void addDomainShouldThrowIfWeAddTwoTimesTheSameDomain() throws DomainListException { + try { + domainList.addDomain(DOMAIN_1); + } catch (Exception e) { + fail(e.getMessage()); + } domainList.addDomain(DOMAIN_1); - domainList.removeDomain(DOMAIN_2); - assertEquals(1, domainList.getDomains().length); - assertEquals(true, domainList.containsDomain(DOMAIN_1)); + } + + @Test(expected = DomainListException.class) + public void removeDomainShouldThrowIfTheDomainIsAbsent() throws DomainListException { + domainList.removeDomain(DOMAIN_1); } /** * Delete all possible domains from database. - * - * @throws DomainListException */ - private void deleteAll() throws DomainListException { - domainList.removeDomain(DOMAIN_1); - domainList.removeDomain(DOMAIN_2); - domainList.removeDomain(DOMAIN_3); - domainList.removeDomain(DOMAIN_4); - domainList.removeDomain(DOMAIN_5); + private void deleteAll() { + deleteWithoutError(DOMAIN_1); + deleteWithoutError(DOMAIN_2); + deleteWithoutError(DOMAIN_3); + deleteWithoutError(DOMAIN_4); + deleteWithoutError(DOMAIN_5); + } + + private void deleteWithoutError(String domain) { + try { + domainList.removeDomain(domain); + } catch(DomainListException e) { + + } } /** * Return a fake DNSServer. - * - * @param hostName - * @return */ protected DNSService getDNSServer(final String hostName) { return new MockDNSService() { --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org