[jboss-cvs] JBossAS SVN: r71030 - in projects/microcontainer/trunk/aop-mc-int/src: tests/org/jboss/test/aop/junit and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 19 19:14:09 EDT 2008


Author: alesj
Date: 2008-03-19 19:14:08 -0400 (Wed, 19 Mar 2008)
New Revision: 71030

Added:
   projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/beans/test/FieldAccessTestCase.xml
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/aop/junit/AbstractTypeTest.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/aop/junit/AbstractTypeTestDelegate.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/beans/support/
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/beans/support/AccessBean.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/beans/test/FieldAccessTestCase.java
Log:
AOP and field injection test.

Added: projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/beans/test/FieldAccessTestCase.xml
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/beans/test/FieldAccessTestCase.xml	                        (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/beans/test/FieldAccessTestCase.xml	2008-03-19 23:14:08 UTC (rev 71030)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="AspectManager" class="org.jboss.aop.AspectManager">
+      <constructor factoryClass="org.jboss.aop.AspectManager" factoryMethod="instance"/>
+   </bean>
+
+	<interceptor xmlns="urn:jboss:aop-beans:1.0" class="org.jboss.test.microcontainer.beans.TestInterceptor"/>
+
+	<bind xmlns="urn:jboss:aop-beans:1.0" pointcut="execution(* org.jboss.test.microcontainer.beans.support.AccessBean->*(..))">
+		<interceptor-ref name="org.jboss.test.microcontainer.beans.TestInterceptor"/>
+	</bind>
+
+   <bean name="private" class="org.jboss.test.microcontainer.beans.support.AccessBean" access-mode="ALL">
+      <property name="priString">foobar</property>
+   </bean>
+
+   <bean name="protected" class="org.jboss.test.microcontainer.beans.support.AccessBean" access-mode="ALL">
+      <property name="protString">foobar</property>
+   </bean>
+
+   <bean name="public" class="org.jboss.test.microcontainer.beans.support.AccessBean" access-mode="ALL">
+      <property name="pubString">foobar</property>
+   </bean>
+
+</deployment>

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/aop/junit/AbstractTypeTest.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/aop/junit/AbstractTypeTest.java	                        (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/aop/junit/AbstractTypeTest.java	2008-03-19 23:14:08 UTC (rev 71030)
@@ -0,0 +1,91 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.aop.junit;
+
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * AbstractTypeTest.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractTypeTest extends AbstractTestCaseWithSetup
+{
+   public AbstractTypeTest(String name)
+   {
+      super(name);
+   }
+   
+   /**
+    * Get the test delegate
+    *
+    * @param clazz the test class
+    * @return the delegate
+    * @throws Exception for any error
+    */
+   public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+   {
+      String property = System.getProperty("jboss.mc.secure", "false");
+      boolean enableSecurity = Boolean.valueOf(property);
+      AbstractTypeTestDelegate delegate = new AbstractTypeTestDelegate(clazz);
+      delegate.enableSecurity = enableSecurity;
+      return delegate;
+   }
+
+   protected KernelController getController()
+   {
+      AbstractTypeTestDelegate delegate = (AbstractTypeTestDelegate)getDelegate();
+      return delegate.getKernel().getController();
+   }
+
+   protected ControllerContext getControllerContext(String name) throws Throwable
+   {
+      return getControllerContext(name, null);
+   }
+
+   protected ControllerContext getControllerContext(String name, ControllerState state) throws Throwable
+   {
+      return getController().getContext(name, state);
+   }
+
+   protected <T> T getBean(String name, Class<T> expectedType) throws Throwable
+   {
+      ControllerContext context = getControllerContext(name);
+      assertNotNull(context);
+      Object target = context.getTarget();
+      assertNotNull(target);
+      return assertInstanceOf(target, expectedType);
+   }
+
+   protected AbstractTypeTestDelegate.Type getType(Object name)
+   {
+      AbstractTypeTestDelegate delegate = (AbstractTypeTestDelegate)getDelegate();
+      AbstractTypeTestDelegate.Type type = delegate.getTypes().get(name);
+      if (type == null)
+         throw new IllegalArgumentException("No such context installed by name: " + name);
+      return type;
+   }
+}

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/aop/junit/AbstractTypeTestDelegate.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/aop/junit/AbstractTypeTestDelegate.java	                        (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/aop/junit/AbstractTypeTestDelegate.java	2008-03-19 23:14:08 UTC (rev 71030)
@@ -0,0 +1,154 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.aop.junit;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import org.jboss.kernel.plugins.bootstrap.AbstractBootstrap;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.plugins.config.property.PropertyKernelConfig;
+import org.jboss.kernel.plugins.dependency.AbstractKernelController;
+import org.jboss.kernel.plugins.dependency.InstantiateAction;
+import org.jboss.kernel.spi.config.KernelConfig;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.kernel.Kernel;
+import org.jboss.test.kernel.junit.MicrocontainerTestDelegate;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.aop.proxy.container.AspectManaged;
+import org.jboss.aop.Advised;
+
+/**
+ * AbstractTypeTestDelegate.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AbstractTypeTestDelegate extends MicrocontainerTestDelegate
+{
+   /** Is proxy, woven or pojo map -> <bean name, type> */
+   private Map<Object, Type> types = new HashMap<Object, Type>();
+
+   public AbstractTypeTestDelegate(Class<?> clazz) throws Exception
+   {
+      super(clazz);
+   }
+
+   protected AbstractBootstrap getBootstrap() throws Exception
+   {
+      return new BasicBootstrap(createKernelConfig());
+   }
+
+   Map<Object, Type> getTypes()
+   {
+      return types;
+   }
+
+   Kernel getKernel()
+   {
+      return kernel;
+   }
+
+   protected KernelConfig createKernelConfig()
+   {
+      return new TestKernelConfig();
+   }
+
+   private class TestKernelConfig extends PropertyKernelConfig
+   {
+      public TestKernelConfig()
+      {
+         super(null);
+      }
+
+      public KernelController createKernelController() throws Throwable
+      {
+         return new TestController();
+      }
+   }
+
+   private class TestController extends AbstractKernelController
+   {
+      private TestInstantiateAction instantiate = new TestInstantiateAction();
+
+      public TestController() throws Exception
+      {
+      }
+
+      protected void install(ControllerContext context, ControllerState fromState, ControllerState toState) throws Throwable
+      {
+         if (ControllerState.INSTANTIATED.equals(toState))
+            instantiate.install(context);
+         else
+            super.install(context, fromState, toState);
+      }
+
+      protected void uninstall(ControllerContext context, ControllerState fromState, ControllerState toState)
+      {
+         if (ControllerState.INSTANTIATED.equals(fromState))
+            instantiate.uninstall(context);
+         else
+            super.uninstall(context, fromState, toState);
+      }
+   }
+
+   private class TestInstantiateAction extends InstantiateAction
+   {
+      protected void installActionInternal(KernelControllerContext context) throws Throwable
+      {
+         super.installActionInternal(context);
+         checkTargetType(context.getName(), context.getTarget());
+      }
+
+      protected void uninstallActionInternal(KernelControllerContext context)
+      {
+         types.remove(context.getName());
+         super.uninstallActionInternal(context);
+      }
+   }
+
+   protected void checkTargetType(Object name, Object target) throws Throwable
+   {
+      Type type;
+      if (target instanceof AspectManaged)
+      {
+         type = Type.PROXY;
+      }
+      else if (target instanceof Advised)
+      {
+         type = Type.WOVEN;
+      }
+      else
+      {
+         type = Type.POJO;
+      }
+      types.put(name, type);
+   }
+
+   public enum Type
+   {
+      PROXY,
+      WOVEN,
+      POJO
+   }
+}

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/beans/support/AccessBean.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/beans/support/AccessBean.java	                        (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/beans/support/AccessBean.java	2008-03-19 23:14:08 UTC (rev 71030)
@@ -0,0 +1,48 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.microcontainer.beans.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AccessBean
+{
+   @SuppressWarnings("unused")
+   private String priString;
+   protected String protString;
+   public String pubString;
+
+   public String getPriString()
+   {
+      return priString;
+   }
+
+   public String getProtString()
+   {
+      return protString;
+   }
+
+   public String getPubString()
+   {
+      return pubString;
+   }
+}

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/beans/test/FieldAccessTestCase.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/beans/test/FieldAccessTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/beans/test/FieldAccessTestCase.java	2008-03-19 23:14:08 UTC (rev 71030)
@@ -0,0 +1,80 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.microcontainer.beans.test;
+
+import junit.framework.Test;
+import org.jboss.test.aop.junit.AbstractTypeTest;
+import org.jboss.test.aop.junit.AbstractTypeTestDelegate;
+import org.jboss.test.microcontainer.beans.support.AccessBean;
+
+/**
+ * AOP field test case.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class FieldAccessTestCase extends AbstractTypeTest
+{
+   public FieldAccessTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(FieldAccessTestCase.class);
+   }
+
+   protected void testAccessBean(String name) throws Throwable
+   {
+      AccessBean bean = getBean(name, AccessBean.class);
+      AbstractTypeTestDelegate.Type type = getType(name);
+      if (type == AbstractTypeTestDelegate.Type.PROXY)
+      {
+         assertNull(bean.getPriString());
+         assertNull(bean.getProtString());
+         assertNull(bean.getPubString());
+      }
+      else
+      {
+         assertEquals("foobar", concat(bean));
+      }
+   }
+
+   private String concat(AccessBean bean)
+   {
+      String string = "";
+      if (bean.getPriString() != null)
+         string += bean.getPriString();
+      if (bean.getProtString() != null)
+         string += bean.getProtString();
+      if (bean.pubString != null)
+         string += bean.pubString;
+      return string;
+   }
+
+   public void testFieldAccess() throws Throwable
+   {
+      testAccessBean("private");
+      testAccessBean("protected");
+      testAccessBean("public");
+   }
+}




More information about the jboss-cvs-commits mailing list