directory-commits mailing list archives

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

Added:
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/script/NullRealmBuilderMonitor.java
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/NullRealmBuilderMonitor.java
      - copied unchanged from rev 6979, incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/NullRealmBuilderMonitor.java
Removed:
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/script/xml/NullRealmBuilderMonitor.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/script/xml/XMLRealm.java
   incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/script/xml/XMLRealmTest.java
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/NullRealmBuilderMonitor.java
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/XMLRealm.java
   incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/XMLRealmTest.java
Modified:
   incubator/directory/janus/trunk/sandbox/project.properties
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/script/xml/Dom4JRealmBuilder.java
   incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/script/xml/Dom4JRealmBuilderTest.java
Log:
o Refactored to keep things simple

Modified: incubator/directory/janus/trunk/sandbox/project.properties
==============================================================================
--- incubator/directory/janus/trunk/sandbox/project.properties	(original)
+++ incubator/directory/janus/trunk/sandbox/project.properties	Wed Mar  3 21:02:44 2004
@@ -1,3 +1,5 @@
+maven.repo.remote = http://www.ibiblio.org/maven, http://dist.codehaus.org
+
 maven.compile.source=1.4
 maven.compile.target=1.4
 maven.test.source=1.4

Added: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/script/NullRealmBuilderMonitor.java
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/script/NullRealmBuilderMonitor.java
Wed Mar  3 21:02:44 2004
@@ -0,0 +1,30 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.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>
+ */
+public class NullRealmBuilderMonitor implements RealmBuilderMonitor
+{
+    public void duplicateIdentity( CredentialSet identity )
+    {
+    }
+}

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/script/xml/Dom4JRealmBuilder.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/script/xml/Dom4JRealmBuilder.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/script/xml/Dom4JRealmBuilder.java
Wed Mar  3 21:02: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/sandbox/src/test/org/apache/janus/script/xml/Dom4JRealmBuilderTest.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/script/xml/Dom4JRealmBuilderTest.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/script/xml/Dom4JRealmBuilderTest.java
Wed Mar  3 21:02: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