[jboss-cvs] JBossAS SVN: r84242 - in projects/ejb3/trunk: nointerface and 17 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Feb 16 06:44:20 EST 2009


Author: jaikiran
Date: 2009-02-16 06:44:20 -0500 (Mon, 16 Feb 2009)
New Revision: 84242

Added:
   projects/ejb3/trunk/nointerface/
   projects/ejb3/trunk/nointerface/pom.xml
   projects/ejb3/trunk/nointerface/src/
   projects/ejb3/trunk/nointerface/src/main/
   projects/ejb3/trunk/nointerface/src/main/java/
   projects/ejb3/trunk/nointerface/src/main/java/org/
   projects/ejb3/trunk/nointerface/src/main/java/org/jboss/
   projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/
   projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/
   projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewCreator.java
   projects/ejb3/trunk/nointerface/src/main/resources/
   projects/ejb3/trunk/nointerface/src/test/
   projects/ejb3/trunk/nointerface/src/test/java/
   projects/ejb3/trunk/nointerface/src/test/java/org/
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/AbstractSimpleBase.java
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/ChildBean.java
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/MethodInvocationTrackingContainer.java
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSLSBWithoutInterface.java
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/NoInterfaceEJBViewCreatorTestCase.java
   projects/ejb3/trunk/nointerface/src/test/resources/
   projects/ejb3/trunk/nointerface/src/test/resources/log4j.xml
Log:
EJBTHREE-1727 Initial implementation of the no-interface view

Added: projects/ejb3/trunk/nointerface/pom.xml
===================================================================
--- projects/ejb3/trunk/nointerface/pom.xml	                        (rev 0)
+++ projects/ejb3/trunk/nointerface/pom.xml	2009-02-16 11:44:20 UTC (rev 84242)
@@ -0,0 +1,60 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <!-- Parent -->
+  <parent>
+    <groupId>org.jboss.ejb3</groupId>
+    <artifactId>jboss-ejb3-build</artifactId>
+    <version>1.0.0</version>
+    <relativePath>../build/pom.xml</relativePath>
+  </parent>
+
+  <!-- POM Model Version -->
+  <modelVersion>4.0.0</modelVersion>
+
+  <!-- Artifact Information -->
+  <artifactId>jboss-ejb3-nointerface</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0.0-SNAPSHOT</version>
+  <name>JBoss EJB 3.1 Implementation of the No-Interface view</name>
+  <url>http://labs.jboss.com/jbossejb3</url>
+  <description>No-Interface implementation for EJB as defined by section 3.4.4 in EJB3.1 spec</description>
+
+  <properties>
+      <version.org.jboss_jboss-vfs>2.0.1.GA</version.org.jboss_jboss-vfs>
+      <version.javassist>3.7.1.GA</version.javassist>
+  </properties>
+
+
+
+
+  <dependencies>
+
+
+    <!-- JUnit support -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>javassist</groupId>
+      <artifactId>javassist</artifactId>
+      <version>${version.javassist}</version>
+    </dependency>
+
+   <dependency>
+        <groupId>org.jboss.logging</groupId>
+        <artifactId>jboss-logging-spi</artifactId>
+    </dependency>
+
+   <dependency>
+      <groupId>org.jboss.javaee</groupId>
+      <artifactId>jboss-ejb-api</artifactId>
+    </dependency>
+
+
+    </dependencies>
+</project>

Added: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewCreator.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewCreator.java	                        (rev 0)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewCreator.java	2009-02-16 11:44:20 UTC (rev 84242)
@@ -0,0 +1,235 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.nointerface;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
+import java.util.HashSet;
+import java.util.Set;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtField;
+import javassist.CtMethod;
+import javassist.CtNewMethod;
+import javassist.Modifier;
+
+import org.jboss.logging.Logger;
+
+/**
+ * NoInterfaceEJBViewCreator
+ *
+ * Creates a no-interface view for a EJB as per the EJB3.1 spec (section 3.4.4)
+ *
+ * TODO:
+ * 1) Needs to be tested more for i) Classloaders ii) Security Manager
+ * 2) Though not related here, we need to have support for @LocalBean (and corresponding xml element) through JBMETA
+ *
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class NoInterfaceEJBViewCreator //implements EJBViewCreator
+{
+
+   /**
+    * The proxies (sub-classes) created for the bean class need to be
+    * unique. This unique number is appended to the generated class name
+    */
+   private long nextUniqueNumberForNoViewInterfaceClassName = 0;
+
+   /**
+    * Used while generating unique number for the proxy class
+    */
+   private Object nextUniqueNumberLock = new Object();
+
+   /**
+    * Logger
+    */
+   private static Logger logger = Logger.getLogger(NoInterfaceEJBViewCreator.class);
+
+   /**
+    * Inspects the bean class for all public methods and creates a proxy (sub-class)
+    * out of it with overriden implementation of the public methods. The overriden
+    * implementation will just give a call to <code>container</code>'s invoke(...) method
+    * which handles the actual call.
+    *
+    * @param <T>
+    * @param container The container correpsonding to the bean class
+    * @param beanClass The bean class (currently assumed)
+    * @return Returns the no-interface view for the <code>beanClass</code>
+    * @throws Exception
+    */
+   public <T> T createView(InvocationHandler container, Class<T> beanClass) throws Exception
+   {
+      if (logger.isTraceEnabled())
+      {
+         logger.trace("Creating nointerface view for beanClass: " + beanClass + " with container " + container);
+      }
+      //TODO: Validation as per section 4.9.8 of EJB 3.1 PR spec needs to be implemented.
+      // Instead of accepting a bean class, maybe we should accept the JBossSessionBeanMetadata.
+      // The metadata is required to carry out validations on the bean to ensure that section 4.9.8
+      // of the EJB 3.1 PR spec. We could create the metadata ourselves, from the bean class, here, but
+      // that would be duplication of efforts since the metadata is surely going to created at some place else too
+
+      ClassPool pool = ClassPool.getDefault();
+      CtClass beanCtClass = pool.get(beanClass.getName());
+
+      // Create a sub-class (proxy) for the bean class
+      // TODO: This should be a unique name. Should not clash with any of the classnames in
+      // the user application or with any of already created proxy names
+      // Right now lets append _NoInterfaceProxy to the bean class name
+      CtClass proxyCtClass = pool.makeClass(beanClass.getName() + "_NoInterfaceProxy$" + getNextUniqueNumber(),
+            beanCtClass);
+
+      // We need to maintain a reference of the container in the proxy, so that we can
+      // forward the method calls to container.invoke. Create a new field in the sub-class (proxy)
+      CtField containerField = CtField.make("private java.lang.reflect.InvocationHandler container;", proxyCtClass);
+      proxyCtClass.addField(containerField);
+
+      // get all public methods from the bean class
+      Set<CtMethod> beanPublicMethods = getAllPublicNonStaticNonFinalMethods(beanCtClass);
+
+      // Override each of the public methods
+      for (CtMethod beanPublicMethod : beanPublicMethods)
+      {
+         // Methods from java.lang.Object can be skipped, if they are
+         // not implemented (overriden) in the bean class. TODO: Do we really need to do this?
+         if (shouldMethodBeSkipped(beanCtClass, beanPublicMethod))
+         {
+            logger.debug("Skipping " + beanPublicMethod.getName() + " on bean " + beanCtClass.getName()
+                  + " from no-interface view");
+            continue;
+         }
+         // We should not be changing the bean class methods. So we need to create a copy of the methods
+         // for the sub-class (proxy)
+         CtMethod proxyPublicMethod = CtNewMethod.copy(beanPublicMethod, proxyCtClass, null);
+         // All the public methods of the bean should now be overriden (through the proxy)
+         // to give a call to the container.invoke
+         // Ex: If the bean's public method was:
+         // public String sayHi(String name) { return "Hi " + name; }
+         // then it will be changed in the proxy to
+         // public String sayHi(String name) { java.lang.reflect.Method currentMethod = beanClass.getName() + ".class.getMethod(theMethodName,params);
+         // return container.invoke(this,currentMethod,args); }
+         proxyPublicMethod.setBody("{"
+               +
+               // The proxy needs to call the container.invoke
+               // the InvocationHandler.invoke accepts (Object proxy,Method method,Object[] args)
+               // The proxy needs to create a java.lang.reflect.Method object based on the "current method"
+               // that is invoked on the proxy. Note that we need to get the Method from the super class (i.e. the
+               // bean class) of the proxy, since that's our "target" method
+               // Note: All the '$' parameters used are javassist specific syntax
+               "java.lang.reflect.Method currentMethod = " + beanClass.getName() + ".class.getMethod(\""
+               + beanPublicMethod.getName() + "\",$sig);" +
+               // At this point we have the container, the proxy, the Method to be invoked and the parameters to be passed
+               // All we have to do is invoke the container
+               "return ($r) container.invoke((java.lang.Object)this,currentMethod,$args);" + "}");
+         // We have now created the overriden method. We need to add it to the proxy
+         proxyCtClass.addMethod(proxyPublicMethod);
+         if (logger.isTraceEnabled())
+         {
+            logger.trace("Added method " + proxyPublicMethod.getName() + " in no-interface view "
+                  + proxyCtClass.getName() + " for bean " + beanClass.getName());
+         }
+      }
+      // We are almost done (except for setting the container field in the proxy)
+      // Let's first create a java.lang.Class (i.e. load) out of the javassist class
+      // using the classloader of the bean
+      Class<?> proxyClass = proxyCtClass.toClass(beanClass.getClassLoader());
+      // time to set the container field through normal java reflection
+      Object proxyInstance = proxyClass.newInstance();
+      Field containerInProxy = proxyClass.getDeclaredField("container");
+      containerInProxy.setAccessible(true);
+      containerInProxy.set(proxyInstance, container);
+
+      // return the proxy instance
+      return beanClass.cast(proxyInstance);
+
+   }
+
+   /**
+    * Returns all public, non-static and non-final methods for the class
+    *
+    * @param ctClass The class whose non-final, non-static public methods are to be returned
+    * @return
+    * @throws Exception
+    */
+   private Set<CtMethod> getAllPublicNonStaticNonFinalMethods(CtClass ctClass) throws Exception
+   {
+      CtMethod[] allMethods = ctClass.getMethods();
+      Set<CtMethod> publicMethods = new HashSet<CtMethod>();
+
+      for (CtMethod ctMethod : allMethods)
+      {
+         int modifier = ctMethod.getModifiers();
+         // Public non-static non-final methods
+         if (((Modifier.PUBLIC & modifier) == Modifier.PUBLIC) && ((Modifier.STATIC & modifier) != Modifier.STATIC)
+               && ((Modifier.FINAL & modifier) != Modifier.FINAL) && ((Modifier.NATIVE & modifier) != Modifier.NATIVE))
+         {
+            publicMethods.add(ctMethod);
+         }
+      }
+      return publicMethods;
+   }
+
+   /**
+    * Checks whether a method has to be skipped from being overriden in the proxy
+    * that is returned for the no-interface view.
+    *
+    * TODO: Do we really need this. Need to think more. Let's keep it for the time-being
+    *
+    * @param beanCtClass
+    * @param ctMethod
+    * @return
+    * @throws Exception
+    */
+   private boolean shouldMethodBeSkipped(CtClass beanCtClass, CtMethod ctMethod) throws Exception
+   {
+
+      //      List<CtMethod> declaredMethods = Arrays.asList(beanCtClass.getDeclaredMethods());
+      //      if (declaredMethods.contains(ctMethod))
+      //      {
+      //         return false;
+      //      }
+      //      CtClass objectCtClass = ClassPool.getDefault().get(Object.class.getName());
+      //      CtMethod[] methodsInObjectClass = objectCtClass.getMethods();
+      //      List<CtMethod> methodsToBeSkipped = Arrays.asList(methodsInObjectClass);
+      //      return methodsToBeSkipped.contains(ctMethod);
+      return false;
+
+   }
+
+   /**
+    * Get the next unique number which will be used for the proxy class name
+    *
+    * @return
+    */
+   private long getNextUniqueNumber()
+   {
+      synchronized (nextUniqueNumberLock)
+      {
+         this.nextUniqueNumberForNoViewInterfaceClassName++;
+         return this.nextUniqueNumberForNoViewInterfaceClassName;
+      }
+   }
+
+}

Added: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/AbstractSimpleBase.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/AbstractSimpleBase.java	                        (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/AbstractSimpleBase.java	2009-02-16 11:44:20 UTC (rev 84242)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.nointerface.test.viewcreator;
+
+/**
+ * AbstractSimpleBase
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public abstract class AbstractSimpleBase
+{
+
+   private String someString;
+
+   public String sayHiFromBase(String user)
+   {
+      return "Hi from base, to user " + user;
+   }
+
+   public static void someStaticMethod()
+   {
+      // do nothing
+   }
+
+   @Override
+   public String toString()
+   {
+      return "AbstractSimpleBase";
+   }
+
+   public abstract String sayHiFromChild(String name);
+
+   public final void someFinalMethod()
+   {
+
+   }
+}

Added: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/ChildBean.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/ChildBean.java	                        (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/ChildBean.java	2009-02-16 11:44:20 UTC (rev 84242)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.nointerface.test.viewcreator;
+
+import javax.ejb.Stateless;
+
+/**
+ * ChildBean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+public class ChildBean extends AbstractSimpleBase
+{
+
+   @Override
+   public String sayHiFromChild(String name)
+   {
+      return "Hi from " + ChildBean.class.getName() + " to user " + name;
+   }
+
+   private void somePrivateMethod()
+   {
+      // do nothing
+   }
+
+
+   public int somePublicMethod(int number)
+   {
+      return number;
+   }
+}

Added: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/MethodInvocationTrackingContainer.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/MethodInvocationTrackingContainer.java	                        (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/MethodInvocationTrackingContainer.java	2009-02-16 11:44:20 UTC (rev 84242)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.nointerface.test.viewcreator;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.ejb3.nointerface.test.viewcreator.unit.NoInterfaceEJBViewCreatorTestCase;
+import org.jboss.logging.Logger;
+
+/**
+ * MethodInvocationTrackingContainer
+ *
+ * Mock container which just tracks/maintains the methods which were
+ * invoked on the bean through this container. This MethodInvocationTrackingContainer will be
+ * used by the {@link NoInterfaceEJBViewCreatorTestCase} to create a no-interface view out of a
+ * bean and associate this container with the bean. Any invocations on the public methods of the
+ * no-interface view of the bean in, the {@link NoInterfaceEJBViewCreatorTestCase} test case,
+ * will be routed through this MethodInvocationTrackingContainer
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class MethodInvocationTrackingContainer implements InvocationHandler
+{
+
+   /**
+    * Logger
+    */
+   private Logger logger = Logger.getLogger(MethodInvocationTrackingContainer.class);
+
+   /**
+    * The bean class to which this container corresponds to
+    */
+   private Class<?> beanClass;
+
+
+   private List<String> invokedMethods;
+
+   /**
+    * Constructor
+    * @param targetBean The bean class to which this container corresponds to
+    */
+   public MethodInvocationTrackingContainer(Class<?> targetBean)
+   {
+      this.beanClass = targetBean;
+      invokedMethods = new ArrayList<String>();
+   }
+
+   /**
+    * Maintains the method name invoked, in its internal list and then forwards
+    * the method invocation to the instance of the bean class
+    *
+    *
+    * @see InvocationHandler#invoke(Object, Method, Object[])
+    */
+   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      logger.debug("Tracking method " + method.getName() + " for bean " + beanClass.getName());
+      // add to internal map for tracking
+      this.invokedMethods.add(method.getName());
+
+      Object target = beanClass.newInstance();
+      return method.invoke(target, args);
+   }
+
+   /**
+    * Clears the methods that were tracked
+    */
+   public void resetTracking()
+   {
+      this.invokedMethods.clear();
+   }
+
+   /**
+    * Return the tracked method names
+    * @return
+    */
+   public List<String> getTrackedMethodNames()
+   {
+      return Collections.unmodifiableList(this.invokedMethods);
+   }
+
+}

Added: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSLSBWithoutInterface.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSLSBWithoutInterface.java	                        (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSLSBWithoutInterface.java	2009-02-16 11:44:20 UTC (rev 84242)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.nointerface.test.viewcreator;
+
+import javax.ejb.Stateless;
+
+import org.jboss.logging.Logger;
+
+/**
+ * SimpleSLSBWithoutInterface
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+public class SimpleSLSBWithoutInterface
+{
+
+   /**
+    * Logger
+    */
+   private static Logger logger = Logger.getLogger(SimpleSLSBWithoutInterface.class);
+
+   public Object container;
+
+   public void simplePublicMethod()
+   {
+      // do nothing
+   }
+
+   private void somePrivateMethod()
+   {
+      // do nothing
+
+   }
+
+   public static void someStaticMethod()
+   {
+      // do nothing
+   }
+
+   public String sayHi(String name)
+   {
+      return "Hi " + name;
+   }
+
+   @Override
+   public String toString()
+   {
+      return "Test - " + this.getClass().getName();
+   }
+
+   public final String someFinalMethod()
+   {
+      return "someFinalMethod";
+   }
+
+   public static final int someStaticFinalMethod(int number)
+   {
+      return number;
+   }
+}

Added: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/NoInterfaceEJBViewCreatorTestCase.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/NoInterfaceEJBViewCreatorTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/NoInterfaceEJBViewCreatorTestCase.java	2009-02-16 11:44:20 UTC (rev 84242)
@@ -0,0 +1,208 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.nointerface.test.viewcreator.unit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+
+import org.jboss.ejb3.nointerface.NoInterfaceEJBViewCreator;
+import org.jboss.ejb3.nointerface.test.viewcreator.ChildBean;
+import org.jboss.ejb3.nointerface.test.viewcreator.MethodInvocationTrackingContainer;
+import org.jboss.ejb3.nointerface.test.viewcreator.SimpleSLSBWithoutInterface;
+import org.jboss.logging.Logger;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * NoInterfaceEJBViewCreatorTestCase
+ *
+ * Tests the {@link NoInterfaceEJBViewCreator}
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class NoInterfaceEJBViewCreatorTestCase
+{
+
+   /**
+    * Logger
+    */
+   private static Logger logger = Logger.getLogger(NoInterfaceEJBViewCreatorTestCase.class);
+
+   private static NoInterfaceEJBViewCreator noInterfaceViewCreator;
+
+   @BeforeClass
+   public static void beforeClass() throws Exception
+   {
+      noInterfaceViewCreator = new NoInterfaceEJBViewCreator();
+
+   }
+
+   @AfterClass
+   public static void afterClass() throws Exception
+   {
+
+   }
+
+   /**
+    * Test to ensure that all the public (non-static, non-final) methods on a bean
+    * are routed through the container
+    *
+    * @throws Exception
+    */
+   @Test
+   public void testNoInterfaceViewCreator() throws Exception
+   {
+      MethodInvocationTrackingContainer mockContainer = new MethodInvocationTrackingContainer(
+            SimpleSLSBWithoutInterface.class);
+      SimpleSLSBWithoutInterface noInterfaceView = noInterfaceViewCreator.createView(mockContainer,
+            SimpleSLSBWithoutInterface.class);
+
+      int numberOfMethodsInvokedOnBean = 0;
+
+      String message = noInterfaceView.sayHi("jaikiran");
+      numberOfMethodsInvokedOnBean++;
+
+      logger.debug("Bean returned message : " + message);
+
+      noInterfaceView.simplePublicMethod();
+      numberOfMethodsInvokedOnBean++;
+
+      logger.info("Number of methods invoked on bean = " + numberOfMethodsInvokedOnBean);
+
+      assertNotNull("Methods on no-interface view were not tracked by container", mockContainer.getTrackedMethodNames());
+      assertEquals("The container did not handle the expected number of calls on the bean",
+            numberOfMethodsInvokedOnBean, mockContainer.getTrackedMethodNames().size());
+
+   }
+
+   /**
+    * Test to ensure that the no-interface view instance does NOT consider
+    * a final method on the bean while creating the view
+    *
+    * @throws Exception
+    */
+   @Test
+   public void testFinalMethodsAreNotConsideredInView() throws Exception
+   {
+      MethodInvocationTrackingContainer mockContainer = new MethodInvocationTrackingContainer(
+            SimpleSLSBWithoutInterface.class);
+      SimpleSLSBWithoutInterface noInterfaceView = noInterfaceViewCreator.createView(mockContainer,
+            SimpleSLSBWithoutInterface.class);
+
+      noInterfaceView.someFinalMethod();
+
+      assertEquals("Final method of bean " + SimpleSLSBWithoutInterface.class.getName()
+            + " was included in no-inteface view", 0, mockContainer.getTrackedMethodNames().size());
+
+   }
+
+   /**
+    * Test to ensure that the no-interface view instance does NOT consider
+    * a static method on the bean while creating the view
+    *
+    * @throws Exception
+    */
+   @Test
+   public void testStaticMethodsAreNotConsideredInView() throws Exception
+   {
+      MethodInvocationTrackingContainer mockContainer = new MethodInvocationTrackingContainer(
+            SimpleSLSBWithoutInterface.class);
+      SimpleSLSBWithoutInterface noInterfaceView = noInterfaceViewCreator.createView(mockContainer,
+            SimpleSLSBWithoutInterface.class);
+
+      noInterfaceView.someStaticMethod();
+
+      assertEquals("Static method of bean " + SimpleSLSBWithoutInterface.class.getName()
+            + " was included in no-inteface view", 0, mockContainer.getTrackedMethodNames().size());
+
+      noInterfaceView.someStaticFinalMethod(3);
+      assertEquals("Static final method of bean " + SimpleSLSBWithoutInterface.class.getName()
+            + " was included in no-inteface view", 0, mockContainer.getTrackedMethodNames().size());
+
+   }
+
+   /**
+    * Test that multiple invocations to the {@link NoInterfaceEJBViewCreator#createView(java.lang.reflect.InvocationHandler, Class)}
+    * returns different instances of the view with unique view-classnames
+    *
+    * @throws Exception
+    */
+   @Test
+   public void testViewCreatorCreatesUniqueViewInstanceNames() throws Exception
+   {
+      MethodInvocationTrackingContainer mockContainer = new MethodInvocationTrackingContainer(
+            SimpleSLSBWithoutInterface.class);
+
+      SimpleSLSBWithoutInterface noInterfaceView = noInterfaceViewCreator.createView(mockContainer,
+            SimpleSLSBWithoutInterface.class);
+      logger.debug("No-interface view for first invocation is " + noInterfaceView);
+
+      SimpleSLSBWithoutInterface anotherNoInterfaceViewOnSameBean = noInterfaceViewCreator.createView(mockContainer,
+            SimpleSLSBWithoutInterface.class);
+      logger.debug("No-interface view for second invocation is " + anotherNoInterfaceViewOnSameBean);
+
+      assertNotSame("No-interface view returned same instance for two createView invocations", noInterfaceView,
+            anotherNoInterfaceViewOnSameBean);
+      assertTrue("No-interfave view class name is the same for two createView invocations", !noInterfaceView
+            .equals(anotherNoInterfaceViewOnSameBean));
+   }
+
+   /**
+    * Test that the no-interface view works as expected when the bean extends from some other class
+    *
+    * @throws Exception
+    */
+   @Test
+   public void testNoInterfaceViewCreatorWithInheritedClasses() throws Exception
+   {
+      MethodInvocationTrackingContainer mockContainer = new MethodInvocationTrackingContainer(ChildBean.class);
+
+      ChildBean noInterfaceView = noInterfaceViewCreator.createView(mockContainer, ChildBean.class);
+
+      int numberOfInvokedMethods = 0;
+      noInterfaceView.sayHiFromBase("jaikiran");
+      numberOfInvokedMethods++;
+
+      noInterfaceView.sayHiFromChild("jaikiran");
+      numberOfInvokedMethods++;
+
+      noInterfaceView.somePublicMethod(4);
+      numberOfInvokedMethods++;
+
+      // Do NOT increment the counter, since we are calling the final method
+      // which will NOT be covered by the no-interface view
+      noInterfaceView.someFinalMethod();
+
+      logger.debug("Number of methods invoked on bean = " + numberOfInvokedMethods);
+
+      assertNotNull("Methods on no-interface view on inherited bean were not tracked by container", mockContainer.getTrackedMethodNames());
+      assertEquals("The container did not handle the expected number of calls on the inherited bean",
+            numberOfInvokedMethods, mockContainer.getTrackedMethodNames().size());
+
+
+
+   }
+}

Added: projects/ejb3/trunk/nointerface/src/test/resources/log4j.xml
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/resources/log4j.xml	                        (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/resources/log4j.xml	2009-02-16 11:44:20 UTC (rev 84242)
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!--                                                                       -->
+<!--  Log4j Configuration                                                  -->
+<!--                                                                       -->
+<!-- ===================================================================== -->
+
+<!-- $Id: log4j.xml 68671 2008-01-08 10:04:25Z wolfc $ -->
+
+<!--
+   | For more configuration infromation and examples see the Jakarta Log4j
+   | owebsite: http://jakarta.apache.org/log4j
+ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+  <!-- ================================= -->
+  <!-- Preserve messages in a local file -->
+  <!-- ================================= -->
+
+  <!-- A time/date based rolling appender -->
+  <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
+    <param name="File" value="target/test.log"/>
+    <param name="Threshold" value="TRACE"/>
+    <param name="Append" value="false"/>
+
+    <!-- Rollover at midnight each day -->
+    <param name="DatePattern" value="'.'yyyy-MM-dd"/>
+
+    <!-- Rollover at the top of each hour
+    <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
+    -->
+
+    <layout class="org.apache.log4j.PatternLayout">
+      <!-- The default pattern: Date Priority [Category] Message\n -->
+      <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
+
+      <!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
+      <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
+       -->
+    </layout>
+  </appender>
+
+  <!-- ============================== -->
+  <!-- Append messages to the console -->
+  <!-- ============================== -->
+
+  <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+    <param name="Target" value="System.out"/>
+
+    <layout class="org.apache.log4j.PatternLayout">
+      <!-- The default pattern: Date Priority [Category] Message\n -->
+      <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
+    </layout>
+  </appender>
+
+
+  <!-- ================ -->
+  <!-- Limit categories -->
+  <!-- ================ -->
+
+  <category name="org.jboss">
+    <priority value="TRACE"/>
+  </category>
+
+  <category name="org.jnp">
+    <priority value="INFO"/>
+  </category>
+
+  <category name="org.jboss.ejb3">
+    <priority value="ALL"/>
+  </category>
+
+  <!-- ======================= -->
+  <!-- Setup the Root category -->
+  <!-- ======================= -->
+
+  <root>
+    <appender-ref ref="CONSOLE"/>
+    <appender-ref ref="FILE"/>
+  </root>
+
+</log4j:configuration>


Property changes on: projects/ejb3/trunk/nointerface/src/test/resources/log4j.xml
___________________________________________________________________
Name: svn:executable
   + *




More information about the jboss-cvs-commits mailing list