directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vte...@apache.org
Subject svn commit: r109512 - in incubator/directory/janus/trunk/jdbc/src: java/org/apache/janus/authentication/realm test/org/apache/janus/authentication/realm
Date Thu, 02 Dec 2004 18:18:54 GMT
Author: vtence
Date: Thu Dec  2 10:18:53 2004
New Revision: 109512

URL: http://svn.apache.org/viewcvs?view=rev&rev=109512
Log:
Fixed nasty bug in tests where insert was not going to proper columns depending on credential
Class object ids, causing tests to fail randomly.
Added:
   incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/Creds.java
Modified:
   incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/AndExpression.java
   incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Column.java
   incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Converter.java
   incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/EqExpression.java
   incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Expression.java
   incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/ExpressionBuilder.java
   incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/JDBCSelector.java
   incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/SameCredentialsBuilder.java
   incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/SelectorBuilder.java
   incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Table.java
   incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/Columns.java
   incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCRealmTest.java
   incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCSelectorTest.java
   incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/MemoryDatabase.java
   incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/SameCredentialsBuilderTest.java

Modified: incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/AndExpression.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/AndExpression.java?view=diff&rev=109512&p1=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/AndExpression.java&r1=109511&p2=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/AndExpression.java&r2=109512
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/AndExpression.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/AndExpression.java
Thu Dec  2 10:18:53 2004
@@ -31,12 +31,12 @@
         m_right = right;
     }
 
-    public String getQueryString( Table table )
+    public String getQueryString()
     {
         StringBuffer fragment = new StringBuffer();
-        fragment.append( m_left.getQueryString( table ) );
+        fragment.append( m_left.getQueryString() );
         fragment.append( " " ).append( operand() ).append( " ");
-        fragment.append( m_right.getQueryString( table ));
+        fragment.append( m_right.getQueryString());
 
         return fragment.toString();
     }
@@ -46,18 +46,13 @@
         return m_left.getParameterCount() + m_right.getParameterCount();
     }
 
-    public String[] getParameterValues( Table table )
+    public String[] getParameterValues()
     {
         Collection parameters = new ArrayList( );
-        parameters.addAll( Arrays.asList( m_left.getParameterValues( table ) ) );
-        parameters.addAll( Arrays.asList( m_right.getParameterValues( table ) ) );
+        parameters.addAll( Arrays.asList( m_left.getParameterValues() ) );
+        parameters.addAll( Arrays.asList( m_right.getParameterValues() ) );
         
         return ( String[] ) parameters.toArray( new String[parameters.size()] );
-    }
-
-    public boolean supports( Table table )
-    {
-        return m_left.supports( table ) && m_right.supports( table );
     }
 
     protected String operand()

Modified: incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Column.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Column.java?view=diff&rev=109512&p1=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Column.java&r1=109511&p2=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Column.java&r2=109512
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Column.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Column.java
Thu Dec  2 10:18:53 2004
@@ -20,11 +20,18 @@
 {
     private final String m_name;
     private final Class m_type;
+    private final Converter m_converter;
 
     public Column( String name, Class type )
     {
+        this( name, type, new DefaultConverter() );
+    }
+
+    public Column( String name, Class type, Converter converter )
+    {
         m_name = name;
         m_type = type;
+        m_converter = converter;
     }
 
     public String getName()
@@ -35,5 +42,33 @@
     public Class getMappedType()
     {
         return m_type;
+    }
+
+    public String getValue( Object value )
+    {
+        return m_converter.convert( value );
+    }
+
+    public boolean equals( Object o )
+    {
+        if ( this == o ) return true;
+        if ( !( o instanceof Column ) ) return false;
+
+        final Column column = ( Column ) o;
+
+        if ( !m_name.equals( column.m_name ) ) return false;
+
+        return true;
+    }
+
+    public int hashCode()
+    {
+        return m_name.hashCode();
+    }
+
+
+    public String toString()
+    {
+        return "m_name=" + m_name + ", m_type=" + m_type;
     }
 }

Modified: incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Converter.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Converter.java?view=diff&rev=109512&p1=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Converter.java&r1=109511&p2=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Converter.java&r2=109512
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Converter.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Converter.java
Thu Dec  2 10:18:53 2004
@@ -18,7 +18,7 @@
 
 public interface Converter
 {
-    String convert( Object credential );
+    String convert( Object value );
 
-    boolean supports( Class credentialType );
+    boolean supports( Class type );
 }

Modified: incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/EqExpression.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/EqExpression.java?view=diff&rev=109512&p1=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/EqExpression.java&r1=109511&p2=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/EqExpression.java&r2=109512
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/EqExpression.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/EqExpression.java
Thu Dec  2 10:18:53 2004
@@ -18,19 +18,19 @@
 
 public class EqExpression implements Expression
 {
-    private final Class m_type;
+    private final Column m_column;
     private final Object m_value;
 
-    public EqExpression( Class type, Object value )
+    public EqExpression( Column column, Object value )
     {
-        m_type = type;
+        m_column = column;
         m_value = value;
     }
 
-    public String getQueryString( Table table )
+    public String getQueryString()
     {
         StringBuffer statement = new StringBuffer();
-        statement.append( table.getColumnName( m_type ) );
+        statement.append( m_column.getName() );
         statement.append( operand() );
         statement.append( "?" );
 
@@ -42,14 +42,9 @@
         return 1;
     }
 
-    public String[] getParameterValues( Table table )
+    public String[] getParameterValues()
     {
-        return new String[] { table.getColumnValue( m_value ) };
-    }
-
-    public boolean supports( Table table )
-    {
-        return table.supports( m_type ) ;
+        return new String[] { m_column.getValue( m_value ) };
     }
 
     protected String operand()
@@ -64,7 +59,7 @@
 
         final EqExpression eqExpression = ( EqExpression ) o;
 
-        if ( !m_type.equals( eqExpression.m_type ) ) return false;
+        if ( !m_column.equals( eqExpression.m_column ) ) return false;
         if ( !m_value.equals( eqExpression.m_value ) ) return false;
 
         return true;
@@ -73,13 +68,13 @@
     public int hashCode()
     {
         int result;
-        result = m_type.hashCode();
+        result = m_column.hashCode();
         result = 29 * result + m_value.hashCode();
         return result;
     }
 
     public String toString()
     {
-        return "eq(" + m_type.getName() + ", " + m_value.toString() + ")";
+        return "eq(" + m_column.getName() + ", " + m_value.toString() + ")";
     }
 }

Modified: incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Expression.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Expression.java?view=diff&rev=109512&p1=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Expression.java&r1=109511&p2=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Expression.java&r2=109512
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Expression.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Expression.java
Thu Dec  2 10:18:53 2004
@@ -18,11 +18,9 @@
 
 public interface Expression
 {
-    String getQueryString( Table table );
+    String getQueryString( );
 
     int getParameterCount();
 
-    String[] getParameterValues( Table table );
-
-    boolean supports( Table table );
+    String[] getParameterValues();
 }

Modified: incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/ExpressionBuilder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/ExpressionBuilder.java?view=diff&rev=109512&p1=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/ExpressionBuilder.java&r1=109511&p2=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/ExpressionBuilder.java&r2=109512
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/ExpressionBuilder.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/ExpressionBuilder.java
Thu Dec  2 10:18:53 2004
@@ -18,9 +18,16 @@
 
 public class ExpressionBuilder
 {
+    private final Table m_table;
+
+    public ExpressionBuilder( Table table )
+    {
+        m_table = table;
+    }
+
     public Expression eq( Class type, Object value )
     {
-        return new EqExpression( type, value );
+        return new EqExpression( m_table.getColumn( type ), value );
     }
 
     public Expression and( Expression left, Expression right )

Modified: incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/JDBCSelector.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/JDBCSelector.java?view=diff&rev=109512&p1=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/JDBCSelector.java&r1=109511&p2=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/JDBCSelector.java&r2=109512
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/JDBCSelector.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/JDBCSelector.java
Thu Dec  2 10:18:53 2004
@@ -21,6 +21,7 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
 
@@ -37,14 +38,13 @@
 
     public void addExpression( Expression expression )
     {
-        if ( !expression.supports( m_table ) ) throw new IllegalArgumentException( "Expression
does not support table metadata" );
         m_expressions.add( expression );
     }
 
     public boolean select( Connection c ) throws SQLException
     {
         PreparedStatement statement = c.prepareStatement( buildQueryString() );
-        bindParameterValues( statement );
+        bindParameterValues( statement, getParameterValues() );
         ResultSet rs = statement.executeQuery();
         boolean found = rs.next();
         statement.close();
@@ -52,48 +52,38 @@
         return found;
     }
 
-    private String buildQueryString()
+    private String[] getParameterValues()
     {
-        StringBuffer statement = new StringBuffer();
-        statement.append( "select * from " ).append( m_table.getName() ).append( " where
" );
-
+        Collection parameters = new ArrayList();
         for ( Iterator it = m_expressions.iterator(); it.hasNext(); )
         {
             Expression expression = ( Expression ) it.next();
-            statement.append( expression.getQueryString( m_table ) );
-            if ( it.hasNext() ) statement.append( " and " );
+            parameters.addAll( Arrays.asList( expression.getParameterValues( ) ) );
         }
 
-        return statement.toString();
+        return ( String[] ) parameters.toArray( new String[parameters.size()] );
     }
 
-    private void bindParameterValues( PreparedStatement statement ) throws SQLException
+    private String buildQueryString()
     {
-        Parameters parameters = new Parameters( statement );
+        StringBuffer statement = new StringBuffer();
+        statement.append( "select * from " ).append( m_table.getName() ).append( " where
" );
+
         for ( Iterator it = m_expressions.iterator(); it.hasNext(); )
         {
             Expression expression = ( Expression ) it.next();
-            parameters.bind( expression );
+            statement.append( expression.getQueryString() );
+            if ( it.hasNext() ) statement.append( " and " );
         }
+
+        return statement.toString();
     }
 
-    private class Parameters
+    private void bindParameterValues( PreparedStatement statement, String[] parameters )
throws SQLException
     {
-        private final PreparedStatement m_statement;
-        private int m_index = 1;
-
-        public Parameters( PreparedStatement statement )
-        {
-            m_statement = statement;
-        }
-
-        public void bind( Expression expression ) throws SQLException
+        for ( int i = 0; i < parameters.length; i++ )
         {
-            String[] values = expression.getParameterValues( m_table );
-            for ( int i = 0; i < values.length; i++ )
-            {
-                m_statement.setString( m_index++, values[i] );
-            }
+            statement.setString( i + 1, parameters[i] );
         }
     }
 }

Modified: incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/SameCredentialsBuilder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/SameCredentialsBuilder.java?view=diff&rev=109512&p1=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/SameCredentialsBuilder.java&r1=109511&p2=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/SameCredentialsBuilder.java&r2=109512
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/SameCredentialsBuilder.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/SameCredentialsBuilder.java
Thu Dec  2 10:18:53 2004
@@ -23,21 +23,19 @@
 
 public class SameCredentialsBuilder implements SelectorBuilder
 {
-    private final ExpressionBuilder m_builder;
     private final CredentialSet m_credentials;
 
-    public SameCredentialsBuilder( ExpressionBuilder builder, CredentialSet credentials )
+    public SameCredentialsBuilder( CredentialSet credentials )
     {
-        m_builder = builder;
         m_credentials = credentials;
     }
 
-    public void build( Selector selector )
+    public void build( ExpressionBuilder builder, Selector selector )
     {
         for ( Iterator it = m_credentials.elements().iterator(); it.hasNext(); )
         {
             Credential credential = (Credential) it.next();
-            selector.addExpression( m_builder.eq( credential.getClass(), credential.getValue()
));
+            selector.addExpression( builder.eq( credential.getClass(), credential.getValue()
));
         }
     }
 }

Modified: incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/SelectorBuilder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/SelectorBuilder.java?view=diff&rev=109512&p1=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/SelectorBuilder.java&r1=109511&p2=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/SelectorBuilder.java&r2=109512
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/SelectorBuilder.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/SelectorBuilder.java
Thu Dec  2 10:18:53 2004
@@ -18,5 +18,5 @@
 
 public interface SelectorBuilder
 {
-    void build( Selector selector );
+    void build( ExpressionBuilder builder, Selector selector );
 }

Modified: incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Table.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Table.java?view=diff&rev=109512&p1=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Table.java&r1=109511&p2=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Table.java&r2=109512
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Table.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Table.java
Thu Dec  2 10:18:53 2004
@@ -25,13 +25,11 @@
 {
     private final String m_name;
     private final Map m_columns;
-    private final Map m_converters;
 
     public Table( String name )
     {
         m_name = name;
         m_columns = new HashMap();
-        m_converters = new HashMap();
     }
 
     public String getName()
@@ -51,17 +49,17 @@
 
     public String getColumnName( Class type )
     {
-        Column column = column( type );
+        Column column = getColumn( type );
         return column != null ? column.getName() : null;
     }
 
-    public String getColumnValue( Object object )
+    public String getColumnValue( Class type, Object value )
     {
-        Converter converter = ( Converter ) m_converters.get( object.getClass() );
-        return converter != null ? converter.convert( object ) : object.toString();
+        Column column = getColumn( type );
+        return column != null ? column.getValue( value ) : null;
     }
 
-    private Column column( Class type )
+    public Column getColumn( Class type )
     {
         Column column = ( Column ) m_columns.get( type );
         return column;

Modified: incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/Columns.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/Columns.java?view=diff&rev=109512&p1=incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/Columns.java&r1=109511&p2=incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/Columns.java&r2=109512
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/Columns.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/Columns.java
Thu Dec  2 10:18:53 2004
@@ -22,11 +22,11 @@
 
     public static Column username()
     {
-        return new Column( "username", UsernameCredential.class );
+        return new Column( "USERNAME", UsernameCredential.class );
     }
 
     public static Column password()
     {
-        return new Column( "password", PasswordCredential.class );
+        return new Column( "PASSWORD", PasswordCredential.class );
     }
 }

Added: incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/Creds.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/Creds.java?view=auto&rev=109512
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/Creds.java
Thu Dec  2 10:18:53 2004
@@ -0,0 +1,40 @@
+/*
+ *   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.authentication.realm;
+
+import org.apache.janus.authentication.CredentialSet;
+
+public class Creds
+{
+    private Creds() {}
+
+    public static CredentialSet joe()
+    {
+        CredentialSet creds = new CredentialSet();
+        creds.add( new UsernameCredential( "joe" ) );
+        creds.add( new PasswordCredential( "foo" ) );
+        return creds;
+    }
+
+    public static CredentialSet jane()
+    {
+        CredentialSet creds = new CredentialSet();
+        creds.add( new UsernameCredential( "jane" ) );
+        creds.add( new PasswordCredential( "bar" ) );
+        return creds;
+    }
+}

Modified: incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCRealmTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCRealmTest.java?view=diff&rev=109512&p1=incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCRealmTest.java&r1=109511&p2=incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCRealmTest.java&r2=109512
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCRealmTest.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCRealmTest.java
Thu Dec  2 10:18:53 2004
@@ -17,7 +17,6 @@
 package org.apache.janus.authentication.realm;
 
 import junit.framework.TestCase;
-import org.apache.janus.authentication.CredentialSet;
 
 public class JDBCRealmTest extends TestCase
 {
@@ -34,8 +33,8 @@
         m_db = new MemoryDatabase();
         Table table = Tables.users();
         m_db.create( table );
-        m_db.insertInto( table, new String[] { "joe", "foo" } );
-        m_db.insertInto( table, new String[] { "jane", "bar" } );
+        m_db.insertInto( table, Creds.joe() );
+        m_db.insertInto( table, Creds.jane() );
         m_realm = new JDBCRealm( m_db.getDataSource() , table );
     }
 
@@ -47,11 +46,8 @@
     public void testExecutesSelectionQueriesAgainstDatabase() throws Exception
     {
         JDBCSelector selector = new JDBCSelector( Tables.users() );
-        CredentialSet creds = new CredentialSet();
-        creds.add( new UsernameCredential( "joe" ) );
-        creds.add( new PasswordCredential( "foo" ) );
-        SameCredentialsBuilder builder = new SameCredentialsBuilder( new ExpressionBuilder(),
creds );
-        builder.build( selector );
+        SameCredentialsBuilder builder = new SameCredentialsBuilder( Creds.joe() );
+        builder.build( new ExpressionBuilder( Tables.users() ), selector );
 
         assertTrue( m_realm.find( selector ) );
     }
@@ -60,11 +56,8 @@
     {
         JDBCSelector selector = new JDBCSelector( undefinedTable() );
 
-        CredentialSet creds = new CredentialSet();
-        creds.add( new UsernameCredential( "joe" ) );
-        creds.add( new PasswordCredential( "foo" ) );
-        SameCredentialsBuilder builder = new SameCredentialsBuilder( new ExpressionBuilder(),
creds );
-        builder.build( selector );
+        SameCredentialsBuilder builder = new SameCredentialsBuilder( Creds.joe() );
+        builder.build( new ExpressionBuilder(Tables.users()), selector );
 
         try
         {

Modified: incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCSelectorTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCSelectorTest.java?view=diff&rev=109512&p1=incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCSelectorTest.java&r1=109511&p2=incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCSelectorTest.java&r2=109512
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCSelectorTest.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCSelectorTest.java
Thu Dec  2 10:18:53 2004
@@ -19,6 +19,8 @@
 import junit.framework.TestCase;
 
 import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
 
 public class JDBCSelectorTest extends TestCase
 {
@@ -31,8 +33,8 @@
         m_db = new MemoryDatabase();
         Table table = Tables.users();
         m_db.create( table );
-        m_db.insertInto( table, new String[] { "joe", "foo" } );
-        m_db.insertInto( table, new String[] { "jane", "bar" } );
+        m_db.insertInto( table, Creds.joe() );
+        m_db.insertInto( table, Creds.jane() );
         m_selector = new JDBCSelector( table );
 
         m_connection = m_db.getDataSource().getConnection();
@@ -49,35 +51,22 @@
      */
     public void testFindsDataBasedOnCredentialExpression() throws Exception
     {
-        m_selector.addExpression( new EqExpression( UsernameCredential.class, "joe" ) );
+        m_selector.addExpression( new EqExpression( Columns.username(), "joe" ) );
         assertTrue( m_selector.select( m_connection ) );
     }
 
     public void testSupportsMultipleCredentialExpressions() throws Exception
     {
-        m_selector.addExpression( new EqExpression( UsernameCredential.class, "joe" ) );
-        m_selector.addExpression( new EqExpression( PasswordCredential.class, "foo" ) );
+        m_selector.addExpression( new EqExpression( Columns.username(), "joe" ) );
+        m_selector.addExpression( new EqExpression( Columns.password(), "foo" ) );
 
         assertTrue( m_selector.select( m_connection ) );
     }
 
     public void testSupportsAndExpressions() throws Exception
     {
-        m_selector.addExpression( new AndExpression( new EqExpression( UsernameCredential.class,
"joe" ),
-                new EqExpression( PasswordCredential.class, "foo" ) ) );
+        m_selector.addExpression( new AndExpression( new EqExpression( Columns.username(),
"joe" ),
+                new EqExpression( Columns.password(), "foo" ) ) );
         assertTrue( m_selector.select( m_connection ) );
-    }
-
-    public void testValidatesExpressionAgainstTableMetadata()
-    {
-        try
-        {
-            m_selector.addExpression( new EqExpression( Object.class, new Object() ) );
-            fail( "IllegalArgumentException expected" );
-        }
-        catch ( IllegalArgumentException expected )
-        {
-            assertTrue( true );
-        }
     }
 }

Modified: incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/MemoryDatabase.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/MemoryDatabase.java?view=diff&rev=109512&p1=incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/MemoryDatabase.java&r1=109511&p2=incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/MemoryDatabase.java&r2=109512
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/MemoryDatabase.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/MemoryDatabase.java
Thu Dec  2 10:18:53 2004
@@ -16,15 +16,18 @@
  */
 package org.apache.janus.authentication.realm;
 
+import org.apache.janus.authentication.Credential;
+import org.apache.janus.authentication.CredentialSet;
+import org.hsqldb.DatabaseManager;
 import org.hsqldb.jdbc.jdbcDataSource;
 
 import javax.sql.DataSource;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Iterator;
-import java.util.Collection;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
 
 public class MemoryDatabase
 {
@@ -60,6 +63,7 @@
         }
         sb.append( "\n)" );
         statement.executeUpdate( sb.toString() );
+        statement.close();
         c.close();
 
         m_tables.add( table );
@@ -72,24 +76,36 @@
         StringBuffer sb = new StringBuffer( );
         sb.append( "drop table ").append( table.getName() );
         statement.executeUpdate( sb.toString() );
+        statement.close();
         c.close();
 
         m_tables.remove( table );
     }
 
-    public void insertInto( Table table, String[] values ) throws SQLException
+    public void insertInto( Table table, CredentialSet creds ) throws SQLException
     {
         Connection c = m_ds.getConnection();
         Statement statement = c.createStatement();
         StringBuffer sb = new StringBuffer( );
-        sb.append( "insert into ").append( table.getName() ).append( " values( ");
-        for ( int i = 0; i < values.length; i++ )
+
+        sb.append( "insert into ").append( table.getName() ).append( "(");
+        for ( Iterator it = creds.elements().iterator(); it.hasNext(); )
+        {
+            Credential credential = ( Credential ) it.next();
+            sb.append( table.getColumnName( credential.getClass() ));
+            if ( it.hasNext() ) sb.append( ",");
+        }
+
+        sb.append( ") values( ");
+        for ( Iterator it = creds.elements().iterator(); it.hasNext(); )
         {
-            sb.append( "'" ).append( values[i] ).append( "'" );
-            if ( i < values.length - 1 ) sb.append( ",");
+            Credential credential = ( Credential ) it.next();
+            sb.append( "'" ).append( table.getColumnValue( credential.getClass(), credential.getValue()
) ).append( "'" );
+            if ( it.hasNext() ) sb.append( ",");
         }
         sb.append( ")");
         statement.executeUpdate( sb.toString() );
+        statement.close();
         c.close();
     }
 
@@ -100,5 +116,18 @@
         {
             drop( tables[i] );
         }
+    }
+
+    public void dispose()
+    {
+        try
+        {
+            dropAll();
+        }
+        catch ( SQLException ignored )
+        {
+
+        }
+        DatabaseManager.closeDatabases( -1 );
     }
 }

Modified: incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/SameCredentialsBuilderTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/SameCredentialsBuilderTest.java?view=diff&rev=109512&p1=incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/SameCredentialsBuilderTest.java&r1=109511&p2=incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/SameCredentialsBuilderTest.java&r2=109512
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/SameCredentialsBuilderTest.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/SameCredentialsBuilderTest.java
Thu Dec  2 10:18:53 2004
@@ -38,13 +38,13 @@
         CredentialSet creds = new CredentialSet();
         creds.add( new UsernameCredential( "joe" ) );
         creds.add( new PasswordCredential( "foo" ) );
-        m_builder = new SameCredentialsBuilder( new ExpressionBuilder(), creds );
+        m_builder = new SameCredentialsBuilder( creds );
 
         Mock mockSelector = new Mock( Selector.class );
 
-        mockSelector.expects( once() ).method( "addExpression" ).with( eq( new EqExpression(
UsernameCredential.class, "joe" ) ) );
-        mockSelector.expects( once() ).method( "addExpression" ).with( eq( new EqExpression(
PasswordCredential.class, "foo" ) ) );
-        m_builder.build( ( Selector ) mockSelector.proxy() );
+        mockSelector.expects( once() ).method( "addExpression" ).with( eq( new EqExpression(
Columns.username(), "joe" ) ) );
+        mockSelector.expects( once() ).method( "addExpression" ).with( eq( new EqExpression(
Columns.password(), "foo" ) ) );
+        m_builder.build( new ExpressionBuilder( Tables.users() ), ( Selector ) mockSelector.proxy()
);
         mockSelector.verify();
     }
 }

Mime
View raw message