You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2006/11/28 20:05:25 UTC

svn commit: r480156 - in /incubator/openejb/trunk/openejb3/container/openejb-core/src: main/java/org/apache/openejb/assembler/classic/ test/java/org/apache/openejb/assembler/ test/java/org/apache/openejb/assembler/classic/

Author: dblevins
Date: Tue Nov 28 11:05:24 2006
New Revision: 480156

URL: http://svn.apache.org/viewvc?view=rev&rev=480156
Log:
Added test case to validate the InfoObject tree ensuring nothing "illegal" is added.

Added:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/
    incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/
    incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/OpenEjbConfigurationValidationTest.java
Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/IntraVmServerInfo.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LifecycleCallbackInfo.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodInfo.java

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/IntraVmServerInfo.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/IntraVmServerInfo.java?view=diff&rev=480156&r1=480155&r2=480156
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/IntraVmServerInfo.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/IntraVmServerInfo.java Tue Nov 28 11:05:24 2006
@@ -23,7 +23,6 @@
     public String proxyFactoryClassName;
     public String codebase;
     public String factoryName;
-    public Class proxyFactoryClass;
     public Properties properties;
 
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LifecycleCallbackInfo.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LifecycleCallbackInfo.java?view=diff&rev=480156&r1=480155&r2=480156
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LifecycleCallbackInfo.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LifecycleCallbackInfo.java Tue Nov 28 11:05:24 2006
@@ -20,7 +20,7 @@
 /**
  * @version $Revision$ $Date$
  */
-public class LifecycleCallbackInfo {
+public class LifecycleCallbackInfo extends InfoObject {
     public String className;
     public String method;
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodInfo.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodInfo.java?view=diff&rev=480156&r1=480155&r2=480156
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodInfo.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodInfo.java Tue Nov 28 11:05:24 2006
@@ -19,7 +19,7 @@
 public class MethodInfo extends InfoObject {
 
     public String description;
-    public Object ejbDeploymentId;
+    public String ejbDeploymentId;
     public String methodIntf;
     public String methodName;
     public String[] methodParams;

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/OpenEjbConfigurationValidationTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/OpenEjbConfigurationValidationTest.java?view=auto&rev=480156
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/OpenEjbConfigurationValidationTest.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/OpenEjbConfigurationValidationTest.java Tue Nov 28 11:05:24 2006
@@ -0,0 +1,109 @@
+/**
+ * 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.assembler.classic;
+
+import junit.framework.TestCase;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class OpenEjbConfigurationValidationTest extends TestCase {
+
+    private List<Class> seen = new ArrayList();
+
+    public void testValidate() throws Exception {
+        seen.add(Object.class);
+        validate(OpenEjbConfiguration.class);
+    }
+
+    private void validate(Class clazz) throws Exception {
+        if (clazz == null) return;
+        if (seen.contains(clazz)) return;
+
+//        validate(clazz.getSuperclass());
+
+        seen.add(clazz);
+
+        String simpleName = clazz.getSimpleName();
+
+        Constructor[] constructors = clazz.getDeclaredConstructors();
+        assertEquals("constructors are not allowed: " + simpleName, 1, constructors.length);
+        assertEquals("constructors are not allowed: " + simpleName, 0, constructors[0].getParameterTypes().length);
+
+        Method[] methods = clazz.getDeclaredMethods();
+        assertEquals("methods are not allowed: " + simpleName, 0, methods.length);
+
+        Annotation[] annotations = clazz.getDeclaredAnnotations();
+        assertEquals("annotations are not allowed: " + simpleName, 0, annotations.length);
+
+        Field[] fields = clazz.getDeclaredFields();
+        for (Field field : fields) {
+            Class type = field.getType();
+            if (type.isArray()) {
+                type = type.getComponentType();
+            }
+
+            if (List.class.isAssignableFrom(type)) {
+                type = getGenericType(field);
+                assertNotNull("Lists must have a generic type: "+simpleName+"."+field.getName(), type);
+            }
+
+            if (type.isPrimitive()) {
+                continue;
+            }
+
+            if (String.class.isAssignableFrom(type)){
+                continue;
+            }
+
+            if (Properties.class.isAssignableFrom(type)){
+                continue;
+            }
+
+            if (InfoObject.class.isAssignableFrom(type)){
+                validate(type);
+                continue;
+            }
+
+            fail("Field is not of an allowed type: "+simpleName+"."+field.getName());
+        }
+    }
+
+    private Class getGenericType(Field field) throws Exception {
+        Type genericType = field.getGenericType();
+
+        if (genericType instanceof ParameterizedType) {
+            ParameterizedType parameterizedType = (ParameterizedType) genericType;
+            Type firstParamType = parameterizedType.getActualTypeArguments()[0];
+            return (Class) firstParamType;
+        } else if (genericType instanceof Class) {
+            return (Class) genericType;
+        } else {
+            return null;
+       }
+    }
+}