You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2011/09/10 00:59:00 UTC
svn commit: r1167385 - in
/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded: ./
src/test/java/org/apache/openejb/arquillian/
Author: dblevins
Date: Fri Sep 9 22:58:59 2011
New Revision: 1167385
URL: http://svn.apache.org/viewvc?rev=1167385&view=rev
Log:
Switched to Tomcat 7.0.16 to match trunk
Bunch of renaming and refactoring.. Not quite finished, but in progress
Added:
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletCdiInjectionTest.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletEjbLocalInjectionTest.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletEjbRemoteTest.java
- copied, changed from r1165129, openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletRemoteEjbTest.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletEnvEntryInjectionTest.java
- copied, changed from r1165185, openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletPojoInjectionTest.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterEjbLocalInjectionTest.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterEjbRemoteInjectionTest.java
- copied, changed from r1165131, openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterRemoteEjbTest.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterEnvEntryInjectionTest.java
- copied, changed from r1165185, openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterPojoInjectionTest.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerEjbLocalInjectionTest.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerEjbRemoteTest.java
- copied, changed from r1165135, openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerRemoteEjbTest.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerEnvEntryInjectionTest.java
- copied, changed from r1165185, openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerPojoInjectionTest.java
Modified:
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/pom.xml
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterPojoInjectionTest.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterRemoteEjbTest.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerPojoInjectionTest.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerRemoteEjbTest.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletPojoInjectionTest.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletRemoteEjbTest.java
Modified: openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/pom.xml?rev=1167385&r1=1167384&r2=1167385&view=diff
==============================================================================
--- openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/pom.xml (original)
+++ openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/pom.xml Fri Sep 9 22:58:59 2011
@@ -33,7 +33,7 @@
<url>http://maven.apache.org</url>
<properties>
- <version.org.apache.tomcat>7.0.12</version.org.apache.tomcat>
+ <version.org.apache.tomcat>7.0.16</version.org.apache.tomcat>
<version.cdi-api>1.0</version.cdi-api>
<version.arquillian>1.0.0.Alpha5</version.arquillian>
</properties>
Added: openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletCdiInjectionTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletCdiInjectionTest.java?rev=1167385&view=auto
==============================================================================
--- openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletCdiInjectionTest.java (added)
+++ openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletCdiInjectionTest.java Fri Sep 9 22:58:59 2011
@@ -0,0 +1,132 @@
+/**
+ * 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.openejb.arquillian;
+
+import org.apache.commons.lang.StringUtils;
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.descriptor.api.Descriptors;
+import org.jboss.shrinkwrap.descriptor.api.Node;
+import org.jboss.shrinkwrap.descriptor.api.spec.servlet.web.WebAppDescriptor;
+import org.jboss.shrinkwrap.descriptor.spi.NodeProvider;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Local;
+import javax.ejb.LocalBean;
+import javax.ejb.Stateless;
+import javax.inject.Inject;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+
+@RunWith(Arquillian.class)
+public class ServletCdiInjectionTest {
+
+ public static final String TEST_NAME = ServletCdiInjectionTest.class.getSimpleName();
+
+ @Test
+ public void pojoInjectionShouldSucceed() throws Exception {
+ final String expectedOutput = "OpenEJB is on the wheel of a 2011 Lexus IS 350";
+ validateTest(expectedOutput);
+ }
+
+// @Test
+ public void testNothing() {
+ }
+
+ @Deployment(testable = false)
+ public static WebArchive createDeployment() {
+ WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class)
+ .version("3.0")
+ .servlet(PojoServlet.class, "/" + TEST_NAME);
+
+ WebArchive archive = ShrinkWrap.create(WebArchive.class, TEST_NAME + ".war")
+ .addClass(PojoServlet.class)
+ .addClass(Car.class)
+ .setWebXML(new StringAsset(descriptor.exportAsString()))
+ .addAsWebResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
+
+ System.err.println(descriptor.exportAsString());
+
+ return archive;
+ }
+
+ public static class PojoServlet extends HttpServlet {
+
+ @Inject
+ private Car car;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ String name = req.getParameter("name");
+ if (StringUtils.isEmpty(name)) {
+ name = "OpenEJB";
+ }
+
+ if (car != null) {
+ resp.getOutputStream().println(car.drive(name));
+ }
+ }
+ }
+
+ public static class Car {
+ private final String make = "Lexus", model = "IS 350";
+ private final int year = 2011;
+
+ public String drive(String name) {
+ return name + " is on the wheel of a " + year + " " + make + " " + model;
+ }
+ }
+
+ private void validateTest(String expectedOutput) throws IOException {
+ final InputStream is = new URL("http://localhost:9080/" + TEST_NAME + "/" + TEST_NAME).openStream();
+ final ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+ int bytesRead = -1;
+ byte[] buffer = new byte[8192];
+ while ((bytesRead = is.read(buffer)) > -1) {
+ os.write(buffer, 0, bytesRead);
+ }
+
+ is.close();
+ os.close();
+
+ String output = new String(os.toByteArray(), "UTF-8");
+ assertNotNull("Response shouldn't be null", output);
+ assertTrue("Output should contain: " + expectedOutput, output.contains(expectedOutput));
+ }
+
+}
+
+
+
Added: openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletEjbLocalInjectionTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletEjbLocalInjectionTest.java?rev=1167385&view=auto
==============================================================================
--- openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletEjbLocalInjectionTest.java (added)
+++ openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletEjbLocalInjectionTest.java Fri Sep 9 22:58:59 2011
@@ -0,0 +1,174 @@
+/**
+ * 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.openejb.arquillian;
+
+import org.apache.commons.lang.StringUtils;
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.descriptor.api.Descriptors;
+import org.jboss.shrinkwrap.descriptor.api.Node;
+import org.jboss.shrinkwrap.descriptor.api.spec.servlet.web.WebAppDescriptor;
+import org.jboss.shrinkwrap.descriptor.spi.NodeProvider;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Local;
+import javax.ejb.LocalBean;
+import javax.ejb.Stateless;
+import javax.inject.Inject;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+
+@RunWith(Arquillian.class)
+public class ServletEjbLocalInjectionTest {
+
+ public static final String TEST_NAME = ServletEjbLocalInjectionTest.class.getSimpleName();
+
+ @Test
+ public void localEjbInjectionShouldSucceed() throws Exception {
+ final String expectedOutput = "Local: OpenEJB is employed at TomEE Software Inc.";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void localBeanEjbInjectionShouldSucceed() throws Exception {
+ final String expectedOutput = "OpenEJB shops at Apache Marketplace";
+ validateTest(expectedOutput);
+ }
+
+ @Deployment(testable = false)
+ public static WebArchive createDeployment() {
+ WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class)
+ .version("3.0")
+ .servlet(PojoServlet.class, "/" + TEST_NAME);
+
+ WebArchive archive = ShrinkWrap.create(WebArchive.class, TEST_NAME + ".war")
+ .addClass(PojoServlet.class)
+ .addClass(CompanyLocal.class)
+ .addClass(Company.class)
+ .addClass(DefaultCompany.class)
+ .addClass(OtherCompany.class)
+ .addClass(SuperMarket.class)
+ .setWebXML(new StringAsset(descriptor.exportAsString()));
+
+ return archive;
+ }
+
+ public static class PojoServlet extends HttpServlet {
+
+ @EJB(beanName = "DefaultCompany")
+ private CompanyLocal localCompany;
+
+ @EJB
+ private SuperMarket market;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ String name = req.getParameter("name");
+ if (StringUtils.isEmpty(name)) {
+ name = "OpenEJB";
+ }
+
+ if (localCompany != null) {
+ resp.getOutputStream().println("Local: " + localCompany.employ(name));
+ }
+ if (market != null) {
+ resp.getOutputStream().println(market.shop(name));
+ }
+ }
+ }
+
+ public static interface Company {
+ }
+
+ @Local
+ public static interface CompanyLocal extends Company {
+ public String employ(String employeeName);
+ }
+
+ @Stateless
+ public static class DefaultCompany implements CompanyLocal {
+
+ private final String name = "TomEE Software Inc.";
+
+ public String employ(String employeeName) {
+ return employeeName + " is employed at " + name;
+ }
+
+ }
+
+ @Stateless
+ public static class OtherCompany implements CompanyLocal {
+
+ private final String name = "Other Software Inc.";
+
+ public String employ(String employeeName) {
+ return employeeName + " is employed at " + name;
+ }
+
+ }
+
+ @Stateless
+ @LocalBean
+ public static class SuperMarket {
+
+ private final String name = "Apache Marketplace";
+
+ public String shop(String employeeName) {
+ return employeeName + " shops at " + name;
+ }
+
+ }
+
+ private void validateTest(String expectedOutput) throws IOException {
+ final InputStream is = new URL("http://localhost:9080/" + TEST_NAME + "/" + TEST_NAME).openStream();
+ final ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+ int bytesRead = -1;
+ byte[] buffer = new byte[8192];
+ while ((bytesRead = is.read(buffer)) > -1) {
+ os.write(buffer, 0, bytesRead);
+ }
+
+ is.close();
+ os.close();
+
+ String output = new String(os.toByteArray(), "UTF-8");
+ assertNotNull("Response shouldn't be null", output);
+ assertTrue("Output should contain: " + expectedOutput, output.contains(expectedOutput));
+ }
+
+}
+
+
+
Copied: openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletEjbRemoteTest.java (from r1165129, openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletRemoteEjbTest.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletEjbRemoteTest.java?p2=openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletEjbRemoteTest.java&p1=openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletRemoteEjbTest.java&r1=1165129&r2=1167385&rev=1167385&view=diff
==============================================================================
--- openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletRemoteEjbTest.java (original)
+++ openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletEjbRemoteTest.java Fri Sep 9 22:58:59 2011
@@ -45,9 +45,9 @@ import static junit.framework.Assert.ass
import static junit.framework.Assert.assertTrue;
@RunWith(Arquillian.class)
-public class ServletRemoteEjbTest {
+public class ServletEjbRemoteTest {
- public static final String TEST_NAME = ServletRemoteEjbTest.class.getSimpleName();
+ public static final String TEST_NAME = ServletEjbRemoteTest.class.getSimpleName();
@Test
public void ejbInjectionShouldSucceed() throws Exception {
Copied: openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletEnvEntryInjectionTest.java (from r1165185, openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletPojoInjectionTest.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletEnvEntryInjectionTest.java?p2=openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletEnvEntryInjectionTest.java&p1=openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletPojoInjectionTest.java&r1=1165185&r2=1167385&rev=1167385&view=diff
==============================================================================
--- openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletPojoInjectionTest.java (original)
+++ openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletEnvEntryInjectionTest.java Fri Sep 9 22:58:59 2011
@@ -50,9 +50,9 @@ import static junit.framework.Assert.ass
import static junit.framework.Assert.assertTrue;
@RunWith(Arquillian.class)
-public class ServletPojoInjectionTest {
+public class ServletEnvEntryInjectionTest {
- public static final String TEST_NAME = ServletPojoInjectionTest.class.getSimpleName();
+ public static final String TEST_NAME = ServletEnvEntryInjectionTest.class.getSimpleName();
@Test
public void localEjbInjectionShouldSucceed() throws Exception {
@@ -144,13 +144,7 @@ public class ServletPojoInjectionTest {
WebArchive archive = ShrinkWrap.create(WebArchive.class, TEST_NAME + ".war")
.addClass(PojoServlet.class)
- .addClass(Car.class)
- .addClass(CompanyLocal.class)
- .addClass(Company.class)
- .addClass(DefaultCompany.class)
- .addClass(SuperMarket.class)
- .setWebXML(new StringAsset(descriptor.exportAsString()))
- .addAsWebResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
+ .setWebXML(new StringAsset(descriptor.exportAsString()));
System.err.println(descriptor.exportAsString());
@@ -164,15 +158,6 @@ public class ServletPojoInjectionTest {
public static class PojoServlet extends HttpServlet {
- @Inject
- private Car car;
-
- @EJB
- private CompanyLocal localCompany;
-
- @EJB
- private SuperMarket market;
-
@Resource(name = "returnEmail")
private String returnEmail;
@@ -213,15 +198,6 @@ public class ServletPojoInjectionTest {
name = "OpenEJB";
}
- if (car != null) {
- resp.getOutputStream().println(car.drive(name));
- }
- if (localCompany != null) {
- resp.getOutputStream().println("Local: " + localCompany.employ(name));
- }
- if (market != null) {
- resp.getOutputStream().println(market.shop(name));
- }
if (connectionPool != null) {
resp.getOutputStream().println("Connection Pool: " + connectionPool);
}
@@ -250,49 +226,6 @@ public class ServletPojoInjectionTest {
resp.getOutputStream().println("DefaultCode: " + defaultCode);
}
}
-
-
- }
-
- public static class Car {
- private final String make = "Lexus", model = "IS 350";
- private final int year = 2011;
-
- public String drive(String name) {
- return name + " is on the wheel of a " + year + " " + make + " " + model;
- }
- }
-
-
- public static interface Company {
- public String employ(String employeeName);
- }
-
- @Local
- public static interface CompanyLocal extends Company {
- }
-
- @Stateless
- public static class DefaultCompany implements CompanyLocal {
-
- private final String name = "TomEE Software Inc.";
-
- public String employ(String employeeName) {
- return employeeName + " is employed at " + name;
- }
-
- }
-
- @Stateless
- @LocalBean
- public static class SuperMarket {
-
- private final String name = "Apache Marketplace";
-
- public String shop(String employeeName) {
- return employeeName + " shops at " + name;
- }
-
}
private static void addEnvEntry(WebAppDescriptor descriptor, String name, String type, String value) {
@@ -304,13 +237,6 @@ public class ServletPojoInjectionTest {
.create("env-entry-type").text(type)
.parent()
.create("env-entry-value").text(value)
-/*
- .parent()
- .create("injection-target")
- .create("injection-target-class").text("org.apache.openejb.arquillian.ServletPojoInjectionTest$PojoServlet")
- .parent()
- .create("injection-target-name").text(name)
-*/
;
}
Added: openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterEjbLocalInjectionTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterEjbLocalInjectionTest.java?rev=1167385&view=auto
==============================================================================
--- openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterEjbLocalInjectionTest.java (added)
+++ openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterEjbLocalInjectionTest.java Fri Sep 9 22:58:59 2011
@@ -0,0 +1,198 @@
+/**
+ * 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.openejb.arquillian;
+
+import org.apache.commons.lang.StringUtils;
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.descriptor.api.Descriptors;
+import org.jboss.shrinkwrap.descriptor.api.Node;
+import org.jboss.shrinkwrap.descriptor.api.spec.servlet.web.WebAppDescriptor;
+import org.jboss.shrinkwrap.descriptor.spi.NodeProvider;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Local;
+import javax.ejb.LocalBean;
+import javax.ejb.Stateless;
+import javax.inject.Inject;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+
+@RunWith(Arquillian.class)
+public class ServletFilterEjbLocalInjectionTest {
+
+ public static final String TEST_NAME = ServletFilterEjbLocalInjectionTest.class.getSimpleName();
+
+ @Test
+ public void localEjbInjectionShouldSucceed() throws Exception {
+ final String expectedOutput = "Local: OpenEJB is employed at TomEE Software Inc.";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void localBeanEjbInjectionShouldSucceed() throws Exception {
+ final String expectedOutput = "OpenEJB shops at Apache Marketplace";
+ validateTest(expectedOutput);
+ }
+
+ @Deployment(testable = false)
+ public static WebArchive createDeployment() {
+ WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class)
+ .version("3.0")
+ .filter(PojoServletFilter.class, "/" + TEST_NAME);
+
+ WebArchive archive = ShrinkWrap.create(WebArchive.class, TEST_NAME + ".war")
+ .addClass(PojoServletFilter.class)
+ .addClass(CompanyLocal.class)
+ .addClass(Company.class)
+ .addClass(DefaultCompany.class)
+ .addClass(SuperMarket.class)
+ .setWebXML(new StringAsset(descriptor.exportAsString()))
+ .addAsWebResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
+
+ System.err.println(descriptor.exportAsString());
+
+ return archive;
+ }
+
+ public static class PojoServletFilter implements Filter {
+
+ @EJB
+ private CompanyLocal localCompany;
+
+ @EJB
+ private SuperMarket market;
+
+ private FilterConfig config;
+
+ public void init(FilterConfig config) {
+ this.config = config;
+ }
+
+ public void destroy() {
+ }
+
+ @Override
+ public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
+ String name = req.getParameter("name");
+ if (StringUtils.isEmpty(name)) {
+ name = "OpenEJB";
+ }
+
+ if (localCompany != null) {
+ resp.getOutputStream().println("Local: " + localCompany.employ(name));
+ }
+ if (market != null) {
+ resp.getOutputStream().println(market.shop(name));
+ }
+ }
+
+
+ }
+
+ public static interface Company {
+ public String employ(String employeeName);
+ }
+
+ @Local
+ public static interface CompanyLocal extends Company {
+ }
+
+ @Stateless
+ public static class DefaultCompany implements CompanyLocal {
+
+ private final String name = "TomEE Software Inc.";
+
+ public String employ(String employeeName) {
+ return employeeName + " is employed at " + name;
+ }
+
+ }
+
+ @Stateless
+ @LocalBean
+ public static class SuperMarket {
+
+ private final String name = "Apache Marketplace";
+
+ public String shop(String employeeName) {
+ return employeeName + " shops at " + name;
+ }
+
+ }
+
+ private static void addEnvEntry(WebAppDescriptor descriptor, String name, String type, String value) {
+ Node rootNode = ((NodeProvider) descriptor).getRootNode();
+ Node appNode = rootNode.get("/web-app").iterator().next();
+ appNode.create("/env-entry")
+ .create("env-entry-name").text(name)
+ .parent()
+ .create("env-entry-type").text(type)
+ .parent()
+ .create("env-entry-value").text(value)
+/*
+ .parent()
+ .create("injection-target")
+ .create("injection-target-class").text("org.apache.openejb.arquillian.ServletPojoInjectionTest$PojoServletFilter")
+ .parent()
+ .create("injection-target-name").text(name)
+*/
+ ;
+
+ }
+
+ private void validateTest(String expectedOutput) throws IOException {
+ final InputStream is = new URL("http://localhost:9080/" + TEST_NAME + "/" + TEST_NAME).openStream();
+ final ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+ int bytesRead = -1;
+ byte[] buffer = new byte[8192];
+ while ((bytesRead = is.read(buffer)) > -1) {
+ os.write(buffer, 0, bytesRead);
+ }
+
+ is.close();
+ os.close();
+
+ String output = new String(os.toByteArray(), "UTF-8");
+ assertNotNull("Response shouldn't be null", output);
+ assertTrue("Output should contain: " + expectedOutput, output.contains(expectedOutput));
+ }
+
+}
+
+
+
Copied: openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterEjbRemoteInjectionTest.java (from r1165131, openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterRemoteEjbTest.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterEjbRemoteInjectionTest.java?p2=openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterEjbRemoteInjectionTest.java&p1=openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterRemoteEjbTest.java&r1=1165131&r2=1167385&rev=1167385&view=diff
==============================================================================
--- openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterRemoteEjbTest.java (original)
+++ openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterEjbRemoteInjectionTest.java Fri Sep 9 22:58:59 2011
@@ -42,9 +42,9 @@ import static junit.framework.Assert.ass
import static junit.framework.Assert.assertTrue;
@RunWith(Arquillian.class)
-public class ServletFilterRemoteEjbTest {
+public class ServletFilterEjbRemoteInjectionTest {
- public static final String TEST_NAME = ServletFilterRemoteEjbTest.class.getSimpleName();
+ public static final String TEST_NAME = ServletFilterEjbRemoteInjectionTest.class.getSimpleName();
@Test
public void ejbInjectionShouldSucceed() throws Exception {
Copied: openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterEnvEntryInjectionTest.java (from r1165185, openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterPojoInjectionTest.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterEnvEntryInjectionTest.java?p2=openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterEnvEntryInjectionTest.java&p1=openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterPojoInjectionTest.java&r1=1165185&r2=1167385&rev=1167385&view=diff
==============================================================================
--- openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterPojoInjectionTest.java (original)
+++ openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletFilterEnvEntryInjectionTest.java Fri Sep 9 22:58:59 2011
@@ -47,9 +47,9 @@ import static junit.framework.Assert.ass
import static junit.framework.Assert.assertTrue;
@RunWith(Arquillian.class)
-public class ServletFilterPojoInjectionTest {
+public class ServletFilterEnvEntryInjectionTest {
- public static final String TEST_NAME = ServletFilterPojoInjectionTest.class.getSimpleName();
+ public static final String TEST_NAME = ServletFilterEnvEntryInjectionTest.class.getSimpleName();
@Test
public void localEjbInjectionShouldSucceed() throws Exception {
Added: openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerEjbLocalInjectionTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerEjbLocalInjectionTest.java?rev=1167385&view=auto
==============================================================================
--- openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerEjbLocalInjectionTest.java (added)
+++ openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerEjbLocalInjectionTest.java Fri Sep 9 22:58:59 2011
@@ -0,0 +1,542 @@
+/**
+ * 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.openejb.arquillian;
+
+import org.apache.commons.lang.StringUtils;
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.descriptor.api.Descriptors;
+import org.jboss.shrinkwrap.descriptor.api.Node;
+import org.jboss.shrinkwrap.descriptor.api.spec.servlet.web.WebAppDescriptor;
+import org.jboss.shrinkwrap.descriptor.spi.NodeProvider;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Local;
+import javax.ejb.LocalBean;
+import javax.ejb.Stateless;
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+
+@RunWith(Arquillian.class)
+public class ServletListenerEjbLocalInjectionTest {
+
+ public static final String TEST_NAME = ServletListenerEjbLocalInjectionTest.class.getSimpleName();
+
+ @Test
+ public void localEjbInjectionShouldSucceedInCtxtListener() throws Exception {
+ final String expectedOutput = "Context: Local: OpenEJB is employed at TomEE Software Inc.";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void localBeanEjbInjectionShouldSucceedInCtxtListener() throws Exception {
+ final String expectedOutput = "Context: OpenEJB shops at Apache Marketplace";
+ validateTest(expectedOutput);
+ }
+
+// @Test
+ public void pojoInjectionShouldSucceedInCtxtListener() throws Exception {
+ final String expectedOutput = "Context: OpenEJB is on the wheel of a 2011 Lexus IS 350";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void stringEnvEntryInjectionShouldSucceedInCtxtListener() throws Exception {
+ final String expectedOutput = "Context: tomee@apache.org";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void integerTypeEnvEntryInjectionShouldSucceedInCtxtListener() throws Exception {
+ final String expectedOutput = "Context: Connection Pool: 20";
+ validateTest(expectedOutput);
+ }
+
+// @Test
+ public void longTypeEnvEntryInjectionShouldSucceedInCtxtListener() throws Exception {
+ final String expectedOutput = "Context: Start Count: 200000";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void shortTypeEnvEntryInjectionShouldSucceedInCtxtListener() throws Exception {
+ final String expectedOutput = "Context: Init Size: 5";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void byteTypeEnvEntryInjectionShouldSucceedInCtxtListener() throws Exception {
+ final String expectedOutput = "Context: Total Quantity: 5";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void booleanTypeEnvEntryInjectionShouldSucceedInCtxtListener() throws Exception {
+ final String expectedOutput = "Context: Enable Email: true";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void charTypeEnvEntryInjectionShouldSucceedInCtxtListener() throws Exception {
+ final String expectedOutput = "Context: Option Default: X";
+ validateTest(expectedOutput);
+ }
+
+// @Test
+ public void classEnvEntryInjectionShouldSucceedInCtxtListener() throws Exception {
+ final String expectedOutput = "Context: java.lang.String";
+ validateTest(expectedOutput);
+ }
+
+// @Test
+ public void enumEnvEntryInjectionShouldSucceedInCtxtListener() throws Exception {
+ final String expectedOutput = "Context: DefaultCode: OK";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void localEjbInjectionShouldSucceedInSessionListener() throws Exception {
+ final String expectedOutput = "Session: Local: OpenEJB is employed at TomEE Software Inc.";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void localBeanEjbInjectionShouldSucceedInSessionListener() throws Exception {
+ final String expectedOutput = "Session: OpenEJB shops at Apache Marketplace";
+ validateTest(expectedOutput);
+ }
+
+// @Test
+ public void pojoInjectionShouldSucceedInSessionListener() throws Exception {
+ final String expectedOutput = "Session: OpenEJB is on the wheel of a 2011 Lexus IS 350";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void stringEnvEntryInjectionShouldSucceedInSessionListener() throws Exception {
+ final String expectedOutput = "Session: tomee@apache.org";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void integerTypeEnvEntryInjectionShouldSucceedInSessionListener() throws Exception {
+ final String expectedOutput = "Session: Connection Pool: 20";
+ validateTest(expectedOutput);
+ }
+
+// @Test
+ public void longTypeEnvEntryInjectionShouldSucceedInSessionListener() throws Exception {
+ final String expectedOutput = "Session: Start Count: 200000";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void shortTypeEnvEntryInjectionShouldSucceedInSessionListener() throws Exception {
+ final String expectedOutput = "Session: Init Size: 5";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void byteTypeEnvEntryInjectionShouldSucceedInSessionListener() throws Exception {
+ final String expectedOutput = "Session: Total Quantity: 5";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void booleanTypeEnvEntryInjectionShouldSucceedInSessionListener() throws Exception {
+ final String expectedOutput = "Session: Enable Email: true";
+ validateTest(expectedOutput);
+ }
+
+ @Test
+ public void charTypeEnvEntryInjectionShouldSucceedInSessionListener() throws Exception {
+ final String expectedOutput = "Session: Option Default: X";
+ validateTest(expectedOutput);
+ }
+
+// @Test
+ public void classEnvEntryInjectionShouldSucceedInSessionListener() throws Exception {
+ final String expectedOutput = "Session: java.lang.String";
+ validateTest(expectedOutput);
+ }
+
+// @Test
+ public void enumEnvEntryInjectionShouldSucceedInSessionListener() throws Exception {
+ final String expectedOutput = "Session: DefaultCode: OK";
+ validateTest(expectedOutput);
+ }
+
+ @Deployment(testable = false)
+ public static WebArchive createDeployment() {
+ final WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class)
+ .version("3.0")
+ .listener(PojoServletContextListener.class)
+ .listener(PojoServletSessionListener.class)
+ .servlet(ServletToCheckListener.class, "/" + TEST_NAME);
+
+ addEnvEntry(descriptor, "returnEmail", "java.lang.String", "tomee@apache.org");
+ addEnvEntry(descriptor, "connectionPool", "java.lang.Integer", "20");
+ addEnvEntry(descriptor, "startCount", "java.lang.Long", "200000");
+ addEnvEntry(descriptor, "initSize", "java.lang.Short", "5");
+ addEnvEntry(descriptor, "enableEmail", "java.lang.Boolean", "true");
+ addEnvEntry(descriptor, "totalQuantity", "java.lang.Byte", "5");
+ addEnvEntry(descriptor, "optionDefault", "java.lang.Character", "X");
+ addEnvEntry(descriptor, "auditWriter", "java.lang.Class", "java.lang.String");
+ addEnvEntry(descriptor, "defaultCode", "java.lang.Enum", "org.apache.openejb.arquillian.ServletListenerPojoInjectionTest$Code.OK");
+
+ final WebArchive archive = ShrinkWrap.create(WebArchive.class, TEST_NAME + ".war")
+ .addClass(PojoServletContextListener.class)
+ .addClass(PojoServletSessionListener.class)
+ .addClass(ServletToCheckListener.class)
+ .addClass(Car.class)
+ .addClass(CompanyLocal.class)
+ .addClass(Company.class)
+ .addClass(DefaultCompany.class)
+ .addClass(SuperMarket.class)
+ .setWebXML(new StringAsset(descriptor.exportAsString()))
+ .addAsWebResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
+
+ System.err.println(descriptor.exportAsString());
+
+ return archive;
+ }
+
+ public static enum Code {
+ OK,
+ ERROR;
+ }
+
+ public static enum ContextAttributeName {
+ KEY_Car,
+ KEY_LocalEjb,
+ KEY_Market,
+ KEY_ConnPool,
+ KEY_StartCount,
+ KEY_InitSize,
+ KEY_TotalQuantity,
+ KEY_EnableEmail,
+ KEY_DefaultOption,
+ KEY_ReturnEmail,
+ KEY_AuditWriter,
+ KEY_DefaultCode,;
+ }
+
+ public static class ServletToCheckListener extends HttpServlet {
+
+ @Override
+ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ final ServletContext ctxt = req.getServletContext();
+ for (ContextAttributeName s : ContextAttributeName.values()) {
+ resp.getOutputStream().println("Context: " + ctxt.getAttribute(s.name()));
+ }
+
+ final HttpSession session = req.getSession();
+ for (ContextAttributeName s : ContextAttributeName.values()) {
+ resp.getOutputStream().println("Session: " + session.getAttribute(s.name()));
+ }
+ }
+ }
+
+ public static class PojoServletContextListener implements ServletContextListener {
+
+ @Inject
+ private Car car;
+
+ @EJB
+ private CompanyLocal localCompany;
+
+ @EJB
+ private SuperMarket market;
+
+ @Resource(name = "returnEmail")
+ private String returnEmail;
+
+ @Resource(name = "connectionPool")
+ private Integer connectionPool;
+
+ @Resource(name = "startCount")
+ private Long startCount;
+
+ @Resource(name = "initSize")
+ private Short initSize;
+
+ @Resource(name = "totalQuantity")
+ private Byte totalQuantity;
+
+ @Resource(name = "enableEmail")
+ private Boolean enableEmail;
+
+ @Resource(name = "optionDefault")
+ private Character optionDefault;
+
+ /* TODO: Enable this resource after functionality is fixed
+ @Resource
+ */
+ private Code defaultCode;
+
+ /* TODO: Enable this resource after functionality is fixed
+ @Resource
+ @SuppressWarnings("unchecked")
+ */
+ private Class auditWriter;
+
+
+ public void contextInitialized(ServletContextEvent event) {
+ final String name = "OpenEJB";
+ final ServletContext context = event.getServletContext();
+
+ if (car != null) {
+ context.setAttribute(ContextAttributeName.KEY_Car.name(), car.drive(name));
+ }
+ if (localCompany != null) {
+ context.setAttribute(ContextAttributeName.KEY_LocalEjb.name(), "Local: " + localCompany.employ(name));
+ }
+ if (market != null) {
+ context.setAttribute(ContextAttributeName.KEY_Market.name(), market.shop(name));
+ }
+ if (connectionPool != null) {
+ context.setAttribute(ContextAttributeName.KEY_ConnPool.name(), "Connection Pool: " + connectionPool);
+ }
+ if (startCount != null) {
+ context.setAttribute(ContextAttributeName.KEY_StartCount.name(), "Start Expressions.Count: " + startCount);
+ }
+ if (initSize != null) {
+ context.setAttribute(ContextAttributeName.KEY_InitSize.name(), "Init Size: " + initSize);
+ }
+ if (totalQuantity != null) {
+ context.setAttribute(ContextAttributeName.KEY_TotalQuantity.name(), "Total Quantity: " + totalQuantity);
+ }
+ if (enableEmail != null) {
+ context.setAttribute(ContextAttributeName.KEY_EnableEmail.name(), "Enable Email: " + enableEmail);
+ }
+ if (optionDefault != null) {
+ context.setAttribute(ContextAttributeName.KEY_DefaultOption.name(), "Option Default: " + optionDefault);
+ }
+ if (StringUtils.isNotEmpty(returnEmail) && returnEmail.equals("tomee@apache.org")) {
+ context.setAttribute(ContextAttributeName.KEY_ReturnEmail.name(), returnEmail);
+ }
+ if (auditWriter != null) {
+ context.setAttribute(ContextAttributeName.KEY_AuditWriter.name(), auditWriter.getClass().getName());
+ }
+ if (defaultCode != null) {
+ context.setAttribute(ContextAttributeName.KEY_DefaultCode.name(), "DefaultCode: " + defaultCode);
+ }
+ }
+
+ public void contextDestroyed(ServletContextEvent event) {
+ }
+
+ }
+
+ public static class PojoServletSessionListener implements HttpSessionListener {
+
+ @Inject
+ private Car car;
+
+ @EJB
+ private CompanyLocal localCompany;
+
+ @EJB
+ private SuperMarket market;
+
+ @Resource(name = "returnEmail")
+ private String returnEmail;
+
+ @Resource(name = "connectionPool")
+ private Integer connectionPool;
+
+ @Resource(name = "startCount")
+ private Long startCount;
+
+ @Resource(name = "initSize")
+ private Short initSize;
+
+ @Resource(name = "totalQuantity")
+ private Byte totalQuantity;
+
+ @Resource(name = "enableEmail")
+ private Boolean enableEmail;
+
+ @Resource(name = "optionDefault")
+ private Character optionDefault;
+
+ /* TODO: Enable this resource after functionality is fixed
+ @Resource
+ */
+ private Code defaultCode;
+
+ /* TODO: Enable this resource after functionality is fixed
+ @Resource
+ @SuppressWarnings("unchecked")
+ */
+ private Class auditWriter;
+
+
+ public void sessionCreated(HttpSessionEvent event) {
+ final String name = "OpenEJB";
+ final HttpSession context = event.getSession();
+
+ if (car != null) {
+ context.setAttribute(ContextAttributeName.KEY_Car.name(), car.drive(name));
+ }
+ if (localCompany != null) {
+ context.setAttribute(ContextAttributeName.KEY_LocalEjb.name(), "Local: " + localCompany.employ(name));
+ }
+ if (market != null) {
+ context.setAttribute(ContextAttributeName.KEY_Market.name(), market.shop(name));
+ }
+ if (connectionPool != null) {
+ context.setAttribute(ContextAttributeName.KEY_ConnPool.name(), "Connection Pool: " + connectionPool);
+ }
+ if (startCount != null) {
+ context.setAttribute(ContextAttributeName.KEY_StartCount.name(), "Start Expressions.Count: " + startCount);
+ }
+ if (initSize != null) {
+ context.setAttribute(ContextAttributeName.KEY_InitSize.name(), "Init Size: " + initSize);
+ }
+ if (totalQuantity != null) {
+ context.setAttribute(ContextAttributeName.KEY_TotalQuantity.name(), "Total Quantity: " + totalQuantity);
+ }
+ if (enableEmail != null) {
+ context.setAttribute(ContextAttributeName.KEY_EnableEmail.name(), "Enable Email: " + enableEmail);
+ }
+ if (optionDefault != null) {
+ context.setAttribute(ContextAttributeName.KEY_DefaultOption.name(), "Option Default: " + optionDefault);
+ }
+ if (StringUtils.isNotEmpty(returnEmail) && returnEmail.equals("tomee@apache.org")) {
+ context.setAttribute(ContextAttributeName.KEY_ReturnEmail.name(), returnEmail);
+ }
+ if (auditWriter != null) {
+ context.setAttribute(ContextAttributeName.KEY_AuditWriter.name(), auditWriter.getClass().getName());
+ }
+ if (defaultCode != null) {
+ context.setAttribute(ContextAttributeName.KEY_DefaultCode.name(), "DefaultCode: " + defaultCode);
+ }
+ }
+
+ public void sessionDestroyed(HttpSessionEvent event) {
+ }
+
+ }
+
+ public static class Car {
+ private final String make = "Lexus", model = "IS 350";
+ private final int year = 2011;
+
+ public String drive(String name) {
+ return name + " is on the wheel of a " + year + " " + make + " " + model;
+ }
+ }
+
+
+ public static interface Company {
+ public String employ(String employeeName);
+ }
+
+ @Local
+ public static interface CompanyLocal extends Company {
+ }
+
+ @Stateless
+ public static class DefaultCompany implements CompanyLocal {
+
+ private final String name = "TomEE Software Inc.";
+
+ public String employ(String employeeName) {
+ return employeeName + " is employed at " + name;
+ }
+
+ }
+
+ @Stateless
+ @LocalBean
+ public static class SuperMarket {
+
+ private final String name = "Apache Marketplace";
+
+ public String shop(String employeeName) {
+ return employeeName + " shops at " + name;
+ }
+
+ }
+
+ private static void addEnvEntry(WebAppDescriptor descriptor, String name, String type, String value) {
+ Node rootNode = ((NodeProvider) descriptor).getRootNode();
+ Node appNode = rootNode.get("/web-app").iterator().next();
+ appNode.create("/env-entry")
+ .create("env-entry-name").text(name)
+ .parent()
+ .create("env-entry-type").text(type)
+ .parent()
+ .create("env-entry-value").text(value)
+/*
+ .parent()
+ .create("injection-target")
+ .create("injection-target-class").text("org.apache.openejb.arquillian.ServletPojoInjectionTest$PojoServletContextListener")
+ .parent()
+ .create("injection-target-name").text(name)
+*/
+ ;
+
+ }
+
+ private void validateTest(String expectedOutput) throws IOException {
+ final InputStream is = new URL("http://localhost:9080/" + TEST_NAME + "/" + TEST_NAME).openStream();
+ final ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+ int bytesRead = -1;
+ byte[] buffer = new byte[8192];
+ while ((bytesRead = is.read(buffer)) > -1) {
+ os.write(buffer, 0, bytesRead);
+ }
+
+ is.close();
+ os.close();
+
+ String output = new String(os.toByteArray(), "UTF-8");
+ assertNotNull("Response shouldn't be null", output);
+ assertTrue("Output should contain: " + expectedOutput, output.contains(expectedOutput));
+ }
+
+}
+
+
+
Copied: openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerEjbRemoteTest.java (from r1165135, openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerRemoteEjbTest.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerEjbRemoteTest.java?p2=openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerEjbRemoteTest.java&p1=openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerRemoteEjbTest.java&r1=1165135&r2=1167385&rev=1167385&view=diff
==============================================================================
--- openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerRemoteEjbTest.java (original)
+++ openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerEjbRemoteTest.java Fri Sep 9 22:58:59 2011
@@ -45,9 +45,9 @@ import static junit.framework.Assert.ass
import static junit.framework.Assert.assertTrue;
@RunWith(Arquillian.class)
-public class ServletListenerRemoteEjbTest {
+public class ServletListenerEjbRemoteTest {
- public static final String TEST_NAME = ServletListenerRemoteEjbTest.class.getSimpleName();
+ public static final String TEST_NAME = ServletListenerEjbRemoteTest.class.getSimpleName();
@Test
public void ejbInjectionShouldSucceedInCtxtListener() throws Exception {
Copied: openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerEnvEntryInjectionTest.java (from r1165185, openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerPojoInjectionTest.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerEnvEntryInjectionTest.java?p2=openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerEnvEntryInjectionTest.java&p1=openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerPojoInjectionTest.java&r1=1165185&r2=1167385&rev=1167385&view=diff
==============================================================================
--- openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerPojoInjectionTest.java (original)
+++ openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/ServletListenerEnvEntryInjectionTest.java Fri Sep 9 22:58:59 2011
@@ -51,9 +51,9 @@ import static junit.framework.Assert.ass
import static junit.framework.Assert.assertTrue;
@RunWith(Arquillian.class)
-public class ServletListenerPojoInjectionTest {
+public class ServletListenerEnvEntryInjectionTest {
- public static final String TEST_NAME = ServletListenerPojoInjectionTest.class.getSimpleName();
+ public static final String TEST_NAME = ServletListenerEnvEntryInjectionTest.class.getSimpleName();
@Test
public void localEjbInjectionShouldSucceedInCtxtListener() throws Exception {