hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahue...@apache.org
Subject svn commit: r468309 - in /hivemind/branches/branch-2-0-annot/annotations/src: java/org/apache/hivemind/annotations/ java/org/apache/hivemind/annotations/internal/ java/org/apache/hivemind/annotations/test/ test/org/apache/hivemind/annotations/
Date Fri, 27 Oct 2006 08:02:36 GMT
Author: ahuegen
Date: Fri Oct 27 01:02:35 2006
New Revision: 468309

URL: http://svn.apache.org/viewvc?view=rev&rev=468309
Log:
refactored tests

Added:
    hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/AnnotatedRegistryBuilder.java
    hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/test/
    hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/test/AnnotationTestCase.java
    hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModules.java
Modified:
    hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
    hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/SimpleAnnotatedModule.java
    hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModuleReader.java

Added: hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/AnnotatedRegistryBuilder.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/AnnotatedRegistryBuilder.java?view=auto&rev=468309
==============================================================================
--- hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/AnnotatedRegistryBuilder.java
(added)
+++ hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/AnnotatedRegistryBuilder.java
Fri Oct 27 01:02:35 2006
@@ -0,0 +1,89 @@
+package org.apache.hivemind.annotations;
+
+import java.util.Locale;
+
+import org.apache.hivemind.ClassResolver;
+import org.apache.hivemind.ErrorHandler;
+import org.apache.hivemind.Registry;
+import org.apache.hivemind.definition.RegistryDefinition;
+import org.apache.hivemind.impl.DefaultClassResolver;
+import org.apache.hivemind.impl.DefaultErrorHandler;
+import org.apache.hivemind.impl.RegistryBuilder;
+
+/**
+ * Helper class for defining hivemind registries that mainly base on
+ * annotated modules.
+ * 
+ * @author Achim Huegen
+ */
+public class AnnotatedRegistryBuilder
+{
+    private ClassResolver _classResolver;
+    private ErrorHandler _errorHandler;
+    private Locale _locale;
+    
+    public AnnotatedRegistryBuilder()
+    {
+        this(new DefaultClassResolver(), new DefaultErrorHandler(), Locale.getDefault());
+    }
+    
+    public AnnotatedRegistryBuilder(ClassResolver classResolver, ErrorHandler errorHandler,
+            Locale locale)
+    {
+        _classResolver = classResolver;
+        _errorHandler = errorHandler;
+        _locale = locale;
+        
+    }
+    
+    public Registry constructRegistry(String moduleClassName)
+    {
+        return constructRegistry(new String[] {moduleClassName});
+    }
+
+    public Registry constructRegistry(String[] moduleClassNames)
+    {
+        RegistryDefinition definition = constructRegistryDefinition(moduleClassNames);
+        return RegistryBuilder.constructRegistry(definition, _errorHandler, _locale);
+    }
+    
+    public Registry constructRegistry(Class moduleClass)
+    {
+        return constructRegistry(new Class[] {moduleClass});
+    }
+
+    public Registry constructRegistry(Class[] moduleClasses)
+    {
+        RegistryDefinition definition = constructRegistryDefinition(moduleClasses);
+        return RegistryBuilder.constructRegistry(definition, _errorHandler, _locale);
+    }
+    
+    private RegistryDefinition constructRegistryDefinition(String[] moduleClassNames)
+    {
+        RegistryDefinition definition = new RegistryDefinition();
+
+        for (int i = 0; i < moduleClassNames.length; i++)
+        {
+            AnnotatedModuleReader reader = new AnnotatedModuleReader(definition,
+                    _classResolver, _errorHandler);
+            reader.readModule(moduleClassNames[i]);
+        }
+
+        return definition;
+    }
+    
+    private RegistryDefinition constructRegistryDefinition(Class[] moduleClasses)
+    {
+        RegistryDefinition definition = new RegistryDefinition();
+
+        for (int i = 0; i < moduleClasses.length; i++)
+        {
+            AnnotatedModuleReader reader = new AnnotatedModuleReader(definition,
+                    _classResolver, _errorHandler);
+            reader.readModule(moduleClasses[i]);
+        }
+
+        return definition;
+    }
+
+}

Modified: hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java?view=diff&rev=468309&r1=468308&r2=468309
==============================================================================
--- hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
(original)
+++ hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
Fri Oct 27 01:02:35 2006
@@ -76,16 +76,6 @@
 
     }
 
-    // /**
-    // * Detects all services defined in the module class.
-    // *
-    // * @param moduleClass
-    // */
-    // private void processServices(Class moduleClass)
-    // {
-    // // TODO Auto-generated method stub
-    //        
-    // }
     public void processModuleMethods(Class moduleClass, ModuleDefinition module,
             ModuleInstanceProvider instanceProvider)
     {

Added: hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/test/AnnotationTestCase.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/test/AnnotationTestCase.java?view=auto&rev=468309
==============================================================================
--- hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/test/AnnotationTestCase.java
(added)
+++ hivemind/branches/branch-2-0-annot/annotations/src/java/org/apache/hivemind/annotations/test/AnnotationTestCase.java
Fri Oct 27 01:02:35 2006
@@ -0,0 +1,55 @@
+package org.apache.hivemind.annotations.test;
+
+import org.apache.hivemind.Registry;
+import org.apache.hivemind.annotations.AnnotatedModuleReader;
+import org.apache.hivemind.annotations.AnnotatedRegistryBuilder;
+import org.apache.hivemind.definition.RegistryDefinition;
+import org.apache.hivemind.impl.DefaultErrorHandler;
+import org.apache.hivemind.test.HiveMindTestCase;
+
+public class AnnotationTestCase extends HiveMindTestCase
+{
+    protected Registry constructRegistry(String[] moduleClassNames)
+    {
+        AnnotatedRegistryBuilder builder = new AnnotatedRegistryBuilder();
+        return builder.constructRegistry(moduleClassNames);
+    }
+
+    protected Registry constructRegistry(String moduleClassName)
+    {
+        AnnotatedRegistryBuilder builder = new AnnotatedRegistryBuilder();
+        return builder.constructRegistry(moduleClassName);
+    }
+
+    protected Registry constructRegistry(Class[] moduleClasses)
+    {
+        AnnotatedRegistryBuilder builder = new AnnotatedRegistryBuilder();
+        return builder.constructRegistry(moduleClasses);
+    }
+
+    protected Registry constructRegistry(Class moduleClass)
+    {
+        AnnotatedRegistryBuilder builder = new AnnotatedRegistryBuilder();
+        return builder.constructRegistry(moduleClass);
+    }
+
+    protected RegistryDefinition constructRegistryDefinition(Class moduleClass)
+    {
+        return constructRegistryDefinition(new Class[] {moduleClass});
+    }
+    
+    protected RegistryDefinition constructRegistryDefinition(Class[] moduleClasses)
+    {
+        RegistryDefinition definition = new RegistryDefinition();
+
+        for (int i = 0; i < moduleClasses.length; i++)
+        {
+            AnnotatedModuleReader reader = new AnnotatedModuleReader(definition, getClassResolver(),
+                    new DefaultErrorHandler());
+            reader.readModule(moduleClasses[i]);
+        }
+
+        return definition;
+    }
+
+}

Modified: hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/SimpleAnnotatedModule.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/SimpleAnnotatedModule.java?view=diff&rev=468309&r1=468308&r2=468309
==============================================================================
--- hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/SimpleAnnotatedModule.java
(original)
+++ hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/SimpleAnnotatedModule.java
Fri Oct 27 01:02:35 2006
@@ -3,6 +3,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
 import org.apache.hivemind.impl.ServiceModelContribution;
 
 public class SimpleAnnotatedModule
@@ -57,4 +59,24 @@
     {
         _registry = registry;
     }
+    
+    // @methodInterceptor(name="loggingInterceptor")
+    public Object interceptIt(MethodInvocation invocation) throws Throwable
+    {
+        return invocation.proceed();
+    }
+
+    // @interceptorFactory(name="", services="hivemind.*", methods="*" );
+    public MethodInterceptor createInterceptor()
+    {
+        return null;
+    }
+    
+//    public Runnable getService1(List interceptors)
+//    {
+//        Runnable result = null;
+//        interceptors.add(createInterceptor("eenemenemu"));
+//        interceptors.add("loggingInterceptor");
+//        return result;
+//    }
 }

Modified: hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModuleReader.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModuleReader.java?view=diff&rev=468309&r1=468308&r2=468309
==============================================================================
--- hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModuleReader.java
(original)
+++ hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModuleReader.java
Fri Oct 27 01:02:35 2006
@@ -1,66 +1,22 @@
 package org.apache.hivemind.annotations;
 
-import hivemind.test.services.ServiceAutowireTarget;
-
-import java.util.Locale;
-
-import org.apache.hivemind.ClassResolver;
-import org.apache.hivemind.ErrorHandler;
 import org.apache.hivemind.Registry;
+import org.apache.hivemind.annotations.test.AnnotationTestCase;
 import org.apache.hivemind.definition.RegistryDefinition;
-import org.apache.hivemind.impl.DefaultErrorHandler;
-import org.apache.hivemind.impl.RegistryBuilder;
-import org.apache.hivemind.test.HiveMindTestCase;
 
-public class TestAnnotatedModuleReader extends HiveMindTestCase
+public class TestAnnotatedModuleReader extends AnnotationTestCase
 {
-    protected Registry buildRegistry(String[] moduleClassNames)
-    {
-        RegistryDefinition definition = buildRegistryDefinition(moduleClassNames);
-        
-        RegistryBuilder builder = new RegistryBuilder(definition);
-//        builder.
-//        builder.autoDetectModules();
-
-        return builder.constructRegistry(Locale.getDefault());
-    }
-    
-    protected RegistryDefinition buildRegistryDefinition(String[] moduleClassNames)
-    {
-        ClassResolver resolver = getClassResolver();
-        
-        ErrorHandler errorHandler = new DefaultErrorHandler();
-        
-        RegistryDefinition definition = new RegistryDefinition();
-
-        for (int i = 0; i < moduleClassNames.length; i++)
-        {
-            AnnotatedModuleReader reader = new AnnotatedModuleReader(definition,
-                    resolver, errorHandler);
-            reader.readModule(moduleClassNames[i]);
-        }
-
-        return definition;
-    }
-    
     public void testSimpleModule()
     {
-        Registry registry = buildRegistry(new String[] {SimpleAnnotatedModule.class.getName()});
+        Registry registry = constructRegistry(SimpleAnnotatedModule.class);
         Runnable service = (Runnable) registry.getService("org.apache.hivemind.annotations.SimpleAnnotatedModule.Test",
Runnable.class);
         service.run();
     }
 
     public void testModuleId()
     {
-        RegistryDefinition registry = buildRegistryDefinition((new String[] {ModuleWithExplicitId.class.getName()}));
+        RegistryDefinition registry = constructRegistryDefinition((new Class[] {ModuleWithExplicitId.class}));
         assertNotNull(registry.getModule("Test"));
-    }
-    
-    public void testAutowiring()
-    {
-        Registry registry = buildRegistry(new String[] {AutowiringModule.class.getName()});
-        ServiceAutowireTarget service = (ServiceAutowireTarget) registry.getService(ServiceAutowireTarget.class);
-        assertNotNull(service.getStringHolder());
     }
     
 }

Added: hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModules.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModules.java?view=auto&rev=468309
==============================================================================
--- hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModules.java
(added)
+++ hivemind/branches/branch-2-0-annot/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModules.java
Fri Oct 27 01:02:35 2006
@@ -0,0 +1,17 @@
+package org.apache.hivemind.annotations;
+
+import hivemind.test.services.ServiceAutowireTarget;
+
+import org.apache.hivemind.Registry;
+import org.apache.hivemind.annotations.test.AnnotationTestCase;
+
+public class TestAnnotatedModules extends AnnotationTestCase
+{
+    public void testAutowiring()
+    {
+        Registry registry = constructRegistry(AutowiringModule.class);
+        ServiceAutowireTarget service = (ServiceAutowireTarget) registry.getService(ServiceAutowireTarget.class);
+        assertNotNull(service.getStringHolder());
+    }
+    
+}



Mime
View raw message