[jboss-cvs] JBossAS SVN: r58245 - in projects/microcontainer/trunk/aop-mc-int/src: main/org/jboss/aop/microcontainer/aspects main/org/jboss/aop/microcontainer/aspects/jndi main/org/jboss/aop/microcontainer/junit resources/tests/org/jboss/test/microcontainer/test tests/org/jboss/test/microcontainer/support tests/org/jboss/test/microcontainer/support/jndi tests/org/jboss/test/microcontainer/test

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 10 05:41:16 EST 2006


Author: scott.stark at jboss.org
Date: 2006-11-10 05:41:12 -0500 (Fri, 10 Nov 2006)
New Revision: 58245

Added:
   projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/aspects/jndi/
   projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/aspects/jndi/JndiBinding.java
   projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/aspects/jndi/JndiIntroduction.java
   projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JndiDecoratedTestCase.xml
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/ISimpleBean.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/MockInitialContextFactory.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/MockJndiProvider.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/MockNameParser.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/SimpleBean.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/SimpleBeanAnnotatedImpl.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/JndiDecoratedTestCase.java
Modified:
   projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/junit/AOPMicrocontainerTestDelegate.java
Log:
A JNDI binding aspect that creates bindings on interception of the kernel setKernelControllerContext callback, and removes them on any other method. The expectation is that this is applied to the  org.jboss.kernel.spi.dependency.KernelControllerContextAware interface so that unbinding occurs on the unsetKernelControllerContext method.

Added: projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/aspects/jndi/JndiBinding.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/aspects/jndi/JndiBinding.java	2006-11-09 22:53:49 UTC (rev 58244)
+++ projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/aspects/jndi/JndiBinding.java	2006-11-10 10:41:12 UTC (rev 58245)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * 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.aop.microcontainer.aspects.jndi;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * An annotation that indicates an object should be bound into JNDI
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 46386 $
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ElementType.TYPE,ElementType.FIELD})
+public @interface JndiBinding 
+{
+   /**
+    * the name under which the binding will be located
+    * @return
+    */
+   String name() ;
+   /**
+    * Optional additional aliases to also bind
+    * @return
+    */
+   String[] aliases() default {};
+}

Added: projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/aspects/jndi/JndiIntroduction.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/aspects/jndi/JndiIntroduction.java	2006-11-09 22:53:49 UTC (rev 58244)
+++ projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/aspects/jndi/JndiIntroduction.java	2006-11-10 10:41:12 UTC (rev 58245)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * 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.aop.microcontainer.aspects.jndi;
+
+import java.util.Properties;
+
+import javax.naming.InitialContext;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.logging.Logger;
+import org.jboss.util.naming.Util;
+
+/**
+ * A JNDI binding aspect that creates bindings on interception of the kernel setKernelControllerContext
+ * callback, and removes them on any other method. The expectation is that this is applied to the
+ * org.jboss.kernel.spi.dependency.KernelControllerContextAware interface so that unbinding occurs on
+ * the unsetKernelControllerContext method.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 46386 $
+ */
+public class JndiIntroduction implements Interceptor
+{
+   private static final Logger log = Logger.getLogger(JndiIntroduction.class);
+   private Properties env;
+
+   public String getName()
+   {
+      return getClass().getName();
+   }
+ 
+   /**
+    * Get the InitialContext properties to use for binding/unbinding
+    * @return the InitialContext ctor env
+    */
+   public Properties getEnv()
+   {
+      return env;
+   }
+
+   /**
+    * Set the InitialContext properties to use for binding/unbinding
+    * @param env - the InitialContext ctor env
+    */
+   public void setEnv(Properties env)
+   {
+      this.env = env;
+   }
+
+   /**
+    * Bind the target on setKernelControllerContext, unbind on any other method provided that
+    * the invocation has a JndiBinding annotation.
+    */
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      MethodInvocation mi = (MethodInvocation) invocation;
+      KernelControllerContext context = (KernelControllerContext) mi.getArguments()[0];
+
+      boolean trace = log.isTraceEnabled();
+      JndiBinding bindingInfo = (JndiBinding) invocation.resolveClassAnnotation(JndiBinding.class);
+      if( trace )
+         log.trace("Checking method: "+mi.getMethod()+", bindingInfo: "+bindingInfo);
+      // If this is the setKernelControllerContext callback, bind the target into jndi
+      if ("setKernelControllerContext".equals(mi.getMethod().getName()) && bindingInfo != null)
+      {
+         InitialContext ctx = new InitialContext(env);
+         Object target = context.getTarget();
+         Util.bind(ctx, bindingInfo.name(), target);
+         if( trace )
+            log.trace("Bound to: "+bindingInfo.name());
+         String[] aliases = bindingInfo.aliases();
+         if( aliases != null )
+         {
+            for(String name : aliases)
+            {
+               Util.bind(ctx, name, target);               
+               if( trace )
+                  log.trace("Bound to alias: "+bindingInfo.name());
+            }
+         }
+      }
+      // If this is the unsetKernelControllerContext callback, unbind the target
+      else if( bindingInfo != null )
+      {
+         InitialContext ctx = new InitialContext(env);
+         Util.unbind(ctx, bindingInfo.name());
+         if( trace )
+            log.trace("Unbound: "+bindingInfo.name());
+         String[] aliases = bindingInfo.aliases();
+         if( aliases != null )
+         {
+            for(String name : aliases)
+            {
+               Util.unbind(ctx, name);               
+               if( trace )
+                  log.trace("Unbound alias: "+bindingInfo.name());
+            }
+         }
+      }
+      else if ( trace )
+      {
+         log.trace("Ignoring null binding info");
+      }
+
+      return null;
+   }
+
+}

Modified: projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/junit/AOPMicrocontainerTestDelegate.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/junit/AOPMicrocontainerTestDelegate.java	2006-11-09 22:53:49 UTC (rev 58244)
+++ projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/junit/AOPMicrocontainerTestDelegate.java	2006-11-10 10:41:12 UTC (rev 58245)
@@ -58,6 +58,7 @@
       log.debug("Security enabled: " + enableSecurity);
    }
 
+   
 
    protected void deploy() throws Exception
    {

Added: projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JndiDecoratedTestCase.xml
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JndiDecoratedTestCase.xml	2006-11-09 22:53:49 UTC (rev 58244)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JndiDecoratedTestCase.xml	2006-11-10 10:41:12 UTC (rev 58245)
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="Repository" class="org.jboss.metadata.plugins.repository.basic.BasicMetaDataRepository"/>
+
+   <bean name="AspectManager" class="org.jboss.aop.AspectManager">
+      <constructor factoryClass="org.jboss.aop.AspectManager" factoryMethod="instance"/>
+   </bean>
+
+	<!-- Define the jndi binding advice -->
+   <beanfactory name="JndiAdvice" class="org.jboss.aop.microcontainer.aspects.jndi.JndiIntroduction">
+   	<property name="env">
+           <map class="java.util.Properties" keyClass="java.lang.String" valueClass="java.lang.String">
+              <entry><key>java.naming.factory.initial</key><value>org.jboss.test.microcontainer.support.jndi.MockInitialContextFactory</value></entry>
+           </map>
+   	</property>
+   </beanfactory>
+
+   <beanfactory name="MetaDataContextAdvice" class="org.jboss.test.microcontainer.support.MetaDataContextInterceptor">
+      <property name="annotation">org.jboss.aop.microcontainer.aspects.jndi.JndiBinding</property>
+   </beanfactory>
+
+   <bean name="JndiAspect" class="org.jboss.aop.microcontainer.beans.Aspect">
+      <property name="advice"><inject bean="JndiAdvice"/></property>
+      <property name="manager"><inject bean="AspectManager"/></property>
+   </bean>
+
+   <bean name="MetaDataContextAspect" class="org.jboss.aop.microcontainer.beans.Aspect">
+      <property name="advice"><inject bean="MetaDataContextAdvice"/></property>
+      <property name="manager"><inject bean="AspectManager"/></property>
+   </bean>
+
+   <!-- Introduce the KernelControllerContextAware interface to the JndiBinding annotation -->
+   <bean name="JndiIntroduction" class="org.jboss.aop.microcontainer.beans.IntroductionBinding">
+      <property name="classes">@org.jboss.aop.microcontainer.aspects.jndi.JndiBinding</property>
+      <property name="interfaces">
+         <list elementClass="java.lang.String">
+            <value>org.jboss.kernel.spi.dependency.KernelControllerContextAware</value>
+         </list>
+      </property>
+      <property name="manager"><inject bean="AspectManager"/></property>
+   </bean>
+
+   <!-- Apply the jndi binding to all KernelControllerContextAware interface callbacks -->
+   <bean name="JndiBinding" class="org.jboss.aop.microcontainer.beans.AspectBinding">
+      <property name="pointcut">execution(* $instanceof{org.jboss.kernel.spi.dependency.KernelControllerContextAware}->$implements{org.jboss.kernel.spi.dependency.KernelControllerContextAware}(..))</property>
+      <property name="aspect"><inject bean="JndiAspect" property="definition"/></property>
+      <property name="manager"><inject bean="AspectManager"/></property>
+   </bean>
+
+   <bean name="MetaDataContextBinding" class="org.jboss.aop.microcontainer.beans.AspectBinding">
+      <property name="pointcut">execution(* org.jboss.test.microcontainer.support.jndi.SimpleBean->*(..))</property>
+      <property name="aspect"><inject bean="MetaDataContextAspect" property="definition"/></property>
+      <property name="manager"><inject bean="AspectManager"/></property>
+   </bean>
+
+   <bean name="Bean" class="org.jboss.test.microcontainer.support.jndi.SimpleBean">
+      <annotation>@org.jboss.aop.microcontainer.aspects.jndi.JndiBinding(name="beans/SimpleBean0", aliases={"beans/XmlAnnotatedSimpleBean0"})</annotation>
+      <property name="prop1">bean0.prop1</property>
+   </bean>
+
+   <bean name="AnnotatedBean" class="org.jboss.test.microcontainer.support.jndi.SimpleBeanAnnotatedImpl">
+      <property name="prop1">bean1.prop1</property>
+   </bean>
+</deployment>

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/ISimpleBean.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/ISimpleBean.java	2006-11-09 22:53:49 UTC (rev 58244)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/ISimpleBean.java	2006-11-10 10:41:12 UTC (rev 58245)
@@ -0,0 +1,11 @@
+package org.jboss.test.microcontainer.support.jndi;
+
+public interface ISimpleBean
+{
+   public String getProp1();
+   public void setProp1(String prop1);
+   public int getProp2();
+   public void setProp2(int prop2);
+   public float getProp3();
+   public void setProp3(float prop3);
+}

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/MockInitialContextFactory.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/MockInitialContextFactory.java	2006-11-09 22:53:49 UTC (rev 58244)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/MockInitialContextFactory.java	2006-11-10 10:41:12 UTC (rev 58245)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * 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.support.jndi;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class MockInitialContextFactory implements InitialContextFactory
+{
+
+   public Context getInitialContext(Hashtable<?, ?> env) throws NamingException
+   {
+      return new MockJndiProvider(env);
+   }
+
+}

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/MockJndiProvider.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/MockJndiProvider.java	2006-11-09 22:53:49 UTC (rev 58244)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/MockJndiProvider.java	2006-11-10 10:41:12 UTC (rev 58245)
@@ -0,0 +1,187 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * 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.support.jndi;
+
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class MockJndiProvider implements Context
+{
+   private static ConcurrentHashMap bindings = new ConcurrentHashMap();
+   private Hashtable<?, ?> env;
+
+   MockJndiProvider(Hashtable<?, ?> env)
+   {
+      this.env = env;
+   }
+   public Object addToEnvironment(String propName, Object propVal) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+   public void bind(Name name, Object obj) throws NamingException
+   {
+      String sname = name.toString();
+      bind(sname, obj);
+   }
+   public void bind(String name, Object obj) throws NamingException
+   {
+      bindings.put(name, obj);
+   }
+   public void close() throws NamingException
+   {
+   }
+   public Name composeName(Name name, Name prefix) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+   public String composeName(String name, String prefix) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+   public Context createSubcontext(Name name) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+   public Context createSubcontext(String name) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+   public void destroySubcontext(Name name) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      
+   }
+   public void destroySubcontext(String name) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      
+   }
+   public Hashtable<?, ?> getEnvironment() throws NamingException
+   {
+      return env;
+   }
+   public String getNameInNamespace() throws NamingException
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+   public NameParser getNameParser(Name name) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      return new MockNameParser();
+   }
+   public NameParser getNameParser(String name) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      return new MockNameParser();
+   }
+   public NamingEnumeration<NameClassPair> list(Name name) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+   public NamingEnumeration<NameClassPair> list(String name) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+   public NamingEnumeration<Binding> listBindings(Name name) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+   public NamingEnumeration<Binding> listBindings(String name) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+   public Object lookup(Name name) throws NamingException
+   {
+      String sname = name.toString();
+      return lookup(sname);
+   }
+   public Object lookup(String name) throws NamingException
+   {
+      Object value = bindings.get(name);
+      return value;
+   }
+   public Object lookupLink(Name name) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+   public Object lookupLink(String name) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+   public void rebind(Name name, Object obj) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      
+   }
+   public void rebind(String name, Object obj) throws NamingException
+   {
+      bindings.put(name, obj);
+   }
+   public Object removeFromEnvironment(String propName) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+   public void rename(Name oldName, Name newName) throws NamingException
+   {
+      // TODO Auto-generated method stub
+      
+   }
+   public void rename(String oldName, String newName) throws NamingException
+   {
+      
+   }
+   public void unbind(Name name) throws NamingException
+   {
+      unbind(name.toString());
+   }
+   public void unbind(String name) throws NamingException
+   {
+      bindings.remove(name);
+   }
+   
+}

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/MockNameParser.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/MockNameParser.java	2006-11-09 22:53:49 UTC (rev 58244)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/MockNameParser.java	2006-11-10 10:41:12 UTC (rev 58245)
@@ -0,0 +1,24 @@
+package org.jboss.test.microcontainer.support.jndi;
+
+import java.util.Properties;
+
+import javax.naming.CompoundName;
+import javax.naming.Name;
+import javax.naming.NameParser;
+import javax.naming.NamingException;
+
+public class MockNameParser implements NameParser
+{
+   private static final Properties syntax = new Properties();
+   static
+   {
+      syntax.setProperty("jndi.syntax.direction", "flat");
+   }
+
+   public Name parse(String name) throws NamingException
+   {
+      CompoundName cn = new CompoundName(name, syntax);
+      return cn;
+   }
+
+}

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/SimpleBean.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/SimpleBean.java	2006-11-09 22:53:49 UTC (rev 58244)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/SimpleBean.java	2006-11-10 10:41:12 UTC (rev 58245)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * 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.support.jndi;
+
+import java.io.Serializable;
+
+/**
+ * Test of the jndi binding aspect
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class SimpleBean implements ISimpleBean, Serializable
+{
+   public static final long serialVersionUID = 1;
+   private String prop1;
+   private int prop2;
+   private float prop3;
+
+   public String getProp1()
+   {
+      return prop1;
+   }
+   public void setProp1(String prop1)
+   {
+      this.prop1 = prop1;
+   }
+   public int getProp2()
+   {
+      return prop2;
+   }
+   public void setProp2(int prop2)
+   {
+      this.prop2 = prop2;
+   }
+   public float getProp3()
+   {
+      return prop3;
+   }
+   public void setProp3(float prop3)
+   {
+      this.prop3 = prop3;
+   }
+}

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/SimpleBeanAnnotatedImpl.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/SimpleBeanAnnotatedImpl.java	2006-11-09 22:53:49 UTC (rev 58244)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/jndi/SimpleBeanAnnotatedImpl.java	2006-11-10 10:41:12 UTC (rev 58245)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * 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.support.jndi;
+
+import org.jboss.aop.microcontainer.aspects.jndi.JndiBinding;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at JndiBinding(name="beans/SimpleBean1", aliases={"beans/AnnotatedSimpleBean1"})
+public class SimpleBeanAnnotatedImpl extends SimpleBean
+{
+   private static final long serialVersionUID = 1;
+}

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/JndiDecoratedTestCase.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/JndiDecoratedTestCase.java	2006-11-09 22:53:49 UTC (rev 58244)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/JndiDecoratedTestCase.java	2006-11-10 10:41:12 UTC (rev 58245)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * 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.test;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+
+import org.jboss.aop.microcontainer.junit.AOPMicrocontainerTest;
+import org.jboss.test.microcontainer.support.jndi.SimpleBean;
+import org.jboss.test.microcontainer.support.jndi.SimpleBeanAnnotatedImpl;
+
+public class JndiDecoratedTestCase extends AOPMicrocontainerTest
+{
+   public JndiDecoratedTestCase(String name)
+   {
+      super(name);
+   }
+   public static Test suite()
+   {
+      return suite(JndiDecoratedTestCase.class);
+   }
+
+   /**
+    * Validate that the 
+    * @throws Exception
+    */
+   public void testJndi() throws Exception
+   {
+      super.enableTrace("org.jboss");
+      Properties env = new Properties();
+      env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.test.microcontainer.support.jndi.MockInitialContextFactory");
+      InitialContext ctx = new InitialContext(env);
+
+      SimpleBean bean0 = (SimpleBean) ctx.lookup("beans/SimpleBean0");
+      assertNotNull(bean0);
+      assertEquals("bean0.prop1", bean0.getProp1());
+      SimpleBean alias0 = (SimpleBean) ctx.lookup("beans/XmlAnnotatedSimpleBean0");
+      assertNotNull(alias0);
+      assertEquals("bean0.prop1", alias0.getProp1());
+      SimpleBeanAnnotatedImpl bean1 = (SimpleBeanAnnotatedImpl) ctx.lookup("beans/SimpleBean1");
+      assertEquals("bean1.prop1", bean1.getProp1());
+      SimpleBean alias1 = (SimpleBean) ctx.lookup("beans/AnnotatedSimpleBean1");
+      assertNotNull(alias1);
+      assertEquals("bean1.prop1", alias1.getProp1());
+   }
+   
+}




More information about the jboss-cvs-commits mailing list