[jboss-svn-commits] JBoss Common SVN: r4425 - arquillian/trunk/testenrichers/cdi/src/main/java/org/jboss/arquillian/testenricher/cdi.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun May 23 15:45:59 EDT 2010
Author: aslak
Date: 2010-05-23 15:45:58 -0400 (Sun, 23 May 2010)
New Revision: 4425
Added:
arquillian/trunk/testenrichers/cdi/src/main/java/org/jboss/arquillian/testenricher/cdi/MethodParameterInjectionPoint.java
Modified:
arquillian/trunk/testenrichers/cdi/src/main/java/org/jboss/arquillian/testenricher/cdi/CDIInjectionEnricher.java
Log:
ARQ-120 Changed argument injection strategy. Now creates a InjectionPoint for the argument to simulate a real argument injection point.
Modified: arquillian/trunk/testenrichers/cdi/src/main/java/org/jboss/arquillian/testenricher/cdi/CDIInjectionEnricher.java
===================================================================
--- arquillian/trunk/testenrichers/cdi/src/main/java/org/jboss/arquillian/testenricher/cdi/CDIInjectionEnricher.java 2010-05-23 19:32:54 UTC (rev 4424)
+++ arquillian/trunk/testenrichers/cdi/src/main/java/org/jboss/arquillian/testenricher/cdi/CDIInjectionEnricher.java 2010-05-23 19:45:58 UTC (rev 4425)
@@ -16,12 +16,9 @@
*/
package org.jboss.arquillian.testenricher.cdi;
-import java.lang.annotation.Annotation;
-
import java.lang.reflect.Method;
import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.InjectionTarget;
import javax.naming.InitialContext;
@@ -38,7 +35,7 @@
public class CDIInjectionEnricher implements TestEnricher
{
private static final String JNDI_BEAN_MANAGER = "java:comp/BeanManager";
- private static final String JNDI_BEAN_MANAGER_JBOSS = "java:app/BeanManager";
+ private static final String JNDI_BEAN_MANAGER_JBOSS = "java:global/test/arquillian-protocol/BeanManager";
private static final String ANNOTATION_NAME = "javax.inject.Inject";
/* (non-Javadoc)
@@ -65,24 +62,22 @@
{
return values;
}
- Annotation[][] parameterAnnotations = method.getParameterAnnotations();
Class<?>[] parameterTypes = method.getParameterTypes();
for(int i = 0; i < parameterTypes.length; i++)
{
- Class<?> parameterType = parameterTypes[i];
- Annotation[] parameterAnnotation = parameterAnnotations[i];
- values[i] = getInstanceByType(beanManager, parameterType, parameterAnnotation);
+ values[i] = getInstanceByType(beanManager, i, method);
}
}
return values;
}
@SuppressWarnings("unchecked")
- private <T> T getInstanceByType(BeanManager manager, Class<T> type, Annotation... bindings)
+ private <T> T getInstanceByType(BeanManager manager, final int position, final Method method)
{
- final Bean<?> bean = manager.resolve(manager.getBeans(type, bindings));
CreationalContext<?> cc = manager.createCreationalContext(null);
- return (T) manager.getReference(bean, type, cc);
+ return (T)manager.getInjectableReference(
+ new MethodParameterInjectionPoint<T>(method, position),
+ cc);
}
protected void injectClass(Context context, Object testCase)
Added: arquillian/trunk/testenrichers/cdi/src/main/java/org/jboss/arquillian/testenricher/cdi/MethodParameterInjectionPoint.java
===================================================================
--- arquillian/trunk/testenrichers/cdi/src/main/java/org/jboss/arquillian/testenricher/cdi/MethodParameterInjectionPoint.java (rev 0)
+++ arquillian/trunk/testenrichers/cdi/src/main/java/org/jboss/arquillian/testenricher/cdi/MethodParameterInjectionPoint.java 2010-05-23 19:45:58 UTC (rev 4425)
@@ -0,0 +1,174 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.testenricher.cdi;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.AnnotatedCallable;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+/**
+ * MethodParameterInjectionPoint
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class MethodParameterInjectionPoint<T> implements InjectionPoint
+{
+ private Method method;
+ private int position;
+
+ public MethodParameterInjectionPoint(Method method, int position)
+ {
+ this.method = method;
+ this.position = position;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.InjectionPoint#getBean()
+ */
+ public Bean<?> getBean()
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.InjectionPoint#getMember()
+ */
+ public Member getMember()
+ {
+ return method;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.InjectionPoint#getQualifiers()
+ */
+ public Set<Annotation> getQualifiers()
+ {
+ return new HashSet<Annotation>(
+ Arrays.asList(method.getParameterAnnotations()[position]));
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.InjectionPoint#getType()
+ */
+ public Type getType()
+ {
+ return method.getParameterTypes()[position];
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.InjectionPoint#isDelegate()
+ */
+ public boolean isDelegate()
+ {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.InjectionPoint#isTransient()
+ */
+ public boolean isTransient()
+ {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.InjectionPoint#getAnnotated()
+ */
+ public Annotated getAnnotated()
+ {
+ return new ArgumentAnnotated<T>();
+ }
+
+ private class ArgumentAnnotated<X> implements AnnotatedParameter<X> {
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.AnnotatedParameter#getDeclaringCallable()
+ */
+ public AnnotatedCallable<X> getDeclaringCallable()
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.AnnotatedParameter#getPosition()
+ */
+ public int getPosition()
+ {
+ return position;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.Annotated#getAnnotation(java.lang.Class)
+ */
+ public <Y extends Annotation> Y getAnnotation(Class<Y> annotationType)
+ {
+ for(Annotation annotation : method.getParameterAnnotations()[position])
+ {
+ if(annotation.annotationType() == annotationType)
+ {
+ return annotationType.cast(annotation);
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.Annotated#getAnnotations()
+ */
+ public Set<Annotation> getAnnotations()
+ {
+ return getQualifiers();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.Annotated#getBaseType()
+ */
+ // TODO: what is the BaseType ?
+ public Type getBaseType()
+ {
+ return method.getParameterTypes()[position];
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.Annotated#getTypeClosure()
+ */
+ // TODO: what is the TypeClosure ?
+ public Set<Type> getTypeClosure()
+ {
+ return new HashSet<Type>(Arrays.asList(getBaseType()));
+ }
+
+ /* (non-Javadoc)
+ * @see javax.enterprise.inject.spi.Annotated#isAnnotationPresent(java.lang.Class)
+ */
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+ {
+ return getAnnotation(annotationType) != null;
+ }
+ }
+}
More information about the jboss-svn-commits
mailing list