Author: rdonkin
Date: Wed Nov 26 13:37:05 2008
New Revision: 720990

URL: http://svn.apache.org/viewvc?rev=720990&view=rev
Log:
Factored out user adding. First step towards being able to run script against 
remote manager. Added jmock for BDD.

Added:
    
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/NullMonitor.java
    
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/UserAdder.java
Modified:
    james/protocol-tester/trunk/main/pom.xml
    
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalHostSystem.java
    
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/HostSystem.java
    
james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestExternalHostSystem.java
    james/protocol-tester/trunk/pom.xml

Modified: james/protocol-tester/trunk/main/pom.xml
URL: 
http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/pom.xml?rev=720990&r1=720989&r2=720990&view=diff
==============================================================================
--- james/protocol-tester/trunk/main/pom.xml (original)
+++ james/protocol-tester/trunk/main/pom.xml Wed Nov 26 13:37:05 2008
@@ -41,5 +41,10 @@
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
     </dependency>
+       <dependency>
+      <groupId>jmock</groupId>
+      <artifactId>jmock</artifactId>
+      <scope>test</scope>
+    </dependency>   
   </dependencies>
 </project>

Modified: 
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalHostSystem.java
URL: 
http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalHostSystem.java?rev=720990&r1=720989&r2=720990&view=diff
==============================================================================
--- 
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalHostSystem.java
 (original)
+++ 
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/ExternalHostSystem.java
 Wed Nov 26 13:37:05 2008
@@ -36,6 +36,8 @@
     private final Monitor monitor;
 
     private final String shabang;
+    
+    private final UserAdder userAdder;
 
     /**
      * Constructs a host system suitable for connection to an open port.
@@ -46,19 +48,24 @@
      * first line received from the server. Many protocols pass server 
specific information
      * in the first line. When not null, this line will be replaced.
      * Or null when the first line should be passed without replacement
+     * @param userAdder null when test system has appropriate users already set
      */
     public ExternalHostSystem(final String host, final int port,
-            final Monitor monitor, final String shabang) {
+            final Monitor monitor, final String shabang, final UserAdder 
userAdder) {
         super();
         this.address = new InetSocketAddress(host, port);
         this.monitor = monitor;
         this.shabang = shabang;
+        this.userAdder = userAdder;
     }
 
-    public boolean addUser(String user, String password) throws Exception {
-        monitor.note("Please ensure user '" + user + "' with password '"
+    public void addUser(String user, String password) throws Exception {
+        if (userAdder == null) {
+            monitor.note("Please ensure user '" + user + "' with password '"
                 + password + "' exists.");
-        return true;
+        } else {
+            userAdder.addUser(user, password);
+        }
     }
 
     public Session newSession(Continuation continuation) throws Exception {

Modified: 
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/HostSystem.java
URL: 
http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/HostSystem.java?rev=720990&r1=720989&r2=720990&view=diff
==============================================================================
--- 
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/HostSystem.java
 (original)
+++ 
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/HostSystem.java
 Wed Nov 26 13:37:05 2008
@@ -41,7 +41,7 @@
      *            user password
      * @throws Exception
      */
-    public boolean addUser(String user, String password) throws Exception;
+    public void addUser(String user, String password) throws Exception;
 
     /**
      * Creates a new session for functional testing.

Added: 
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/NullMonitor.java
URL: 
http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/NullMonitor.java?rev=720990&view=auto
==============================================================================
--- 
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/NullMonitor.java
 (added)
+++ 
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/NullMonitor.java
 Wed Nov 26 13:37:05 2008
@@ -0,0 +1,29 @@
+/****************************************************************
+ * 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.mpt;
+
+/**
+ * Discards all monitored messages.
+ */
+public class NullMonitor implements Monitor {
+
+    public void note(String message) {
+    }
+}

Added: 
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/UserAdder.java
URL: 
http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/UserAdder.java?rev=720990&view=auto
==============================================================================
--- 
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/UserAdder.java
 (added)
+++ 
james/protocol-tester/trunk/main/src/main/java/org/apache/james/mpt/UserAdder.java
 Wed Nov 26 13:37:05 2008
@@ -0,0 +1,34 @@
+/****************************************************************
+ * 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.mpt;
+
+/**
+ * Adds users on demand.
+ */
+public interface UserAdder {
+    
+    /**
+     * Adds a user.
+     * @param user not null
+     * @param password not null
+     * @throws Exception when user cannot be added
+     */
+    public void addUser(String user, String password) throws Exception;
+}

Modified: 
james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestExternalHostSystem.java
URL: 
http://svn.apache.org/viewvc/james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestExternalHostSystem.java?rev=720990&r1=720989&r2=720990&view=diff
==============================================================================
--- 
james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestExternalHostSystem.java
 (original)
+++ 
james/protocol-tester/trunk/main/src/test/java/org/apache/james/mpt/TestExternalHostSystem.java
 Wed Nov 26 13:37:05 2008
@@ -20,12 +20,18 @@
 package org.apache.james.mpt;
 
 import org.apache.james.mpt.HostSystem.Continuation;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
 
 import junit.framework.TestCase;
 
-public class TestExternalHostSystem extends TestCase {
+public class TestExternalHostSystem extends MockObjectTestCase {
 
     
+    private static final String USER = "USER NAME";
+
+    private static final String PASSWORD = "SOME PASSWORD";
+
     private static final String SHABANG = "This Is The Shabang";
 
     private static final int PORT = 10001;
@@ -33,6 +39,12 @@
     private DiscardProtocol protocol;
     
     private DiscardProtocol.Record record;
+
+    private Continuation continuation;
+
+    private UserAdder userAdder;
+
+    private Mock mockUserAdder;
     
     //@Override
     protected void setUp() throws Exception {
@@ -40,6 +52,9 @@
         protocol = new DiscardProtocol(PORT);
         protocol.start();
         record = protocol.recordNext();
+        continuation = (Continuation) mock(Continuation.class).proxy();
+        mockUserAdder = mock(UserAdder.class);
+        userAdder = (UserAdder) mockUserAdder.proxy();
     }
 
     //@Override
@@ -55,13 +70,22 @@
         session.stop();
         assertEquals(in + "\r\n", record.complete());
     }
+    
+    public void testAddUser() throws Exception {
+        mockUserAdder.expects(once()).method("addUser").with(eq(USER), 
eq(PASSWORD));
+        ExternalHostSystem system = buildSystem(SHABANG);
+        system.addUser(USER, PASSWORD);
+    }
 
     private ExternalHostSystem.Session newSession(final String shabang) throws 
Exception {
-        ExternalHostSystem system = new ExternalHostSystem("localhost", PORT ,
-                new SystemLoggingMonitor(), shabang);
-        ExternalHostSystem.Session session = system.newSession(new 
Continuation() {
-            public void doContinue() {}
-        });
+        ExternalHostSystem system = buildSystem(shabang);
+        ExternalHostSystem.Session session = system.newSession(continuation);
         return session;
     }
+
+    private ExternalHostSystem buildSystem(final String shabang) {
+        ExternalHostSystem system = new ExternalHostSystem("localhost", PORT ,
+                new NullMonitor(), shabang, userAdder);
+        return system;
+    }
 }

Modified: james/protocol-tester/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/james/protocol-tester/trunk/pom.xml?rev=720990&r1=720989&r2=720990&view=diff
==============================================================================
--- james/protocol-tester/trunk/pom.xml (original)
+++ james/protocol-tester/trunk/pom.xml Wed Nov 26 13:37:05 2008
@@ -251,6 +251,12 @@
       <artifactId>junit</artifactId>
       <version>3.8.1</version>
     </dependency>
+    <dependency>
+      <groupId>jmock</groupId>
+      <artifactId>jmock</artifactId>
+      <version>1.1.0</version>
+      <scope>test</scope>
+    </dependency>
    </dependencies>
   </dependencyManagement>
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to