wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r995608 [1/2] - in /incubator/wink/trunk: ./ wink-common/src/main/resources/org/apache/wink/common/internal/i18n/ wink-jcdi-server/ wink-jcdi-server/src/ wink-jcdi-server/src/main/ wink-jcdi-server/src/main/java/ wink-jcdi-server/src/main/j...
Date Thu, 09 Sep 2010 23:14:48 GMT
Author: bluk
Date: Thu Sep  9 23:14:47 2010
New Revision: 995608

URL: http://svn.apache.org/viewvc?rev=995608&view=rev
Log:
Add JCDI extension support for Wink

Allows Apache Wink to use JCDI managed beans
as root resources, providers, and
Applciation sub-classes.

See [WINK-287]

Added:
    incubator/wink/trunk/wink-jcdi-server/
    incubator/wink/trunk/wink-jcdi-server/pom.xml
    incubator/wink/trunk/wink-jcdi-server/src/
    incubator/wink/trunk/wink-jcdi-server/src/main/
    incubator/wink/trunk/wink-jcdi-server/src/main/java/
    incubator/wink/trunk/wink-jcdi-server/src/main/java/org/
    incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/
    incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/
    incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/
    incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/
    incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/
    incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/JCDIRestServlet.java
    incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/extension/
    incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/extension/JAXRSJCDICustomInjectionTarget.java
    incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/extension/JCDIDeploymentConfiguration.java
    incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/extension/JCDIExtension.java
    incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/lifecycle/
    incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDIDefaultObjectFactory.java
    incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDILifecycleManager.java
    incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDISingletonObjectFactory.java
    incubator/wink/trunk/wink-jcdi-server/src/main/resources/
    incubator/wink/trunk/wink-jcdi-server/src/main/resources/META-INF/
    incubator/wink/trunk/wink-jcdi-server/src/main/resources/META-INF/services/
    incubator/wink/trunk/wink-jcdi-server/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
    incubator/wink/trunk/wink-jcdi-server/src/test/
    incubator/wink/trunk/wink-jcdi-server/src/test/java/
    incubator/wink/trunk/wink-jcdi-server/src/test/java/org/
    incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/
    incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/
    incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/
    incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/
    incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/
    incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/extension/
    incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/extension/JAXRSJCDICustomInjectionTargetTest.java
    incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/extension/JAXRSJCDIExtensionTest.java
    incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/lifecycle/
    incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDIDefaultObjectFactoryTest.java
    incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDILifecycleManagerTest.java
    incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDISingletonObjectFactoryTest.java
Modified:
    incubator/wink/trunk/pom.xml
    incubator/wink/trunk/wink-common/src/main/resources/org/apache/wink/common/internal/i18n/resource.properties

Modified: incubator/wink/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/pom.xml?rev=995608&r1=995607&r2=995608&view=diff
==============================================================================
--- incubator/wink/trunk/pom.xml (original)
+++ incubator/wink/trunk/pom.xml Thu Sep  9 23:14:47 2010
@@ -45,6 +45,7 @@
         <module>wink-spring-support</module>
         <module>wink-webdav</module>
         <module>wink-providers</module>
+        <module>wink-jcdi-server</module>
         <module>wink-guice-server</module>
         <module>wink-examples</module>
         <module>wink-assembly</module>

Modified: incubator/wink/trunk/wink-common/src/main/resources/org/apache/wink/common/internal/i18n/resource.properties
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/resources/org/apache/wink/common/internal/i18n/resource.properties?rev=995608&r1=995607&r2=995608&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/resources/org/apache/wink/common/internal/i18n/resource.properties (original)
+++ incubator/wink/trunk/wink-common/src/main/resources/org/apache/wink/common/internal/i18n/resource.properties Thu Sep  9 23:14:47 2010
@@ -222,3 +222,6 @@ followingProvidersUserDefined=The follow
 applicationProcessed=The following application has been processed: {0}
 multipleHttpMethodAnnotations=Multiple http method annotations on method {0} in class {1}
 resourceMethodMoreThanOneEntityParam=The {0} method has more than one entity parameter. You must use only one entity parameter.
+exceptionDuringInjection=Exception encountered during JCDI injection
+couldNotFindBeanManager=Could not find BeanManager.
+jcdiSingletonObjectFactoryCannotInstantiateInstance=Cannot create an instance of the JCDI managed bean class {0}.  Verify that the bean is a singleton or is annotated with @javax.enterprise.context.ApplicationScoped.

Added: incubator/wink/trunk/wink-jcdi-server/pom.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-jcdi-server/pom.xml?rev=995608&view=auto
==============================================================================
--- incubator/wink/trunk/wink-jcdi-server/pom.xml (added)
+++ incubator/wink/trunk/wink-jcdi-server/pom.xml Thu Sep  9 23:14:47 2010
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>wink</artifactId>
+        <groupId>org.apache.wink</groupId>
+        <version>1.1.2-incubating-SNAPSHOT</version>
+    </parent>
+    <groupId>org.apache.wink</groupId>
+    <artifactId>wink-jcdi-server</artifactId>
+    <name>Apache Wink :: JCDI Extensions and Integration</name>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jcdi_1.0_spec</artifactId>
+            <version>1.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-atinject_1.0_spec</artifactId>
+            <version>1.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-servlet_3.0_spec</artifactId>
+            <scope>provided</scope>
+            <version>1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.wink</groupId>
+            <artifactId>wink-server</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.faces</groupId>
+            <artifactId>jsf-api</artifactId>
+            <scope>provided</scope>
+            <version>1.2_02</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-interceptor_1.1_spec</artifactId>
+            <scope>provided</scope>
+            <version>1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-el_2.2_spec</artifactId>
+            <scope>provided</scope>
+            <version>1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-annotation_1.1_spec</artifactId>
+            <scope>provided</scope>
+            <version>1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jmock</groupId>
+            <artifactId>jmock-junit3</artifactId>
+            <version>2.5.1</version>
+            <scope>test</scope>
+        </dependency>
+       <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-jdk14</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>

Added: incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/JCDIRestServlet.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/JCDIRestServlet.java?rev=995608&view=auto
==============================================================================
--- incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/JCDIRestServlet.java (added)
+++ incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/JCDIRestServlet.java Thu Sep  9 23:14:47 2010
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.wink.jcdi.server.internal;
+
+import org.apache.wink.common.internal.i18n.Messages;
+import org.apache.wink.common.internal.utils.ClassUtils;
+import org.apache.wink.jcdi.server.internal.extension.JCDIDeploymentConfiguration;
+import org.apache.wink.server.internal.DeploymentConfiguration;
+import org.apache.wink.server.internal.servlet.RestServlet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JCDIRestServlet extends RestServlet {
+
+    private static final String DEPLOYMENT_CONF_PARAM = "deploymentConfiguration";
+
+    private static final Logger logger               =
+                                                         LoggerFactory
+                                                             .getLogger(JCDIRestServlet.class);
+
+    private static final long   serialVersionUID     = -1920970727031271538L;
+
+    @Override
+    protected DeploymentConfiguration createDeploymentConfiguration()
+        throws ClassNotFoundException, InstantiationException, IllegalAccessException {
+        String initParameter = getInitParameter(DEPLOYMENT_CONF_PARAM);
+        if (initParameter != null) {
+            logger.info(Messages.getMessage("restServletUseDeploymentConfigurationParam",
+                        initParameter,
+                        DEPLOYMENT_CONF_PARAM));
+            // use ClassUtils.loadClass instead of Class.forName so we have
+            // classloader visibility into the Web module in J2EE environments
+            Class<?> confClass = ClassUtils.loadClass(initParameter);
+            return (DeploymentConfiguration)confClass.newInstance();
+        }
+        return new JCDIDeploymentConfiguration();
+    }
+
+}

Added: incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/extension/JAXRSJCDICustomInjectionTarget.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/extension/JAXRSJCDICustomInjectionTarget.java?rev=995608&view=auto
==============================================================================
--- incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/extension/JAXRSJCDICustomInjectionTarget.java (added)
+++ incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/extension/JAXRSJCDICustomInjectionTarget.java Thu Sep  9 23:14:47 2010
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.wink.jcdi.server.internal.extension;
+
+import java.io.IOException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+import org.apache.wink.common.internal.i18n.Messages;
+import org.apache.wink.common.internal.lifecycle.CreationUtils;
+import org.apache.wink.common.internal.registry.metadata.ApplicationMetadataCollector;
+import org.apache.wink.common.internal.registry.metadata.ClassMetadata;
+import org.apache.wink.common.internal.registry.metadata.ProviderMetadataCollector;
+import org.apache.wink.common.internal.registry.metadata.ResourceMetadataCollector;
+import org.apache.wink.common.internal.runtime.RuntimeContextTLS;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JAXRSJCDICustomInjectionTarget<T> implements InjectionTarget<T> {
+
+    private static final Logger      logger =
+                                                LoggerFactory
+                                                    .getLogger(JAXRSJCDICustomInjectionTarget.class);
+
+    private ClassMetadata            classMetadata;
+
+    final private InjectionTarget<T> delegate;
+
+    static <T> ClassMetadata collectClassMetadata(final Class<T> cls) {
+        ClassMetadata classMetadata = null;
+        if (ProviderMetadataCollector.isProvider(cls)) {
+            classMetadata = ProviderMetadataCollector.collectMetadata(cls);
+        } else if (ResourceMetadataCollector.isResource(cls)) {
+            classMetadata = ResourceMetadataCollector.collectMetadata(cls);
+        } else if (ApplicationMetadataCollector.isApplication(cls)) {
+            classMetadata = ApplicationMetadataCollector.collectMetadata(cls);
+        }
+        return classMetadata;
+    }
+
+    public JAXRSJCDICustomInjectionTarget(InjectionTarget<T> delegate) {
+        logger.trace("constructor({}) entry", delegate);
+        this.delegate = delegate;
+        logger.trace("constructor() exit");
+    }
+
+    public void inject(final T instance, final CreationalContext<T> creationalContext) {
+        logger.trace("inject({}, {}) entry", instance, creationalContext);
+        try {
+            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+
+                public Object run() throws PrivilegedActionException {
+                    if (classMetadata == null) {
+                        logger.trace("Collecting classMetadata for {}", this);
+                        classMetadata = collectClassMetadata(instance.getClass());
+                    }
+                    logger.trace("Calling CreationUtils.injectFields for instance");
+                    try {
+                        CreationUtils.injectFields(instance, classMetadata, RuntimeContextTLS
+                            .getRuntimeContext());
+                    } catch (IOException e) {
+                        throw new PrivilegedActionException(e);
+                    }
+                    return null;
+                }
+            });
+        } catch (Exception e) {
+            logger.warn(Messages.getMessage("exceptionDuringInjection"), e);
+        }
+
+        logger.trace("calling delegate.inject(instance, creationalContext)");
+        delegate.inject(instance, creationalContext);
+        logger.trace("inject() exit");
+    }
+
+    public void postConstruct(T instance) {
+        delegate.postConstruct(instance);
+    }
+
+    public void preDestroy(T instance) {
+        delegate.preDestroy(instance);
+    }
+
+    public void dispose(T instance) {
+        delegate.dispose(instance);
+    }
+
+    public Set<InjectionPoint> getInjectionPoints() {
+        return delegate.getInjectionPoints();
+    }
+
+    public T produce(CreationalContext<T> creationalContext) {
+        return delegate.produce(creationalContext);
+    }
+}

Added: incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/extension/JCDIDeploymentConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/extension/JCDIDeploymentConfiguration.java?rev=995608&view=auto
==============================================================================
--- incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/extension/JCDIDeploymentConfiguration.java (added)
+++ incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/extension/JCDIDeploymentConfiguration.java Thu Sep  9 23:14:47 2010
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.wink.jcdi.server.internal.extension;
+
+import org.apache.wink.common.internal.lifecycle.LifecycleManagersRegistry;
+import org.apache.wink.jcdi.server.internal.lifecycle.JCDILifecycleManager;
+import org.apache.wink.server.internal.DeploymentConfiguration;
+
+public class JCDIDeploymentConfiguration extends DeploymentConfiguration {
+
+    @SuppressWarnings("unchecked")
+    public JCDIDeploymentConfiguration() {
+        LifecycleManagersRegistry lifecycleManagersRegistry = new LifecycleManagersRegistry();
+        setOfFactoryRegistry(lifecycleManagersRegistry);
+        lifecycleManagersRegistry.addFactoryFactory(new JCDILifecycleManager());
+    }
+}

Added: incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/extension/JCDIExtension.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/extension/JCDIExtension.java?rev=995608&view=auto
==============================================================================
--- incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/extension/JCDIExtension.java (added)
+++ incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/extension/JCDIExtension.java Thu Sep  9 23:14:47 2010
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.wink.jcdi.server.internal.extension;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessInjectionTarget;
+
+import org.apache.wink.common.internal.registry.metadata.ApplicationMetadataCollector;
+import org.apache.wink.common.internal.registry.metadata.ProviderMetadataCollector;
+import org.apache.wink.common.internal.registry.metadata.ResourceMetadataCollector;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JCDIExtension implements Extension {
+
+    private static final Logger logger = LoggerFactory.getLogger(JCDIExtension.class);
+
+    public <T> void observeProcessInjectionTarget(@Observes ProcessInjectionTarget<T> pij) {
+        logger.trace("observeProcessInjectionTarget({}) entry", pij);
+        if (isJAXRSBean(pij.getAnnotatedType().getJavaClass())) {
+            logger.trace("Was JAX-RS annotated class so changing the injection target");
+            pij.setInjectionTarget(new JAXRSJCDICustomInjectionTarget<T>(pij.getInjectionTarget()));
+        }
+        logger.trace("observeProcessInjectionTarget() exit");
+    }
+
+    static boolean isJAXRSBean(final Class<?> cls) {
+        if (logger.isTraceEnabled()) {
+            logger.trace("isJAXRSBean({}) entry", cls.getName());
+        }
+        boolean result = false;
+        if (ProviderMetadataCollector.isProvider(cls)) {
+            result = true;
+        } else if (ResourceMetadataCollector.isResource(cls)) {
+            result = true;
+        } else if (ApplicationMetadataCollector.isApplication(cls)) {
+            result = true;
+        }
+        if (logger.isTraceEnabled()) {
+            logger.trace("isJAXRSBean({}) exit", result);
+        }
+        return result;
+    }
+
+}

Added: incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDIDefaultObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDIDefaultObjectFactory.java?rev=995608&view=auto
==============================================================================
--- incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDIDefaultObjectFactory.java (added)
+++ incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDIDefaultObjectFactory.java Thu Sep  9 23:14:47 2010
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.wink.jcdi.server.internal.lifecycle;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.IdentityHashMap;
+import java.util.List;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.apache.wink.common.RuntimeContext;
+import org.apache.wink.common.internal.lifecycle.ObjectFactory;
+
+public class JCDIDefaultObjectFactory<T> implements ObjectFactory<T> {
+
+    final private Class<T>                           clazz;
+    final private BeanManager                        beanManager;
+    private Bean<?>                                  theBean;
+    private IdentityHashMap<T, CreationalContext<T>> creationalContextMap;
+
+    public JCDIDefaultObjectFactory(Class<T> c, BeanManager beanManager) {
+        this.clazz = c;
+        this.beanManager = beanManager;
+        // this.creationalContextMap = new IdentityHashMap<T,
+        // CreationalContext<T>>();
+        theBean = null;
+    }
+
+    /* package */IdentityHashMap<T, CreationalContext<T>> getCreationalContextMap() {
+        return creationalContextMap;
+    }
+
+    @SuppressWarnings("unchecked")
+    public T getInstance(RuntimeContext context) {
+        if (theBean == null) {
+            // cache the Bean object
+            Annotation[] annotations = clazz.getAnnotations();
+            List<Annotation> qualifierAnnotations = new ArrayList<Annotation>(1);
+            for (Annotation a : annotations) {
+                if (beanManager.isQualifier(a.annotationType())) {
+                    qualifierAnnotations.add(a);
+                }
+            }
+            Set<Bean<?>> beans =
+                beanManager.getBeans(clazz, qualifierAnnotations.toArray(new Annotation[0]));
+            theBean = beans.iterator().next();
+        }
+
+        /*
+         * need a new CreationalContext every "new" instance and use it to get
+         * the bean instance
+         */
+        CreationalContext<?> creationalContext = beanManager.createCreationalContext(theBean);
+        T instance = (T)beanManager.getReference(theBean, clazz, creationalContext);
+
+        /*
+         * if there is a context, this is during a request. if context is null,
+         * this is during application scoped. store the CreationalContext to
+         * release it later.
+         */
+        if (context != null) {
+            context.setAttribute(CreationalContext.class, creationalContext);
+        } else {
+            /*
+             * be sure to synchronize on the off chance this is run concurrently
+             * (in normal operation, the application scoped instances are
+             * created sequentially but that could change
+             */
+            synchronized (this) {
+                if (creationalContextMap == null) {
+                    creationalContextMap = new IdentityHashMap<T, CreationalContext<T>>();
+                }
+                creationalContextMap.put(instance, (CreationalContext<T>)creationalContext);
+            }
+        }
+        return instance;
+    }
+
+    public Class<T> getInstanceClass() {
+        return clazz;
+    }
+
+    public void releaseAll(RuntimeContext context) {
+        synchronized (this) {
+            if (creationalContextMap != null) {
+                for (CreationalContext<T> c : creationalContextMap.values()) {
+                    c.release();
+                }
+                creationalContextMap = null;
+            }
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public void releaseInstance(T instance, RuntimeContext context) {
+        if (context != null) {
+            CreationalContext<T> creationalContext =
+                (CreationalContext<T>)context.getAttributes().remove(CreationalContext.class
+                    .getName());
+            if (creationalContext != null) {
+                creationalContext.release();
+            }
+        }
+// /* will this code ever run? */
+//        if (creationalContextMap != null) {
+//            synchronized (creationalContextMap) {
+//                CreationalContext<T> creationalContext =
+//                    (CreationalContext<T>)creationalContextMap.remove(instance);
+//                if (creationalContext != null) {
+//                    creationalContext.release();
+//                }
+//            }
+//        }
+    }
+
+}

Added: incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDILifecycleManager.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDILifecycleManager.java?rev=995608&view=auto
==============================================================================
--- incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDILifecycleManager.java (added)
+++ incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDILifecycleManager.java Thu Sep  9 23:14:47 2010
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.wink.jcdi.server.internal.lifecycle;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.wink.common.internal.i18n.Messages;
+import org.apache.wink.common.internal.lifecycle.LifecycleManager;
+import org.apache.wink.common.internal.lifecycle.ObjectCreationException;
+import org.apache.wink.common.internal.lifecycle.ObjectFactory;
+import org.apache.wink.common.internal.registry.metadata.ApplicationMetadataCollector;
+import org.apache.wink.common.internal.registry.metadata.ProviderMetadataCollector;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JCDILifecycleManager<T> implements LifecycleManager<T> {
+
+    public JCDILifecycleManager() {
+        logger.trace("JCDILifecycleManager created");
+    }
+
+    private static final Logger logger      = LoggerFactory.getLogger(JCDILifecycleManager.class);
+
+    private BeanManager         beanManager = null;
+
+    void setBeanManager(BeanManager beanManager) {
+        this.beanManager = beanManager;
+    }
+
+    BeanManager getBeanManager() {
+        if (beanManager == null) {
+            try {
+                InitialContext initialContext = new InitialContext();
+                beanManager = (BeanManager)initialContext.lookup("java:comp/BeanManager");
+            } catch (NamingException e) {
+                logger.warn(Messages.getMessage("couldNotFindBeanManager"), e);
+            }
+        }
+        return beanManager;
+    }
+
+    public ObjectFactory<T> createObjectFactory(T object) throws ObjectCreationException {
+        logger.trace("createObjectFactory({}) entry", object);
+        if (object == null) {
+            throw new NullPointerException(Messages.getMessage("variableIsNull", "object")); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+        logger.trace("createObjectFactory() exit returning null");
+        return null;
+    }
+
+    public ObjectFactory<T> createObjectFactory(Class<T> cls) throws ObjectCreationException {
+        logger.trace("createObjectFactory({}) entry", cls);
+        if (cls == null) {
+            throw new NullPointerException(Messages.getMessage("variableIsNull", "cls")); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+
+        BeanManager beanManager = getBeanManager();
+        if (isJCDIManagedBean(cls, beanManager)) {
+            if (ProviderMetadataCollector.isProvider(cls) || ApplicationMetadataCollector
+                .isApplication(cls)) {
+                /*
+                 * for providers and application sub-classes, they must be
+                 * singletons, so use a special caching singleton object factory
+                 * for them. also allows error messages to be handled.
+                 */
+                logger.trace("createObjectFactory() returning JCDISingletonObjectFactory");
+                return new JCDISingletonObjectFactory<T>(cls, beanManager);
+            }
+            logger.trace("createObjectFactory() returning JCDIDefaultObjectFactory");
+            return new JCDIDefaultObjectFactory<T>(cls, beanManager);
+        }
+
+        logger.trace("createObjectFactory() returning null");
+        return null;
+    }
+
+    /**
+     * Determines if a class is a JCDI managed bean or not.
+     * 
+     * @param <T>
+     * @param cls
+     * @return true if the class is a JCDI managed bean, false if not
+     */
+    static <T> boolean isJCDIManagedBean(Class<T> cls, BeanManager beanManager) {
+        logger.trace("isJCDIManagedBean({}, {}) entry", cls, beanManager);
+        Annotation[] annotations = cls.getAnnotations();
+        List<Annotation> qualifierAnnotations = new ArrayList<Annotation>(1);
+        for (Annotation a : annotations) {
+            if (beanManager.isQualifier(a.annotationType())) {
+                qualifierAnnotations.add(a);
+            }
+        }
+        logger.trace("Qualifier annotations are {}", qualifierAnnotations);
+        Set<Bean<?>> beans =
+            beanManager.getBeans(cls, qualifierAnnotations.toArray(new Annotation[0]));
+        logger.trace("Beans are {}", beans);
+        if (beans == null || beans.isEmpty()) {
+            logger
+                .debug("{} is NOT a JCDI managed bean.",
+                       cls);
+            logger.trace("isJCDIManagedBean() returning false");
+            return false;
+        }
+        logger.debug("{} is a JCDI managed bean.", cls);
+
+        logger.trace("isJCDIManagedBean() returning true");
+        return true;
+    }
+
+}

Added: incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDISingletonObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDISingletonObjectFactory.java?rev=995608&view=auto
==============================================================================
--- incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDISingletonObjectFactory.java (added)
+++ incubator/wink/trunk/wink-jcdi-server/src/main/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDISingletonObjectFactory.java Thu Sep  9 23:14:47 2010
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.wink.jcdi.server.internal.lifecycle;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.apache.wink.common.RuntimeContext;
+import org.apache.wink.common.internal.i18n.Messages;
+import org.apache.wink.common.internal.lifecycle.ObjectCreationException;
+import org.apache.wink.common.internal.lifecycle.ObjectFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JCDISingletonObjectFactory<T> implements ObjectFactory<T> {
+
+    private final Logger               logger     =
+                                                      LoggerFactory
+                                                          .getLogger(JCDISingletonObjectFactory.class);
+
+    final private T                    instance;
+
+    final private CreationalContext<?> creationalContext;
+
+    private boolean                    isReleased = false;
+
+    @SuppressWarnings("unchecked")
+    public JCDISingletonObjectFactory(Class<T> clazz, BeanManager beanManager) {
+        Annotation[] annotations = clazz.getAnnotations();
+        List<Annotation> qualifierAnnotations = new ArrayList<Annotation>(1);
+        for (Annotation a : annotations) {
+            if (beanManager.isQualifier(a.annotationType())) {
+                qualifierAnnotations.add(a);
+            }
+        }
+        Set<Bean<?>> beans =
+            beanManager.getBeans(clazz, qualifierAnnotations.toArray(new Annotation[0]));
+        Bean theBean = beans.iterator().next();
+
+        creationalContext = beanManager.createCreationalContext(theBean);
+        try {
+            instance = (T)beanManager.getReference(theBean, clazz, creationalContext);
+        } catch (Exception e) {
+            if (logger.isErrorEnabled()) {
+                logger.error(Messages
+                    .getMessage("jcdiSingletonObjectFactoryCannotInstantiateInstance", clazz
+                        .getName()), e);
+            }
+            throw new ObjectCreationException(e);
+        }
+    }
+
+    public T getInstance(RuntimeContext context) {
+        return instance;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Class<T> getInstanceClass() {
+        return (Class<T>)instance.getClass();
+    }
+
+    public void releaseAll(RuntimeContext context) {
+        if (isReleased) {
+            /* already released so return */
+            return;
+        }
+        isReleased = true;
+        if (creationalContext != null) {
+            creationalContext.release();
+
+        }
+    }
+
+    public void releaseInstance(T instance, RuntimeContext context) {
+        /* do nothing */
+    }
+
+}

Added: incubator/wink/trunk/wink-jcdi-server/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-jcdi-server/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension?rev=995608&view=auto
==============================================================================
--- incubator/wink/trunk/wink-jcdi-server/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension (added)
+++ incubator/wink/trunk/wink-jcdi-server/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension Thu Sep  9 23:14:47 2010
@@ -0,0 +1 @@
+org.apache.wink.jcdi.server.internal.extension.JCDIExtension

Added: incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/extension/JAXRSJCDICustomInjectionTargetTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/extension/JAXRSJCDICustomInjectionTargetTest.java?rev=995608&view=auto
==============================================================================
--- incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/extension/JAXRSJCDICustomInjectionTargetTest.java (added)
+++ incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/extension/JAXRSJCDICustomInjectionTargetTest.java Thu Sep  9 23:14:47 2010
@@ -0,0 +1,228 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.wink.jcdi.server.internal.extension;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.Provider;
+
+import junit.framework.TestCase;
+
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+
+@SuppressWarnings("unchecked")
+public class JAXRSJCDICustomInjectionTargetTest extends TestCase {
+
+    private Mockery                                mockContext       = new Mockery();
+    private InjectionTarget<Object>                it                =
+                                                                         mockContext
+                                                                             .mock(InjectionTarget.class);
+    private JAXRSJCDICustomInjectionTarget<Object> jaxrsIT;
+
+    private CreationalContext<Object>              creationalContext =
+                                                                         mockContext
+                                                                             .mock(CreationalContext.class);
+
+    static class JAXRSApplicationClass extends Application {
+        @Context
+        public Request      request;
+
+        private HttpHeaders http;
+
+        @Context
+        public void setHeaders(HttpHeaders headers) {
+            http = headers;
+        }
+
+        public HttpHeaders getHttp() {
+            return http;
+        }
+    }
+
+    @Provider
+    static class JAXRSProviderClass implements MessageBodyReader<Object> {
+
+        @Context
+        public Request      request;
+
+        private HttpHeaders http;
+
+        @Context
+        public void setHeaders(HttpHeaders headers) {
+            http = headers;
+        }
+
+        public HttpHeaders getHttp() {
+            return http;
+        }
+
+        public boolean isReadable(Class<?> type,
+                                  Type genericType,
+                                  Annotation[] annotations,
+                                  MediaType mediaType) {
+            return false;
+        }
+
+        public Object readFrom(Class<Object> type,
+                               Type genericType,
+                               Annotation[] annotations,
+                               MediaType mediaType,
+                               MultivaluedMap<String, String> httpHeaders,
+                               InputStream entityStream) throws IOException {
+            return null;
+        }
+    }
+
+    @Path("/hello")
+    static class JAXRSResourceClass {
+
+        @Context
+        public Request      request;
+
+        private HttpHeaders http;
+
+        @Context
+        public void setHeaders(HttpHeaders headers) {
+            http = headers;
+        }
+
+        public HttpHeaders getHttp() {
+            return http;
+        }
+    }
+
+    public void setUp() {
+        jaxrsIT = new JAXRSJCDICustomInjectionTarget<Object>(it);
+    }
+
+    public void testInjectJAXRSApplication() {
+        final JAXRSApplicationClass jaxrsObj = new JAXRSApplicationClass();
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(it).inject(jaxrsObj, creationalContext);
+            }
+        });
+        jaxrsIT.inject(jaxrsObj, creationalContext);
+        assertNotNull(jaxrsObj.getHttp());
+        assertNotNull(jaxrsObj.request);
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testInjectJAXRSProvider() {
+        final JAXRSProviderClass jaxrsObj = new JAXRSProviderClass();
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(it).inject(jaxrsObj, creationalContext);
+            }
+        });
+        jaxrsIT.inject(jaxrsObj, creationalContext);
+        assertNotNull(jaxrsObj.getHttp());
+        assertNotNull(jaxrsObj.request);
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testInjectJAXRSResource() {
+        final JAXRSResourceClass jaxrsObj = new JAXRSResourceClass();
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(it).inject(jaxrsObj, creationalContext);
+            }
+        });
+        jaxrsIT.inject(jaxrsObj, creationalContext);
+        assertNotNull(jaxrsObj.getHttp());
+        assertNotNull(jaxrsObj.request);
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testPostConstruct() {
+        final Object instance = new Object();
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(it).postConstruct(instance);
+            }
+        });
+        jaxrsIT.postConstruct(instance);
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testPreDestroy() {
+        final Object instance = new Object();
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(it).preDestroy(instance);
+            }
+        });
+        jaxrsIT.preDestroy(instance);
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testDispose() {
+        final Object instance = new Object();
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(it).dispose(instance);
+            }
+        });
+        jaxrsIT.dispose(instance);
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testGetInjectionPoints() {
+        final Set<InjectionPoint> expectedIPSet = new HashSet<InjectionPoint>();
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(it).getInjectionPoints();
+                will(returnValue(expectedIPSet));
+            }
+        });
+        Set<InjectionPoint> actualIPSet = jaxrsIT.getInjectionPoints();
+        assertEquals(expectedIPSet, actualIPSet);
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testProduce() {
+        final Object expectedProducedInstance = new Object();
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(it).produce(creationalContext);
+                will(returnValue(expectedProducedInstance));
+            }
+        });
+        Object retValue = jaxrsIT.produce(creationalContext);
+        assertEquals(expectedProducedInstance, retValue);
+        mockContext.assertIsSatisfied();
+    }
+}

Added: incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/extension/JAXRSJCDIExtensionTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/extension/JAXRSJCDIExtensionTest.java?rev=995608&view=auto
==============================================================================
--- incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/extension/JAXRSJCDIExtensionTest.java (added)
+++ incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/extension/JAXRSJCDIExtensionTest.java Thu Sep  9 23:14:47 2010
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.wink.jcdi.server.internal.extension;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.ProcessInjectionTarget;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.Provider;
+
+import junit.framework.TestCase;
+
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+
+public class JAXRSJCDIExtensionTest extends TestCase {
+
+    private Mockery                   mockContext     = new Mockery();
+
+    private ProcessInjectionTarget<?> pij             =
+                                                          mockContext
+                                                              .mock(ProcessInjectionTarget.class);
+
+    private InjectionTarget<?>        injectionTarget = mockContext.mock(InjectionTarget.class);
+
+    private AnnotatedType<?>          aType           = mockContext.mock(AnnotatedType.class);
+
+    private JCDIExtension             jcdiExtension   = new JCDIExtension();
+
+    static class JAXRSApplicationClass extends Application {
+    }
+
+    @Provider
+    static class JAXRSProviderClass implements MessageBodyReader<Object> {
+
+        public boolean isReadable(Class<?> type,
+                                  Type genericType,
+                                  Annotation[] annotations,
+                                  MediaType mediaType) {
+            return false;
+        }
+
+        public Object readFrom(Class<Object> type,
+                               Type genericType,
+                               Annotation[] annotations,
+                               MediaType mediaType,
+                               MultivaluedMap<String, String> httpHeaders,
+                               InputStream entityStream) throws IOException {
+            return null;
+        }
+    }
+
+    @Path("/hello")
+    static class JAXRSResourceClass {
+
+    }
+
+    public void testIsJAXRSBean() {
+        assertFalse(JCDIExtension.isJAXRSBean(Object.class));
+        assertFalse(JCDIExtension.isJAXRSBean(JCDIExtension.class));
+
+        assertTrue(JCDIExtension.isJAXRSBean(JAXRSResourceClass.class));
+        assertTrue(JCDIExtension.isJAXRSBean(JAXRSProviderClass.class));
+        assertTrue(JCDIExtension.isJAXRSBean(JAXRSApplicationClass.class));
+    }
+
+    public void testObserveNonJAXRSProcessInjectionTarget() {
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(pij).getAnnotatedType();
+                will(returnValue(aType));
+
+                oneOf(aType).getJavaClass();
+                will(returnValue(Object.class));
+            }
+        });
+        jcdiExtension.observeProcessInjectionTarget(pij);
+        mockContext.assertIsSatisfied();
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testObserveJAXRSProcessInjectionTargetForApplicationSubclasses() {
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(pij).getAnnotatedType();
+                will(returnValue(aType));
+
+                oneOf(aType).getJavaClass();
+                will(returnValue(JAXRSApplicationClass.class));
+
+                oneOf(pij).getInjectionTarget();
+                will(returnValue(injectionTarget));
+
+                oneOf(pij).setInjectionTarget(with(any(JAXRSJCDICustomInjectionTarget.class)));
+            }
+        });
+        jcdiExtension.observeProcessInjectionTarget(pij);
+        mockContext.assertIsSatisfied();
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testObserveJAXRSProcessInjectionTargetForResourceClasses() {
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(pij).getAnnotatedType();
+                will(returnValue(aType));
+
+                oneOf(aType).getJavaClass();
+                will(returnValue(JAXRSResourceClass.class));
+
+                oneOf(pij).getInjectionTarget();
+                will(returnValue(injectionTarget));
+
+                oneOf(pij).setInjectionTarget(with(any(JAXRSJCDICustomInjectionTarget.class)));
+            }
+        });
+        jcdiExtension.observeProcessInjectionTarget(pij);
+        mockContext.assertIsSatisfied();
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testObserveJAXRSProcessInjectionTargetForProviderClasses() {
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(pij).getAnnotatedType();
+                will(returnValue(aType));
+
+                oneOf(aType).getJavaClass();
+                will(returnValue(JAXRSProviderClass.class));
+
+                oneOf(pij).getInjectionTarget();
+                will(returnValue(injectionTarget));
+
+                oneOf(pij).setInjectionTarget(with(any(JAXRSJCDICustomInjectionTarget.class)));
+            }
+        });
+        jcdiExtension.observeProcessInjectionTarget(pij);
+        mockContext.assertIsSatisfied();
+    }
+}

Added: incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDIDefaultObjectFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDIDefaultObjectFactoryTest.java?rev=995608&view=auto
==============================================================================
--- incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDIDefaultObjectFactoryTest.java (added)
+++ incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDIDefaultObjectFactoryTest.java Thu Sep  9 23:14:47 2010
@@ -0,0 +1,247 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.wink.jcdi.server.internal.lifecycle;
+
+import java.lang.annotation.Annotation;
+import java.util.Collections;
+import java.util.Map;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Request;
+
+import junit.framework.TestCase;
+
+import org.apache.wink.common.RuntimeContext;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+
+public class JCDIDefaultObjectFactoryTest extends TestCase {
+
+    @Path("/hello")
+    static class JAXRSResourceClass {
+
+        @Context
+        public Request      request;
+
+        private HttpHeaders http;
+
+        @Context
+        public void setHeaders(HttpHeaders headers) {
+            http = headers;
+        }
+
+        public HttpHeaders getHttp() {
+            return http;
+        }
+    }
+
+    private Mockery              mockContext           = new Mockery();
+
+    private BeanManager          beanManagerMock       = mockContext.mock(BeanManager.class);
+
+    private RuntimeContext       runtimeContextMock    = mockContext.mock(RuntimeContext.class);
+
+    private Bean<?>              beanMock              = mockContext.mock(Bean.class);
+
+    private CreationalContext<?> creationalContextMock = mockContext.mock(CreationalContext.class);
+
+    private Map<?, ?>            attributeMap          = mockContext.mock(Map.class);
+
+    public void testInit() {
+        JCDIDefaultObjectFactory<JAXRSResourceClass> objFactory =
+            new JCDIDefaultObjectFactory<JAXRSResourceClass>(JAXRSResourceClass.class, beanManagerMock);
+        assertEquals(JAXRSResourceClass.class, objFactory.getInstanceClass());
+        assertNull(objFactory.getCreationalContextMap());
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testGetInstanceWithNullRuntimeContext() {
+        final JAXRSResourceClass resourceInstance = new JAXRSResourceClass();
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(beanManagerMock).isQualifier(Path.class);
+                will(returnValue(false));
+
+                oneOf(beanManagerMock).getBeans(JAXRSResourceClass.class, new Annotation[0]);
+                will(returnValue(Collections.singleton(beanMock)));
+
+                oneOf(beanManagerMock).createCreationalContext(beanMock);
+                will(returnValue(creationalContextMock));
+
+                oneOf(beanManagerMock).getReference(beanMock,
+                                                    JAXRSResourceClass.class,
+                                                    creationalContextMock);
+                will(returnValue(resourceInstance));
+            }
+        });
+
+        JCDIDefaultObjectFactory<JAXRSResourceClass> objFactory =
+            new JCDIDefaultObjectFactory<JAXRSResourceClass>(JAXRSResourceClass.class, beanManagerMock);
+        assertSame(resourceInstance, objFactory.getInstance(null));
+        assertNotNull(objFactory.getCreationalContextMap());
+        assertSame(creationalContextMock, objFactory.getCreationalContextMap()
+            .get(resourceInstance));
+        mockContext.assertIsSatisfied();
+
+        /*
+         * now test a releaseInstance; this should never occur in practice
+         * because the getInstance was passed a null RuntimeContext (so it is a
+         * global/ApplicationScoped object) but testing it
+         */
+
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(runtimeContextMock).getAttributes();
+                will(returnValue(attributeMap));
+
+                oneOf(attributeMap).remove(CreationalContext.class.getName());
+                will(returnValue(null));
+            }
+        });
+
+        objFactory.releaseInstance(resourceInstance, runtimeContextMock);
+        assertNotNull(objFactory.getCreationalContextMap());
+        mockContext.assertIsSatisfied();
+
+        /* now test the releaseAll */
+
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(creationalContextMock).release();
+            }
+        });
+
+        objFactory.releaseAll(null);
+        assertNull(objFactory.getCreationalContextMap());
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testGetInstanceWithRuntimeContext() {
+        final JAXRSResourceClass resourceInstance = new JAXRSResourceClass();
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(beanManagerMock).isQualifier(Path.class);
+                will(returnValue(false));
+
+                oneOf(beanManagerMock).getBeans(JAXRSResourceClass.class, new Annotation[0]);
+                will(returnValue(Collections.singleton(beanMock)));
+
+                oneOf(beanManagerMock).createCreationalContext(beanMock);
+                will(returnValue(creationalContextMock));
+
+                oneOf(beanManagerMock).getReference(beanMock,
+                                                    JAXRSResourceClass.class,
+                                                    creationalContextMock);
+                will(returnValue(resourceInstance));
+
+                oneOf(runtimeContextMock).setAttribute(CreationalContext.class,
+                                                       creationalContextMock);
+            }
+        });
+
+        JCDIDefaultObjectFactory<JAXRSResourceClass> objFactory =
+            new JCDIDefaultObjectFactory<JAXRSResourceClass>(JAXRSResourceClass.class, beanManagerMock);
+        assertSame(resourceInstance, objFactory.getInstance(runtimeContextMock));
+        assertNull(objFactory.getCreationalContextMap());
+        mockContext.assertIsSatisfied();
+
+        /* now test the release */
+
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(creationalContextMock).release();
+
+                oneOf(runtimeContextMock).getAttributes();
+                will(returnValue(attributeMap));
+
+                oneOf(attributeMap).remove(CreationalContext.class.getName());
+                will(returnValue(creationalContextMock));
+            }
+        });
+
+        objFactory.releaseInstance(resourceInstance, runtimeContextMock);
+        assertNull(objFactory.getCreationalContextMap());
+
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testReleaseInstanceNull() {
+        JCDIDefaultObjectFactory<JAXRSResourceClass> objFactory =
+            new JCDIDefaultObjectFactory<JAXRSResourceClass>(JAXRSResourceClass.class, beanManagerMock);
+        assertNull(objFactory.getCreationalContextMap());
+        objFactory.releaseInstance(null, null);
+        assertNull(objFactory.getCreationalContextMap());
+
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testReleaseInstanceRuntimeContextNoCreationalContext() {
+        JCDIDefaultObjectFactory<JAXRSResourceClass> objFactory =
+            new JCDIDefaultObjectFactory<JAXRSResourceClass>(JAXRSResourceClass.class, beanManagerMock);
+        assertNull(objFactory.getCreationalContextMap());
+        objFactory.releaseInstance(new JAXRSResourceClass(), null);
+        assertNull(objFactory.getCreationalContextMap());
+        mockContext.assertIsSatisfied();
+
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(runtimeContextMock).getAttributes();
+                will(returnValue(attributeMap));
+
+                oneOf(attributeMap).remove(CreationalContext.class.getName());
+                will(returnValue(null));
+            }
+        });
+
+        assertNull(objFactory.getCreationalContextMap());
+        objFactory.releaseInstance(null, runtimeContextMock);
+        assertNull(objFactory.getCreationalContextMap());
+
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testReleaseAllNull() {
+        JCDIDefaultObjectFactory<JAXRSResourceClass> objFactory =
+            new JCDIDefaultObjectFactory<JAXRSResourceClass>(JAXRSResourceClass.class, beanManagerMock);
+        assertNull(objFactory.getCreationalContextMap());
+        objFactory.releaseAll(null);
+        assertNull(objFactory.getCreationalContextMap());
+
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testReleaseAllNoApplicationScopedObjects() {
+        JCDIDefaultObjectFactory<JAXRSResourceClass> objFactory =
+            new JCDIDefaultObjectFactory<JAXRSResourceClass>(JAXRSResourceClass.class, beanManagerMock);
+        assertNull(objFactory.getCreationalContextMap());
+        objFactory.releaseAll(runtimeContextMock);
+        assertNull(objFactory.getCreationalContextMap());
+
+        mockContext.assertIsSatisfied();
+    }
+    
+    /* TODO need to test multiple runs */
+}

Added: incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDILifecycleManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDILifecycleManagerTest.java?rev=995608&view=auto
==============================================================================
--- incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDILifecycleManagerTest.java (added)
+++ incubator/wink/trunk/wink-jcdi-server/src/test/java/org/apache/wink/jcdi/server/internal/lifecycle/JCDILifecycleManagerTest.java Thu Sep  9 23:14:47 2010
@@ -0,0 +1,328 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.wink.jcdi.server.internal.lifecycle;
+
+import static org.hamcrest.Matchers.anyOf;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.Type;
+import java.util.Collections;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Named;
+import javax.inject.Qualifier;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.Provider;
+
+import junit.framework.TestCase;
+
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+
+public class JCDILifecycleManagerTest extends TestCase {
+
+    private Mockery     mockContext      = new Mockery();
+
+    private BeanManager beanManagerMock  = mockContext.mock(BeanManager.class);
+
+    private BeanManager beanManager2Mock = mockContext.mock(BeanManager.class, "beanManager2Mock");
+
+    private Bean<?>     beanMock         = mockContext.mock(Bean.class);
+
+    static class JAXRSApplicationClass extends Application {
+        @Context
+        public Request      request;
+
+        private HttpHeaders http;
+
+        @Context
+        public void setHeaders(HttpHeaders headers) {
+            http = headers;
+        }
+
+        public HttpHeaders getHttp() {
+            return http;
+        }
+    }
+
+    @Provider
+    static class JAXRSProviderClass implements MessageBodyReader<Object> {
+
+        @Context
+        public Request      request;
+
+        private HttpHeaders http;
+
+        @Context
+        public void setHeaders(HttpHeaders headers) {
+            http = headers;
+        }
+
+        public HttpHeaders getHttp() {
+            return http;
+        }
+
+        public boolean isReadable(Class<?> type,
+                                  Type genericType,
+                                  Annotation[] annotations,
+                                  MediaType mediaType) {
+            return false;
+        }
+
+        public Object readFrom(Class<Object> type,
+                               Type genericType,
+                               Annotation[] annotations,
+                               MediaType mediaType,
+                               MultivaluedMap<String, String> httpHeaders,
+                               InputStream entityStream) throws IOException {
+            return null;
+        }
+    }
+
+    @Path("/hello")
+    static class JAXRSResourceClass {
+
+        @Context
+        public Request      request;
+
+        private HttpHeaders http;
+
+        @Context
+        public void setHeaders(HttpHeaders headers) {
+            http = headers;
+        }
+
+        public HttpHeaders getHttp() {
+            return http;
+        }
+    }
+
+    @Named("myJAXRSResourceClassName")
+    @Path("/hello")
+    static class JAXRSResourceClassWithQualifier {
+
+    }
+
+    @Qualifier
+    @Retention(value = RetentionPolicy.RUNTIME)
+    public @interface MyQualifierAnnotation {
+    }
+
+    @Named("myJAXRSResourceClassName")
+    @MyQualifierAnnotation
+    @Path("/hello")
+    static class JAXRSResourceClassWithMultipleQualifiers {
+
+    }
+
+    public void testIsJCDIManagedBeanResourceClass() {
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(beanManagerMock).isQualifier(Path.class);
+                will(returnValue(false));
+
+                oneOf(beanManagerMock).getBeans(JAXRSResourceClass.class, new Annotation[0]);
+                will(returnValue(Collections.singleton(beanMock)));
+            }
+        });
+        assertTrue(JCDILifecycleManager
+            .isJCDIManagedBean(JAXRSResourceClass.class, beanManagerMock));
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testIsJCDIManagedBeanResourceClassWithQualifier() {
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(beanManagerMock).isQualifier(Path.class);
+                will(returnValue(false));
+
+                oneOf(beanManagerMock).isQualifier(Named.class);
+                will(returnValue(true));
+
+                oneOf(beanManagerMock)
+                    .getBeans(JAXRSResourceClassWithQualifier.class,
+                              new Annotation[] {JAXRSResourceClassWithQualifier.class
+                                  .getAnnotation(Named.class)});
+                will(returnValue(Collections.singleton(beanMock)));
+            }
+        });
+        assertTrue(JCDILifecycleManager.isJCDIManagedBean(JAXRSResourceClassWithQualifier.class,
+                                                          beanManagerMock));
+        mockContext.assertIsSatisfied();
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testIsJCDIManagedBeanResourceClassWithMultipleQualifiers() {
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(beanManagerMock).isQualifier(Path.class);
+                will(returnValue(false));
+
+                oneOf(beanManagerMock).isQualifier(Named.class);
+                will(returnValue(true));
+
+                oneOf(beanManagerMock).isQualifier(MyQualifierAnnotation.class);
+                will(returnValue(true));
+
+                oneOf(beanManagerMock)
+                    .getBeans(with(same(JAXRSResourceClassWithMultipleQualifiers.class)),
+                              with(anyOf(
+
+                              equal(new Annotation[] {
+                                  JAXRSResourceClassWithMultipleQualifiers.class
+                                      .getAnnotation(Named.class),
+                                  JAXRSResourceClassWithMultipleQualifiers.class
+                                      .getAnnotation(MyQualifierAnnotation.class)}),
+
+                              equal(new Annotation[] {
+                                  JAXRSResourceClassWithMultipleQualifiers.class
+                                      .getAnnotation(MyQualifierAnnotation.class),
+                                  JAXRSResourceClassWithMultipleQualifiers.class
+                                      .getAnnotation(Named.class)})
+
+                              )));
+                will(returnValue(Collections.singleton(beanMock)));
+            }
+        });
+        assertTrue(JCDILifecycleManager
+            .isJCDIManagedBean(JAXRSResourceClassWithMultipleQualifiers.class, beanManagerMock));
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testIsJCDIManagedBeanResourceClassReturnsFalseDueToEmptySet() {
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(beanManagerMock).isQualifier(Path.class);
+                will(returnValue(false));
+
+                oneOf(beanManagerMock).getBeans(JAXRSResourceClass.class, new Annotation[0]);
+                will(returnValue(Collections.emptySet()));
+            }
+        });
+        assertFalse(JCDILifecycleManager.isJCDIManagedBean(JAXRSResourceClass.class,
+                                                           beanManagerMock));
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testIsJCDIManagedBeanResourceClassReturnsFalseDueToNull() {
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(beanManagerMock).isQualifier(Path.class);
+                will(returnValue(false));
+
+                oneOf(beanManagerMock).getBeans(JAXRSResourceClass.class, new Annotation[0]);
+                will(returnValue(null));
+            }
+        });
+        assertFalse(JCDILifecycleManager.isJCDIManagedBean(JAXRSResourceClass.class,
+                                                           beanManagerMock));
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testSetGetBeanManager() {
+        JCDILifecycleManager<Object> manager = new JCDILifecycleManager<Object>();
+
+        // should not be able to lookup via JNDI
+        assertNull(manager.getBeanManager());
+
+        manager.setBeanManager(beanManagerMock);
+        assertSame(beanManagerMock, manager.getBeanManager());
+
+        manager.setBeanManager(beanManager2Mock);
+        assertSame(beanManager2Mock, manager.getBeanManager());
+
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testCreateSingletonObjectFactory() {
+        JCDILifecycleManager<Object> manager = new JCDILifecycleManager<Object>();
+        try {
+            manager.createObjectFactory(null);
+            fail("Expected NPE");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        assertNull(manager.createObjectFactory(new Object()));
+        assertNull(manager.createObjectFactory(new JAXRSResourceClass()));
+        assertNull(manager.createObjectFactory(new JAXRSApplicationClass()));
+        assertNull(manager.createObjectFactory(new JAXRSProviderClass()));
+        assertNull(manager.createObjectFactory(new JAXRSResourceClassWithQualifier()));
+        assertNull(manager.createObjectFactory(new JAXRSResourceClassWithMultipleQualifiers()));
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testCreateClassObjectFactoryNull() {
+        JCDILifecycleManager<JAXRSResourceClass> manager =
+            new JCDILifecycleManager<JAXRSResourceClass>();
+        try {
+            Class<JAXRSResourceClass> c = null;
+            manager.createObjectFactory(c);
+            fail("Expected NPE");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testCreateClassObjectFactoryButNotManagedBean() {
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(beanManagerMock).isQualifier(Path.class);
+                will(returnValue(false));
+
+                oneOf(beanManagerMock).getBeans(JAXRSResourceClass.class, new Annotation[0]);
+                will(returnValue(null));
+            }
+        });
+        JCDILifecycleManager<JAXRSResourceClass> manager =
+            new JCDILifecycleManager<JAXRSResourceClass>();
+        manager.setBeanManager(beanManagerMock);
+        assertNull(manager.createObjectFactory(JAXRSResourceClass.class));
+        mockContext.assertIsSatisfied();
+    }
+
+    public void testCreateClassObjectFactoryWithResourceManagedBean() {
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(beanManagerMock).isQualifier(Path.class);
+                will(returnValue(false));
+
+                oneOf(beanManagerMock).getBeans(JAXRSResourceClass.class, new Annotation[0]);
+                will(returnValue(Collections.singleton(beanMock)));
+            }
+        });
+        JCDILifecycleManager<JAXRSResourceClass> manager =
+            new JCDILifecycleManager<JAXRSResourceClass>();
+        manager.setBeanManager(beanManagerMock);
+        assertNotNull(manager.createObjectFactory(JAXRSResourceClass.class));
+        mockContext.assertIsSatisfied();
+    }
+}



Mime
View raw message