incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r1212590 - in /incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit: Authenticator.java Authorizer.java Persistor.java internal/AnnotationInstaller.java internal/IsisSystemUsingInstallersWithinJunit.java
Date Fri, 09 Dec 2011 19:28:11 GMT
Author: kevin
Date: Fri Dec  9 19:28:11 2011
New Revision: 1212590

URL: http://svn.apache.org/viewvc?rev=1212590&view=rev
Log:
ISIS-149: Update IsisTestRunner to accept @Persistor, @Authenticator annotations.

Added:
    incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/Authenticator.java
    incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/Authorizer.java
    incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/Persistor.java
    incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/internal/AnnotationInstaller.java
Modified:
    incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/internal/IsisSystemUsingInstallersWithinJunit.java

Added: incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/Authenticator.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/Authenticator.java?rev=1212590&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/Authenticator.java
(added)
+++ incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/Authenticator.java
Fri Dec  9 19:28:11 2011
@@ -0,0 +1,14 @@
+package org.apache.isis.viewer.junit;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+@Inherited
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Authenticator {
+    Class<?> value();
+}

Added: incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/Authorizer.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/Authorizer.java?rev=1212590&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/Authorizer.java
(added)
+++ incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/Authorizer.java
Fri Dec  9 19:28:11 2011
@@ -0,0 +1,14 @@
+package org.apache.isis.viewer.junit;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+@Inherited
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Authorizer {
+    Class<?> value();
+}

Added: incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/Persistor.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/Persistor.java?rev=1212590&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/Persistor.java
(added)
+++ incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/Persistor.java
Fri Dec  9 19:28:11 2011
@@ -0,0 +1,14 @@
+package org.apache.isis.viewer.junit;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+@Inherited
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Persistor {
+    Class<?> value();
+}

Added: incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/internal/AnnotationInstaller.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/internal/AnnotationInstaller.java?rev=1212590&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/internal/AnnotationInstaller.java
(added)
+++ incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/internal/AnnotationInstaller.java
Fri Dec  9 19:28:11 2011
@@ -0,0 +1,82 @@
+package org.apache.isis.viewer.junit.internal;
+
+import org.apache.isis.core.runtime.authentication.AuthenticationManagerInstaller;
+import org.apache.isis.core.runtime.authorization.AuthorizationManagerInstaller;
+import org.apache.isis.runtimes.dflt.runtime.installerregistry.installerapi.PersistenceMechanismInstaller;
+import org.apache.isis.security.dflt.authentication.NoopAuthenticationManagerInstaller;
+import org.apache.isis.security.dflt.authorization.NoopAuthorizationManagerInstaller;
+import org.apache.isis.viewer.junit.Authenticator;
+import org.apache.isis.viewer.junit.Authorizer;
+import org.apache.isis.viewer.junit.Persistor;
+
+public class AnnotationInstaller {
+
+    /**
+     * Should be called prior to installing; typically called immediately after instantiation.
+     * 
+     * <p>
+     * Note: an alternative design would be to have a 1-arg constructor, but the convention
for installers is to make
+     * them no-arg.
+     */
+    // {{ AuthenticationManagerInstaller
+    public AuthenticationManagerInstaller addAuthenticatorAnnotatedOn(final Class<?>
javaClass)
+        throws InstantiationException, IllegalAccessException {
+        final Authenticator authenticatorAnnotation = javaClass.getAnnotation(Authenticator.class);
+        if (authenticatorAnnotation != null) {
+            return addAuthenticatorRepresentedBy(authenticatorAnnotation);
+        } else {
+            return new NoopAuthenticationManagerInstaller();
+        }
+
+    }
+
+    private AuthenticationManagerInstaller addAuthenticatorRepresentedBy(final Authenticator
authenticatorAnnotation)
+        throws InstantiationException, IllegalAccessException {
+        final Class<?> fixtureClass = authenticatorAnnotation.value();
+        return (AuthenticationManagerInstaller) fixtureClass.newInstance();
+    }
+
+    // }}
+
+    // {{ AuthorizationManagerInstaller
+    public AuthorizationManagerInstaller addAuthorizerAnnotatedOn(final Class<?> javaClass)
+        throws InstantiationException, IllegalAccessException {
+        final Authorizer authorizorAnnotation = javaClass.getAnnotation(Authorizer.class);
+        if (authorizorAnnotation != null) {
+            return addAuthorizerRepresentedBy(authorizorAnnotation);
+        } else {
+            return new NoopAuthorizationManagerInstaller();
+        }
+
+    }
+
+    private AuthorizationManagerInstaller addAuthorizerRepresentedBy(final Authorizer authorizorAnnotation)
+        throws InstantiationException, IllegalAccessException {
+        final Class<?> fixtureClass = authorizorAnnotation.value();
+        return (AuthorizationManagerInstaller) fixtureClass.newInstance();
+    }
+
+    // }}
+
+    // {{ PersistenceMechanismInstaller
+    public PersistenceMechanismInstaller addPersistorAnnotatedOn(final Class<?> javaClass)
+        throws InstantiationException, IllegalAccessException {
+        final Persistor annotation = javaClass.getAnnotation(Persistor.class);
+        if (annotation != null) {
+            return addPersistorRepresentedBy(annotation);
+        } else {
+            return new InMemoryPersistenceMechanismInstallerWithinJunit();
+        }
+
+    }
+
+    private PersistenceMechanismInstaller addPersistorRepresentedBy(final Persistor annotation)
+        throws InstantiationException, IllegalAccessException {
+        final Class<?> fixtureClass = annotation.value();
+        return (PersistenceMechanismInstaller) fixtureClass.newInstance();
+    }
+    // }}
+
+    // new InMemoryUserProfileStoreInstaller();
+
+}

Modified: incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/internal/IsisSystemUsingInstallersWithinJunit.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/internal/IsisSystemUsingInstallersWithinJunit.java?rev=1212590&r1=1212589&r2=1212590&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/internal/IsisSystemUsingInstallersWithinJunit.java
(original)
+++ incubator/isis/trunk/framework/viewer/junit/src/main/java/org/apache/isis/viewer/junit/internal/IsisSystemUsingInstallersWithinJunit.java
Fri Dec  9 19:28:11 2011
@@ -19,14 +19,13 @@
 
 package org.apache.isis.viewer.junit.internal;
 
+import org.junit.internal.runners.TestClass;
+
 import org.apache.isis.core.commons.exceptions.IsisException;
 import org.apache.isis.runtimes.dflt.profilestores.dflt.InMemoryUserProfileStoreInstaller;
 import org.apache.isis.runtimes.dflt.runtime.installerregistry.InstallerLookup;
 import org.apache.isis.runtimes.dflt.runtime.system.DeploymentType;
 import org.apache.isis.runtimes.dflt.runtime.systemusinginstallers.IsisSystemUsingInstallers;
-import org.apache.isis.security.dflt.authentication.NoopAuthenticationManagerInstaller;
-import org.apache.isis.security.dflt.authorization.NoopAuthorizationManagerInstaller;
-import org.junit.internal.runners.TestClass;
 
 public class IsisSystemUsingInstallersWithinJunit extends IsisSystemUsingInstallers {
 
@@ -37,24 +36,30 @@ public class IsisSystemUsingInstallersWi
         super(deploymentType, installerLookup);
         this.testClass = testClass;
 
-        setAuthenticationInstaller(getInstallerLookup()
-            .injectDependenciesInto(new NoopAuthenticationManagerInstaller()));
-        setAuthorizationInstaller(getInstallerLookup().injectDependenciesInto(new NoopAuthorizationManagerInstaller()));
-        setPersistenceMechanismInstaller(getInstallerLookup().injectDependenciesInto(
-            new InMemoryPersistenceMechanismInstallerWithinJunit()));
-        setUserProfileStoreInstaller(getInstallerLookup().injectDependenciesInto(
-            new InMemoryUserProfileStoreInstaller()));
+        AnnotationInstaller installer = new AnnotationInstaller();
 
-        // fixture installer
-        final FixtureInstallerAnnotatedClass fixtureInstaller = new FixtureInstallerAnnotatedClass();
         try {
+            setAuthenticationInstaller(getInstallerLookup().injectDependenciesInto(
+                installer.addAuthenticatorAnnotatedOn(this.testClass.getJavaClass())));
+
+            setAuthorizationInstaller(getInstallerLookup().injectDependenciesInto(
+                installer.addAuthorizerAnnotatedOn(this.testClass.getJavaClass())));
+
+            setPersistenceMechanismInstaller(getInstallerLookup().injectDependenciesInto(
+                installer.addPersistorAnnotatedOn(this.testClass.getJavaClass())));
+
+            setUserProfileStoreInstaller(getInstallerLookup().injectDependenciesInto(
+                new InMemoryUserProfileStoreInstaller()));
+
+            // fixture installer
+            final FixtureInstallerAnnotatedClass fixtureInstaller = new FixtureInstallerAnnotatedClass();
             fixtureInstaller.addFixturesAnnotatedOn(this.testClass.getJavaClass());
+            setFixtureInstaller(fixtureInstaller);
         } catch (final InstantiationException e) {
             throw new IsisException(e);
         } catch (final IllegalAccessException e) {
             throw new IsisException(e);
         }
-        setFixtureInstaller(fixtureInstaller);
 
         // services installer
         final ServicesInstallerAnnotatedClass servicesInstaller = new ServicesInstallerAnnotatedClass();



Mime
View raw message