tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlmonte...@apache.org
Subject svn commit: r1405818 - in /openejb/trunk/openejb: container/openejb-core/src/main/java/org/apache/openejb/junit/ container/openejb-core/src/main/java/org/apache/openejb/util/ server/openejb-server/src/main/java/org/apache/openejb/server/
Date Mon, 05 Nov 2012 14:56:59 GMT
Author: jlmonteiro
Date: Mon Nov  5 14:56:59 2012
New Revision: 1405818

URL: http://svn.apache.org/viewvc?rev=1405818&view=rev
Log:
Add the ability to filter services to start with a test case.

Added:
    openejb/trunk/openejb/server/openejb-server/src/main/java/org/apache/openejb/server/FilteredServiceManager.java
Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/EnableServices.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/ServiceManagerProxy.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java?rev=1405818&r1=1405817&r2=1405818&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
Mon Nov  5 14:56:59 2012
@@ -73,6 +73,7 @@ import org.junit.runners.model.TestClass
 
 import javax.naming.Context;
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -485,10 +486,14 @@ public class ApplicationComposer extends
 
                 assembler.buildContainerSystem(config.getOpenEjbConfiguration());
 
+                EnableServices annotation = testClass.getJavaClass().getAnnotation(EnableServices.class);
                 if ("true".equals(configuration.getProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE,
"false"))
-                        || testClass.getJavaClass().getAnnotation(EnableServices.class) !=
null) {
+                        || annotation != null) {
                     try {
                         serviceManager = new ServiceManagerProxy();
+                        if (annotation != null) {
+                            initFilteredServiceManager(annotation);
+                        }
                         serviceManager.start();
                     } catch (ServiceManagerProxy.AlreadyStartedException e) {
                         throw new OpenEJBRuntimeException(e);
@@ -612,4 +617,25 @@ public class ApplicationComposer extends
     private static IAnnotationFinder finderFromClasses(final Class<?>[] value) {
         return new AnnotationFinder(new ClassesArchive(value)).link();
     }
+
+    private void initFilteredServiceManager(EnableServices services) {
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        Class serviceManagerClass;
+        try {
+            serviceManagerClass = classLoader.loadClass("org.apache.openejb.server.FilteredServiceManager");
+        } catch (ClassNotFoundException e) {
+            String msg = "Services filtering requires class 'org.apache.openejb.server.FilteredServiceManager'
to be available.  " +
+                    "Make sure you have the openejb-server-*.jar in your classpath.";
+            throw new IllegalStateException(msg, e);
+        }
+
+        Method initServiceManager = null;
+        try {
+            initServiceManager = serviceManagerClass.getMethod("initServiceManager", String[].class);
+            initServiceManager.invoke(null, new Object[]{services.value()});
+        } catch (Exception e) {
+            throw new IllegalStateException("Failed initializing FilteredServiceManager with
services " + services.value(), e);
+        }
+    }
+
 }

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/EnableServices.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/EnableServices.java?rev=1405818&r1=1405817&r2=1405818&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/EnableServices.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/EnableServices.java
Mon Nov  5 14:56:59 2012
@@ -24,4 +24,7 @@ import java.lang.annotation.Target;
 @Target(ElementType.TYPE)
 @Retention(RetentionPolicy.RUNTIME)
 public @interface EnableServices {
+    // should contain the list of services to activate
+    // default is empty list which means that all services gonna be activated
+    String[] value () default {};
 }

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/ServiceManagerProxy.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/ServiceManagerProxy.java?rev=1405818&r1=1405817&r2=1405818&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/ServiceManagerProxy.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/ServiceManagerProxy.java
Mon Nov  5 14:56:59 2012
@@ -17,6 +17,7 @@
 package org.apache.openejb.util;
 
 import org.apache.openejb.core.LocalInitialContext;
+import org.apache.openejb.junit.EnableServices;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;

Added: openejb/trunk/openejb/server/openejb-server/src/main/java/org/apache/openejb/server/FilteredServiceManager.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-server/src/main/java/org/apache/openejb/server/FilteredServiceManager.java?rev=1405818&view=auto
==============================================================================
--- openejb/trunk/openejb/server/openejb-server/src/main/java/org/apache/openejb/server/FilteredServiceManager.java
(added)
+++ openejb/trunk/openejb/server/openejb-server/src/main/java/org/apache/openejb/server/FilteredServiceManager.java
Mon Nov  5 14:56:59 2012
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.openejb.server;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+/**
+ * This implementation is mainly used in the application composer to get the most from
+ * The EnableServices annotation created
+ */
+public class FilteredServiceManager extends SimpleServiceManager {
+
+    private Collection<String> services;
+
+    public FilteredServiceManager (String[] services) {
+        this.services = Arrays.asList(services);
+    }
+
+    @Override
+    protected boolean accept(String serviceName) {
+        return services.isEmpty() || services.contains(serviceName);
+    }
+
+    public static void initServiceManager(String[] services) {
+        setServiceManager(new FilteredServiceManager(services));
+    }
+}



Mime
View raw message