openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r919555 - in /openwebbeans/trunk/webbeans-test: ./ cditest-owb/ cditest-owb/src/ cditest-owb/src/main/ cditest-owb/src/main/java/ cditest-owb/src/main/java/org/ cditest-owb/src/main/java/org/apache/ cditest-owb/src/main/java/org/apache/webb...
Date Fri, 05 Mar 2010 19:35:10 GMT
Author: struberg
Date: Fri Mar  5 19:35:09 2010
New Revision: 919555

URL: http://svn.apache.org/viewvc?rev=919555&view=rev
Log:
OWB-316 implement generic CDI test container + OWB provider integration

Added:
    openwebbeans/trunk/webbeans-test/   (with props)
    openwebbeans/trunk/webbeans-test/cditest/   (with props)
    openwebbeans/trunk/webbeans-test/cditest-owb/   (with props)
    openwebbeans/trunk/webbeans-test/cditest-owb/pom.xml
    openwebbeans/trunk/webbeans-test/cditest-owb/src/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/CdiTestOpenWebBeansContainer.java
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/MockHttpSession.java
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/MockServletContext.java
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/resources/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/resources/META-INF/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/resources/META-INF/openwebbeans/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/resources/META-INF/services/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/main/resources/META-INF/services/org.apache.webbeans.cditest.CdiTestContainer
    openwebbeans/trunk/webbeans-test/cditest-owb/src/test/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/test/java/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/test/java/org/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/test/java/org/apache/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/test/java/org/apache/webbeans/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/test/java/org/apache/webbeans/cditest/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/test/java/org/apache/webbeans/cditest/test/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/test/java/org/apache/webbeans/cditest/test/SessionScopedTestBean.java
    openwebbeans/trunk/webbeans-test/cditest-owb/src/test/java/org/apache/webbeans/cditest/test/TestOwbTestContainer.java
    openwebbeans/trunk/webbeans-test/cditest-owb/src/test/resouces/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/test/resources/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/test/resources/META-INF/
    openwebbeans/trunk/webbeans-test/cditest-owb/src/test/resources/META-INF/beans.xml
    openwebbeans/trunk/webbeans-test/cditest/pom.xml
    openwebbeans/trunk/webbeans-test/cditest/src/
    openwebbeans/trunk/webbeans-test/cditest/src/main/
    openwebbeans/trunk/webbeans-test/cditest/src/main/java/
    openwebbeans/trunk/webbeans-test/cditest/src/main/java/org/
    openwebbeans/trunk/webbeans-test/cditest/src/main/java/org/apache/
    openwebbeans/trunk/webbeans-test/cditest/src/main/java/org/apache/webbeans/
    openwebbeans/trunk/webbeans-test/cditest/src/main/java/org/apache/webbeans/cditest/
    openwebbeans/trunk/webbeans-test/cditest/src/main/java/org/apache/webbeans/cditest/CdiTestContainer.java
    openwebbeans/trunk/webbeans-test/cditest/src/main/java/org/apache/webbeans/cditest/CdiTestContainerLoader.java
    openwebbeans/trunk/webbeans-test/cditest/src/main/resources/
    openwebbeans/trunk/webbeans-test/pom.xml

Propchange: openwebbeans/trunk/webbeans-test/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Mar  5 19:35:09 2010
@@ -0,0 +1,11 @@
+target
+.metadata
+.classpath
+.project
+.settings
+*.iml
+*.ipr
+*.iws
+.git
+.gitignore
+

Propchange: openwebbeans/trunk/webbeans-test/cditest/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Mar  5 19:35:09 2010
@@ -0,0 +1,11 @@
+target
+.metadata
+.classpath
+.project
+.settings
+*.iml
+*.ipr
+*.iws
+.git
+.gitignore
+

Propchange: openwebbeans/trunk/webbeans-test/cditest-owb/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Mar  5 19:35:09 2010
@@ -0,0 +1,11 @@
+target
+.metadata
+.classpath
+.project
+.settings
+*.iml
+*.ipr
+*.iws
+.git
+.gitignore
+

Added: openwebbeans/trunk/webbeans-test/cditest-owb/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-test/cditest-owb/pom.xml?rev=919555&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-test/cditest-owb/pom.xml (added)
+++ openwebbeans/trunk/webbeans-test/cditest-owb/pom.xml Fri Mar  5 19:35:09 2010
@@ -0,0 +1,87 @@
+<?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>
+        <groupId>org.apache.openwebbeans.test</groupId>
+        <artifactId>parent</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
+    
+    <artifactId>cditest-owb</artifactId>
+    <packaging>jar</packaging>
+
+    <name>Apache CDI OpenWebBeans Testing integration</name>
+    <description>
+        This module provides plugable CDI-Testing support for the OpenWebBeans CDI container.
+    </description>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.openwebbeans.test</groupId>
+            <artifactId>cditest</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.openwebbeans</groupId>
+            <artifactId>openwebbeans-impl</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-servlet_2.5_spec</artifactId>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-el_2.2_spec</artifactId>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-interceptor_1.1_spec</artifactId>
+        </dependency>
+        
+        
+        <!-- TODO REMOVE! this should not be needed for M5 -->
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jta_1.1_spec</artifactId>
+            <optional>true</optional>
+        </dependency>
+
+        <!-- TODO REMOVE! this should not be needed for M5 -->
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-validation_1.0_spec</artifactId>
+        </dependency>
+        
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        
+    </dependencies>
+
+</project>

Added: openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/CdiTestOpenWebBeansContainer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/CdiTestOpenWebBeansContainer.java?rev=919555&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/CdiTestOpenWebBeansContainer.java
(added)
+++ openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/CdiTestOpenWebBeansContainer.java
Fri Mar  5 19:35:09 2010
@@ -0,0 +1,179 @@
+/*
+ * 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.webbeans.cditest.owb;
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+import javax.enterprise.inject.AmbiguousResolutionException;
+import javax.enterprise.inject.ResolutionException;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.apache.webbeans.cditest.CdiTestContainer;
+import org.apache.webbeans.context.ContextFactory;
+import org.apache.webbeans.lifecycle.LifecycleFactory;
+import org.apache.webbeans.spi.ContainerLifecycle;
+
+/**
+ * OpenWebBeans specific implementation of {@link CdiTestContainer}.
+ */
+public class CdiTestOpenWebBeansContainer implements CdiTestContainer 
+{
+
+    private ContainerLifecycle  lifecycle = null;
+    private MockServletContext  servletContext = null;
+    private MockHttpSession     session = null;
+
+    @Override
+    public void bootContainer() throws Exception 
+    {
+        servletContext = new MockServletContext();
+        session = new MockHttpSession();
+        lifecycle = LifecycleFactory.getInstance().getLifecycle();
+        lifecycle.start(servletContext);
+    }
+
+    @Override
+    public void shutdownContainer() throws Exception 
+    {
+        if (lifecycle != null) 
+        {
+            lifecycle.stop(servletContext);
+        }
+    }
+
+    @Override
+    public void startContexts() throws Exception 
+    {
+        ContextFactory.initSingletonContext(servletContext);
+        ContextFactory.initApplicationContext(servletContext);
+        ContextFactory.initSessionContext(session);
+        ContextFactory.initConversationContext(null);
+        ContextFactory.initRequestContext(null);
+    }
+
+    @Override
+    public void startApplicationScope() throws Exception 
+    {
+        ContextFactory.initApplicationContext(servletContext);
+    }
+
+    @Override
+    public void startConversationScope() throws Exception 
+    {
+        ContextFactory.initConversationContext(null);
+    }
+
+    @Override
+    public void startCustomScope(Class<? extends Annotation> scopeClass) throws Exception

+    {
+        //X TODO
+    }
+
+    @Override
+    public void startRequestScope() throws Exception 
+    {
+        ContextFactory.initRequestContext(null);
+    }
+
+    @Override
+    public void startSessionScope() throws Exception 
+    {
+        ContextFactory.initSessionContext(session);
+    }
+
+    @Override
+    public void stopContexts() throws Exception 
+    {
+        ContextFactory.destroyRequestContext(null);
+        ContextFactory.destroyConversationContext();
+        ContextFactory.destroySessionContext(session);
+        ContextFactory.destroyApplicationContext(servletContext);
+        ContextFactory.destroySingletonContext(servletContext);
+    }
+
+    @Override
+    public void stopApplicationScope() throws Exception 
+    {
+        ContextFactory.destroyApplicationContext(servletContext);
+    }
+
+    @Override
+    public void stopConversationScope() throws Exception 
+    {
+        ContextFactory.destroyConversationContext();
+    }
+
+    @Override
+    public void stopCustomScope(Class<? extends Annotation> scopeClass) throws Exception

+    {
+        //X TODO
+    }
+
+    @Override
+    public void stopRequestScope() throws Exception 
+    {
+        ContextFactory.destroyRequestContext(null);
+    }
+
+    @Override
+    public void stopSessionScope() throws Exception 
+    {
+        ContextFactory.destroySessionContext(session);
+    }
+    
+    public  BeanManager getBeanManager() 
+    {
+        return lifecycle.getBeanManager();
+    }
+
+    @Override
+    public <T> T getInstance(Class<T> type, Annotation... qualifiers)
+    throws ResolutionException 
+    {
+        Set<Bean<?>> beans = getBeanManager().getBeans(type, qualifiers);
+        if (beans == null || beans.isEmpty()) 
+        {
+            throw new ResolutionException("cannot find beans for class " + type.getCanonicalName());
+        }
+
+        if (beans.size() > 1) 
+        {
+            throw new AmbiguousResolutionException("cannot find beans for class " + type.getCanonicalName());
+        }
+
+        @SuppressWarnings("unchecked")
+        Bean<T> bean = (Bean<T>)beans.iterator().next();
+
+        @SuppressWarnings("unchecked")
+        T instance = (T) getBeanManager().getReference(bean, type, getBeanManager().createCreationalContext(bean));
+        return instance;
+    }
+
+    @Override
+    public Object getInstance(String name)
+    throws ResolutionException 
+    {
+        //X getBeanManager().getELResolver();
+        // TODO implement
+        return null;
+    }
+
+}

Added: openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/MockHttpSession.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/MockHttpSession.java?rev=919555&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/MockHttpSession.java
(added)
+++ openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/MockHttpSession.java
Fri Mar  5 19:35:09 2010
@@ -0,0 +1,111 @@
+/*
+ * 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.webbeans.cditest.owb;
+
+import java.util.Enumeration;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionContext;
+
+/**
+ * A simple mock HttpSession
+ */
+public class MockHttpSession implements HttpSession {
+
+    @Override
+    public long getCreationTime() {
+        return 0;
+    }
+
+    @Override
+    public String getId() {
+        return "sessId1";
+    }
+
+    @Override
+    public long getLastAccessedTime() {
+        return 0;
+    }
+
+    @Override
+    public ServletContext getServletContext() {
+        return null;
+    }
+
+    @Override
+    public void setMaxInactiveInterval(int interval) {
+    }
+
+    @Override
+    public int getMaxInactiveInterval() {
+        return 0;
+    }
+
+    @Override
+    public HttpSessionContext getSessionContext() {
+        return null;
+    }
+
+    @Override
+    public Object getAttribute(String name) {
+        return null;
+    }
+
+    @Override
+    public Object getValue(String name) {
+        return null;
+    }
+
+    @Override
+    public Enumeration getAttributeNames() {
+        return null;
+    }
+
+    @Override
+    public String[] getValueNames() {
+        return new String[0];
+    }
+
+    @Override
+    public void setAttribute(String name, Object value) {
+    }
+
+    @Override
+    public void putValue(String name, Object value) {
+    }
+
+    @Override
+    public void removeAttribute(String name) {
+    }
+
+    @Override
+    public void removeValue(String name) {
+    }
+
+    @Override
+    public void invalidate() {
+    }
+
+    @Override
+    public boolean isNew() {
+        return false;
+    }
+
+}

Added: openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/MockServletContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/MockServletContext.java?rev=919555&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/MockServletContext.java
(added)
+++ openwebbeans/trunk/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/MockServletContext.java
Fri Mar  5 19:35:09 2010
@@ -0,0 +1,176 @@
+/*
+ * 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.webbeans.cditest.owb;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+/**
+ * Mock ServletContext needed to startup the container.
+ *
+ */
+public class MockServletContext implements ServletContext {
+
+    @SuppressWarnings("unchecked")
+    private Hashtable attributes = new Hashtable();
+
+    public Object getAttribute(String name)
+    {
+        return attributes.get(name);
+    }
+
+    @SuppressWarnings("unchecked")
+    public Enumeration getAttributeNames()
+    {
+        return attributes.keys();
+    }
+
+    public ServletContext getContext(String uripath)
+    {
+        return this;
+    }
+
+    public String getContextPath()
+    {
+        return "mockContextpath";
+    }
+
+    public String getInitParameter(String name)
+    {
+        return null;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Enumeration getInitParameterNames()
+    {
+        return new StringTokenizer(""); // 'standard' empty Enumeration
+    }
+
+    public int getMajorVersion()
+    {
+        return 2;
+    }
+
+    public String getMimeType(String file)
+    {
+        return null;
+    }
+
+    public int getMinorVersion()
+    {
+        return 0;
+    }
+
+    public RequestDispatcher getNamedDispatcher(String name)
+    {
+        return null;
+    }
+
+    public String getRealPath(String path)
+    {
+        return "mockRealPath";
+    }
+
+    public RequestDispatcher getRequestDispatcher(String path)
+    {
+        return null;
+    }
+
+    public URL getResource(String path) throws MalformedURLException
+    {
+        return null;
+    }
+
+    public InputStream getResourceAsStream(String path)
+    {
+        return null;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Set getResourcePaths(String path)
+    {
+        return null;
+    }
+
+    public String getServerInfo()
+    {
+        return "mockServer";
+    }
+
+    public Servlet getServlet(String name) throws ServletException
+    {
+        return null;
+    }
+
+    public String getServletContextName()
+    {
+        return null;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Enumeration getServletNames()
+    {
+        return null;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Enumeration getServlets()
+    {
+        return null;
+    }
+
+    public void log(String msg)
+    {
+        // TODO
+    }
+
+    public void log(Exception exception, String msg)
+    {
+        // TODO
+
+    }
+
+    public void log(String message, Throwable throwable)
+    {
+        // TODO
+
+    }
+
+    public void removeAttribute(String name)
+    {
+        attributes.remove(name);
+    }
+
+    @SuppressWarnings("unchecked")
+    public void setAttribute(String name, Object object)
+    {
+        attributes.put(name, object);
+    }
+
+}

Added: openwebbeans/trunk/webbeans-test/cditest-owb/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-test/cditest-owb/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=919555&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-test/cditest-owb/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
(added)
+++ openwebbeans/trunk/webbeans-test/cditest-owb/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
Fri Mar  5 19:35:09 2010
@@ -0,0 +1,27 @@
+#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.
+
+#general configuration section for testing with OpenWebBeans
+
+# make ViewScoped available
+#org.apache.webbeans.application.useJSF2Extensions=true
+
+# use non-JTA resource injection
+org.apache.webbeans.spi.ResourceInjectionService=org.apache.webbeans.resource.spi.se.StandaloneResourceInjectionService
+
+#Lifecycle to start container
+org.apache.webbeans.spi.ContainerLifecycle=org.apache.webbeans.lifecycle.test.EnterpriseTestLifeCycle

Added: openwebbeans/trunk/webbeans-test/cditest-owb/src/main/resources/META-INF/services/org.apache.webbeans.cditest.CdiTestContainer
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-test/cditest-owb/src/main/resources/META-INF/services/org.apache.webbeans.cditest.CdiTestContainer?rev=919555&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-test/cditest-owb/src/main/resources/META-INF/services/org.apache.webbeans.cditest.CdiTestContainer
(added)
+++ openwebbeans/trunk/webbeans-test/cditest-owb/src/main/resources/META-INF/services/org.apache.webbeans.cditest.CdiTestContainer
Fri Mar  5 19:35:09 2010
@@ -0,0 +1,24 @@
+# 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.
+
+
+# 
+# This will register the OpenWebBeans specific CdiTestContainer
+# as a service and make it available for use in Unit Tests.
+
+org.apache.webbeans.cditest.owb.CdiTestOpenWebBeansContainer
+

Added: openwebbeans/trunk/webbeans-test/cditest-owb/src/test/java/org/apache/webbeans/cditest/test/SessionScopedTestBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-test/cditest-owb/src/test/java/org/apache/webbeans/cditest/test/SessionScopedTestBean.java?rev=919555&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-test/cditest-owb/src/test/java/org/apache/webbeans/cditest/test/SessionScopedTestBean.java
(added)
+++ openwebbeans/trunk/webbeans-test/cditest-owb/src/test/java/org/apache/webbeans/cditest/test/SessionScopedTestBean.java
Fri Mar  5 19:35:09 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.webbeans.cditest.test;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.SessionScoped;
+
+@SessionScoped
+public class SessionScopedTestBean implements Serializable {
+    private int i;
+
+    public int getI() {
+        return i;
+    }
+
+    public void setI(int i) {
+        this.i = i;
+    }
+}

Added: openwebbeans/trunk/webbeans-test/cditest-owb/src/test/java/org/apache/webbeans/cditest/test/TestOwbTestContainer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-test/cditest-owb/src/test/java/org/apache/webbeans/cditest/test/TestOwbTestContainer.java?rev=919555&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-test/cditest-owb/src/test/java/org/apache/webbeans/cditest/test/TestOwbTestContainer.java
(added)
+++ openwebbeans/trunk/webbeans-test/cditest-owb/src/test/java/org/apache/webbeans/cditest/test/TestOwbTestContainer.java
Fri Mar  5 19:35:09 2010
@@ -0,0 +1,41 @@
+/*
+ * 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.webbeans.cditest.test;
+
+import org.apache.webbeans.cditest.CdiTestContainer;
+import org.apache.webbeans.cditest.CdiTestContainerLoader;
+import org.junit.Test;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+public class TestOwbTestContainer extends TestCase {
+
+    @Test
+    public void testInstanceRetrieval() throws Exception
+    {
+        CdiTestContainer cdi = CdiTestContainerLoader.getCdiContainer();
+        cdi.bootContainer();
+
+        SessionScopedTestBean testReference = cdi.getInstance(SessionScopedTestBean.class);
+        Assert.assertNotNull(testReference);
+
+        cdi.shutdownContainer();
+    }
+}

Added: openwebbeans/trunk/webbeans-test/cditest-owb/src/test/resources/META-INF/beans.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-test/cditest-owb/src/test/resources/META-INF/beans.xml?rev=919555&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-test/cditest-owb/src/test/resources/META-INF/beans.xml (added)
+++ openwebbeans/trunk/webbeans-test/cditest-owb/src/test/resources/META-INF/beans.xml Fri
Mar  5 19:35:09 2010
@@ -0,0 +1,20 @@
+<?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.
+-->
+<beans/>
\ No newline at end of file

Added: openwebbeans/trunk/webbeans-test/cditest/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-test/cditest/pom.xml?rev=919555&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-test/cditest/pom.xml (added)
+++ openwebbeans/trunk/webbeans-test/cditest/pom.xml Fri Mar  5 19:35:09 2010
@@ -0,0 +1,58 @@
+<?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>
+        <groupId>org.apache.openwebbeans.test</groupId>
+        <artifactId>parent</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
+    <artifactId>cditest</artifactId>
+    <packaging>jar</packaging>
+
+    <name>Apache CDI Testing integration</name>
+    <description>
+        This project provides a way to genericly run CDI containers 
+        from inside of unit tests like junit or testng.
+    </description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jcdi_1.0_spec</artifactId>
+            <optional>true</optional>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-atinject_1.0_spec</artifactId>
+            <optional>true</optional>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-interceptor_1.1_spec</artifactId>
+            <optional>true</optional>
+        </dependency>
+    </dependencies>
+
+</project>

Added: openwebbeans/trunk/webbeans-test/cditest/src/main/java/org/apache/webbeans/cditest/CdiTestContainer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-test/cditest/src/main/java/org/apache/webbeans/cditest/CdiTestContainer.java?rev=919555&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-test/cditest/src/main/java/org/apache/webbeans/cditest/CdiTestContainer.java
(added)
+++ openwebbeans/trunk/webbeans-test/cditest/src/main/java/org/apache/webbeans/cditest/CdiTestContainer.java
Fri Mar  5 19:35:09 2010
@@ -0,0 +1,97 @@
+/*
+ * 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.webbeans.cditest;
+
+
+import java.lang.annotation.Annotation;
+import javax.enterprise.inject.ResolutionException;
+import javax.enterprise.inject.spi.BeanManager;
+
+
+/**
+ * A CdiTestContainer provides access to an underlying JSR-299 (CDI)
+ * Container. It allows starting and stopping the container as to start
+ * and stop single contexts.
+ *
+ */
+public interface CdiTestContainer 
+{
+    /**
+     * Booting the CdiTestContainer will scan the whole classpath
+     * for Beans and extensions available.
+     */
+    public void bootContainer() throws Exception;
+    
+    /**
+     * This will shutdown the underlying CDI container.
+     */
+    public void shutdownContainer() throws Exception;
+    
+    /**
+     * This will start all Contexts
+     */
+    public void startContexts() throws Exception;
+    
+    /**
+     * Stop all Contexts and destroy all beans properly
+     */
+    public void stopContexts() throws Exception;
+    
+    
+    public void startApplicationScope() throws Exception;
+    public void stopApplicationScope() throws Exception;
+    
+    public void startSessionScope() throws Exception;
+    public void stopSessionScope() throws Exception;
+    
+    public void startRequestScope() throws Exception;
+    public void stopRequestScope() throws Exception;
+
+    public void startConversationScope() throws Exception;
+    public void stopConversationScope() throws Exception;
+
+    public void startCustomScope(Class<? extends Annotation> scopeClass) throws Exception;
+    public void stopCustomScope(Class<? extends Annotation> scopeClass) throws Exception;
+
+    /**
+     * @return the {@link BeanManager} or <code>null</code> it not available
+     */
+    public  BeanManager getBeanManager();
+
+    /**
+     * Provide a contextual reference via it's type and optional qualifier annotations.
+     * If no qualifier is given, &#064;Default is assumed.
+     * @param <T> the Type of the contextual reference
+     * @param type the Type of the contextual reference
+     * @param qualifiers optional qualifiers to restrict the search
+     * @return a contextual reference of the given bean if it is not ambiguous.
+     * @throws ResolutionException if not exactly 1 {@code Bean<T>} got found
+     */
+    public <T> T getInstance(Class<T> type, Annotation... qualifiers) throws
ResolutionException;
+
+    /**
+     * Provide a contextual reference via it's type and ExpressionLanguage name.
+     * @param <T> the Type of the contextual reference
+     * @param elName the EL name to search for.
+     * @return a contextual reference of the given bean via it's name.
+     * @throws ResolutionException if not exactly 1 {@code Bean<T>} got found
+     */
+    public Object getInstance(String elNname) throws ResolutionException;
+
+}

Added: openwebbeans/trunk/webbeans-test/cditest/src/main/java/org/apache/webbeans/cditest/CdiTestContainerLoader.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-test/cditest/src/main/java/org/apache/webbeans/cditest/CdiTestContainerLoader.java?rev=919555&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-test/cditest/src/main/java/org/apache/webbeans/cditest/CdiTestContainerLoader.java
(added)
+++ openwebbeans/trunk/webbeans-test/cditest/src/main/java/org/apache/webbeans/cditest/CdiTestContainerLoader.java
Fri Mar  5 19:35:09 2010
@@ -0,0 +1,55 @@
+/*
+ * 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.webbeans.cditest;
+
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+/**
+ * <p>This class provides access to the CdiTestContainer.</p>
+ * <p>It uses the {@code java.util.ServiceLoader} mechanism  to 
+ * automatically pickup the container providers from the classpath.</p>
+ *
+ */
+public class CdiTestContainerLoader 
+{
+
+    
+    public static CdiTestContainer getCdiContainer() 
+    {
+        CdiTestContainer testContainer = null;
+        
+        ServiceLoader<CdiTestContainer> cdiContainerLoader = ServiceLoader.load(CdiTestContainer.class);
+        Iterator<CdiTestContainer> cdiIt = cdiContainerLoader.iterator();
+        if (cdiIt.hasNext())
+        {
+            testContainer = cdiIt.next();
+        }
+        else 
+        {
+            throw new RuntimeException("Could not find a CdiTestContainer available in the
classpath!");
+        }
+        
+        if (cdiIt.hasNext()) {
+            throw new RuntimeException("Too many CdiTestContainers found in the classpath!");
+        }
+        
+        return testContainer;
+    }
+}

Added: openwebbeans/trunk/webbeans-test/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-test/pom.xml?rev=919555&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-test/pom.xml (added)
+++ openwebbeans/trunk/webbeans-test/pom.xml Fri Mar  5 19:35:09 2010
@@ -0,0 +1,39 @@
+<?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>
+		<groupId>org.apache.openwebbeans</groupId>
+		<artifactId>openwebbeans</artifactId>
+		<version>1.0.0-SNAPSHOT</version>
+	</parent>
+	<groupId>org.apache.openwebbeans.test</groupId>
+	<artifactId>parent</artifactId>
+	<packaging>pom</packaging>
+	<name>Apache OpenWebBeans Test Support </name>
+	<description>
+		This module contains testing support for CDI containers and 
+		also provides an implementation for OpenWebBeans.
+	</description>
+	<modules>
+           <module>cditest</module>
+           <module>cditest-owb</module>
+        </modules>
+</project>



Mime
View raw message