Author: matthieu
Date: Mon Nov  2 13:37:02 2015
New Revision: 1711965

URL: http://svn.apache.org/viewvc?rev=1711965&view=rev
Log:
JAMES-1594 First test on empty mapping

Modified:
    james/project/trunk/server/data/data-file/pom.xml
    
james/project/trunk/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLStepdefs.java
    james/project/trunk/server/data/data-hbase/pom.xml
    
james/project/trunk/server/data/data-hbase/src/test/java/org/apache/james/rrt/hbase/HBaseStepdefs.java
    james/project/trunk/server/data/data-jdbc/pom.xml
    
james/project/trunk/server/data/data-jdbc/src/test/java/org/apache/james/rrt/jdbc/JDBCStepdefs.java
    james/project/trunk/server/data/data-jpa/pom.xml
    
james/project/trunk/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPAStepdefs.java
    james/project/trunk/server/data/data-library/pom.xml
    
james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
    
james/project/trunk/server/data/data-library/src/test/resources/cucumber/rewrite_tables.feature
    james/project/trunk/server/pom.xml

Modified: james/project/trunk/server/data/data-file/pom.xml
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/data/data-file/pom.xml?rev=1711965&r1=1711964&r2=1711965&view=diff
==============================================================================
--- james/project/trunk/server/data/data-file/pom.xml (original)
+++ james/project/trunk/server/data/data-file/pom.xml Mon Nov  2 13:37:02 2015
@@ -96,11 +96,21 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>info.cukes</groupId>
+            <artifactId>cucumber-picocontainer</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.james</groupId>
             <artifactId>james-server-data-library</artifactId>
             <type>test-jar</type>

Modified: 
james/project/trunk/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLStepdefs.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLStepdefs.java?rev=1711965&r1=1711964&r2=1711965&view=diff
==============================================================================
--- 
james/project/trunk/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLStepdefs.java
 (original)
+++ 
james/project/trunk/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLStepdefs.java
 Mon Nov  2 13:37:02 2015
@@ -18,13 +18,28 @@
  ****************************************************************/
 package org.apache.james.rrt.file;
 
-import cucumber.api.java.en.Given;
+import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
+import org.apache.james.rrt.lib.RewriteTablesStepdefs;
+import org.slf4j.LoggerFactory;
 
-public class XMLStepdefs{
+import cucumber.api.java.Before;
 
-    @Given("perform backend setup")
-    public void given() throws Throwable {
-        System.out.println("XML");
+public class XMLStepdefs {
+
+    private RewriteTablesStepdefs mainStepdefs;
+
+    public XMLStepdefs(RewriteTablesStepdefs mainStepdefs) {
+        this.mainStepdefs = mainStepdefs;
     }
 
+    @Before
+    public void setup() throws Throwable {
+        mainStepdefs.rewriteTable = getRecipientRewriteTable(); 
+    }
+
+    private AbstractRecipientRewriteTable getRecipientRewriteTable() throws 
Exception {
+        XMLRecipientRewriteTable localVirtualUserTable = new 
XMLRecipientRewriteTable();
+        localVirtualUserTable.setLog(LoggerFactory.getLogger("MockLog"));
+        return localVirtualUserTable;
+    }
 }

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=1711965&r1=1711964&r2=1711965&view=diff
==============================================================================
--- james/project/trunk/server/data/data-hbase/pom.xml (original)
+++ james/project/trunk/server/data/data-hbase/pom.xml Mon Nov  2 13:37:02 2015
@@ -114,11 +114,21 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>info.cukes</groupId>
+            <artifactId>cucumber-picocontainer</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.james</groupId>
             <artifactId>james-server-data-library</artifactId>
             <type>test-jar</type>

Modified: 
james/project/trunk/server/data/data-hbase/src/test/java/org/apache/james/rrt/hbase/HBaseStepdefs.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/data/data-hbase/src/test/java/org/apache/james/rrt/hbase/HBaseStepdefs.java?rev=1711965&r1=1711964&r2=1711965&view=diff
==============================================================================
--- 
james/project/trunk/server/data/data-hbase/src/test/java/org/apache/james/rrt/hbase/HBaseStepdefs.java
 (original)
+++ 
james/project/trunk/server/data/data-hbase/src/test/java/org/apache/james/rrt/hbase/HBaseStepdefs.java
 Mon Nov  2 13:37:02 2015
@@ -18,13 +18,43 @@
  ****************************************************************/
 package org.apache.james.rrt.hbase;
 
-import cucumber.api.java.en.Given;
+import java.io.IOException;
 
-public class HBaseStepdefs{
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.james.mailbox.hbase.HBaseClusterSingleton;
+import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
+import org.apache.james.rrt.lib.RewriteTablesStepdefs;
+import org.apache.james.system.hbase.TablePool;
+import org.slf4j.LoggerFactory;
 
-    @Given("perform backend setup")
-    public void given() throws Throwable {
-        System.out.println("HBase");
+import com.google.common.base.Throwables;
+
+import cucumber.api.java.Before;
+
+public class HBaseStepdefs {
+
+    private static final HBaseClusterSingleton cluster = 
HBaseClusterSingleton.build();
+
+    private RewriteTablesStepdefs mainStepdefs;
+
+    public HBaseStepdefs(RewriteTablesStepdefs mainStepdefs) {
+        try {
+            this.mainStepdefs = mainStepdefs;
+            TablePool.getInstance(cluster.getConf());
+        } catch (IOException e) {
+            Throwables.propagate(e);
+        }
+    }
+
+    @Before
+    public void setup() throws Throwable {
+        mainStepdefs.rewriteTable = getRecipientRewriteTable(); 
     }
 
+    private AbstractRecipientRewriteTable getRecipientRewriteTable() throws 
Exception {
+        HBaseRecipientRewriteTable rrt = new HBaseRecipientRewriteTable();
+        rrt.setLog(LoggerFactory.getLogger("MockLog"));
+        rrt.configure(new DefaultConfigurationBuilder());
+        return rrt;
+    }
 }

Modified: james/project/trunk/server/data/data-jdbc/pom.xml
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/data/data-jdbc/pom.xml?rev=1711965&r1=1711964&r2=1711965&view=diff
==============================================================================
--- james/project/trunk/server/data/data-jdbc/pom.xml (original)
+++ james/project/trunk/server/data/data-jdbc/pom.xml Mon Nov  2 13:37:02 2015
@@ -101,11 +101,21 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>info.cukes</groupId>
+            <artifactId>cucumber-picocontainer</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.james</groupId>
             <artifactId>james-server-data-library</artifactId>
             <type>test-jar</type>

Modified: 
james/project/trunk/server/data/data-jdbc/src/test/java/org/apache/james/rrt/jdbc/JDBCStepdefs.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/data/data-jdbc/src/test/java/org/apache/james/rrt/jdbc/JDBCStepdefs.java?rev=1711965&r1=1711964&r2=1711965&view=diff
==============================================================================
--- 
james/project/trunk/server/data/data-jdbc/src/test/java/org/apache/james/rrt/jdbc/JDBCStepdefs.java
 (original)
+++ 
james/project/trunk/server/data/data-jdbc/src/test/java/org/apache/james/rrt/jdbc/JDBCStepdefs.java
 Mon Nov  2 13:37:02 2015
@@ -18,13 +18,48 @@
  ****************************************************************/
 package org.apache.james.rrt.jdbc;
 
-import cucumber.api.java.en.Given;
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.derby.jdbc.EmbeddedDriver;
+import org.apache.james.filesystem.api.mock.MockFileSystem;
+import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
+import org.apache.james.rrt.lib.RewriteTablesStepdefs;
+import org.slf4j.LoggerFactory;
 
-public class JDBCStepdefs{
+import cucumber.api.java.Before;
 
-    @Given("perform backend setup")
-    public void given() throws Throwable {
-        System.out.println("JDBC");
+public class JDBCStepdefs {
+
+    private RewriteTablesStepdefs mainStepdefs;
+
+    public JDBCStepdefs(RewriteTablesStepdefs mainStepdefs) {
+        this.mainStepdefs = mainStepdefs;
+    }
+
+    @Before
+    public void setup() throws Throwable {
+        mainStepdefs.rewriteTable = getRecipientRewriteTable(); 
     }
 
+    protected AbstractRecipientRewriteTable getRecipientRewriteTable() throws 
Exception {
+        JDBCRecipientRewriteTable localVirtualUserTable = new 
JDBCRecipientRewriteTable();
+        localVirtualUserTable.setLog(LoggerFactory.getLogger("MockLog"));
+        localVirtualUserTable.setDataSource(getDataSource());
+        localVirtualUserTable.setFileSystem(new MockFileSystem());
+        DefaultConfigurationBuilder defaultConfiguration = new 
DefaultConfigurationBuilder();
+        defaultConfiguration.addProperty("[@destinationURL]", 
"db://maildb/RecipientRewriteTable");
+        defaultConfiguration.addProperty("sqlFile", 
"file://conf/sqlResources.xml");
+        localVirtualUserTable.configure(defaultConfiguration);
+        localVirtualUserTable.init();
+        return localVirtualUserTable;
+    }
+    
+    private BasicDataSource getDataSource() {
+        BasicDataSource ds = new BasicDataSource();
+        ds.setDriverClassName(EmbeddedDriver.class.getName());
+        ds.setUrl("jdbc:derby:target/testdb;create=true");
+        ds.setUsername("james");
+        ds.setPassword("james");
+        return ds;
+    }
 }

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=1711965&r1=1711964&r2=1711965&view=diff
==============================================================================
--- james/project/trunk/server/data/data-jpa/pom.xml (original)
+++ james/project/trunk/server/data/data-jpa/pom.xml Mon Nov  2 13:37:02 2015
@@ -92,11 +92,21 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>info.cukes</groupId>
+            <artifactId>cucumber-picocontainer</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.james</groupId>
             <artifactId>james-server-data-library</artifactId>
             <type>test-jar</type>

Modified: 
james/project/trunk/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPAStepdefs.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPAStepdefs.java?rev=1711965&r1=1711964&r2=1711965&view=diff
==============================================================================
--- 
james/project/trunk/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPAStepdefs.java
 (original)
+++ 
james/project/trunk/server/data/data-jpa/src/test/java/org/apache/james/rrt/jpa/JPAStepdefs.java
 Mon Nov  2 13:37:02 2015
@@ -18,13 +18,54 @@
  ****************************************************************/
 package org.apache.james.rrt.jpa;
 
-import cucumber.api.java.en.Given;
+import java.util.HashMap;
 
-public class JPAStepdefs{
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.james.rrt.jpa.model.JPARecipientRewrite;
+import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
+import org.apache.james.rrt.lib.RewriteTablesStepdefs;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.slf4j.LoggerFactory;
 
-    @Given("perform backend setup")
-    public void given() throws Throwable {
-        System.out.println("JPA");
+import cucumber.api.java.Before;
+
+public class JPAStepdefs {
+
+    private RewriteTablesStepdefs mainStepdefs;
+
+    public JPAStepdefs(RewriteTablesStepdefs mainStepdefs) {
+        this.mainStepdefs = mainStepdefs;
+    }
+
+    @Before
+    public void setup() throws Throwable {
+        mainStepdefs.rewriteTable = getRecipientRewriteTable(); 
     }
 
+    private OpenJPAEntityManagerFactory managerFactory() throws Exception {
+
+        // Use a memory database.
+        /*
+      The properties for the OpenJPA Entity Manager.
+     */
+        HashMap<String, String> properties = new HashMap<String, String>();
+        properties.put("openjpa.ConnectionDriverName", "org.h2.Driver");
+        properties.put("openjpa.ConnectionURL", "jdbc:h2:target/users/db");
+        properties.put("openjpa.Log", "JDBC=WARN, SQL=WARN, Runtime=WARN");
+        properties.put("openjpa.ConnectionFactoryProperties", 
"PrettyPrint=true, PrettyPrintLineLength=72");
+        properties.put("openjpa.jdbc.SynchronizeMappings", 
"buildSchema(ForeignKeys=true)");
+        properties.put("openjpa.MetaDataFactory", "jpa(Types=" + 
JPARecipientRewrite.class.getName() + ")");
+
+        return OpenJPAPersistence.getEntityManagerFactory(properties);
+    }
+
+    private AbstractRecipientRewriteTable getRecipientRewriteTable() throws 
Exception {
+        JPARecipientRewriteTable localVirtualUserTable = new 
JPARecipientRewriteTable();
+        localVirtualUserTable.setLog(LoggerFactory.getLogger("MockLog"));
+        localVirtualUserTable.setEntityManagerFactory(managerFactory());
+        DefaultConfigurationBuilder defaultConfiguration = new 
DefaultConfigurationBuilder();
+        localVirtualUserTable.configure(defaultConfiguration);
+        return localVirtualUserTable;
+    }
 }

Modified: james/project/trunk/server/data/data-library/pom.xml
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/data/data-library/pom.xml?rev=1711965&r1=1711964&r2=1711965&view=diff
==============================================================================
--- james/project/trunk/server/data/data-library/pom.xml (original)
+++ james/project/trunk/server/data/data-library/pom.xml Mon Nov  2 13:37:02 
2015
@@ -98,6 +98,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-simple</artifactId>
             <scope>test</scope>

Modified: 
james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java?rev=1711965&r1=1711964&r2=1711965&view=diff
==============================================================================
--- 
james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
 (original)
+++ 
james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
 Mon Nov  2 13:37:02 2015
@@ -18,24 +18,16 @@
  ****************************************************************/
 package org.apache.james.rrt.lib;
 
-import cucumber.api.java.en.Given;
+import static org.assertj.core.api.Assertions.assertThat;
+
 import cucumber.api.java.en.Then;
-import cucumber.api.java.en.When;
 
 public class RewriteTablesStepdefs {
 
-    @Given("i'm up")
-    public void given() throws Throwable {
-        System.out.println("i'm up");
-    }
-
-    @When("it's time")
-    public void when() throws Throwable {
-        System.out.println("it's time");
-    }
+    public AbstractRecipientRewriteTable rewriteTable;
 
-    @Then("say hello")
-    public void then() throws Throwable {
-        System.out.println("say hello");
+    @Then("mappings should be empty")
+    public void assertMappingsIsEmpty() throws Throwable {
+        assertThat(rewriteTable.getAllMappings()).isNullOrEmpty();
     }
 }

Modified: 
james/project/trunk/server/data/data-library/src/test/resources/cucumber/rewrite_tables.feature
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/data/data-library/src/test/resources/cucumber/rewrite_tables.feature?rev=1711965&r1=1711964&r2=1711965&view=diff
==============================================================================
--- 
james/project/trunk/server/data/data-library/src/test/resources/cucumber/rewrite_tables.feature
 (original)
+++ 
james/project/trunk/server/data/data-library/src/test/resources/cucumber/rewrite_tables.feature
 Mon Nov  2 13:37:02 2015
@@ -1,7 +1,4 @@
 Feature: Rewrite Tables tests
 
-  Scenario: will say hello
-    Given i'm up
-    And perform backend setup
-    When it's time
-    Then say hello
\ No newline at end of file
+  Scenario: rewrite tables should be empty when none defined
+    Then mappings should be empty
\ No newline at end of file

Modified: james/project/trunk/server/pom.xml
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/pom.xml?rev=1711965&r1=1711964&r2=1711965&view=diff
==============================================================================
--- james/project/trunk/server/pom.xml (original)
+++ james/project/trunk/server/pom.xml Mon Nov  2 13:37:02 2015
@@ -842,6 +842,12 @@
                 <scope>test</scope>
             </dependency>
             <dependency>
+                <groupId>org.assertj</groupId>
+                <artifactId>assertj-core</artifactId>
+                <version>1.7.1</version>
+                <scope>test</scope>
+            </dependency>
+            <dependency>
                 <groupId>org.jmock</groupId>
                 <artifactId>jmock</artifactId>
                 <version>${jmock.version}</version>
@@ -1251,6 +1257,12 @@
                 <artifactId>cucumber-picocontainer</artifactId>
                 <version>${cucumber.version}</version>
             </dependency>
+            <dependency>
+                <groupId>info.cukes</groupId>
+                <artifactId>cucumber-picocontainer</artifactId>
+                <version>${cucumber.version}</version>
+                <scope>test</scope>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to