This is an automated email from the ASF dual-hosted git repository. jgallimore pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomee.git
The following commit(s) were added to refs/heads/master by this push: new 968a648 Adding test for EJB invokation from a JSP 968a648 is described below commit 968a648b09f3de0455723eab8e2fbc4441ca383a Author: Jonathan Gallimore <j...@jrg.me.uk> AuthorDate: Sat Jan 26 16:05:37 2019 +0000 Adding test for EJB invokation from a JSP --- .../apache/openejb/arquillian/tests/jsp/Data.java | 32 +++++++++ .../openejb/arquillian/tests/jsp/DataBusiness.java | 25 ++++++++ .../arquillian/tests/jsp/DataBusinessBean.java | 46 +++++++++++++ .../arquillian/tests/jsp/DataBusinessHome.java | 27 ++++++++ .../openejb/arquillian/tests/jsp/DataEarTest.java | 75 ++++++++++++++++++++++ .../openejb/arquillian/tests/jsp/ejb-jar.xml | 46 +++++++++++++ .../apache/openejb/arquillian/tests/jsp/test.jsp | 16 +++++ .../apache/openejb/arquillian/tests/jsp/web.xml | 32 +++++++++ 8 files changed, 299 insertions(+) diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/jsp/Data.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/jsp/Data.java new file mode 100644 index 0000000..2a7c01b --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/jsp/Data.java @@ -0,0 +1,32 @@ +/* + * 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.tests.jsp; + +import java.io.Serializable; + +public class Data implements Serializable { + + private String someText; + + public String getSomeText() { + return someText; + } + + public void setSomeText(String someText) { + this.someText = someText; + } +} diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/jsp/DataBusiness.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/jsp/DataBusiness.java new file mode 100644 index 0000000..c0dcca0 --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/jsp/DataBusiness.java @@ -0,0 +1,25 @@ +/* + * 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.tests.jsp; + +import javax.ejb.EJBObject; +import java.rmi.RemoteException; + + +public interface DataBusiness extends EJBObject { + Data doLogic(Data data) throws RemoteException; +} diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/jsp/DataBusinessBean.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/jsp/DataBusinessBean.java new file mode 100644 index 0000000..6e08aa9 --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/jsp/DataBusinessBean.java @@ -0,0 +1,46 @@ +/* + * 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.tests.jsp; + + +import javax.ejb.CreateException; +import javax.ejb.SessionBean; +import javax.ejb.SessionContext; + +public class DataBusinessBean implements SessionBean { + public Data doLogic(Data data) { + final Data clone = new Data(); + clone.setSomeText(data.getSomeText()); + + return clone; + } + + public void ejbCreate() throws CreateException { + } + + public void ejbActivate() { + } + + public void ejbPassivate() { + } + + public void ejbRemove() { + } + + public void setSessionContext(final SessionContext sc) { + } +} diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/jsp/DataBusinessHome.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/jsp/DataBusinessHome.java new file mode 100644 index 0000000..ac6fd6d --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/jsp/DataBusinessHome.java @@ -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. + */ + +package org.apache.openejb.arquillian.tests.jsp; + +import javax.ejb.CreateException; +import javax.ejb.EJBHome; +import java.rmi.RemoteException; + + +public interface DataBusinessHome extends EJBHome { + DataBusiness create() throws RemoteException, CreateException; +} diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/jsp/DataEarTest.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/jsp/DataEarTest.java new file mode 100644 index 0000000..c887bc9 --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/jsp/DataEarTest.java @@ -0,0 +1,75 @@ +/* + * 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.tests.jsp; + +import org.apache.ziplock.IO; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset; +import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.net.URL; + +/** + * @version $Rev$ $Date$ + */ +@RunWith(Arquillian.class) +public class DataEarTest { + + @ArquillianResource + private URL url; + + @Deployment(testable = false) + public static EnterpriseArchive createDeployment() { + + final JavaArchive clientJar = ShrinkWrap.create(JavaArchive.class, "client.jar") + .addClasses(Data.class, DataBusiness.class, DataBusinessHome.class); + + final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ejb-jar.jar") + .addClasses(DataBusinessBean.class) + .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/jsp/ejb-jar.xml"), "META-INF/ejb-jar.xml"); + + final WebArchive testWar = ShrinkWrap.create(WebArchive.class, "test.war") + .add(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/jsp/test.jsp"), "test.jsp") + .addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/jsp/web.xml"), "web.xml"); + + final EnterpriseArchive archive = ShrinkWrap.create(EnterpriseArchive.class, "test.ear") + .addAsLibrary(clientJar) + .addAsModule(ejbJar) + .addAsModule(testWar); + + System.out.println(archive.toString(true)); + return archive; + } + + + @Test + @RunAsClient + public void ejbCallFromJsp() throws Exception { + final String output = IO.slurp(new URL("http://" + url.getHost() + ":" + url.getPort() + "/test/test/test.jsp")); + System.out.println(output); + Assert.assertEquals("this is a test", output.trim()); + } +} \ No newline at end of file diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/jsp/ejb-jar.xml b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/jsp/ejb-jar.xml new file mode 100644 index 0000000..441a767 --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/jsp/ejb-jar.xml @@ -0,0 +1,46 @@ +<?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. +--> +<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" version="2.1" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"> + <display-name>RosterJAR</display-name> + <enterprise-beans> + <session> + <ejb-name>RosterBean</ejb-name> + <home>org.apache.openejb.arquillian.tests.jsp.DataBusinessHome</home> + <remote>org.apache.openejb.arquillian.tests.jsp.DataBusiness</remote> + <ejb-class>org.apache.openejb.arquillian.tests.jsp.DataBusinessBean</ejb-class> + <session-type>Stateless</session-type> + <transaction-type>Container</transaction-type> + <security-identity> + <use-caller-identity/> + </security-identity> + </session> + </enterprise-beans> + <assembly-descriptor> + <container-transaction> + <method> + <ejb-name>RosterBean</ejb-name> + <method-intf>Remote</method-intf> + <method-name>*</method-name> + </method> + <trans-attribute>Required</trans-attribute> + </container-transaction> + </assembly-descriptor> +</ejb-jar> diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/jsp/test.jsp b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/jsp/test.jsp new file mode 100644 index 0000000..05ab5a2 --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/jsp/test.jsp @@ -0,0 +1,16 @@ +<%@ page import="javax.naming.InitialContext"%><%@ page import="java.util.Properties"%><%@ page import="javax.naming.Context"%><%@ page import="org.apache.openejb.arquillian.tests.jsp.DataBusinessHome"%><%@ page import="javax.rmi.PortableRemoteObject"%><%@ page import="org.apache.openejb.arquillian.tests.jsp.DataBusiness"%><%@ page import="org.apache.openejb.arquillian.tests.jsp.Data"%><%@ page contentType="text/plain;charset=UTF-8" language="java" %> +<% + + final Properties p = new Properties(); + p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory"); + + final InitialContext initialContext = new InitialContext(p); + Object lookup = initialContext.lookup("java:comp/env/ejb/DataBusiness"); + DataBusinessHome home = (DataBusinessHome) PortableRemoteObject.narrow(lookup, DataBusinessHome.class); + + final DataBusiness dataBusiness = home.create(); + final Data data = new Data(); + data.setSomeText("this is a test"); + Data echoedData = dataBusiness.doLogic(data); +%> +<%= echoedData.getSomeText() %> \ No newline at end of file diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/jsp/web.xml b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/jsp/web.xml new file mode 100644 index 0000000..94bb85d --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/jsp/web.xml @@ -0,0 +1,32 @@ +<?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. +--> +<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://java.sun.com/xml/ns/javaee" + xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee + http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" + id="WebApp_ID" version="2.5"> + + <ejb-ref> + <ejb-ref-name>ejb/DataBusiness</ejb-ref-name> + <ejb-ref-type>Session</ejb-ref-type> + <home>org.apache.openejb.arquillian.tests.jsp.DataBusinessHome</home> + <remote>org.apache.openejb.arquillian.tests.jsp.DataBusiness</remote> + </ejb-ref> +</web-app> \ No newline at end of file