You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2010/12/26 11:10:23 UTC

svn commit: r1052852 - in /myfaces/extensions/cdi/trunk: ./ test-modules/base-test-infrastructure-module/ test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/base/junit4/ test-modules/base-test-infrastructu...

Author: gpetracek
Date: Sun Dec 26 10:10:22 2010
New Revision: 1052852

URL: http://svn.apache.org/viewvc?rev=1052852&view=rev
Log:
EXTCDI-106 first draft and cleanup

Added:
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/base/junit4/AbstractTest.java
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/java/
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/java/org/
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/java/org/apache/
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/java/org/apache/myfaces/
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/java/org/apache/myfaces/extensions/
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/java/org/apache/myfaces/extensions/cdi/
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/java/org/apache/myfaces/extensions/cdi/test/
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/java/org/apache/myfaces/extensions/cdi/test/base/
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/java/org/apache/myfaces/extensions/cdi/test/base/junit4/
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/java/org/apache/myfaces/extensions/cdi/test/base/junit4/InjectedProjectStageTest.java
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/resources/
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/resources/META-INF/
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/resources/META-INF/beans.xml
Modified:
    myfaces/extensions/cdi/trunk/pom.xml
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/pom.xml
    myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/base/junit4/AbstractServletAwareTest.java

Modified: myfaces/extensions/cdi/trunk/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/pom.xml?rev=1052852&r1=1052851&r2=1052852&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/pom.xml (original)
+++ myfaces/extensions/cdi/trunk/pom.xml Sun Dec 26 10:10:22 2010
@@ -249,7 +249,7 @@
             <!-- Base test infrastructure modules -->
             <dependency>
                 <groupId>org.apache.myfaces.extensions.cdi.test</groupId>
-                <artifactId>myfaces-extcdi-cargo-base-test-infrastructure</artifactId>
+                <artifactId>myfaces-extcdi-base-test-infrastructure</artifactId>
                 <version>0.9.2-SNAPSHOT</version>
             </dependency>
             

Modified: myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/pom.xml?rev=1052852&r1=1052851&r2=1052852&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/pom.xml (original)
+++ myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/pom.xml Sun Dec 26 10:10:22 2010
@@ -46,6 +46,18 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-el_2.2_spec</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-validation_1.0_spec</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.myfaces.extensions.cdi.core</groupId>
             <artifactId>myfaces-extcdi-core-api</artifactId>
             <scope>provided</scope>

Modified: myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/base/junit4/AbstractServletAwareTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/base/junit4/AbstractServletAwareTest.java?rev=1052852&r1=1052851&r2=1052852&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/base/junit4/AbstractServletAwareTest.java (original)
+++ myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/base/junit4/AbstractServletAwareTest.java Sun Dec 26 10:10:22 2010
@@ -20,27 +20,21 @@ package org.apache.myfaces.extensions.cd
 
 import org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStage;
 import org.apache.myfaces.extensions.cdi.core.impl.projectstage.ProjectStageProducer;
-import org.apache.webbeans.cditest.CdiTestContainer;
 import org.apache.webbeans.context.ContextFactory;
 import org.junit.After;
 import org.junit.Before;
 
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.context.SessionScoped;
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.InjectionTarget;
 
 /**
  * Allows dependency injection in JUnit tests and implementing JUnit tests in web-projects.
  *
  * @author Gerhard Petracek
  */
-public abstract class AbstractServletAwareTest
+public abstract class AbstractServletAwareTest extends AbstractTest
 {
-    private CdiTestContainer testContainer;
-
+    @Override
     @Before
     public void before() throws Exception
     {
@@ -53,12 +47,7 @@ public abstract class AbstractServletAwa
         ContextFactory.activateContext(SessionScoped.class);
         ContextFactory.activateContext(RequestScoped.class);
 
-        BeanManager beanManager = this.testContainer.getBeanManager();
-        CreationalContext creationalContext = beanManager.createCreationalContext(null);
-
-        AnnotatedType annotatedType = beanManager.createAnnotatedType(getClass());
-        InjectionTarget injectionTarget = beanManager.createInjectionTarget(annotatedType);
-        injectionTarget.inject(this, creationalContext);
+        injectFields();
     }
 
     @After

Added: myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/base/junit4/AbstractTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/base/junit4/AbstractTest.java?rev=1052852&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/base/junit4/AbstractTest.java (added)
+++ myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/main/java/org/apache/myfaces/extensions/cdi/test/base/junit4/AbstractTest.java Sun Dec 26 10:10:22 2010
@@ -0,0 +1,69 @@
+/*
+ * 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.myfaces.extensions.cdi.test.base.junit4;
+
+import org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStage;
+import org.apache.myfaces.extensions.cdi.core.impl.projectstage.ProjectStageProducer;
+import org.apache.webbeans.cditest.CdiTestContainer;
+import org.apache.webbeans.cditest.CdiTestContainerLoader;
+import org.junit.After;
+import org.junit.Before;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+/**
+ * Allows dependency injection in (standalone) JUnit tests.
+ *
+ * @author Gerhard Petracek
+ */
+public abstract class AbstractTest
+{
+    protected CdiTestContainer testContainer;
+
+    @Before
+    public void before() throws Exception
+    {
+        ProjectStageProducer.setProjectStage(ProjectStage.UnitTest);
+
+        this.testContainer = CdiTestContainerLoader.getCdiContainer();
+        this.testContainer.bootContainer();
+        this.testContainer.startContexts();
+
+        injectFields();
+    }
+
+    protected void injectFields()
+    {
+        BeanManager beanManager = this.testContainer.getBeanManager();
+        CreationalContext creationalContext = beanManager.createCreationalContext(null);
+
+        AnnotatedType annotatedType = beanManager.createAnnotatedType(getClass());
+        InjectionTarget injectionTarget = beanManager.createInjectionTarget(annotatedType);
+        injectionTarget.inject(this, creationalContext);
+    }
+
+    @After
+    public void after() throws Exception
+    {
+        this.testContainer.stopContexts();
+    }
+}

Added: myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/java/org/apache/myfaces/extensions/cdi/test/base/junit4/InjectedProjectStageTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/java/org/apache/myfaces/extensions/cdi/test/base/junit4/InjectedProjectStageTest.java?rev=1052852&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/java/org/apache/myfaces/extensions/cdi/test/base/junit4/InjectedProjectStageTest.java (added)
+++ myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/java/org/apache/myfaces/extensions/cdi/test/base/junit4/InjectedProjectStageTest.java Sun Dec 26 10:10:22 2010
@@ -0,0 +1,45 @@
+/*
+ * 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.myfaces.extensions.cdi.test.base.junit4;
+
+import org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStage;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import javax.inject.Inject;
+
+import static org.testng.Assert.assertEquals;
+
+/**
+ * @author Gerhard Petracek
+ */
+
+@RunWith(JUnit4.class)
+public class InjectedProjectStageTest extends AbstractTest
+{
+    @Inject
+    private ProjectStage projectStage;
+
+    @Test
+    public void testProjectStage()
+    {
+        assertEquals(this.projectStage, ProjectStage.UnitTest);
+    }
+}

Added: myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/resources/META-INF/beans.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/resources/META-INF/beans.xml?rev=1052852&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/resources/META-INF/beans.xml (added)
+++ myfaces/extensions/cdi/trunk/test-modules/base-test-infrastructure-module/src/test/resources/META-INF/beans.xml Sun Dec 26 10:10:22 2010
@@ -0,0 +1,23 @@
+<?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 xmlns="http://java.sun.com/xml/ns/javaee"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+</beans>
\ No newline at end of file