[jboss-svn-commits] JBoss Common SVN: r4343 - in arquillian/trunk/containers/openejb/src: main/java/org/jboss/arquillian/prototyping/context/api and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Apr 30 22:13:28 EDT 2010


Author: ALRubinger
Date: 2010-04-30 22:13:27 -0400 (Fri, 30 Apr 2010)
New Revision: 4343

Added:
   arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/api/Properties.java
   arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/api/Property.java
   arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/impl/PropertiesImpl.java
   arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/impl/PropertyImpl.java
   arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/prototyping/context/OpenEJBAuthenticatedJndiContextTestCase.java
   arquillian/trunk/containers/openejb/src/test/resources/groups.properties
   arquillian/trunk/containers/openejb/src/test/resources/users.properties
Removed:
   arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/prototyping/context/OpenEJBArquillianContextTestCase.java
Modified:
   arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/openejb/OpenEJBTestEnricher.java
   arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/api/ArquillianContext.java
   arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/impl/BaseContext.java
   arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/impl/BaseContextualResolver.java
   arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/spi/ContextualResolver.java
   arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/openejb/ejb/EchoBean.java
   arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/openejb/ejb/EchoLocalBusiness.java
Log:
[ARQ-125] Allow @Properties to be specified upon injection points to give context to the resolution process

Modified: arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/openejb/OpenEJBTestEnricher.java
===================================================================
--- arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/openejb/OpenEJBTestEnricher.java	2010-04-30 14:35:18 UTC (rev 4342)
+++ arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/openejb/OpenEJBTestEnricher.java	2010-05-01 02:13:27 UTC (rev 4343)
@@ -29,6 +29,9 @@
 
 import org.apache.openejb.assembler.classic.AppInfo;
 import org.jboss.arquillian.prototyping.context.api.ArquillianContext;
+import org.jboss.arquillian.prototyping.context.api.Properties;
+import org.jboss.arquillian.prototyping.context.api.Property;
+import org.jboss.arquillian.prototyping.context.impl.PropertiesImpl;
 import org.jboss.arquillian.prototyping.context.impl.openejb.OpenEJBArquillianContextImpl;
 import org.jboss.arquillian.spi.Context;
 import org.jboss.arquillian.spi.TestEnricher;
@@ -46,7 +49,7 @@
 {
 
    private ArquillianContext arquillianContext = null;
-   
+
    /**
     * {@inheritDoc}
     * @see org.jboss.arquillian.testenricher.ejb.EJBInjectionEnricher#enrich(org.jboss.arquillian.spi.Context, java.lang.Object)
@@ -56,8 +59,6 @@
    {
       // Call the super implementation to handle @EJB
       super.enrich(context, testCase);
-      
-      
 
       // Handle Typesafe @Inject (ie. ask Arquillian for a an instance of the field type with no additional context properties)
       final Class<? extends Annotation> inject = (Class<? extends Annotation>) Inject.class;
@@ -82,7 +83,35 @@
          }
          try
          {
-            field.set(testCase, this.getArquillianContext(context).get(field.getType()));
+            /*
+             *  Resolve (based on contextual properties if specified)
+             */
+            final Object resolvedVaue;
+            final ArquillianContext arquillianContext = this.getArquillianContext(context);
+            final Class<?> type = field.getType();
+
+            // If Properties are defined
+            if (field.isAnnotationPresent(Properties.class))
+            {
+               final Properties properties = field.getAnnotation(Properties.class);
+               resolvedVaue = arquillianContext.get(type, properties);
+            }
+            // If just one property is defined
+            else if (field.isAnnotationPresent(Property.class))
+            {
+               final Property property = field.getAnnotation(Property.class);
+               final Properties properties = new PropertiesImpl(new Property[]
+               {property});
+               resolvedVaue = arquillianContext.get(type, properties);
+            }
+            // No properties defined; do type-based resolution only
+            else
+            {
+               resolvedVaue = arquillianContext.get(type);
+            }
+
+            // Inject
+            field.set(testCase, resolvedVaue);
          }
          catch (final IllegalAccessException e)
          {
@@ -92,15 +121,17 @@
 
    }
 
-   protected ArquillianContext getArquillianContext(final Context context){
-      if(arquillianContext==null)
+   protected ArquillianContext getArquillianContext(final Context context)
+   {
+      if (arquillianContext == null)
       {
-      // Make a context
+         // Make a context
          final AppInfo deployment = context.get(AppInfo.class);
-         arquillianContext = new OpenEJBArquillianContextImpl(deployment);  
-      }return arquillianContext;
+         arquillianContext = new OpenEJBArquillianContextImpl(deployment);
+      }
+      return arquillianContext;
    }
-   
+
    @Override
    protected InitialContext createContext(final Context context) throws Exception
    {

Modified: arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/api/ArquillianContext.java
===================================================================
--- arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/api/ArquillianContext.java	2010-04-30 14:35:18 UTC (rev 4342)
+++ arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/api/ArquillianContext.java	2010-05-01 02:13:27 UTC (rev 4343)
@@ -64,4 +64,22 @@
     */
    <T> T get(Class<T> type, Map<String, Object> properties) throws IllegalArgumentException;
 
+   /**
+    * Obtains an instance of the requested type from Arquillian
+    * or the underlying target container.  The supplied properties
+    * may be used to define additional context used to resolve
+    * the correct instance to be returned: for instance @EJB injection
+    * by type may also require a beanName to be deterministic.  This method is 
+    * functionally equivalent to {@link ArquillianContext#get(Class, Map)}
+    * where the supplied properties are converted to a {@link Map} view.
+    * 
+    * @return An instance of the type requested, or null if none is supported
+    *   by the container for the given arguments
+    * @param type The type of object to be returned from the container
+    * @param properties Additional context used to determine object resolution.
+    *   The keys and values contained herein may be container-specific
+    * @throws IllegalArgumentException If either argument is not specified
+    */
+   <T> T get(Class<T> type, Properties properties) throws IllegalArgumentException;
+
 }

Added: arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/api/Properties.java
===================================================================
--- arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/api/Properties.java	                        (rev 0)
+++ arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/api/Properties.java	2010-05-01 02:13:27 UTC (rev 4343)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ *
+ * Licensed 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.jboss.arquillian.prototyping.context.api;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.util.Map;
+
+/**
+ * Container for holding an array of {@link Property}
+ * annotations; together comprises the annotated equivalent
+ * of a {@link Map} structure,
+ *  
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target(
+{ElementType.FIELD, ElementType.METHOD})
+ at Documented
+public @interface Properties {
+
+   //-------------------------------------------------------------------------------------||
+   // Fields -----------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Combined properties
+    * @return
+    */
+   Property[] value();
+
+}

Added: arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/api/Property.java
===================================================================
--- arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/api/Property.java	                        (rev 0)
+++ arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/api/Property.java	2010-05-01 02:13:27 UTC (rev 4343)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ *
+ * Licensed 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.jboss.arquillian.prototyping.context.api;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Represents a contextual property with key / value
+ * pair used to bolster type-specific resolution with some additional
+ * metadata.
+ *  
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target(
+{ElementType.FIELD, ElementType.METHOD})
+ at Documented
+public @interface Property {
+
+   //-------------------------------------------------------------------------------------||
+   // Fields -----------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * The key of this property
+    * @return
+    */
+   String key() default "";
+
+   /**
+    * The value of this property
+    * @return
+    */
+   String value() default "";
+
+}

Modified: arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/impl/BaseContext.java
===================================================================
--- arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/impl/BaseContext.java	2010-04-30 14:35:18 UTC (rev 4342)
+++ arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/impl/BaseContext.java	2010-05-01 02:13:27 UTC (rev 4343)
@@ -17,9 +17,12 @@
 package org.jboss.arquillian.prototyping.context.impl;
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
 
 import org.jboss.arquillian.prototyping.context.api.ArquillianContext;
+import org.jboss.arquillian.prototyping.context.api.Properties;
+import org.jboss.arquillian.prototyping.context.api.Property;
 
 /**
  * Base for implementations of {@link ArquillianContext}.
@@ -46,4 +49,28 @@
       return this.get(type, properties);
    }
 
+   /**
+    * @see org.jboss.arquillian.prototyping.context.api.ArquillianContext#get(java.lang.Class,org.jboss.arquillian.prototyping.context.api.Properties)
+    */
+   @Override
+   public <T> T get(final Class<T> type, final Properties properties) throws IllegalArgumentException
+   {
+      // Precondition checks
+      if (properties == null)
+      {
+         throw new IllegalArgumentException("properties must be specified");
+      }
+      // The class argument will be checked for null when delegated
+
+      // Map properties to a java.util.Map
+      final Map<String, Object> map = new HashMap<String, Object>();
+      for (final Property property : properties.value())
+      {
+         map.put(property.key(), property.value());
+      }
+
+      // Delegate
+      return this.get(type, map);
+   }
+
 }

Modified: arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/impl/BaseContextualResolver.java
===================================================================
--- arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/impl/BaseContextualResolver.java	2010-04-30 14:35:18 UTC (rev 4342)
+++ arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/impl/BaseContextualResolver.java	2010-05-01 02:13:27 UTC (rev 4343)
@@ -17,8 +17,11 @@
 package org.jboss.arquillian.prototyping.context.impl;
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
 
+import org.jboss.arquillian.prototyping.context.api.Properties;
+import org.jboss.arquillian.prototyping.context.api.Property;
 import org.jboss.arquillian.prototyping.context.spi.ContextualResolver;
 
 /**
@@ -37,12 +40,37 @@
 
    /**
     * {@inheritDoc}
-    * @see org.jboss.arquillian.prototyping.context.spi.ContextualResolver#get(java.lang.Class)
+    * @see org.jboss.arquillian.prototyping.context.spi.ContextualResolver#resolve(java.lang.Class)
     */
    @Override
-   public <T> T get(final Class<T> type) throws IllegalArgumentException
+   public <T> T resolve(final Class<T> type) throws IllegalArgumentException
    {
       final Map<String, Object> properties = Collections.emptyMap();
       return this.resolve(type, properties);
    }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.arquillian.prototyping.context.spi.ContextualResolver#resolve(java.lang.Class, org.jboss.arquillian.prototyping.context.api.Properties)
+    */
+   @Override
+   public <T> T resolve(final Class<T> type, final Properties properties) throws IllegalArgumentException
+   {
+      // Precondition checks
+      if (properties == null)
+      {
+         throw new IllegalArgumentException("properties must be specified");
+      }
+      // The class argument will be checked for null when delegated
+
+      // Map properties to a java.util.Map
+      final Map<String, Object> map = new HashMap<String, Object>();
+      for (final Property property : properties.value())
+      {
+         map.put(property.key(), property.value());
+      }
+
+      // Delegate
+      return this.resolve(type, map);
+   }
 }

Added: arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/impl/PropertiesImpl.java
===================================================================
--- arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/impl/PropertiesImpl.java	                        (rev 0)
+++ arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/impl/PropertiesImpl.java	2010-05-01 02:13:27 UTC (rev 4343)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ *
+ * Licensed 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.jboss.arquillian.prototyping.context.impl;
+
+import java.lang.annotation.Annotation;
+import java.util.Map;
+
+import org.jboss.arquillian.prototyping.context.api.Properties;
+import org.jboss.arquillian.prototyping.context.api.Property;
+
+/**
+ * Value object metadata view by which {@link Properties}
+ * may be represented.  Conceptually, a {@link Map} of key/value
+ * pairs.  Immutable after construction.
+ * 
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at SuppressWarnings("all")
+// Shh, we're gonna implement an annotation if we want to
+public class PropertiesImpl implements Properties
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * The properties
+    */
+   private final Property[] properties;
+
+   //-------------------------------------------------------------------------------------||
+   // Constructor ------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Constructs a new instance with the specified, required
+    * properties
+    * 
+    * @param key
+    * @param value
+    * @throws IllegalArgumentException If the properties argument is null
+    */
+   public PropertiesImpl(final Property[] properties) throws IllegalArgumentException
+   {
+      // Precondition checks
+      if (properties == null)
+      {
+         throw new IllegalArgumentException("properties must be specified");
+      }
+
+      // Defensive copy on set
+      this.properties = this.copy(properties);
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Required Implementations -----------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.arquillian.prototyping.context.api.Properties#value()
+    */
+   @Override
+   public Property[] value()
+   {
+      // Return a copy so we can't be altered
+      return this.copy(properties);
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see java.lang.annotation.Annotation#annotationType()
+    */
+   @Override
+   public Class<? extends Annotation> annotationType()
+   {
+      return Properties.class;
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Internal Helper Methods ------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Returns a copy of the specified array
+    */
+   private Property[] copy(final Property[] source)
+   {
+      assert source != null : "source must be specified";
+      final int length = source.length;
+      final Property[] copy = new Property[length];
+      System.arraycopy(source, 0, copy, 0, length);
+      return copy;
+   }
+
+}

Added: arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/impl/PropertyImpl.java
===================================================================
--- arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/impl/PropertyImpl.java	                        (rev 0)
+++ arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/impl/PropertyImpl.java	2010-05-01 02:13:27 UTC (rev 4343)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ *
+ * Licensed 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.jboss.arquillian.prototyping.context.impl;
+
+import java.lang.annotation.Annotation;
+
+import org.jboss.arquillian.prototyping.context.api.Property;
+
+/**
+ * Value object metadata view by which {@link Property}
+ * may be represented.  A contextual key/value property
+ * implementation.  Immutable after construction.
+ * 
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at SuppressWarnings("all")
+// Shh, we're gonna implement an annotation if we want to
+public class PropertyImpl implements Property
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * The key
+    */
+   private final String key;
+
+   /**
+    * The value
+    */
+   private final String value;
+
+   //-------------------------------------------------------------------------------------||
+   // Constructor ------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Constructs a new instance with the specified, required
+    * key and value
+    * 
+    * @param key
+    * @param value
+    * @throws IllegalArgumentException If either argument is null or empty
+    */
+   public PropertyImpl(final String key, final String value) throws IllegalArgumentException
+   {
+      // Precondition checks
+      if (key == null || key.length() == 0)
+      {
+         throw new IllegalArgumentException("key must be specified and not empty");
+      }
+      if (value == null || value.length() == 0)
+      {
+         throw new IllegalArgumentException("value must be specified and not empty");
+      }
+
+      // Set
+      this.key = key;
+      this.value = value;
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Required Implementations -----------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.arquillian.prototyping.context.api.Property#key()
+    */
+   @Override
+   public String key()
+   {
+      return key;
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.arquillian.prototyping.context.api.Property#value()
+    */
+   @Override
+   public String value()
+   {
+      return value;
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see java.lang.annotation.Annotation#annotationType()
+    */
+   @Override
+   public Class<? extends Annotation> annotationType()
+   {
+      return Property.class;
+   }
+
+}

Modified: arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/spi/ContextualResolver.java
===================================================================
--- arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/spi/ContextualResolver.java	2010-04-30 14:35:18 UTC (rev 4342)
+++ arquillian/trunk/containers/openejb/src/main/java/org/jboss/arquillian/prototyping/context/spi/ContextualResolver.java	2010-05-01 02:13:27 UTC (rev 4343)
@@ -18,6 +18,8 @@
 
 import java.util.Map;
 
+import org.jboss.arquillian.prototyping.context.api.Properties;
+
 /**
  * An entity capable of resolving a given type and
  * optional contextual properties to an implementation
@@ -47,7 +49,7 @@
     * @param type The type of object to be returned from the container
     * @throws IllegalArgumentException If the type if not specified
     */
-   <T> T get(Class<T> type) throws IllegalArgumentException;
+   <T> T resolve(Class<T> type) throws IllegalArgumentException;
 
    /**
     * Obtains an instance of the requested type from Arquillian
@@ -65,4 +67,22 @@
     */
    <T> T resolve(Class<T> type, Map<String, Object> properties) throws IllegalArgumentException;
 
+   /**
+    * Obtains an instance of the requested type from Arquillian
+    * or the underlying target container.  The supplied properties
+    * may be used to define additional context used to resolve
+    * the correct instance to be returned: for instance @EJB injection
+    * by type may also require a beanName to be deterministic.  This method is 
+    * functionally equivalent to {@link ContextualResolver#resolve(Class, Map)}
+    * where the supplied properties are converted to a {@link Map} view.
+    * 
+    * @return An instance of the type requested, or null if none is supported
+    *   by the container for the given arguments
+    * @param type The type of object to be returned from the container
+    * @param properties Additional context used to determine object resolution.
+    *   The keys and values contained herein may be container-specific
+    * @throws IllegalArgumentException If either argument is not specified
+    */
+   <T> T resolve(Class<T> type, Properties properties) throws IllegalArgumentException;
+
 }

Modified: arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/openejb/ejb/EchoBean.java
===================================================================
--- arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/openejb/ejb/EchoBean.java	2010-04-30 14:35:18 UTC (rev 4342)
+++ arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/openejb/ejb/EchoBean.java	2010-05-01 02:13:27 UTC (rev 4343)
@@ -16,8 +16,13 @@
  */
 package org.jboss.arquillian.openejb.ejb;
 
+import javax.annotation.Resource;
+import javax.annotation.security.DeclareRoles;
+import javax.annotation.security.PermitAll;
+import javax.annotation.security.RolesAllowed;
 import javax.ejb.Local;
-import javax.ejb.Stateless;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateful;
 
 /**
  * Implementation class of an EJB which returns request parameters
@@ -25,14 +30,49 @@
  * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
  * @version $Revision: $
  */
- at Stateless
+ at Stateful
 @Local(EchoLocalBusiness.class)
+ at RolesAllowed(
+{})
+ at DeclareRoles(
+{EchoBean.ROLE_ADMIN, "another"})
 public class EchoBean implements EchoLocalBusiness
 {
    //-------------------------------------------------------------------------------------||
+   // Constants --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Admin role
+    */
+   public static final String ROLE_ADMIN = "Administrator";
+
+   @Resource
+   private SessionContext context;
+
+   //-------------------------------------------------------------------------------------||
    // Required Implementations -----------------------------------------------------------||
    //-------------------------------------------------------------------------------------||
-   
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.arquillian.openejb.ejb.EchoLocalBusiness#securedEcho(java.lang.String)
+    */
+   @RolesAllowed(
+   {ROLE_ADMIN})
+   @Override
+   public String securedEcho(final String value)
+   {
+      System.out.println(context.getCallerPrincipal().getName());
+      return this.echo(value);
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.arquillian.openejb.ejb.EchoLocalBusiness#echo(java.lang.String)
+    */
+   @Override
+   @PermitAll
    public String echo(final String value)
    {
       return value;

Modified: arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/openejb/ejb/EchoLocalBusiness.java
===================================================================
--- arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/openejb/ejb/EchoLocalBusiness.java	2010-04-30 14:35:18 UTC (rev 4342)
+++ arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/openejb/ejb/EchoLocalBusiness.java	2010-05-01 02:13:27 UTC (rev 4343)
@@ -29,9 +29,19 @@
    //-------------------------------------------------------------------------------------||
 
    /**
-    * Returns the specified reference unaltered
+    * Returns the specified reference unaltered.  Anyone, even unauthenticated callers,
+    * may invoke this method
     * @param value
     * @return
     */
    String echo(String value);
+
+   /**
+    * Returns the specified reference unaltered, but
+    * only if the caller has been authenticated and authorized
+    * w/ EJB security
+    * @param value
+    * @return
+    */
+   String securedEcho(String value);
 }

Deleted: arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/prototyping/context/OpenEJBArquillianContextTestCase.java
===================================================================
--- arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/prototyping/context/OpenEJBArquillianContextTestCase.java	2010-04-30 14:35:18 UTC (rev 4342)
+++ arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/prototyping/context/OpenEJBArquillianContextTestCase.java	2010-05-01 02:13:27 UTC (rev 4343)
@@ -1,149 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, 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.
- *
- * Licensed 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.jboss.arquillian.prototyping.context;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Logger;
-
-import javax.inject.Inject;
-import javax.naming.AuthenticationException;
-import javax.naming.Context;
-import javax.naming.NamingException;
-
-import junit.framework.TestCase;
-
-import org.jboss.arquillian.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.openejb.ejb.EchoBean;
-import org.jboss.arquillian.openejb.ejb.EchoLocalBusiness;
-import org.jboss.arquillian.prototyping.context.api.ArquillianContext;
-import org.jboss.arquillian.prototyping.context.api.openejb.OpenEJBArquillianContext;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-/**
- * Tests that integration with the backing container via 
- * {@link OpenEJBArquillianContext} is in place as contracted
- * 
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
- at RunWith(Arquillian.class)
-public class OpenEJBArquillianContextTestCase
-{
-
-   //-------------------------------------------------------------------------------------||
-   // Class Members ----------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Logger
-    */
-   private static final Logger log = Logger.getLogger(OpenEJBArquillianContextTestCase.class.getName());
-
-   /**
-    * JNDI Name that OpenEJB will assign to our deployment
-    */
-   private static final String JNDI_NAME = "EchoBeanLocal";
-
-   //-------------------------------------------------------------------------------------||
-   // Instance Members -------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * TODO: We don't really need a deployment
-    */
-   @Deployment
-   public static JavaArchive createDeployment()
-   {
-      return ShrinkWrap.create("slsb.jar", JavaArchive.class).addClasses(EchoLocalBusiness.class, EchoBean.class);
-   }
-
-   /**
-    * The hook to the ARQ container, and by extension, OpenEJB
-    */
-   @Inject
-   private OpenEJBArquillianContext arquillianContext;
-
-   //-------------------------------------------------------------------------------------||
-   // Tests ------------------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Ensures that we may inject an {@link ArquillianContext}
-    * into the test
-    */
-   @Test
-   public void injectArquillianContext()
-   {
-      Assert.assertNotNull("Arquillian context should have been injected", arquillianContext);
-   }
-
-   /**
-    * Ensures we can get at OpenEJB deployment metadata
-    * from the {@link OpenEJBArquillianContext} 
-    */
-   @Test
-   public void deploymentMetadata()
-   {
-      final String ejbName = arquillianContext.getDeploymentMetadata().ejbJars.get(0).enterpriseBeans.get(0).ejbName;
-      log.info("Got EJB Name: " + ejbName);
-      Assert.assertEquals("Did not obtain correct EJB name from deployment metadata", EchoBean.class.getSimpleName(),
-            ejbName);
-   }
-
-   /**
-    * Ensures we can create an OpenEJB-specific JNDI {@link Context} via the 
-    * {@link OpenEJBArquillianContext} 
-    */
-   @Test
-   public void programmaticNamingContext() throws NamingException
-   {
-      final Context context = arquillianContext.get(Context.class);
-      Assert.assertNotNull("Should be able to look up EJB via naming context obtained from Arquillian context", context
-            .lookup(JNDI_NAME));
-   }
-
-   /**
-    * Ensures we can create an OpenEJB-specific JNDI {@link Context} via the 
-    * {@link OpenEJBArquillianContext} which supports/respects context properties
-    */
-   @Test
-   public void programmaticNamingContextWithProperties() throws NamingException
-   {
-      final Map<String, Object> props = new HashMap<String, Object>();
-      props.put(Context.SECURITY_PRINCIPAL, "testuser");
-      props.put(Context.SECURITY_CREDENTIALS, "testpassword");
-      try
-      {
-         // This should fail on construction, because we haven't a matching user/pass configured in OpenEJB
-         arquillianContext.get(Context.class, props);
-      }
-      catch (final RuntimeException re)
-      {
-         // Validates that the props we passed in were respected when making the naming context
-         Assert.assertEquals(AuthenticationException.class, re.getCause().getClass());
-         return;
-      }
-      TestCase.fail("Should have obtained exception on logging in with bad user/pass config");
-
-   }
-}

Copied: arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/prototyping/context/OpenEJBAuthenticatedJndiContextTestCase.java (from rev 4338, arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/prototyping/context/OpenEJBArquillianContextTestCase.java)
===================================================================
--- arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/prototyping/context/OpenEJBAuthenticatedJndiContextTestCase.java	                        (rev 0)
+++ arquillian/trunk/containers/openejb/src/test/java/org/jboss/arquillian/prototyping/context/OpenEJBAuthenticatedJndiContextTestCase.java	2010-05-01 02:13:27 UTC (rev 4343)
@@ -0,0 +1,128 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ *
+ * Licensed 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.jboss.arquillian.prototyping.context;
+
+import java.util.logging.Logger;
+
+import javax.ejb.EJBAccessException;
+import javax.inject.Inject;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.openejb.ejb.EchoBean;
+import org.jboss.arquillian.openejb.ejb.EchoLocalBusiness;
+import org.jboss.arquillian.prototyping.context.api.Properties;
+import org.jboss.arquillian.prototyping.context.api.Property;
+import org.jboss.arquillian.prototyping.context.api.openejb.OpenEJBArquillianContext;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests that integration with the backing container via 
+ * {@link OpenEJBArquillianContext} is in place as contracted
+ * 
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at RunWith(Arquillian.class)
+public class OpenEJBAuthenticatedJndiContextTestCase
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(OpenEJBAuthenticatedJndiContextTestCase.class.getName());
+
+   /**
+    * JNDI Name that OpenEJB will assign to our deployment
+    */
+   private static final String JNDI_NAME = "EchoBeanLocal";
+
+   /**
+    * User who is in role "Administrator"
+    */
+   private static final String ADMIN_USER_NAME = "admin";
+
+   /**
+    * Password of an admin user
+    */
+   private static final String ADMIN_PASSWORD = "adminPassword";
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Define the SLSB Deployment for this test
+    */
+   @Deployment
+   public static JavaArchive createDeployment()
+   {
+      return ShrinkWrap.create("slsb.jar", JavaArchive.class).addClasses(EchoLocalBusiness.class, EchoBean.class);
+   }
+
+   /**
+    * Here we test typesafe injection coupled with some context properties;
+    * OpenEJB has been configured with security in users.properties and 
+    * groups.properties on the test classpath.  If this doesn't work, we'll either get
+    * an error during injection (during login) or when we try to get at a privileged 
+    * method in the test EJB.
+    */
+   @Properties(
+   {@Property(key = Context.SECURITY_PRINCIPAL, value = ADMIN_USER_NAME),
+         @Property(key = Context.SECURITY_CREDENTIALS, value = ADMIN_PASSWORD)})
+   @Inject
+   private Context namingContext;
+
+   //-------------------------------------------------------------------------------------||
+   // Tests ------------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Ensures that we can invoke upon a bean obtained via a secured logic
+    * and access restricted methods
+    */
+   @Test
+   public void authenticatedInvocation() throws NamingException
+   {
+      // Look up the EJB though the authenticated Context
+      final EchoLocalBusiness bean = (EchoLocalBusiness) namingContext.lookup(JNDI_NAME);
+
+      // Invoke and test
+      final String expected = "Authenticated Invocation";
+      final String actual;
+      try
+      {
+         actual = bean.securedEcho(expected);
+      }
+      catch (final EJBAccessException e)
+      {
+         Assert.fail("Should have been able to access secured method via authenticated JNDI Context, but got: " + e);
+         return;
+      }
+      Assert.assertSame("Value was not as expected", expected, actual);
+   }
+}

Added: arquillian/trunk/containers/openejb/src/test/resources/groups.properties
===================================================================
--- arquillian/trunk/containers/openejb/src/test/resources/groups.properties	                        (rev 0)
+++ arquillian/trunk/containers/openejb/src/test/resources/groups.properties	2010-05-01 02:13:27 UTC (rev 4343)
@@ -0,0 +1,3 @@
+# OpenEJB Roles Configuration
+# Format: Role=Username
+Administrator=admin
\ No newline at end of file

Added: arquillian/trunk/containers/openejb/src/test/resources/users.properties
===================================================================
--- arquillian/trunk/containers/openejb/src/test/resources/users.properties	                        (rev 0)
+++ arquillian/trunk/containers/openejb/src/test/resources/users.properties	2010-05-01 02:13:27 UTC (rev 4343)
@@ -0,0 +1,3 @@
+# OpenEJB Users Configuration
+# Format: Username=Password
+admin=adminPassword
\ No newline at end of file



More information about the jboss-svn-commits mailing list