directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vte...@apache.org
Subject svn commit: rev 6881 - in incubator/directory/janus/trunk/sandbox: . src/java/org/apache/janus/authentication src/test/org/apache/janus/authentication/realm
Date Thu, 26 Feb 2004 18:35:03 GMT
Author: vtence
Date: Thu Feb 26 10:35:02 2004
New Revision: 6881

Added:
   incubator/directory/janus/trunk/sandbox/maven.xml
   incubator/directory/janus/trunk/sandbox/project.xml
   incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authentication/realm/UsernamePasswordAuthTest.groovy
Modified:
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authentication/CredentialSet.java
   incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authentication/realm/UsernamePasswordAuthenticationTest.java
Log:
o Added sample test case in groovy
o Added maven goals to run groovy tests

Added: incubator/directory/janus/trunk/sandbox/maven.xml
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/sandbox/maven.xml	Thu Feb 26 10:35:02 2004
@@ -0,0 +1,100 @@
+<project xmlns:j="jelly:core" xmlns:u="jelly:util">
+
+    <postGoal name="test:compile">
+        <attainGoal name="setclasspath"/>
+        <attainGoal name="compile-groovy-tests"/>
+    </postGoal>
+
+    <goal name="setclasspath">
+        <path id="test.classpath">
+            <pathelement path="${maven.build.dest}"/>
+            <pathelement path="target/classes"/>
+            <pathelement path="target/test-classes"/>
+            <path refid="maven.dependency.classpath"/>
+        </path>
+        <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="test.classpath"/>
+    </goal>
+
+
+    <goal name="compile-groovy-tests" prereqs="setclasspath"
+        description="Compiles the Groovy unit test cases">
+        <!-- lets copy and touch all the groovy files to ensure they all recompile -->
+        <mkdir dir="${basedir}/target/test-classes"/>
+        <copy todir="${basedir}/target/test-classes">
+            <fileset dir="${basedir}/src/test">
+                <include name="**/*.groovy"/>
+                <exclude name=".svn/*"/>
+            </fileset>
+        </copy>
+        <touch>
+            <fileset dir="${basedir}/target/test-classes" includes="**/*.groovy"/>
+        </touch>
+        <groovyc destdir="${basedir}/target/test-classes" srcdir="${basedir}/target/test-classes"
listfiles="true">
+            <classpath refid="test.classpath"/>
+        </groovyc>
+    </goal>
+
+    <goal name="run-tests"
+        description="Test the application with any Java or Groovy unit tests"
+        prereqs="test:compile">
+
+        <j:if test="${unitTestSourcesPresent == 'true' and context.getVariable('maven.test.skip')
!= 'true'}">
+            <taskdef
+                name="junit"
+                classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"/>
+
+            <j:set var="testPlugin" value="${pom.getPluginContext('maven-test-plugin')}"/>
+            <j:set var="reportsDirectory">${testPlugin.findVariable('maven.test.reportsDirectory')}</j:set>
+
+            <mkdir dir="${reportsDirectory}"/>
+
+            <junit printSummary="yes"
+                failureProperty="maven.test.failure"
+                fork="${maven.junit.fork}"
+                dir="${maven.junit.dir}">
+                <sysproperty key="basedir" value="${basedir}"/>
+
+                <u:tokenize var="listOfProperties" delim=" ">${maven.junit.sysproperties}</u:tokenize>
+                <j:forEach var="someProperty" items="${listOfProperties}">
+                    <sysproperty key="${someProperty}" value="${context.getVariable(someProperty)}"/>
+                </j:forEach>
+                <u:tokenize var="listOfJvmArgs" delim=" ">${maven.junit.jvmargs}</u:tokenize>
+                <j:forEach var="somejvmarg" items="${listOfJvmArgs}">
+                    <jvmarg value="${somejvmarg}"/>
+                </j:forEach>
+                <formatter type="xml"/>
+                <formatter type="plain" usefile="${maven.junit.usefile}"/>
+                <classpath>
+                    <path refid="maven.dependency.classpath"/>
+                    <pathelement location="${basedir}/target/classes"/>
+                    <pathelement location="${basedir}/target/test-classes"/>
+                    <pathelement path="${plugin.getDependencyPath('junit')}"/>
+                </classpath>
+                <batchtest todir="${reportsDirectory}">
+                    <fileset dir="${basedir}/target/test-classes">
+                        <j:forEach var="pat" items="${pom.build.unitTest.includes}">
+                            <include name="${pat}"/>
+                        </j:forEach>
+                        <j:forEach var="pat" items="${pom.build.unitTest.excludes}">
+                            <exclude name="${pat}"/>
+                        </j:forEach>
+                        <!-- KEEP ALL ABSTRACT TESTS FROM BEING RUN! -->
+                        <exclude name="**/*AbstractTestCase.*"/>
+                    </fileset>
+                </batchtest>
+            </junit>
+
+            <j:if test="${maven.test.failure}">
+                <j:set var="ignore__" value="${maven.test.failure.ignore}X"/>
+                <j:if test="${ignore__ == 'X'}">
+                    <fail message="There were test failures."/>
+                </j:if>
+            </j:if>
+
+        </j:if>
+
+        <j:if test="${!unitTestSourcesPresent}">
+            <echo>No tests to run.</echo>
+        </j:if>
+    </goal>
+</project>

Added: incubator/directory/janus/trunk/sandbox/project.xml
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/sandbox/project.xml	Thu Feb 26 10:35:02 2004
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<project>
+    <extend>${basedir}/../project.xml</extend>
+
+    <name>Janus Sandbox</name>
+    <id>janus-sandbox</id>
+    <package>org.apache.janus</package>
+
+    <shortDescription>Janus Sandbox Space</shortDescription>
+
+    <description>
+    A playground for all sorts of ideas
+    </description>
+
+    <dependencies>
+        <dependency>
+            <groupId>groovy</groupId>
+            <artifactId>groovy</artifactId>
+            <version>1.0-beta-3</version>
+        </dependency>
+
+        <dependency>
+          <id>asm</id>
+          <version>1.4.1</version>
+          <url>http://asm.objectweb.org/</url>
+        </dependency>
+
+        <dependency>
+          <id>asm+util</id>
+          <version>1.4.1</version>
+          <url>http://asm.objectweb.org/</url>
+        </dependency>
+        
+    </dependencies>
+
+</project>
\ No newline at end of file

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authentication/CredentialSet.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authentication/CredentialSet.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authentication/CredentialSet.java
Thu Feb 26 10:35:02 2004
@@ -41,7 +41,7 @@
         this( credentials.elements() );
     }
 
-    public CredentialSet( Set credentials )
+    public CredentialSet( Collection credentials )
     {
         m_credentials = new HashSet( credentials );
     }

Added: incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authentication/realm/UsernamePasswordAuthTest.groovy
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authentication/realm/UsernamePasswordAuthTest.groovy
Thu Feb 26 10:35:02 2004
@@ -0,0 +1,88 @@
+/*
+ *   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 junit.framework.Assert;
+import junit.framework.TestCase;
+import org.apache.janus.authentication.Credential;
+import org.apache.janus.authentication.CredentialSet;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import groovy.util.GroovyTestCase;
+
+/**
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ */
+class UsernamePasswordAuthTest extends GroovyTestCase
+{
+    UsernamePasswordAuthentication m_auth
+
+    void setUp()
+    {
+        m_auth = new UsernamePasswordAuthentication();
+    }
+
+    void testCredentialsWithNoUsernameAreNotSupported()
+    {
+        assert !m_auth.supports(new CredentialSet([new Credential("password", "bar")]))
+    }
+
+    void testCredentialsWithNoPasswordAreNotSupported()
+    {
+        assert !m_auth.supports(new CredentialSet([new Credential("username", "foo")]))
+    }
+
+    CredentialSet extraCreds()
+    {
+      return new CredentialSet([
+            new Credential("username", "john"),
+            new Credential("password", "doe"),
+            new Credential("password", "baz"),
+            new Credential("foo", "bar")])
+    }
+
+    void testSetsWithAllValidCredentialsPlusExtraOnesAreNotSupported()
+    {
+        assert !m_auth.supports(extraCreds())
+    }
+
+    CredentialSet validCreds()
+    {
+        return new CredentialSet([
+            new Credential("username", "john"),
+            new Credential("password", "doe")])
+    }
+
+    void testAUsernameAndAPaswordIsAValidCredentialSet()
+    {
+        assert m_auth.supports(validCreds())
+    }
+
+    public void testCredentialsMatchIfEqual()
+    {
+        assert m_auth.matcher(validCreds()).matches(validCreds())
+        assert !m_auth.matcher(extraCreds()).matches(validCreds())
+    }
+
+    public void testPrincipalsCreatedAreUsernamePrincipals()
+    {
+        assert new UsernamePrincipal("john") == m_auth.getPrincipal(validCreds())
+    }
+}

Modified: incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authentication/realm/UsernamePasswordAuthenticationTest.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authentication/realm/UsernamePasswordAuthenticationTest.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authentication/realm/UsernamePasswordAuthenticationTest.java
Thu Feb 26 10:35:02 2004
@@ -65,24 +65,24 @@
         assertFalse( "Reports it supports credentials with no password", m_auth.supports(
new CredentialSet( Collections.singleton( new Credential( "username", "foo" ) ) ) ) );
     }
 
-    public void testExtraCredentialsAreNotSupported()
+    public void testSetsWithAllValidCredentialsPlusExtraOnesAreNotSupported()
     {
         assertFalse( "Reports it supports extra credentials", m_auth.supports( extraCredentials()
) );
     }
 
-    public void testUsernameAndPaswordAreValidCredentials()
+    public void testAUsernameAndAPaswordIsAValidCredentialSet()
     {
-        assertFalse( "Reports it does not support credentials with a username and a password",
m_auth.supports( extraCredentials() ) );
+        assertTrue( "Reports it does not support credentials with a username and a password",
m_auth.supports( validCredentials() ) );
     }
 
-    public void testCredentialsMatchesIfEqual()
+    public void testCredentialsMatchIfEqual()
     {
         assertTrue( "Equal sets of credentials do not match", m_auth.matcher( validCredentials()
).matches( validCredentials() ) );
         assertFalse( "Different sets of credentials were matched", m_auth.matcher( extraCredentials()
).matches( validCredentials() ) );
     }
 
-    public void testCreatesUsernamePrincipals()
+    public void testPrincipalsCreatedAreUsernamePrincipals()
     {
-        Assert.assertEquals( "Created wrong principal", new UsernamePrincipal( "john" ),
m_auth.getPrincipal( validCredentials() ) );
+        assertEquals( "Created wrong principal", new UsernamePrincipal( "john" ), m_auth.getPrincipal(
validCredentials() ) );
     }
 }

Mime
View raw message