directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vte...@apache.org
Subject svn commit: rev 6986 - in incubator/directory/janus/trunk/script/src: java/org/apache/janus/script java/org/apache/janus/script/xml test/org/apache/janus/script/xml
Date Thu, 04 Mar 2004 05:54:54 GMT
Author: vtence
Date: Wed Mar  3 21:06:44 2004
New Revision: 6986

Modified:
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/NullRealmBuilderMonitor.java
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/Dom4JRealmBuilder.java
   incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/Dom4JRealmBuilderTest.java
Log:
o Refactored to keep things simple

Modified: incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/NullRealmBuilderMonitor.java
==============================================================================
--- incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/NullRealmBuilderMonitor.java
(original)
+++ incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/NullRealmBuilderMonitor.java
Wed Mar  3 21:06:44 2004
@@ -14,10 +14,9 @@
  *   limitations under the License.
  *
  */
-package org.apache.janus.script.xml;
+package org.apache.janus.script;
 
 import org.apache.janus.authentication.CredentialSet;
-import org.apache.janus.script.RealmBuilderMonitor;
 
 /**
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>

Modified: incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/Dom4JRealmBuilder.java
==============================================================================
--- incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/Dom4JRealmBuilder.java
(original)
+++ incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/Dom4JRealmBuilder.java
Wed Mar  3 21:06:44 2004
@@ -19,12 +19,16 @@
 import org.apache.janus.authentication.Credential;
 import org.apache.janus.authentication.CredentialSet;
 import org.apache.janus.authentication.realm.MutableRealm;
+import org.apache.janus.script.NullRealmBuilderMonitor;
 import org.apache.janus.script.RealmBuilder;
 import org.apache.janus.script.RealmBuilderMonitor;
 import org.dom4j.Document;
+import org.dom4j.DocumentException;
 import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
 
 import java.io.IOException;
+import java.io.Reader;
 import java.util.Iterator;
 import java.util.List;
 
@@ -37,12 +41,18 @@
  */
 public class Dom4JRealmBuilder implements RealmBuilder
 {
-    private final Document m_doc;
     private final RealmBuilderMonitor m_monitor;
+    private Document m_doc;
 
-    public Dom4JRealmBuilder( Document doc, RealmBuilderMonitor monitor )
+    public Dom4JRealmBuilder( Reader reader ) throws DocumentException
     {
-        m_doc = doc;
+        this( reader, new NullRealmBuilderMonitor() );
+    }
+
+    public Dom4JRealmBuilder( Reader reader, RealmBuilderMonitor monitor )
+            throws DocumentException
+    {
+        m_doc = readDocument( reader );
         m_monitor = monitor;
     }
 
@@ -69,5 +79,13 @@
             boolean added = realm.addIdentity( creds );
             if ( !added ) m_monitor.duplicateIdentity( creds );
         }
+    }
+
+    private Document readDocument( Reader reader ) throws DocumentException
+    {
+        SAXReader xmlReader = new SAXReader();
+        Document doc = xmlReader.read( reader );
+
+        return doc;
     }
 }

Modified: incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/Dom4JRealmBuilderTest.java
==============================================================================
--- incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/Dom4JRealmBuilderTest.java
(original)
+++ incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/Dom4JRealmBuilderTest.java
Wed Mar  3 21:06:44 2004
@@ -24,9 +24,8 @@
 import org.apache.janus.authentication.realm.MutableRealm;
 import org.apache.janus.authentication.realm.UsernamePasswordAuthentication;
 import org.apache.janus.script.RealmBuilderMonitor;
-import org.dom4j.Document;
-import org.dom4j.Element;
-import org.dom4j.tree.DefaultDocument;
+
+import java.io.StringReader;
 
 /**
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
@@ -44,7 +43,7 @@
 
     public void testSimpleBuild() throws Exception
     {
-        Dom4JRealmBuilder builder = new Dom4JRealmBuilder( simpleRealm(), new NullRealmBuilderMonitor()
);
+        Dom4JRealmBuilder builder = new Dom4JRealmBuilder( new StringReader( simpleRealm()
) );
 
         Mock mockRealm = new Mock( MutableRealm.class );
         mockRealm.expectAndReturn( "addIdentity", johnCredentials(), true );
@@ -55,19 +54,16 @@
         mockRealm.verify();
     }
 
-    private Document simpleRealm()
+    private String simpleRealm()
     {
-        Document doc = new DefaultDocument();
-        Element root = doc.addElement( "realm" );
-        Element users = root.addElement( "users" );
-        Element john = users.addElement( "user" );
-        john.addAttribute( "username", "john" );
-        john.addAttribute( "password", "doe" );
-        Element jane = users.addElement( "user" );
-        jane.addAttribute( "username", "jane" );
-        jane.addAttribute( "password", "doe" );
-
-        return doc;
+        String content = "<?xml version=\"1.0\"?>\n"
+                         + "<realm>\n"
+                         + "    <users>\n"
+                         + "        <user username=\"john\" password=\"doe\"/>\n"
+                         + "        <user username=\"jane\" password=\"doe\"/>\n"
+                         + "    </users>\n"
+                         + "</realm>";
+        return content;
     }
 
     private CredentialSet johnCredentials()
@@ -89,7 +85,8 @@
     public void testNotifiesOfDuplicateIdentities() throws Exception
     {
         Mock mockMonitor = new Mock( RealmBuilderMonitor.class );
-        Dom4JRealmBuilder builder = new Dom4JRealmBuilder( realmWithDuplicateIdentity(),
+        Dom4JRealmBuilder builder = new Dom4JRealmBuilder(
+                new StringReader( realmWithDuplicateIdentity() ),
                 (RealmBuilderMonitor) mockMonitor.proxy() );
 
         mockMonitor.expect( "duplicateIdentity", johnCredentials() );
@@ -98,18 +95,15 @@
         mockMonitor.verify();
     }
 
-    private Document realmWithDuplicateIdentity()
+    private String realmWithDuplicateIdentity()
     {
-        Document doc = new DefaultDocument();
-        Element root = doc.addElement( "realm" );
-        Element users = root.addElement( "users" );
-        Element john = users.addElement( "user" );
-        john.addAttribute( "username", "john" );
-        john.addAttribute( "password", "doe" );
-        Element jane = users.addElement( "user" );
-        jane.addAttribute( "username", "john" );
-        jane.addAttribute( "password", "doe" );
-
-        return doc;
+        String content = "<?xml version=\"1.0\"?>\n"
+                         + "<realm>\n"
+                         + "    <users>\n"
+                         + "        <user username=\"john\" password=\"doe\"/>\n"
+                         + "        <user username=\"john\" password=\"doe\"/>\n"
+                         + "    </users>\n"
+                         + "</realm>";
+        return content;
     }
 }

Mime
View raw message