Initial Contribution Signed-off-by: Vinay Vishal <vinay.vishal@oracle.com>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/README.md b/appserver/tests/appserv-tests/devtests/cdi/README.md new file mode 100644 index 0000000..c5cad8e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/README.md
@@ -0,0 +1,59 @@ +CDI developer tests README +========================== + +To checkout CDI devtests +------------------------ +- checkout CDI developer tests using the following commands: +svn -N co https://svn.java.net/svn/glassfish~svn/trunk/v2/appserv-tests +cd appserv-tests #this is the directory set later to APS_HOME +svn co https://svn.java.net/svn/glassfish~svn/trunk/v2/appserv-tests/config +svn co https://svn.java.net/svn/glassfish~svn/trunk/v2/appserv-tests/lib +svn co https://svn.java.net/svn/glassfish~svn/trunk/v2/appserv-tests/util +svn -N co https://svn.java.net/svn/glassfish~svn/trunk/v2/appserv-tests/devtests +cd devtests +svn co https://svn.java.net/svn/glassfish~svn/trunk/v2/appserv-tests/devtests/cdi + +Test setup +---------- +- set S1AS_HOME, APS_HOME as appropriate +export APS_HOME=<appserv-tests> directory +export S1AS_HOME=<GlassFish Installation> directory +- start GlassFish +$S1AS_HOME/bin/asadmin start-domain domain1 +- start Derby +$S1AS_HOME/bin/asadmin start-database + +To run all CDI developer tests +------------------------------ +- cd $APS_HOME/devtests/cdi +- ant all +- results can be found at APS_HOME/test_results.html + + +Test setup teardown +------------------- +- stop GlassFish +$S1AS_HOME/bin/asadmin stop-domain domain1 +- asadmin stop-database +$S1AS_HOME/bin/asadmin stop-database + +To run a single CDI developer test +---------------------------------- +- after performing tasks under "Test setup" +- cd $APS_HOME/devtests/cdi/[test-dir] +- ant all +- perform tasks listed under "Test setup teardown" + +To run CDI developer test suite with Security Manager on +--------------------------------------------------------- +- start domain and enable security manager by +asadmin create-jvm-options -Djava.security.manager +- stop domain +- Add the following permission block to $S1AS_HOME/domains/domain1/config/server.policy +grant codeBase "file:${com.sun.aas.instanceRoot}/applications/-" { + permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; +}; +- restart domain +- run tests + +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/README_Embedded.txt b/appserver/tests/appserv-tests/devtests/cdi/README_Embedded.txt new file mode 100644 index 0000000..0b349d3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/README_Embedded.txt
@@ -0,0 +1,25 @@ +export APS_HOME=<Your-Workspace>/v2/appserv-tests + +export S1AS_HOME=<installed-glassfish> (eg.,, /tmp/glassfish5/glassfish) + +export ANT_OPTS="-Xss128k -Xmx2048m -XX:MaxPermSize=256m" + +export CDI_TESTHOME=$APS_HOME/devtests/cdi +export CDI_TESTRUNLOG=$CDI_TESTHOME/cditests-run.log +export CDITESTSUMMARY=$CDI_TESTHOME/cditests-summary.log + +Download ant-tasks.jar[1] and copy it under /tmp + +export CLASSPATH=/tmp/ant-tasks-3.1.1-SNAPSHOT.jar:$S1AS_HOME/lib/embedded/glassfish-embedded-static-shell.jar:$S1AS_HOME/lib/gf-client.jar:$CLASSPATH + +export GF_EMBEDDED_ENABLE_CLI=true + +cp $APS_HOME/devtests/embedded/config/common.xml $APS_HOME/config +cp $APS_HOME/devtests/embedded/config/run.xml $APS_HOME/config + +cd $APS_HOME/devtests/cdi + +########## Running CDI tests ######### +ant start-server all stop-server + +[1] http://maven.glassfish.org/content/groups/glassfish/org/glassfish/ant-tasks/3.1.1-SNAPSHOT/ant-tasks-3.1.1-SNAPSHOT.jar
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/README b/appserver/tests/appserv-tests/devtests/cdi/alternatives/README new file mode 100644 index 0000000..0dcab93 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/README
@@ -0,0 +1,2 @@ +Test +- Alternatives: MockPaymentProcessor is an Alternative that is enabled through beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/alternatives/WebTest.java new file mode 100644 index 0000000..4505147 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/WebTest.java
@@ -0,0 +1,105 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "alternatives-tests"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Testing Alternatives"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + System.out.println("TESTNAME " + TEST_NAME); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/build.properties b/appserver/tests/appserv-tests/devtests/cdi/alternatives/build.properties new file mode 100644 index 0000000..317b372 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi-alternatives"/> +<property name="appname" value="${module}-servlet-annotation"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/build.xml b/appserver/tests/appserv-tests/devtests/cdi/alternatives/build.xml new file mode 100644 index 0000000..c0d904d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/alternatives/descriptor/beans.xml new file mode 100644 index 0000000..c0da4fc --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/descriptor/beans.xml
@@ -0,0 +1,26 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <alternatives> + <class>test.artifacts.MockPaymentProcessor</class> + </alternatives> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/AlternativesServlet.java b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/AlternativesServlet.java new file mode 100644 index 0000000..77bee4e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/AlternativesServlet.java
@@ -0,0 +1,70 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.artifacts.Asynchronous; +import test.artifacts.AsynchronousPaymentProcessor; +import test.artifacts.MockPaymentProcessor; +import test.artifacts.PaymentProcessor; +import test.artifacts.Synchronous; +import test.artifacts.SynchronousPaymentProcessor; +import test.beans.BeanToTestAlternatives; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }, initParams = { + @WebInitParam(name = "n1", value = "v1"), + @WebInitParam(name = "n2", value = "v2") }) +public class AlternativesServlet extends HttpServlet { + + @Inject + BeanToTestAlternatives tb; + + @Inject + @Synchronous + PaymentProcessor synchronousPaymentProcessor; + @Inject + @Asynchronous + PaymentProcessor asynchronousPaymentProcessor; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + ", n2=" + + getInitParameter("n2"); + + if (!tb.testInjection()) + msg += "Alternatives injection and test for availability of other beans via @Any Failed"; + + //In the case of ambiguous dependencies such as synchronous and asynchronous payment processors + //the enabled alternative wins + boolean qualifierTestSuccess = synchronousPaymentProcessor instanceof MockPaymentProcessor + && asynchronousPaymentProcessor instanceof MockPaymentProcessor; + if (!qualifierTestSuccess) + msg += "Qualifier based injection into Servlet Failed"; + + writer.write("initParams: " + msg + "\n"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/Asynchronous.java b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/Asynchronous.java new file mode 100644 index 0000000..ca0dd14 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/Asynchronous.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) + +public @interface Asynchronous { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/AsynchronousPaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/AsynchronousPaymentProcessor.java new file mode 100644 index 0000000..9e0c62b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/AsynchronousPaymentProcessor.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +@Asynchronous +public class AsynchronousPaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/CashReliablePaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/CashReliablePaymentProcessor.java new file mode 100644 index 0000000..a72f9db --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/CashReliablePaymentProcessor.java
@@ -0,0 +1,27 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +@PayBy(value=PaymentMethod.CASH) @Reliable +//To test multiple qualifiers +public class CashReliablePaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/ChequePaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/ChequePaymentProcessor.java new file mode 100644 index 0000000..9fe824b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/ChequePaymentProcessor.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +@PayBy(PaymentMethod.CHEQUE) +public class ChequePaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/MockPaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/MockPaymentProcessor.java new file mode 100644 index 0000000..8d736e2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/MockPaymentProcessor.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +import javax.enterprise.inject.Alternative; + +@Alternative @Asynchronous @Synchronous +public class MockPaymentProcessor implements PaymentProcessor{ + + @Override + public boolean processPayment() { + return true; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/PayBy.java b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/PayBy.java new file mode 100644 index 0000000..179aca6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/PayBy.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.enterprise.util.Nonbinding; +import javax.inject.Qualifier; + +@Qualifier +@Target( { TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface PayBy { + PaymentMethod value() default PaymentMethod.CHEQUE; + + @Nonbinding + String comment() default ""; // A Non-Binding member. Is ignored during + // dependency resolution +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/PaymentMethod.java b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/PaymentMethod.java new file mode 100644 index 0000000..82e7eb6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/PaymentMethod.java
@@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +public enum PaymentMethod { + CHEQUE, CASH +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/PaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/PaymentProcessor.java new file mode 100644 index 0000000..3e25336 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/PaymentProcessor.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +public interface PaymentProcessor { + boolean processPayment(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/Reliable.java b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/Reliable.java new file mode 100644 index 0000000..8ece693 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/Reliable.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Reliable { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/Synchronous.java b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/Synchronous.java new file mode 100644 index 0000000..b4c5d7e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/Synchronous.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Synchronous { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/SynchronousPaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/SynchronousPaymentProcessor.java new file mode 100644 index 0000000..921cd3e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/artifacts/SynchronousPaymentProcessor.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +@Synchronous +public class SynchronousPaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/beans/BeanToTestAlternatives.java b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/beans/BeanToTestAlternatives.java new file mode 100644 index 0000000..a640949 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/alternatives/servlet/test/beans/BeanToTestAlternatives.java
@@ -0,0 +1,55 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.inject.Any; +import javax.enterprise.inject.Instance; +import javax.inject.Inject; + +import test.artifacts.Asynchronous; +import test.artifacts.MockPaymentProcessor; +import test.artifacts.PaymentProcessor; +import test.artifacts.Synchronous; + +//Alternatives injection and test for availability of other beans via @Any Failed +public class BeanToTestAlternatives { + private int numberOfPaymentProcessors = 0; + + @Inject + @Asynchronous + @Synchronous + private PaymentProcessor pp; + + @Inject + public void init(@Any Instance<PaymentProcessor> payInstances) { + for (PaymentProcessor p : payInstances) { + System.out.println("Payment Processor #" + + numberOfPaymentProcessors + ":" + p); + numberOfPaymentProcessors++; + } + } + + public boolean testInjection() { + System.out.println("# of Payment processors:" + + numberOfPaymentProcessors); + System.out.println("mock payment procssor:" + pp); + return (numberOfPaymentProcessors == 5) + && (pp instanceof MockPaymentProcessor); // Async, Sync, Cheque, + // ReliableCash, + // MockPaymentProcessor + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/README b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/README new file mode 100644 index 0000000..a53d83b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/README
@@ -0,0 +1,5 @@ +Test +- Ensure that presence of disabled alternatives do not result in ambiguous +dependencies +- Ensure that the presence of disabled alternatives do not result in appearance +of @Any
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/WebTest.java new file mode 100644 index 0000000..844c2a8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/WebTest.java
@@ -0,0 +1,105 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "ambiguous-dependencies-tests"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Testing Ambiguous dependencies"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + System.out.println("TESTNAME " + TEST_NAME); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/build.properties b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/build.properties new file mode 100644 index 0000000..2b73b98 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi-ambiguousdeps"/> +<property name="appname" value="${module}-servlet-annotation"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/build.xml b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/build.xml new file mode 100644 index 0000000..c0d904d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/descriptor/beans.xml new file mode 100644 index 0000000..19f070f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/descriptor/beans.xml
@@ -0,0 +1,33 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <alternatives> + <class>test.artifacts.MockPaymentProcessor</class> + <!-- DisabledMockPaymentProcessor is not enabled --> + <!-- + <class>test.artifacts.DisabledMockPaymentProcessor</class> + --> + + <!-- MockCashReliablePaymentProcessor and MockChequePaymentProcessor are not enabled --> + </alternatives> + +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/AmbiguousDependenciesServlet.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/AmbiguousDependenciesServlet.java new file mode 100644 index 0000000..f66b468 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/AmbiguousDependenciesServlet.java
@@ -0,0 +1,70 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.artifacts.Asynchronous; +import test.artifacts.AsynchronousPaymentProcessor; +import test.artifacts.MockPaymentProcessor; +import test.artifacts.PaymentProcessor; +import test.artifacts.Synchronous; +import test.artifacts.SynchronousPaymentProcessor; +import test.beans.BeanToTestAmbiguousDependencies; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }, initParams = { + @WebInitParam(name = "n1", value = "v1"), + @WebInitParam(name = "n2", value = "v2") }) +public class AmbiguousDependenciesServlet extends HttpServlet { + + @Inject + BeanToTestAmbiguousDependencies tb; + + @Inject + @Synchronous + PaymentProcessor synchronousPaymentProcessor; + @Inject + @Asynchronous + PaymentProcessor asynchronousPaymentProcessor; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + ", n2=" + + getInitParameter("n2"); + + if (!tb.testInjection()) + msg += "Alternatives injection and test for availability of other beans via @Any Failed"; + + //In the case of ambiguous dependencies such as synchronous and asynchronous payment processors + //the enabled alternative wins + boolean qualifierTestSuccess = synchronousPaymentProcessor instanceof MockPaymentProcessor + && asynchronousPaymentProcessor instanceof MockPaymentProcessor; + if (!qualifierTestSuccess) + msg += "Qualifier based injection into Servlet Failed"; + + writer.write("initParams: " + msg + "\n"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/Asynchronous.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/Asynchronous.java new file mode 100644 index 0000000..ca0dd14 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/Asynchronous.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) + +public @interface Asynchronous { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/AsynchronousPaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/AsynchronousPaymentProcessor.java new file mode 100644 index 0000000..9e0c62b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/AsynchronousPaymentProcessor.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +@Asynchronous +public class AsynchronousPaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/CashReliablePaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/CashReliablePaymentProcessor.java new file mode 100644 index 0000000..a72f9db --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/CashReliablePaymentProcessor.java
@@ -0,0 +1,27 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +@PayBy(value=PaymentMethod.CASH) @Reliable +//To test multiple qualifiers +public class CashReliablePaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/ChequePaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/ChequePaymentProcessor.java new file mode 100644 index 0000000..9fe824b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/ChequePaymentProcessor.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +@PayBy(PaymentMethod.CHEQUE) +public class ChequePaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/DisabledMockPaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/DisabledMockPaymentProcessor.java new file mode 100644 index 0000000..4f1a98f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/DisabledMockPaymentProcessor.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +import javax.enterprise.inject.Alternative; + +@Alternative +@Asynchronous +@Synchronous +//Not enabled via beans.xml +public class DisabledMockPaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return true; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/MockCashReliablePaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/MockCashReliablePaymentProcessor.java new file mode 100644 index 0000000..a986225 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/MockCashReliablePaymentProcessor.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +import javax.enterprise.inject.Alternative; + + +@Alternative @PayBy(value=PaymentMethod.CASH) @Reliable +//To test multiple qualifiers +//Not enabled via beans.xml +public class MockCashReliablePaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/MockChequePaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/MockChequePaymentProcessor.java new file mode 100644 index 0000000..e00b802 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/MockChequePaymentProcessor.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +import javax.enterprise.inject.Alternative; + +@Alternative @PayBy(PaymentMethod.CHEQUE) +//Not enabled via beans.xml +public class MockChequePaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/MockPaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/MockPaymentProcessor.java new file mode 100644 index 0000000..8d736e2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/MockPaymentProcessor.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +import javax.enterprise.inject.Alternative; + +@Alternative @Asynchronous @Synchronous +public class MockPaymentProcessor implements PaymentProcessor{ + + @Override + public boolean processPayment() { + return true; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/PayBy.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/PayBy.java new file mode 100644 index 0000000..179aca6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/PayBy.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.enterprise.util.Nonbinding; +import javax.inject.Qualifier; + +@Qualifier +@Target( { TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface PayBy { + PaymentMethod value() default PaymentMethod.CHEQUE; + + @Nonbinding + String comment() default ""; // A Non-Binding member. Is ignored during + // dependency resolution +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/PaymentMethod.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/PaymentMethod.java new file mode 100644 index 0000000..82e7eb6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/PaymentMethod.java
@@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +public enum PaymentMethod { + CHEQUE, CASH +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/PaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/PaymentProcessor.java new file mode 100644 index 0000000..3e25336 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/PaymentProcessor.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +public interface PaymentProcessor { + boolean processPayment(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/Reliable.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/Reliable.java new file mode 100644 index 0000000..8ece693 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/Reliable.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Reliable { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/Synchronous.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/Synchronous.java new file mode 100644 index 0000000..b4c5d7e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/Synchronous.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Synchronous { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/SynchronousPaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/SynchronousPaymentProcessor.java new file mode 100644 index 0000000..921cd3e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/artifacts/SynchronousPaymentProcessor.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +@Synchronous +public class SynchronousPaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/beans/BeanToTestAmbiguousDependencies.java b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/beans/BeanToTestAmbiguousDependencies.java new file mode 100644 index 0000000..438d3b9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/ambiguous-deps/servlet/test/beans/BeanToTestAmbiguousDependencies.java
@@ -0,0 +1,55 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.inject.Any; +import javax.enterprise.inject.Instance; +import javax.inject.Inject; + +import test.artifacts.Asynchronous; +import test.artifacts.MockPaymentProcessor; +import test.artifacts.PaymentProcessor; +import test.artifacts.Synchronous; + +//Alternatives injection and test for availability of other beans via @Any Failed +public class BeanToTestAmbiguousDependencies { + private int numberOfPaymentProcessors = 0; + + @Inject + @Asynchronous + @Synchronous + private PaymentProcessor pp; + + @Inject + public void init(@Any Instance<PaymentProcessor> payInstances) { + for (PaymentProcessor p : payInstances) { + System.out.println("Payment Processor #" + + numberOfPaymentProcessors + ":" + p); + numberOfPaymentProcessors++; + } + } + + public boolean testInjection() { + System.out.println("# of Payment processors:" + + numberOfPaymentProcessors); + System.out.println("mock payment procssor:" + pp); + return (numberOfPaymentProcessors == 5) + && (pp instanceof MockPaymentProcessor); // Async, Sync, Cheque, + // ReliableCash, + // MockPaymentProcessor + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/build.xml b/appserver/tests/appserv-tests/devtests/cdi/build.xml new file mode 100644 index 0000000..0d9d960 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/build.xml
@@ -0,0 +1,244 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../config/common.xml"> +<!ENTITY commonRun SYSTEM "./../../config/run.xml"> +<!ENTITY reporting SYSTEM "./report.xml"> +]> + +<project name="cdi" default="usage" basedir="."> + + &commonSetup; + &commonBuild; + &commonRun; + &reporting; + + <property name="cdi-target" value="all"/> + + <taskdef resource="net/sf/antcontrib/antcontrib.properties"> + <classpath> + <pathelement location="${env.APS_HOME}/devtests/cdi/lib/ant-contrib-1.0b3.jar"/> + </classpath> + </taskdef> + + <target name="pe-all"> + <antcall target="backup-config-pe"/> + <echo message="NOTE: The file ${env.APS_HOME}/config.properties is being replaced with ${basedir}/config/pe-config.properties. The file will be reverted to its original state after the completion of these tests."/> + <copy file="${basedir}/config/pe-config.properties" tofile="${env.APS_HOME}/config.properties" overwrite="true"/> + <antcall target="create-pe-passwordfile"/> + <antcall target="all"/> + <antcall target="restore-config-pe"/> + </target> + + <target name="das-all"> + <antcall target="backup-config-pe"/> + <echo message="NOTE: The file ${env.APS_HOME}/config.properties is being replaced with ${basedir}/config/das-config.properties. The file will be reverted to its original state after the completion of these tests."/> + <copy file="${basedir}/config/das-config.properties" tofile="${env.APS_HOME}/config.properties" overwrite="true"/> + <antcall target="create-ee-passwordfile"/> + <antcall target="all"/> + <antcall target="restore-config-pe"/> + </target> + + <target name="ee-all"> + <antcall target="backup-config-pe"/> + <antcall target="backup-config-ee"/> + <echo message="NOTE: The file ${env.APS_HOME}/config.properties is being replaced with ${basedir}/config/das-config.properties. The file will be reverted to its original state after the completion of these tests."/> + <copy file="${basedir}/config/ee-config.properties" tofile="${env.APS_HOME}/config.properties" overwrite="true"/> + <copy file="${basedir}/config/ee-config.properties" tofile="${env.APS_HOME}/eeconfig/ee-config.properties" overwrite="true"/> + <antcall target="create-ee-passwordfile"/> + <antcall target="ee"/> + <antcall target="all"/> + <antcall target="restore-config-pe"/> + <antcall target="restore-config-ee"/> + </target> + + <target name="backup-config-pe" depends="replace-password-with-passwordfile"> + <copy file="${env.APS_HOME}/config.properties" tofile="${env.APS_HOME}/config.properties.bak" overwrite="true"/> + </target> + + <target name="restore-config-pe" depends="undo-replace-password-with-passwordfile"> + <copy file="${env.APS_HOME}/config.properties.bak" tofile="${env.APS_HOME}/config.properties" overwrite="true"/> + </target> + + <target name="backup-config-ee"> + <copy file="${env.APS_HOME}/eeconfig/ee-config.properties" tofile="${env.APS_HOME}/eeconfig/ee-config.properties.bak" overwrite="true"/> + </target> + + <target name="restore-config-ee"> + <copy file="${env.APS_HOME}/eeconfig/ee-config.properties.bak" tofile="${env.APS_HOME}/eeconfig/ee-config.properties" overwrite="true"/> + </target> + + <target name="create-pe-passwordfile"> + <property file="${env.APS_HOME}/config.properties"/> + <echo message="AS_ADMIN_PASSWORD=${admin.password}${line.separator}" file="${env.APS_HOME}/devtests/cdi/config/password.txt"/> + </target> + + <target name="create-ee-passwordfile"> + <property file="${env.APS_HOME}/config.properties"/> + <echo message="AS_ADMIN_PASSWORD=${admin.password}${line.separator}" file="${env.APS_HOME}/devtests/cdi/config/password.txt"/> + <echo message="AS_ADMIN_MASTERPASSWORD=${master.password}${line.separator}" file="${env.APS_HOME}/devtests/cdi/config/password.txt" append="true"/> + </target> + + <target name="replace-password-with-passwordfile"> + <replace dir="${env.APS_HOME}/config/"> + <include name="**/*.xml"/> + <replacetoken>--password ${admin.password}</replacetoken> + <replacevalue>--passwordfile ${env.APS_HOME}/devtests/cdi/config/password.txt</replacevalue> + </replace> + </target> + + <target name="undo-replace-password-with-passwordfile"> + <replace dir="${env.APS_HOME}/config/"> + <include name="**/*.xml"/> + <replacetoken>--passwordfile ${env.APS_HOME}/devtests/cdi/config/password.txt</replacetoken> + <replacevalue>--password ${admin.password}</replacevalue> + </replace> + </target> + + <target name="run-test"> + <antcall target="cdi"> + <param name="cdi-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="cdi"> + <param name="cdi-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="cdi"> + <param name="cdi-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="cdi"> + <param name="cdi-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="cdi"> + <param name="cdi-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="cdi"> + <param name="cdi-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="cdi"> + <param name="cdi-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="cdi"> + <param name="cdi-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="cdi"> + <param name="cdi-target" value="run"/> + </antcall> + </target> + + <target name="cdi"> + <record name="cdi.output" action="start" /> + <echo message="@@## Running all CDI developer tests##@@"/> + <ant dir="smoke-tests" target="${cdi-target}"/> + <ant dir="qualifiers" target="${cdi-target}"/> + + <!-- + Not running until https://issues.jboss.org/browse/CDI-331 is sorted out. + In 1.1.10.Final the test passes. + In 2.0 Beta it fails. + See email from Jozef 3/4/13 + <ant dir="alternatives" target="${cdi-target}"/> + <ant dir="ambiguous-deps" target="${cdi-target}"/> + --> + <ant dir="events" target="${cdi-target}"/> + <ant dir="injection-point" target="${cdi-target}"/> + <ant dir="interceptors" target="${cdi-target}"/> + <ant dir="javaee-component-resources" target="${cdi-target}"/> + <ant dir="javaee-integration" target="${cdi-target}"/> + <ant dir="managed-beans" target="${cdi-target}"/> + <ant dir="portable-extensions" target="${cdi-target}"/> + <ant dir="producer-methods" target="${cdi-target}"/> + + <!-- + Not running until https://issues.jboss.org/browse/CDI-331 is sorted out. + In 1.1.10.Final the test passes. + In 2.0 Beta it fails. + See email from Jozef 3/4/13 + <ant dir="programmatic-lookup" target="${cdi-target}"/> + --> + + <ant dir="scopes" target="${cdi-target}"/> + <ant dir="specialization" target="${cdi-target}"/> + <ant dir="stereotypes" target="${cdi-target}"/> + <ant dir="transactions" target="${cdi-target}"/> + <ant dir="unproxyable-deps" target="${cdi-target}"/> + <ant dir="unsatisfied-deps" target="${cdi-target}"/> + + <ant dir="implicit" target="${cdi-target}"/> + + <if> + <equals arg1="${test.embedded.mode}" arg2="true"/> + <then> + <echo> Excluding testcase directory osgi-cdi for embedded mode</echo> + </then> + <else> + <ant dir="osgi-cdi" target="${cdi-target}"/> + </else> + </if> + <!-- now generate report --> + <antcall target="report"/> + + <record name="cdi.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant cdi (Executes the cdi tests) + ant all (Executes all the cdi tests) + ant clean (cleans all the cdi tests) + ant build (builds all the cdi tests) + ant setup (sets up all resources for cdi tests) + ant deploy (deploys all the cdi apps) + ant run (Executes all the cdi tests) + ant undeploy (undeploys all the cdi apps) + ant unsetup (unsets all resources for cdi tests) + </echo> + </target> + + <target name="report-local"> + <exec executable="sh"> + <arg value="./resultCount.sh"/> + </exec> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/config/alltables_oracle.sql b/appserver/tests/appserv-tests/devtests/cdi/config/alltables_oracle.sql new file mode 100644 index 0000000..82a61d0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/config/alltables_oracle.sql
@@ -0,0 +1,3 @@ +-- droping all tables from the current user db +-- delete from user_tables; +select 'drop table', table_name,'cascade constraints;' from user_tables;
diff --git a/appserver/tests/appserv-tests/devtests/cdi/config/das-config.properties b/appserver/tests/appserv-tests/devtests/cdi/config/das-config.properties new file mode 100644 index 0000000..e0f75f7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/config/das-config.properties
@@ -0,0 +1,53 @@ +# +# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + + +execution.mode=pe +admin.port=4849 +admin.user=admin +admin.host=localhost +admin.domain=domain1 +admin.domain.dir=${env.S1AS_HOME}/domains +activeconsumer.maxnum=1 +mail.host="ha21sca.sfbay.sun.com" +http.port=8080 +http.host=localhost +https.host=localhost +https.port=8181 +orb.port=3700 +admin.password=admin123 +master.password=admin123 +appserver.instance.name=server +appserver.config.name=server-config +directory.server.host=localhost +directory.server.port=389 +directory.server.basedn=dc=sfbay,dc=sun,dc=com +directory.manager.dn=cn=Directory Manager +directory.manager.pwd=directorymanager +server.dir=home/results/s1aspe80 +log.server.location=sardinia.sfbay.sun.com +win.map.drive=Q: +results.mailer=abc@sun.com +results.mailee=xyz@sun.com +interop.admin.port=5858 +interop.admin.host=localhost +interop.admin.domain=domain2 +interop.http.port=9090 +interop.http.host=localhost +interop.https.port=2043 +interop.orb.port=4700 +isInteropDomain=true +resources.dottedname.prefix=server.resources
diff --git a/appserver/tests/appserv-tests/devtests/cdi/config/database.xml b/appserver/tests/appserv-tests/devtests/cdi/config/database.xml new file mode 100644 index 0000000..d4d1fb0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/config/database.xml
@@ -0,0 +1,123 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!-- +<!DOCTYPE project [ + <!ENTITY common SYSTEM "file:../../../config/common.xml"> + <!ENTITY testcommon SYSTEM "file:../../../config/properties.xml"> +]> +--> +<!-- ============================ --> +<!-- ORACLE SETUP FOR CONPOOL --> +<!-- ============================ --> +<!-- +<project name="oracle-db-settings" default="create-jdbc-conpool-connector" basedir="."> + +&common; +&testcommon; +--> + +<target name="create-jdbc-conpool-connector" depends="default-jdbc-conpool, oracle-jdbc-conpool"/> + +<target name="default-jdbc-conpool" depends="init-common" unless="oracle"> + <antcall target="create-jdbc-connpool-common"/> +</target> + +<target name="oracle-jdbc-conpool" depends="init-common" if="oracle"> +<echo message="creating jdbc connection pool ${jdbc.conpool.name}" + level="verbose"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="create-jdbc-connection-pool"/> + <arg line="--datasourceclassname ${db.class}"/> + <arg line="--restype ${jdbc.resource.type}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${as.props}"/> + <arg line="${jdbc.conpool.name}"/> + </exec> + <antcall target="set-oracle-props"> + <param name="pool.type" value="jdbc"/> + <param name="conpool.name" value="${jdbc.conpool.name}"/> + </antcall> +</target> + +<target name="set-oracle-props" depends="init-common" if="oracle"> + <property file="${env.APS_HOME}/devtests/connector/config/oracle.properties"/> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.${pool.type}-connection-pool.${conpool.name}.property.ServerName=${oracleForConnector.host}"/> + </antcall> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.${pool.type}-connection-pool.${conpool.name}.property.PortNumber=${oracleForConnector.port}" /> + </antcall> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.${pool.type}-connection-pool.${conpool.name}.property.DatabaseName='jdbc:sun:oracle://${oracleForConnector.host}:${oracleForConnector.port};SID=${oracleForConnector.sid}' " /> + </antcall> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.${pool.type}-connection-pool.${conpool.name}.property.ClassName=${oracleForConnector.dbclass}" /> + </antcall> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.${pool.type}-connection-pool.${conpool.name}.property.SID=${oracleForConnector.sid}" /> + </antcall> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.${pool.type}-connection-pool.${conpool.name}.property.User=${oracleForConnector.user}" /> + </antcall> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.${pool.type}-connection-pool.${conpool.name}.property.Password=${oracleForConnector.pwd}" /> + </antcall> +</target> + + +<target name="execute-sql-connector" depends="init-common, default-sql, sql-oracle"/> + +<target name="default-sql" depends="init-common" unless="oracle" > + <antcall target="execute-sql-common"/> +</target> + +<target name="sql-oracle" depends="init-common" if="oracle"> + <property file="${env.APS_HOME}/devtests/connector/config/oracle.properties"/> + <property name="domain.lib.ext" value="${env.S1AS_HOME}/domains/domain1/lib/ext"/> + <property name="oracle.driver.path" value="${domain.lib.ext}/smoracle.jar:${domain.lib.ext}/smbase.jar:${domain.lib.ext}/smresource.jar:${domain.lib.ext}/smutil.jar:${domain.lib.ext}/smspy.jar:${domain.lib.ext}/Oranxo.jar"/> + <echo message="${oracleForConnector.driver}"/> +<echo message="Executing sql statement at ${basedir} from ${sql.file}" + level="verbose"/> + <sql + driver="${oracleForConnector.driver}" + url="${oracleForConnector.url}" + userid="${oracleForConnector.user}" + password="${oracleForConnector.pwd}" + src="${sql.file}" + onerror="continue" + print="yes" + classpath="${oracle.driver.path}"/> +</target> +<!-- +</project> +-->
diff --git a/appserver/tests/appserv-tests/devtests/cdi/config/ee-config.properties b/appserver/tests/appserv-tests/devtests/cdi/config/ee-config.properties new file mode 100644 index 0000000..461bee1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/config/ee-config.properties
@@ -0,0 +1,57 @@ +# +# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + + +execution.mode=ee +admin.port=4849 +admin.user=admin +admin.password=admin123 +master.password=admin123 +admin.host=localhost +admin.domain=sqe-domain +admin.domain.dir=${env.S1AS_HOME}/domains +imq.dir=${env.S1AS_HOME}/imq +activeconsumer.maxnum=-1 +http.port=38080 +http.host=localhost +https.host=localhost +https.port=33820 +orb.port=33700 +nodeagent.name=sqe-agent +appserver.config.name=server-config +cluster.name=sqe-cluster +clustered.instance.name=clustered_server +server.instance.name=sqe-cluster +appserver.instance.name=sqe-cluster +config.dottedname.prefix=server +resources.dottedname.prefix=domain.resources +directory.server.host=localhost +directory.server.port=389 +directory.server.basedn=dc=sfbay,dc=sun,dc=com +directory.manager.dn=cn=Directory Manager +directory.manager.pwd=directorymanager +interop.admin.port=5858 +interop.admin.host=localhost +interop.admin.domain=domain2 +interop.http.port=9090 +interop.http.host=localhost +interop.https.port=2043 +interop.orb.port=4700 +isInteropDomain=true +results.mailer=abc@sun.com +results.mailee=xyz@sun.com +mail.host="ha21sca.sfbay.sun.com" +install.type=cluster
diff --git a/appserver/tests/appserv-tests/devtests/cdi/config/eesetup b/appserver/tests/appserv-tests/devtests/cdi/config/eesetup new file mode 100644 index 0000000..ef24e53 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/config/eesetup
@@ -0,0 +1,226 @@ +#!/bin/sh +# +# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + + +# This script creates and starts a domain called "sqe-domain" +# with a single server instance named "sqe-server". + +#--- Extract environment properties --- "sed" doesn't work with iastools.zip used in windows + +PASSWORD_FILE=${APS_HOME}/devtests/connector/config/password.txt + +for x in `cat $APS_HOME/devtests/connector/config/ee-config.properties` +do + varval=`echo $x |cut -d'=' -f1` + + if [ $varval = "admin.user" ]; + then + AS_ADMIN_USER=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "admin.port" ]; + then + AS_ADMIN_PORT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "admin.host" ]; + then + AS_ADMIN_HOST=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "orb.port" ]; + then + ORB_LISTENER_1_PORT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "http.port" ]; + then + HTTP_LISTENER_1_PORT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "https.port" ]; + then + SSL_PORT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "admin.password" ]; + then + echo "AS_ADMIN_PASSWORD=`echo $x |cut -d'=' -f2`" > ${PASSWORD_FILE} + echo "AS_ADMIN_ADMINPASSWORD=`echo $x |cut -d'=' -f2`" >> ${PASSWORD_FILE} + fi + + if [ $varval = "master.password" ]; + then + echo "AS_ADMIN_MASTERPASSWORD=`echo $x |cut -d'=' -f2`" >> ${PASSWORD_FILE} + fi + + if [ $varval = "admin.domain" ]; + then + AS_ADMIN_DOMAIN=`echo $x |cut -d'=' -f2` + fi + if [ $varval = "nodeagent.name" ]; + then + AS_ADMIN_NODEAGENT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "server.instance.name" ]; + then + AS_ADMIN_SERVER=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "cluster.name" ]; + then + CLUSTER_NAME=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "clustered.instance.name" ]; + then + CLUSTERED_INSTANCE_NAME=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "install.type" ]; + then + INSTALL_TYPE=`echo $x |cut -d'=' -f2` + fi + +done + +ASADMIN=${S1AS_HOME}/bin/asadmin +HTTP_LISTENER_2_PORT="1042" +SSL_MUTUALAUTH_PORT="1058" +JMX_SYSTEM_CONNECTOR_PORT="8687" + +export AS_ADMIN_USER +#export AS_ADMIN_PASSWORD ## do not set AS_ADMIN_PASSWORD in env. -password option is deprecated. +export AS_ADMIN_PORT +export AS_ADMIN_HOST +export AS_ADMIN_DOMAIN +export AS_ADMIN_NODEAGENT +export AS_ADMIN_SERVER +export CLUSTER_NAME +export CLUSTERED_INSTANCE_NAME + +##----- End Variable Defintions -------------- + + + +#Create domain: sqe-domain---- +echo " EESETUP: creating domain ${AS_ADMIN_DOMAIN}..." +${ASADMIN} create-domain --adminport ${AS_ADMIN_PORT} --adminuser ${AS_ADMIN_USER} --passwordfile ${PASSWORD_FILE} ${AS_ADMIN_DOMAIN} + +# Start domain: sqe-domain---- +echo " EESETUP: starting domain ${AS_ADMIN_DOMAIN}..." +${ASADMIN} start-domain --user ${AS_ADMIN_USER} --passwordfile ${PASSWORD_FILE} ${AS_ADMIN_DOMAIN} + +# Create node agent (sqe-agent) referencing sqe-domain.---- +echo " EESETUP: creating node agent: ${AS_ADMIN_NODEAGENT}..." +${ASADMIN} create-node-agent --host ${AS_ADMIN_HOST} --port ${AS_ADMIN_PORT} --user ${AS_ADMIN_USER} --passwordfile ${PASSWORD_FILE} ${AS_ADMIN_NODEAGENT} + +#----Start the sqe-agent. ---- +echo " EESETUP: starting node agent: ${AS_ADMIN_NODEAGENT}..." +${ASADMIN} start-node-agent --user ${AS_ADMIN_USER} --passwordfile ${PASSWORD_FILE} ${AS_ADMIN_NODEAGENT} + +echo " EESETUP: INSTALL TYPE is set to :${INSTALL_TYPE}" +#echo " EESETUP: install.type value in config.properties needs to be one of [standalone | cluster]" + +if [ ${INSTALL_TYPE} = "standalone" ]; then +# ---------------- + # Create server instance: sqe-server---- + echo " EESETUP: creating sever instance:${AS_ADMIN_SERVER}..." + ${ASADMIN} create-instance \ + --user ${AS_ADMIN_USER} \ + --passwordfile ${PASSWORD_FILE} \ + --nodeagent ${AS_ADMIN_NODEAGENT} \ + ${AS_ADMIN_SERVER} + + ${ASADMIN} start-instance \ + --user ${AS_ADMIN_USER} \ + --passwordfile ${PASSWORD_FILE} \ + ${AS_ADMIN_SERVER} +fi + +if [ ${INSTALL_TYPE} = "cluster" ]; then +# ---------------- + # Create cluster: sqe-cluster---- + echo " EESETUP: creating cluster:${CLUSTER_NAME}..." + ${ASADMIN} create-cluster --user ${AS_ADMIN_USER} --passwordfile ${PASSWORD_FILE} --host ${AS_ADMIN_HOST} --port ${AS_ADMIN_PORT} ${CLUSTER_NAME} + + # Set ports for first instance + echo " EESETUP: using default ports in ee-config.properties for first instance..." + HTTP_LISTENER_1_PORT=`expr ${HTTP_LISTENER_1_PORT} ` + HTTP_LISTENER_2_PORT=`expr ${HTTP_LISTENER_2_PORT} ` + ORB_LISTENER_1_PORT=`expr ${ORB_LISTENER_1_PORT} ` + SSL_PORT=`expr ${SSL_PORT} ` + SSL_MUTUALAUTH_PORT=`expr ${SSL_MUTUALAUTH_PORT} ` + JMX_SYSTEM_CONNECTOR_PORT=`expr ${JMX_SYSTEM_CONNECTOR_PORT} ` + + # Create clustered instance: clustered-server---- + echo " EESETUP: creating server instance:${CLUSTERED_INSTANCE_NAME}_1..." + ${ASADMIN} create-instance \ + --nodeagent ${AS_ADMIN_NODEAGENT} \ + --cluster ${CLUSTER_NAME} \ + --systemproperties "HTTP_LISTENER_PORT=${HTTP_LISTENER_1_PORT}:HTTP_SSL_LISTENER_PORT=${HTTP_LISTENER_2_PORT}:IIOP_LISTENER_PORT=${ORB_LISTENER_1_PORT}:IIOP_SSL_LISTENER_PORT=${SSL_PORT}:IIOP_SSL_MUTUALAUTH_PORT=${SSL_MUTUALAUTH_PORT}:JMX_SYSTEM_CONNECTOR_PORT=${JMX_SYSTEM_CONNECTOR_PORT}" \ + --user ${AS_ADMIN_USER} \ + --passwordfile ${PASSWORD_FILE} \ + ${CLUSTERED_INSTANCE_NAME}_1 + + # Roll over ports ---------------- + echo " EESETUP: Rolling over default port values by 4." + HTTP_LISTENER_1_PORT=`expr ${HTTP_LISTENER_1_PORT} + 4` + HTTP_LISTENER_2_PORT=`expr ${HTTP_LISTENER_2_PORT} + 4` + ORB_LISTENER_1_PORT=`expr ${ORB_LISTENER_1_PORT} + 4` + SSL_PORT=`expr ${SSL_PORT} + 4` + SSL_MUTUALAUTH_PORT=`expr ${SSL_MUTUALAUTH_PORT} + 4` + JMX_SYSTEM_CONNECTOR_PORT=`expr ${JMX_SYSTEM_CONNECTOR_PORT} + 4` + + # Create clustered instance: clustered-server---- + echo " EESETUP: creating server instance:${CLUSTERED_INSTANCE_NAME}_2..." + ${ASADMIN} create-instance \ + --nodeagent ${AS_ADMIN_NODEAGENT} \ + --cluster ${CLUSTER_NAME} \ + --systemproperties "HTTP_LISTENER_PORT=${HTTP_LISTENER_1_PORT}:HTTP_SSL_LISTENER_PORT=${HTTP_LISTENER_2_PORT}:IIOP_LISTENER_PORT=${ORB_LISTENER_1_PORT}:IIOP_SSL_LISTENER_PORT=${SSL_PORT}:IIOP_SSL_MUTUALAUTH_PORT=${SSL_MUTUALAUTH_PORT}:JMX_SYSTEM_CONNECTOR_PORT=${JMX_SYSTEM_CONNECTOR_PORT}" \ + --user ${AS_ADMIN_USER} \ + --passwordfile ${PASSWORD_FILE} \ + ${CLUSTERED_INSTANCE_NAME}_2 + #-- END Cluster Setup-------------------------- + + # Start cluster: sqe-cluster---- + echo " EESETUP: Starting cluster:${CLUSTER_NAME}..." + ${ASADMIN} start-cluster --user ${AS_ADMIN_USER} --passwordfile ${PASSWORD_FILE} --host ${AS_ADMIN_HOST} --port ${AS_ADMIN_PORT} ${CLUSTER_NAME} + +fi + +rm -f $PASSWORD_FILE +echo " EESETUP: EE setup complete!" + +# --------- Notes. ------------ + +#NOTE: There is an unstated jmx port 8686 which is +# currently not configurable. This port will need to be specified +# when creating the node agent. + +#NOTE: The domain should be up an running when the node agent is started. + +#NOTE: The stop-nodeagent command currently does +# not function due to a bug so should you ever need to stop the node +# agent you must kill its process. In reality you should never need +# to stop the node agent once it is started. + +#NOTE: The ports by default will not conflict with those of the DAS. +#The http-listener port will default to 8079. + +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/config/eeunsetup b/appserver/tests/appserv-tests/devtests/cdi/config/eeunsetup new file mode 100644 index 0000000..b5a1038 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/config/eeunsetup
@@ -0,0 +1,173 @@ +#!/bin/sh +# +# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + + +#--- Extract environment properties --- "sed" doesn't work with iastools.zip used in windows +PASSWORD_FILE=${APS_HOME}/devtests/connector/config/password.txt +for x in `cat $APS_HOME/devtests/connector/config/ee-config.properties` +do + varval=`echo $x |cut -d'=' -f1` + + if [ $varval = "admin.user" ]; + then + AS_ADMIN_USER=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "admin.port" ]; + then + AS_ADMIN_PORT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "admin.host" ]; + then + AS_ADMIN_HOST=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "orb.port" ]; + then + ORB_LISTENER_1_PORT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "http.port" ]; + then + HTTP_LISTENER_1_PORT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "https.port" ]; + then + SSL_PORT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "admin.password" ]; + then + echo "AS_ADMIN_PASSWORD=`echo $x |cut -d'=' -f2`" > ${PASSWORD_FILE} + echo "AS_ADMIN_ADMINPASSWORD=`echo $x |cut -d'=' -f2`" >> ${PASSWORD_FILE} + fi + + if [ $varval = "master.password" ]; + then + echo "AS_ADMIN_MASTERPASSWORD=`echo $x |cut -d'=' -f2`" >> ${PASSWORD_FILE} + fi + + if [ $varval = "admin.domain" ]; + then + AS_ADMIN_DOMAIN=`echo $x |cut -d'=' -f2` + fi + if [ $varval = "nodeagent.name" ]; + then + AS_ADMIN_NODEAGENT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "server.instance.name" ]; + then + AS_ADMIN_SERVER=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "cluster.name" ]; + then + CLUSTER_NAME=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "clustered.instance.name" ]; + then + CLUSTERED_INSTANCE_NAME=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "install.type" ]; + then + INSTALL_TYPE=`echo $x |cut -d'=' -f2` + fi + +done + +ASADMIN=${S1AS_HOME}/bin/asadmin +HTTP_LISTENER_2_PORT="1042" +SSL_MUTUALAUTH_PORT="1058" +JMX_SYSTEM_CONNECTOR_PORT="8687" + +export AS_ADMIN_USER +#export AS_ADMIN_PASSWORD ## do not set AS_ADMIN_PASSWORD in env. -password option is deprecated. +export AS_ADMIN_PORT +export AS_ADMIN_HOST +export AS_ADMIN_DOMAIN +export AS_ADMIN_NODEAGENT +export AS_ADMIN_SERVER +export CLUSTER_NAME +export CLUSTERED_INSTANCE_NAME + + +LOG_DIR=$APS_HOME/devtests/jdbc/logs + +if [ ${INSTALL_TYPE} = "standalone" ]; then +# ---------------- + # Stop server instance: sqe-server---- + echo " EEUNSETUP: stopping sever instance:${AS_ADMIN_SERVER}..." + ${ASADMIN} stop-instance \ + --user ${AS_ADMIN_USER} \ + --passwordfile ${PASSWORD_FILE} \ + ${AS_ADMIN_SERVER} + + ${ASADMIN} delete-instance \ + --user ${AS_ADMIN_USER} \ + --passwordfile ${PASSWORD_FILE} \ + ${AS_ADMIN_SERVER} +fi + +if [ ${INSTALL_TYPE} = "cluster" ]; then +# ---------------- + # Create server instance: sqe-server---- + echo " EEUNSETUP: stopping cluster ${CLUSTER_NAME}" + ${ASADMIN} stop-cluster \ + --user ${AS_ADMIN_USER} \ + --passwordfile ${PASSWORD_FILE} \ + ${CLUSTER_NAME} + + ${ASADMIN} delete-instance \ + --user ${AS_ADMIN_USER} \ + --passwordfile ${PASSWORD_FILE} \ + ${CLUSTERED_INSTANCE_NAME}_1 + + ${ASADMIN} delete-instance \ + --user ${AS_ADMIN_USER} \ + --passwordfile ${PASSWORD_FILE} \ + ${CLUSTERED_INSTANCE_NAME}_2 + + ${ASADMIN} delete-cluster \ + --user ${AS_ADMIN_USER} \ + --passwordfile ${PASSWORD_FILE} \ + ${CLUSTER_NAME} +fi + + +echo " EEUNSETUP: stopping nodeagent....." +${ASADMIN} stop-node-agent $AS_ADMIN_NODEAGENT + +echo " EEUNSETUP: Deleting nodeagent....." +${ASADMIN} delete-node-agent ${AS_ADMIN_NODEAGENT} + +echo " EEUNSETUP: Deleting nodeagent config....." +${ASADMIN} delete-node-agent-config --passwordfile ${PASSWORD_FILE} ${AS_ADMIN_NODEAGENT} + +echo " EEUNSETUP: stopping domain...." +${ASADMIN} stop-domain ${AS_ADMIN_DOMAIN} + +${ASADMIN} delete-domain ${AS_ADMIN_DOMAIN} +echo " EEUNSETUP: EE domain,server instance and nodeagent has been deleted" + +rm -f $PASSWORD_FILE +echo " EEUNSETUP: Unsetup complete.... " +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/config/oracle.properties b/appserver/tests/appserv-tests/devtests/cdi/config/oracle.properties new file mode 100644 index 0000000..7109dfb --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/config/oracle.properties
@@ -0,0 +1,25 @@ +# +# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + + +oracleForConnector.port=1527 +oracleForConnector.host=localhost +oracleForConnector.sid=testdb +oracleForConnector.user=dbuser +oracleForConnector.pwd=dbpassword +oracleForConnector.driver=org.apache.derby.jdbc.ClientDriver +oracleForConnector.dbclass=org.apache.derby.jdbc.ClientXADataSource +oracleForConnector.url=jdbc:derby://${oracleForConnector.host}:${oracleForConnector.port}/${oracleForConnector.sid};create=true;
diff --git a/appserver/tests/appserv-tests/devtests/cdi/config/oracle_datadirect.properties b/appserver/tests/appserv-tests/devtests/cdi/config/oracle_datadirect.properties new file mode 100644 index 0000000..3b7fe95 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/config/oracle_datadirect.properties
@@ -0,0 +1,46 @@ +# +# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + + +db.port=1521 +db.host=natraj.sfbay.sun.com +db.sid=dbsmpl1 +db.type=oracle +db.name=dbsmpl1 +db.user=dbuser +db.pwd=dbpassword +db.driver=com.sun.sql.jdbc.oracle.OracleDriver +db.class=com.sun.sql.jdbcx.oracle.OracleDataSource +db.xaclass=com.sun.sql.jdbcx.oracle.OracleDataSource +db.url=jdbc:sun:oracle://${db.host}:${db.port};SID=${db.sid} +connector.url=jdbc\\:sun\\:oracle\\://natraj.sfbay.sun.com\\:1521\\;SID\\=dbsmpl1 +db.unixdriverpath=lib/drivers/oracle/smoracle.jar +db.windriverpath=lib/drivers/oracle/smoracle.jar +cpds.class=com.sun.sql.jdbcx.oracle.OracleDataSource +isDBOracle=true +datadirect=true + +#properties used by global transaction tests. +txdb.port=1521 +txdb.host=natraj.sfbay.sun.com +txdb.name=dbsmpl2 +txdb.user=pbpublic +txdb.pwd=pbpublic +txdb.url=jdbc:sun:oracle://natraj.sfbay.sun.com:1521;SID=dbsmpl2 + +#Properties used by admincli +adminclidb.user=admincli +adminclidb.pwd=admincli
diff --git a/appserver/tests/appserv-tests/devtests/cdi/config/pe-config.properties b/appserver/tests/appserv-tests/devtests/cdi/config/pe-config.properties new file mode 100644 index 0000000..4e1e6fc --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/config/pe-config.properties
@@ -0,0 +1,54 @@ +# +# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + + +execution.mode=pe +admin.port=4848 +admin.user=admin +admin.host=localhost +admin.domain=domain1 +admin.domain.dir=${env.S1AS_HOME}/domains +activeconsumer.maxnum=1 +mail.host="ha21sca.sfbay.sun.com" +http.port=8080 +http.host=localhost +https.host=localhost +https.port=8181 +orb.port=3700 +admin.password=adminadmin +master.password=changeit +appserver.instance.name=server +appserver.config.name=server-config +directory.server.host=localhost +directory.server.port=389 +directory.server.basedn=dc=sfbay,dc=sun,dc=com +directory.manager.dn=cn=Directory Manager +directory.manager.pwd=directorymanager +server.dir=home/results/s1aspe80 +log.server.location=sardinia.sfbay.sun.com +win.map.drive=Q: +results.mailer=abc@sun.com +results.mailee=xyz@sun.com +interop.admin.port=5858 +interop.admin.host=localhost +interop.admin.domain=domain2 +interop.http.port=9090 +interop.http.host=localhost +interop.https.port=2043 +interop.orb.port=4700 +isInteropDomain=true +resources.dottedname.prefix=domain.resources +admin.password.file=${env.APS_HOME}/devtests/connector/config/password.txt
diff --git a/appserver/tests/appserv-tests/devtests/cdi/config/pointbase.properties b/appserver/tests/appserv-tests/devtests/cdi/config/pointbase.properties new file mode 100644 index 0000000..27f6c75 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/config/pointbase.properties
@@ -0,0 +1,42 @@ +# +# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + + +db.port=9092 +db.host=localhost +db.type=pointbase +db.user=dbuser +db.pwd=dbpassword +db.name=sqe-samples +db.class=com.pointbase.jdbc.jdbcDataSource +db.xaclass=com.pointbase.xa.xaDataSource +db.driver=com.pointbase.jdbc.jdbcUniversalDriver +db.url=jdbc:pointbase:server://${db.host}:${db.port}/${db.name},new +#db.unixdriverpath=lib/drivers/pointbase/pbclient.jar +db.unixdriverpath=pointbase/lib/pbclient.jar +db.windriverpath=lib/\drivers/\pointbase\/\pbclient.jar +connector.url=jdbc\\:pointbase\\:server\\://${db.host}\\:${db.port}/${db.name},new +cpds.class=com.pointbase.jdbc.jdbcDataSource +isDBPointbase=true + +#properties used by global transaction tests. +txdb.port=9095 +txdb.host=localhost +txdb.name=txsample +txdb.user=dbuser +txdb.pwd=dbpassword +txdb.url=jdbc:pointbase:server://localhost:9095/txsample,new +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/config/startee b/appserver/tests/appserv-tests/devtests/cdi/config/startee new file mode 100644 index 0000000..aad2af1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/config/startee
@@ -0,0 +1,142 @@ +#!/bin/sh +# +# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + + +#--- Extract environment properties --- "sed" doesn't work with iastools.zip used in windows + +for x in `cat $APS_HOME/devtests/jdbc/config/ee-config.properties` +do + varval=`echo $x |cut -d'=' -f1` + + if [ $varval = "admin.user" ]; + then + AS_ADMIN_USER=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "admin.port" ]; + then + AS_ADMIN_PORT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "admin.host" ]; + then + AS_ADMIN_HOST=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "orb.port" ]; + then + ORB_LISTENER_1_PORT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "http.port" ]; + then + HTTP_LISTENER_1_PORT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "https.port" ]; + then + SSL_PORT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "admin.password" ]; + then + AS_ADMIN_PASSWORD=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "admin.domain" ]; + then + AS_ADMIN_DOMAIN=`echo $x |cut -d'=' -f2` + fi + if [ $varval = "nodeagent.name" ]; + then + AS_ADMIN_NODEAGENT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "server.instance.name" ]; + then + AS_ADMIN_SERVER=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "cluster.name" ]; + then + CLUSTER_NAME="sqe-cluster" + fi + + if [ $varval = "clustered.instance.name" ]; + then + CLUSTERED_INSTANCE_NAME="clustered_server" + fi + + if [ $varval = "install.type" ]; + then + INSTALL_TYPE=`echo $x |cut -d'=' -f2` + fi + +done + + +ASADMIN=${ASADMIN}/bin/asadmin +HTTP_LISTENER_2_PORT="1042" +SSL_MUTUALAUTH_PORT="1058" +JMX_SYSTEM_CONNECTOR_PORT="8687" + +export AS_ADMIN_USER +export AS_ADMIN_PASSWORD +export AS_ADMIN_PORT +export AS_ADMIN_HOST +export AS_ADMIN_DOMAIN +export AS_ADMIN_NODEAGENT +export AS_ADMIN_SERVER +export CLUSTER_NAME +export CLUSTERED_INSTANCE_NAME + +##--- End Variables Definitions -------- + +# Start domain: sqe-domain---- +echo "starting domain ${AS_ADMIN_DOMAIN}..." +${S1AS_HOME}/bin/asadmin start-domain --user ${AS_ADMIN_USER} --password ${AS_ADMIN_PASSWORD} ${AS_ADMIN_DOMAIN} + + +# Create node agent (sqe-agent) referencing sqe-domain.---- +echo "starting node agent: ${AS_ADMIN_NODEAGENT}..." +${S1AS_HOME}/bin/asadmin start-node-agent --user ${AS_ADMIN_USER} --password ${AS_ADMIN_PASSWORD} ${AS_ADMIN_NODEAGENT} + + +if [ ${INSTALL_TYPE} = "standalone" -o ${INSTALL_TYPE} = "all" ]; then + + echo "Doing nothing,starting nodeagent would have started server instance" +# ---------------- + #echo "Starting server instance ${AS_ADMIN_SERVER}" + # ${S1AS_HOME}/bin/asadmin start-instance \ + # -u ${AS_ADMIN_USER} \ + # -w ${AS_ADMIN_PASSWORD} \ + # ${AS_ADMIN_SERVER} + +fi + +if [ ${INSTALL_TYPE} = "cluster" -o ${INSTALL_TYPE} = "all" ]; then +# ---------------- + # Start cluster: sqe-cluster---- + echo "Starting cluster:${CLUSTER_NAME}..." + ${S1AS_HOME}/bin/asadmin start-cluster -u ${AS_ADMIN_USER} -w ${AS_ADMIN_PASSWORD} ${CLUSTER_NAME} + + +fi + + +echo "***All server process started***" +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/config/stopee b/appserver/tests/appserv-tests/devtests/cdi/config/stopee new file mode 100644 index 0000000..6ee0ba9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/config/stopee
@@ -0,0 +1,90 @@ +#!/bin/sh +# +# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + + +for x in `cat $APS_HOME/devtests/jdbc/config/ee-config.properties` +do + varval=`echo $x |cut -d'=' -f1` + + if [ $varval = "admin.user" ]; + then + AS_ADMIN_USER=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "admin.port" ]; + then + AS_ADMIN_PORT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "admin.password" ]; + then + AS_ADMIN_PASSWORD=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "admin.domain" ]; + then + AS_ADMIN_DOMAIN=`echo $x |cut -d'=' -f2` + fi + if [ $varval = "nodeagent.name" ]; + then + AS_ADMIN_NODEAGENT=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "server.instance.name" ]; + then + AS_ADMIN_SERVER=`echo $x |cut -d'=' -f2` + fi + + if [ $varval = "cluster.name" ]; + then + CLUSTER_NAME="sqe-cluster" + fi + + if [ $varval = "clustered.instance.name" ]; + then + CLUSTERED_INSTANCE_NAME="clustered_server" + fi + +done + + +export AS_ADMIN_USER +export AS_ADMIN_PASSWORD +export AS_ADMIN_PORT +export AS_ADMIN_DOMAIN +export AS_ADMIN_NODEAGENT +export AS_ADMIN_SERVER +export CLUSTER_NAME +export CLUSTERED_INSTANCE_NAME + +##--- End Variables Definitions -------- + +# stop standalone server instance ---- + +# stop nodeagent ---- +echo "stopping nodeagent:${AS_ADMIN_NODEAGENT}..." +${S1AS_HOME}/bin/asadmin stop-node-agent ${AS_ADMIN_NODEAGENT} + +# sleep ---- +echo "sleeping for 15 seconds..." +sleep 15 + +# stop domain ---- +echo "stopping domain ${AS_ADMIN_DOMAIN}..." +${S1AS_HOME}/bin/asadmin stop-domain ${AS_ADMIN_DOMAIN} + +echo "***All Server Processes Stopped!"
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/build.xml b/appserver/tests/appserv-tests/devtests/cdi/decorators/build.xml new file mode 100644 index 0000000..823b1b1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/build.xml
@@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<project name="decorators-test" default="usage" basedir="."> + + <property name="decorators-target" value="all"/> + + <target name="run-test"> + <antcall target="decorators"> + <param name="decorators-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="decorators"> + <param name="decorators-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="decorators"> + <param name="decorators-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="decorators"> + <param name="decorators-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="decorators"> + <param name="decorators-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="decorators"> + <param name="decorators-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="decorators"> + <param name="decorators-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="decorators"> + <param name="decorators-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="decorators"> + <param name="decorators-target" value="run"/> + </antcall> + </target> + + <target name="decorators"> + <record name="decorators.output" action="start" /> + <ant dir="simple-decorator" target="${decorators-target}"/> + <record name="decorators.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant all (Executes all the decorators tests) + ant clean (cleans all the decorators tests) + ant build (builds all the decorators tests) + ant setup (sets up all resources for decorators tests) + ant deploy (deploys all the decorators apps) + ant run (Executes all the decorators tests) + ant undeploy (undeploys all the decorators apps) + ant unsetup (unsets all resources for decorators tests) + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/README b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/README new file mode 100644 index 0000000..8c0e832 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/README
@@ -0,0 +1 @@ +Test to check if Beans produced from Producer Methods are decorated
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/build.properties b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/build.properties new file mode 100644 index 0000000..581be99 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-decorator-for-beeans-from-producer-methods"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/build.xml b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/client/test/client/WebTest.java new file mode 100644 index 0000000..d445b69 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/client/test/client/WebTest.java
@@ -0,0 +1,107 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "decorators-decorator-for-beeans-from-producer-methods"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/descriptor/beans.xml new file mode 100644 index 0000000..efdec0d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/descriptor/beans.xml
@@ -0,0 +1,26 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <decorators> + <class>test.beans.TestBeanDecorator</class> + </decorators> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/beans/ProducedAtRuntime.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/beans/ProducedAtRuntime.java new file mode 100644 index 0000000..aca6de0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/beans/ProducedAtRuntime.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Retention(RUNTIME) +@Target({METHOD, FIELD, PARAMETER, TYPE}) +public @interface ProducedAtRuntime { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/beans/TestBeanDecorator.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/beans/TestBeanDecorator.java new file mode 100644 index 0000000..82d43d0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/beans/TestBeanDecorator.java
@@ -0,0 +1,42 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.decorator.Decorator; +import javax.decorator.Delegate; +import javax.inject.Inject; + +@Decorator +public abstract class TestBeanDecorator implements TestBeanInterface{ + + public static boolean decoratorCalled = false; + + @Inject + @Delegate + @ProducedAtRuntime + TestBeanInterface tb; + + @Override + public String m1() { + System.out.println("Decorator called"); + decoratorCalled = true; + return tb.m1(); + } + + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/beans/TestBeanImpl.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/beans/TestBeanImpl.java new file mode 100644 index 0000000..4c55e89 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/beans/TestBeanImpl.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public class TestBeanImpl implements TestBeanInterface { + + @Override + public String m1() { + return "TestBeanImpl::m1"; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..0afbf75 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public String m1(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/beans/TestBeanProducer.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/beans/TestBeanProducer.java new file mode 100644 index 0000000..a171c87 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/beans/TestBeanProducer.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; +import javax.enterprise.inject.New; +import javax.enterprise.inject.Produces; + +public class TestBeanProducer { + + @Produces + @ProducedAtRuntime + @RequestScoped + public TestBeanInterface getRuntimeTB(@New TestBeanImpl tbi) { + return tbi; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/servlet/TestDecorationOfBeansFromProducerMethodsTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/servlet/TestDecorationOfBeansFromProducerMethodsTestServlet.java new file mode 100644 index 0000000..8fa868b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/servlet/test/servlet/TestDecorationOfBeansFromProducerMethodsTestServlet.java
@@ -0,0 +1,56 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.ProducedAtRuntime; +import test.beans.TestBeanDecorator; +import test.beans.TestBeanInterface; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class TestDecorationOfBeansFromProducerMethodsTestServlet extends HttpServlet { + @Inject + @ProducedAtRuntime + TestBeanInterface tb; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (tb == null) + msg += "Injection of request scoped bean failed"; + + tb.m1(); + if (!TestBeanDecorator.decoratorCalled) + msg += "decorator for beans from producer methods not called"; + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/README b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/README new file mode 100644 index 0000000..87401fe --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/README
@@ -0,0 +1,3 @@ +Test +- Simple decorator test + - ensure that decorated methods are called and the ability for the decorator to modify method arguments.
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/build.properties b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/build.properties new file mode 100644 index 0000000..5d45b07 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-simple-decorator"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/build.xml b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/client/test/client/WebTest.java new file mode 100644 index 0000000..0a194c9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/client/test/client/WebTest.java
@@ -0,0 +1,107 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "decorators-simple-decorator"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/descriptor/beans.xml new file mode 100644 index 0000000..54a5a82 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/descriptor/beans.xml
@@ -0,0 +1,30 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.TransactionInterceptor</class> + <class>test.beans.RequiresNewTransactionInterceptor</class> + </interceptors> + <decorators> + <class>test.beans.LargeTransactionDecorator</class> + </decorators> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/Account.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/Account.java new file mode 100644 index 0000000..dfeaaa3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/Account.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.math.BigDecimal; + +public interface Account { + + public BigDecimal getBalance(); + + public String getOwner(); + + public void withdraw(BigDecimal amount); + + public void deposit(BigDecimal amount); + + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/LargeTransactionDecorator.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/LargeTransactionDecorator.java new file mode 100644 index 0000000..e0a1302 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/LargeTransactionDecorator.java
@@ -0,0 +1,48 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.math.BigDecimal; + +import javax.decorator.Decorator; +import javax.decorator.Delegate; +import javax.inject.Inject; + +@Decorator +public abstract class LargeTransactionDecorator implements Account { + public static boolean withDrawCalled = false; + public static boolean depositCalled = false; + + @Inject @Delegate + Account account; + + @Override + public void withdraw(BigDecimal amount) { + System.out.println("LargeTransactionDecorator::withdraw"); + LargeTransactionDecorator.withDrawCalled = true; + account.withdraw(amount); + } + + + @Override + public void deposit(BigDecimal amount){ + System.out.println("LargeTransactionDecorator::deposit"); + LargeTransactionDecorator.depositCalled = true; + account.deposit(amount); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..fa8fdb7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/RequiresNewTransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/RequiresNewTransactionInterceptor.java new file mode 100644 index 0000000..73f5964 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/RequiresNewTransactionInterceptor.java
@@ -0,0 +1,50 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Interceptor +@Transactional(requiresNew=true, rolesAllowed={"admin", "manager"}) +//the rolesAllowed value must be ignored as it s a non-binding attribute +public class RequiresNewTransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("RequiresNewTransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/ShoppingCart.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/ShoppingCart.java new file mode 100644 index 0000000..60a8a40 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/ShoppingCart.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + + +@Transactional(requiresNew=true) +@Preferred +public class ShoppingCart { + + public void addItem(String s) { + System.out.println("ShoppingCart::addItem called"); + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/TestAccount.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/TestAccount.java new file mode 100644 index 0000000..066e62b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/TestAccount.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.math.BigDecimal; + +public class TestAccount implements Account { + BigDecimal currentBal = new BigDecimal(100); + + @Override + public void deposit(BigDecimal amount) { + System.out.println("TestAccount::deposit+" + amount); + + //get a bonus of 5 + currentBal = currentBal.add(amount.add(new BigDecimal(5))); + System.out.println("new bal:" + currentBal); + } + + @Override + public BigDecimal getBalance() { + System.out.println("TestAccount::getBalance"); + return currentBal; + } + + @Override + public String getOwner() { + return "test user"; + } + + @Override + public void withdraw(BigDecimal amount) { + System.out.println("TestAccount::withdraw-" + amount); + currentBal = currentBal.subtract(amount); + System.out.println("new bal:" + currentBal); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4792d26 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/TestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class TestBean { + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/TestDependentBean.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/TestDependentBean.java new file mode 100644 index 0000000..230c493 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/TestDependentBean.java
@@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.io.Serializable; + +public class TestDependentBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/TransactionInterceptor.java new file mode 100644 index 0000000..f762992 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/TransactionInterceptor.java
@@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/Transactional.java new file mode 100644 index 0000000..b8937b9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/beans/Transactional.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.enterprise.util.Nonbinding; +import javax.interceptor.InterceptorBinding; + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + boolean requiresNew() default false; + @Nonbinding String[] rolesAllowed() default {}; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/servlet/SimpleDecoratorTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/servlet/SimpleDecoratorTestServlet.java new file mode 100644 index 0000000..a327946 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/decorators/simple-decorator/servlet/test/servlet/SimpleDecoratorTestServlet.java
@@ -0,0 +1,120 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.math.BigDecimal; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.Account; +import test.beans.LargeTransactionDecorator; +import test.beans.Preferred; +import test.beans.RequiresNewTransactionInterceptor; +import test.beans.ShoppingCart; +import test.beans.TestBean; +import test.beans.TransactionInterceptor; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class SimpleDecoratorTestServlet extends HttpServlet { + @Inject + @Preferred + TestBean tb; + + @Inject + @Preferred + ShoppingCart sc; + + @Inject + Account testAccount; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (tb == null) + msg += "Injection of request scoped bean failed"; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + if (RequiresNewTransactionInterceptor.aroundInvokeCalled) + msg += "RequiresNew TransactionInterceptor called when " + + "it shouldn't have been called"; + + TransactionInterceptor.clear(); + //invoke shopping cart bean. This should result in an invocation on + //the RequiresNewTransactional + sc.addItem("Test Item"); + if (!RequiresNewTransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke in requires new " + + "transaction interceptor not called"; + if (RequiresNewTransactionInterceptor.aroundInvokeInvocationCount != 1) + msg += "Business method requires new interceptor invocation on " + + "method-level interceptor annotation count not expected. " + + "expected =1, actual=" + + RequiresNewTransactionInterceptor.aroundInvokeInvocationCount; + if (!RequiresNewTransactionInterceptor.errorMessage.trim().equals("")) + msg += RequiresNewTransactionInterceptor.errorMessage; + + //TransactionInterceptor should not have been called + if (TransactionInterceptor.aroundInvokeCalled) + msg += "TranscationInterceptor aroundInvoke called when a requiresnew" + + "transaction interceptor should have been called"; + + //Test decorators + System.out.println(testAccount.getBalance()); + if (testAccount.getBalance().compareTo(new BigDecimal(100)) != 0) + msg += "Decorators:Invalid initial balance"; + + testAccount.deposit(new BigDecimal(10)); + if (testAccount.getBalance().compareTo(new BigDecimal(115)) != 0) //5 as bonus by the decorator + msg += "Decorators:Invalid balance after deposit"; + + + testAccount.withdraw(new BigDecimal(10)); + if (testAccount.getBalance().compareTo(new BigDecimal(105)) != 0) + msg += "Decorators:Invalid balance after withdrawal"; + + + if (!LargeTransactionDecorator.depositCalled) + msg += "deposit method in Decorator not called"; + if (!LargeTransactionDecorator.withDrawCalled) + msg += "deposit method in Decorator not called"; + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/build.xml b/appserver/tests/appserv-tests/devtests/cdi/events/build.xml new file mode 100644 index 0000000..63beb4a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/build.xml
@@ -0,0 +1,101 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<project name="events-test" default="usage" basedir="."> + + <property name="events-target" value="all"/> + + <target name="run-test"> + <antcall target="events"> + <param name="events-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="events"> + <param name="events-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="events"> + <param name="events-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="events"> + <param name="events-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="events"> + <param name="events-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="events"> + <param name="events-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="events"> + <param name="events-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="events"> + <param name="events-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="events"> + <param name="events-target" value="run"/> + </antcall> + </target> + + <target name="events"> + <record name="events.output" action="start" /> + <ant dir="simple-event-observers" target="${events-target}"/> +<!-- + <ant dir="conditional-observer" target="${events-target}"/> +--> + <ant dir="event-producers" target="${events-target}"/> + <ant dir="multiple-event-qualifiers" target="${events-target}"/> + <record name="events.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant all (Executes all the events tests) + ant clean (cleans all the events tests) + ant build (builds all the events tests) + ant setup (sets up all resources for events tests) + ant deploy (deploys all the events apps) + ant run (Executes all the events tests) + ant undeploy (undeploys all the events apps) + ant unsetup (unsets all resources for events tests) + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/README b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/README new file mode 100644 index 0000000..d84291b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/README
@@ -0,0 +1,4 @@ +Test +- Use of Events + - conditional observer methods. ensuring that there is no event notification + to a conversation scoped observer when there is no active conversation context
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/build.properties b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/build.properties new file mode 100644 index 0000000..aaa9202 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-event-producers"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/build.xml b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/client/test/client/WebTest.java new file mode 100644 index 0000000..1ea454b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/client/test/client/WebTest.java
@@ -0,0 +1,108 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = + "events-conditional-observers"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/Approved.java b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/Approved.java new file mode 100644 index 0000000..7a107aa --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/Approved.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Approved { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/Created.java b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/Created.java new file mode 100644 index 0000000..f71048f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/Created.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Created { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/Document.java b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/Document.java new file mode 100644 index 0000000..d857f5a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/Document.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public class Document { + String name = ""; + public Document(String name) { + System.out.println("Document created with name" + name ); + this.name = name; + } + + public void update(){ + System.out.println("Document:" + name + " updated."); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/SecondTestEventConditionalObserver.java b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/SecondTestEventConditionalObserver.java new file mode 100644 index 0000000..0a34e1e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/SecondTestEventConditionalObserver.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.io.Serializable; + +import javax.enterprise.context.ConversationScoped; +import javax.enterprise.event.Observes; +import javax.enterprise.event.Reception; + +@ConversationScoped +public class SecondTestEventConditionalObserver implements Serializable{ + public static int documentCreatedEvent = 0; + + //should not get called as there is no conversation is in this test + public void onDocumentCreate(@Observes(notifyObserver=Reception.IF_EXISTS) + @Created Document d) { + System.out.println("TestEventObserver:onDocumentCreate"); + documentCreatedEvent++; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/TestEventConditionalObserver.java b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/TestEventConditionalObserver.java new file mode 100644 index 0000000..1725d36 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/TestEventConditionalObserver.java
@@ -0,0 +1,52 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Observes; +import javax.enterprise.event.Reception; + +@RequestScoped +public class TestEventConditionalObserver { + public static int documentCreatedEvent = 0; + public static int documentUpdatedEvent = 0; + public static int documentAnyEvents = 0; + public static int documentApprovedEvents = 0; + + public void onDocumentCreate(@Observes(notifyObserver=Reception.IF_EXISTS) @Created Document d) { + System.out.println("TestEventObserver:onDocumentCreate"); + documentCreatedEvent++; + } + + public void onAnyDocumentEvent(@Observes Document d) { + System.out.println("TestEventObserver:onAnyDocumentUpdatedEvent"); + documentAnyEvents++; + } + + public void afterDocumentUpdate(@Observes @Updated Document d) { + System.out.println("TestEventObserver:afterDocumentUpdate"); + documentUpdatedEvent++; + } + + public void onDocumentUpdatedAndApproved( + @Observes @Updated @Approved Document d){ + System.out.println("TestEventObserver:updated and approved"); + documentApprovedEvents++; + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/TestEventProducer.java b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/TestEventProducer.java new file mode 100644 index 0000000..92dafa7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/TestEventProducer.java
@@ -0,0 +1,45 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.event.Event; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; + +public class TestEventProducer { + @Inject Event<Document> docEvent; + + public void fireEvents(){ + Document d = new Document("Test"); + docEvent.fire(d); //general fire of a Document related event + + //send a created event + docEvent.select( + new AnnotationLiteral<Created>(){}).fire(d); + + + d.update(); + //send an updated event + docEvent.select( + new AnnotationLiteral<Updated>(){}).fire(d); + + //send an updated and approved event + docEvent.select(new AnnotationLiteral<Updated>(){}, new AnnotationLiteral<Approved>(){}).fire(d); + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/Updated.java b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/Updated.java new file mode 100644 index 0000000..07c6894 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/beans/Updated.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Updated { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/servlet/ConditionalObserverTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/servlet/ConditionalObserverTestServlet.java new file mode 100644 index 0000000..52863cb --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/conditional-observer/servlet/test/servlet/ConditionalObserverTestServlet.java
@@ -0,0 +1,74 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.SecondTestEventConditionalObserver; +import test.beans.TestEventConditionalObserver; +import test.beans.TestEventProducer; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class ConditionalObserverTestServlet extends HttpServlet { + + @Inject + TestEventProducer trsb; + + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + trsb.fireEvents(); + if (TestEventConditionalObserver.documentCreatedEvent != 1){ + msg += "Document created event not received by observer"; + } + + if (TestEventConditionalObserver.documentUpdatedEvent != 2){ + msg += "Document updated event not received by observer"; + } + + if (TestEventConditionalObserver.documentApprovedEvents != 1){ + msg += "Document updated and approved event not " + + "received by observer"; + } + + if (TestEventConditionalObserver.documentAnyEvents != 4){ + msg += "# of Document event received by observer does not " + + "match expected values. expected = 2. observed="+ TestEventConditionalObserver.documentAnyEvents; + } + + if (SecondTestEventConditionalObserver.documentCreatedEvent > 0) + msg += "A conditional observer was notified when it did not exist"; + + + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/README b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/README new file mode 100644 index 0000000..1a0da81 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/README
@@ -0,0 +1,7 @@ +Test +- Use of Events + - Simple observer methods that observer qualified and any events on a + particular Event payload + - event producer to produce the appropriate event by specifying event + qualifiers dynamically through the select() method + - events produced and observed with multiple event qualifiers
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/build.properties b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/build.properties new file mode 100644 index 0000000..aaa9202 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-event-producers"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/build.xml b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/client/test/client/WebTest.java new file mode 100644 index 0000000..5d6b503 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/client/test/client/WebTest.java
@@ -0,0 +1,108 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = + "events-simple-event-producer"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/Approved.java b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/Approved.java new file mode 100644 index 0000000..7a107aa --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/Approved.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Approved { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/Created.java b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/Created.java new file mode 100644 index 0000000..f71048f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/Created.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Created { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/Document.java b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/Document.java new file mode 100644 index 0000000..d857f5a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/Document.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public class Document { + String name = ""; + public Document(String name) { + System.out.println("Document created with name" + name ); + this.name = name; + } + + public void update(){ + System.out.println("Document:" + name + " updated."); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/TestEventObserver.java b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/TestEventObserver.java new file mode 100644 index 0000000..9bddd9a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/TestEventObserver.java
@@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.event.Observes; + +public class TestEventObserver { + public static int documentCreatedEvent = 0; + public static int documentUpdatedEvent = 0; + public static int documentAnyEvents = 0; + public static int documentApprovedEvents = 0; + + public void onDocumentCreate(@Observes @Created Document d) { + System.out.println("TestEventObserver:onDocumentCreate"); + documentCreatedEvent++; + } + + public void onAnyDocumentEvent(@Observes Document d) { + System.out.println("TestEventObserver:onAnyDocumentUpdatedEvent"); + documentAnyEvents++; + } + + public void afterDocumentUpdate(@Observes @Updated Document d) { + System.out.println("TestEventObserver:afterDocumentUpdate"); + documentUpdatedEvent++; + } + + public void onDocumentUpdatedAndApproved( + @Observes @Updated @Approved Document d){ + System.out.println("TestEventObserver:updated and approved"); + documentApprovedEvents++; + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/TestEventProducer.java b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/TestEventProducer.java new file mode 100644 index 0000000..92dafa7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/TestEventProducer.java
@@ -0,0 +1,45 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.event.Event; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; + +public class TestEventProducer { + @Inject Event<Document> docEvent; + + public void fireEvents(){ + Document d = new Document("Test"); + docEvent.fire(d); //general fire of a Document related event + + //send a created event + docEvent.select( + new AnnotationLiteral<Created>(){}).fire(d); + + + d.update(); + //send an updated event + docEvent.select( + new AnnotationLiteral<Updated>(){}).fire(d); + + //send an updated and approved event + docEvent.select(new AnnotationLiteral<Updated>(){}, new AnnotationLiteral<Approved>(){}).fire(d); + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/Updated.java b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/Updated.java new file mode 100644 index 0000000..07c6894 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/beans/Updated.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Updated { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/servlet/SimpleEventObserverTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/servlet/SimpleEventObserverTestServlet.java new file mode 100644 index 0000000..b621081 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-producers/servlet/test/servlet/SimpleEventObserverTestServlet.java
@@ -0,0 +1,69 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestEventObserver; +import test.beans.TestEventProducer; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class SimpleEventObserverTestServlet extends HttpServlet { + + @Inject + TestEventProducer trsb; + + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + trsb.fireEvents(); + if (TestEventObserver.documentCreatedEvent != 1){ + msg += "Document created event not received by observer"; + } + + if (TestEventObserver.documentUpdatedEvent != 2){ + msg += "Document updated event not received by observer"; + } + + if (TestEventObserver.documentApprovedEvents != 1){ + msg += "Document updated and approved event not " + + "received by observer"; + } + + + if (TestEventObserver.documentAnyEvents != 4){ + msg += "# of Document event received by observer does not " + + "match expected values. expected = 2. observed="+ TestEventObserver.documentAnyEvents; + } + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/README b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/README new file mode 100644 index 0000000..dbbffd6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/README
@@ -0,0 +1,5 @@ +Test +- Use of Events + - Event Qualifiers with members + - qualifier member value specified statically for event production and dynamically through a + subclass of AnnotationLiteral
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/build.properties b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/build.properties new file mode 100644 index 0000000..aaa9202 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-event-producers"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/build.xml b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/client/test/client/WebTest.java new file mode 100644 index 0000000..ded1d20 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/client/test/client/WebTest.java
@@ -0,0 +1,108 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = + "events-event-qualifiers-with-members"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/Approved.java b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/Approved.java new file mode 100644 index 0000000..7a107aa --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/Approved.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Approved { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/Created.java b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/Created.java new file mode 100644 index 0000000..f71048f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/Created.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Created { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/Document.java b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/Document.java new file mode 100644 index 0000000..d857f5a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/Document.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public class Document { + String name = ""; + public Document(String name) { + System.out.println("Document created with name" + name ); + this.name = name; + } + + public void update(){ + System.out.println("Document:" + name + " updated."); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/TestEventConditionalObserver.java b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/TestEventConditionalObserver.java new file mode 100644 index 0000000..8c2f110 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/TestEventConditionalObserver.java
@@ -0,0 +1,39 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Observes; +import javax.enterprise.event.Reception; + +public class TestEventConditionalObserver { + public static int documentAdminUpdatedEvent, + documentFooUserUpdatedEvent = 0; + + public void afterAdminDocumentUpdate( + @Observes @Updated(updatedBy = "admin") Document d) { + System.out.println("TestEventObserver:afterAdminDocumentUpdate"); + documentAdminUpdatedEvent++; + } + + public void afterFooUserDocumentUpdate( + @Observes @Updated(updatedBy = "FooUser") Document d) { + System.out.println("TestEventObserver:afterFooUserDocumentUpdate"); + documentFooUserUpdatedEvent++; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/TestEventProducer.java b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/TestEventProducer.java new file mode 100644 index 0000000..407807f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/TestEventProducer.java
@@ -0,0 +1,61 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.event.Event; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; + +public class TestEventProducer { + @Inject Event<Document> docEvent; + + @Inject @Updated(updatedBy="admin") Event<Document> updatedByAdminEvent; + + public void fireEvents(){ + Document d = new Document("Test"); + docEvent.fire(d); //general fire of a Document related event + + //send a created event + docEvent.select( + new AnnotationLiteral<Created>(){}).fire(d); + + + d.update(); + //send an updated by admin event + updatedByAdminEvent.fire(d); + + //send an updated by FooUser event + docEvent.select(new UserBinding("FooUser")).fire(d); + + } + + +} + +class UserBinding extends AnnotationLiteral<Updated> implements Updated{ + private String userName; + + public UserBinding(String userName){ + this.userName = userName; + } + + @Override + public String updatedBy() { + return this.userName; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/Updated.java b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/Updated.java new file mode 100644 index 0000000..b6893f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/beans/Updated.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Updated { + String updatedBy(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/servlet/ConditionalObserverTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/servlet/ConditionalObserverTestServlet.java new file mode 100644 index 0000000..9b25265 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/event-qualifiers-with-members/servlet/test/servlet/ConditionalObserverTestServlet.java
@@ -0,0 +1,57 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestEventConditionalObserver; +import test.beans.TestEventProducer; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class ConditionalObserverTestServlet extends HttpServlet { + + @Inject + TestEventProducer trsb; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + trsb.fireEvents(); + if (TestEventConditionalObserver.documentAdminUpdatedEvent != 1) { + msg += "Document updated event by admin not received by observer"; + } + + if (TestEventConditionalObserver.documentFooUserUpdatedEvent != 1) { + msg += "Document updated event by FooUser not received by observer"; + } + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/README b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/README new file mode 100644 index 0000000..23607e1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/README
@@ -0,0 +1,4 @@ +Test +- Use of Events + - Multiple Event Qualifiers and notification of observers when + such qualifier types are combined \ No newline at end of file
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/build.properties b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/build.properties new file mode 100644 index 0000000..362e832 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-multiple-event-qualifiers"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/build.xml b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/client/test/client/WebTest.java new file mode 100644 index 0000000..748fc4d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/client/test/client/WebTest.java
@@ -0,0 +1,108 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = + "events-multiple-event-qualifiers"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/Approved.java b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/Approved.java new file mode 100644 index 0000000..7a107aa --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/Approved.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Approved { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/Blog.java b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/Blog.java new file mode 100644 index 0000000..573402b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/Blog.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Blog { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/Created.java b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/Created.java new file mode 100644 index 0000000..f71048f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/Created.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Created { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/Document.java b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/Document.java new file mode 100644 index 0000000..6e6eee6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/Document.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public class Document { + String name = ""; + private boolean isBlog; + public Document(String name, boolean blog) { + System.out.println("Document created with name" + name ); + this.name = name; + this.isBlog = blog; + } + + public boolean isBlog(){ + return this.isBlog; + } + + public void update(){ + System.out.println("Document:" + name + " updated."); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/TestEventObserver.java b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/TestEventObserver.java new file mode 100644 index 0000000..7885b88 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/TestEventObserver.java
@@ -0,0 +1,52 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.event.Observes; + +public class TestEventObserver { + public static int documentAfterBlogUpdate; + public static int documentAfterDocumentUpdate; + public static int documentOnAnyBlogEvent; + public static int documentOnAnyDocumentEvent; + + public void afterBlogUpdate( + @Observes @Updated @Blog Document d) { + System.out.println("TestEventObserver:afterBlogUpdate"); + documentAfterBlogUpdate++; + } + + + public void afterDocumentUpdate( + @Observes @Updated Document d) { + System.out.println("TestEventObserver:afterDocumentUpdate"); + documentAfterDocumentUpdate++; + } + + public void onAnyBlogEvent( + @Observes @Blog Document d) { + System.out.println("TestEventObserver:onAnyBlogEvent"); + documentOnAnyBlogEvent++; + } + + public void onAnyDocumentEvent(@Observes Document d){ + System.out.println("TestEventObserver:onAnyDocumentEvent"); + documentOnAnyDocumentEvent++; + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/TestEventProducer.java b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/TestEventProducer.java new file mode 100644 index 0000000..a1b19d2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/TestEventProducer.java
@@ -0,0 +1,47 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.event.Event; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; + +import com.sun.research.ws.wadl.Doc; + +public class TestEventProducer { + @Inject + Event<Document> docEvent; + + @Inject @Blog + Event<Document> blogEvent; + public void fireEvents() { + Document d = new Document("Test", true); + docEvent.fire(d); // general fire of a Document related event + + // send a created event + docEvent.select(new AnnotationLiteral<Created>() { + }).fire(d); + + d.update(); + // send an updated blog event + if (d.isBlog()){ + blogEvent.select(new AnnotationLiteral<Updated>() {}).fire(d); + } + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/Updated.java b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/Updated.java new file mode 100644 index 0000000..14cebc9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/beans/Updated.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Updated { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/servlet/MultipleEventQualifierTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/servlet/MultipleEventQualifierTestServlet.java new file mode 100644 index 0000000..cb2684a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/multiple-event-qualifiers/servlet/test/servlet/MultipleEventQualifierTestServlet.java
@@ -0,0 +1,67 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestEventObserver; +import test.beans.TestEventProducer; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class MultipleEventQualifierTestServlet extends HttpServlet { + + @Inject + TestEventProducer trsb; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + trsb.fireEvents(); + if (TestEventObserver.documentAfterBlogUpdate != 1) { + msg += "Blog updated event not received by observer"; + } + + if (TestEventObserver.documentAfterDocumentUpdate != 1) { + msg += "Document updated event not received by observer"; + } + + if (TestEventObserver.documentOnAnyBlogEvent != 1) { + msg += "On Any Blog event not received by observer"; + } + + if (TestEventObserver.documentOnAnyDocumentEvent != 3) { + msg += "On any document event not received by observer"; + } + + + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/README b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/README new file mode 100644 index 0000000..039a7e9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/README
@@ -0,0 +1,5 @@ +Test +- Use of Events + - Defining Event Qualifiers + - Simple observer methods that observer qualified and any events on a particular Event payload + - Simple event producer (with qualifiers) to produce the appropriate event
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/build.properties b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/build.properties new file mode 100644 index 0000000..5b4b830 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-simple-event-observer"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/build.xml b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/client/test/client/WebTest.java new file mode 100644 index 0000000..bcac1d2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/client/test/client/WebTest.java
@@ -0,0 +1,108 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = + "events-simple-event-observer"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/beans/Created.java b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/beans/Created.java new file mode 100644 index 0000000..f71048f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/beans/Created.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Created { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/beans/Document.java b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/beans/Document.java new file mode 100644 index 0000000..d857f5a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/beans/Document.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public class Document { + String name = ""; + public Document(String name) { + System.out.println("Document created with name" + name ); + this.name = name; + } + + public void update(){ + System.out.println("Document:" + name + " updated."); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/beans/TestEventObserver.java b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/beans/TestEventObserver.java new file mode 100644 index 0000000..9b642a6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/beans/TestEventObserver.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.event.Observes; + +public class TestEventObserver { + public static int documentCreatedEvent = 0; + public static int documentUpdatedEvent = 0; + public static int documentAnyEvents = 0; + + public void onDocumentCreate(@Observes @Created Document d) { + System.out.println("TestEventObserver:onDocumentCreate"); + documentCreatedEvent++; + } + + public void onAnyDocumentEvent(@Observes Document d) { + System.out.println("TestEventObserver:onAnyDocumentUpdatedEvent"); + documentAnyEvents++; + } + + public void afterDocumentUpdate(@Observes @Updated Document d) { + System.out.println("TestEventObserver:afterDocumentUpdate"); + documentUpdatedEvent++; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/beans/TestRequestScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/beans/TestRequestScopedBean.java new file mode 100644 index 0000000..aa0613e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/beans/TestRequestScopedBean.java
@@ -0,0 +1,33 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.event.Event; +import javax.inject.Inject; + +public class TestRequestScopedBean { + @Inject @Created Event<Document> docCreatedEvent; + @Inject @Updated Event<Document> docUpdatedEvent; + + public void fireEvents(){ + Document d = new Document("Test"); + docCreatedEvent.fire(d); + d.update(); + docUpdatedEvent.fire(d); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/beans/Updated.java b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/beans/Updated.java new file mode 100644 index 0000000..07c6894 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/beans/Updated.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Updated { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/servlet/SimpleEventObserverTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/servlet/SimpleEventObserverTestServlet.java new file mode 100644 index 0000000..af1783e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/events/simple-event-observers/servlet/test/servlet/SimpleEventObserverTestServlet.java
@@ -0,0 +1,61 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestEventObserver; +import test.beans.TestRequestScopedBean; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class SimpleEventObserverTestServlet extends HttpServlet { + + @Inject + TestRequestScopedBean trsb; + + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + trsb.fireEvents(); + if (TestEventObserver.documentCreatedEvent != 1){ + msg += "Document created event not received by observer"; + } + if (TestEventObserver.documentUpdatedEvent != 1){ + msg += "Document updated event not received by observer"; + } + + if (TestEventObserver.documentAnyEvents != 2){ + msg += "# of Document event received by observer does not match expected values. expected = 2. observed="+ TestEventObserver.documentAnyEvents; + } + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/build.xml b/appserver/tests/appserv-tests/devtests/cdi/implicit/build.xml new file mode 100644 index 0000000..8860d2f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/build.xml
@@ -0,0 +1,116 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../config/common.xml"> +<!ENTITY commonRun SYSTEM "./../../../config/run.xml"> +<!ENTITY reporting SYSTEM "../report.xml"> +]> + +<project name="implicit-test" default="usage" basedir="."> + + &commonSetup; + &commonBuild; + &commonRun; + &reporting; + + <property name="implicit-target" value="all"/> + + <taskdef resource="net/sf/antcontrib/antcontrib.properties"> + <classpath> + <pathelement location="${env.APS_HOME}/devtests/cdi/lib/ant-contrib-1.0b3.jar"/> + </classpath> + </taskdef> + + <target name="run-test"> + <antcall target="implicit"> + <param name="implicit-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="implicit"> + <param name="implicit-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="implicit"> + <param name="implicit-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="implicit"> + <param name="implicit-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="implicit"> + <param name="implicit-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="implicit"> + <param name="implicit-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="implicit"> + <param name="implicit-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="implicit"> + <param name="implicit-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="implicit"> + <param name="implicit-target" value="run"/> + </antcall> + </target> + + <target name="implicit"> + <record name="implicit.output" action="start" /> + <ant dir="simple-ejb-cdi" target="${implicit-target}"/> + <ant dir="deployment-option" target="${implicit-target}"/> + <!--ant dir="bean-discovery-mode-none" target="${implicit-target}"/--> + <record name="implicit.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant all (Executes all the smoke tests) + ant clean (cleans all the smoke tests) + ant build (builds all the smoke tests) + ant setup (sets up all resources for smoke tests) + ant deploy (deploys all the smoke apps) + ant run (Executes all the smoke tests) + ant undeploy (undeploys all the smoke apps) + ant unsetup (unsets all resources for smoke tests) + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/build.properties b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/build.properties new file mode 100644 index 0000000..281ba02 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/build.properties
@@ -0,0 +1,33 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="simple-ejb-implicit-cdi-deployment-opt"/> +<property name="appname" value="${module}"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="test.client" value="Client"/> +<property name="application.xml" value="descriptor/application.xml"/> +<property name="sun-application.xml" value="descriptor/sun-application.xml"/> +<property name="ejb-jar.xml" value="descriptor/ejb-jar.xml"/> +<property name="sun-ejb-jar.xml" value="descriptor/sun-ejb-jar.xml"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="application-client.xml" value="descriptor/application-client.xml"/> +<property name="sun-application-client.xml" value="descriptor/sun-application-client.xml"/> +<property name="appclientjar.files" value="${build.classes.dir}"/> +<property name="appclient.jar" value="${assemble.dir}/${appname}-client.jar"/> +<property name="app.type" value="application"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/build.xml b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/build.xml new file mode 100644 index 0000000..f13f542 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/build.xml
@@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="simple-ejb-implicit-cdi-deployment-opt" default="usage" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete file="client/Client.java"/> + </target> + + <target name="compile" depends="clean"> + <copy file="client/Client.java.token" tofile="client/Client.java"/> + <replace file="client/Client.java" token="@ORB_PORT@" value="${orb.port}"/> + + <antcall target="compile-common"> + <param name="src" value="ejb"/> + </antcall> + <antcall target="compile-common"> + <param name="src" value="client"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <antcall target="build-ear-common"> + <param name="ejbjar.classes" + value="**/Sless*.class, **/ImplicitTestBean.class"/> + <param name="appclientjar.classes" + value="**/Client.class,**/Sless.class"/> + </antcall> + </target> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-common"> + <param name="extra-params" value="--property implicitCdiEnabled=false"/> + </antcall> + </target> + + <target name="run" depends="init-common"> + <antcall target="runclient-common"/> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/client/Client.java b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/client/Client.java new file mode 100644 index 0000000..65d580f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/client/Client.java
@@ -0,0 +1,74 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.util.*; +import javax.ejb.EJB; +import javax.naming.InitialContext; +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +public class Client { + + private static SimpleReporterAdapter stat = + new SimpleReporterAdapter("appserv-tests"); + + public static void main (String[] args) { + + stat.addDescription("simple-ejb-implicit-cdi-deployment-opt"); + Client client = new Client(args); + client.doTest(); + stat.printSummary("simple-ejb-implicit-cdi-deployment-opt"); + } + + public Client (String[] args) { + } + + private static @EJB(mappedName="Sless") Sless sless; + + public void doTest() { + + try { + + System.out.println("Creating InitialContext()"); + InitialContext ic = new InitialContext(); + org.omg.CORBA.ORB orb = (org.omg.CORBA.ORB) ic.lookup("java:comp/ORB"); + Sless sless = (Sless) ic.lookup("Sless"); + + String response = null; + + response = sless.hello(); + testResponse("invoking stateless", response); + + System.out.println("test complete"); + + stat.addStatus("local main", stat.PASS); + + } catch(Exception e) { + e.printStackTrace(); + stat.addStatus("local main" , stat.FAIL); + } + + return; + } + + private void testResponse(String testDescription, String response){ + // Expecting a null response because the injection should fail since implicit bean discovery + // is disabled by the deployment property implicitCdiEnabled=false + stat.addStatus(testDescription, (response == null ? stat.PASS : stat.FAIL)); + } + +} +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/client/Client.java.token b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/client/Client.java.token new file mode 100644 index 0000000..f377ea1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/client/Client.java.token
@@ -0,0 +1,75 @@ +/* + * Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + + +import java.io.*; +import java.util.*; +import javax.ejb.EJB; +import javax.naming.InitialContext; +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +public class Client { + + private static SimpleReporterAdapter stat = + new SimpleReporterAdapter("appserv-tests"); + + public static void main (String[] args) { + + stat.addDescription("simple-ejb-implicit-cdi-deployment-opt"); + Client client = new Client(args); + client.doTest(); + stat.printSummary("simple-ejb-implicit-cdi-deployment-opt"); + } + + public Client (String[] args) { + } + + private static @EJB(mappedName="Sless") Sless sless; + + public void doTest() { + + try { + + System.out.println("Creating InitialContext()"); + InitialContext ic = new InitialContext(); + org.omg.CORBA.ORB orb = (org.omg.CORBA.ORB) ic.lookup("java:comp/ORB"); + Sless sless = (Sless) ic.lookup("Sless"); + + String response = null; + + response = sless.hello(); + testResponse("invoking stateless", response); + + System.out.println("test complete"); + + stat.addStatus("local main", stat.PASS); + + } catch(Exception e) { + e.printStackTrace(); + stat.addStatus("local main" , stat.FAIL); + } + + return; + } + + private void testResponse(String testDescription, String response){ + // Expecting a null response because the injection should fail since implicit bean discovery + // is disabled by the deployment property implicitCdiEnabled=false + stat.addStatus(testDescription, (response == null ? stat.PASS : stat.FAIL)); + } + +} +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/client/MANIFEST.MF b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/client/MANIFEST.MF new file mode 100644 index 0000000..20ba4bf --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/client/MANIFEST.MF
@@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Created-By: 1.4.0-beta3 (Sun Microsystems Inc.) +Main-Class: Client +Class-Path: reporter.jar
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/ejb/ImplicitTestBean.java b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/ejb/ImplicitTestBean.java new file mode 100644 index 0000000..c7ca937 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/ejb/ImplicitTestBean.java
@@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import javax.enterprise.context.RequestScoped; + +//Simple TestBean to test CDI. +@RequestScoped +public class ImplicitTestBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/ejb/Sless.java b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/ejb/Sless.java new file mode 100644 index 0000000..851ca56 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/ejb/Sless.java
@@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import javax.ejb.Remote; + +@Remote +public interface Sless { + public String hello(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/ejb/SlessEJB.java b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/ejb/SlessEJB.java new file mode 100644 index 0000000..30d299a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/ejb/SlessEJB.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import javax.ejb.Stateless; +import javax.inject.Inject; + + +@Stateless +public class SlessEJB implements Sless { + + @Inject ImplicitTestBean tb; //Field Injection + + public String hello() { + System.out.println("In SlessEJB:hello()"); + if (tb != null) return "hello"; + else return null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/readme.txt b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/readme.txt new file mode 100644 index 0000000..ad1515b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/deployment-option/readme.txt
@@ -0,0 +1,3 @@ +client/Client.java is created during build process from client/Client.java.token via copying it and replacing token @ORB_PORT@ with the ORB port number from config.properties (${orb.pprt}). + +The application is deployed with the implicitCdiEnabled deployment property set to false, which disables CDI 1.1 implicit bean discovery.
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/build.properties b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/build.properties new file mode 100644 index 0000000..382bcd3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/build.properties
@@ -0,0 +1,33 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="simple-ejb-implicit-cdi"/> +<property name="appname" value="${module}"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="test.client" value="Client"/> +<property name="application.xml" value="descriptor/application.xml"/> +<property name="sun-application.xml" value="descriptor/sun-application.xml"/> +<property name="ejb-jar.xml" value="descriptor/ejb-jar.xml"/> +<property name="sun-ejb-jar.xml" value="descriptor/sun-ejb-jar.xml"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="application-client.xml" value="descriptor/application-client.xml"/> +<property name="sun-application-client.xml" value="descriptor/sun-application-client.xml"/> +<property name="appclientjar.files" value="${build.classes.dir}"/> +<property name="appclient.jar" value="${assemble.dir}/${appname}-client.jar"/> +<property name="app.type" value="application"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/build.xml b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/build.xml new file mode 100644 index 0000000..2b950fc --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/build.xml
@@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="simple-ejb-cdi" default="usage" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete file="client/Client.java"/> + </target> + + <target name="compile" depends="clean"> + <copy file="client/Client.java.token" tofile="client/Client.java"/> + <replace file="client/Client.java" token="@ORB_PORT@" value="${orb.port}"/> + + <antcall target="compile-common"> + <param name="src" value="ejb"/> + </antcall> + <antcall target="compile-common"> + <param name="src" value="client"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <antcall target="build-ear-common"> + <param name="ejbjar.classes" + value="**/Sless*.class, **/ImplicitTestBean.class"/> + <param name="appclientjar.classes" + value="**/Client.class,**/Sless.class"/> + </antcall> + </target> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-common"/> + </target> + + <target name="run" depends="init-common"> + <antcall target="runclient-common"/> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/client/Client.java b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/client/Client.java new file mode 100644 index 0000000..339f717 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/client/Client.java
@@ -0,0 +1,98 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.util.*; +import javax.ejb.EJB; +import javax.naming.InitialContext; +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +public class Client { + + private static SimpleReporterAdapter stat = + new SimpleReporterAdapter("appserv-tests"); + + public static void main (String[] args) { + + stat.addDescription("simple-ejb-implicit-cdi"); + Client client = new Client(args); + client.doTest(); + stat.printSummary("simple-ejb-implicit-cdi"); + } + + public Client (String[] args) { + } + + private static @EJB(mappedName="Sless") Sless sless; + + // + // NOTE: Token 3700 will be replaced in @EJB annotations below + // with the value of the port from config.properties during the build + // + private static @EJB(mappedName="corbaname:iiop:localhost:3700#Sless") Sless sless2; + + private static @EJB(mappedName="corbaname:iiop:localhost:3700#java:global/simple-ejb-implicit-cdiApp/simple-ejb-implicit-cdi-ejb/SlessEJB!Sless") Sless sless3; + + + public void doTest() { + + try { + + System.out.println("Creating InitialContext()"); + InitialContext ic = new InitialContext(); + org.omg.CORBA.ORB orb = (org.omg.CORBA.ORB) ic.lookup("java:comp/ORB"); + Sless sless = (Sless) ic.lookup("Sless"); + + String response = null; + + response = sless.hello(); + testResponse("invoking stateless", response); + + response = sless2.hello(); + testResponse("invoking stateless2", response); + + System.out.println("ensuring that sless1 and sless2 are not equal"); + if( !sless.equals(sless2) ) { + stat.addStatus("ensuring that sless1 and sless2 are not equal" , stat.FAIL); + throw new Exception("invalid equality checks on same " + + "sless session beans"); + } + + + response = sless3.hello(); + testResponse("invoking stateless3", response); + + System.out.println("test complete"); + + stat.addStatus("local main", stat.PASS); + + } catch(Exception e) { + e.printStackTrace(); + stat.addStatus("local main" , stat.FAIL); + } + + return; + } + + private void testResponse(String testDescription, String response){ + if(response.equals("hello")) + stat.addStatus(testDescription, stat.PASS); + else + stat.addStatus(testDescription, stat.FAIL); + } + +} +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/client/Client.java.token b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/client/Client.java.token new file mode 100644 index 0000000..d1e456d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/client/Client.java.token
@@ -0,0 +1,99 @@ +/* + * Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + + +import java.io.*; +import java.util.*; +import javax.ejb.EJB; +import javax.naming.InitialContext; +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +public class Client { + + private static SimpleReporterAdapter stat = + new SimpleReporterAdapter("appserv-tests"); + + public static void main (String[] args) { + + stat.addDescription("simple-ejb-implicit-cdi"); + Client client = new Client(args); + client.doTest(); + stat.printSummary("simple-ejb-implicit-cdi"); + } + + public Client (String[] args) { + } + + private static @EJB(mappedName="Sless") Sless sless; + + // + // NOTE: Token @ORB_PORT@ will be replaced in @EJB annotations below + // with the value of the port from config.properties during the build + // + private static @EJB(mappedName="corbaname:iiop:localhost:@ORB_PORT@#Sless") Sless sless2; + + private static @EJB(mappedName="corbaname:iiop:localhost:@ORB_PORT@#java:global/simple-ejb-implicit-cdiApp/simple-ejb-implicit-cdi-ejb/SlessEJB!Sless") Sless sless3; + + + public void doTest() { + + try { + + System.out.println("Creating InitialContext()"); + InitialContext ic = new InitialContext(); + org.omg.CORBA.ORB orb = (org.omg.CORBA.ORB) ic.lookup("java:comp/ORB"); + Sless sless = (Sless) ic.lookup("Sless"); + + String response = null; + + response = sless.hello(); + testResponse("invoking stateless", response); + + response = sless2.hello(); + testResponse("invoking stateless2", response); + + System.out.println("ensuring that sless1 and sless2 are not equal"); + if( !sless.equals(sless2) ) { + stat.addStatus("ensuring that sless1 and sless2 are not equal" , stat.FAIL); + throw new Exception("invalid equality checks on same " + + "sless session beans"); + } + + + response = sless3.hello(); + testResponse("invoking stateless3", response); + + System.out.println("test complete"); + + stat.addStatus("local main", stat.PASS); + + } catch(Exception e) { + e.printStackTrace(); + stat.addStatus("local main" , stat.FAIL); + } + + return; + } + + private void testResponse(String testDescription, String response){ + if(response.equals("hello")) + stat.addStatus(testDescription, stat.PASS); + else + stat.addStatus(testDescription, stat.FAIL); + } + +} +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/client/MANIFEST.MF b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/client/MANIFEST.MF new file mode 100644 index 0000000..20ba4bf --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/client/MANIFEST.MF
@@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Created-By: 1.4.0-beta3 (Sun Microsystems Inc.) +Main-Class: Client +Class-Path: reporter.jar
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/ejb/ImplicitTestBean.java b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/ejb/ImplicitTestBean.java new file mode 100644 index 0000000..c7ca937 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/ejb/ImplicitTestBean.java
@@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import javax.enterprise.context.RequestScoped; + +//Simple TestBean to test CDI. +@RequestScoped +public class ImplicitTestBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/ejb/Sless.java b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/ejb/Sless.java new file mode 100644 index 0000000..851ca56 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/ejb/Sless.java
@@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import javax.ejb.Remote; + +@Remote +public interface Sless { + public String hello(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/ejb/SlessEJB.java b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/ejb/SlessEJB.java new file mode 100644 index 0000000..30d299a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/ejb/SlessEJB.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import javax.ejb.Stateless; +import javax.inject.Inject; + + +@Stateless +public class SlessEJB implements Sless { + + @Inject ImplicitTestBean tb; //Field Injection + + public String hello() { + System.out.println("In SlessEJB:hello()"); + if (tb != null) return "hello"; + else return null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/readme.txt b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/readme.txt new file mode 100644 index 0000000..bad16d6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/implicit/simple-ejb-cdi/readme.txt
@@ -0,0 +1 @@ +client/Client.java is created during build process from client/Client.java.token via copying it and replacing token @ORB_PORT@ with the ORB port number from config.properties (${orb.pprt}).
diff --git a/appserver/tests/appserv-tests/devtests/cdi/injection-point/README b/appserver/tests/appserv-tests/devtests/cdi/injection-point/README new file mode 100644 index 0000000..3892cf0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/injection-point/README
@@ -0,0 +1,4 @@ +Test +- Use of InjectionPoint API to get dependent objects that needs to know something +about the injection point(Logger and HttpParams example from the CDI documentation at +https://docs.jboss.org/weld/reference/snapshot/en-US/html/injection.html#d0e1635)
diff --git a/appserver/tests/appserv-tests/devtests/cdi/injection-point/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/injection-point/WebTest.java new file mode 100644 index 0000000..4fd782a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/injection-point/WebTest.java
@@ -0,0 +1,110 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "injection-point-tests"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Testing InjectionPoint capabilities"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl?username=scott&password=tiger"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + System.out.println("TESTNAME " + TEST_NAME); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/injection-point/build.properties b/appserver/tests/appserv-tests/devtests/cdi/injection-point/build.properties new file mode 100644 index 0000000..57ba5ff --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/injection-point/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi-programmatic-lookup"/> +<property name="appname" value="${module}-servlet-annotation"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/injection-point/build.xml b/appserver/tests/appserv-tests/devtests/cdi/injection-point/build.xml new file mode 100644 index 0000000..c0d904d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/injection-point/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/injection-point/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/injection-point/descriptor/beans.xml new file mode 100644 index 0000000..c35311a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/injection-point/descriptor/beans.xml
@@ -0,0 +1,23 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/injection-point/servlet/InjectionPointFilter.java b/appserver/tests/appserv-tests/devtests/cdi/injection-point/servlet/InjectionPointFilter.java new file mode 100644 index 0000000..0fd897e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/injection-point/servlet/InjectionPointFilter.java
@@ -0,0 +1,54 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; + +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 javax.servlet.annotation.WebFilter; + +import test.artifacts.HttpParams; + + +//A web filter to set ServletRequest in the thread local context. +@WebFilter(urlPatterns="/*") +public class InjectionPointFilter implements Filter{ + + @Override + public void destroy() { + System.out.println("InjectionPointFilter::destroy"); + + } + + public void doFilter(ServletRequest req, ServletResponse res, + FilterChain arg2) throws IOException, ServletException { + System.out.println("InjectionPointFilter::doFilter"); + //setting the ServletRequest in the thread-local + //variable so that it could be used in HttpParams + HttpParams.sr.set(req); + arg2.doFilter(req, res); + } + + @Override + public void init(FilterConfig arg0) throws ServletException { + System.out.println("InjectionPointFilter::init"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/injection-point/servlet/InjectionPointServlet.java b/appserver/tests/appserv-tests/devtests/cdi/injection-point/servlet/InjectionPointServlet.java new file mode 100644 index 0000000..137e205 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/injection-point/servlet/InjectionPointServlet.java
@@ -0,0 +1,69 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.logging.Logger; + +import javax.enterprise.inject.Instance; +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.artifacts.HttpParam; +import test.artifacts.HttpParams; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class InjectionPointServlet extends HttpServlet { + + @Inject + Logger log; + + // Another workaround. The servletrequest is not available in HttpParams + // unless the request comes in and so we use programmatic lookup of the + // http parameters + @Inject + @HttpParam() + Instance<String> username; + @Inject + @HttpParam() + Instance<String> password; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + System.out.println("Injected logger into servlet:" + log); + boolean loggerAvailable = (log != null); + if (!loggerAvailable) + msg += " Logger unavailable:" + "injection into Servlet Failed "; + + System.out.println("Injected username:" + username.get() + + " password:" + password.get()); + boolean httpParamInjectionSuccess = username.get().equals("scott") + && password.get().equals("tiger"); + if (!httpParamInjectionSuccess) + msg += " HTTP Parameter injection through InjectionPoint capabilities failed "; + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/injection-point/servlet/test/artifacts/HttpParam.java b/appserver/tests/appserv-tests/devtests/cdi/injection-point/servlet/test/artifacts/HttpParam.java new file mode 100644 index 0000000..88e91c7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/injection-point/servlet/test/artifacts/HttpParam.java
@@ -0,0 +1,33 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import static java.lang.annotation.ElementType.*; + +import javax.enterprise.util.Nonbinding; +import javax.inject.Qualifier; + +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target({TYPE, METHOD, FIELD, PARAMETER}) +public @interface HttpParam { + @Nonbinding public String value() default ""; //If none specified, the injection point's member name is used as the parameter name. + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/injection-point/servlet/test/artifacts/HttpParams.java b/appserver/tests/appserv-tests/devtests/cdi/injection-point/servlet/test/artifacts/HttpParams.java new file mode 100644 index 0000000..d7d2bd4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/injection-point/servlet/test/artifacts/HttpParams.java
@@ -0,0 +1,45 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +import java.util.Enumeration; + +import javax.enterprise.context.RequestScoped; +import javax.enterprise.inject.Produces; +import javax.enterprise.inject.spi.InjectionPoint; +import javax.servlet.ServletRequest; + +@RequestScoped +public class HttpParams { + //A thread local variable to house the servlet request. This is set by the + //servlet filter. This is not a recommended way to get hold of HttpServletRequest + //in a CDI bean but a workaround that is described in + //http://www.seamframework.org/Community/HowToReachHttpServletRequestAndHttpServletResponseFromBean + //The right approach is to use JSF's FacesContext as described in + //https://docs.jboss.org/weld/reference/snapshot/en-US/html/injection.html#d0e1635 + public static ThreadLocal<ServletRequest> sr = new ThreadLocal<ServletRequest>(); + + @Produces + @HttpParam("") + String getParamValue(InjectionPoint ip) { + ServletRequest req = sr.get(); + String parameterName = ip.getAnnotated().getAnnotation(HttpParam.class).value(); + if (parameterName.trim().equals("")) parameterName = ip.getMember().getName(); + return req.getParameter(parameterName); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/injection-point/servlet/test/artifacts/LogFactory.java b/appserver/tests/appserv-tests/devtests/cdi/injection-point/servlet/test/artifacts/LogFactory.java new file mode 100644 index 0000000..a486c8f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/injection-point/servlet/test/artifacts/LogFactory.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +import java.util.logging.Logger; + +import javax.enterprise.inject.Produces; +import javax.enterprise.inject.spi.InjectionPoint; + +public class LogFactory { + @Produces Logger createLogger(InjectionPoint ip){ + String name=ip.getMember().getDeclaringClass().getName(); + System.out.println("Logger for:"+ name); + System.out.println("Logger:" + Logger.getLogger(name)); + return Logger.getLogger(name); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/build.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/build.xml new file mode 100644 index 0000000..0cb7ab1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/build.xml
@@ -0,0 +1,105 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<project name="interceptors-test" default="usage" basedir="."> + + <property name="interceptors-target" value="all"/> + + <target name="run-test"> + <antcall target="interceptors"> + <param name="interceptors-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="interceptors"> + <param name="interceptors-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="interceptors"> + <param name="interceptors-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="interceptors"> + <param name="interceptors-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="interceptors"> + <param name="interceptors-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="interceptors"> + <param name="interceptors-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="interceptors"> + <param name="interceptors-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="interceptors"> + <param name="interceptors-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="interceptors"> + <param name="interceptors-target" value="run"/> + </antcall> + </target> + + <target name="interceptors"> + <record name="interceptors.output" action="start" /> + <ant dir="interceptors-bean-validation" target="${interceptors-target}"/> + <ant dir="interceptors-binding-type-inheritance" target="${interceptors-target}"/> + <ant dir="interceptors-binding-type-with-members" target="${interceptors-target}"/> + <ant dir="interceptors-business-method-interception" target="${interceptors-target}"/> + <ant dir="interceptors-invalid-interceptor-specified-at-beans-xml" target="${interceptors-target}"/> + <ant dir="interceptors-multiple-interceptor-binding-annotations" target="${interceptors-target}"/> + <ant dir="interceptors-multiple-interceptors-for-a-binding-type" target="${interceptors-target}"/> + <ant dir="interceptors-use-of-at-interceptors" target="${interceptors-target}"/> + <ant dir="interceptors-use-of-interceptors-in-ejbs-through-at-interceptors" target="${interceptors-target}"/> + <ant dir="interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings" target="${interceptors-target}"/> + <record name="interceptors.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant all (Executes all the interceptors tests) + ant clean (cleans all the interceptors tests) + ant build (builds all the interceptors tests) + ant setup (sets up all resources for interceptors tests) + ant deploy (deploys all the interceptors apps) + ant run (Executes all the interceptors tests) + ant undeploy (undeploys all the interceptors apps) + ant unsetup (unsets all resources for interceptors tests) + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/README b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/README new file mode 100644 index 0000000..05388f4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/README
@@ -0,0 +1,5 @@ +Test +- Use of business method interceptors + - definition of interceptor binding, interceptor and enabling +interceptor in beans.xml. check interceptor AroundInvoke invocation count + - injection of beans into Interceptors
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/build.properties b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/build.properties new file mode 100644 index 0000000..90a4e51 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-bean-validation"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/build.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/build.xml new file mode 100644 index 0000000..4c7e300 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/build.xml
@@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <property name="jpda.port" value="5009"/> + <property name="suspend" value="n"/> + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java fork="true" classname="test.client.WebTest"> + <jvmarg value="-agentlib:jdwp=transport=dt_socket,server=y,suspend=${suspend},address=${jpda.port}"/> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/client/test/client/WebTest.java new file mode 100644 index 0000000..0684cfd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/client/test/client/WebTest.java
@@ -0,0 +1,103 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "interceptors-bean-validation"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)).openConnection(); + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/descriptor/beans.xml new file mode 100644 index 0000000..1af38a6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/descriptor/beans.xml
@@ -0,0 +1,26 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.TestInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/AnotherTestBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/AnotherTestBean.java new file mode 100644 index 0000000..a2d8873 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/AnotherTestBean.java
@@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.validation.constraints.NotNull; + + +/** + * @author <a href="mailto:phil.zampino@oracle.com">Phil Zampino</a> + */ +@CDITest +public class AnotherTestBean { + + private TestProduct tp; + + + @Inject + public AnotherTestBean(@Preferred TestProduct testProduct) { + this.tp = testProduct; + } + + + @PostConstruct + public void log() { + System.out.println("TestProduct injected: " + (tp != null)); + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/BadProducer.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/BadProducer.java new file mode 100644 index 0000000..c5e5f43 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/BadProducer.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.inject.Produces; + + +/** + * @author <a href="mailto:phil.zampino@oracle.com">Phil Zampino</a> + */ +public class BadProducer { + + @Produces @Preferred + public TestProduct getTestProduct() { + System.out.println(getClass().getName() + "#getTestProducer() invoked...returning null"); + return null; // This producer is bad because it always returns null + } + + @Produces @Preferred + public String getPreferredString() { + return null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/Bar.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/Bar.java new file mode 100644 index 0000000..d0bf09f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/Bar.java
@@ -0,0 +1,23 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +/** + * @author <a href="mailto:phil.zampino@oracle.com">Phil Zampino</a> + */ +public interface Bar { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/BarImpl.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/BarImpl.java new file mode 100644 index 0000000..63b2ab8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/BarImpl.java
@@ -0,0 +1,23 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +/** + * @author <a href="mailto:phil.zampino@oracle.com">Phil Zampino</a> + */ +public class BarImpl implements Bar { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/CDITest.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/CDITest.java new file mode 100644 index 0000000..a21f4fb --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/CDITest.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface CDITest { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/Foo.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/Foo.java new file mode 100644 index 0000000..326d12e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/Foo.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +/** + * @author <a href="mailto:phil.zampino@oracle.com">Phil Zampino</a> + */ +public interface Foo { + + public String value(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/FooImpl.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/FooImpl.java new file mode 100644 index 0000000..fdee67b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/FooImpl.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +/** + * @author <a href="mailto:phil.zampino@oracle.com">Phil Zampino</a> + */ +public class FooImpl implements Foo { + + @Override + public String value() { + return getClass().getName(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..4323e19 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/Preferred.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; + +import javax.inject.Qualifier; + + +/** + * @author <a href="mailto:phil.zampino@oracle.com">Phil Zampino</a> + */ +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE}) +public @interface Preferred { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..2515cf2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/TestBean.java
@@ -0,0 +1,69 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.annotation.PostConstruct; +import javax.enterprise.context.RequestScoped; + +import javax.validation.constraints.NotNull; + +import javax.inject.Inject; + + +@RequestScoped +@CDITest +public class TestBean { + + private Bar myBar; + + @Inject + private Foo myFoo; + + private String ctorLog; + + public TestBean() { + ctorLog = "no-args ctor"; + } + + + @Inject + public TestBean(@NotNull Bar bar) { + ctorLog = "annotated ctor"; + this.myBar = bar; + } + + @PostConstruct + private void log() { + System.out.println(toString() + ": ctor=" + getConstructorLog() + " ; myFoo=" + myFoo.toString() + " ; myBar=" + myBar.toString()); + } + + public String echo(@NotNull String message) { + System.out.println("TestBean::echo called with String argument: " + message); + return message + " : " + myFoo.value() + " : " + myBar.toString(); + } + + + public void hello(String name) { + System.out.println("TestBean::hello called with String argument: " + name); + } + + + public String getConstructorLog() { + return ctorLog; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/TestDependentBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/TestDependentBean.java new file mode 100644 index 0000000..0811a03 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/TestDependentBean.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + + +import javax.inject.Inject; + + +public class TestDependentBean { + + @Inject TestBean bean; + + + public TestBean getTestBean() { + return bean; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/TestInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/TestInterceptor.java new file mode 100644 index 0000000..de03948 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/TestInterceptor.java
@@ -0,0 +1,65 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundConstruct; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@CDITest +@Interceptor +public class TestInterceptor { + + public static boolean aroundConstructCalled = false; + public static int aroundConstructInvocationCount = 0; + + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + + public static String errorMessage = ""; + + @AroundConstruct + public void interceptConstruction(InvocationContext ctx) throws Exception { + + System.out.println(getClass().getName() + "::AroundConstruct"); + + aroundConstructCalled = true; + aroundConstructInvocationCount++; + + ctx.proceed(); + } + + @AroundInvoke + public Object interceptInvocation(InvocationContext ctx) throws Exception { + + System.out.println(getClass().getName() + "::AroundInvoke"); + + aroundInvokeCalled = true; + aroundInvokeInvocationCount++; + + return ctx.proceed(); + } + + public static void clear() { + aroundConstructCalled = false; + aroundConstructInvocationCount = 0; + errorMessage = ""; + } + + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/TestProduct.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/TestProduct.java new file mode 100644 index 0000000..95e32ad --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/beans/TestProduct.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +/** + * @author <a href="mailto:phil.zampino@oracle.com">Phil Zampino</a> + */ +public class TestProduct { + + public TestProduct() { + System.out.println(getClass().getName() + "Default Constructor invoked."); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/servlet/BusinessMethodInterceptorTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/servlet/BusinessMethodInterceptorTestServlet.java new file mode 100644 index 0000000..e5302a9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-bean-validation/servlet/test/servlet/BusinessMethodInterceptorTestServlet.java
@@ -0,0 +1,110 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.AnotherTestBean; +import test.beans.Preferred; +import test.beans.TestBean; +import test.beans.TestInterceptor; + + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class BusinessMethodInterceptorTestServlet extends HttpServlet { + + @Inject + TestBean tb; + + + @Inject @Preferred + String echoMessage; + + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (tb == null) { + msg += "Injection of request scoped bean failed "; + } + + // Violate the constraint on the echo method + try { + tb.echo(null); + msg += "; Expected ConstraintViolationException not thrown "; + } catch (Exception e) { + // Expected exception + if (!"javax.validation.ConstraintViolationException".equals(e.getClass().getName())) { + msg += "; Unexpected exception: " + e.getClass().getName(); + } + } + + // Since validation failed, the aroundConstruct interceptor method should still have been called + if (!TestInterceptor.aroundConstructCalled) { + msg += "; Business method interceptor aroundConstruct was not called "; + } + + // Since validation failed, the interceptor should not have been called + if (TestInterceptor.aroundInvokeCalled || TestInterceptor.aroundInvokeInvocationCount != 0) { + msg += "; Business method interceptor aroundInvoke should not have been called "; + } + + tb.echo("Test Echo Request Message"); + + if (!TestInterceptor.aroundConstructCalled) { + msg += "; Business method interceptor aroundConstruct not called "; + } + + if (!TestInterceptor.aroundInvokeCalled || TestInterceptor.aroundInvokeInvocationCount != 1) { + msg += "; Business method interceptor aroundInvoke not called "; + } + + tb.hello("Client"); + + if (TestInterceptor.aroundInvokeInvocationCount != 2) { + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected=2, actual=" + + TestInterceptor.aroundInvokeInvocationCount; + } + + if (TestInterceptor.aroundConstructInvocationCount != 1) { + msg += "Bean construct interceptor invocation count not expected. " + + "expected=1, actual=" + + TestInterceptor.aroundConstructInvocationCount; + } + + if (!TestInterceptor.errorMessage.trim().equals("")) { + msg += TestInterceptor.errorMessage; + } + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/README b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/README new file mode 100644 index 0000000..d71c47b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/README
@@ -0,0 +1,5 @@ +Test +- Use of business method interceptors + - Interceptor binding type inheritance + - bean annotated with @Action bound to TranscationInterceptor, + SecureInterceptor, TransactionalSecureInterceptor
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/build.properties b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/build.properties new file mode 100644 index 0000000..8432d77 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-interceptor-binding-type-inheritance"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/build.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/client/test/client/WebTest.java new file mode 100644 index 0000000..3c45f3c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/client/test/client/WebTest.java
@@ -0,0 +1,108 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = + "interceptors-interceptor-binding-type-inheritance"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/descriptor/beans.xml new file mode 100644 index 0000000..c7dc6b2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/descriptor/beans.xml
@@ -0,0 +1,30 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.TransactionalSecureInterceptor</class> + <class>test.beans.TransactionInterceptor</class> + <class>test.beans.SecureInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/Action.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/Action.java new file mode 100644 index 0000000..684bd63 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/Action.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; +import javax.interceptor.InterceptorBinding; + +@Target({ TYPE, METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +@Transactional @Secure +public @interface Action { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..fa8fdb7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/SecondShoppingCart.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/SecondShoppingCart.java new file mode 100644 index 0000000..c7cd9a5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/SecondShoppingCart.java
@@ -0,0 +1,27 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +@Action +@Preferred +public class SecondShoppingCart { + + public void checkout() { + System.out.println("SecondShoppingCart::checkout"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/Secure.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/Secure.java new file mode 100644 index 0000000..90251e3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/Secure.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; +import javax.interceptor.InterceptorBinding; + +@Target({ TYPE, METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Secure { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/SecureInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/SecureInterceptor.java new file mode 100644 index 0000000..7085281 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/SecureInterceptor.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Secure @Interceptor +public class SecureInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestRequestScopedBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + + System.out.println("SecureInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + tb.interceptorInvocationOrder.add(this.getClass().getCanonicalName()); + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/ShoppingCart.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/ShoppingCart.java new file mode 100644 index 0000000..793c408 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/ShoppingCart.java
@@ -0,0 +1,25 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public class ShoppingCart { + + @Action public void checkout(){ + System.out.println("ShoppingCart::checkout"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4792d26 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/TestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class TestBean { + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/TestRequestScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/TestRequestScopedBean.java new file mode 100644 index 0000000..4317821 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/TestRequestScopedBean.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.util.ArrayList; +import java.util.List; + +import javax.enterprise.context.RequestScoped; + +@RequestScoped +public class TestRequestScopedBean { + public static List<String> interceptorInvocationOrder = new ArrayList<String>(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/TransactionInterceptor.java new file mode 100644 index 0000000..5e47864 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/TransactionInterceptor.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Transactional @Interceptor +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestRequestScopedBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + tb.interceptorInvocationOrder.add(this.getClass().getCanonicalName()); + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/Transactional.java new file mode 100644 index 0000000..42f2c58 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/Transactional.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/TransactionalSecureInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/TransactionalSecureInterceptor.java new file mode 100644 index 0000000..ddcdff6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/beans/TransactionalSecureInterceptor.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Transactional @Secure @Interceptor +public class TransactionalSecureInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestRequestScopedBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + + System.out.println("TransactionalSecureInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + tb.interceptorInvocationOrder.add(this.getClass().getCanonicalName()); + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/servlet/BindingTypeInheritanceTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/servlet/BindingTypeInheritanceTestServlet.java new file mode 100644 index 0000000..0d74aae --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-inheritance/servlet/test/servlet/BindingTypeInheritanceTestServlet.java
@@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.Preferred; +import test.beans.SecondShoppingCart; +import test.beans.SecureInterceptor; +import test.beans.ShoppingCart; +import test.beans.TestBean; +import test.beans.TransactionInterceptor; +import test.beans.TransactionalSecureInterceptor; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class BindingTypeInheritanceTestServlet extends HttpServlet { + + @Inject + ShoppingCart sc; + + @Inject + @Preferred + SecondShoppingCart sc2; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + // Now use the two shopping cart to test TransactionalSecureInterceptor + sc.checkout(); + if (!TransactionalSecureInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke on " + + "TransactionSecureInterceptor not called"; + + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke on " + + "TransactionInterceptor not called"; + + if (!SecureInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke on " + + "SecureInterceptor not called"; + + if (TransactionalSecureInterceptor.aroundInvokeInvocationCount != 1) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =1, actual=" + + TransactionalSecureInterceptor.aroundInvokeInvocationCount; + if (!TransactionalSecureInterceptor.errorMessage.trim().equals("")) + msg += TransactionalSecureInterceptor.errorMessage; + + // reset all counts + TransactionInterceptor.clear(); + SecureInterceptor.clear(); + TransactionalSecureInterceptor.clear(); + + // try on the second shopping cart bean + sc2.checkout(); + if (!TransactionalSecureInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke on " + + "TransactionSecureInterceptor not called"; + + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke on " + + "TransactionInterceptor not called"; + + if (!SecureInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke on " + + "SecureInterceptor not called"; + + if (TransactionalSecureInterceptor.aroundInvokeInvocationCount != 1) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =1, actual=" + + TransactionalSecureInterceptor.aroundInvokeInvocationCount; + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/README b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/README new file mode 100644 index 0000000..3e2d829 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/README
@@ -0,0 +1,6 @@ +Test +- Use of business method interceptors + - definition of interceptor binding type with members + - association of an interceptor binding type with different values for a member + variable with different interceptors + - non-binding members in an interceptor binding type
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/build.properties b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/build.properties new file mode 100644 index 0000000..669edc0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-binding-types-with-members"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/build.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/client/test/client/WebTest.java new file mode 100644 index 0000000..ed0bec0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/client/test/client/WebTest.java
@@ -0,0 +1,107 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "interceptors-business-method-interceptors"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/descriptor/beans.xml new file mode 100644 index 0000000..bc97106 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/descriptor/beans.xml
@@ -0,0 +1,29 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.TransactionInterceptor</class> + <class>test.beans.RequiresNewTransactionInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..fa8fdb7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/RequiresNewTransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/RequiresNewTransactionInterceptor.java new file mode 100644 index 0000000..73f5964 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/RequiresNewTransactionInterceptor.java
@@ -0,0 +1,50 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Interceptor +@Transactional(requiresNew=true, rolesAllowed={"admin", "manager"}) +//the rolesAllowed value must be ignored as it s a non-binding attribute +public class RequiresNewTransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("RequiresNewTransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/ShoppingCart.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/ShoppingCart.java new file mode 100644 index 0000000..60a8a40 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/ShoppingCart.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + + +@Transactional(requiresNew=true) +@Preferred +public class ShoppingCart { + + public void addItem(String s) { + System.out.println("ShoppingCart::addItem called"); + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4792d26 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/TestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class TestBean { + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/TestDependentBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/TestDependentBean.java new file mode 100644 index 0000000..230c493 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/TestDependentBean.java
@@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.io.Serializable; + +public class TestDependentBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/TransactionInterceptor.java new file mode 100644 index 0000000..f762992 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/TransactionInterceptor.java
@@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/Transactional.java new file mode 100644 index 0000000..b8937b9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/beans/Transactional.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.enterprise.util.Nonbinding; +import javax.interceptor.InterceptorBinding; + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + boolean requiresNew() default false; + @Nonbinding String[] rolesAllowed() default {}; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/servlet/BusinessMethodInterceptorTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/servlet/BusinessMethodInterceptorTestServlet.java new file mode 100644 index 0000000..7dfbb05 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-binding-type-with-members/servlet/test/servlet/BusinessMethodInterceptorTestServlet.java
@@ -0,0 +1,94 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.Preferred; +import test.beans.RequiresNewTransactionInterceptor; +import test.beans.ShoppingCart; +import test.beans.TestBean; +import test.beans.TransactionInterceptor; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class BusinessMethodInterceptorTestServlet extends HttpServlet { + @Inject + @Preferred + TestBean tb; + + @Inject + @Preferred + ShoppingCart sc; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (tb == null) + msg += "Injection of request scoped bean failed"; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + if (RequiresNewTransactionInterceptor.aroundInvokeCalled) + msg += "RequiresNew TransactionInterceptor called when " + + "it shouldn't have been called"; + + TransactionInterceptor.clear(); + //invoke shopping cart bean. This should result in an invocation on + //the RequiresNewTransactional + sc.addItem("Test Item"); + if (!RequiresNewTransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke in requires new " + + "transaction interceptor not called"; + if (RequiresNewTransactionInterceptor.aroundInvokeInvocationCount != 1) + msg += "Business method requires new interceptor invocation on " + + "method-level interceptor annotation count not expected. " + + "expected =1, actual=" + + RequiresNewTransactionInterceptor.aroundInvokeInvocationCount; + if (!RequiresNewTransactionInterceptor.errorMessage.trim().equals("")) + msg += RequiresNewTransactionInterceptor.errorMessage; + + //TransactionInterceptor should not have been called + if (TransactionInterceptor.aroundInvokeCalled) + msg += "TranscationInterceptor aroundInvoke called when a requiresnew" + + "transaction interceptor should have been called"; + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/README b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/README new file mode 100644 index 0000000..05388f4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/README
@@ -0,0 +1,5 @@ +Test +- Use of business method interceptors + - definition of interceptor binding, interceptor and enabling +interceptor in beans.xml. check interceptor AroundInvoke invocation count + - injection of beans into Interceptors
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/build.properties b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/build.properties new file mode 100644 index 0000000..7fee82e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-business-method-interceptors"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/build.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/client/test/client/WebTest.java new file mode 100644 index 0000000..ed0bec0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/client/test/client/WebTest.java
@@ -0,0 +1,107 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "interceptors-business-method-interceptors"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/descriptor/beans.xml new file mode 100644 index 0000000..f075638 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/descriptor/beans.xml
@@ -0,0 +1,28 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.TransactionInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..fa8fdb7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/beans/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4792d26 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/beans/TestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class TestBean { + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/beans/TestDependentBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/beans/TestDependentBean.java new file mode 100644 index 0000000..1c15313 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/beans/TestDependentBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public class TestDependentBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/beans/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/beans/TransactionInterceptor.java new file mode 100644 index 0000000..f762992 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/beans/TransactionInterceptor.java
@@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/beans/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/beans/Transactional.java new file mode 100644 index 0000000..eef70c9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/beans/Transactional.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/servlet/BusinessMethodInterceptorTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/servlet/BusinessMethodInterceptorTestServlet.java new file mode 100644 index 0000000..504d347 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-business-method-interception/servlet/test/servlet/BusinessMethodInterceptorTestServlet.java
@@ -0,0 +1,64 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.Preferred; +import test.beans.TestBean; +import test.beans.TransactionInterceptor; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class BusinessMethodInterceptorTestServlet extends HttpServlet { + @Inject + @Preferred + TestBean tb; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (tb == null) + msg += "Injection of request scoped bean failed"; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/README b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/README new file mode 100644 index 0000000..f430f60 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/README
@@ -0,0 +1,4 @@ +Test +- Use of business method interceptors + - invalid specification of interceptor class in beans.xml should result + in deployment failure of archive.
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/build.properties b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/build.properties new file mode 100644 index 0000000..baeb63b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-invalid-interceptor-in-beans-xml"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/build.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/client/test/client/WebTest.java new file mode 100644 index 0000000..351ad46 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/client/test/client/WebTest.java
@@ -0,0 +1,83 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "interceptors-invalid-interceptor-specified-in-beans-xml"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + // We expect the call to fail with a 404 as the archive should + // not have deployed + if (code != 404) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + stat.addStatus(TEST_NAME, stat.PASS); + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/descriptor/beans.xml new file mode 100644 index 0000000..efe55d8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/descriptor/beans.xml
@@ -0,0 +1,28 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.INVALIDInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..fa8fdb7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/beans/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4792d26 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/beans/TestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class TestBean { + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/beans/TestDependentBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/beans/TestDependentBean.java new file mode 100644 index 0000000..1c15313 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/beans/TestDependentBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public class TestDependentBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/beans/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/beans/TransactionInterceptor.java new file mode 100644 index 0000000..f762992 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/beans/TransactionInterceptor.java
@@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/beans/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/beans/Transactional.java new file mode 100644 index 0000000..42f2c58 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/beans/Transactional.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/servlet/InvalidInterceptorInBeansXMLTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/servlet/InvalidInterceptorInBeansXMLTestServlet.java new file mode 100644 index 0000000..ccce0fb --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-invalid-interceptor-specified-at-beans-xml/servlet/test/servlet/InvalidInterceptorInBeansXMLTestServlet.java
@@ -0,0 +1,64 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.Preferred; +import test.beans.TestBean; +import test.beans.TransactionInterceptor; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class InvalidInterceptorInBeansXMLTestServlet extends HttpServlet { + @Inject + @Preferred + TestBean tb; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (tb == null) + msg += "Injection of request scoped bean failed"; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/README b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/README new file mode 100644 index 0000000..6278c1e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/README
@@ -0,0 +1,5 @@ +Test +- Use of business method interceptors + - Multiple interceptor binding annotations in an interceptor + - Interceptors bound to a method through the placement of @Transactional @Secure + at various places (Class level, method level)
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/build.properties b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/build.properties new file mode 100644 index 0000000..a5b08a4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-multiple-interceptor-binding-annotations"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/build.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/client/test/client/WebTest.java new file mode 100644 index 0000000..77abe96 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/client/test/client/WebTest.java
@@ -0,0 +1,108 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = + "interceptors-multiple-interceptor-binding-annotations"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/descriptor/beans.xml new file mode 100644 index 0000000..7b9b221 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/descriptor/beans.xml
@@ -0,0 +1,28 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.TransactionalSecureInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..fa8fdb7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/SecondShoppingCart.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/SecondShoppingCart.java new file mode 100644 index 0000000..00ef3e2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/SecondShoppingCart.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +@Transactional +//Differs from the other shopping cart in placement of annotations +@Preferred +public class SecondShoppingCart { + @Secure + public void checkout(){ + System.out.println("SecondShoppingCart::checkout"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/Secure.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/Secure.java new file mode 100644 index 0000000..377cb2f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/Secure.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; +import javax.interceptor.InterceptorBinding; + +@Qualifier +@Target({ TYPE, METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Secure { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/ShoppingCart.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/ShoppingCart.java new file mode 100644 index 0000000..b99ce6c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/ShoppingCart.java
@@ -0,0 +1,25 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public class ShoppingCart { + + @Transactional @Secure public void checkout(){ + System.out.println("ShoppingCart::checkout"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4792d26 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/TestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class TestBean { + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/TestRequestScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/TestRequestScopedBean.java new file mode 100644 index 0000000..4317821 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/TestRequestScopedBean.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.util.ArrayList; +import java.util.List; + +import javax.enterprise.context.RequestScoped; + +@RequestScoped +public class TestRequestScopedBean { + public static List<String> interceptorInvocationOrder = new ArrayList<String>(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/ThirdShoppingCart.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/ThirdShoppingCart.java new file mode 100644 index 0000000..7cd15c7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/ThirdShoppingCart.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + + +@Transactional @Secure +//Differs from the other shopping cart in placement of annotations +@Preferred +public class ThirdShoppingCart { + public void checkout(){ + System.out.println("SecondShoppingCart::checkout"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/Transactional.java new file mode 100644 index 0000000..42f2c58 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/Transactional.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/TransactionalSecureInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/TransactionalSecureInterceptor.java new file mode 100644 index 0000000..d47052d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/beans/TransactionalSecureInterceptor.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Transactional @Secure @Interceptor +public class TransactionalSecureInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestRequestScopedBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + tb.interceptorInvocationOrder.add(this.getClass().getCanonicalName()); + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/servlet/MultipleInterceptorBindingAnnotationsTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/servlet/MultipleInterceptorBindingAnnotationsTestServlet.java new file mode 100644 index 0000000..7e2d824 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptor-binding-annotations/servlet/test/servlet/MultipleInterceptorBindingAnnotationsTestServlet.java
@@ -0,0 +1,108 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.Preferred; +import test.beans.SecondShoppingCart; +import test.beans.ShoppingCart; +import test.beans.TestBean; +import test.beans.TestRequestScopedBean; +import test.beans.ThirdShoppingCart; +import test.beans.TransactionalSecureInterceptor; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class MultipleInterceptorBindingAnnotationsTestServlet extends HttpServlet { + @Inject + @Preferred + TestBean tb; + + @Inject + ShoppingCart sc; + + @Inject + @Preferred + SecondShoppingCart sc2; + + @Inject + @Preferred + ThirdShoppingCart sc3; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (tb == null) + msg += "Injection of bean (that is being intercepted) failed"; + + tb.m1(); + if (TransactionalSecureInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke on " + + "TransactionSecureInterceptor called when it shouldn't have"; + tb.m2(); + if (TransactionalSecureInterceptor.aroundInvokeInvocationCount != 0) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =0, actual=" + + TransactionalSecureInterceptor.aroundInvokeInvocationCount; + if (!TransactionalSecureInterceptor.errorMessage.trim().equals("")) + msg += TransactionalSecureInterceptor.errorMessage; + + + //Now use the two shopping cart to test TransactionalSecureInterceptor + sc.checkout(); + if (!TransactionalSecureInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke on " + + "TransactionSecureInterceptor not called"; + if (TransactionalSecureInterceptor.aroundInvokeInvocationCount != 1) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =1, actual=" + + TransactionalSecureInterceptor.aroundInvokeInvocationCount; + if (!TransactionalSecureInterceptor.errorMessage.trim().equals("")) + msg += TransactionalSecureInterceptor.errorMessage; + + sc2.checkout(); + if (TransactionalSecureInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionalSecureInterceptor.aroundInvokeInvocationCount; + + sc3.checkout(); + if (TransactionalSecureInterceptor.aroundInvokeInvocationCount != 3) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =3, actual=" + + TransactionalSecureInterceptor.aroundInvokeInvocationCount; + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/README b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/README new file mode 100644 index 0000000..4ef22fe --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/README
@@ -0,0 +1,5 @@ +Test +- Use of business method interceptors + - Multiple interceptors implementations for a binding type + - Ordering of interceptors (via beans.xml) + - Disabling of interceptors (via beans.xml)
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/build.properties b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/build.properties new file mode 100644 index 0000000..647c53f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-multiple-interceptor-implementations"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/build.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/client/test/client/WebTest.java new file mode 100644 index 0000000..98bf8c6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/client/test/client/WebTest.java
@@ -0,0 +1,108 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = + "interceptors-multiple-interceptors-for-a-binding-type"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/descriptor/beans.xml new file mode 100644 index 0000000..999fa4a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/descriptor/beans.xml
@@ -0,0 +1,32 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.SecondTransactionInterceptor</class> <!-- first invoke second interceptor --> + <class>test.beans.TransactionInterceptor</class> + <!-- Third Transactional Interceptor is disabled + <class>test.beans.ThirdTransactionInterceptor</class> + --> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..fa8fdb7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/SecondTransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/SecondTransactionInterceptor.java new file mode 100644 index 0000000..d73fcae --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/SecondTransactionInterceptor.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Transactional +@Interceptor +public class SecondTransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + @Inject + TestRequestScopedBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("SecondTransactionInterceptor::AroundInvoke"); + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + tb.interceptorInvocationOrder.add(this.getClass().getCanonicalName()); + return ctx.proceed(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4792d26 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/TestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class TestBean { + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/TestRequestScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/TestRequestScopedBean.java new file mode 100644 index 0000000..4317821 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/TestRequestScopedBean.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.util.ArrayList; +import java.util.List; + +import javax.enterprise.context.RequestScoped; + +@RequestScoped +public class TestRequestScopedBean { + public static List<String> interceptorInvocationOrder = new ArrayList<String>(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/ThirdTransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/ThirdTransactionInterceptor.java new file mode 100644 index 0000000..8450653 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/ThirdTransactionInterceptor.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Transactional +@Interceptor +public class ThirdTransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + @Inject + TestRequestScopedBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("ThirdTransactionInterceptor::AroundInvoke"); + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + tb.interceptorInvocationOrder.add(this.getClass().getCanonicalName()); + return ctx.proceed(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/TransactionInterceptor.java new file mode 100644 index 0000000..a4fe338 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/TransactionInterceptor.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestRequestScopedBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + tb.interceptorInvocationOrder.add(this.getClass().getCanonicalName()); + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/Transactional.java new file mode 100644 index 0000000..42f2c58 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/beans/Transactional.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/servlet/MultipleInterceptorImplementationsTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/servlet/MultipleInterceptorImplementationsTestServlet.java new file mode 100644 index 0000000..bc328db --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-multiple-interceptors-for-a-binding-type/servlet/test/servlet/MultipleInterceptorImplementationsTestServlet.java
@@ -0,0 +1,93 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.Preferred; +import test.beans.SecondTransactionInterceptor; +import test.beans.TestBean; +import test.beans.TestRequestScopedBean; +import test.beans.ThirdTransactionInterceptor; +import test.beans.TransactionInterceptor; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class MultipleInterceptorImplementationsTestServlet extends HttpServlet { + @Inject + @Preferred + TestBean tb; + + @Inject + TestRequestScopedBean trsb; + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (tb == null) + msg += "Injection of bean (that is being intercepted) failed"; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + + if (!SecondTransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke in the second " + + "transaction interceptor not called"; + tb.m2(); //calling m2 again + if (SecondTransactionInterceptor.aroundInvokeInvocationCount != 3) + msg += "Business method second interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =3, actual=" + + SecondTransactionInterceptor.aroundInvokeInvocationCount; + + //test ordering of interceptors in the system + boolean expectedOrdering = + ((trsb.interceptorInvocationOrder.get(0). + equals(SecondTransactionInterceptor.class.getCanonicalName())) + && (trsb.interceptorInvocationOrder.get(1). + equals(TransactionInterceptor.class.getCanonicalName()))); + if (!expectedOrdering) + msg += "Interceptor invocation order does not match with the expected order"; + + //test disabling of interceptors via beans.xml + if (ThirdTransactionInterceptor.aroundInvokeCalled) + msg += "Disabled interceptor called"; + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/README b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/README new file mode 100644 index 0000000..9df38aa --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/README
@@ -0,0 +1,3 @@ +Test +- Use of business method interceptors + - Use of the old-style Interceptors on a CDI bean
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/build.properties b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/build.properties new file mode 100644 index 0000000..a646191 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-use-of-at-interceptors"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/build.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/client/test/client/WebTest.java new file mode 100644 index 0000000..cd812bd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/client/test/client/WebTest.java
@@ -0,0 +1,113 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = + "interceptors-use-of-"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/descriptor/beans.xml new file mode 100644 index 0000000..b0ae3bd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/descriptor/beans.xml
@@ -0,0 +1,29 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.TransactionInterceptor</class> + <class>test.beans.SecureInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..fa8fdb7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/Secure.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/Secure.java new file mode 100644 index 0000000..377cb2f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/Secure.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; +import javax.interceptor.InterceptorBinding; + +@Qualifier +@Target({ TYPE, METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Secure { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/SecureInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/SecureInterceptor.java new file mode 100644 index 0000000..7085281 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/SecureInterceptor.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Secure @Interceptor +public class SecureInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestRequestScopedBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + + System.out.println("SecureInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + tb.interceptorInvocationOrder.add(this.getClass().getCanonicalName()); + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..a8d9b77 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/TestBean.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; +import javax.interceptor.Interceptors; + + +@RequestScoped +@Preferred +@Interceptors({TransactionInterceptor.class, SecureInterceptor.class}) +public class TestBean { + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/TestRequestScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/TestRequestScopedBean.java new file mode 100644 index 0000000..4317821 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/TestRequestScopedBean.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.util.ArrayList; +import java.util.List; + +import javax.enterprise.context.RequestScoped; + +@RequestScoped +public class TestRequestScopedBean { + public static List<String> interceptorInvocationOrder = new ArrayList<String>(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/TransactionInterceptor.java new file mode 100644 index 0000000..5e47864 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/TransactionInterceptor.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Transactional @Interceptor +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestRequestScopedBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + tb.interceptorInvocationOrder.add(this.getClass().getCanonicalName()); + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/Transactional.java new file mode 100644 index 0000000..42f2c58 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/beans/Transactional.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/servlet/InterceptorsTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/servlet/InterceptorsTestServlet.java new file mode 100644 index 0000000..e11f7cc --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-at-interceptors/servlet/test/servlet/InterceptorsTestServlet.java
@@ -0,0 +1,65 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.Preferred; +import test.beans.SecureInterceptor; +import test.beans.TestBean; +import test.beans.TransactionInterceptor; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class InterceptorsTestServlet extends HttpServlet { + @Inject + @Preferred + TestBean tb; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg +="TransactionInterceptor aroundInvoke method not called"; + if (!SecureInterceptor.aroundInvokeCalled) + msg +="SecureInterceptor aroundInvoke method not called"; + if ((TransactionInterceptor.aroundInvokeInvocationCount != 1)) + msg +="TransactionInterceptor aroundInvoke invocation count is " + + "not expected 1 but" + + TransactionInterceptor.aroundInvokeInvocationCount; + tb.m2(); + if ((SecureInterceptor.aroundInvokeInvocationCount != 2)) + msg +="SecureInterceptor aroundInvoke invocation count is " + + "not expected 2 but" + + SecureInterceptor.aroundInvokeInvocationCount; + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/README b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/README new file mode 100644 index 0000000..fd987b9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/README
@@ -0,0 +1,5 @@ +Test +- Use of business method interceptors to EJBs that specify interceptors through +traditional @Interceptors +Related issue: GLASSFISH-14831 +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/build.properties b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/build.properties new file mode 100644 index 0000000..1ab3b40 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-use-of-interceptors-in-ejbs-through-at-interceptors"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/build.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/client/test/client/WebTest.java new file mode 100644 index 0000000..e7521b7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/client/test/client/WebTest.java
@@ -0,0 +1,113 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = + "interceptors-use-of-interceptors-in-ejbs-through-at-interceptors"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/descriptor/beans.xml new file mode 100644 index 0000000..ce56e12 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/descriptor/beans.xml
@@ -0,0 +1,28 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>org.glassfish.cditest.security.interceptor.SecurityInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/security/api/Secure.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/security/api/Secure.java new file mode 100644 index 0000000..a237123 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/security/api/Secure.java
@@ -0,0 +1,47 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.cditest.security.api; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + +/** + * EJBs annotated with Secure are intercepted by SecurityInterceptor, ensuring + * that the caller has the permissions to call an EJB method. May only be + * applied to EJBs. + * + * @author ifischer + * + * @see SecurityInterceptor + * + * @since 0.3 + */ +@Inherited +@Target({ TYPE, METHOD }) +@Retention(RUNTIME) +@InterceptorBinding +public @interface Secure +{ + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/security/interceptor/SecurityInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/security/interceptor/SecurityInterceptor.java new file mode 100644 index 0000000..8708abf --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/security/interceptor/SecurityInterceptor.java
@@ -0,0 +1,96 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.cditest.security.interceptor; + +import java.lang.reflect.Method; +import java.security.Principal; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.annotation.Resource; +import javax.ejb.EJBContext; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import java.io.Serializable; +import org.glassfish.cditest.security.api.Secure; + +/** + * Realizes security for EJBs. + * + * @author ifischer + * + */ +@Secure +@Interceptor +public class SecurityInterceptor implements Serializable +{ + private static final Logger LOG = Logger.getLogger(SecurityInterceptor.class.getName()); + + public static boolean aroundInvokeCalled = false; + + @Resource + private EJBContext ejbCtx; + + /** + * Perform lookup for permissions. + * Does the caller has the permission to call the method? + * TODO: implement lookup + * + * @param InvocationContext of intercepted method + * @return + * @throws Exception + */ + @AroundInvoke + protected Object invoke(final InvocationContext ctx) throws Exception + { + Principal p = ejbCtx.getCallerPrincipal(); + Method interfaceMethod = ctx.getMethod(); + + LOG.log(Level.INFO, "EJB Method called [Full]:\"{0}\" by Principal:{1}", new Object[]{getFullEJBClassName(interfaceMethod), p.toString()}); + LOG.log(Level.INFO, "EJB Method called [Methodonly]:{0} by Principal:{1}", new Object[]{interfaceMethod.getName(), p.toString()}); + + SecurityInterceptor.aroundInvokeCalled = true; + return ctx.proceed(); + } + + /** + * The EJBContext interface doesn't provide convenient methods to get the name of the EJB class, + * so the classname has to be extracted from the method. + * + * @param the method whose classname is needed + * @return classname (fully qualified) of given method, e.g. "com.profitbricks.user.api.UserService" + */ + private String getFullEJBClassName(Method method) { + // extract className from methodName + // methodName format example:"public void com.profitbricks.user.api.UserService.testMe()" + String methodName = method.toString(); + + int start = methodName.lastIndexOf(' ') + 1; + int end = methodName.lastIndexOf('.'); + + String className = methodName.substring(start, end); + + return className; + } + + public static void reset(){ + //reset invocation status + SecurityInterceptor.aroundInvokeCalled = false; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/api/UserService.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/api/UserService.java new file mode 100644 index 0000000..b727c50 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/api/UserService.java
@@ -0,0 +1,72 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * To change this template, choose Tools | Templates and open the template in + * the editor. + */ + +package org.glassfish.cditest.user.api; + +import javax.ejb.EJBException; +import org.glassfish.cditest.user.api.model.User; + +/** + * <p> + * Manage user-related data + * </p> + * + * <p> + * A service that implements this interface is responsible for managing + * user-related master-data + * </p> + * + * @author kane + * + * @see User + */ +public interface UserService +{ + + /** + * <p> + * Get a {@link User} by the user id + * </p> + * + * @param userid + * The userid to search for + * @return A {@link User} object or <code>null</code> if no user was found + */ + public User findById(long userId) throws EJBException; + + /** + * <p> + * Add a new user + * </p> + * + * <p> + * The implementation must ensure that the provided user object is persisted + * before returning the assigned persistent user ID. + * </p> + * + * @param user + * The user object to persist + * @return The newly created persistent ID of the user object + * + * @see User + */ + public Long addUser(User user) throws EJBException; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/api/model/Gender.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/api/model/Gender.java new file mode 100644 index 0000000..616ee49 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/api/model/Gender.java
@@ -0,0 +1,50 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.glassfish.cditest.user.api.model; + +/** + * <p>All available genders</p> + * + * @author kane + */ +public enum Gender { + + /** + * <p>Represents a woman</p> + */ + FEMALE, + + /** + * <p>Represents a man</p> + */ + MALE, + + /** + * <p>Represents a person that is biologically and/or socially suited for both sexes</p> + */ + UNISEX, + + /** + * <p>Represents a person that is biologically and/or socially suited for none of the sexes</p> + */ + ASEXUAL; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/api/model/User.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/api/model/User.java new file mode 100644 index 0000000..59450f1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/api/model/User.java
@@ -0,0 +1,82 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * To change this template, choose Tools | Templates and open the template in + * the editor. + */ + +package org.glassfish.cditest.user.api.model; + +/** + * A user login account within our system. + * + * @author kane + * + * @since 0.1 + */ +public interface User +{ + + public Long getId(); + + /** + * Get the value of firstName + * + * @return the value of firstName + */ + public String getFirstName(); + + /** + * <p> + * Get the gender for the user + * </p> + * + * <p> + * A gender is much better suited to our needs here as the pure biological + * sex is. + * </p> + * + * @return the value of gender + */ + public Gender getGender(); + + /** + * Get the value of lastName + * + * @return the value of lastName + */ + public String getLastName(); + + /** + * <p> + * Get the username used for login + * </p> + * + * @return the value of username + */ + public String getUsername(); + + /** + * <p> + * Get the email address of the user + * </p> + * + * @return the value of the email + */ + public String getEmailAddress(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/api/model/package-info.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/api/model/package-info.java new file mode 100644 index 0000000..2e32979 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/api/model/package-info.java
@@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/** + * The user service transfer object model interfaces + */ +package org.glassfish.cditest.user.api.model;
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/api/package-info.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/api/package-info.java new file mode 100644 index 0000000..3f1435c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/api/package-info.java
@@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/** + * The user service API interfaces + */ +package org.glassfish.cditest.user.api;
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/impl/UserServiceImpl.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/impl/UserServiceImpl.java new file mode 100644 index 0000000..8284c73 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/impl/UserServiceImpl.java
@@ -0,0 +1,94 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.cditest.user.impl; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.ejb.EJBException; +import javax.ejb.Local; +import javax.ejb.Stateless; + +import org.glassfish.cditest.security.api.Secure; +import org.glassfish.cditest.user.api.UserService; +import org.glassfish.cditest.user.api.model.Gender; +import org.glassfish.cditest.user.api.model.User; +import org.glassfish.cditest.user.model.UserImpl; +/** + * <p> + * Implementation of the UserService. + * </p> + * + * @author chaoslayer + */ +@Stateless +@Local +@javax.interceptor.Interceptors(org.glassfish.cditest.security.interceptor.SecurityInterceptor.class) +public class UserServiceImpl implements UserService { + private static final Logger LOG = Logger.getLogger(UserService.class.getName()); + + /** + * <p> + * Add a new user + * </p> + * + * <p> + * The implementation must ensure that the provided user object is persisted + * before returning the assigned persistent user ID. + * </p> + * + * @param user + * The user object to persist + * @return The newly created persistent ID of the user object + * + * @see UserImpl + */ + @Override + public Long addUser(final User user) throws EJBException + { + LOG.log(Level.INFO, "Storing user {0}", user); + + return new Long(123); + } + + /** + * <p> + * Get a {@link User} by the user id + * </p> + * + * @param userid + * The userid to search for + * @return A {@link User} object or <code>null</code> if no user was found + */ + @Override + public User findById(long userId) throws EJBException + { + UserImpl u = new UserImpl(); + + u.setId(userId); + u.setEmailAddress("test@test.org"); + u.setFirstName("John"); + u.setLastName("Doe"); + u.setGender(Gender.UNISEX); + u.setUsername("john-123"); + + LOG.log(Level.INFO, "Returning user {0}", u); + + return u; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/model/UserImpl.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/model/UserImpl.java new file mode 100644 index 0000000..07ae9b7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/org/glassfish/cditest/user/model/UserImpl.java
@@ -0,0 +1,193 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * To change this template, choose Tools | Templates and open the template in + * the editor. + */ + +package org.glassfish.cditest.user.model; + +import org.glassfish.cditest.user.api.model.Gender; +import org.glassfish.cditest.user.api.model.User; + +/** + * <p> + * Client-side implementation of {@link User}. + * </p> + * + * @author chaoslayer + */ +public class UserImpl implements User +{ + + private static final long serialVersionUID = 1L; + + private Long id; + private String lastName; + private String firstName; + private Gender gender; + private String username; + private String emailAddress; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + /** + * <p> + * Get the username used for login + * </p> + * + * @return the value of username + */ + public String getUsername() + { + return username; + } + + /** + * <p> + * Set the username + * </p> + * + * @param username + * new value of username + */ + public void setUsername(String username) + { + this.username = username; + } + + /** + * <p> + * Get the gender for the user + * </p> + * + * <p> + * A gender is much better suited to our needs here as the pure biological + * sex is. + * </p> + * + * @return the value of gender + */ + public Gender getGender() + { + return gender; + } + + /** + * <p> + * Set the gender for the user + * </p> + * + * <p> + * A gender is much better suited to our needs here as the pure biological + * sex is. + * </p> + * + * @param gender + * new value of gender + */ + public void setGender(Gender gender) + { + this.gender = gender; + } + + /** + * Get the value of firstName + * + * @return the value of firstName + */ + public String getFirstName() + { + return firstName; + } + + /** + * Set the value of firstName + * + * @param firstName + * new value of firstName + */ + public void setFirstName(String firstName) + { + this.firstName = firstName; + } + + /** + * Get the value of lastName + * + * @return the value of lastName + */ + public String getLastName() + { + return lastName; + } + + /** + * Set the value of lastName + * + * @param lastName + * new value of lastName + */ + public void setLastName(String lastName) + { + this.lastName = lastName; + } + + /** + * Get the value of emailAddress + * + * @return the value of emailAddress + */ + public String getEmailAddress() + { + return emailAddress; + } + + /** + * Set the value of emailAddress + * + * @param emailAddress + * new value of emailAddress + */ + public void setEmailAddress(String emailAddress) + { + this.emailAddress = emailAddress; + } + + /** + * String representation of the object data + * + * @return The object data as String + */ + @Override + public String toString() + { + return "UserImpl [id=" + id + + ", emailAddress=" + emailAddress + + ", firstName=" + firstName + + ", gender=" + gender + + ", lastName=" + lastName + + ", username=" + username + "]"; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/test/servlet/InterceptorsTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/test/servlet/InterceptorsTestServlet.java new file mode 100644 index 0000000..77edccf --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-at-interceptors/servlet/test/servlet/InterceptorsTestServlet.java
@@ -0,0 +1,53 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.ejb.EJB; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.glassfish.cditest.security.interceptor.SecurityInterceptor; +import org.glassfish.cditest.user.api.UserService; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class InterceptorsTestServlet extends HttpServlet { + @EJB UserService svc; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + svc.findById(0); + if (!SecurityInterceptor.aroundInvokeCalled) + msg += "SecurityInterceptor aroundInvoke method not called when using" + + "@Interceptors to specify CDI interceptors"; + + SecurityInterceptor.reset(); + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/README b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/README new file mode 100644 index 0000000..6efea55 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/README
@@ -0,0 +1,5 @@ +Test +- Use of business method interceptors to EJBs that specify interceptors through +CDI interceptor bindings. +Related issue: GLASSFISH-14831 +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/build.properties b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/build.properties new file mode 100644 index 0000000..82f0c3b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-use-of-interceptors-in-ejbs-through-interceptor-bindings"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/build.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/client/test/client/WebTest.java new file mode 100644 index 0000000..6fba929 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/client/test/client/WebTest.java
@@ -0,0 +1,113 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = + "interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for interceptors"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/descriptor/beans.xml new file mode 100644 index 0000000..ce56e12 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/descriptor/beans.xml
@@ -0,0 +1,28 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>org.glassfish.cditest.security.interceptor.SecurityInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/security/api/Secure.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/security/api/Secure.java new file mode 100644 index 0000000..a237123 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/security/api/Secure.java
@@ -0,0 +1,47 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.cditest.security.api; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + +/** + * EJBs annotated with Secure are intercepted by SecurityInterceptor, ensuring + * that the caller has the permissions to call an EJB method. May only be + * applied to EJBs. + * + * @author ifischer + * + * @see SecurityInterceptor + * + * @since 0.3 + */ +@Inherited +@Target({ TYPE, METHOD }) +@Retention(RUNTIME) +@InterceptorBinding +public @interface Secure +{ + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/security/interceptor/SecurityInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/security/interceptor/SecurityInterceptor.java new file mode 100644 index 0000000..8708abf --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/security/interceptor/SecurityInterceptor.java
@@ -0,0 +1,96 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.cditest.security.interceptor; + +import java.lang.reflect.Method; +import java.security.Principal; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.annotation.Resource; +import javax.ejb.EJBContext; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import java.io.Serializable; +import org.glassfish.cditest.security.api.Secure; + +/** + * Realizes security for EJBs. + * + * @author ifischer + * + */ +@Secure +@Interceptor +public class SecurityInterceptor implements Serializable +{ + private static final Logger LOG = Logger.getLogger(SecurityInterceptor.class.getName()); + + public static boolean aroundInvokeCalled = false; + + @Resource + private EJBContext ejbCtx; + + /** + * Perform lookup for permissions. + * Does the caller has the permission to call the method? + * TODO: implement lookup + * + * @param InvocationContext of intercepted method + * @return + * @throws Exception + */ + @AroundInvoke + protected Object invoke(final InvocationContext ctx) throws Exception + { + Principal p = ejbCtx.getCallerPrincipal(); + Method interfaceMethod = ctx.getMethod(); + + LOG.log(Level.INFO, "EJB Method called [Full]:\"{0}\" by Principal:{1}", new Object[]{getFullEJBClassName(interfaceMethod), p.toString()}); + LOG.log(Level.INFO, "EJB Method called [Methodonly]:{0} by Principal:{1}", new Object[]{interfaceMethod.getName(), p.toString()}); + + SecurityInterceptor.aroundInvokeCalled = true; + return ctx.proceed(); + } + + /** + * The EJBContext interface doesn't provide convenient methods to get the name of the EJB class, + * so the classname has to be extracted from the method. + * + * @param the method whose classname is needed + * @return classname (fully qualified) of given method, e.g. "com.profitbricks.user.api.UserService" + */ + private String getFullEJBClassName(Method method) { + // extract className from methodName + // methodName format example:"public void com.profitbricks.user.api.UserService.testMe()" + String methodName = method.toString(); + + int start = methodName.lastIndexOf(' ') + 1; + int end = methodName.lastIndexOf('.'); + + String className = methodName.substring(start, end); + + return className; + } + + public static void reset(){ + //reset invocation status + SecurityInterceptor.aroundInvokeCalled = false; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/api/UserService.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/api/UserService.java new file mode 100644 index 0000000..b727c50 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/api/UserService.java
@@ -0,0 +1,72 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * To change this template, choose Tools | Templates and open the template in + * the editor. + */ + +package org.glassfish.cditest.user.api; + +import javax.ejb.EJBException; +import org.glassfish.cditest.user.api.model.User; + +/** + * <p> + * Manage user-related data + * </p> + * + * <p> + * A service that implements this interface is responsible for managing + * user-related master-data + * </p> + * + * @author kane + * + * @see User + */ +public interface UserService +{ + + /** + * <p> + * Get a {@link User} by the user id + * </p> + * + * @param userid + * The userid to search for + * @return A {@link User} object or <code>null</code> if no user was found + */ + public User findById(long userId) throws EJBException; + + /** + * <p> + * Add a new user + * </p> + * + * <p> + * The implementation must ensure that the provided user object is persisted + * before returning the assigned persistent user ID. + * </p> + * + * @param user + * The user object to persist + * @return The newly created persistent ID of the user object + * + * @see User + */ + public Long addUser(User user) throws EJBException; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/api/model/Gender.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/api/model/Gender.java new file mode 100644 index 0000000..616ee49 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/api/model/Gender.java
@@ -0,0 +1,50 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.glassfish.cditest.user.api.model; + +/** + * <p>All available genders</p> + * + * @author kane + */ +public enum Gender { + + /** + * <p>Represents a woman</p> + */ + FEMALE, + + /** + * <p>Represents a man</p> + */ + MALE, + + /** + * <p>Represents a person that is biologically and/or socially suited for both sexes</p> + */ + UNISEX, + + /** + * <p>Represents a person that is biologically and/or socially suited for none of the sexes</p> + */ + ASEXUAL; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/api/model/User.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/api/model/User.java new file mode 100644 index 0000000..59450f1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/api/model/User.java
@@ -0,0 +1,82 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * To change this template, choose Tools | Templates and open the template in + * the editor. + */ + +package org.glassfish.cditest.user.api.model; + +/** + * A user login account within our system. + * + * @author kane + * + * @since 0.1 + */ +public interface User +{ + + public Long getId(); + + /** + * Get the value of firstName + * + * @return the value of firstName + */ + public String getFirstName(); + + /** + * <p> + * Get the gender for the user + * </p> + * + * <p> + * A gender is much better suited to our needs here as the pure biological + * sex is. + * </p> + * + * @return the value of gender + */ + public Gender getGender(); + + /** + * Get the value of lastName + * + * @return the value of lastName + */ + public String getLastName(); + + /** + * <p> + * Get the username used for login + * </p> + * + * @return the value of username + */ + public String getUsername(); + + /** + * <p> + * Get the email address of the user + * </p> + * + * @return the value of the email + */ + public String getEmailAddress(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/api/model/package-info.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/api/model/package-info.java new file mode 100644 index 0000000..2e32979 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/api/model/package-info.java
@@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/** + * The user service transfer object model interfaces + */ +package org.glassfish.cditest.user.api.model;
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/api/package-info.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/api/package-info.java new file mode 100644 index 0000000..3f1435c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/api/package-info.java
@@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/** + * The user service API interfaces + */ +package org.glassfish.cditest.user.api;
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/impl/UserServiceImpl.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/impl/UserServiceImpl.java new file mode 100644 index 0000000..d938b81 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/impl/UserServiceImpl.java
@@ -0,0 +1,94 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.cditest.user.impl; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.ejb.EJBException; +import javax.ejb.Local; +import javax.ejb.Stateless; + +import org.glassfish.cditest.security.api.Secure; +import org.glassfish.cditest.user.api.UserService; +import org.glassfish.cditest.user.api.model.Gender; +import org.glassfish.cditest.user.api.model.User; +import org.glassfish.cditest.user.model.UserImpl; +/** + * <p> + * Implementation of the UserService. + * </p> + * + * @author chaoslayer + */ +@Stateless +@Local +@Secure +public class UserServiceImpl implements UserService { + private static final Logger LOG = Logger.getLogger(UserService.class.getName()); + + /** + * <p> + * Add a new user + * </p> + * + * <p> + * The implementation must ensure that the provided user object is persisted + * before returning the assigned persistent user ID. + * </p> + * + * @param user + * The user object to persist + * @return The newly created persistent ID of the user object + * + * @see UserImpl + */ + @Override + public Long addUser(final User user) throws EJBException + { + LOG.log(Level.INFO, "Storing user {0}", user); + + return new Long(123); + } + + /** + * <p> + * Get a {@link User} by the user id + * </p> + * + * @param userid + * The userid to search for + * @return A {@link User} object or <code>null</code> if no user was found + */ + @Override + public User findById(long userId) throws EJBException + { + UserImpl u = new UserImpl(); + + u.setId(userId); + u.setEmailAddress("test@test.org"); + u.setFirstName("John"); + u.setLastName("Doe"); + u.setGender(Gender.UNISEX); + u.setUsername("john-123"); + + LOG.log(Level.INFO, "Returning user {0}", u); + + return u; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/model/UserImpl.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/model/UserImpl.java new file mode 100644 index 0000000..07ae9b7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/org/glassfish/cditest/user/model/UserImpl.java
@@ -0,0 +1,193 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/* + * To change this template, choose Tools | Templates and open the template in + * the editor. + */ + +package org.glassfish.cditest.user.model; + +import org.glassfish.cditest.user.api.model.Gender; +import org.glassfish.cditest.user.api.model.User; + +/** + * <p> + * Client-side implementation of {@link User}. + * </p> + * + * @author chaoslayer + */ +public class UserImpl implements User +{ + + private static final long serialVersionUID = 1L; + + private Long id; + private String lastName; + private String firstName; + private Gender gender; + private String username; + private String emailAddress; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + /** + * <p> + * Get the username used for login + * </p> + * + * @return the value of username + */ + public String getUsername() + { + return username; + } + + /** + * <p> + * Set the username + * </p> + * + * @param username + * new value of username + */ + public void setUsername(String username) + { + this.username = username; + } + + /** + * <p> + * Get the gender for the user + * </p> + * + * <p> + * A gender is much better suited to our needs here as the pure biological + * sex is. + * </p> + * + * @return the value of gender + */ + public Gender getGender() + { + return gender; + } + + /** + * <p> + * Set the gender for the user + * </p> + * + * <p> + * A gender is much better suited to our needs here as the pure biological + * sex is. + * </p> + * + * @param gender + * new value of gender + */ + public void setGender(Gender gender) + { + this.gender = gender; + } + + /** + * Get the value of firstName + * + * @return the value of firstName + */ + public String getFirstName() + { + return firstName; + } + + /** + * Set the value of firstName + * + * @param firstName + * new value of firstName + */ + public void setFirstName(String firstName) + { + this.firstName = firstName; + } + + /** + * Get the value of lastName + * + * @return the value of lastName + */ + public String getLastName() + { + return lastName; + } + + /** + * Set the value of lastName + * + * @param lastName + * new value of lastName + */ + public void setLastName(String lastName) + { + this.lastName = lastName; + } + + /** + * Get the value of emailAddress + * + * @return the value of emailAddress + */ + public String getEmailAddress() + { + return emailAddress; + } + + /** + * Set the value of emailAddress + * + * @param emailAddress + * new value of emailAddress + */ + public void setEmailAddress(String emailAddress) + { + this.emailAddress = emailAddress; + } + + /** + * String representation of the object data + * + * @return The object data as String + */ + @Override + public String toString() + { + return "UserImpl [id=" + id + + ", emailAddress=" + emailAddress + + ", firstName=" + firstName + + ", gender=" + gender + + ", lastName=" + lastName + + ", username=" + username + "]"; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/test/servlet/InterceptorsTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/test/servlet/InterceptorsTestServlet.java new file mode 100644 index 0000000..77edccf --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/interceptors/interceptors-use-of-interceptors-in-ejbs-through-interceptor-bindings/servlet/test/servlet/InterceptorsTestServlet.java
@@ -0,0 +1,53 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.ejb.EJB; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.glassfish.cditest.security.interceptor.SecurityInterceptor; +import org.glassfish.cditest.user.api.UserService; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class InterceptorsTestServlet extends HttpServlet { + @EJB UserService svc; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + svc.findById(0); + if (!SecurityInterceptor.aroundInvokeCalled) + msg += "SecurityInterceptor aroundInvoke method not called when using" + + "@Interceptors to specify CDI interceptors"; + + SecurityInterceptor.reset(); + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/build.xml new file mode 100644 index 0000000..9b021d2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/build.xml
@@ -0,0 +1,109 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<project name="javaee-comp-test" default="usage" basedir="."> + + <property name="javaee-comp-target" value="all"/> + + <target name="run-test"> + <antcall target="javaee-comp"> + <param name="javaee-comp-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="javaee-comp"> + <param name="javaee-comp-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="javaee-comp"> + <param name="javaee-comp-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="javaee-comp"> + <param name="javaee-comp-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="javaee-comp"> + <param name="javaee-comp-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="javaee-comp"> + <param name="javaee-comp-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="javaee-comp"> + <param name="javaee-comp-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="javaee-comp"> + <param name="javaee-comp-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="javaee-comp"> + <param name="javaee-comp-target" value="run"/> + </antcall> + </target> + + <target name="javaee-comp"> + <record name="javaee-comp.output" action="start" /> + <ant dir="javaee-component-resource-typesafe-injection" target="${javaee-comp-target}"/> + <ant dir="jpa-resource-injection" target="${javaee-comp-target}"/> + <ant dir="jpa-resource-injection-non-serializable" target="${javaee-comp-target}"/> + <ant dir="jpa-resource-injection-passivating-scope" target="${javaee-comp-target}"/> + <ant dir="jpa-resource-injection-with-singleton-ejb-producer" target="${javaee-comp-target}"/> + <ant dir="no-interface-ejb" target="${javaee-comp-target}"/> + <ant dir="jms-resource-producer-field" target="${javaee-comp-target}"/> +<!-- TODO: Investigate + <ant dir="jms-resource-producer-field-in-library-jar" target="${javaee-comp-target}"/> +--> + <ant dir="em-resource-injection" target="${javaee-comp-target}"/> + <ant dir="em-injection-no-interface-ejb" target="${javaee-comp-target}"/> + <ant dir="em-resource-injection-with-resource-declaration-in-another-jar" target="${javaee-comp-target}"/> + <ant dir="slsb-injection-into-sessionscoped" target="${javaee-comp-target}"/> + <record name="javaee-comp.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant all (Executes all the javaee-comp tests) + ant clean (cleans all the javaee-comp tests) + ant build (builds all the javaee-comp tests) + ant setup (sets up all resources for javaee-comp tests) + ant deploy (deploys all the javaee-comp apps) + ant run (Executes all the javaee-comp tests) + ant undeploy (undeploys all the javaee-comp apps) + ant unsetup (unsets all resources for javaee-comp tests) + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/README new file mode 100644 index 0000000..098e4ae --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/README
@@ -0,0 +1,5 @@ +Test +- Injection of a no-interface bean in a request-scoped model via @Inject +and @EJB and invocation of methods defined in the EJB class and +in a super-class of the EJB +- glassfish issue 13040
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/build.properties new file mode 100644 index 0000000..2696b45 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/build.properties
@@ -0,0 +1,26 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-eminjection-into-no-interface-ejb"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="persistence.xml" value="descriptor/persistence.xml"/> +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/build.xml new file mode 100644 index 0000000..a0e6a9d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy" /> + + <target name="clean" depends="init-common"> + <antcall target="clean-common" /> + <delete> + <fileset dir="." includes="*.class" /> + <fileset dir="client/test/client" includes="*.class" /> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet" /> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes" /> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes" /> + <param name="webclient.war.classes" value="**/*.class" /> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" includes="test/client/WebTest.java" /> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common" /> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}" /> + <arg value="${http.port}" /> + <arg value="${contextroot}" /> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar" /> + <pathelement location="client" /> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common" /> + </target> + + <target name="usage"> + <antcall target="usage-common" /> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/client/test/client/WebTest.java new file mode 100644 index 0000000..24e3ebb --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/client/test/client/WebTest.java
@@ -0,0 +1,111 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "em-injection-of-no-interface-EJB"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for Java EE resource injection"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/descriptor/persistence.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/descriptor/persistence.xml new file mode 100644 index 0000000..82f2d7b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/descriptor/persistence.xml
@@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> + <persistence-unit name="pu1" transaction-type="JTA"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <jta-data-source>jdbc/__default</jta-data-source> + <non-jta-data-source>jdbc/__default</non-jta-data-source> + <class>myapp.Department</class> + <class>myapp.Employee</class> + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> + <property name="eclipselink.logging.level" value="INFO"/> + </properties> + </persistence-unit> +</persistence>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..8615fd5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public boolean m1(); + public boolean m2(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/artifacts/InjectViaAtEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/artifacts/InjectViaAtEJB.java new file mode 100644 index 0000000..594448d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/artifacts/InjectViaAtEJB.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface InjectViaAtEJB { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/artifacts/InjectViaAtInject.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/artifacts/InjectViaAtInject.java new file mode 100644 index 0000000..8e11c88 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/artifacts/InjectViaAtInject.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface InjectViaAtInject { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/nonmock/TestBeanSuper.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/nonmock/TestBeanSuper.java new file mode 100644 index 0000000..3480165 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/nonmock/TestBeanSuper.java
@@ -0,0 +1,42 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import javax.inject.Inject; + +import test.beans.TestBeanInterface; +import test.ejb.TestNoInterfaceEJB; + +abstract class TestBeanSuper implements TestBeanInterface { + + abstract TestNoInterfaceEJB getTestEJB(); + + @Override + public boolean m1() { + System.out.println("TestBean::m1 called"); + return getTestEJB().m1().equals("Hello:m1"); + } + + @Override + public boolean m2() { + System.out.println("TestBean::m2 called"); + System.out.println("Calling TestNoInterfaceEJB from TestBean"); + return getTestEJB().m2().equals("Hello:m2"); + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/nonmock/TestEJBInjectionViaAtEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/nonmock/TestEJBInjectionViaAtEJB.java new file mode 100644 index 0000000..9948f7c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/nonmock/TestEJBInjectionViaAtEJB.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import javax.ejb.EJB; +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +import test.beans.artifacts.InjectViaAtEJB; +import test.ejb.TestNoInterfaceEJB; + + +@RequestScoped +@InjectViaAtEJB +@Named +public class TestEJBInjectionViaAtEJB extends TestBeanSuper{ + @EJB TestNoInterfaceEJB tnie; + + @Override + TestNoInterfaceEJB getTestEJB() { + return tnie; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/nonmock/TestEJBInjectionViaInject.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/nonmock/TestEJBInjectionViaInject.java new file mode 100644 index 0000000..83f9383 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/beans/nonmock/TestEJBInjectionViaInject.java
@@ -0,0 +1,39 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.inject.Named; + +import test.beans.artifacts.InjectViaAtInject; +import test.ejb.TestNoInterfaceEJB; + + +@RequestScoped +@InjectViaAtInject +@Named +public class TestEJBInjectionViaInject extends TestBeanSuper { + @Inject TestNoInterfaceEJB tnie; + + @Override + TestNoInterfaceEJB getTestEJB() { + return tnie; + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/ejb/TestNoInterfaceEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/ejb/TestNoInterfaceEJB.java new file mode 100644 index 0000000..64e874e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/ejb/TestNoInterfaceEJB.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb; + +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.inject.Inject; + +@Stateless +public class TestNoInterfaceEJB extends TestSuperClass { + @Inject + EntityManager em; + + public String m2() { + System.out.println("TestNoInterfaceEJB::m2"); + if (em == null ) return "EntityManager injection failed"; + return "Hello:m2"; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/ejb/TestSuperClass.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/ejb/TestSuperClass.java new file mode 100644 index 0000000..65af297 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/ejb/TestSuperClass.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb; + +public class TestSuperClass { + public String m1(){ + System.out.println("***************TestSuperClass::m1"); + return "Hello:m1"; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/entity/Department.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/entity/Department.java new file mode 100644 index 0000000..14191ec --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/entity/Department.java
@@ -0,0 +1,82 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "DEPARTMENT") +public class Department implements java.io.Serializable { + + // Instance variables + private int id; + private String name; + private Set<Employee> employees; + + public Department() { + } + + public Department(int id, String name) { + this.id = id; + this.name = name; + } + + // =========================================================== + // getters and setters for the state fields + + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "NAME") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + // =========================================================== + // getters and setters for the association fields + @OneToMany(cascade = CascadeType.ALL, mappedBy = "department") + public Set<Employee> getEmployees() { + return employees; + } + + public void setEmployees(Set<Employee> employees) { + this.employees = employees; + } + + public String toString() { + return "Department id=" + getId() + ", Department Name=" + getName(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/entity/Employee.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/entity/Employee.java new file mode 100644 index 0000000..a1820e8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/entity/Employee.java
@@ -0,0 +1,117 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Transient; + +@Entity +@Table(name = "EMPLOYEE") +public class Employee implements java.io.Serializable { + + private int id; + private String firstName; + private String lastName; + private Department department; + + public Employee() { + } + + public Employee(int id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public Employee(int id, String firstName, String lastName, + Department department) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + this.department = department; + } + + // =========================================================== + // getters and setters for the state fields + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "FIRSTNAME") + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + @Column(name = "LASTNAME") + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + // =========================================================== + // getters and setters for the association fields + // @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "DEPARTMENT_ID") + public Department getDepartment() { + return department; + } + + @Transient + public Department getDepartmentNoWeaving() { + try { + java.lang.reflect.Field f = Employee.class + .getDeclaredField("department"); + return (Department) f.get(this); + } catch (NoSuchFieldException e) { + throw new RuntimeException( + "Please change argument to getDeclaredField", e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public void setDepartment(Department department) { + this.department = department; + } + + public String toString() { + return "Employee id=" + getId() + ", firstName=" + getFirstName() + + ", lastName=" + getLastName() + ", department=" + + getDepartment(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/servlet/NoInterfaceEJBTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/servlet/NoInterfaceEJBTestServlet.java new file mode 100644 index 0000000..246b541 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/servlet/NoInterfaceEJBTestServlet.java
@@ -0,0 +1,91 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.transaction.UserTransaction; +import test.beans.TestBeanInterface; +import test.beans.artifacts.InjectViaAtEJB; +import test.beans.artifacts.InjectViaAtInject; +import test.util.JpaTest; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class NoInterfaceEJBTestServlet extends HttpServlet { + + @Inject + @InjectViaAtInject + TestBeanInterface testBeanInject; + + @Inject + @InjectViaAtEJB + TestBeanInterface testBeanEJB; + + @Inject + private EntityManager em; + + private @Resource + UserTransaction utx; + + + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, + IOException { + PrintWriter writer = response.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + //test EJB injection via @EJB + if (!testBeanEJB.m2()) + msg += "Invocation on no-interface EJB -- obtained through @EJB -- (method defined in EJB) failed"; + if (!testBeanEJB.m1()) + msg += "Invocation on no-interface EJB -- obtained through @EJB -- (method defined in super class) failed"; + + //test EJB injection via @Inject + if (!testBeanInject.m2()) + msg += "Invocation on no-interface EJB -- obtained through @Inject -- (method defined in EJB) failed"; + + //TODO: This fails currently + if (!testBeanInject.m1()) + msg += "Invocation on no-interface EJB -- obtained through @Inject -- (method defined in super class) failed"; + + JpaTest jt = new JpaTest(em, utx); + boolean status = jt.lazyLoadingInit(); + if (!status) msg += "Injection and use of EntityMaanger failed"; + status = jt.lazyLoadingByFind(1); + if (!status) msg += "Injection and use of EntityMaanger lazy loading test failed"; + + writer.write(msg + "\n"); + + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/util/JPAResourceProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/util/JPAResourceProducer.java new file mode 100644 index 0000000..b029006 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/util/JPAResourceProducer.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.enterprise.inject.Produces; +import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + + +@Singleton +public class JPAResourceProducer { + @Produces @PersistenceContext(unitName="pu1") + EntityManager customerDatabasePersistenceUnit; + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/util/JpaTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/util/JpaTest.java new file mode 100644 index 0000000..3d47448 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-injection-no-interface-ejb/servlet/test/util/JpaTest.java
@@ -0,0 +1,170 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Query; +import javax.transaction.UserTransaction; + +import test.entity.Department; +import test.entity.Employee; + +public class JpaTest { + + private EntityManager em; + private UserTransaction utx; + + private static Department deptRef[] = new Department[2]; + private static Employee empRef[] = new Employee[5]; + + public JpaTest() { + } + + public JpaTest(EntityManager em, UserTransaction utx) { + this.em = em; + this.utx = utx; + } + + public boolean lazyLoadingInit() { + boolean status = false; + System.out.println("-----lazeLoadingInit()---------"); + try { + deptRef[0] = new Department(1, "Engineering"); + deptRef[1] = new Department(2, "Marketing"); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 2; i++) { + em.persist(deptRef[i]); + } + utx.commit(); + + empRef[0] = new Employee(1, "Alan", "Frechette", deptRef[0]); + empRef[1] = new Employee(2, "Arthur", "Wesley", deptRef[0]); + empRef[2] = new Employee(3, "Abe", "White", deptRef[0]); + empRef[3] = new Employee(4, "Paul", "Hinz", deptRef[1]); + empRef[4] = new Employee(5, "Carla", "Calrson", deptRef[1]); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 5; i++) { + em.persist(empRef[i]); + } + utx.commit(); + status = true; + } catch (Exception ex) { + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByFind(int employeeID) { + + boolean status = true; + System.out.println("------------lazyLoadingAfterFind -----------"); + System.out.println("employeeID = " + employeeID); + Employee emp = em.find(Employee.class, employeeID); + + System.out.println("found: emp.id=" + emp.getId()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByQuery(String fName) { + + boolean status = true; + System.out.println("------------lazyLoadingByQuery -----------"); + System.out.println("fName = " + fName); + Query query = em.createQuery( + "SELECT e FROM Employee e WHERE e.firstName like :firstName") + .setParameter("firstName", fName); + ; + Employee emp = (Employee) query.getSingleResult(); + + System.out.println("queried: emp.firstName=" + emp.getFirstName()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/README new file mode 100644 index 0000000..91f9387 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/README
@@ -0,0 +1,2 @@ +Test +- EM producer method scenario with extended transaction context (issue 11805)
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/build.properties new file mode 100644 index 0000000..b2a8756 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/build.properties
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-em-resource-injection-extended-transactional-context"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="persistence.xml" value="descriptor/persistence.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/build.xml new file mode 100644 index 0000000..295d086 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/build.xml
@@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,create-resources,deploy,run,undeploy,delete-resources" /> + + <target name="clean" depends="init-common"> + <antcall target="clean-common" /> + <delete> + <fileset dir="." includes="*.class" /> + <fileset dir="client/test/client" includes="*.class" /> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet" /> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes" /> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes" /> + <param name="webclient.war.classes" value="**/*.class" /> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" includes="test/client/WebTest.java" /> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common" /> + </target> + + <target name="create-resources" depends="init-common"> + <antcall target="create-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + <antcall target="create-jdbc-resource-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + </target> + + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}" /> + <arg value="${http.port}" /> + <arg value="${contextroot}" /> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar" /> + <pathelement location="client" /> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common" /> + </target> + + <target name="delete-resources" depends="init-common"> + <antcall target="delete-jdbc-resource-common"> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + + <antcall target="delete-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + </target> + + <target name="usage"> + <antcall target="usage-common" /> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/client/test/client/WebTest.java new file mode 100644 index 0000000..7dc1c83 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/client/test/client/WebTest.java
@@ -0,0 +1,115 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "em-resource-injection-extended-transaction-context"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for Java EE resource injection"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke("llinit"); + invoke("llquery"); + invoke("llfind"); + invoke("llinj"); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke(String testCase) throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl" + + "?testcase=" + testCase; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME + testCase, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME + testCase, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME + testCase, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/descriptor/persistence.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/descriptor/persistence.xml new file mode 100644 index 0000000..82f2d7b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/descriptor/persistence.xml
@@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> + <persistence-unit name="pu1" transaction-type="JTA"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <jta-data-source>jdbc/__default</jta-data-source> + <non-jta-data-source>jdbc/__default</non-jta-data-source> + <class>myapp.Department</class> + <class>myapp.Employee</class> + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> + <property name="eclipselink.logging.level" value="INFO"/> + </properties> + </persistence-unit> +</persistence>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..29e137a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void m1(); + public void m2(); + + public String testDatasourceInjection(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/beans/artifacts/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/beans/artifacts/Preferred.java new file mode 100644 index 0000000..b7584c8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/beans/artifacts/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/beans/artifacts/TestDatabase.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/beans/artifacts/TestDatabase.java new file mode 100644 index 0000000..b69ab8e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/beans/artifacts/TestDatabase.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestDatabase { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/beans/nonmock/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/beans/nonmock/TestBean.java new file mode 100644 index 0000000..2363d68 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/beans/nonmock/TestBean.java
@@ -0,0 +1,53 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.TestDatabase; + + +@RequestScoped +@Preferred +public class TestBean implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Inject //@TestDatabase + EntityManager emf; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + + @Override + public String testDatasourceInjection() { + return (emf==null ? "typesafe injection into testbean failed" : ""); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/entity/Department.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/entity/Department.java new file mode 100644 index 0000000..14191ec --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/entity/Department.java
@@ -0,0 +1,82 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "DEPARTMENT") +public class Department implements java.io.Serializable { + + // Instance variables + private int id; + private String name; + private Set<Employee> employees; + + public Department() { + } + + public Department(int id, String name) { + this.id = id; + this.name = name; + } + + // =========================================================== + // getters and setters for the state fields + + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "NAME") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + // =========================================================== + // getters and setters for the association fields + @OneToMany(cascade = CascadeType.ALL, mappedBy = "department") + public Set<Employee> getEmployees() { + return employees; + } + + public void setEmployees(Set<Employee> employees) { + this.employees = employees; + } + + public String toString() { + return "Department id=" + getId() + ", Department Name=" + getName(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/entity/Employee.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/entity/Employee.java new file mode 100644 index 0000000..a1820e8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/entity/Employee.java
@@ -0,0 +1,117 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Transient; + +@Entity +@Table(name = "EMPLOYEE") +public class Employee implements java.io.Serializable { + + private int id; + private String firstName; + private String lastName; + private Department department; + + public Employee() { + } + + public Employee(int id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public Employee(int id, String firstName, String lastName, + Department department) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + this.department = department; + } + + // =========================================================== + // getters and setters for the state fields + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "FIRSTNAME") + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + @Column(name = "LASTNAME") + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + // =========================================================== + // getters and setters for the association fields + // @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "DEPARTMENT_ID") + public Department getDepartment() { + return department; + } + + @Transient + public Department getDepartmentNoWeaving() { + try { + java.lang.reflect.Field f = Employee.class + .getDeclaredField("department"); + return (Department) f.get(this); + } catch (NoSuchFieldException e) { + throw new RuntimeException( + "Please change argument to getDeclaredField", e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public void setDepartment(Department department) { + this.department = department; + } + + public String toString() { + return "Employee id=" + getId() + ", firstName=" + getFirstName() + + ", lastName=" + getLastName() + ", department=" + + getDepartment(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/servlet/JPAResourceInjectionServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/servlet/JPAResourceInjectionServlet.java new file mode 100644 index 0000000..4472160 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/servlet/JPAResourceInjectionServlet.java
@@ -0,0 +1,94 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.transaction.UserTransaction; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.TestDatabase; +import test.util.JpaTest; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class JPAResourceInjectionServlet extends HttpServlet { + + @PersistenceUnit(unitName = "pu1") + private EntityManagerFactory emf; + + @Inject + //@TestDatabase + private EntityManager emf1; + + private @Resource + UserTransaction utx; + + @Inject + @Preferred + TestBeanInterface tbi; + + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, + IOException { + PrintWriter writer = response.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + System.out.println("JPAResourceInjectionServlet::@PersistenceUnit " + + "CDI EntityManagerFactory=" + emf1); + + EntityManager em = emf1; + System.out.println("JPAResourceInjectionServlet::createEM" + + "EntityManager=" + em); + String testcase = request.getParameter("testcase"); + System.out.println("testcase=" + testcase); + + if (testcase != null) { + JpaTest jt = new JpaTest(em, utx); + boolean status = false; + if ("llinit".equals(testcase)) { + status = jt.lazyLoadingInit(); + } else if ("llfind".equals(testcase)) { + status = jt.lazyLoadingByFind(1); + } else if ("llquery".equals(testcase)) { + status = jt.lazyLoadingByQuery("Carla"); + } else if ("llinj".equals(testcase)){ + status = ((tbi != null) && + (tbi.testDatasourceInjection().trim().length()==0)); + } + if (status) { + msg += "";// pass + } else { + msg += (testcase + ":fail"); + } + } + + writer.write(msg + "\n"); + + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/util/JPAResourceProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/util/JPAResourceProducer.java new file mode 100644 index 0000000..1d6fd04 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/util/JPAResourceProducer.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.enterprise.inject.Produces; +import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.PersistenceContextType; + +@Singleton +public class JPAResourceProducer { + @Produces @PersistenceContext(unitName="pu1", type=PersistenceContextType.EXTENDED) + //@TestDatabase + EntityManager customerDatabasePersistenceUnit; + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/util/JpaTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/util/JpaTest.java new file mode 100644 index 0000000..3d47448 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-extended-transaction-context/servlet/test/util/JpaTest.java
@@ -0,0 +1,170 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Query; +import javax.transaction.UserTransaction; + +import test.entity.Department; +import test.entity.Employee; + +public class JpaTest { + + private EntityManager em; + private UserTransaction utx; + + private static Department deptRef[] = new Department[2]; + private static Employee empRef[] = new Employee[5]; + + public JpaTest() { + } + + public JpaTest(EntityManager em, UserTransaction utx) { + this.em = em; + this.utx = utx; + } + + public boolean lazyLoadingInit() { + boolean status = false; + System.out.println("-----lazeLoadingInit()---------"); + try { + deptRef[0] = new Department(1, "Engineering"); + deptRef[1] = new Department(2, "Marketing"); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 2; i++) { + em.persist(deptRef[i]); + } + utx.commit(); + + empRef[0] = new Employee(1, "Alan", "Frechette", deptRef[0]); + empRef[1] = new Employee(2, "Arthur", "Wesley", deptRef[0]); + empRef[2] = new Employee(3, "Abe", "White", deptRef[0]); + empRef[3] = new Employee(4, "Paul", "Hinz", deptRef[1]); + empRef[4] = new Employee(5, "Carla", "Calrson", deptRef[1]); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 5; i++) { + em.persist(empRef[i]); + } + utx.commit(); + status = true; + } catch (Exception ex) { + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByFind(int employeeID) { + + boolean status = true; + System.out.println("------------lazyLoadingAfterFind -----------"); + System.out.println("employeeID = " + employeeID); + Employee emp = em.find(Employee.class, employeeID); + + System.out.println("found: emp.id=" + emp.getId()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByQuery(String fName) { + + boolean status = true; + System.out.println("------------lazyLoadingByQuery -----------"); + System.out.println("fName = " + fName); + Query query = em.createQuery( + "SELECT e FROM Employee e WHERE e.firstName like :firstName") + .setParameter("firstName", fName); + ; + Employee emp = (Employee) query.getSingleResult(); + + System.out.println("queried: emp.firstName=" + emp.getFirstName()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/README new file mode 100644 index 0000000..dc88f85 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/README
@@ -0,0 +1,2 @@ +A test to check if resources produced by a class in a library jar is available in servlets and EJBs. +[issues 11653 and 11640]
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/build.properties new file mode 100644 index 0000000..1bc0c2e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/build.properties
@@ -0,0 +1,29 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi-full-ear"/> +<property name="appname" value="${module}"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="se.client" value="com.acme.Client"/> +<property name="app.type" value="application"/> +<property name="sun-application.xml" value="descriptor/sun-application.xml"/> +<property name="application.xml" value="descriptor/application.xml"/> +<property name="persistence.xml" value="descriptor/persistence.xml"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="contextroot" value="${module}"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/build.xml new file mode 100644 index 0000000..8539621 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/build.xml
@@ -0,0 +1,139 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="cdi-full-ear-App" default="usage" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + + <target name="all" depends="clean,build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="lib"/> + </antcall> + + + <antcall target="compile-common"> + <param name="src" value="ejb"/> + </antcall> + + <antcall target="compile-common"> + <param name="src" value="war"/> + </antcall> + + <javac classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/lib/gf-client.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar" srcdir="client" destdir="${build.classes.dir}" debug="on" failonerror="true"> + <compilerarg line="-endorseddirs ${env.S1AS_HOME}/modules/endorsed"/> + </javac> + </target> + + <target name="build" depends="compile"> + <mkdir dir="${assemble.dir}"/> + + <antcall target="ejb-jar-common"> + <param name="ejbjar.classes" value="com/acme/ejb/**/*.class"/> + </antcall> + + <!-- build library jar --> + <mkdir dir="${build.classes.dir}/META-INF"/> + <copy file="${persistence.xml}" + tofile="${build.classes.dir}/META-INF/persistence.xml" + failonerror="false"/> + <copy file="${beans.xml}" + tofile="${build.classes.dir}/META-INF/beans.xml" + failonerror="false"/> + + <mkdir dir="${build.classes.dir}/lib-dir"/> + + <jar jarfile="${build.classes.dir}/lib-dir/lib.jar" basedir="${build.classes.dir}" includes="com/acme/util/*.class"> + <metainf dir="${build.classes.dir}/META-INF"> + <include name="persistence.xml"/> + <include name="beans.xml"/> + </metainf> + </jar> + + <!-- build war --> + <!-- must remove ejb classes and lib classes first --> + <delete file="${build.classes.dir}/META-INF/beans.xml"/> + <delete dir="${build.classes.dir}/com/acme/ejb"/> + <delete dir="${build.classes.dir}/com/acme/util"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="true"/> + </antcall> + + <copy file="${env.APS_HOME}/lib/reporter.jar" todir="${build.classes.dir}/lib-dir"/> + + <delete file="${assemble.dir}/${appname}.ear"/> + <mkdir dir="${assemble.dir}"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <copy file="${sun-application.xml}" tofile="${build.classes.dir}/META-INF/sun-application.xml" failonerror="false"/> + <copy file="${glassfish-resources-ear.xml}" tofile="${build.classes.dir}/META-INF/glassfish-resources.xml" failonerror="false" filtering="true"/> + <ear earfile="${assemble.dir}/${appname}App.ear" + appxml="${application.xml}" > + <fileset dir="${assemble.dir}"> + <include name="*.jar"/> + <include name="*.war"/> + </fileset> + <fileset dir="${build.classes.dir}"> + <include name="META-INF/sun-application.xml"/> + <include name="META-INF/glassfish-resources.xml"/> + </fileset> +<!-- + <fileset dir="${env.APS_HOME}" includes="lib/reporter.jar"/> +--> + <fileset dir="${build.classes.dir}" includes="lib-dir/*"/> + </ear> + + </target> + + <target name="deploy" + depends="init-common"> + <antcall target="deploy-common"/> + </target> + + <target name="run" depends="init-common"> + <java fork="on" + failonerror="true" + classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/lib/gf-client.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar" + classname="${se.client}"> + <arg line="${contextroot}"/> + <arg line="${http.host}"/> + <arg line="${http.port}"/> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/client/com/acme/Client.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/client/com/acme/Client.java new file mode 100644 index 0000000..c5ca393 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/client/com/acme/Client.java
@@ -0,0 +1,88 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import javax.annotation.Resource; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +public class Client { + + private static final String TEST_NAME = "em-resource-injection-with-resource-declaration-in-another-jar"; + + private static SimpleReporterAdapter stat = + new SimpleReporterAdapter("appserv-tests"); + + private static String appName; + private String host; + private String port; + + @Resource(lookup = "java:app/env/value1") + private static Integer appLevelViaLookup; + + public static void main(String args[]) { + appName = args[0]; + stat.addDescription(appName); + Client client = new Client(args); + client.doTest(); + stat.printSummary(appName + "ID"); + System.out.println("appLevelViaLookup = '" + appLevelViaLookup + "'"); + } + + public Client(String[] args) { + host = args[1]; + port = args[2]; + } + + public void doTest() { + try { + String url = "http://" + host + ":" + port + "/" + appName + + "/HelloServlet"; + System.out.println("invoking webclient servlet at " + url); + URL u = new URL(url); + HttpURLConnection c1 = (HttpURLConnection) u.openConnection(); + int code = c1.getResponseCode(); + InputStream is = c1.getInputStream(); + BufferedReader input = new BufferedReader(new InputStreamReader( + is)); + String line = null; + while ((line = input.readLine()) != null) { + System.out.println("<response>:" + line); + if (line.trim().length() > 0) { + stat.addStatus(TEST_NAME, stat.FAIL); + return; + } + } + if (code != 200) { + stat.addStatus(TEST_NAME, stat.FAIL); + return; + } + stat.addStatus(TEST_NAME, stat.PASS); + + } catch (Exception e) { + stat.addStatus(TEST_NAME, stat.FAIL); + e.printStackTrace(); + } + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/descriptor/application.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/descriptor/application.xml new file mode 100644 index 0000000..1188e6a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/descriptor/application.xml
@@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="6" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"> + <display-name>ejb-ejb30-hello-session3App</display-name> + <module> + <ejb>cdi-full-ear-ejb.jar</ejb> + </module> + <module> + <web> + <web-uri>cdi-full-ear-web.war</web-uri> + <context-root>cdi-full-ear</context-root> + </web> + </module> + <library-directory>lib-dir</library-directory> + <env-entry> + <env-entry-name>java:app/env/value1</env-entry-name> + <env-entry-type>java.lang.Integer</env-entry-type> + <env-entry-value>18338</env-entry-value> + </env-entry> + <env-entry> + <env-entry-name>java:app/env/myString</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + <env-entry-value>myString</env-entry-value> + </env-entry> +</application>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/descriptor/persistence.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/descriptor/persistence.xml new file mode 100644 index 0000000..82f2d7b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/descriptor/persistence.xml
@@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> + <persistence-unit name="pu1" transaction-type="JTA"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <jta-data-source>jdbc/__default</jta-data-source> + <non-jta-data-source>jdbc/__default</non-jta-data-source> + <class>myapp.Department</class> + <class>myapp.Employee</class> + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> + <property name="eclipselink.logging.level" value="INFO"/> + </properties> + </persistence-unit> +</persistence>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/ejb/com/acme/ejb/api/Hello.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/ejb/com/acme/ejb/api/Hello.java new file mode 100644 index 0000000..739e1ec --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/ejb/com/acme/ejb/api/Hello.java
@@ -0,0 +1,25 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.ejb.api; + +public interface Hello { + + public String hello(); + public static final String HELLO_TEST_STRING = "hello, world!\n"; + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/ejb/com/acme/ejb/api/HelloRemote.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/ejb/com/acme/ejb/api/HelloRemote.java new file mode 100644 index 0000000..0993e59 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/ejb/com/acme/ejb/api/HelloRemote.java
@@ -0,0 +1,27 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.ejb.api; + +import javax.ejb.Remote; + +@Remote +public interface HelloRemote { + + public String hello(); + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/ejb/com/acme/ejb/impl/HelloSingleton.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/ejb/com/acme/ejb/impl/HelloSingleton.java new file mode 100644 index 0000000..083e62f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/ejb/com/acme/ejb/impl/HelloSingleton.java
@@ -0,0 +1,73 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.ejb.impl; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.annotation.Resource; +import javax.ejb.DependsOn; +import javax.ejb.SessionContext; +import javax.ejb.Singleton; +import javax.ejb.Startup; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; + +import com.acme.ejb.api.Hello; +import com.acme.util.TestDatabase; + +@Singleton +@Startup +@DependsOn("Singleton4") +public class HelloSingleton implements Hello { + + @Resource + SessionContext sessionCtx; + + @PersistenceUnit(unitName = "pu1") + @TestDatabase + private EntityManagerFactory emf; + + + @PostConstruct + private void init() { + System.out.println("HelloSingleton::init()"); + + String appName; + String moduleName; + appName = (String) sessionCtx.lookup("java:app/AppName"); + moduleName = (String) sessionCtx.lookup("java:module/ModuleName"); + System.out.println("AppName = " + appName); + System.out.println("ModuleName = " + moduleName); + } + + public String hello() { + System.out.println("HelloSingleton::hello()"); + return testEMF(emf); + } + + private String testEMF(EntityManagerFactory emf2) { + if (emf == null) return "EMF injection failed, is null in Singleton EJB"; + if (emf.createEntityManager() == null) return "Usage of EMF failed in Singleton EJB"; + return Hello.HELLO_TEST_STRING; + } + + @PreDestroy + private void destroy() { + System.out.println("HelloSingleton::destroy()"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/ejb/com/acme/ejb/impl/Singleton4.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/ejb/com/acme/ejb/impl/Singleton4.java new file mode 100644 index 0000000..b3fd249 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/ejb/com/acme/ejb/impl/Singleton4.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.ejb.impl; + +import javax.ejb.*; +import javax.annotation.*; + + +@Singleton +public class Singleton4 { + + @PostConstruct + public void init() { + System.out.println("In SingletonBean4::init()"); + } + + @PreDestroy + public void destroy() { + System.out.println("In SingletonBean4::destroy()"); + } + + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/lib/com/acme/util/ResourcesProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/lib/com/acme/util/ResourcesProducer.java new file mode 100644 index 0000000..fdc079b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/lib/com/acme/util/ResourcesProducer.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.util; + +import javax.enterprise.inject.Produces; +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +@Singleton +public class ResourcesProducer { + @Produces + @PersistenceContext(unitName = "pu1") + @TestDatabase + EntityManager customerDatabasePersistenceUnit; + + @Inject + TestDependentBeanInLib foo; + + public boolean isInjectionSuccessful(){ + return (foo != null); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/lib/com/acme/util/TestDatabase.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/lib/com/acme/util/TestDatabase.java new file mode 100644 index 0000000..db9e318 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/lib/com/acme/util/TestDatabase.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.util; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target( { TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestDatabase { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/lib/com/acme/util/TestDependentBeanInLib.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/lib/com/acme/util/TestDependentBeanInLib.java new file mode 100644 index 0000000..9596b22 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/lib/com/acme/util/TestDependentBeanInLib.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.util; + + +public class TestDependentBeanInLib { + public TestDependentBeanInLib() { + super(); + } + + public String foo(){ + return "foo!"; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/lib/com/acme/util/TestManagedBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/lib/com/acme/util/TestManagedBean.java new file mode 100644 index 0000000..c7763cc --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/lib/com/acme/util/TestManagedBean.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.util; + +import javax.annotation.ManagedBean; +import javax.inject.Inject; + +@ManagedBean +public class TestManagedBean { + @Inject + private TestDependentBeanInLib tdbl; + + public boolean isInjectionSuccessful(){ + return tdbl != null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/manifest.mf b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/manifest.mf
@@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/war/com/acme/servlet/HelloServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/war/com/acme/servlet/HelloServlet.java new file mode 100644 index 0000000..221e1e4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection-with-resource-declaration-in-another-jar/war/com/acme/servlet/HelloServlet.java
@@ -0,0 +1,101 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.servlet; + + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.ejb.EJB; +import javax.inject.Inject; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.acme.ejb.api.Hello; +import com.acme.util.TestDependentBeanInLib; +import com.acme.util.ResourcesProducer; +import com.acme.util.TestDatabase; +import com.acme.util.TestManagedBean; + +@WebServlet(urlPatterns = "/HelloServlet", loadOnStartup = 1) + +@SuppressWarnings("serial") +public class HelloServlet extends HttpServlet { + String msg = ""; + + @EJB(name = "java:module/m1", beanName = "HelloSingleton", beanInterface = Hello.class) + Hello h; + + @PersistenceUnit(unitName = "pu1") + @TestDatabase + private EntityManagerFactory emf; + + @Inject + private ResourcesProducer rp; + + @Inject + private TestDependentBeanInLib fb; + + @Inject + private TestManagedBean tmb; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + System.out.println("In HelloServlet::doGet"); + resp.setContentType("text/html"); + PrintWriter out = resp.getWriter(); + + checkForNull(emf, "Injection of EMF failed in Servlet"); + //ensure EMF works! + emf.createEntityManager(); + + //call Singleton EJB + String response = h.hello(); + if(!response.equals(Hello.HELLO_TEST_STRING)) + msg += "Invocation of Hello Singeton EJB failed:msg=" + response; + + if (!rp.isInjectionSuccessful()) + msg += "Injection of a bean in lib directory into another " + + "Bean in lib directory failed"; + checkForNull(fb, "Injection of a bean that is placed in lib directory " + + "into a Servlet that is placed in a WAR failed"); + checkForNull(tmb, "Injection of a Managed bean that is placed in lib directory " + + "into a Servlet that is placed in a WAR failed"); + + if (!rp.isInjectionSuccessful()) + msg += "Injection of a bean in lib directory into another Bean " + + "in lib directory failed"; + + if (!tmb.isInjectionSuccessful()) + msg += "Injection of a Bean placed in lib dir into a " + + "ManagedBean placed in lib dir failed"; + + + out.println(msg); + } + + protected void checkForNull(Object o, String errorMessage){ + System.out.println("o=" + o); + if (o == null) msg += " " + errorMessage; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/README new file mode 100644 index 0000000..d620428 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/README
@@ -0,0 +1,5 @@ +Test +- Use of Java EE component environment resources + - type safe injection of JPA resources (EntityManagerFactory, EntityManager) + by declaring a resource by annotating a producer field wuth a + component environment injection annotation
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/build.properties new file mode 100644 index 0000000..0411ec9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/build.properties
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-em-resource-injection"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="persistence.xml" value="descriptor/persistence.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/build.xml new file mode 100644 index 0000000..295d086 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/build.xml
@@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,create-resources,deploy,run,undeploy,delete-resources" /> + + <target name="clean" depends="init-common"> + <antcall target="clean-common" /> + <delete> + <fileset dir="." includes="*.class" /> + <fileset dir="client/test/client" includes="*.class" /> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet" /> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes" /> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes" /> + <param name="webclient.war.classes" value="**/*.class" /> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" includes="test/client/WebTest.java" /> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common" /> + </target> + + <target name="create-resources" depends="init-common"> + <antcall target="create-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + <antcall target="create-jdbc-resource-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + </target> + + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}" /> + <arg value="${http.port}" /> + <arg value="${contextroot}" /> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar" /> + <pathelement location="client" /> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common" /> + </target> + + <target name="delete-resources" depends="init-common"> + <antcall target="delete-jdbc-resource-common"> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + + <antcall target="delete-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + </target> + + <target name="usage"> + <antcall target="usage-common" /> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/client/test/client/WebTest.java new file mode 100644 index 0000000..2b9abe8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/client/test/client/WebTest.java
@@ -0,0 +1,115 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "em-resource-injection"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for Java EE resource injection"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke("llinit"); + invoke("llquery"); + invoke("llfind"); + invoke("llinj"); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke(String testCase) throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl" + + "?testcase=" + testCase; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME + testCase, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME + testCase, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME + testCase, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/descriptor/persistence.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/descriptor/persistence.xml new file mode 100644 index 0000000..82f2d7b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/descriptor/persistence.xml
@@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> + <persistence-unit name="pu1" transaction-type="JTA"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <jta-data-source>jdbc/__default</jta-data-source> + <non-jta-data-source>jdbc/__default</non-jta-data-source> + <class>myapp.Department</class> + <class>myapp.Employee</class> + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> + <property name="eclipselink.logging.level" value="INFO"/> + </properties> + </persistence-unit> +</persistence>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..29e137a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void m1(); + public void m2(); + + public String testDatasourceInjection(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/beans/artifacts/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/beans/artifacts/Preferred.java new file mode 100644 index 0000000..b7584c8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/beans/artifacts/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/beans/artifacts/TestDatabase.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/beans/artifacts/TestDatabase.java new file mode 100644 index 0000000..b69ab8e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/beans/artifacts/TestDatabase.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestDatabase { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/beans/nonmock/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/beans/nonmock/TestBean.java new file mode 100644 index 0000000..2363d68 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/beans/nonmock/TestBean.java
@@ -0,0 +1,53 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.TestDatabase; + + +@RequestScoped +@Preferred +public class TestBean implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Inject //@TestDatabase + EntityManager emf; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + + @Override + public String testDatasourceInjection() { + return (emf==null ? "typesafe injection into testbean failed" : ""); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/entity/Department.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/entity/Department.java new file mode 100644 index 0000000..14191ec --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/entity/Department.java
@@ -0,0 +1,82 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "DEPARTMENT") +public class Department implements java.io.Serializable { + + // Instance variables + private int id; + private String name; + private Set<Employee> employees; + + public Department() { + } + + public Department(int id, String name) { + this.id = id; + this.name = name; + } + + // =========================================================== + // getters and setters for the state fields + + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "NAME") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + // =========================================================== + // getters and setters for the association fields + @OneToMany(cascade = CascadeType.ALL, mappedBy = "department") + public Set<Employee> getEmployees() { + return employees; + } + + public void setEmployees(Set<Employee> employees) { + this.employees = employees; + } + + public String toString() { + return "Department id=" + getId() + ", Department Name=" + getName(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/entity/Employee.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/entity/Employee.java new file mode 100644 index 0000000..a1820e8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/entity/Employee.java
@@ -0,0 +1,117 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Transient; + +@Entity +@Table(name = "EMPLOYEE") +public class Employee implements java.io.Serializable { + + private int id; + private String firstName; + private String lastName; + private Department department; + + public Employee() { + } + + public Employee(int id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public Employee(int id, String firstName, String lastName, + Department department) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + this.department = department; + } + + // =========================================================== + // getters and setters for the state fields + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "FIRSTNAME") + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + @Column(name = "LASTNAME") + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + // =========================================================== + // getters and setters for the association fields + // @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "DEPARTMENT_ID") + public Department getDepartment() { + return department; + } + + @Transient + public Department getDepartmentNoWeaving() { + try { + java.lang.reflect.Field f = Employee.class + .getDeclaredField("department"); + return (Department) f.get(this); + } catch (NoSuchFieldException e) { + throw new RuntimeException( + "Please change argument to getDeclaredField", e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public void setDepartment(Department department) { + this.department = department; + } + + public String toString() { + return "Employee id=" + getId() + ", firstName=" + getFirstName() + + ", lastName=" + getLastName() + ", department=" + + getDepartment(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/servlet/JPAResourceInjectionServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/servlet/JPAResourceInjectionServlet.java new file mode 100644 index 0000000..de25da1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/servlet/JPAResourceInjectionServlet.java
@@ -0,0 +1,93 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.transaction.UserTransaction; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.util.JpaTest; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class JPAResourceInjectionServlet extends HttpServlet { + + @PersistenceUnit(unitName = "pu1") + private EntityManagerFactory emf_at_pu; + + @Inject + //@TestDatabase + private EntityManager emf_at_inj; + + private @Resource + UserTransaction utx; + + @Inject + @Preferred + TestBeanInterface tbi; + + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, + IOException { + PrintWriter writer = response.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + System.out.println("JPAResourceInjectionServlet::@PersistenceUnit " + + "CDI EntityManagerFactory=" + emf_at_inj); + + EntityManager em = emf_at_inj; + System.out.println("JPAResourceInjectionServlet::createEM" + + "EntityManager=" + em); + String testcase = request.getParameter("testcase"); + System.out.println("testcase=" + testcase); + + if (testcase != null) { + JpaTest jt = new JpaTest(em, utx); + boolean status = false; + if ("llinit".equals(testcase)) { + status = jt.lazyLoadingInit(); + } else if ("llfind".equals(testcase)) { + status = jt.lazyLoadingByFind(1); + } else if ("llquery".equals(testcase)) { + status = jt.lazyLoadingByQuery("Carla"); + } else if ("llinj".equals(testcase)){ + status = ((tbi != null) && + (tbi.testDatasourceInjection().trim().length()==0)); + } + if (status) { + msg += "";// pass + } else { + msg += (testcase + ":fail"); + } + } + + writer.write(msg + "\n"); + + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/util/JPAResourceProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/util/JPAResourceProducer.java new file mode 100644 index 0000000..dc70909 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/util/JPAResourceProducer.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.enterprise.inject.Produces; +import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import test.beans.artifacts.TestDatabase; + +@Singleton +public class JPAResourceProducer { + @Produces @PersistenceContext(unitName="pu1") + //@TestDatabase + EntityManager customerDatabasePersistenceUnit; + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/util/JpaTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/util/JpaTest.java new file mode 100644 index 0000000..3d47448 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/em-resource-injection/servlet/test/util/JpaTest.java
@@ -0,0 +1,170 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Query; +import javax.transaction.UserTransaction; + +import test.entity.Department; +import test.entity.Employee; + +public class JpaTest { + + private EntityManager em; + private UserTransaction utx; + + private static Department deptRef[] = new Department[2]; + private static Employee empRef[] = new Employee[5]; + + public JpaTest() { + } + + public JpaTest(EntityManager em, UserTransaction utx) { + this.em = em; + this.utx = utx; + } + + public boolean lazyLoadingInit() { + boolean status = false; + System.out.println("-----lazeLoadingInit()---------"); + try { + deptRef[0] = new Department(1, "Engineering"); + deptRef[1] = new Department(2, "Marketing"); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 2; i++) { + em.persist(deptRef[i]); + } + utx.commit(); + + empRef[0] = new Employee(1, "Alan", "Frechette", deptRef[0]); + empRef[1] = new Employee(2, "Arthur", "Wesley", deptRef[0]); + empRef[2] = new Employee(3, "Abe", "White", deptRef[0]); + empRef[3] = new Employee(4, "Paul", "Hinz", deptRef[1]); + empRef[4] = new Employee(5, "Carla", "Calrson", deptRef[1]); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 5; i++) { + em.persist(empRef[i]); + } + utx.commit(); + status = true; + } catch (Exception ex) { + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByFind(int employeeID) { + + boolean status = true; + System.out.println("------------lazyLoadingAfterFind -----------"); + System.out.println("employeeID = " + employeeID); + Employee emp = em.find(Employee.class, employeeID); + + System.out.println("found: emp.id=" + emp.getId()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByQuery(String fName) { + + boolean status = true; + System.out.println("------------lazyLoadingByQuery -----------"); + System.out.println("fName = " + fName); + Query query = em.createQuery( + "SELECT e FROM Employee e WHERE e.firstName like :firstName") + .setParameter("firstName", fName); + ; + Employee emp = (Employee) query.getSingleResult(); + + System.out.println("queried: emp.firstName=" + emp.getFirstName()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/README new file mode 100644 index 0000000..b3115ec --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/README
@@ -0,0 +1,5 @@ +Test +- Use of Java EE component environment resources + - type safe injection of Java EE component resources by declaring a + resource by annotating a producer field wuth a component environment injection + annotation
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/build.properties new file mode 100644 index 0000000..3543e4c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-typesafe-javaee-resource-injection"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/build.xml new file mode 100644 index 0000000..295d086 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/build.xml
@@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,create-resources,deploy,run,undeploy,delete-resources" /> + + <target name="clean" depends="init-common"> + <antcall target="clean-common" /> + <delete> + <fileset dir="." includes="*.class" /> + <fileset dir="client/test/client" includes="*.class" /> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet" /> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes" /> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes" /> + <param name="webclient.war.classes" value="**/*.class" /> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" includes="test/client/WebTest.java" /> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common" /> + </target> + + <target name="create-resources" depends="init-common"> + <antcall target="create-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + <antcall target="create-jdbc-resource-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + </target> + + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}" /> + <arg value="${http.port}" /> + <arg value="${contextroot}" /> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar" /> + <pathelement location="client" /> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common" /> + </target> + + <target name="delete-resources" depends="init-common"> + <antcall target="delete-jdbc-resource-common"> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + + <antcall target="delete-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + </target> + + <target name="usage"> + <antcall target="usage-common" /> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/client/test/client/WebTest.java new file mode 100644 index 0000000..fb8c7f3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/client/test/client/WebTest.java
@@ -0,0 +1,111 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "typesafe-javaee-resource-injection"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for stereotypes"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..29e137a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void m1(); + public void m2(); + + public String testDatasourceInjection(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/beans/artifacts/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/beans/artifacts/Preferred.java new file mode 100644 index 0000000..b7584c8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/beans/artifacts/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/beans/artifacts/TestDatabase.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/beans/artifacts/TestDatabase.java new file mode 100644 index 0000000..b69ab8e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/beans/artifacts/TestDatabase.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestDatabase { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/beans/nonmock/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/beans/nonmock/TestBean.java new file mode 100644 index 0000000..1947fac --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/beans/nonmock/TestBean.java
@@ -0,0 +1,52 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.sql.DataSource; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.TestDatabase; + + +@RequestScoped +@Preferred +public class TestBean implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Inject @TestDatabase + DataSource ds; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + + @Override + public String testDatasourceInjection() { + return (ds==null ? "typesafe injection into testbean failed" : ""); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/servlet/DatabaseManager.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/servlet/DatabaseManager.java new file mode 100644 index 0000000..0b4d0b3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/servlet/DatabaseManager.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import javax.annotation.Resource; +import javax.enterprise.inject.Produces; +import javax.sql.DataSource; + +import test.beans.artifacts.TestDatabase; + +public class DatabaseManager { + @Produces + @TestDatabase + @Resource(name = "jdbc/jdbc-dev-test-resource", + mappedName = "jdbc/jdbc-dev-test-resource") + DataSource ds; + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/servlet/TypesafeJavaEEResourceInjectionTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/servlet/TypesafeJavaEEResourceInjectionTestServlet.java new file mode 100644 index 0000000..f1d5970 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/javaee-component-resource-typesafe-injection/servlet/test/servlet/TypesafeJavaEEResourceInjectionTestServlet.java
@@ -0,0 +1,64 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.sql.DataSource; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.TestDatabase; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class TypesafeJavaEEResourceInjectionTestServlet extends HttpServlet { + @Inject + @Preferred + TestBeanInterface tb; + + @Inject @TestDatabase + DataSource ds; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (ds == null) + msg += "typesafe Injection of datasource into a servlet failed"; + + if (tb == null) + msg += "Injection of request scoped bean failed"; + + if (tb.testDatasourceInjection().trim().length() != 0) + msg += tb.testDatasourceInjection(); + + + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/README new file mode 100644 index 0000000..e613bc1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/README
@@ -0,0 +1,5 @@ +Test +- Use of Java EE component environment resources + - type safe injection of Java EE component resources by declaring a + resource by annotating a producer field wuth a component environment injection + annotation in a library jar
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/build.properties new file mode 100644 index 0000000..4806149 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-jms-resource-injection-in-library-bean-archive"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/build.xml new file mode 100644 index 0000000..8df2c24 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/build.xml
@@ -0,0 +1,115 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,create-resources,deploy,run,undeploy,delete-resources" /> + + <target name="clean" depends="init-common"> + <antcall target="clean-common" /> + <delete> + <fileset dir="." includes="*.class" /> + <fileset dir="client/test/client" includes="*.class" /> + </delete> + </target> + + <target name="compile" depends="clean"> + <!-- compile and create library jar --> + <mkdir dir="tmp"/> + <mkdir dir="tmp/META-INF"/> + <javac srcdir="producer-library-jar" destdir="tmp" classpath="${s1astest.classpath}" debug="on" failonerror="true"/> + <copy file="descriptor/beans.xml" todir="tmp/META-INF"/> + + <mkdir dir="lib"/> + <jar jarfile="lib/producer-library.jar" update="true"> + <fileset dir="tmp" casesensitive="yes"> + <include name="**/*class*"/> + <include name="META-INF/beans.xml"/> <!-- include a beans.xml in the library jar for it to be considered as a bean archive --> + </fileset> + </jar> + <echo message="created library jar at lib/producer-library.jar"/> + + <antcall target="compile-common"> + <param name="src" value="servlet" /> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes" /> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes" /> + <param name="webclient.war.classes" value="**/*.class" /> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" includes="test/client/WebTest.java" /> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common" /> + </target> + + <target name="create-resources" depends="init-common"> + <antcall target="asadmin-batch-common"> + <param name="asadmin.file" value="create_resources.asadmin"/> + </antcall> + </target> + + <target name="delete-resources" depends="init-common"> + <antcall target="asadmin-batch-common"> + <param name="asadmin.file" value="delete_resources.asadmin"/> + </antcall> + </target> + + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}" /> + <arg value="${http.port}" /> + <arg value="${contextroot}" /> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar" /> + <pathelement location="client" /> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common" /> + <delete file="lib/producer-library.jar"/> + </target> + + <target name="usage"> + <antcall target="usage-common" /> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/client/test/client/WebTest.java new file mode 100644 index 0000000..70744e7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/client/test/client/WebTest.java
@@ -0,0 +1,111 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "jms-resource-lookup-producer-field-in-library-bean-archive"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for stereotypes"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/create_resources.asadmin b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/create_resources.asadmin new file mode 100644 index 0000000..940c1b9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/create_resources.asadmin
@@ -0,0 +1,3 @@ +create-jms-resource --restype javax.jms.ConnectionFactory jms/ConnectionFactory +create-jmsdest --desttype queue Q1 +create-jms-resource --restype javax.jms.Queue --property imqDestinationName=Q1 jms/Queue
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/delete_resources.asadmin b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/delete_resources.asadmin new file mode 100644 index 0000000..29acf02 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/delete_resources.asadmin
@@ -0,0 +1,3 @@ +delete-jms-resource jms/ConnectionFactory +delete-jms-resource jms/Queue +delete-jmsdest --desttype queue Q1
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/producer-library-jar/test/servlet/JMSResourcesProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/producer-library-jar/test/servlet/JMSResourcesProducer.java new file mode 100644 index 0000000..31f4a60 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/producer-library-jar/test/servlet/JMSResourcesProducer.java
@@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import javax.annotation.Resource; +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.jms.ConnectionFactory; +import javax.jms.JMSException; +import javax.jms.Queue; +import javax.jms.Session; + + +@ApplicationScoped +public class JMSResourcesProducer { + + @Resource(mappedName = "jms/ConnectionFactory") + private ConnectionFactory connectionFactory; + + @SuppressWarnings("unused") + @Produces + @Resource(mappedName = "jms/Queue") + private Queue queue; + + @Produces + public Session produceSession() throws JMSException { + /*try { + connectionFactory = (ConnectionFactory) new javax.naming.InitialContext().lookup("jms/ConnectionFactory"); + } catch (javax.naming.NamingException exc) { + throw new RuntimeException("couldn't lookup JMS Session", exc); + }*/ + // as per EJB 3.1 specs $13.3.5 + return connectionFactory.createConnection().createSession(true, 0); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..29e137a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void m1(); + public void m2(); + + public String testDatasourceInjection(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/servlet/test/beans/artifacts/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/servlet/test/beans/artifacts/Preferred.java new file mode 100644 index 0000000..b7584c8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/servlet/test/beans/artifacts/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/servlet/test/beans/nonmock/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/servlet/test/beans/nonmock/TestBean.java new file mode 100644 index 0000000..db83a56 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/servlet/test/beans/nonmock/TestBean.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.jms.Queue; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; + + +@RequestScoped +@Preferred +public class TestBean implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Inject + Queue ds; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + + @Override + public String testDatasourceInjection() { + return (ds==null ? "typesafe injection into testbean failed" : ""); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/servlet/test/servlet/JMSResourceInjectionInLibraryBeanArchiveTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/servlet/test/servlet/JMSResourceInjectionInLibraryBeanArchiveTestServlet.java new file mode 100644 index 0000000..5075703 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/servlet/test/servlet/JMSResourceInjectionInLibraryBeanArchiveTestServlet.java
@@ -0,0 +1,68 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.jms.Queue; +import javax.jms.Session; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class JMSResourceInjectionInLibraryBeanArchiveTestServlet extends HttpServlet { + @Inject + @Preferred + TestBeanInterface tb; + + @Inject + private Queue queue; + + @Inject + private Session session; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (queue == null) + msg += "typesafe Injection of queue into a servlet failed"; + + if (session == null) + msg += "typesafe Injection of Session into a servlet failed"; + + if (tb == null) + msg += "Injection of request scoped bean failed"; + + if (tb.testDatasourceInjection().trim().length() != 0) + msg += tb.testDatasourceInjection(); + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/tmp/META-INF/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/tmp/META-INF/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field-in-library-jar/tmp/META-INF/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/README new file mode 100644 index 0000000..e613bc1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/README
@@ -0,0 +1,5 @@ +Test +- Use of Java EE component environment resources + - type safe injection of Java EE component resources by declaring a + resource by annotating a producer field wuth a component environment injection + annotation in a library jar
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/build.properties new file mode 100644 index 0000000..65a6203 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-jms-resource-injection"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/build.xml new file mode 100644 index 0000000..1380e6b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/build.xml
@@ -0,0 +1,99 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,create-resources,deploy,run,undeploy,delete-resources" /> + + <target name="clean" depends="init-common"> + <antcall target="clean-common" /> + <delete> + <fileset dir="." includes="*.class" /> + <fileset dir="client/test/client" includes="*.class" /> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet" /> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes" /> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes" /> + <param name="webclient.war.classes" value="**/*.class" /> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" includes="test/client/WebTest.java" /> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common" /> + </target> + + <target name="create-resources" depends="init-common"> + <antcall target="asadmin-batch-common"> + <param name="asadmin.file" value="create_resources.asadmin"/> + </antcall> + </target> + + <target name="delete-resources" depends="init-common"> + <antcall target="asadmin-batch-common"> + <param name="asadmin.file" value="delete_resources.asadmin"/> + </antcall> + </target> + + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}" /> + <arg value="${http.port}" /> + <arg value="${contextroot}" /> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar" /> + <pathelement location="client" /> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common" /> + </target> + + <target name="usage"> + <antcall target="usage-common" /> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/client/test/client/WebTest.java new file mode 100644 index 0000000..c3720d7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/client/test/client/WebTest.java
@@ -0,0 +1,111 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "jms-resource-injection"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for stereotypes"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/create_resources.asadmin b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/create_resources.asadmin new file mode 100644 index 0000000..940c1b9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/create_resources.asadmin
@@ -0,0 +1,3 @@ +create-jms-resource --restype javax.jms.ConnectionFactory jms/ConnectionFactory +create-jmsdest --desttype queue Q1 +create-jms-resource --restype javax.jms.Queue --property imqDestinationName=Q1 jms/Queue
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/delete_resources.asadmin b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/delete_resources.asadmin new file mode 100644 index 0000000..29acf02 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/delete_resources.asadmin
@@ -0,0 +1,3 @@ +delete-jms-resource jms/ConnectionFactory +delete-jms-resource jms/Queue +delete-jmsdest --desttype queue Q1
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..29e137a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void m1(); + public void m2(); + + public String testDatasourceInjection(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/servlet/test/beans/artifacts/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/servlet/test/beans/artifacts/Preferred.java new file mode 100644 index 0000000..b7584c8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/servlet/test/beans/artifacts/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/servlet/test/beans/nonmock/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/servlet/test/beans/nonmock/TestBean.java new file mode 100644 index 0000000..db83a56 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/servlet/test/beans/nonmock/TestBean.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.jms.Queue; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; + + +@RequestScoped +@Preferred +public class TestBean implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Inject + Queue ds; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + + @Override + public String testDatasourceInjection() { + return (ds==null ? "typesafe injection into testbean failed" : ""); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/servlet/test/servlet/JMSResourceInjectionInLibraryBeanArchiveTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/servlet/test/servlet/JMSResourceInjectionInLibraryBeanArchiveTestServlet.java new file mode 100644 index 0000000..5075703 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/servlet/test/servlet/JMSResourceInjectionInLibraryBeanArchiveTestServlet.java
@@ -0,0 +1,68 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.jms.Queue; +import javax.jms.Session; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class JMSResourceInjectionInLibraryBeanArchiveTestServlet extends HttpServlet { + @Inject + @Preferred + TestBeanInterface tb; + + @Inject + private Queue queue; + + @Inject + private Session session; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (queue == null) + msg += "typesafe Injection of queue into a servlet failed"; + + if (session == null) + msg += "typesafe Injection of Session into a servlet failed"; + + if (tb == null) + msg += "Injection of request scoped bean failed"; + + if (tb.testDatasourceInjection().trim().length() != 0) + msg += tb.testDatasourceInjection(); + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/servlet/test/servlet/JMSResourcesProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/servlet/test/servlet/JMSResourcesProducer.java new file mode 100644 index 0000000..31f4a60 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jms-resource-producer-field/servlet/test/servlet/JMSResourcesProducer.java
@@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import javax.annotation.Resource; +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.jms.ConnectionFactory; +import javax.jms.JMSException; +import javax.jms.Queue; +import javax.jms.Session; + + +@ApplicationScoped +public class JMSResourcesProducer { + + @Resource(mappedName = "jms/ConnectionFactory") + private ConnectionFactory connectionFactory; + + @SuppressWarnings("unused") + @Produces + @Resource(mappedName = "jms/Queue") + private Queue queue; + + @Produces + public Session produceSession() throws JMSException { + /*try { + connectionFactory = (ConnectionFactory) new javax.naming.InitialContext().lookup("jms/ConnectionFactory"); + } catch (javax.naming.NamingException exc) { + throw new RuntimeException("couldn't lookup JMS Session", exc); + }*/ + // as per EJB 3.1 specs $13.3.5 + return connectionFactory.createConnection().createSession(true, 0); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/README new file mode 100644 index 0000000..c5e296b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/README
@@ -0,0 +1,6 @@ +Test +- Use of Java EE component environment resources + - type safe injection of JPA resources (EntityManagerFactory, EntityManager) + by declaring a resource by annotating a producer field wuth a + component environment injection annotation + - test if injection of non-serializable resource like EntityManager is supported. This should not result in a deployment failure
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/build.properties new file mode 100644 index 0000000..fa73b33 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/build.properties
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-jpa-resource-injection-non-serializable"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="persistence.xml" value="descriptor/persistence.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/build.xml new file mode 100644 index 0000000..295d086 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/build.xml
@@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,create-resources,deploy,run,undeploy,delete-resources" /> + + <target name="clean" depends="init-common"> + <antcall target="clean-common" /> + <delete> + <fileset dir="." includes="*.class" /> + <fileset dir="client/test/client" includes="*.class" /> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet" /> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes" /> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes" /> + <param name="webclient.war.classes" value="**/*.class" /> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" includes="test/client/WebTest.java" /> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common" /> + </target> + + <target name="create-resources" depends="init-common"> + <antcall target="create-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + <antcall target="create-jdbc-resource-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + </target> + + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}" /> + <arg value="${http.port}" /> + <arg value="${contextroot}" /> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar" /> + <pathelement location="client" /> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common" /> + </target> + + <target name="delete-resources" depends="init-common"> + <antcall target="delete-jdbc-resource-common"> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + + <antcall target="delete-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + </target> + + <target name="usage"> + <antcall target="usage-common" /> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/client/test/client/WebTest.java new file mode 100644 index 0000000..19e1eb6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/client/test/client/WebTest.java
@@ -0,0 +1,115 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "jpa-resource-injection-non-serializable"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for Java EE resource injection"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke("llinit"); + invoke("llquery"); + invoke("llfind"); + invoke("llinj"); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed. Unexpected error obtained:" + ex); + stat.addStatus(TEST_NAME, stat.FAIL); + //ex.printStackTrace(); + } + } + + private void invoke(String testCase) throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl" + + "?testcase=" + testCase; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME + testCase, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME + testCase, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME + testCase, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/descriptor/persistence.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/descriptor/persistence.xml new file mode 100644 index 0000000..713e047 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/descriptor/persistence.xml
@@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> + <persistence-unit name="pu2" transaction-type="JTA"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <jta-data-source>jdbc/__default</jta-data-source> + <non-jta-data-source>jdbc/__default</non-jta-data-source> + <class>myapp.Department</class> + <class>myapp.Employee</class> + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> + <property name="eclipselink.logging.level" value="INFO"/> + </properties> + </persistence-unit> +</persistence>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..29e137a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void m1(); + public void m2(); + + public String testDatasourceInjection(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/beans/artifacts/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/beans/artifacts/Preferred.java new file mode 100644 index 0000000..b7584c8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/beans/artifacts/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/beans/artifacts/TestDatabase.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/beans/artifacts/TestDatabase.java new file mode 100644 index 0000000..b69ab8e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/beans/artifacts/TestDatabase.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestDatabase { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/beans/nonmock/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/beans/nonmock/TestBean.java new file mode 100644 index 0000000..e2d6110 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/beans/nonmock/TestBean.java
@@ -0,0 +1,61 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import java.io.Serializable; + +import javax.enterprise.context.SessionScoped; +import javax.inject.Inject; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityManager; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.TestDatabase; + + +@SessionScoped //a passivating scope +@Preferred +public class TestBean implements TestBeanInterface, Serializable{ + public static boolean testBeanInvoked = false; + + @Inject @TestDatabase + EntityManagerFactory emf; + + //Inject a non-serializable resource + @Inject @TestDatabase + EntityManager em; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + + @Override + public String testDatasourceInjection() { + String s = (emf==null ? "typesafe injection into testbean of EntityManagerFactory failed" : ""); + s += (em == null ? "typesafe injection of EntityManager into testbean failed":""); + return s; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/entity/Department.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/entity/Department.java new file mode 100644 index 0000000..14191ec --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/entity/Department.java
@@ -0,0 +1,82 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "DEPARTMENT") +public class Department implements java.io.Serializable { + + // Instance variables + private int id; + private String name; + private Set<Employee> employees; + + public Department() { + } + + public Department(int id, String name) { + this.id = id; + this.name = name; + } + + // =========================================================== + // getters and setters for the state fields + + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "NAME") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + // =========================================================== + // getters and setters for the association fields + @OneToMany(cascade = CascadeType.ALL, mappedBy = "department") + public Set<Employee> getEmployees() { + return employees; + } + + public void setEmployees(Set<Employee> employees) { + this.employees = employees; + } + + public String toString() { + return "Department id=" + getId() + ", Department Name=" + getName(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/entity/Employee.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/entity/Employee.java new file mode 100644 index 0000000..a1820e8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/entity/Employee.java
@@ -0,0 +1,117 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Transient; + +@Entity +@Table(name = "EMPLOYEE") +public class Employee implements java.io.Serializable { + + private int id; + private String firstName; + private String lastName; + private Department department; + + public Employee() { + } + + public Employee(int id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public Employee(int id, String firstName, String lastName, + Department department) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + this.department = department; + } + + // =========================================================== + // getters and setters for the state fields + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "FIRSTNAME") + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + @Column(name = "LASTNAME") + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + // =========================================================== + // getters and setters for the association fields + // @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "DEPARTMENT_ID") + public Department getDepartment() { + return department; + } + + @Transient + public Department getDepartmentNoWeaving() { + try { + java.lang.reflect.Field f = Employee.class + .getDeclaredField("department"); + return (Department) f.get(this); + } catch (NoSuchFieldException e) { + throw new RuntimeException( + "Please change argument to getDeclaredField", e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public void setDepartment(Department department) { + this.department = department; + } + + public String toString() { + return "Employee id=" + getId() + ", firstName=" + getFirstName() + + ", lastName=" + getLastName() + ", department=" + + getDepartment(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/servlet/JPAResourceInjectionServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/servlet/JPAResourceInjectionServlet.java new file mode 100644 index 0000000..086729b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/servlet/JPAResourceInjectionServlet.java
@@ -0,0 +1,94 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.transaction.UserTransaction; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.TestDatabase; +import test.util.JpaTest; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class JPAResourceInjectionServlet extends HttpServlet { + + @PersistenceUnit(unitName = "pu2") + private EntityManagerFactory emf; + + @Inject + @TestDatabase + private EntityManagerFactory emf1; + + private @Resource + UserTransaction utx; + + @Inject + @Preferred + TestBeanInterface tbi; + + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, + IOException { + PrintWriter writer = response.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + System.out.println("JPAResourceInjectionServlet::@PersistenceUnit " + + "CDI EntityManagerFactory=" + emf1); + + EntityManager em = emf1.createEntityManager(); + System.out.println("JPAResourceInjectionServlet::createEM" + + "EntityManager=" + em); + String testcase = request.getParameter("testcase"); + System.out.println("testcase=" + testcase); + + if (testcase != null) { + JpaTest jt = new JpaTest(em, utx); + boolean status = false; + if ("llinit".equals(testcase)) { + status = jt.lazyLoadingInit(); + } else if ("llfind".equals(testcase)) { + status = jt.lazyLoadingByFind(1); + } else if ("llquery".equals(testcase)) { + status = jt.lazyLoadingByQuery("Carla"); + } else if ("llinj".equals(testcase)){ + status = ((tbi != null) && + (tbi.testDatasourceInjection().trim().length()==0)); + } + if (status) { + msg += "";// pass + } else { + msg += (testcase + ":fail"); + } + } + + writer.write(msg + "\n"); + + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/util/JPAResourceProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/util/JPAResourceProducer.java new file mode 100644 index 0000000..3623e19 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/util/JPAResourceProducer.java
@@ -0,0 +1,37 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.enterprise.inject.Produces; +import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceContext; +import javax.persistence.PersistenceUnit; + +import test.beans.artifacts.TestDatabase; + +@Singleton +public class JPAResourceProducer { + @Produces @PersistenceUnit(unitName="pu2") + @TestDatabase + EntityManagerFactory customerDatabasePersistenceUnit; + + @Produces @PersistenceContext(unitName="pu2") + @TestDatabase + EntityManager customerDatabasePersistenceContext; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/util/JpaTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/util/JpaTest.java new file mode 100644 index 0000000..3d47448 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-non-serializable/servlet/test/util/JpaTest.java
@@ -0,0 +1,170 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Query; +import javax.transaction.UserTransaction; + +import test.entity.Department; +import test.entity.Employee; + +public class JpaTest { + + private EntityManager em; + private UserTransaction utx; + + private static Department deptRef[] = new Department[2]; + private static Employee empRef[] = new Employee[5]; + + public JpaTest() { + } + + public JpaTest(EntityManager em, UserTransaction utx) { + this.em = em; + this.utx = utx; + } + + public boolean lazyLoadingInit() { + boolean status = false; + System.out.println("-----lazeLoadingInit()---------"); + try { + deptRef[0] = new Department(1, "Engineering"); + deptRef[1] = new Department(2, "Marketing"); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 2; i++) { + em.persist(deptRef[i]); + } + utx.commit(); + + empRef[0] = new Employee(1, "Alan", "Frechette", deptRef[0]); + empRef[1] = new Employee(2, "Arthur", "Wesley", deptRef[0]); + empRef[2] = new Employee(3, "Abe", "White", deptRef[0]); + empRef[3] = new Employee(4, "Paul", "Hinz", deptRef[1]); + empRef[4] = new Employee(5, "Carla", "Calrson", deptRef[1]); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 5; i++) { + em.persist(empRef[i]); + } + utx.commit(); + status = true; + } catch (Exception ex) { + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByFind(int employeeID) { + + boolean status = true; + System.out.println("------------lazyLoadingAfterFind -----------"); + System.out.println("employeeID = " + employeeID); + Employee emp = em.find(Employee.class, employeeID); + + System.out.println("found: emp.id=" + emp.getId()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByQuery(String fName) { + + boolean status = true; + System.out.println("------------lazyLoadingByQuery -----------"); + System.out.println("fName = " + fName); + Query query = em.createQuery( + "SELECT e FROM Employee e WHERE e.firstName like :firstName") + .setParameter("firstName", fName); + ; + Employee emp = (Employee) query.getSingleResult(); + + System.out.println("queried: emp.firstName=" + emp.getFirstName()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/README new file mode 100644 index 0000000..e90237d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/README
@@ -0,0 +1,7 @@ +Test +- Use of Java EE component environment resources +Passivating Scopes and passivation capable dependencies + - test if a producer method can return a non-serializable resource [EntityManager]. + - test if a Stateful session bean can have non-transient injected field that is a resource + +This test is similar to jpa-resource-injection-non-serializable except that the injection happens into a SFSB [a passivating bean]
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/build.properties new file mode 100644 index 0000000..87af1eb --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/build.properties
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-jpa-resource-injection-passivating-scope"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="persistence.xml" value="descriptor/persistence.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/build.xml new file mode 100644 index 0000000..295d086 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/build.xml
@@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,create-resources,deploy,run,undeploy,delete-resources" /> + + <target name="clean" depends="init-common"> + <antcall target="clean-common" /> + <delete> + <fileset dir="." includes="*.class" /> + <fileset dir="client/test/client" includes="*.class" /> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet" /> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes" /> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes" /> + <param name="webclient.war.classes" value="**/*.class" /> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" includes="test/client/WebTest.java" /> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common" /> + </target> + + <target name="create-resources" depends="init-common"> + <antcall target="create-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + <antcall target="create-jdbc-resource-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + </target> + + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}" /> + <arg value="${http.port}" /> + <arg value="${contextroot}" /> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar" /> + <pathelement location="client" /> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common" /> + </target> + + <target name="delete-resources" depends="init-common"> + <antcall target="delete-jdbc-resource-common"> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + + <antcall target="delete-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + </target> + + <target name="usage"> + <antcall target="usage-common" /> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/client/test/client/WebTest.java new file mode 100644 index 0000000..5b5f610 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/client/test/client/WebTest.java
@@ -0,0 +1,115 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "jpa-resource-injection-passivating-scope"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for Java EE resource injection"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke("llinit"); + invoke("llquery"); + invoke("llfind"); + invoke("llinj"); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed. Expected error obtained:" + ex); + stat.addStatus(TEST_NAME, stat.FAIL); + //ex.printStackTrace(); + } + } + + private void invoke(String testCase) throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl" + + "?testcase=" + testCase; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME + testCase, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME + testCase, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME + testCase, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/descriptor/persistence.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/descriptor/persistence.xml new file mode 100644 index 0000000..2a7b5a0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/descriptor/persistence.xml
@@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> + <persistence-unit name="pu3" transaction-type="JTA"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <jta-data-source>jdbc/__default</jta-data-source> + <non-jta-data-source>jdbc/__default</non-jta-data-source> + <class>myapp.Department</class> + <class>myapp.Employee</class> + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> + <property name="eclipselink.logging.level" value="INFO"/> + </properties> + </persistence-unit> +</persistence>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..29e137a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void m1(); + public void m2(); + + public String testDatasourceInjection(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/beans/artifacts/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/beans/artifacts/Preferred.java new file mode 100644 index 0000000..b7584c8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/beans/artifacts/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/beans/artifacts/TestDatabase.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/beans/artifacts/TestDatabase.java new file mode 100644 index 0000000..b69ab8e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/beans/artifacts/TestDatabase.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestDatabase { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/ejb/TestEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/ejb/TestEJB.java new file mode 100644 index 0000000..4065801 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/ejb/TestEJB.java
@@ -0,0 +1,39 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb; + +import javax.ejb.Stateful; +import javax.inject.Inject; +import javax.persistence.EntityManager; + +import test.beans.artifacts.TestDatabase; + +@Stateful +public class TestEJB{ + + @Inject + @TestDatabase + transient EntityManager em; + + public String test() { + String s = ""; + em.isOpen();//use the EM + if(em == null) s += "EntityManager injection into TestEJB failed"; + return s; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/entity/Department.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/entity/Department.java new file mode 100644 index 0000000..14191ec --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/entity/Department.java
@@ -0,0 +1,82 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "DEPARTMENT") +public class Department implements java.io.Serializable { + + // Instance variables + private int id; + private String name; + private Set<Employee> employees; + + public Department() { + } + + public Department(int id, String name) { + this.id = id; + this.name = name; + } + + // =========================================================== + // getters and setters for the state fields + + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "NAME") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + // =========================================================== + // getters and setters for the association fields + @OneToMany(cascade = CascadeType.ALL, mappedBy = "department") + public Set<Employee> getEmployees() { + return employees; + } + + public void setEmployees(Set<Employee> employees) { + this.employees = employees; + } + + public String toString() { + return "Department id=" + getId() + ", Department Name=" + getName(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/entity/Employee.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/entity/Employee.java new file mode 100644 index 0000000..a1820e8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/entity/Employee.java
@@ -0,0 +1,117 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Transient; + +@Entity +@Table(name = "EMPLOYEE") +public class Employee implements java.io.Serializable { + + private int id; + private String firstName; + private String lastName; + private Department department; + + public Employee() { + } + + public Employee(int id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public Employee(int id, String firstName, String lastName, + Department department) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + this.department = department; + } + + // =========================================================== + // getters and setters for the state fields + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "FIRSTNAME") + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + @Column(name = "LASTNAME") + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + // =========================================================== + // getters and setters for the association fields + // @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "DEPARTMENT_ID") + public Department getDepartment() { + return department; + } + + @Transient + public Department getDepartmentNoWeaving() { + try { + java.lang.reflect.Field f = Employee.class + .getDeclaredField("department"); + return (Department) f.get(this); + } catch (NoSuchFieldException e) { + throw new RuntimeException( + "Please change argument to getDeclaredField", e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public void setDepartment(Department department) { + this.department = department; + } + + public String toString() { + return "Employee id=" + getId() + ", firstName=" + getFirstName() + + ", lastName=" + getLastName() + ", department=" + + getDepartment(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/servlet/JPAResourceInjectionServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/servlet/JPAResourceInjectionServlet.java new file mode 100644 index 0000000..afb7a69 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/servlet/JPAResourceInjectionServlet.java
@@ -0,0 +1,94 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.transaction.UserTransaction; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.TestDatabase; +import test.ejb.TestEJB; +import test.util.JpaTest; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class JPAResourceInjectionServlet extends HttpServlet { + + @PersistenceUnit(unitName = "pu3") + private EntityManagerFactory emf; + + @Inject + @TestDatabase + private EntityManagerFactory emf1; + + private @Resource + UserTransaction utx; + + @Inject + TestEJB tbi; + + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, + IOException { + PrintWriter writer = response.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + System.out.println("JPAResourceInjectionServlet::@PersistenceUnit " + + "CDI EntityManagerFactory=" + emf1); + + EntityManager em = emf1.createEntityManager(); + System.out.println("JPAResourceInjectionServlet::createEM" + + "EntityManager=" + em); + String testcase = request.getParameter("testcase"); + System.out.println("testcase=" + testcase); + + if (testcase != null) { + JpaTest jt = new JpaTest(em, utx); + boolean status = false; + if ("llinit".equals(testcase)) { + status = jt.lazyLoadingInit(); + } else if ("llfind".equals(testcase)) { + status = jt.lazyLoadingByFind(1); + } else if ("llquery".equals(testcase)) { + status = jt.lazyLoadingByQuery("Carla"); + } else if ("llinj".equals(testcase)){ + status = ((tbi != null) && + (tbi.test().length() == 0)); + } + if (status) { + msg += "";// pass + } else { + msg += (testcase + ":fail"); + } + } + + writer.write(msg + "\n"); + + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/util/JPAResourceProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/util/JPAResourceProducer.java new file mode 100644 index 0000000..4714b5d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/util/JPAResourceProducer.java
@@ -0,0 +1,39 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.enterprise.context.ConversationScoped; +import javax.enterprise.inject.Produces; +import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceContext; +import javax.persistence.PersistenceUnit; + +import test.beans.artifacts.TestDatabase; + +@Singleton +public class JPAResourceProducer { + @Produces @PersistenceUnit(unitName="pu3") + @TestDatabase + EntityManagerFactory customerDatabasePersistenceUnit; + + @Produces @PersistenceContext(unitName="pu3") + @TestDatabase + EntityManager customerDatabasePersistenceContext; + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/util/JpaTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/util/JpaTest.java new file mode 100644 index 0000000..3d47448 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-passivating-scope/servlet/test/util/JpaTest.java
@@ -0,0 +1,170 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Query; +import javax.transaction.UserTransaction; + +import test.entity.Department; +import test.entity.Employee; + +public class JpaTest { + + private EntityManager em; + private UserTransaction utx; + + private static Department deptRef[] = new Department[2]; + private static Employee empRef[] = new Employee[5]; + + public JpaTest() { + } + + public JpaTest(EntityManager em, UserTransaction utx) { + this.em = em; + this.utx = utx; + } + + public boolean lazyLoadingInit() { + boolean status = false; + System.out.println("-----lazeLoadingInit()---------"); + try { + deptRef[0] = new Department(1, "Engineering"); + deptRef[1] = new Department(2, "Marketing"); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 2; i++) { + em.persist(deptRef[i]); + } + utx.commit(); + + empRef[0] = new Employee(1, "Alan", "Frechette", deptRef[0]); + empRef[1] = new Employee(2, "Arthur", "Wesley", deptRef[0]); + empRef[2] = new Employee(3, "Abe", "White", deptRef[0]); + empRef[3] = new Employee(4, "Paul", "Hinz", deptRef[1]); + empRef[4] = new Employee(5, "Carla", "Calrson", deptRef[1]); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 5; i++) { + em.persist(empRef[i]); + } + utx.commit(); + status = true; + } catch (Exception ex) { + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByFind(int employeeID) { + + boolean status = true; + System.out.println("------------lazyLoadingAfterFind -----------"); + System.out.println("employeeID = " + employeeID); + Employee emp = em.find(Employee.class, employeeID); + + System.out.println("found: emp.id=" + emp.getId()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByQuery(String fName) { + + boolean status = true; + System.out.println("------------lazyLoadingByQuery -----------"); + System.out.println("fName = " + fName); + Query query = em.createQuery( + "SELECT e FROM Employee e WHERE e.firstName like :firstName") + .setParameter("firstName", fName); + ; + Employee emp = (Employee) query.getSingleResult(); + + System.out.println("queried: emp.firstName=" + emp.getFirstName()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/README new file mode 100644 index 0000000..0a06178 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/README
@@ -0,0 +1,6 @@ +Test +- Use of Java EE component environment resources + - type safe injection of JPA resources (EntityManagerFactory, EntityManager) + by declaring a resource through + - a static field of a singleton EJB acting as a producer field + - a business method in a singleton EJB acting as a producer method
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/build.properties new file mode 100644 index 0000000..e2f195c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/build.properties
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-jpa-resource-injection-in-singleton-ejb"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="persistence.xml" value="descriptor/persistence.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/build.xml new file mode 100644 index 0000000..295d086 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/build.xml
@@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,create-resources,deploy,run,undeploy,delete-resources" /> + + <target name="clean" depends="init-common"> + <antcall target="clean-common" /> + <delete> + <fileset dir="." includes="*.class" /> + <fileset dir="client/test/client" includes="*.class" /> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet" /> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes" /> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes" /> + <param name="webclient.war.classes" value="**/*.class" /> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" includes="test/client/WebTest.java" /> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common" /> + </target> + + <target name="create-resources" depends="init-common"> + <antcall target="create-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + <antcall target="create-jdbc-resource-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + </target> + + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}" /> + <arg value="${http.port}" /> + <arg value="${contextroot}" /> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar" /> + <pathelement location="client" /> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common" /> + </target> + + <target name="delete-resources" depends="init-common"> + <antcall target="delete-jdbc-resource-common"> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + + <antcall target="delete-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + </target> + + <target name="usage"> + <antcall target="usage-common" /> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/client/test/client/WebTest.java new file mode 100644 index 0000000..b474733 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/client/test/client/WebTest.java
@@ -0,0 +1,125 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "jpa-resource-injection-from-singleton-EJB"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for Java EE resource injection"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + runOneCycle("producer"); + //TODO: This test fails currently + //runOneCycle("static"); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void runOneCycle(String whichEMF) throws Exception { + invoke(whichEMF, "llinit"); + invoke(whichEMF, "llquery"); + invoke(whichEMF,"llfind"); + invoke(whichEMF,"llinj"); + } + + private void invoke(String whichEMF, String testCase) throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl" + + "?testcase=" + testCase + "&whichemf=" + whichEMF; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(getTestName(whichEMF, testCase), stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(getTestName(whichEMF, testCase), stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(getTestName(whichEMF, testCase), stat.FAIL); + } + } + } + + private String getTestName(String whichEMF, String testCase){ + return TEST_NAME + "_" + whichEMF + "_" +testCase; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/descriptor/persistence.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/descriptor/persistence.xml new file mode 100644 index 0000000..82f2d7b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/descriptor/persistence.xml
@@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> + <persistence-unit name="pu1" transaction-type="JTA"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <jta-data-source>jdbc/__default</jta-data-source> + <non-jta-data-source>jdbc/__default</non-jta-data-source> + <class>myapp.Department</class> + <class>myapp.Employee</class> + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> + <property name="eclipselink.logging.level" value="INFO"/> + </properties> + </persistence-unit> +</persistence>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..29e137a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void m1(); + public void m2(); + + public String testDatasourceInjection(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/artifacts/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/artifacts/Preferred.java new file mode 100644 index 0000000..b7584c8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/artifacts/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/artifacts/ProducedViaProducerMethod.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/artifacts/ProducedViaProducerMethod.java new file mode 100644 index 0000000..5c60345 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/artifacts/ProducedViaProducerMethod.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface ProducedViaProducerMethod { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/artifacts/ProducedViaStaticField.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/artifacts/ProducedViaStaticField.java new file mode 100644 index 0000000..e988e7e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/artifacts/ProducedViaStaticField.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface ProducedViaStaticField { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/artifacts/TestDatabase.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/artifacts/TestDatabase.java new file mode 100644 index 0000000..b69ab8e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/artifacts/TestDatabase.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestDatabase { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/nonmock/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/nonmock/TestBean.java new file mode 100644 index 0000000..f61ec1b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/beans/nonmock/TestBean.java
@@ -0,0 +1,54 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.persistence.EntityManagerFactory; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.ProducedViaProducerMethod; +import test.beans.artifacts.ProducedViaStaticField; +import test.beans.artifacts.TestDatabase; + + +@RequestScoped +@Preferred +public class TestBean implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Inject @ProducedViaProducerMethod + EntityManagerFactory emf; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + + @Override + public String testDatasourceInjection() { + return (emf==null ? "typesafe injection into testbean failed" : ""); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/ejb/JPAResourceProducerSingletonEJB_BusinessMethodProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/ejb/JPAResourceProducerSingletonEJB_BusinessMethodProducer.java new file mode 100644 index 0000000..b20fae4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/ejb/JPAResourceProducerSingletonEJB_BusinessMethodProducer.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb; + +import javax.enterprise.inject.Produces; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; + +import test.beans.artifacts.ProducedViaProducerMethod; +import test.beans.artifacts.ProducedViaStaticField; + +@javax.ejb.Singleton +public class JPAResourceProducerSingletonEJB_BusinessMethodProducer { + @PersistenceUnit(unitName="pu1") + EntityManagerFactory customerDatabasePersistenceUnit; + + @Produces @ProducedViaProducerMethod + public EntityManagerFactory createEMF(){ + return customerDatabasePersistenceUnit; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/ejb/JPAResourceProducerSingletonEJB_StaticField.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/ejb/JPAResourceProducerSingletonEJB_StaticField.java new file mode 100644 index 0000000..adbca7b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/ejb/JPAResourceProducerSingletonEJB_StaticField.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb; + +import javax.enterprise.inject.Produces; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; + +import test.beans.artifacts.ProducedViaStaticField; + +@javax.ejb.Singleton +public class JPAResourceProducerSingletonEJB_StaticField { + @Produces @PersistenceUnit(unitName="pu1") @ProducedViaStaticField + public static EntityManagerFactory customerDatabasePersistenceUnit1; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/entity/Department.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/entity/Department.java new file mode 100644 index 0000000..14191ec --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/entity/Department.java
@@ -0,0 +1,82 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "DEPARTMENT") +public class Department implements java.io.Serializable { + + // Instance variables + private int id; + private String name; + private Set<Employee> employees; + + public Department() { + } + + public Department(int id, String name) { + this.id = id; + this.name = name; + } + + // =========================================================== + // getters and setters for the state fields + + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "NAME") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + // =========================================================== + // getters and setters for the association fields + @OneToMany(cascade = CascadeType.ALL, mappedBy = "department") + public Set<Employee> getEmployees() { + return employees; + } + + public void setEmployees(Set<Employee> employees) { + this.employees = employees; + } + + public String toString() { + return "Department id=" + getId() + ", Department Name=" + getName(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/entity/Employee.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/entity/Employee.java new file mode 100644 index 0000000..a1820e8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/entity/Employee.java
@@ -0,0 +1,117 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Transient; + +@Entity +@Table(name = "EMPLOYEE") +public class Employee implements java.io.Serializable { + + private int id; + private String firstName; + private String lastName; + private Department department; + + public Employee() { + } + + public Employee(int id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public Employee(int id, String firstName, String lastName, + Department department) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + this.department = department; + } + + // =========================================================== + // getters and setters for the state fields + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "FIRSTNAME") + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + @Column(name = "LASTNAME") + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + // =========================================================== + // getters and setters for the association fields + // @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "DEPARTMENT_ID") + public Department getDepartment() { + return department; + } + + @Transient + public Department getDepartmentNoWeaving() { + try { + java.lang.reflect.Field f = Employee.class + .getDeclaredField("department"); + return (Department) f.get(this); + } catch (NoSuchFieldException e) { + throw new RuntimeException( + "Please change argument to getDeclaredField", e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public void setDepartment(Department department) { + this.department = department; + } + + public String toString() { + return "Employee id=" + getId() + ", firstName=" + getFirstName() + + ", lastName=" + getLastName() + ", department=" + + getDepartment(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/servlet/JPAResourceInjectionServletFromSingletonEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/servlet/JPAResourceInjectionServletFromSingletonEJB.java new file mode 100644 index 0000000..96167f7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/servlet/JPAResourceInjectionServletFromSingletonEJB.java
@@ -0,0 +1,118 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.transaction.UserTransaction; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.ProducedViaProducerMethod; +import test.beans.artifacts.ProducedViaStaticField; +import test.util.JpaTest; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class JPAResourceInjectionServletFromSingletonEJB extends HttpServlet { + + @PersistenceUnit(unitName = "pu1") + private EntityManagerFactory emf; + + @Inject + @ProducedViaProducerMethod + private EntityManagerFactory emf_producer; + + @Inject + @ProducedViaStaticField + private EntityManagerFactory emf_static; + + + private @Resource + UserTransaction utx; + + @Inject + @Preferred + TestBeanInterface tbi; + + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, + IOException { + PrintWriter writer = response.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (emf == null) + msg += "Simple injection of EntityManagerFactory through " + + "@PersistenceUnit failed"; + String testcase = request.getParameter("testcase"); + System.out.println("testcase=" + testcase); + + String whichEMF = request.getParameter("whichemf"); + System.out.println("whichEMF=" + whichEMF); + + EntityManager em = null; + if (whichEMF != null){ + EntityManagerFactory emf = null; + if (whichEMF.equals("producer")){ + emf = emf_producer; + } else if (whichEMF.equals("static")) { + emf = emf_static; + } + //System.out.println("JPAResourceInjectionServlet::@PersistenceUnit " + + // "CDI EntityManagerFactory to run against=" + emf); + em = emf.createEntityManager(); + System.out.println("JPAResourceInjectionServlet::createEM" + + "EntityManager=" + em); + } + + if (testcase != null) { + + JpaTest jt = new JpaTest(em, utx); + boolean status = false; + if ("llinit".equals(testcase)) { + status = jt.lazyLoadingInit(); + } else if ("llfind".equals(testcase)) { + status = jt.lazyLoadingByFind(1); + } else if ("llquery".equals(testcase)) { + status = jt.lazyLoadingByQuery("Carla"); + } else if ("llinj".equals(testcase)){ + status = ((tbi != null) && + (tbi.testDatasourceInjection().trim().length()==0)); + } + + if (status) { + msg += "";// pass + } else { + msg += (testcase + ":fail"); + } + } + + writer.write(msg + "\n"); + + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/util/JpaTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/util/JpaTest.java new file mode 100644 index 0000000..3d47448 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/servlet/test/util/JpaTest.java
@@ -0,0 +1,170 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Query; +import javax.transaction.UserTransaction; + +import test.entity.Department; +import test.entity.Employee; + +public class JpaTest { + + private EntityManager em; + private UserTransaction utx; + + private static Department deptRef[] = new Department[2]; + private static Employee empRef[] = new Employee[5]; + + public JpaTest() { + } + + public JpaTest(EntityManager em, UserTransaction utx) { + this.em = em; + this.utx = utx; + } + + public boolean lazyLoadingInit() { + boolean status = false; + System.out.println("-----lazeLoadingInit()---------"); + try { + deptRef[0] = new Department(1, "Engineering"); + deptRef[1] = new Department(2, "Marketing"); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 2; i++) { + em.persist(deptRef[i]); + } + utx.commit(); + + empRef[0] = new Employee(1, "Alan", "Frechette", deptRef[0]); + empRef[1] = new Employee(2, "Arthur", "Wesley", deptRef[0]); + empRef[2] = new Employee(3, "Abe", "White", deptRef[0]); + empRef[3] = new Employee(4, "Paul", "Hinz", deptRef[1]); + empRef[4] = new Employee(5, "Carla", "Calrson", deptRef[1]); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 5; i++) { + em.persist(empRef[i]); + } + utx.commit(); + status = true; + } catch (Exception ex) { + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByFind(int employeeID) { + + boolean status = true; + System.out.println("------------lazyLoadingAfterFind -----------"); + System.out.println("employeeID = " + employeeID); + Employee emp = em.find(Employee.class, employeeID); + + System.out.println("found: emp.id=" + emp.getId()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByQuery(String fName) { + + boolean status = true; + System.out.println("------------lazyLoadingByQuery -----------"); + System.out.println("fName = " + fName); + Query query = em.createQuery( + "SELECT e FROM Employee e WHERE e.firstName like :firstName") + .setParameter("firstName", fName); + ; + Employee emp = (Employee) query.getSingleResult(); + + System.out.println("queried: emp.firstName=" + emp.getFirstName()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/README new file mode 100644 index 0000000..d620428 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/README
@@ -0,0 +1,5 @@ +Test +- Use of Java EE component environment resources + - type safe injection of JPA resources (EntityManagerFactory, EntityManager) + by declaring a resource by annotating a producer field wuth a + component environment injection annotation
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/build.properties new file mode 100644 index 0000000..168fae7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/build.properties
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-jpa-resource-injection"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="persistence.xml" value="descriptor/persistence.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/build.xml new file mode 100644 index 0000000..295d086 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/build.xml
@@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,create-resources,deploy,run,undeploy,delete-resources" /> + + <target name="clean" depends="init-common"> + <antcall target="clean-common" /> + <delete> + <fileset dir="." includes="*.class" /> + <fileset dir="client/test/client" includes="*.class" /> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet" /> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes" /> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes" /> + <param name="webclient.war.classes" value="**/*.class" /> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" includes="test/client/WebTest.java" /> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common" /> + </target> + + <target name="create-resources" depends="init-common"> + <antcall target="create-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + <antcall target="create-jdbc-resource-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + </target> + + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}" /> + <arg value="${http.port}" /> + <arg value="${contextroot}" /> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar" /> + <pathelement location="client" /> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common" /> + </target> + + <target name="delete-resources" depends="init-common"> + <antcall target="delete-jdbc-resource-common"> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + + <antcall target="delete-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + </target> + + <target name="usage"> + <antcall target="usage-common" /> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/client/test/client/WebTest.java new file mode 100644 index 0000000..1cde8c0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/client/test/client/WebTest.java
@@ -0,0 +1,115 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "jpa-resource-injection"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for Java EE resource injection"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke("llinit"); + invoke("llquery"); + invoke("llfind"); + invoke("llinj"); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke(String testCase) throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl" + + "?testcase=" + testCase; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME + testCase, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME + testCase, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME + testCase, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/descriptor/persistence.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/descriptor/persistence.xml new file mode 100644 index 0000000..82f2d7b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/descriptor/persistence.xml
@@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> + <persistence-unit name="pu1" transaction-type="JTA"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <jta-data-source>jdbc/__default</jta-data-source> + <non-jta-data-source>jdbc/__default</non-jta-data-source> + <class>myapp.Department</class> + <class>myapp.Employee</class> + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> + <property name="eclipselink.logging.level" value="INFO"/> + </properties> + </persistence-unit> +</persistence>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..29e137a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void m1(); + public void m2(); + + public String testDatasourceInjection(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/beans/artifacts/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/beans/artifacts/Preferred.java new file mode 100644 index 0000000..b7584c8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/beans/artifacts/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/beans/artifacts/TestDatabase.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/beans/artifacts/TestDatabase.java new file mode 100644 index 0000000..b69ab8e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/beans/artifacts/TestDatabase.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestDatabase { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/beans/nonmock/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/beans/nonmock/TestBean.java new file mode 100644 index 0000000..4fe1ded --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/beans/nonmock/TestBean.java
@@ -0,0 +1,52 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.persistence.EntityManagerFactory; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.TestDatabase; + + +@RequestScoped +@Preferred +public class TestBean implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Inject @TestDatabase + EntityManagerFactory emf; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + + @Override + public String testDatasourceInjection() { + return (emf==null ? "typesafe injection into testbean failed" : ""); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/entity/Department.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/entity/Department.java new file mode 100644 index 0000000..14191ec --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/entity/Department.java
@@ -0,0 +1,82 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "DEPARTMENT") +public class Department implements java.io.Serializable { + + // Instance variables + private int id; + private String name; + private Set<Employee> employees; + + public Department() { + } + + public Department(int id, String name) { + this.id = id; + this.name = name; + } + + // =========================================================== + // getters and setters for the state fields + + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "NAME") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + // =========================================================== + // getters and setters for the association fields + @OneToMany(cascade = CascadeType.ALL, mappedBy = "department") + public Set<Employee> getEmployees() { + return employees; + } + + public void setEmployees(Set<Employee> employees) { + this.employees = employees; + } + + public String toString() { + return "Department id=" + getId() + ", Department Name=" + getName(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/entity/Employee.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/entity/Employee.java new file mode 100644 index 0000000..a1820e8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/entity/Employee.java
@@ -0,0 +1,117 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Transient; + +@Entity +@Table(name = "EMPLOYEE") +public class Employee implements java.io.Serializable { + + private int id; + private String firstName; + private String lastName; + private Department department; + + public Employee() { + } + + public Employee(int id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public Employee(int id, String firstName, String lastName, + Department department) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + this.department = department; + } + + // =========================================================== + // getters and setters for the state fields + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "FIRSTNAME") + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + @Column(name = "LASTNAME") + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + // =========================================================== + // getters and setters for the association fields + // @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "DEPARTMENT_ID") + public Department getDepartment() { + return department; + } + + @Transient + public Department getDepartmentNoWeaving() { + try { + java.lang.reflect.Field f = Employee.class + .getDeclaredField("department"); + return (Department) f.get(this); + } catch (NoSuchFieldException e) { + throw new RuntimeException( + "Please change argument to getDeclaredField", e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public void setDepartment(Department department) { + this.department = department; + } + + public String toString() { + return "Employee id=" + getId() + ", firstName=" + getFirstName() + + ", lastName=" + getLastName() + ", department=" + + getDepartment(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/servlet/JPAResourceInjectionServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/servlet/JPAResourceInjectionServlet.java new file mode 100644 index 0000000..e00446b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/servlet/JPAResourceInjectionServlet.java
@@ -0,0 +1,94 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.transaction.UserTransaction; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.TestDatabase; +import test.util.JpaTest; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class JPAResourceInjectionServlet extends HttpServlet { + + @PersistenceUnit(unitName = "pu1") + private EntityManagerFactory emf; + + @Inject + @TestDatabase + private EntityManagerFactory emf1; + + private @Resource + UserTransaction utx; + + @Inject + @Preferred + TestBeanInterface tbi; + + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, + IOException { + PrintWriter writer = response.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + System.out.println("JPAResourceInjectionServlet::@PersistenceUnit " + + "CDI EntityManagerFactory=" + emf1); + + EntityManager em = emf1.createEntityManager(); + System.out.println("JPAResourceInjectionServlet::createEM" + + "EntityManager=" + em); + String testcase = request.getParameter("testcase"); + System.out.println("testcase=" + testcase); + + if (testcase != null) { + JpaTest jt = new JpaTest(em, utx); + boolean status = false; + if ("llinit".equals(testcase)) { + status = jt.lazyLoadingInit(); + } else if ("llfind".equals(testcase)) { + status = jt.lazyLoadingByFind(1); + } else if ("llquery".equals(testcase)) { + status = jt.lazyLoadingByQuery("Carla"); + } else if ("llinj".equals(testcase)){ + status = ((tbi != null) && + (tbi.testDatasourceInjection().trim().length()==0)); + } + if (status) { + msg += "";// pass + } else { + msg += (testcase + ":fail"); + } + } + + writer.write(msg + "\n"); + + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/util/JPAResourceProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/util/JPAResourceProducer.java new file mode 100644 index 0000000..cf38fab --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/util/JPAResourceProducer.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.enterprise.inject.Produces; +import javax.inject.Singleton; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; + +import test.beans.artifacts.TestDatabase; + +@Singleton +public class JPAResourceProducer { + @Produces @PersistenceUnit(unitName="pu1") + @TestDatabase + EntityManagerFactory customerDatabasePersistenceUnit; + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/util/JpaTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/util/JpaTest.java new file mode 100644 index 0000000..3d47448 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection/servlet/test/util/JpaTest.java
@@ -0,0 +1,170 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Query; +import javax.transaction.UserTransaction; + +import test.entity.Department; +import test.entity.Employee; + +public class JpaTest { + + private EntityManager em; + private UserTransaction utx; + + private static Department deptRef[] = new Department[2]; + private static Employee empRef[] = new Employee[5]; + + public JpaTest() { + } + + public JpaTest(EntityManager em, UserTransaction utx) { + this.em = em; + this.utx = utx; + } + + public boolean lazyLoadingInit() { + boolean status = false; + System.out.println("-----lazeLoadingInit()---------"); + try { + deptRef[0] = new Department(1, "Engineering"); + deptRef[1] = new Department(2, "Marketing"); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 2; i++) { + em.persist(deptRef[i]); + } + utx.commit(); + + empRef[0] = new Employee(1, "Alan", "Frechette", deptRef[0]); + empRef[1] = new Employee(2, "Arthur", "Wesley", deptRef[0]); + empRef[2] = new Employee(3, "Abe", "White", deptRef[0]); + empRef[3] = new Employee(4, "Paul", "Hinz", deptRef[1]); + empRef[4] = new Employee(5, "Carla", "Calrson", deptRef[1]); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 5; i++) { + em.persist(empRef[i]); + } + utx.commit(); + status = true; + } catch (Exception ex) { + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByFind(int employeeID) { + + boolean status = true; + System.out.println("------------lazyLoadingAfterFind -----------"); + System.out.println("employeeID = " + employeeID); + Employee emp = em.find(Employee.class, employeeID); + + System.out.println("found: emp.id=" + emp.getId()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByQuery(String fName) { + + boolean status = true; + System.out.println("------------lazyLoadingByQuery -----------"); + System.out.println("fName = " + fName); + Query query = em.createQuery( + "SELECT e FROM Employee e WHERE e.firstName like :firstName") + .setParameter("firstName", fName); + ; + Employee emp = (Employee) query.getSingleResult(); + + System.out.println("queried: emp.firstName=" + emp.getFirstName()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/README new file mode 100644 index 0000000..098e4ae --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/README
@@ -0,0 +1,5 @@ +Test +- Injection of a no-interface bean in a request-scoped model via @Inject +and @EJB and invocation of methods defined in the EJB class and +in a super-class of the EJB +- glassfish issue 13040
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/build.properties new file mode 100644 index 0000000..5b8ba11 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-no-interface-ejb"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/build.xml new file mode 100644 index 0000000..a0e6a9d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy" /> + + <target name="clean" depends="init-common"> + <antcall target="clean-common" /> + <delete> + <fileset dir="." includes="*.class" /> + <fileset dir="client/test/client" includes="*.class" /> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet" /> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes" /> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes" /> + <param name="webclient.war.classes" value="**/*.class" /> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" includes="test/client/WebTest.java" /> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common" /> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}" /> + <arg value="${http.port}" /> + <arg value="${contextroot}" /> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar" /> + <pathelement location="client" /> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common" /> + </target> + + <target name="usage"> + <antcall target="usage-common" /> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/client/test/client/WebTest.java new file mode 100644 index 0000000..e775694 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/client/test/client/WebTest.java
@@ -0,0 +1,111 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "injection-of-no-interface-bean-view-and-EJB-with-local-view"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for Java EE resource injection"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/descriptor/persistence.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/descriptor/persistence.xml new file mode 100644 index 0000000..82f2d7b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/descriptor/persistence.xml
@@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> + <persistence-unit name="pu1" transaction-type="JTA"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <jta-data-source>jdbc/__default</jta-data-source> + <non-jta-data-source>jdbc/__default</non-jta-data-source> + <class>myapp.Department</class> + <class>myapp.Employee</class> + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> + <property name="eclipselink.logging.level" value="INFO"/> + </properties> + </persistence-unit> +</persistence>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..cf49083 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public String runTests(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/artifacts/InjectViaAtEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/artifacts/InjectViaAtEJB.java new file mode 100644 index 0000000..594448d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/artifacts/InjectViaAtEJB.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface InjectViaAtEJB { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/artifacts/InjectViaAtInject.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/artifacts/InjectViaAtInject.java new file mode 100644 index 0000000..8e11c88 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/artifacts/InjectViaAtInject.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface InjectViaAtInject { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/artifacts/LocalEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/artifacts/LocalEJB.java new file mode 100644 index 0000000..04bb97c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/artifacts/LocalEJB.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface LocalEJB { +} +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/artifacts/NoInterfaceBeanView.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/artifacts/NoInterfaceBeanView.java new file mode 100644 index 0000000..6e95330 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/artifacts/NoInterfaceBeanView.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface NoInterfaceBeanView { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/local/TestBeanSuper.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/local/TestBeanSuper.java new file mode 100644 index 0000000..a95c06e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/local/TestBeanSuper.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock.local; + +import test.beans.TestBeanInterface; +import test.ejb.local.TestInterface; +import test.ejb.local.TestLocalEJB; + +abstract class TestBeanSuper implements TestBeanInterface { + + abstract TestInterface getTestEJB(); + + @Override + public String runTests() { + String s = ""; + if (!getTestEJB().m1DefinedInInterface()) + s += "Cannot call method defined in the local EJB's interface"; + return s; + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/local/TestEJBInjectionViaAtEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/local/TestEJBInjectionViaAtEJB.java new file mode 100644 index 0000000..edadb04 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/local/TestEJBInjectionViaAtEJB.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock.local; + +import javax.ejb.EJB; +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +import test.beans.artifacts.InjectViaAtEJB; +import test.beans.artifacts.LocalEJB; +import test.ejb.local.TestInterface; + + + +@RequestScoped +@InjectViaAtEJB +@LocalEJB + +public class TestEJBInjectionViaAtEJB extends TestBeanSuper{ + @EJB TestInterface tnie; + + @Override + TestInterface getTestEJB() { + return tnie; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/local/TestEJBInjectionViaInject.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/local/TestEJBInjectionViaInject.java new file mode 100644 index 0000000..c4dec72 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/local/TestEJBInjectionViaInject.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock.local; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.inject.Named; + +import test.beans.artifacts.InjectViaAtInject; +import test.beans.artifacts.LocalEJB; +import test.ejb.local.TestInterface; + + +@RequestScoped +@InjectViaAtInject +@LocalEJB + +public class TestEJBInjectionViaInject extends TestBeanSuper { + @Inject TestInterface tnie; + + @Override + TestInterface getTestEJB() { + return tnie; + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/nointerfacebeanview/TestBeanSuper.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/nointerfacebeanview/TestBeanSuper.java new file mode 100644 index 0000000..5a38f90 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/nointerfacebeanview/TestBeanSuper.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock.nointerfacebeanview; + +import test.beans.TestBeanInterface; +import test.ejb.nointerfacebeanview.TestNoInterfaceEJB; + +abstract class TestBeanSuper implements TestBeanInterface { + + abstract TestNoInterfaceEJB getTestEJB(); + + @Override + public String runTests() { + String s = ""; + if (!getTestEJB().m2DefinedInSuperClass()) + s += "Cannot call method defined in super class"; + if (!getTestEJB().m3DefinedInEJB()) + s += "Cannot call method defined in EJB"; + return s; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/nointerfacebeanview/TestEJBInjectionViaAtEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/nointerfacebeanview/TestEJBInjectionViaAtEJB.java new file mode 100644 index 0000000..a6eaacd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/nointerfacebeanview/TestEJBInjectionViaAtEJB.java
@@ -0,0 +1,43 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock.nointerfacebeanview; + +import javax.ejb.EJB; +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +import test.beans.artifacts.InjectViaAtEJB; +import test.beans.artifacts.NoInterfaceBeanView; +import test.ejb.nointerfacebeanview.TestNoInterfaceEJB; + + +@RequestScoped +@InjectViaAtEJB +@NoInterfaceBeanView + +public class TestEJBInjectionViaAtEJB extends TestBeanSuper{ + @EJB TestNoInterfaceEJB tnie; + + public TestEJBInjectionViaAtEJB() { + new Throwable().printStackTrace(); + } + @Override + TestNoInterfaceEJB getTestEJB() { + return tnie; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/nointerfacebeanview/TestEJBInjectionViaInject.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/nointerfacebeanview/TestEJBInjectionViaInject.java new file mode 100644 index 0000000..62b1b11 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/beans/nonmock/nointerfacebeanview/TestEJBInjectionViaInject.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock.nointerfacebeanview; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.inject.Named; + +import test.beans.artifacts.InjectViaAtInject; +import test.beans.artifacts.NoInterfaceBeanView; +import test.ejb.nointerfacebeanview.TestNoInterfaceEJB; + + +@RequestScoped +@InjectViaAtInject +@NoInterfaceBeanView + +public class TestEJBInjectionViaInject extends TestBeanSuper { + @Inject TestNoInterfaceEJB tnie; + + @Override + TestNoInterfaceEJB getTestEJB() { + return tnie; + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/local/TestInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/local/TestInterface.java new file mode 100644 index 0000000..fefb9ad --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/local/TestInterface.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.local; + +public interface TestInterface { + public boolean m1DefinedInInterface(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/local/TestLocalEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/local/TestLocalEJB.java new file mode 100644 index 0000000..18054b1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/local/TestLocalEJB.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.local; + +import javax.ejb.Local; +import javax.ejb.Stateless; + +@Stateless +@Local(TestInterface.class) +public class TestLocalEJB extends TestSuperClass implements TestInterface { + public boolean m3DefinedInEJB(){ + System.out.println("local ejb: m3"); + return true; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/local/TestSuperClass.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/local/TestSuperClass.java new file mode 100644 index 0000000..53ad721 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/local/TestSuperClass.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.local; + +import javax.enterprise.inject.Alternative; + + +//marked as Alternative, otherwise there would +//an ambiguous definition for TestLocalInterface between this +//super class and the TestLocalEJB +public @Alternative class TestSuperClass implements TestInterface{ + + @Override + public boolean m1DefinedInInterface() { + System.out.println("local bean: m1"); + return true; + } + + public boolean m2DefinedInSuperClass(){ + System.out.println("local: m2"); + return true; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/nointerfacebeanview/TestInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/nointerfacebeanview/TestInterface.java new file mode 100644 index 0000000..dcb7186 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/nointerfacebeanview/TestInterface.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.nointerfacebeanview; + +public interface TestInterface { + public boolean m1DefinedInInterface(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/nointerfacebeanview/TestNoInterfaceEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/nointerfacebeanview/TestNoInterfaceEJB.java new file mode 100644 index 0000000..ec60e4d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/nointerfacebeanview/TestNoInterfaceEJB.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.nointerfacebeanview; + +import javax.ejb.Stateless; + + +@Stateless +public class TestNoInterfaceEJB { + public boolean m1DefinedInInterface() { + System.out.println("no interface bean: m1"); + return true; + } + + public boolean m2DefinedInSuperClass(){ + System.out.println("no interface bean: m2"); + return true; + } + public boolean m3DefinedInEJB() { + System.out.println("no interface ejb: m3"); + return true; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/nointerfacebeanview/TestSuperClass.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/nointerfacebeanview/TestSuperClass.java new file mode 100644 index 0000000..b4fbe8e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/ejb/nointerfacebeanview/TestSuperClass.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.nointerfacebeanview; + +import javax.enterprise.inject.Alternative; + + +public class TestSuperClass implements TestInterface{ + + @Override + public boolean m1DefinedInInterface() { + System.out.println("no interface bean: m1"); + return true; + } + + public boolean m2DefinedInSuperClass(){ + System.out.println("no interface bean: m2"); + return true; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/servlet/FooBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/servlet/FooBean.java new file mode 100644 index 0000000..1e102af --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/servlet/FooBean.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import javax.inject.Inject; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.InjectViaAtEJB; +import test.beans.artifacts.NoInterfaceBeanView; + +public class FooBean { + + @Inject + @InjectViaAtEJB + @NoInterfaceBeanView + TestBeanInterface testBeanEJB; + + public TestBeanInterface getBean(){ + return testBeanEJB; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/servlet/NoInterfaceEJBTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/servlet/NoInterfaceEJBTestServlet.java new file mode 100644 index 0000000..d878ef3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/no-interface-ejb/servlet/test/servlet/NoInterfaceEJBTestServlet.java
@@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.InjectViaAtEJB; +import test.beans.artifacts.InjectViaAtInject; +import test.beans.artifacts.LocalEJB; +import test.beans.artifacts.NoInterfaceBeanView; +import test.ejb.nointerfacebeanview.TestInterface; +import test.ejb.nointerfacebeanview.TestSuperClass; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class NoInterfaceEJBTestServlet extends HttpServlet { + +// @Inject +// @InjectViaAtInject +// @NoInterfaceBeanView +// TestBeanInterface testBeanInject; + + + @Inject + FooBean fb; +// @Inject +// @InjectViaAtInject +// @LocalEJB +// TestBeanInterface testLocalBeanInject; + +// @Inject +// @InjectViaAtEJB +// @LocalEJB +// TestBeanInterface testLocalBeanEJB; + + @Inject + TestInterface ti; + + @Inject + TestSuperClass ti1; + + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, + IOException { + PrintWriter writer = response.getWriter(); + writer.write("Hello from Servlet 3.0."); + + String msg = ""; + //test EJB injection via @EJB + String m = fb.getBean().runTests(); + if (!m.equals("")) + msg += "Invocation on no-interface EJB -- obtained through @EJB -- failed. Failed tests" + m; + + //test EJB injection via @Inject +// m = testBeanInject.runTests(); +// if (!m.equals("")) +// msg += "Invocation on no-interface EJB -- obtained through @Inject -- failed. Failed tests" + m; + + //test No-Interface EJB injection via @Inject of an interface the + //no-interface bean is implementing + if (ti != null && !(ti.m1DefinedInInterface())) + msg += "Invocation on no-interface EJB -- obtained through @Inject -- (method defined in super interface) failed"; + + //test No-Interface EJB injection via @Inject of an interface the + //no-interface bean is implementing + if (ti1 != null && !(ti1.m2DefinedInSuperClass())) + msg += "Invocation on no-interface EJB -- obtained through @Inject -- (method defined in super class) failed"; + + //test local EJB injection via @EJB +// m = testLocalBeanEJB.runTests(); +// if (!m.equals("")) +// msg += "Invocation on local EJB -- obtained through @EJB -- failed. Failed tests" + m; + + //test EJB injection via @Inject +// m = testLocalBeanInject.runTests(); +// if (!m.equals("")) +// msg += "Invocation on local EJB -- obtained through @Inject -- failed. Failed tests" + m; + + writer.write(msg + "\n"); + + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/README new file mode 100644 index 0000000..431262e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/README
@@ -0,0 +1,3 @@ +Test +- glassfish issue 11607 +- test to reproduce injection of SLSB into a session scoped bean
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/build.properties new file mode 100644 index 0000000..5b8ba11 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-no-interface-ejb"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/build.xml new file mode 100644 index 0000000..a0e6a9d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy" /> + + <target name="clean" depends="init-common"> + <antcall target="clean-common" /> + <delete> + <fileset dir="." includes="*.class" /> + <fileset dir="client/test/client" includes="*.class" /> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet" /> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes" /> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes" /> + <param name="webclient.war.classes" value="**/*.class" /> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" includes="test/client/WebTest.java" /> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common" /> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}" /> + <arg value="${http.port}" /> + <arg value="${contextroot}" /> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar" /> + <pathelement location="client" /> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common" /> + </target> + + <target name="usage"> + <antcall target="usage-common" /> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/client/test/client/WebTest.java new file mode 100644 index 0000000..05b4076 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/client/test/client/WebTest.java
@@ -0,0 +1,111 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "slsb-injection-into-sessionscopedbean"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for Java EE resource injection"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/descriptor/persistence.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/descriptor/persistence.xml new file mode 100644 index 0000000..82f2d7b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/descriptor/persistence.xml
@@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> + <persistence-unit name="pu1" transaction-type="JTA"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <jta-data-source>jdbc/__default</jta-data-source> + <non-jta-data-source>jdbc/__default</non-jta-data-source> + <class>myapp.Department</class> + <class>myapp.Employee</class> + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> + <property name="eclipselink.logging.level" value="INFO"/> + </properties> + </persistence-unit> +</persistence>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..cf49083 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public String runTests(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/TestSessionScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/TestSessionScopedBean.java new file mode 100644 index 0000000..a9fc170 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/TestSessionScopedBean.java
@@ -0,0 +1,42 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.io.Serializable; +import javax.enterprise.context.SessionScoped; +import javax.inject.Inject; +import javax.inject.Named; + +import test.ejb.slsb.TestSLSB; + +@Named +@SessionScoped +public class TestSessionScopedBean implements Serializable{ + + @Inject + TestSLSB statelessSessionBean; + + public TestSessionScopedBean() { + } + + public boolean testSLSBAccess(){ + if (statelessSessionBean != null) + return statelessSessionBean.statelessMethod1(); + else return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/artifacts/InjectViaAtEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/artifacts/InjectViaAtEJB.java new file mode 100644 index 0000000..594448d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/artifacts/InjectViaAtEJB.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface InjectViaAtEJB { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/artifacts/InjectViaAtInject.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/artifacts/InjectViaAtInject.java new file mode 100644 index 0000000..8e11c88 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/artifacts/InjectViaAtInject.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface InjectViaAtInject { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/artifacts/LocalEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/artifacts/LocalEJB.java new file mode 100644 index 0000000..04bb97c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/artifacts/LocalEJB.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface LocalEJB { +} +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/artifacts/NoInterfaceBeanView.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/artifacts/NoInterfaceBeanView.java new file mode 100644 index 0000000..6e95330 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/artifacts/NoInterfaceBeanView.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface NoInterfaceBeanView { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/local/TestBeanSuper.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/local/TestBeanSuper.java new file mode 100644 index 0000000..a95c06e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/local/TestBeanSuper.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock.local; + +import test.beans.TestBeanInterface; +import test.ejb.local.TestInterface; +import test.ejb.local.TestLocalEJB; + +abstract class TestBeanSuper implements TestBeanInterface { + + abstract TestInterface getTestEJB(); + + @Override + public String runTests() { + String s = ""; + if (!getTestEJB().m1DefinedInInterface()) + s += "Cannot call method defined in the local EJB's interface"; + return s; + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/local/TestEJBInjectionViaAtEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/local/TestEJBInjectionViaAtEJB.java new file mode 100644 index 0000000..edadb04 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/local/TestEJBInjectionViaAtEJB.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock.local; + +import javax.ejb.EJB; +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +import test.beans.artifacts.InjectViaAtEJB; +import test.beans.artifacts.LocalEJB; +import test.ejb.local.TestInterface; + + + +@RequestScoped +@InjectViaAtEJB +@LocalEJB + +public class TestEJBInjectionViaAtEJB extends TestBeanSuper{ + @EJB TestInterface tnie; + + @Override + TestInterface getTestEJB() { + return tnie; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/local/TestEJBInjectionViaInject.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/local/TestEJBInjectionViaInject.java new file mode 100644 index 0000000..c4dec72 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/local/TestEJBInjectionViaInject.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock.local; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.inject.Named; + +import test.beans.artifacts.InjectViaAtInject; +import test.beans.artifacts.LocalEJB; +import test.ejb.local.TestInterface; + + +@RequestScoped +@InjectViaAtInject +@LocalEJB + +public class TestEJBInjectionViaInject extends TestBeanSuper { + @Inject TestInterface tnie; + + @Override + TestInterface getTestEJB() { + return tnie; + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/nointerfacebeanview/TestBeanSuper.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/nointerfacebeanview/TestBeanSuper.java new file mode 100644 index 0000000..5a38f90 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/nointerfacebeanview/TestBeanSuper.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock.nointerfacebeanview; + +import test.beans.TestBeanInterface; +import test.ejb.nointerfacebeanview.TestNoInterfaceEJB; + +abstract class TestBeanSuper implements TestBeanInterface { + + abstract TestNoInterfaceEJB getTestEJB(); + + @Override + public String runTests() { + String s = ""; + if (!getTestEJB().m2DefinedInSuperClass()) + s += "Cannot call method defined in super class"; + if (!getTestEJB().m3DefinedInEJB()) + s += "Cannot call method defined in EJB"; + return s; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/nointerfacebeanview/TestEJBInjectionViaAtEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/nointerfacebeanview/TestEJBInjectionViaAtEJB.java new file mode 100644 index 0000000..ccd055e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/nointerfacebeanview/TestEJBInjectionViaAtEJB.java
@@ -0,0 +1,40 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock.nointerfacebeanview; + +import javax.ejb.EJB; +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +import test.beans.artifacts.InjectViaAtEJB; +import test.beans.artifacts.NoInterfaceBeanView; +import test.ejb.nointerfacebeanview.TestNoInterfaceEJB; + + +@RequestScoped +@InjectViaAtEJB +@NoInterfaceBeanView + +public class TestEJBInjectionViaAtEJB extends TestBeanSuper{ + @EJB TestNoInterfaceEJB tnie; + + @Override + TestNoInterfaceEJB getTestEJB() { + return tnie; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/nointerfacebeanview/TestEJBInjectionViaInject.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/nointerfacebeanview/TestEJBInjectionViaInject.java new file mode 100644 index 0000000..62b1b11 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/beans/nonmock/nointerfacebeanview/TestEJBInjectionViaInject.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock.nointerfacebeanview; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.inject.Named; + +import test.beans.artifacts.InjectViaAtInject; +import test.beans.artifacts.NoInterfaceBeanView; +import test.ejb.nointerfacebeanview.TestNoInterfaceEJB; + + +@RequestScoped +@InjectViaAtInject +@NoInterfaceBeanView + +public class TestEJBInjectionViaInject extends TestBeanSuper { + @Inject TestNoInterfaceEJB tnie; + + @Override + TestNoInterfaceEJB getTestEJB() { + return tnie; + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/local/TestInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/local/TestInterface.java new file mode 100644 index 0000000..fefb9ad --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/local/TestInterface.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.local; + +public interface TestInterface { + public boolean m1DefinedInInterface(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/local/TestLocalEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/local/TestLocalEJB.java new file mode 100644 index 0000000..ce06ab6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/local/TestLocalEJB.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.local; + +import javax.ejb.Local; +import javax.ejb.Stateless; + +@Stateless +@Local(TestInterface.class) +public class TestLocalEJB extends TestSuperClass{ + public boolean m3DefinedInEJB(){ + System.out.println("local ejb: m3"); + return true; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/local/TestSuperClass.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/local/TestSuperClass.java new file mode 100644 index 0000000..53ad721 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/local/TestSuperClass.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.local; + +import javax.enterprise.inject.Alternative; + + +//marked as Alternative, otherwise there would +//an ambiguous definition for TestLocalInterface between this +//super class and the TestLocalEJB +public @Alternative class TestSuperClass implements TestInterface{ + + @Override + public boolean m1DefinedInInterface() { + System.out.println("local bean: m1"); + return true; + } + + public boolean m2DefinedInSuperClass(){ + System.out.println("local: m2"); + return true; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/nointerfacebeanview/TestInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/nointerfacebeanview/TestInterface.java new file mode 100644 index 0000000..dcb7186 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/nointerfacebeanview/TestInterface.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.nointerfacebeanview; + +public interface TestInterface { + public boolean m1DefinedInInterface(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/nointerfacebeanview/TestNoInterfaceEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/nointerfacebeanview/TestNoInterfaceEJB.java new file mode 100644 index 0000000..64ebd63 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/nointerfacebeanview/TestNoInterfaceEJB.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.nointerfacebeanview; + +import javax.ejb.Stateless; + + +@Stateless +public class TestNoInterfaceEJB { + public boolean m1DefinedInInterface() { + System.out.println("no interface bean: m1"); + return true; + } + + public boolean m2DefinedInSuperClass(){ + System.out.println("no interface bean: m2"); + return true; + } + public boolean m3DefinedInEJB() { + System.out.println("no interface ejb: m3"); + return true; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/nointerfacebeanview/TestSuperClass.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/nointerfacebeanview/TestSuperClass.java new file mode 100644 index 0000000..ef5e220 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/nointerfacebeanview/TestSuperClass.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.nointerfacebeanview; + +import javax.enterprise.inject.Alternative; + + +//marked as Alternative, otherwise there would +//an ambiguous definition for TestLocalInterface between this +//super class and the TestLocalEJB +public class TestSuperClass implements TestInterface{ + + @Override + public boolean m1DefinedInInterface() { + System.out.println("no interface bean: m1"); + return true; + } + + public boolean m2DefinedInSuperClass(){ + System.out.println("no interface bean: m2"); + return true; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/slsb/TestSLSB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/slsb/TestSLSB.java new file mode 100644 index 0000000..96b85d8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/ejb/slsb/TestSLSB.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.slsb; +import javax.ejb.Stateless; +import javax.enterprise.context.Dependent; +import javax.inject.Named; + +@Named +@Stateless +@Dependent +public class TestSLSB { + + public TestSLSB() { + } + + public boolean statelessMethod1(){ + return true; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/servlet/SLSBInjectionIntoSessionScopedBeanTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/servlet/SLSBInjectionIntoSessionScopedBeanTestServlet.java new file mode 100644 index 0000000..c5f0232 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-component-resources/slsb-injection-into-sessionscoped/servlet/test/servlet/SLSBInjectionIntoSessionScopedBeanTestServlet.java
@@ -0,0 +1,113 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestBeanInterface; +import test.beans.TestSessionScopedBean; +import test.beans.artifacts.InjectViaAtEJB; +import test.beans.artifacts.InjectViaAtInject; +import test.beans.artifacts.LocalEJB; +import test.beans.artifacts.NoInterfaceBeanView; +import test.ejb.nointerfacebeanview.TestInterface; +import test.ejb.nointerfacebeanview.TestSuperClass; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class SLSBInjectionIntoSessionScopedBeanTestServlet extends HttpServlet { + + @Inject + @InjectViaAtInject + @NoInterfaceBeanView + TestBeanInterface testBeanInject; + + @Inject + @InjectViaAtEJB + @NoInterfaceBeanView + TestBeanInterface testBeanEJB; + + @Inject + @InjectViaAtInject + @LocalEJB + TestBeanInterface testLocalBeanInject; + + @Inject + @InjectViaAtEJB + @LocalEJB + TestBeanInterface testLocalBeanEJB; + + @Inject + TestInterface ti; + + @Inject + TestSuperClass ti1; + + @Inject + TestSessionScopedBean tssb; + + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, + IOException { + PrintWriter writer = response.getWriter(); + writer.write("Hello from Servlet 3.0."); + + String msg = ""; + //test EJB injection via @EJB + String m = testBeanEJB.runTests(); + if (!m.equals("")) + msg += "Invocation on no-interface EJB -- obtained through @EJB -- failed. Failed tests" + m; + + //test EJB injection via @Inject + m = testBeanInject.runTests(); + if (!m.equals("")) + msg += "Invocation on no-interface EJB -- obtained through @Inject -- failed. Failed tests" + m; + + //test No-Interface EJB injection via @Inject of an interface the + //no-interface bean is implementing + if (ti != null && !(ti.m1DefinedInInterface())) + msg += "Invocation on no-interface EJB -- obtained through @Inject -- (method defined in super interface) failed"; + + //test No-Interface EJB injection via @Inject of an interface the + //no-interface bean is implementing + if (ti1 != null && !(ti1.m2DefinedInSuperClass())) + msg += "Invocation on no-interface EJB -- obtained through @Inject -- (method defined in super class) failed"; + + //test local EJB injection via @EJB + m = testLocalBeanEJB.runTests(); + if (!m.equals("")) + msg += "Invocation on local EJB -- obtained through @EJB -- failed. Failed tests" + m; + + //test EJB injection via @Inject + m = testLocalBeanInject.runTests(); + if (!m.equals("")) + msg += "Invocation on local EJB -- obtained through @Inject -- failed. Failed tests" + m; + + if (!tssb.testSLSBAccess()) + msg += "Stateless Session Bean into session scoped bean failed"; + + writer.write(msg + "\n"); + + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/README new file mode 100644 index 0000000..6c8ebfb --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/README
@@ -0,0 +1,7 @@ +- A test to check if ManagedBean, CDI Dependent Bean and a common POJO in a library jar is available for EJBs of an EAR. +[issue GLASSFISH-11888] +- Structure +EAR: + - EJB.jar (EJB impl) + - WAR (uses EJB api to access EJB) + - lib-dir (set as library-directory through application.xml and has EJB API and lib Beans) \ No newline at end of file
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/build.properties new file mode 100644 index 0000000..bc15b60 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/build.properties
@@ -0,0 +1,29 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="bean-in-lib-dir-used-by-ejb-in-ear"/> +<property name="appname" value="${module}"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="se.client" value="com.acme.Client"/> +<property name="app.type" value="application"/> +<property name="sun-application.xml" value="descriptor/sun-application.xml"/> +<property name="application.xml" value="descriptor/application.xml"/> +<property name="persistence.xml" value="descriptor/persistence.xml"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="contextroot" value="${module}"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/build.xml new file mode 100644 index 0000000..bef55c1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/build.xml
@@ -0,0 +1,131 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="cdi-full-ear-App" default="usage" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + + <target name="all" depends="clean,build,deploy,run,undeploy" /> + + <target name="clean" depends="init-common"> + <antcall target="clean-common" /> + </target> + + <target name="compile" depends="clean"> + <!-- compile library --> + <antcall target="compile-common"> + <param name="src" value="lib" /> + </antcall> + + + <antcall target="compile-common"> + <param name="src" value="ejb" /> + </antcall> + + + <antcall target="compile-common"> + <param name="src" value="war" /> + </antcall> + + + <javac classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/lib/gf-client.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar" srcdir="client" destdir="${build.classes.dir}" debug="on" failonerror="true"> + <compilerarg line="-endorseddirs ${env.S1AS_HOME}/modules/endorsed" /> + </javac> + </target> + + <target name="build" depends="compile"> + <mkdir dir="${assemble.dir}" /> + + <!-- build library jar --> + <mkdir dir="${build.classes.dir}/META-INF" /> + <copy file="${persistence.xml}" tofile="${build.classes.dir}/META-INF/persistence.xml" failonerror="false" /> + <copy file="${beans.xml}" tofile="${build.classes.dir}/META-INF/beans.xml" failonerror="false" /> + <mkdir dir="${build.classes.dir}/lib-dir" /> + <jar jarfile="${build.classes.dir}/lib-dir/lib.jar" basedir="${build.classes.dir}" includes="com/acme/util/*.class, com/acme/ejb/api/*.class"> + <metainf dir="${build.classes.dir}/META-INF"> + <include name="persistence.xml" /> + <include name="beans.xml" /> + </metainf> + </jar> + <copy file="${env.APS_HOME}/lib/reporter.jar" todir="${build.classes.dir}/lib-dir" /> + + <!-- build EJB jar --> + <antcall target="ejb-jar-common"> + <param name="ejbjar.classes" value="com/acme/ejb/impl/*.class" /> + </antcall> + + <!-- delete EJB impl and lib classes as WAR should not have them --> + <delete includeEmptyDirs="true"> + <fileset dir="${build.classes.dir}/com/acme/ejb/" /> + <fileset dir="${build.classes.dir}/com/acme/util/" /> + </delete> + + <!-- create WAR --> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="true" /> + </antcall> + + <!-- assemble EAR --> + <delete file="${assemble.dir}/${appname}.ear" /> + <mkdir dir="${assemble.dir}" /> + <mkdir dir="${build.classes.dir}/META-INF" /> + <copy file="${sun-application.xml}" tofile="${build.classes.dir}/META-INF/sun-application.xml" failonerror="false" /> + <copy file="${glassfish-resources-ear.xml}" tofile="${build.classes.dir}/META-INF/glassfish-resources.xml" failonerror="false" filtering="true" /> + <ear earfile="${assemble.dir}/${appname}App.ear" appxml="${application.xml}"> + <fileset dir="${assemble.dir}"> + <include name="*.jar" /> + <include name="*.war" /> + </fileset> + <fileset dir="${build.classes.dir}"> + <include name="META-INF/sun-application.xml" /> + <include name="META-INF/glassfish-resources.xml" /> + </fileset> + <fileset dir="${build.classes.dir}" includes="lib-dir/*" /> + </ear> + + </target> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-common" /> + </target> + + <target name="run" depends="init-common"> + <java fork="on" failonerror="true" classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/lib/gf-client.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar" classname="${se.client}"> + <arg line="${contextroot}" /> + <arg line="${http.host}" /> + <arg line="${http.port}" /> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-common" /> + </target> + + <target name="usage"> + <antcall target="usage-common" /> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/client/com/acme/Client.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/client/com/acme/Client.java new file mode 100644 index 0000000..c6bdce2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/client/com/acme/Client.java
@@ -0,0 +1,88 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import javax.annotation.Resource; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +public class Client { + + private static final String TEST_NAME = "bean-in-lib-dir-of-ear-used-by-ejb"; + + private static SimpleReporterAdapter stat = + new SimpleReporterAdapter("appserv-tests"); + + private static String appName; + private String host; + private String port; + + @Resource(lookup = "java:app/env/value1") + private static Integer appLevelViaLookup; + + public static void main(String args[]) { + appName = args[0]; + stat.addDescription(appName); + Client client = new Client(args); + client.doTest(); + stat.printSummary(appName + "ID"); + System.out.println("appLevelViaLookup = '" + appLevelViaLookup + "'"); + } + + public Client(String[] args) { + host = args[1]; + port = args[2]; + } + + public void doTest() { + try { + String url = "http://" + host + ":" + port + "/" + appName + + "/HelloServlet"; + System.out.println("invoking webclient servlet at " + url); + URL u = new URL(url); + HttpURLConnection c1 = (HttpURLConnection) u.openConnection(); + int code = c1.getResponseCode(); + InputStream is = c1.getInputStream(); + BufferedReader input = new BufferedReader(new InputStreamReader( + is)); + String line = null; + while ((line = input.readLine()) != null) { + System.out.println("<response>:" + line); + if (line.trim().length() > 0) { + stat.addStatus(TEST_NAME, stat.FAIL); + return; + } + } + if (code != 200) { + stat.addStatus(TEST_NAME, stat.FAIL); + return; + } + stat.addStatus(TEST_NAME, stat.PASS); + + } catch (Exception e) { + stat.addStatus(TEST_NAME, stat.FAIL); + e.printStackTrace(); + } + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/descriptor/application.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/descriptor/application.xml new file mode 100644 index 0000000..f604093 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/descriptor/application.xml
@@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="6" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"> + <display-name>bean-in-lib-dir-used-by-ejb-in-ear</display-name> + <module> + <ejb>bean-in-lib-dir-used-by-ejb-in-ear-ejb.jar</ejb> + </module> + <module> + <web> + <web-uri>bean-in-lib-dir-used-by-ejb-in-ear-web.war</web-uri> + <context-root>bean-in-lib-dir-used-by-ejb-in-ear</context-root> + </web> + </module> + <library-directory>lib-dir</library-directory> + <env-entry> + <env-entry-name>java:app/env/value1</env-entry-name> + <env-entry-type>java.lang.Integer</env-entry-type> + <env-entry-value>18338</env-entry-value> + </env-entry> + <env-entry> + <env-entry-name>java:app/env/myString</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + <env-entry-value>myString</env-entry-value> + </env-entry> +</application>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/descriptor/persistence.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/descriptor/persistence.xml new file mode 100644 index 0000000..82f2d7b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/descriptor/persistence.xml
@@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> + <persistence-unit name="pu1" transaction-type="JTA"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <jta-data-source>jdbc/__default</jta-data-source> + <non-jta-data-source>jdbc/__default</non-jta-data-source> + <class>myapp.Department</class> + <class>myapp.Employee</class> + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> + <property name="eclipselink.logging.level" value="INFO"/> + </properties> + </persistence-unit> +</persistence>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/ejb/com/acme/ejb/api/Hello.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/ejb/com/acme/ejb/api/Hello.java new file mode 100644 index 0000000..0151798 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/ejb/com/acme/ejb/api/Hello.java
@@ -0,0 +1,25 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.ejb.api; + +public interface Hello { + + public String hello(); + + public static final String ALL_OK_STRING = "All Iz Well!\n"; + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/ejb/com/acme/ejb/api/HelloRemote.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/ejb/com/acme/ejb/api/HelloRemote.java new file mode 100644 index 0000000..0993e59 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/ejb/com/acme/ejb/api/HelloRemote.java
@@ -0,0 +1,27 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.ejb.api; + +import javax.ejb.Remote; + +@Remote +public interface HelloRemote { + + public String hello(); + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/ejb/com/acme/ejb/impl/HelloSingleton.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/ejb/com/acme/ejb/impl/HelloSingleton.java new file mode 100644 index 0000000..a8518c1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/ejb/com/acme/ejb/impl/HelloSingleton.java
@@ -0,0 +1,102 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.ejb.impl; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.annotation.Resource; +import javax.ejb.DependsOn; +import javax.ejb.SessionContext; +import javax.ejb.Singleton; +import javax.ejb.Startup; +import javax.inject.Inject; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; + +import com.acme.ejb.api.Hello; +import com.acme.util.TestDatabase; +import com.acme.util.TestDependentBeanInLib; +import com.acme.util.TestManagedBean; +import com.acme.util.TestSessionScopedBeanInLib; +import com.acme.util.UtilInLibDir; + +@Singleton +@Startup +@DependsOn("Singleton4") +public class HelloSingleton implements Hello { + + @Resource + SessionContext sessionCtx; + + @PersistenceUnit(unitName = "pu1") + @TestDatabase + private EntityManagerFactory emf; + + @Inject + TestManagedBean tmb; + + @Inject + TestDependentBeanInLib tdbil; + + @Inject + TestSessionScopedBeanInLib tssil; + + + @PostConstruct + private void init() { + System.out.println("HelloSingleton::init()"); + + String appName; + String moduleName; + appName = (String) sessionCtx.lookup("java:app/AppName"); + moduleName = (String) sessionCtx.lookup("java:module/ModuleName"); + System.out.println("AppName = " + appName); + System.out.println("ModuleName = " + moduleName); + } + + public String hello() { + System.out.println("HelloSingleton::hello()"); + String res = testEMF(); + if (!res.equals("")) return res; + res = testInjectionOfBeansInLibDir(); + if (!res.equals("")) return res; + UtilInLibDir uilb = new UtilInLibDir(); + if (!(uilb.add(1, 2) == 3)) { + return "Can't use utility class in library directory"; + } + return ALL_OK_STRING; + } + + private String testInjectionOfBeansInLibDir() { + if (tmb == null) return "Injection of Managed Bean in lib into an EJB in that ear failed"; + if (tdbil == null) return "Injection of Dependent Bean in lib into an EJB in that ear failed"; + if (tssil == null) return "Injection of SessionScoped Bean in lib into an EJB in that ear failed"; + return ""; + } + + private String testEMF() { + if (emf == null) return "EMF injection failed, is null in Singleton EJB"; + if (emf.createEntityManager() == null) return "Usage of EMF failed in Singleton EJB"; + return ""; + } + + @PreDestroy + private void destroy() { + System.out.println("HelloSingleton::destroy()"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/ejb/com/acme/ejb/impl/Singleton4.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/ejb/com/acme/ejb/impl/Singleton4.java new file mode 100644 index 0000000..b3fd249 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/ejb/com/acme/ejb/impl/Singleton4.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.ejb.impl; + +import javax.ejb.*; +import javax.annotation.*; + + +@Singleton +public class Singleton4 { + + @PostConstruct + public void init() { + System.out.println("In SingletonBean4::init()"); + } + + @PreDestroy + public void destroy() { + System.out.println("In SingletonBean4::destroy()"); + } + + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/ResourcesProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/ResourcesProducer.java new file mode 100644 index 0000000..fdc079b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/ResourcesProducer.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.util; + +import javax.enterprise.inject.Produces; +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +@Singleton +public class ResourcesProducer { + @Produces + @PersistenceContext(unitName = "pu1") + @TestDatabase + EntityManager customerDatabasePersistenceUnit; + + @Inject + TestDependentBeanInLib foo; + + public boolean isInjectionSuccessful(){ + return (foo != null); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/TestDatabase.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/TestDatabase.java new file mode 100644 index 0000000..db9e318 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/TestDatabase.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.util; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target( { TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestDatabase { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/TestDependentBeanInLib.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/TestDependentBeanInLib.java new file mode 100644 index 0000000..9596b22 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/TestDependentBeanInLib.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.util; + + +public class TestDependentBeanInLib { + public TestDependentBeanInLib() { + super(); + } + + public String foo(){ + return "foo!"; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/TestManagedBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/TestManagedBean.java new file mode 100644 index 0000000..c650b91 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/TestManagedBean.java
@@ -0,0 +1,37 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.util; + +import javax.annotation.ManagedBean; +import javax.inject.Inject; + +@ManagedBean +public class TestManagedBean { + @Inject + private TestDependentBeanInLib tdb; + + @Inject + private TestSessionScopedBeanInLib tssil; + + public boolean isInjectionSuccessful(){ + System.out.println("TestManagedBean:isInjectionSuccessful"); + System.out.println("TestDependentBean:" + tdb); + System.out.println("TestSessionScopedBean:" + tssil); + return (tdb != null) && (tssil != null); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/TestSessionScopedBeanInLib.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/TestSessionScopedBeanInLib.java new file mode 100644 index 0000000..03f1071 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/TestSessionScopedBeanInLib.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.util; + +import java.io.Serializable; + +import javax.enterprise.context.SessionScoped; + +@SessionScoped +public class TestSessionScopedBeanInLib implements Serializable{ + public void m1(){ + System.out.println("TestSessionScopedBeanInLib:m1"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/UtilInLibDir.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/UtilInLibDir.java new file mode 100644 index 0000000..18e76ab --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/lib/com/acme/util/UtilInLibDir.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.util; + +public class UtilInLibDir { + + public int add(int i1, int i2) { + return i1+i2; + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/manifest.mf b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/manifest.mf
@@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/war/com/acme/servlet/HelloServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/war/com/acme/servlet/HelloServlet.java new file mode 100644 index 0000000..7f9875a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/bean-in-lib-dir-used-by-ejb-in-ear/war/com/acme/servlet/HelloServlet.java
@@ -0,0 +1,101 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme.servlet; + + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.ejb.EJB; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.acme.ejb.api.Hello; +import com.acme.util.TestDatabase; + +@WebServlet(urlPatterns = "/HelloServlet", loadOnStartup = 1) + +@SuppressWarnings("serial") +public class HelloServlet extends HttpServlet { + String msg = ""; + + @EJB(name = "java:module/m1", beanName = "HelloSingleton", beanInterface = Hello.class) + Hello h; + + @PersistenceUnit(unitName = "pu1") + @TestDatabase + private EntityManagerFactory emf; + +// @Inject +// private ResourcesProducer rp; +// +// @Inject +// private TestDependentBeanInLib fb; + +// @Inject +// private TestManagedBean tmb; + +// @Inject +// private TestSessionScopedBeanInLib tssil; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + System.out.println("In HelloServlet::doGet"); + resp.setContentType("text/html"); + PrintWriter out = resp.getWriter(); + + checkForNull(emf, "Injection of EMF failed in Servlet"); + //ensure EMF works! + emf.createEntityManager(); + + //call Singleton EJB + String response = h.hello(); + if(!response.equals(Hello.ALL_OK_STRING)) + msg += "Invocation of Hello Singeton EJB failed:msg=" + response; + +// if (!rp.isInjectionSuccessful()) +// msg += "Injection of a bean in lib directory into another " + +// "Bean in lib directory failed"; +// checkForNull(fb, "Injection of a bean that is placed in lib directory " + +// "into a Servlet that is placed in a WAR failed"); +// checkForNull(tmb, "Injection of a Managed bean that is placed in lib directory " + +// "into a Servlet that is placed in a WAR failed"); +// checkForNull(tssil, "Injection of a session scoped Bean placed in lib dir into a " + +// "into a servlet in that ear failed"); + +// if (!rp.isInjectionSuccessful()) +// msg += "Injection of a bean in lib directory into another Bean " + +// "in lib directory failed"; + +// if (!tmb.isInjectionSuccessful()) +// msg += "Injection of a Bean placed in lib dir into a " + +// "ManagedBean placed in lib dir failed"; + + out.println(msg); + } + + protected void checkForNull(Object o, String errorMessage){ + System.out.println("o=" + o); + if (o == null) msg += " " + errorMessage; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/build.xml new file mode 100644 index 0000000..08b090d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/build.xml
@@ -0,0 +1,112 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<project name="javaee-int-test" default="usage" basedir="."> + + <property name="javaee-int-target" value="all"/> + + <target name="run-test"> + <antcall target="javaee-int"> + <param name="javaee-int-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="javaee-int"> + <param name="javaee-int-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="javaee-int"> + <param name="javaee-int-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="javaee-int"> + <param name="javaee-int-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="javaee-int"> + <param name="javaee-int-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="javaee-int"> + <param name="javaee-int-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="javaee-int"> + <param name="javaee-int-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="javaee-int"> + <param name="javaee-int-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="javaee-int"> + <param name="javaee-int-target" value="run"/> + </antcall> + </target> + + <target name="javaee-int"> + <record name="javaee-int.output" action="start" /> + <ant dir="builtin-beans" target="${javaee-int-target}"/> + <ant dir="servlet-context-injection-cdi" target="${javaee-int-target}"/> +<!-- Test issue: ManagedBean need not have a no-arg constructor in CDI runtimes + <ant dir="simple-managed-bean-interceptor-noargconstructor-missing" target="${javaee-int-target}"/> +--> + <ant dir="simple-managed-bean-interceptor-nonnull-package" target="${javaee-int-target}"/> + <ant dir="no-interface-local-view-proxy-serializable" target="${javaee-int-target}"/> + <ant dir="normal-bean-injection-ear" target="${javaee-int-target}"/> + <ant dir="programmatic-lookup-ear" target="${javaee-int-target}"/> + <ant dir="bean-in-lib-dir-used-by-ejb-in-ear" target="${javaee-int-target}"/> + <ant dir="cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection" target="${javaee-int-target}"/> + <ant dir="cdi-servlet-3.0-annotation-with-web-inf-lib-ordering" target="${javaee-int-target}"/> + <ant dir="cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed" target="${javaee-int-target}"/> + <ant dir="cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative" target="${javaee-int-target}"/> + <ant dir="cdi-servlet-3.0-annotation-with-web-inf-lib" target="${javaee-int-target}"/> + <ant dir="embedded-resource-adapter-as-bean-archive" target="${javaee-int-target}"/> + + <record name="javaee-int.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant all (Executes all the javaee-int tests) + ant clean (cleans all the javaee-int tests) + ant build (builds all the javaee-int tests) + ant setup (sets up all resources for javaee-int tests) + ant deploy (deploys all the javaee-int apps) + ant run (Executes all the javaee-int tests) + ant undeploy (undeploys all the javaee-int apps) + ant unsetup (unsets all resources for javaee-int tests) + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/README new file mode 100644 index 0000000..5b536cb --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/README
@@ -0,0 +1,7 @@ +Test +- Java EE Integration + - container provides the following built-in beans with the qualifier @Default + - UserTransaction + - Principal + - ValidatorFactory + - Validator
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/build.properties new file mode 100644 index 0000000..3543e4c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-typesafe-javaee-resource-injection"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/build.xml new file mode 100644 index 0000000..295d086 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/build.xml
@@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,create-resources,deploy,run,undeploy,delete-resources" /> + + <target name="clean" depends="init-common"> + <antcall target="clean-common" /> + <delete> + <fileset dir="." includes="*.class" /> + <fileset dir="client/test/client" includes="*.class" /> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet" /> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes" /> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes" /> + <param name="webclient.war.classes" value="**/*.class" /> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" includes="test/client/WebTest.java" /> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common" /> + </target> + + <target name="create-resources" depends="init-common"> + <antcall target="create-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + <antcall target="create-jdbc-resource-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + </target> + + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}" /> + <arg value="${http.port}" /> + <arg value="${contextroot}" /> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar" /> + <pathelement location="client" /> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common" /> + </target> + + <target name="delete-resources" depends="init-common"> + <antcall target="delete-jdbc-resource-common"> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + + <antcall target="delete-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + </target> + + <target name="usage"> + <antcall target="usage-common" /> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/client/test/client/WebTest.java new file mode 100644 index 0000000..bce94d2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/client/test/client/WebTest.java
@@ -0,0 +1,111 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "javaee-integration-simple"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for Java EE Integration"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..29e137a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void m1(); + public void m2(); + + public String testDatasourceInjection(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/beans/artifacts/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/beans/artifacts/Preferred.java new file mode 100644 index 0000000..b7584c8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/beans/artifacts/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/beans/artifacts/TestDatabase.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/beans/artifacts/TestDatabase.java new file mode 100644 index 0000000..b69ab8e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/beans/artifacts/TestDatabase.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestDatabase { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/beans/nonmock/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/beans/nonmock/TestBean.java new file mode 100644 index 0000000..1947fac --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/beans/nonmock/TestBean.java
@@ -0,0 +1,52 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.sql.DataSource; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.TestDatabase; + + +@RequestScoped +@Preferred +public class TestBean implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Inject @TestDatabase + DataSource ds; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + + @Override + public String testDatasourceInjection() { + return (ds==null ? "typesafe injection into testbean failed" : ""); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/servlet/DatabaseManager.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/servlet/DatabaseManager.java new file mode 100644 index 0000000..0b4d0b3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/servlet/DatabaseManager.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import javax.annotation.Resource; +import javax.enterprise.inject.Produces; +import javax.sql.DataSource; + +import test.beans.artifacts.TestDatabase; + +public class DatabaseManager { + @Produces + @TestDatabase + @Resource(name = "jdbc/jdbc-dev-test-resource", + mappedName = "jdbc/jdbc-dev-test-resource") + DataSource ds; + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/servlet/SimpleJavaEEIntegrationTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/servlet/SimpleJavaEEIntegrationTestServlet.java new file mode 100644 index 0000000..9d1e2ea --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/builtin-beans/servlet/test/servlet/SimpleJavaEEIntegrationTestServlet.java
@@ -0,0 +1,91 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.security.Principal; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.sql.DataSource; +import javax.transaction.UserTransaction; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.TestDatabase; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class SimpleJavaEEIntegrationTestServlet extends HttpServlet { + @Inject @Preferred + TestBeanInterface tb; + + @Inject @TestDatabase + DataSource ds; + + // Inject the built-in beans + @Inject UserTransaction ut; + @Inject Principal principal; + @Inject Validator validator; + @Inject ValidatorFactory vf; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (ds == null) + msg += "typesafe Injection of datasource into a servlet failed"; + + if (tb == null) + msg += "Injection of request scoped bean failed"; + + if (tb.testDatasourceInjection().trim().length() != 0) + msg += tb.testDatasourceInjection(); + + System.out.println("UserTransaction: " + ut); + System.out.println("Principal: " + principal); + System.out.println("Default Validator: " + validator); + System.out.println("Default ValidatorFactory: " + vf); + if (ut == null) + msg += "UserTransaction not available for injection " + + "with the default qualifier in Servlet"; + + if (principal == null) + msg += "Caller Principal not available for injection " + + "with the default qualifier in Servlet"; + + if (validator == null) + msg += "Default Validator not available for injection " + + "with the default qualifier in Servlet"; + + if (vf == null) + msg += "ValidationFactory not available for injection " + + "with the default qualifier in Servlet"; + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/README new file mode 100644 index 0000000..f98070f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/README
@@ -0,0 +1,8 @@ +GLASSFISH-15791 +Ensure Extension in a bundled library in an archive, does not result in +issues with Alternatives enabled in that bundled library + +GLASSFISH-16279 +Ensure BM injected in sub BDA is not parent BDA's BM +Ensure alternatives enabled in sub BDA is not visible via BeanManager +in parent BDA
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/WebTest.java new file mode 100644 index 0000000..d1198c4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/WebTest.java
@@ -0,0 +1,110 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; + +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "cdi-servlet-annotation-with-web-inf-lib-extension-alternative"; + private static final String EXPECTED_RESPONSE = ""; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke("llinit"); + invoke("llquery"); + invoke("llfind"); + invoke("llinj"); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke(String testCase) throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl" + + "?testcase=" + testCase; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME + testCase, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + if (line.trim().length() != 0) { + System.out.println("line = " + line); + } + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME + testCase, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME + testCase, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/build.properties new file mode 100644 index 0000000..493d4a8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/build.properties
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-servlet-annotation-with-web-inf-lib-extension-alternative"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="persistence.xml" value="descriptor/persistence.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/build.xml new file mode 100644 index 0000000..e4dca16 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/build.xml
@@ -0,0 +1,124 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,create-resources,deploy,run,undeploy,delete-resources"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + <delete file="lib/bean-lib.jar"/> + </target> + + <target name="compile" depends="clean"> + <!-- create WEB-INF/lib/bean-lib.jar --> + <mkdir dir="${build.classes.dir}"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <javac srcdir="servlet" includes="TestBean.java" destdir="${build.classes.dir}" classpath="${s1astest.classpath}" debug="on" source="1.6"/> + <javac srcdir="util" destdir="${build.classes.dir}" classpath="${s1astest.classpath}" debug="on" source="1.6"/> + <copy file="descriptor/beans-alternative.xml" tofile="${build.classes.dir}/META-INF/beans.xml"/> + <mkdir dir="${build.classes.dir}/META-INF/services"/> + <copy file="services/javax.enterprise.inject.spi.Extension" tofile="${build.classes.dir}/META-INF/services/javax.enterprise.inject.spi.Extension"/> + <delete file="${build.classes.dir}/TestBean.class" /> <!-- This is included in the WAR below --> + + <jar destfile="lib/bean-lib.jar"> + <fileset dir="${build.classes.dir}"/> + </jar> + <delete dir="${build.classes.dir}"/> + + <!-- compile test servlet --> + <mkdir dir="${build.classes.dir}"/> + <echo message="common.xml: Compiling test source files" level="verbose"/> + <mkdir dir="servlet"/> + <javac srcdir="servlet" destdir="${build.classes.dir}" classpath="${s1astest.classpath}:lib/bean-lib.jar" debug="on" failonerror="true"/> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="create-resources" depends="init-common"> + <antcall target="create-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + <antcall target="create-jdbc-resource-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="delete-resources" depends="init-common"> + <antcall target="delete-jdbc-resource-common"> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + + <antcall target="delete-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/descriptor/beans-alternative.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/descriptor/beans-alternative.xml new file mode 100644 index 0000000..1b3ee25 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/descriptor/beans-alternative.xml
@@ -0,0 +1,26 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <alternatives> + <class>test.beans.wbinflib.TestAlternativeBeanInWebInfLib</class> + </alternatives> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/descriptor/persistence.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/descriptor/persistence.xml new file mode 100644 index 0000000..82f2d7b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/descriptor/persistence.xml
@@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> + <persistence-unit name="pu1" transaction-type="JTA"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <jta-data-source>jdbc/__default</jta-data-source> + <non-jta-data-source>jdbc/__default</non-jta-data-source> + <class>myapp.Department</class> + <class>myapp.Employee</class> + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> + <property name="eclipselink.logging.level" value="INFO"/> + </properties> + </persistence-unit> +</persistence>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/lib/slf4j-api-1.7.25.jar b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/lib/slf4j-api-1.7.25.jar new file mode 100644 index 0000000..0143c09 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/lib/slf4j-api-1.7.25.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/lib/slf4j-simple-1.7.25.jar b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/lib/slf4j-simple-1.7.25.jar new file mode 100644 index 0000000..a7260f3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/lib/slf4j-simple-1.7.25.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/services/javax.enterprise.inject.spi.Extension b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/services/javax.enterprise.inject.spi.Extension new file mode 100644 index 0000000..ac73a52 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/services/javax.enterprise.inject.spi.Extension
@@ -0,0 +1,2 @@ +test.beans.wbinflib.TestExtensionInWebInfLib +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..34ae7eb --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/beans/TestBean.java
@@ -0,0 +1,50 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.persistence.EntityManager; + +import test.beans.artifacts.Preferred; + + +@RequestScoped +@Preferred +public class TestBean implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Inject //@TestDatabase + EntityManager emf; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + + @Override + public String testDatasourceInjection() { + return (emf==null ? "typesafe injection into testbean failed" : ""); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..29e137a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void m1(); + public void m2(); + + public String testDatasourceInjection(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/beans/TestLoggerProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/beans/TestLoggerProducer.java new file mode 100644 index 0000000..5d6b389 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/beans/TestLoggerProducer.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; +import javax.enterprise.inject.Produces; + + +public class TestLoggerProducer { + @Produces + public org.jboss.logging.Logger getLogger(){ + org.jboss.logging.Logger l = org.jboss.logging.Logger.getLogger(TestLoggerProducer.class); + System.out.println("getLogger:: " + l); + return l; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/beans/artifacts/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/beans/artifacts/Preferred.java new file mode 100644 index 0000000..b7584c8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/beans/artifacts/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/beans/artifacts/TestDatabase.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/beans/artifacts/TestDatabase.java new file mode 100644 index 0000000..b69ab8e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/beans/artifacts/TestDatabase.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestDatabase { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/entity/Department.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/entity/Department.java new file mode 100644 index 0000000..14191ec --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/entity/Department.java
@@ -0,0 +1,82 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "DEPARTMENT") +public class Department implements java.io.Serializable { + + // Instance variables + private int id; + private String name; + private Set<Employee> employees; + + public Department() { + } + + public Department(int id, String name) { + this.id = id; + this.name = name; + } + + // =========================================================== + // getters and setters for the state fields + + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "NAME") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + // =========================================================== + // getters and setters for the association fields + @OneToMany(cascade = CascadeType.ALL, mappedBy = "department") + public Set<Employee> getEmployees() { + return employees; + } + + public void setEmployees(Set<Employee> employees) { + this.employees = employees; + } + + public String toString() { + return "Department id=" + getId() + ", Department Name=" + getName(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/entity/Employee.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/entity/Employee.java new file mode 100644 index 0000000..a1820e8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/entity/Employee.java
@@ -0,0 +1,117 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Transient; + +@Entity +@Table(name = "EMPLOYEE") +public class Employee implements java.io.Serializable { + + private int id; + private String firstName; + private String lastName; + private Department department; + + public Employee() { + } + + public Employee(int id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public Employee(int id, String firstName, String lastName, + Department department) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + this.department = department; + } + + // =========================================================== + // getters and setters for the state fields + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "FIRSTNAME") + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + @Column(name = "LASTNAME") + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + // =========================================================== + // getters and setters for the association fields + // @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "DEPARTMENT_ID") + public Department getDepartment() { + return department; + } + + @Transient + public Department getDepartmentNoWeaving() { + try { + java.lang.reflect.Field f = Employee.class + .getDeclaredField("department"); + return (Department) f.get(this); + } catch (NoSuchFieldException e) { + throw new RuntimeException( + "Please change argument to getDeclaredField", e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public void setDepartment(Department department) { + this.department = department; + } + + public String toString() { + return "Employee id=" + getId() + ", firstName=" + getFirstName() + + ", lastName=" + getLastName() + ", department=" + + getDepartment(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/servlet/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/servlet/TestServlet.java new file mode 100644 index 0000000..d06d708 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/servlet/TestServlet.java
@@ -0,0 +1,194 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Set; + +import javax.annotation.Resource; +import javax.enterprise.inject.Any; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; +import javax.naming.InitialContext; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.transaction.UserTransaction; + +import test.beans.TestBean; +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.wbinflib.AnotherTestBeanInWebInfLib; +import test.beans.wbinflib.TestAlternativeBeanInWebInfLib; +import test.beans.wbinflib.TestBeanInWebInfLib; +import test.util.JpaTest; + +@WebServlet(name="mytest", + urlPatterns={"/myurl"}, + initParams={ @WebInitParam(name="n1", value="v1"), @WebInitParam(name="n2", value="v2") } ) +public class TestServlet extends HttpServlet { + + /* Normal injection of Beans */ + @Inject + private transient org.jboss.logging.Logger log; + @Inject BeanManager bm_at_inj; + + /*Injection of Java EE resources*/ + @PersistenceUnit(unitName = "pu1") + private EntityManagerFactory emf_at_pu; + + @Inject //@TestDatabase + private EntityManager emf_at_inj; + + private @Resource + UserTransaction utx; + + @Inject @Preferred + TestBeanInterface tbi; + + /* Injection of Beans from WEB-INF/lib */ + @Inject TestBeanInWebInfLib tbiwil; + //We are injecting TestBeanInWebInfLib directly above. Since the alternative + //TestBean is not enabled in the WAR's BDA(beans.xml), + //TestBeanInWebInfLib must be injected + + + @Inject AnotherTestBeanInWebInfLib atbiwil; + //However in this case, when AnotherTestBeanInWebInfLib tries to inject + //TestBeanInWebInfLib in its bean, it must inject TestAlternativeBeanInWebInfLib + //as the alternative bean is enabled in the WEB-INF/lib's BDA (beans.xml) + + /* Test lookup of BeanManager*/ + BeanManager bm_lookup; + + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + String msg = ""; + if (tbi == null) msg += "Bean injection into Servlet failed"; + if (tbiwil == null) msg += "Bean injection of a TestBean in WEB-INF/lib into Servlet failed"; + System.out.println("Test Bean from WEB-INF/lib=" + tbiwil); + + System.out.println("BeanManager is " + bm_at_inj); + System.out.println("BeanManager via lookup is " + bm_lookup); + if (bm_at_inj == null) msg += "BeanManager Injection via @Inject failed"; + try { + bm_lookup = (BeanManager)((new InitialContext()).lookup("java:comp/BeanManager")); + } catch (Exception ex) { + ex.printStackTrace(); + msg += "BeanManager Injection via component environment lookup failed"; + } + if (bm_lookup == null) msg += "BeanManager Injection via component environment lookup failed"; + + //Check if Beans in WAR(WEB-INF/classes) and WEB-INF/lib/*.jar are visible + //via BeanManager of WAR + Set warBeans = bm_at_inj.getBeans(TestBean.class,new AnnotationLiteral<Any>() {}); + if (warBeans.size() != 1) msg += "TestBean in WAR is not available via the WAR BeanManager"; + + Set webinfLibBeans = bm_at_inj.getBeans(TestBeanInWebInfLib.class,new AnnotationLiteral<Any>() {}); + if (webinfLibBeans.size() != 1) msg += "TestBean in WEB-INF/lib is not available via the WAR BeanManager"; + System.out.println("Test Bean from WEB-INF/lib via BeanManager:" + webinfLibBeans); + + //Ensure Alternative Beans enabled only in the context of web-inf/lib is + //not visible in WAR's BM + Set webinfLibAltBeans = bm_at_inj.getBeans(TestAlternativeBeanInWebInfLib.class,new AnnotationLiteral<Any>() {}); + if (webinfLibAltBeans.size() != 0) msg += "TestAlternativeBean in WEB-INF/lib is available via the WAR BeanManager"; + System.out.println("Test Bean from WEB-INF/lib via BeanManager:" + webinfLibAltBeans); + + //Test injection of a Bean in WEB-INF/lib beans into Servlet + //and check that the Alternative bean is not called. + //The alternative bean in web-inf/lib is not enabled in the WAR's beans.xml + //and hence must not be visible. + TestAlternativeBeanInWebInfLib.clearStatus(); //clear status + + String injectionOfBeanInWebInfLibResult = tbiwil.testInjection(); + System.out.println("injectionWithAlternative returned: " + injectionOfBeanInWebInfLibResult); + if (injectionOfBeanInWebInfLibResult.equals ("Alternative")) { + msg += "Expected that the original TestBeanInWebInfLib is called, " + + "but instead got " + injectionOfBeanInWebInfLibResult + " instead"; + } + + if(TestAlternativeBeanInWebInfLib.ALTERNATIVE_BEAN_HAS_BEEN_CALLED) { + msg += "Alternate Bean is called even though it is not enabled in the WAR's beans.xml"; + } + + //Test injection into a bean in web-inf/lib + //In this case the alternative bean must be called, as it is enabled + //in the library jar's beans.xml and the injection of the Bean + //happens in the context of the library jar + TestAlternativeBeanInWebInfLib.clearStatus(); //clear status + String injectionWithAlternative2 = atbiwil.testInjection(); + System.out.println("injectionWithAlternative returned: " + injectionWithAlternative2); + if (injectionWithAlternative2.equals ("Alternative")) { + //test injection successful + } else { + msg += "Expected alternative, but got " + injectionWithAlternative2 + " instead"; + } + + if (!TestAlternativeBeanInWebInfLib.ALTERNATIVE_BEAN_HAS_BEEN_CALLED) { + msg += "Alternative Bean enabled in WEB-INF/lib was not called " + + "when the injection happened in the context of a " + + "Bean in WEB-INF/lib where the alternative Bean was enabled"; + } + + + msg += testEMInjection(req); + + writer.write(msg + "\n"); + } + + + private String testEMInjection(HttpServletRequest request) { + String msg = ""; + EntityManager em = emf_at_inj; + System.out.println("JPAResourceInjectionServlet::createEM" + + "EntityManager=" + em); + String testcase = request.getParameter("testcase"); + System.out.println("testcase=" + testcase); + + if (testcase != null) { + JpaTest jt = new JpaTest(em, utx); + boolean status = false; + if ("llinit".equals(testcase)) { + status = jt.lazyLoadingInit(); + } else if ("llfind".equals(testcase)) { + status = jt.lazyLoadingByFind(1); + } else if ("llquery".equals(testcase)) { + status = jt.lazyLoadingByQuery("Carla"); + } else if ("llinj".equals(testcase)){ + status = ((tbi != null) && + (tbi.testDatasourceInjection().trim().length()==0)); + } + if (status) { + msg += "";// pass + } else { + msg += (testcase + ":fail"); + } + } + return msg; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/util/JPAResourceProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/util/JPAResourceProducer.java new file mode 100644 index 0000000..2cf2827 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/util/JPAResourceProducer.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.enterprise.inject.Produces; +import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +@Singleton +public class JPAResourceProducer { + @Produces @PersistenceContext(unitName="pu1") + //@TestDatabase + EntityManager customerDatabasePersistenceUnit; + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/util/JpaTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/util/JpaTest.java new file mode 100644 index 0000000..3d47448 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/servlet/test/util/JpaTest.java
@@ -0,0 +1,170 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Query; +import javax.transaction.UserTransaction; + +import test.entity.Department; +import test.entity.Employee; + +public class JpaTest { + + private EntityManager em; + private UserTransaction utx; + + private static Department deptRef[] = new Department[2]; + private static Employee empRef[] = new Employee[5]; + + public JpaTest() { + } + + public JpaTest(EntityManager em, UserTransaction utx) { + this.em = em; + this.utx = utx; + } + + public boolean lazyLoadingInit() { + boolean status = false; + System.out.println("-----lazeLoadingInit()---------"); + try { + deptRef[0] = new Department(1, "Engineering"); + deptRef[1] = new Department(2, "Marketing"); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 2; i++) { + em.persist(deptRef[i]); + } + utx.commit(); + + empRef[0] = new Employee(1, "Alan", "Frechette", deptRef[0]); + empRef[1] = new Employee(2, "Arthur", "Wesley", deptRef[0]); + empRef[2] = new Employee(3, "Abe", "White", deptRef[0]); + empRef[3] = new Employee(4, "Paul", "Hinz", deptRef[1]); + empRef[4] = new Employee(5, "Carla", "Calrson", deptRef[1]); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 5; i++) { + em.persist(empRef[i]); + } + utx.commit(); + status = true; + } catch (Exception ex) { + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByFind(int employeeID) { + + boolean status = true; + System.out.println("------------lazyLoadingAfterFind -----------"); + System.out.println("employeeID = " + employeeID); + Employee emp = em.find(Employee.class, employeeID); + + System.out.println("found: emp.id=" + emp.getId()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByQuery(String fName) { + + boolean status = true; + System.out.println("------------lazyLoadingByQuery -----------"); + System.out.println("fName = " + fName); + Query query = em.createQuery( + "SELECT e FROM Employee e WHERE e.firstName like :firstName") + .setParameter("firstName", fName); + ; + Employee emp = (Employee) query.getSingleResult(); + + System.out.println("queried: emp.firstName=" + emp.getFirstName()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/util/test/beans/wbinflib/AnotherTestBeanInWebInfLib.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/util/test/beans/wbinflib/AnotherTestBeanInWebInfLib.java new file mode 100644 index 0000000..3140fe1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/util/test/beans/wbinflib/AnotherTestBeanInWebInfLib.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2011, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.wbinflib; + +import javax.inject.Inject; + +public class AnotherTestBeanInWebInfLib { + @Inject + TestBeanInWebInfLib twil; //Enabled alternative bean must be injected here, as this bean is within web-inf/lib BDA which has the enabled alternatives + + + public String testInjection() { + String ret = twil.testInjection(); + return ret; //"Alternative" + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/util/test/beans/wbinflib/TestAlternativeBeanInWebInfLib.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/util/test/beans/wbinflib/TestAlternativeBeanInWebInfLib.java new file mode 100644 index 0000000..45bbdb4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/util/test/beans/wbinflib/TestAlternativeBeanInWebInfLib.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.wbinflib; + +import javax.enterprise.inject.Alternative; + +@Alternative +public class TestAlternativeBeanInWebInfLib extends TestBeanInWebInfLib { + public static boolean ALTERNATIVE_BEAN_HAS_BEEN_CALLED = false; + public TestAlternativeBeanInWebInfLib(){ + System.out.println("**************** Alternative Bean in web-inf/lib created"); + } + + @Override + public String testInjection() { + ALTERNATIVE_BEAN_HAS_BEEN_CALLED = true; + System.out.println("*************** testinjection in alternative bean in web-inf/lib called"); + return "Alternative"; + } + + public static void clearStatus(){ + ALTERNATIVE_BEAN_HAS_BEEN_CALLED = false; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/util/test/beans/wbinflib/TestBeanInWebInfLib.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/util/test/beans/wbinflib/TestBeanInWebInfLib.java new file mode 100644 index 0000000..ccc108f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/util/test/beans/wbinflib/TestBeanInWebInfLib.java
@@ -0,0 +1,90 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.wbinflib; +import java.util.Set; + +import javax.enterprise.inject.Any; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +public class TestBeanInWebInfLib { + @Inject + BeanManager bm; + +// @Inject //@TestDatabase +// EntityManager emf_at_inj; + + @PersistenceContext(unitName="pu1") + EntityManager emf_at_pu; + + //This test injection method would be called in the context of the servlet in WAR + //which does not have the alternative bean enabled in it. + public String testInjection() { + if (bm == null) + return "Bean Manager not injected into the TestBean in WEB-INF/lib"; + System.out.println("BeanManager injected in WEB-INF/lib bean is " + bm); + + System.out.println("EMF injected in WEB-INF/lib bean is " + emf_at_pu); + if (emf_at_pu == null) + return "EMF injected via @PersistenceContext is not injected into " + + "the TestBean packaged in WEB-INF/lib"; + + Set<Bean<?>> webinfLibBeans = bm.getBeans(TestBeanInWebInfLib.class, new AnnotationLiteral<Any>() {}); + if (webinfLibBeans.size() != 2) //Bean and enabled Alternative + return "TestBean in WEB-INF/lib is not available via the WEB-INF/lib " + + "Bean's BeanManager"; + System.out.println("***********************************************************"); + printBeans(webinfLibBeans, "BeanManager.getBeans(TestBeanInWebInfLib, Any):"); + + Set<Bean<?>> webinfLibAltBeans = bm.getBeans(TestAlternativeBeanInWebInfLib.class, new AnnotationLiteral<Any>() {}); + if (webinfLibBeans.size() != 1) //enabled Alternative + return "TestAlternativeBean in WEB-INF/lib is not available via the WEB-INF/lib " + + "Bean's BeanManager"; + printBeans(webinfLibAltBeans, "BeanManager.getBeans(TestAlternativeBeanInWebInfLib, Any):"); + + + Iterable<Bean<?>> accessibleBeans = ((org.jboss.weld.manager.BeanManagerImpl) bm).getAccessibleBeans(); + printBeans(accessibleBeans, "BeanManagerImpl.getAccessibleBeans:"); + + Iterable<Bean<?>> beans = ((org.jboss.weld.manager.BeanManagerImpl) bm).getBeans(); + printBeans(beans, "BeanManagerImpl.getBeans"); + System.out.println("***********************************************************"); + + // success + return ""; + } + + private void printBeans(Iterable<Bean<?>> beans, String msg) { + System.out.println(msg + ":"); + for (Bean b : beans) { + debug(b); + } + System.out.println(); + } + + private void debug(Bean b) { + String name = b.getBeanClass().getName(); + if (name.indexOf("Test") != -1) { + System.out.print(name); + } + + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/util/test/beans/wbinflib/TestExtensionInWebInfLib.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/util/test/beans/wbinflib/TestExtensionInWebInfLib.java new file mode 100644 index 0000000..9f33e08 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-extension-alternative/util/test/beans/wbinflib/TestExtensionInWebInfLib.java
@@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.wbinflib; + +import javax.enterprise.inject.spi.Extension; + +public class TestExtensionInWebInfLib implements Extension { +//no-op +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/README new file mode 100644 index 0000000..c4a8a73 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/README
@@ -0,0 +1 @@ +GLASSFISH-15749
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/WebTest.java new file mode 100644 index 0000000..9eccfad --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/WebTest.java
@@ -0,0 +1,108 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; + +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "cdi-servlet-annotation-with-web-inf-lib-javaee-injection"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke("llinit"); + invoke("llquery"); + invoke("llfind"); + invoke("llinj"); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke(String testCase) throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl" + + "?testcase=" + testCase; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME + testCase, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME + testCase, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME + testCase, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/build.properties new file mode 100644 index 0000000..cf2f0c0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/build.properties
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-servlet-annotation-with-web-inf-lib-javaee-injection"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="persistence.xml" value="descriptor/persistence.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/build.xml new file mode 100644 index 0000000..42ccb47 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/build.xml
@@ -0,0 +1,122 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,create-resources,deploy,run,undeploy,delete-resources"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + <delete file="lib/bean-lib.jar"/> + </target> + + <target name="compile" depends="clean"> + <!-- create WEB-INF/lib/bean-lib.jar --> + <mkdir dir="${build.classes.dir}"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <javac srcdir="servlet" includes="TestBean.java" destdir="${build.classes.dir}" classpath="${s1astest.classpath}" debug="on" source="1.6"/> + <javac srcdir="util" destdir="${build.classes.dir}" classpath="${s1astest.classpath}" debug="on" source="1.6"/> + <copy file="descriptor/beans.xml" tofile="${build.classes.dir}/META-INF/beans.xml"/> + <delete file="${build.classes.dir}/TestBean.class" /> <!-- This is included in the WAR below --> + + <jar destfile="lib/bean-lib.jar"> + <fileset dir="${build.classes.dir}"/> + </jar> + <delete dir="${build.classes.dir}"/> + + <!-- compile test servlet --> + <mkdir dir="${build.classes.dir}"/> + <echo message="common.xml: Compiling test source files" level="verbose"/> + <mkdir dir="servlet"/> + <javac srcdir="servlet" destdir="${build.classes.dir}" classpath="${s1astest.classpath}:lib/bean-lib.jar" debug="on" failonerror="true"/> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="create-resources" depends="init-common"> + <antcall target="create-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + <antcall target="create-jdbc-resource-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="delete-resources" depends="init-common"> + <antcall target="delete-jdbc-resource-common"> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + + <antcall target="delete-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/descriptor/persistence.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/descriptor/persistence.xml new file mode 100644 index 0000000..82f2d7b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/descriptor/persistence.xml
@@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> + <persistence-unit name="pu1" transaction-type="JTA"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <jta-data-source>jdbc/__default</jta-data-source> + <non-jta-data-source>jdbc/__default</non-jta-data-source> + <class>myapp.Department</class> + <class>myapp.Employee</class> + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> + <property name="eclipselink.logging.level" value="INFO"/> + </properties> + </persistence-unit> +</persistence>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/lib/slf4j-api-1.7.25.jar b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/lib/slf4j-api-1.7.25.jar new file mode 100644 index 0000000..0143c09 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/lib/slf4j-api-1.7.25.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/lib/slf4j-simple-1.7.25.jar b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/lib/slf4j-simple-1.7.25.jar new file mode 100644 index 0000000..a7260f3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/lib/slf4j-simple-1.7.25.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..787108a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/beans/TestBean.java
@@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.persistence.EntityManager; + +import test.beans.artifacts.Preferred; + +@RequestScoped +@Preferred +public class TestBean implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Inject //@TestDatabase + EntityManager emf; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + + @Override + public String testDatasourceInjection() { + return (emf==null ? "typesafe injection into testbean failed" : ""); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..29e137a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void m1(); + public void m2(); + + public String testDatasourceInjection(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/beans/TestLoggerProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/beans/TestLoggerProducer.java new file mode 100644 index 0000000..8be9d65 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/beans/TestLoggerProducer.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.inject.Produces; + + +public class TestLoggerProducer { + @Produces + public org.jboss.logging.Logger getLogger(){ + org.jboss.logging.Logger l = org.jboss.logging.Logger.getLogger(TestLoggerProducer.class); + System.out.println("getLogger:: " + l); + return l; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/beans/artifacts/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/beans/artifacts/Preferred.java new file mode 100644 index 0000000..b7584c8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/beans/artifacts/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/beans/artifacts/TestDatabase.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/beans/artifacts/TestDatabase.java new file mode 100644 index 0000000..b69ab8e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/beans/artifacts/TestDatabase.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestDatabase { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/entity/Department.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/entity/Department.java new file mode 100644 index 0000000..14191ec --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/entity/Department.java
@@ -0,0 +1,82 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "DEPARTMENT") +public class Department implements java.io.Serializable { + + // Instance variables + private int id; + private String name; + private Set<Employee> employees; + + public Department() { + } + + public Department(int id, String name) { + this.id = id; + this.name = name; + } + + // =========================================================== + // getters and setters for the state fields + + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "NAME") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + // =========================================================== + // getters and setters for the association fields + @OneToMany(cascade = CascadeType.ALL, mappedBy = "department") + public Set<Employee> getEmployees() { + return employees; + } + + public void setEmployees(Set<Employee> employees) { + this.employees = employees; + } + + public String toString() { + return "Department id=" + getId() + ", Department Name=" + getName(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/entity/Employee.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/entity/Employee.java new file mode 100644 index 0000000..a1820e8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/entity/Employee.java
@@ -0,0 +1,117 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Transient; + +@Entity +@Table(name = "EMPLOYEE") +public class Employee implements java.io.Serializable { + + private int id; + private String firstName; + private String lastName; + private Department department; + + public Employee() { + } + + public Employee(int id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public Employee(int id, String firstName, String lastName, + Department department) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + this.department = department; + } + + // =========================================================== + // getters and setters for the state fields + @Id + @Column(name = "ID") + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "FIRSTNAME") + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + @Column(name = "LASTNAME") + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + // =========================================================== + // getters and setters for the association fields + // @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "DEPARTMENT_ID") + public Department getDepartment() { + return department; + } + + @Transient + public Department getDepartmentNoWeaving() { + try { + java.lang.reflect.Field f = Employee.class + .getDeclaredField("department"); + return (Department) f.get(this); + } catch (NoSuchFieldException e) { + throw new RuntimeException( + "Please change argument to getDeclaredField", e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public void setDepartment(Department department) { + this.department = department; + } + + public String toString() { + return "Employee id=" + getId() + ", firstName=" + getFirstName() + + ", lastName=" + getLastName() + ", department=" + + getDepartment(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/servlet/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/servlet/TestServlet.java new file mode 100644 index 0000000..80a1932 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/servlet/TestServlet.java
@@ -0,0 +1,147 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Set; + +import javax.annotation.Resource; +import javax.enterprise.inject.Any; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; +import javax.naming.InitialContext; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.transaction.UserTransaction; + +import test.beans.TestBean; +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.util.JpaTest; + +import test.beans.wbinflib.TestBeanInWebInfLib; + +@WebServlet(name="mytest", + urlPatterns={"/myurl"}, + initParams={ @WebInitParam(name="n1", value="v1"), @WebInitParam(name="n2", value="v2") } ) +public class TestServlet extends HttpServlet { + + /* Normal injection of Beans */ + @Inject + private transient org.jboss.logging.Logger log; + @Inject BeanManager bm_at_inj; + + /*Injection of Java EE resources*/ + @PersistenceUnit(unitName = "pu1") + private EntityManagerFactory emf_at_pu; + + @Inject //@TestDatabase + private EntityManager emf_at_inj; + + private @Resource + UserTransaction utx; + + @Inject @Preferred + TestBeanInterface tbi; + + /* Injection of Beans from WEB-INF/lib */ + @Inject TestBeanInWebInfLib tbiwil; + + /* Test lookup of BeanManager*/ + BeanManager bm_lookup; + + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + + ", n2=" + getInitParameter("n2"); + + if (tbi == null) msg += "Bean injection into Servlet failed"; + if (tbiwil == null) msg += "Bean injection of a TestBean in WEB-INF/lib into Servlet failed"; + System.out.println("Test Bean from WEB-INF/lib=" + tbiwil); + + System.out.println("BeanManager is " + bm_at_inj); + System.out.println("BeanManager via lookup is " + bm_lookup); + if (bm_at_inj == null) msg += "BeanManager Injection via @Inject failed"; + try { + bm_lookup = (BeanManager)((new InitialContext()).lookup("java:comp/BeanManager")); + } catch (Exception ex) { + ex.printStackTrace(); + msg += "BeanManager Injection via component environment lookup failed"; + } + if (bm_lookup == null) msg += "BeanManager Injection via component environment lookup failed"; + + //Check if Beans in WAR(WEB-INF/classes) and WEB-INF/lib/*.jar are visible + //via BeanManager of WAR + Set warBeans = bm_at_inj.getBeans(TestBean.class,new AnnotationLiteral<Any>() {}); + if (warBeans.size() != 1) msg += "TestBean in WAR is not available via the WAR BeanManager"; + + Set webinfLibBeans = bm_at_inj.getBeans(TestBeanInWebInfLib.class,new AnnotationLiteral<Any>() {}); + if (webinfLibBeans.size() != 1) msg += "TestBean in WEB-INF/lib is not available via the WAR BeanManager"; + System.out.println("Test Bean from WEB-INF/lib via BeanManager:" + webinfLibBeans); + + //Test injection into WEB-INF/lib beans + msg += tbiwil.testInjection(); + + msg += testEMInjection(req); + + writer.write("initParams: " + msg + "\n"); + } + + + private String testEMInjection(HttpServletRequest request) { + String msg = ""; + EntityManager em = emf_at_inj; + System.out.println("JPAResourceInjectionServlet::createEM" + + "EntityManager=" + em); + String testcase = request.getParameter("testcase"); + System.out.println("testcase=" + testcase); + + if (testcase != null) { + JpaTest jt = new JpaTest(em, utx); + boolean status = false; + if ("llinit".equals(testcase)) { + status = jt.lazyLoadingInit(); + } else if ("llfind".equals(testcase)) { + status = jt.lazyLoadingByFind(1); + } else if ("llquery".equals(testcase)) { + status = jt.lazyLoadingByQuery("Carla"); + } else if ("llinj".equals(testcase)){ + status = ((tbi != null) && + (tbi.testDatasourceInjection().trim().length()==0)); + } + if (status) { + msg += "";// pass + } else { + msg += (testcase + ":fail"); + } + } + return msg; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/util/JPAResourceProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/util/JPAResourceProducer.java new file mode 100644 index 0000000..2cf2827 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/util/JPAResourceProducer.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.enterprise.inject.Produces; +import javax.inject.Singleton; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +@Singleton +public class JPAResourceProducer { + @Produces @PersistenceContext(unitName="pu1") + //@TestDatabase + EntityManager customerDatabasePersistenceUnit; + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/util/JpaTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/util/JpaTest.java new file mode 100644 index 0000000..3d47448 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/servlet/test/util/JpaTest.java
@@ -0,0 +1,170 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.util; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Query; +import javax.transaction.UserTransaction; + +import test.entity.Department; +import test.entity.Employee; + +public class JpaTest { + + private EntityManager em; + private UserTransaction utx; + + private static Department deptRef[] = new Department[2]; + private static Employee empRef[] = new Employee[5]; + + public JpaTest() { + } + + public JpaTest(EntityManager em, UserTransaction utx) { + this.em = em; + this.utx = utx; + } + + public boolean lazyLoadingInit() { + boolean status = false; + System.out.println("-----lazeLoadingInit()---------"); + try { + deptRef[0] = new Department(1, "Engineering"); + deptRef[1] = new Department(2, "Marketing"); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 2; i++) { + em.persist(deptRef[i]); + } + utx.commit(); + + empRef[0] = new Employee(1, "Alan", "Frechette", deptRef[0]); + empRef[1] = new Employee(2, "Arthur", "Wesley", deptRef[0]); + empRef[2] = new Employee(3, "Abe", "White", deptRef[0]); + empRef[3] = new Employee(4, "Paul", "Hinz", deptRef[1]); + empRef[4] = new Employee(5, "Carla", "Calrson", deptRef[1]); + utx.begin(); + em.joinTransaction(); + for (int i = 0; i < 5; i++) { + em.persist(empRef[i]); + } + utx.commit(); + status = true; + } catch (Exception ex) { + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByFind(int employeeID) { + + boolean status = true; + System.out.println("------------lazyLoadingAfterFind -----------"); + System.out.println("employeeID = " + employeeID); + Employee emp = em.find(Employee.class, employeeID); + + System.out.println("found: emp.id=" + emp.getId()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + + System.out.println("-----status = " + status + "---------"); + return status; + } + + public boolean lazyLoadingByQuery(String fName) { + + boolean status = true; + System.out.println("------------lazyLoadingByQuery -----------"); + System.out.println("fName = " + fName); + Query query = em.createQuery( + "SELECT e FROM Employee e WHERE e.firstName like :firstName") + .setParameter("firstName", fName); + ; + Employee emp = (Employee) query.getSingleResult(); + + System.out.println("queried: emp.firstName=" + emp.getFirstName()); + + try { + // 1. get Department before loading + Department deptBL = emp.getDepartmentNoWeaving(); + System.out.println("1. before loading: deptBL=" + deptBL); + String deptNameBL = null; + if (deptBL != null) { + deptNameBL = deptBL.getName(); + System.out.println("deptNameBL=" + deptNameBL); + } + // assert deptBL == null; + if (deptBL != null) { + status = false; + } + + // 2. loading + String deptName = emp.getDepartment().getName(); + System.out.println("2. loading, deptName = " + deptName); + + // 3. get Department after loading + Department deptAL = emp.getDepartmentNoWeaving(); + System.out.println("3. after loading: deptAL=" + deptAL); + String deptNameAL = deptAL.getName(); + System.out.println("deptNameAL=" + deptNameAL); + // assert deptAL != null + // assert deptAL.getName == deptName; + if (deptAL == null || deptNameAL != deptName) { + status = false; + } + } catch (Exception ex) { + status = false; + ex.printStackTrace(); + } + System.out.println("-----status = " + status + "---------"); + return status; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/util/test/beans/wbinflib/TestBeanInWebInfLib.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/util/test/beans/wbinflib/TestBeanInWebInfLib.java new file mode 100644 index 0000000..8e89576 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-javaee-injection/util/test/beans/wbinflib/TestBeanInWebInfLib.java
@@ -0,0 +1,84 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.wbinflib; + +import java.util.Set; + +import javax.enterprise.inject.Any; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +public class TestBeanInWebInfLib { + @Inject + BeanManager bm; + +// @Inject //@TestDatabase +// EntityManager emf_at_inj; + + @PersistenceContext(unitName="pu1") + EntityManager emf_at_pu; + + public String testInjection() { + if (bm == null) + return "Bean Manager not injected into the TestBean in WEB-INF/lib"; + System.out.println("BeanManager injected in WEB-INF/lib bean is " + bm); + + System.out.println("EMF injected in WEB-INF/lib bean is " + emf_at_pu); + if (emf_at_pu == null) + return "EMF injected via @PersistenceContext is not injected into " + + "the TestBean packaged in WEB-INF/lib"; + + Set<Bean<?>> webinfLibBeans = bm.getBeans(TestBeanInWebInfLib.class, new AnnotationLiteral<Any>() {}); + if (webinfLibBeans.size() != 1) + return "TestBean in WEB-INF/lib is not available via the WEB-INF/lib " + + "Bean's BeanManager"; + System.out.println("BeanManager.getBeans(TestBeanInWebInfLib, Any):" + webinfLibBeans); + for (Bean b: webinfLibBeans) { + debug(b); + } + + // Get the proxy delegate + org.jboss.weld.manager.BeanManagerImpl delegate = + ((org.jboss.weld.bean.builtin.BeanManagerProxy) bm).delegate(); + + Iterable<Bean<?>> accessibleBeans = delegate.getAccessibleBeans(); + System.out.println("BeanManagerImpl.getAccessibleBeans:" + accessibleBeans); + for (Bean b : accessibleBeans) { + debug(b); + } + + Iterable<Bean<?>> beans = delegate.getBeans(); + System.out.println("BeanManagerImpl.getBeans:" + beans); + for (Bean b : beans) { + debug(b); + } + // success + return ""; + } + + private void debug(Bean b) { + String name = b.getBeanClass().getName(); + if (name.indexOf("Test") != -1) { + System.out.println(name); + } + + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/README new file mode 100644 index 0000000..b055956 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/README
@@ -0,0 +1,5 @@ +GLASSFISH-15735 scenario +with the ordering reversed. +alpha.jar has "Bar"(that requires Foo to be injected) +bravo.jar has "Foo" +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/WebTest.java new file mode 100644 index 0000000..1481991 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/WebTest.java
@@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "cdi-servlet-annotation-with-web-inf-lib-with-ordering-reversed"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/build.properties new file mode 100644 index 0000000..c6b5b5a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-servlet-annotation-with-web-inf-lib-with-ordering-reversed"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/build.xml new file mode 100644 index 0000000..66a8829 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/build.xml
@@ -0,0 +1,112 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + <delete file="lib/alpha.jar"/> + <delete file="lib/bravo.jar"/> + </target> + + <target name="compile" depends="clean"> + <!-- create WEB-INF/lib/bravo.jar --> + <mkdir dir="${build.classes.dir}"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <javac srcdir="util1" destdir="${build.classes.dir}" classpath="${s1astest.classpath}" debug="on" source="1.6"/> + <copy file="descriptor/beans.xml" tofile="${build.classes.dir}/META-INF/beans.xml"/> + <jar destfile="lib/bravo.jar"> + <fileset dir="${build.classes.dir}"/> + </jar> + <delete dir="${build.classes.dir}"/> + + <!-- create WEB-INF/lib/alpha.jar --> + <mkdir dir="${build.classes.dir}"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <javac srcdir="util1" destdir="${build.classes.dir}" classpath="${s1astest.classpath}" debug="on" source="1.6"/> + <javac srcdir="util2" destdir="${build.classes.dir}" classpath="${s1astest.classpath}" debug="on" source="1.6"/> + <delete file="${build.classes.dir}/Foo.class"/> + <copy file="descriptor/beans.xml" tofile="${build.classes.dir}/META-INF/beans.xml"/> + <jar destfile="lib/alpha.jar"> + <fileset dir="${build.classes.dir}"/> + </jar> + <delete dir="${build.classes.dir}"/> + + <!-- compile test servlet --> + <mkdir dir="${build.classes.dir}"/> + <echo message="common.xml: Compiling test source files" level="verbose"/> + <mkdir dir="servlet"/> + <javac srcdir="servlet" destdir="${build.classes.dir}" classpath="${s1astest.classpath}:lib/alpha.jar:lib/bravo.jar" debug="on" failonerror="true"/> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/lib/slf4j-api-1.7.25.jar b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/lib/slf4j-api-1.7.25.jar new file mode 100644 index 0000000..0143c09 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/lib/slf4j-api-1.7.25.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/lib/slf4j-simple-1.7.25.jar b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/lib/slf4j-simple-1.7.25.jar new file mode 100644 index 0000000..a7260f3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/lib/slf4j-simple-1.7.25.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/servlet/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/servlet/TestBean.java new file mode 100644 index 0000000..c696caf --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/servlet/TestBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +//Simple TestBean to test CDI. +public class TestBean +{ + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/servlet/TestLoggerProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/servlet/TestLoggerProducer.java new file mode 100644 index 0000000..f8e08a7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/servlet/TestLoggerProducer.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import javax.enterprise.inject.Produces; + + +public class TestLoggerProducer { + @Produces + public org.jboss.logging.Logger getLogger(){ + org.jboss.logging.Logger l = org.jboss.logging.Logger.getLogger(TestLoggerProducer.class); + System.out.println("getLogger:: " + l); + return l; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/servlet/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/servlet/TestServlet.java new file mode 100644 index 0000000..e3cf013 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/servlet/TestServlet.java
@@ -0,0 +1,96 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; +import java.util.Set; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.inject.Inject; +import javax.enterprise.inject.Any; +import javax.enterprise.inject.Default; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.util.AnnotationLiteral; +import javax.naming.InitialContext; + +@WebServlet(name="mytest", + urlPatterns={"/myurl"}, + initParams={ @WebInitParam(name="n1", value="v1"), @WebInitParam(name="n2", value="v2") } ) +public class TestServlet extends HttpServlet { + @Inject TestBean tb; + @Inject BeanManager bm; + + @Inject Foo f; //from WEB-INF/lib/alpha.jar + @Inject Bar b; //from WEB-INF/lib/bravo.jar + + + BeanManager bm1; + + @Inject + private transient org.jboss.logging.Logger log; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + + ", n2=" + getInitParameter("n2"); + + //Bean Injection + if (tb == null) msg += "Bean injection into Servlet failed"; + + if (f == null) msg += "Bean injection of a TestBean(foo) in WEB-INF/lib/alpha.jar into Servlet failed"; + System.out.println("Test Bean foo from WEB-INF/lib/alpha.jar=" + f); + + if (b == null) msg += "Bean injection of a TestBean(bar) in WEB-INF/lib/bravo.jar into Servlet failed"; + System.out.println("Test Bean foo from WEB-INF/lib/bravo.jar=" + b); + + //BeanManager Injection + System.out.println("BeanManager is " + bm); + if (bm == null) msg += "BeanManager Injection via @Inject failed"; + + try { + bm1 = (BeanManager)((new InitialContext()).lookup("java:comp/BeanManager")); + System.out.println("BeanManager via lookup is " + bm1); + } catch (Exception ex) { + ex.printStackTrace(); + msg += "BeanManager Injection via component environment lookup failed"; + } + if (bm1 == null) msg += "BeanManager Injection via component environment lookup failed"; + + //Check if Beans in WAR(WEB-INF/classes) and WEB-INF/lib/*.jar are visible + //via BeanManager of WAR + Set warBeans = bm.getBeans(TestBean.class,new AnnotationLiteral<Any>() {}); + if (warBeans.size() != 1) msg += "TestBean in WAR is not available via the WAR BeanManager"; + + Set webinfLibBeans = bm.getBeans(Foo.class,new AnnotationLiteral<Any>() {}); + if (webinfLibBeans.size() != 1) msg += "TestBean Foo in WEB-INF/lib/alpha.jar is not available via the WAR BeanManager"; + System.out.println("Test Bean Foo from WEB-INF/lib/alpha.jar via BeanManager:" + webinfLibBeans); + + webinfLibBeans = bm.getBeans(Bar.class,new AnnotationLiteral<Any>() {}); + if (webinfLibBeans.size() != 1) msg += "TestBean Bar in WEB-INF/lib/bravo.jar is not available via the WAR BeanManager"; + System.out.println("Test Bean Bar from WEB-INF/lib/bravo.jar via BeanManager:" + webinfLibBeans); + + writer.write("initParams: " + msg + "\n"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/util1/Foo.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/util1/Foo.java new file mode 100644 index 0000000..9ee6ebb --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/util1/Foo.java
@@ -0,0 +1,19 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +@javax.enterprise.context.RequestScoped +public class Foo { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/util2/Bar.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/util2/Bar.java new file mode 100644 index 0000000..f15bc53 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering-reversed/util2/Bar.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +@javax.enterprise.context.RequestScoped +public class Bar{ +@javax.inject.Inject +Foo f; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/README new file mode 100644 index 0000000..78565b8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/README
@@ -0,0 +1,2 @@ +GLASSFISH-15735 +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/WebTest.java new file mode 100644 index 0000000..0bb3666 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/WebTest.java
@@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "cdi-servlet-annotation-with-web-inf-lib-with-ordering"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/build.properties new file mode 100644 index 0000000..542d011 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-servlet-annotation-with-web-inf-lib-with-ordering"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/build.xml new file mode 100644 index 0000000..3598ebd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/build.xml
@@ -0,0 +1,112 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + <delete file="lib/alpha.jar"/> + <delete file="lib/bravo.jar"/> + </target> + + <target name="compile" depends="clean"> + <!-- create WEB-INF/lib/alpha.jar --> + <mkdir dir="${build.classes.dir}"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <javac srcdir="util1" destdir="${build.classes.dir}" classpath="${s1astest.classpath}" debug="on" source="1.6"/> + <copy file="descriptor/beans.xml" tofile="${build.classes.dir}/META-INF/beans.xml"/> + <jar destfile="lib/alpha.jar"> + <fileset dir="${build.classes.dir}"/> + </jar> + <delete dir="${build.classes.dir}"/> + + <!-- create WEB-INF/lib/bravo.jar --> + <mkdir dir="${build.classes.dir}"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <javac srcdir="util1" destdir="${build.classes.dir}" classpath="${s1astest.classpath}" debug="on" source="1.6"/> + <javac srcdir="util2" destdir="${build.classes.dir}" classpath="${s1astest.classpath}" debug="on" source="1.6"/> + <delete file="${build.classes.dir}/Foo.class"/> + <copy file="descriptor/beans.xml" tofile="${build.classes.dir}/META-INF/beans.xml"/> + <jar destfile="lib/bravo.jar"> + <fileset dir="${build.classes.dir}"/> + </jar> + <delete dir="${build.classes.dir}"/> + + <!-- compile test servlet --> + <mkdir dir="${build.classes.dir}"/> + <echo message="common.xml: Compiling test source files" level="verbose"/> + <mkdir dir="servlet"/> + <javac srcdir="servlet" destdir="${build.classes.dir}" classpath="${s1astest.classpath}:lib/alpha.jar:lib/bravo.jar" debug="on" failonerror="true"/> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/lib/slf4j-api-1.7.25.jar b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/lib/slf4j-api-1.7.25.jar new file mode 100644 index 0000000..0143c09 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/lib/slf4j-api-1.7.25.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/lib/slf4j-simple-1.7.25.jar b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/lib/slf4j-simple-1.7.25.jar new file mode 100644 index 0000000..a7260f3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/lib/slf4j-simple-1.7.25.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/servlet/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/servlet/TestBean.java new file mode 100644 index 0000000..c696caf --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/servlet/TestBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +//Simple TestBean to test CDI. +public class TestBean +{ + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/servlet/TestLoggerProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/servlet/TestLoggerProducer.java new file mode 100644 index 0000000..f8e08a7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/servlet/TestLoggerProducer.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import javax.enterprise.inject.Produces; + + +public class TestLoggerProducer { + @Produces + public org.jboss.logging.Logger getLogger(){ + org.jboss.logging.Logger l = org.jboss.logging.Logger.getLogger(TestLoggerProducer.class); + System.out.println("getLogger:: " + l); + return l; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/servlet/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/servlet/TestServlet.java new file mode 100644 index 0000000..e3cf013 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/servlet/TestServlet.java
@@ -0,0 +1,96 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; +import java.util.Set; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.inject.Inject; +import javax.enterprise.inject.Any; +import javax.enterprise.inject.Default; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.util.AnnotationLiteral; +import javax.naming.InitialContext; + +@WebServlet(name="mytest", + urlPatterns={"/myurl"}, + initParams={ @WebInitParam(name="n1", value="v1"), @WebInitParam(name="n2", value="v2") } ) +public class TestServlet extends HttpServlet { + @Inject TestBean tb; + @Inject BeanManager bm; + + @Inject Foo f; //from WEB-INF/lib/alpha.jar + @Inject Bar b; //from WEB-INF/lib/bravo.jar + + + BeanManager bm1; + + @Inject + private transient org.jboss.logging.Logger log; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + + ", n2=" + getInitParameter("n2"); + + //Bean Injection + if (tb == null) msg += "Bean injection into Servlet failed"; + + if (f == null) msg += "Bean injection of a TestBean(foo) in WEB-INF/lib/alpha.jar into Servlet failed"; + System.out.println("Test Bean foo from WEB-INF/lib/alpha.jar=" + f); + + if (b == null) msg += "Bean injection of a TestBean(bar) in WEB-INF/lib/bravo.jar into Servlet failed"; + System.out.println("Test Bean foo from WEB-INF/lib/bravo.jar=" + b); + + //BeanManager Injection + System.out.println("BeanManager is " + bm); + if (bm == null) msg += "BeanManager Injection via @Inject failed"; + + try { + bm1 = (BeanManager)((new InitialContext()).lookup("java:comp/BeanManager")); + System.out.println("BeanManager via lookup is " + bm1); + } catch (Exception ex) { + ex.printStackTrace(); + msg += "BeanManager Injection via component environment lookup failed"; + } + if (bm1 == null) msg += "BeanManager Injection via component environment lookup failed"; + + //Check if Beans in WAR(WEB-INF/classes) and WEB-INF/lib/*.jar are visible + //via BeanManager of WAR + Set warBeans = bm.getBeans(TestBean.class,new AnnotationLiteral<Any>() {}); + if (warBeans.size() != 1) msg += "TestBean in WAR is not available via the WAR BeanManager"; + + Set webinfLibBeans = bm.getBeans(Foo.class,new AnnotationLiteral<Any>() {}); + if (webinfLibBeans.size() != 1) msg += "TestBean Foo in WEB-INF/lib/alpha.jar is not available via the WAR BeanManager"; + System.out.println("Test Bean Foo from WEB-INF/lib/alpha.jar via BeanManager:" + webinfLibBeans); + + webinfLibBeans = bm.getBeans(Bar.class,new AnnotationLiteral<Any>() {}); + if (webinfLibBeans.size() != 1) msg += "TestBean Bar in WEB-INF/lib/bravo.jar is not available via the WAR BeanManager"; + System.out.println("Test Bean Bar from WEB-INF/lib/bravo.jar via BeanManager:" + webinfLibBeans); + + writer.write("initParams: " + msg + "\n"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/util1/Foo.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/util1/Foo.java new file mode 100644 index 0000000..9ee6ebb --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/util1/Foo.java
@@ -0,0 +1,19 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +@javax.enterprise.context.RequestScoped +public class Foo { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/util2/Bar.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/util2/Bar.java new file mode 100644 index 0000000..f15bc53 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib-ordering/util2/Bar.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +@javax.enterprise.context.RequestScoped +public class Bar{ +@javax.inject.Inject +Foo f; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/README new file mode 100644 index 0000000..b004f04 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/README
@@ -0,0 +1,4 @@ +A simple WAR with a bean archive in WEB-INF/lib. The visibility of the Bean bundled in WAR(WEB-INF/classes) and WEB-INF/lib +is tested in the WAR's BeanManager + +GLASSFISH-15721
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/WebTest.java new file mode 100644 index 0000000..1ea710b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/WebTest.java
@@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "cdi-servlet-annotation-with-web-inf-lib"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/build.properties new file mode 100644 index 0000000..bb7bc8d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-servlet-annotation-with-web-inf-lib"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/build.xml new file mode 100644 index 0000000..3b2d3f1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/build.xml
@@ -0,0 +1,102 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + <delete file="lib/bean-lib.jar"/> + </target> + + <target name="compile" depends="clean"> + <!-- create WEB-INF/lib/bean-lib.jar --> + <mkdir dir="${build.classes.dir}"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <javac srcdir="servlet" includes="TestBean.java" destdir="${build.classes.dir}" classpath="${s1astest.classpath}" debug="on" source="1.6"/> + <javac srcdir="util" destdir="${build.classes.dir}" classpath="${s1astest.classpath}" debug="on" source="1.6"/> + <copy file="descriptor/beans.xml" tofile="${build.classes.dir}/META-INF/beans.xml"/> + <delete file="${build.classes.dir}/TestBean.class" /> <!-- This is included in the WAR below --> + + <jar destfile="lib/bean-lib.jar"> + <fileset dir="${build.classes.dir}"/> + </jar> + <delete dir="${build.classes.dir}"/> + + <!-- compile test servlet --> + <mkdir dir="${build.classes.dir}"/> + <echo message="common.xml: Compiling test source files" level="verbose"/> + <mkdir dir="servlet"/> + <javac srcdir="servlet" destdir="${build.classes.dir}" classpath="${s1astest.classpath}:lib/bean-lib.jar" debug="on" failonerror="true"/> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/lib/slf4j-api-1.7.25.jar b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/lib/slf4j-api-1.7.25.jar new file mode 100644 index 0000000..0143c09 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/lib/slf4j-api-1.7.25.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/lib/slf4j-simple-1.7.25.jar b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/lib/slf4j-simple-1.7.25.jar new file mode 100644 index 0000000..a7260f3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/lib/slf4j-simple-1.7.25.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/servlet/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/servlet/TestBean.java new file mode 100644 index 0000000..c696caf --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/servlet/TestBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +//Simple TestBean to test CDI. +public class TestBean +{ + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/servlet/TestLoggerProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/servlet/TestLoggerProducer.java new file mode 100644 index 0000000..f8e08a7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/servlet/TestLoggerProducer.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import javax.enterprise.inject.Produces; + + +public class TestLoggerProducer { + @Produces + public org.jboss.logging.Logger getLogger(){ + org.jboss.logging.Logger l = org.jboss.logging.Logger.getLogger(TestLoggerProducer.class); + System.out.println("getLogger:: " + l); + return l; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/servlet/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/servlet/TestServlet.java new file mode 100644 index 0000000..9145274 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/servlet/TestServlet.java
@@ -0,0 +1,85 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; +import java.util.Set; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.inject.Inject; +import javax.enterprise.inject.Any; +import javax.enterprise.inject.Default; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.util.AnnotationLiteral; +import javax.naming.InitialContext; + +@WebServlet(name="mytest", + urlPatterns={"/myurl"}, + initParams={ @WebInitParam(name="n1", value="v1"), @WebInitParam(name="n2", value="v2") } ) +public class TestServlet extends HttpServlet { + @Inject TestBean tb; + @Inject BeanManager bm; + @Inject TestBeanInWebInfLib tbiwil; + + BeanManager bm1; + + @Inject + private transient org.jboss.logging.Logger log; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + + ", n2=" + getInitParameter("n2"); + + if (tb == null) msg += "Bean injection into Servlet failed"; + if (tbiwil == null) msg += "Bean injection of a TestBean in WEB-INF/lib into Servlet failed"; + System.out.println("Test Bean from WEB-INF/lib=" + tbiwil); + + System.out.println("BeanManager is " + bm); + System.out.println("BeanManager via lookup is " + bm1); + if (bm == null) msg += "BeanManager Injection via @Inject failed"; + try { + bm1 = (BeanManager)((new InitialContext()).lookup("java:comp/BeanManager")); + } catch (Exception ex) { + ex.printStackTrace(); + msg += "BeanManager Injection via component environment lookup failed"; + } + if (bm1 == null) msg += "BeanManager Injection via component environment lookup failed"; + + //Check if Beans in WAR(WEB-INF/classes) and WEB-INF/lib/*.jar are visible + //via BeanManager of WAR + Set warBeans = bm.getBeans(TestBean.class,new AnnotationLiteral<Any>() {}); + if (warBeans.size() != 1) msg += "TestBean in WAR is not available via the WAR BeanManager"; + + Set webinfLibBeans = bm.getBeans(TestBeanInWebInfLib.class,new AnnotationLiteral<Any>() {}); + if (webinfLibBeans.size() != 1) msg += "TestBean in WEB-INF/lib is not available via the WAR BeanManager"; + System.out.println("Test Bean from WEB-INF/lib via BeanManager:" + webinfLibBeans); + + //Test injection into WEB-INF/lib beans + msg += tbiwil.testInjection(); + + writer.write("initParams: " + msg + "\n"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/util/TestBeanInWebInfLib.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/util/TestBeanInWebInfLib.java new file mode 100644 index 0000000..2658910 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/cdi-servlet-3.0-annotation-with-web-inf-lib/util/TestBeanInWebInfLib.java
@@ -0,0 +1,52 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.util.Set; + +import javax.enterprise.inject.Any; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; +import javax.enterprise.inject.spi.Bean; + +public class TestBeanInWebInfLib { + @Inject + BeanManager bm; + + @Inject + TestBean tb; + + public String testInjection() { + if (bm == null) { + return "Bean Manager not injected into the TestBean in WEB-INF/lib"; + } + System.out.println("BeanManager in WEB-INF/lib bean is " + bm); + + if (tb == null) { + return "Injection of WAR's TestBean into the TestBean in WEB-INF/lib failed"; + } + + Set<Bean<?>> webinfLibBeans = bm.getBeans(TestBeanInWebInfLib.class, + new AnnotationLiteral<Any>() {}); + if (webinfLibBeans.size() != 1){ + return "TestBean in WEB-INF/lib is not available via the WEB-INF/lib Bean's BeanManager"; + } + + // success + return ""; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/README new file mode 100644 index 0000000..344a368 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/README
@@ -0,0 +1,10 @@ +- Test support for enabled beans' classes deployed as an embedded RAR +[test originally from embeddedConnector1.5 test in Connectors developer tests] +section 12.1. Bean archives of JSR 299 spec: + +"Bean classes of enabled beans must be deployed in bean archives. +• A library jar, EJB jar, application client jar or rar archive is a +bean archive if it has a file named beans.xml in the META-INF +directory." + +In this test, an embedded RAR has a TestCDIBean Bean class. This is injected into a MDB in another ejb-jar in the EAR.
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/META-INF/application.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/META-INF/application.xml new file mode 100644 index 0000000..c911361 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/META-INF/application.xml
@@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN' 'http://java.sun.com/dtd/application_1_3.dtd'> +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<application> + <display-name>GenericMessageDrivenBean</display-name> + <description>Application description</description> + <module> + <connector>generic-ra.rar</connector> + </module> + <module> + <ejb>generic-embedded-ejb.jar</ejb> + </module> + <module> + <java>generic-embedded-client.jar</java> + </module> +</application>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/build.xml new file mode 100644 index 0000000..8be2ab7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/build.xml
@@ -0,0 +1,110 @@ +<!-- + + Copyright (c) 2002, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ + <!ENTITY common SYSTEM "../../../../../config/common.xml"> + <!ENTITY testcommon SYSTEM "../../../../../config/properties.xml"> + <!ENTITY database SYSTEM "../../../config/database.xml"> +]> + +<project name="connector1.5 MDB" default="all" basedir="."> + + <property name="j2ee.home" value="../../.."/> + <property name="earfile" value="generic-embedded.ear"/> + + + <!-- include common.xml and testcommon.xml --> + &database; + &common; + &testcommon; + + <target name="all" depends="init-common, clean-common"> + <ant dir="src" inheritAll="false" target="all"/> + <antcall target="build-ear"/> + <!-- + <antcall target="ear-common"> + <param name="appname" value="generic-embedded"/> + <param name="application.xml" value="META-INF/application.xml"/> + </antcall> + --> + </target> + + <target name="build-ear"> + + <delete file="${assemble.dir}/generic-embeddedApp.ear"/> + <mkdir dir="${assemble.dir}"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <ear earfile="${assemble.dir}/generic-embeddedApp.ear" + appxml="META-INF/application.xml"> + + <fileset dir="${assemble.dir}"> + <include name="*.jar"/> + <include name="*.war"/> + </fileset> + <fileset dir="../ra"> + <include name="*.rar"/> + </fileset> + <fileset dir="${env.APS_HOME}/lib"> + <include name="reporter.jar"/> + </fileset> + </ear> + + </target> + + <target name="setupJdbc" depends="init-common"> + <antcall target="create-jdbc-conpool-connector"> + <param name="db.class" value="org.apache.derby.jdbc.ClientXADataSource"/> + <param name="jdbc.conpool.name" value="jdbc-pointbase-pool1"/> + <param name="jdbc.resource.type" value="javax.sql.XADataSource"/> + </antcall> + <antcall target="create-jdbc-resource-common"> + <param name="jdbc.conpool.name" value="jdbc-pointbase-pool1"/> + <param name="jdbc.resource.name" value="jdbc/XAPointbase"/> + </antcall> + + <antcall target="execute-sql-connector"> + <param name="sql.file" value="createdb.sql"/> + </antcall> + </target> + + <target name="unsetJdbc" depends="init-common"> + <antcall target="delete-jdbc-resource-common"> + <param name="jdbc.resource.name" value="jdbc/XAPointbase"/> + </antcall> + <antcall target="delete-jdbc-connpool-common"> + <param name="jdbc.conpool.name" value="jdbc-pointbase-pool1"/> + </antcall> + </target> + + <target name="deploy-ear" depends="init-common"> + <antcall target="deploy-common"> + <param name="appname" value="generic-embedded"/> + </antcall> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-common"> + <param name="deployedapp.name" value="generic-embeddedApp"/> + <param name="appname" value="generic-embedded"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="clean-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/createdb.sql b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/createdb.sql new file mode 100644 index 0000000..7d93610 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/createdb.sql
@@ -0,0 +1,2 @@ +drop table MESSAGES; +create table MESSAGES (messageId CHAR(50), message varchar(80));
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/META-INF/application-client.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/META-INF/application-client.xml new file mode 100644 index 0000000..766d51c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/META-INF/application-client.xml
@@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE application-client PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN' 'http://java.sun.com/dtd/application-client_1_3.dtd'> +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<application-client> + <display-name>generic-embeddedClient</display-name> +</application-client> +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/META-INF/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/META-INF/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/META-INF/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/META-INF/ejb-jar.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/META-INF/ejb-jar.xml new file mode 100644 index 0000000..696dd3e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/META-INF/ejb-jar.xml
@@ -0,0 +1,112 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" + 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" + version="2.1"> + <display-name>Ejb1</display-name> + <enterprise-beans> + <message-driven> + <display-name>Generic_Message_Bean</display-name> + <ejb-name>GenericMessageBean</ejb-name> + <ejb-class>mdb.MyMessageBean</ejb-class> + <messaging-type>connector.MyMessageListener</messaging-type> + <transaction-type>Container</transaction-type> + <activation-config> + <activation-config-property> + <activation-config-property-name> + DestinationType + </activation-config-property-name> + <activation-config-property-value> + java.lang.String + </activation-config-property-value> + </activation-config-property> + <activation-config-property> + <activation-config-property-name> + TestProp + </activation-config-property-name> + <activation-config-property-value> + WrongValue + </activation-config-property-value> + </activation-config-property> + </activation-config> + <resource-ref> + <description>description</description> + <res-ref-name>MyDB</res-ref-name> + <res-type>javax.sql.DataSource</res-type> + <res-auth>Container</res-auth> + <res-sharing-scope>Shareable</res-sharing-scope> + </resource-ref> + </message-driven> + <session> + <display-name>MyMessageChecker</display-name> + <ejb-name>MyMessageChecker</ejb-name> + <home>beans.MessageCheckerHome</home> + <remote>beans.MessageChecker</remote> + <ejb-class>beans.MessageCheckerEJB</ejb-class> + <session-type>Stateless</session-type> + <transaction-type>Container</transaction-type> + <env-entry> + <env-entry-name>user</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + <env-entry-value>PBPUBLIC</env-entry-value> + </env-entry> + <env-entry> + <env-entry-name>password</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + <env-entry-value>PBPUBLIC</env-entry-value> + </env-entry> + <resource-ref> + <res-ref-name>MyDB</res-ref-name> + <res-type>javax.sql.DataSource</res-type> + <res-auth>Container</res-auth> + <res-sharing-scope>Shareable</res-sharing-scope> + </resource-ref> + <resource-env-ref> + <resource-env-ref-name>eis/testAdmin</resource-env-ref-name> + <resource-env-ref-type>connector.MyAdminObject</resource-env-ref-type> + </resource-env-ref> + <security-identity> + <use-caller-identity/> + </security-identity> + </session> + </enterprise-beans> + <assembly-descriptor> + <container-transaction> + <method> + <ejb-name>GenericMessageBean</ejb-name> + <method-name>onMessage</method-name> + <method-params> + <method-param>java.lang.String</method-param> + </method-params> + </method> + <trans-attribute>Required</trans-attribute> + </container-transaction> + <container-transaction> + <method> + <ejb-name>MyMessageChecker</ejb-name> + <method-intf>Remote</method-intf> + <method-name>getMessageCount</method-name> + </method> + <trans-attribute>Required</trans-attribute> + </container-transaction> + </assembly-descriptor> +</ejb-jar>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/META-INF/sun-application-client.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/META-INF/sun-application-client.xml new file mode 100644 index 0000000..2b9166a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/META-INF/sun-application-client.xml
@@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE sun-application-client PUBLIC "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Application Client 1.3//EN" "http://www.sun.com/software/sunone/appserver/dtds/sun-application-client_1_3-0.dtd"> +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<sun-application-client> +</sun-application-client> +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/META-INF/sun-ejb-jar.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/META-INF/sun-ejb-jar.xml new file mode 100644 index 0000000..de701df --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/META-INF/sun-ejb-jar.xml
@@ -0,0 +1,92 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 EJB 2.0//EN" "http://www.sun.com/software/sunone/appserver/dtds/sun-ejb-jar_2_0-0.dtd"> +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<sun-ejb-jar> + <enterprise-beans> + <module-name>ejb.jar</module-name> + <unique-id>1</unique-id> + <ejb> + <ejb-name>GenericMessageBean</ejb-name> + <mdb-resource-adapter> + <resource-adapter-mid>generic-embeddedApp#generic-ra</resource-adapter-mid> + <activation-config> + <activation-config-property> + <activation-config-property-name>DestinationName</activation-config-property-name> + <activation-config-property-value>Foo</activation-config-property-value> + </activation-config-property> + <activation-config-property> + <activation-config-property-name>TestProp</activation-config-property-name> + <activation-config-property-value>RightValue</activation-config-property-value> + </activation-config-property> + </activation-config> + </mdb-resource-adapter> + <ior-security-config> + <transport-config> + <integrity>supported</integrity> + <confidentiality>supported</confidentiality> + <establish-trust-in-target>supported</establish-trust-in-target> + <establish-trust-in-client>supported</establish-trust-in-client> + </transport-config> + <as-context> + <auth-method>username_password</auth-method> + <realm>default</realm> + <required>true</required> + </as-context> + <sas-context> + <caller-propagation>supported</caller-propagation> + </sas-context> + </ior-security-config> + <resource-ref> + <res-ref-name>MyDB</res-ref-name> + <jndi-name>jdbc/XAPointbase</jndi-name> + </resource-ref> + <gen-classes /> + </ejb> + <ejb> + <ejb-name>MyMessageChecker</ejb-name> + <jndi-name>MyMessageChecker</jndi-name> + <ior-security-config> + <transport-config> + <integrity>supported</integrity> + <confidentiality>supported</confidentiality> + <establish-trust-in-target>supported</establish-trust-in-target> + <establish-trust-in-client>supported</establish-trust-in-client> + </transport-config> + <as-context> + <auth-method>username_password</auth-method> + <realm>default</realm> + <required>false</required> + </as-context> + <sas-context> + <caller-propagation>supported</caller-propagation> + </sas-context> + </ior-security-config> + <resource-ref> + <res-ref-name>MyDB</res-ref-name> + <jndi-name>jdbc/XAPointbase</jndi-name> + </resource-ref> + <resource-env-ref> + <resource-env-ref-name>eis/testAdmin</resource-env-ref-name> + <jndi-name>eis/testAdmin</jndi-name> + </resource-env-ref> + <gen-classes/> + </ejb> + </enterprise-beans> +</sun-ejb-jar>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/beans/MessageChecker.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/beans/MessageChecker.java new file mode 100644 index 0000000..f582a2a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/beans/MessageChecker.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package beans; + +import java.rmi.RemoteException; + +import javax.ejb.EJBObject; + +public interface MessageChecker extends EJBObject { + int getMessageCount() throws RemoteException; + boolean done() throws RemoteException; + int expectedResults() throws RemoteException; + void notifyAndWait() throws RemoteException; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerEJB.java new file mode 100644 index 0000000..2751b06 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerEJB.java
@@ -0,0 +1,189 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package beans; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; + +import javax.ejb.CreateException; +import javax.ejb.EJBException; +import javax.ejb.SessionBean; +import javax.ejb.SessionContext; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.sql.DataSource; + +import connector.MyAdminObject; + +public class MessageCheckerEJB implements SessionBean { + + private int WAIT_TIME = 15; + private String user = "j2ee"; + private String password = "j2ee"; + private Properties beanProps = null; + private SessionContext sessionContext = null; + private Connection heldCon = null; + private MyAdminObject Controls; + + public MessageCheckerEJB() {} + + public void ejbCreate() + throws CreateException { + System.out.println("bean removed"); + heldCon = null; + /* + if (holdConnection) { + try { + heldCon = getDBConnection(); + } catch (Exception ex) { + ex.printStackTrace(); + throw new CreateException("Error in ejbCreate"); + } + } + */ + } + + public boolean done() { + return Controls.done(); + } + + public int expectedResults() { + return Controls.expectedResults(); + } + + public void notifyAndWait() { + try { + synchronized (Controls.getLockObject()) { + //Tell the resource adapter the client is ready to run + Controls.getLockObject().notifyAll(); + + debug("NOTIFIED... START WAITING"); + //Wait until being told to read from the database + Controls.getLockObject().wait(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public int getMessageCount() { + try { + Connection con = getFreshConnection(); + int count1 = getCount(con); + con.close(); + + /* + synchronized(Controls.getLockObject()) { + Controls.getLockObject().notify(); + } + */ + + return count1; + } catch (Exception e) { + e.printStackTrace(System.out); + throw new EJBException(e); + } + } + + private int getCount(Connection con) throws SQLException { + Statement stmt = con.createStatement(); + int count = 0; + String messages = ""; + ResultSet result = stmt.executeQuery( + "SELECT messageId, message "+ "FROM messages"); + while (result.next()) { + count++; + messages = messages + " - " + result.getString("messageId")+" "+ + result.getString("message") + "\n"; + } + messages = messages + "count = " + count; + System.out.println(messages); + stmt.close(); + return count; + } + + public void setSessionContext(SessionContext context) { + sessionContext = context; + try { + Context ic = new InitialContext(); + user = (String) ic.lookup("java:comp/env/user"); + password = (String) ic.lookup("java:comp/env/password"); + Controls = (MyAdminObject) ic.lookup("java:comp/env/eis/testAdmin"); + System.out.println("CALLING INITILIZE ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"); + Controls.initialize(); + System.out.println("CALLED INITILIZE ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void ejbRemove() { + System.out.println("bean removed"); + } + + public void ejbActivate() { + System.out.println("bean activated"); + } + + public void ejbPassivate() { + System.out.println("bean passivated"); + } + + private Connection getFreshConnection() throws Exception { + Connection oldHeldCon = heldCon; + heldCon = null; + Connection result = getDBConnection(); + heldCon = oldHeldCon; + return result; + } + + private Connection getDBConnection() throws Exception { + if (heldCon != null) return heldCon; + Connection con = null; + try { + Context ic = new InitialContext(); + DataSource ds = (DataSource) ic.lookup("java:comp/env/MyDB"); + debug("Looked up Datasource\n"); + debug("Get JDBC connection, auto sign on"); + con = ds.getConnection(); + + if (con != null) { + return con; + } else { + throw new Exception("Unable to get database connection "); + } + } catch (SQLException ex1) { + //ex1.printStackTrace(); + throw ex1; + } + } + + private void closeConnection(Connection con) throws SQLException { + if (heldCon != null) { + return; + } else { + con.close(); + } + } + + private void debug(String msg) { + System.out.println("[MessageCheckerEJB]:: -> " + msg); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerHome.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerHome.java new file mode 100644 index 0000000..9b56081 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerHome.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package beans; + +import java.rmi.RemoteException; + +import javax.ejb.CreateException; +import javax.ejb.EJBHome; + +public interface MessageCheckerHome extends EJBHome { + MessageChecker create() throws RemoteException, CreateException; + boolean done() throws RemoteException, CreateException; + int expectedResults() throws RemoteException, CreateException; + void notifyAndWait() throws RemoteException, CreateException; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/build.properties new file mode 100644 index 0000000..dad207b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/build.properties
@@ -0,0 +1,21 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +ejb-jar.xml=META-INF/ejb-jar.xml +sun-ejb-jar.xml=META-INF/sun-ejb-jar.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/build.xml new file mode 100644 index 0000000..b58b0c3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/build.xml
@@ -0,0 +1,68 @@ +<!-- + + Copyright (c) 2002, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ + <!ENTITY common SYSTEM "../../../../../../config/common.xml"> + <!ENTITY testcommon SYSTEM "../../../../../../config/properties.xml"> +]> + +<project name="connector1.5 MDB" default="all" basedir="."> + + <property name="j2ee.home" value="../../../.."/> + + <!-- include common.xml and testcommon.xml --> + &common; + &testcommon; + + <target name="all" depends="init-common"> + <antcall target="compile-common"> + <param name="src" value="." /> + <param name="s1astest.classpath" value="${s1astest.classpath}:../../ra/src/classes" /> + </antcall> + + <antcall target="ejb-jar-common"> + <param name="ejb-jar.xml" value="META-INF/ejb-jar.xml" /> + <param name="ejbjar.classes" value="mdb/*.class, beans/*.class, connector/*.class" /> + <param name="sun-ejb-jar.xml" value="META-INF/sun-ejb-jar.xml" /> + <param name="beans.xml" value="META-INF/beans.xml" /> + <param name="appname" value="generic-embedded" /> + </antcall> + + <antcall target="appclient-jar-common"> + <param name="appname" value="generic-embedded" /> + <param name="application-client.xml" value="META-INF/application-client.xml" /> + <param name="appclientjar.classes" value="mdb/*.class, beans/*.class, connector/*.class, client/Client.class" /> + <param name="sun-application-client.xml" value="META-INF/sun-application-client.xml" /> + </antcall> +<!-- + <jar jarfile="../ejb.jar" basedir="classes" + includes="mdb/*.class, beans/*.class, connector/*.class" > + <metainf dir="META-INF"> + <include name="ejb-jar.xml"/> + <include name="sun-ejb-jar.xml"/> + </metainf> + </jar> +--> + </target> + + <target name="clean"> + <antcall target="clean-classes-common"> + <param name="build.classes.dir" value="classes" /> + </antcall> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/client/Client.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/client/Client.java new file mode 100644 index 0000000..676b07b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/client/Client.java
@@ -0,0 +1,121 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package client; + +import javax.naming.InitialContext; +import javax.rmi.PortableRemoteObject; + +import beans.MessageChecker; +import beans.MessageCheckerHome; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +public class Client { + + private static final String TEST_NAME = " Embedded-Connector-1.5 test - "; + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + + public Client(String[] args) { + // super(args); + } + + public static void main(String[] args) { + Client client = new Client(args); + client.doTest(); + } + + public String doTest() { + stat.addDescription("This is to test connector 1.5 " + "contracts."); + + String res = "NOT RUN"; + debug("doTest() ENTER..."); + boolean pass = false; + try { + res = "ALL TESTS PASSED"; + int testCount = 1; + while (!done()) { + + notifyAndWait(); + if (!done()) { + debug("Running..."); + pass = checkResults(expectedResults()); + debug("Got expected results = " + pass); + + // do not continue if one test failed + if (!pass) { + res = "SOME TESTS FAILED"; + stat.addStatus(TEST_NAME + testCount, stat.FAIL); + break; + } else { + stat.addStatus(TEST_NAME + testCount, stat.PASS); + } + } else { + break; + } + testCount++; + } + + } catch (Exception ex) { + System.out.println("Importing transaction test failed."); + ex.printStackTrace(); + res = "TEST FAILED"; + } + + stat.printSummary(TEST_NAME); + + debug("EXITING... STATUS = " + res); + return res; + } + + private boolean checkResults(int num) throws Exception { + Object o = (new InitialContext()).lookup("MyMessageChecker"); + MessageCheckerHome home = (MessageCheckerHome) PortableRemoteObject + .narrow(o, MessageCheckerHome.class); + MessageChecker checker = home.create(); + int result = checker.getMessageCount(); + return result == num; + } + + private boolean done() throws Exception { + Object o = (new InitialContext()).lookup("MyMessageChecker"); + MessageCheckerHome home = (MessageCheckerHome) PortableRemoteObject + .narrow(o, MessageCheckerHome.class); + MessageChecker checker = home.create(); + return checker.done(); + } + + private int expectedResults() throws Exception { + Object o = (new InitialContext()).lookup("MyMessageChecker"); + MessageCheckerHome home = (MessageCheckerHome) PortableRemoteObject + .narrow(o, MessageCheckerHome.class); + MessageChecker checker = home.create(); + return checker.expectedResults(); + } + + private void notifyAndWait() throws Exception { + Object o = (new InitialContext()).lookup("MyMessageChecker"); + MessageCheckerHome home = (MessageCheckerHome) PortableRemoteObject + .narrow(o, MessageCheckerHome.class); + MessageChecker checker = home.create(); + checker.notifyAndWait(); + } + + private void debug(String msg) { + System.out.println("[CLIENT]:: --> " + msg); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/client/MANIFEST.MF b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/client/MANIFEST.MF new file mode 100644 index 0000000..179cd4d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/client/MANIFEST.MF
@@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Created-By: 1.4.0 (Sun Microsystems Inc.) +Main-Class: client.Client +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/connector/MyMessageListener.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/connector/MyMessageListener.java new file mode 100644 index 0000000..a3928d3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/connector/MyMessageListener.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +public interface MyMessageListener { + public void onMessage (String message); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/mdb/MyMessageBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/mdb/MyMessageBean.java new file mode 100644 index 0000000..caf41e9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/app/src/mdb/MyMessageBean.java
@@ -0,0 +1,230 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package mdb; + +import java.sql.Statement; + +import javax.ejb.MessageDrivenBean; +import javax.ejb.MessageDrivenContext; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.sql.DataSource; + +import connector.MyMessageListener; + +/** + */ +public class MyMessageBean implements MessageDrivenBean, MyMessageListener { + + private transient MessageDrivenContext mdc = null; + private Context context; + + @javax.inject.Inject + private connector.TestCDIBean tb; + + /** + * Constructor, which is public and takes no arguments. + */ + public MyMessageBean() { + } + + /** + * setMessageDrivenContext method, declared as public (but not final or + * static), with a return type of void, and with one argument of type + * javax.ejb.MessageDrivenContext. + * + * @param mdc + * the context to set + */ + public void setMessageDrivenContext(MessageDrivenContext mdc) { + this.mdc = mdc; + } + + /** + * ejbCreate method, declared as public (but not final or static), with a + * return type of void, and with no arguments. + */ + public void ejbCreate() { + } + + /** + * onMessage method, declared as public (but not final or static), with a + * return type of void, and with one argument of type javax.jms.Message. + * + * Casts the incoming Message to a TextMessage and displays the text. + * + * @param inMessage + * the incoming message + */ + public void onMessage(String inMessage) { + + debug("onMessage:: RECEIVED [" + inMessage + "]"); + debug("TestCDIBean injected:" + tb); + + if (tb == null) + throw new RuntimeException("Injection of enabled Bean " + + "in RAR into a MDB injection point failed"); + + try { + if (inMessage.endsWith("WRITE")) { + doDbStuff("WRITE", inMessage.substring(0, inMessage + .lastIndexOf(":"))); + } else if (inMessage.endsWith("DELETE")) { + doDbStuff("DELETE", inMessage.substring(0, inMessage + .lastIndexOf(":"))); + } else if (inMessage.endsWith("DELETE_ALL")) { + doDbStuff("DELETE_ALL", "::"); + } else { + // unsupported op. + } + } catch (Exception ex) { + debug("UH OH..."); + ex.printStackTrace(); + } + + } + + /** + * ejbRemove method, declared as public (but not final or static), with a + * return type of void, and with no arguments. + */ + public void ejbRemove() { + } + + private void doDbStuff(String op, String message) throws Exception { + + java.sql.Connection dbConnection = null; + String id = message.substring(0, message.indexOf(":")); + String body = message.substring(message.indexOf(":") + 1); + try { + Context ic = new InitialContext(); + + if ("READ".equals(op)) { + + debug("Reading row from database..."); + + // Creating a database connection + /* + * DataSource ds = (DataSource) ic.lookup("java:comp/env/MyDB"); + * debug("Looked up Datasource\n"); + * debug("Get JDBC connection, auto sign on"); dbConnection = + * ds.getConnection(); + * + * Statement stmt = dbConnection.createStatement(); String query + * = "SELECT id from messages where id = 'QQ'"; ResultSet + * results = stmt.executeQuery(query); results.next(); + * System.out.println("QQ has balance " + + * results.getInt("balance") + " dollars"); results.close(); + * stmt.close(); + * + * System.out.println("Read one account\n"); + */ + + } else if ("WRITE".equals(op)) { + + debug("Inserting one message in the database\n"); + + // Creating a database connection + DataSource ds = (DataSource) ic.lookup("java:comp/env/MyDB"); + // debug("Looked up Datasource\n"); + // debug("Get JDBC connection, auto sign on"); + dbConnection = ds.getConnection(); + + createRow(id, body, dbConnection); + System.out.println("Created one message\n"); + + } else if ("DELETE".equals(op)) { + + debug("Deleting one message from the database\n"); + + // Creating a database connection + DataSource ds = (DataSource) ic.lookup("java:comp/env/MyDB"); + // debug("Looked up Datasource\n"); + // debug("Get JDBC connection, auto sign on"); + dbConnection = ds.getConnection(); + + deleteRow(id, dbConnection); + System.out.println("Deleted one message\n"); + } else if ("DELETE_ALL".equals(op)) { + + debug("Deleting all messages from the database\n"); + + // Creating a database connection + DataSource ds = (DataSource) ic.lookup("java:comp/env/MyDB"); + // debug("Looked up Datasource\n"); + // debug("Get JDBC connection, auto sign on"); + dbConnection = ds.getConnection(); + deleteAll(dbConnection); + System.out.println("Deleted all messages\n"); + } else { + // unsupported op + } + + } finally { + try { + dbConnection.close(); + } catch (Exception ex) { + debug("Exception occured while closing database con nection."); + } + } + } + + private void createRow(String id, String body, + java.sql.Connection dbConnection) throws Exception { + + // Create row for this message + debug("CreateRow with ID = " + id + ", BODY = " + body); + Statement stmt = dbConnection.createStatement(); + String query = "INSERT INTO messages (messageId, message)" + + "VALUES ('" + id + "', '" + body + "')"; + int resultCount = stmt.executeUpdate(query); + if (resultCount != 1) { + throw new Exception("ERROR in INSERT !! resultCount = " + + resultCount); + } + stmt.close(); + } + + private void deleteRow(String id, java.sql.Connection dbConnection) + throws Exception { + + // Delete row for this message + debug("DeleteRow with ID = " + id); + Statement stmt = dbConnection.createStatement(); + String query = "DELETE FROM messages WHERE messageId = '" + id + "'"; + int resultCount = stmt.executeUpdate(query); + if (resultCount != 1) { + throw new Exception("ERROR in INSERT !! resultCount = " + + resultCount); + } + stmt.close(); + } + + private void deleteAll(java.sql.Connection dbConnection) throws Exception { + + // Delete row for this message + Statement stmt = dbConnection.createStatement(); + String query = "DELETE FROM messages"; + int resultCount = stmt.executeUpdate(query); + debug("Delete all rows from messages... count = " + resultCount); + stmt.close(); + } + + private void debug(String msg) { + System.out.println("[MyMessageBean] --> " + msg); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/build.xml new file mode 100644 index 0000000..ccd3fa5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/build.xml
@@ -0,0 +1,75 @@ +<!-- + + Copyright (c) 2002, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ + <!ENTITY common SYSTEM "../../../../config/common.xml"> + <!ENTITY testcommon SYSTEM "../../../../config/properties.xml"> +]> + +<project name="connector1.5 TEST" default="all" basedir="."> +<property name="j2ee.home" value="../.."/> +<property name="client.class" value="client/Client"/> + + <!-- include common.xml and testcommon.xml --> + &common; + &testcommon; + + <target name="all" depends="init-common, build, setup, runtest, unset"/> + <target name="build" depends="init-common"> + <ant dir="ra" inheritAll="false" target="all"/> + <ant dir="app" inheritAll="false" target="all"/> + </target> + + <target name="setup"> + <ant dir="app" inheritAll="false" target="setupJdbc"/> + <ant dir="." inheritAll="false" target="deploy"/> + </target> + + <target name="deploy"> + <ant dir="app" inheritAll="false" target="deploy-ear"/> + <ant dir="ra" inheritAll="false" target="testAddAdmin"/> + <ant dir="." inheritAll="false" target="restart"/> + </target> + + <target name="runtest" depends="init-common"> + <antcall target="runclient-common"> + <param name="appname" value="generic-embedded" /> + </antcall> + </target> + + <target name="unset"> + <ant dir="app" inheritAll="false" target="unsetJdbc"/> + <ant dir="." inheritAll="false" target="undeploy"/> + <ant dir="." inheritAll="false" target="restart"/> + </target> + + <target name="undeploy"> + <ant dir="ra" inheritAll="false" target="testDelAdmin"/> + <ant dir="app" inheritAll="false" target="undeploy"/> + </target> + + <target name="restart" depends="init-common"> + <echo message="Not required to restart"/> + </target> + + <target name="clean"> + <ant dir="ra" inheritAll="false" target="clean"/> + <ant dir="app" inheritAll="false" target="clean"/> + </target> + +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/createdb.sql b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/createdb.sql new file mode 100644 index 0000000..19f3324 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/createdb.sql
@@ -0,0 +1,2 @@ +drop table messages; +create table messages (messageId CHAR(50), message varchar(80));
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/META-INF/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/META-INF/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/META-INF/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/META-INF/ra.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/META-INF/ra.xml new file mode 100644 index 0000000..2ca2ebc --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/META-INF/ra.xml
@@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!-- +<!DOCTYPE connector PUBLIC '-//Sun Microsystems, Inc.//DTD Connector 1.5//EN' 'http://java.sun.com/dtd/connector_1_5.dtd'> +--> +<connector xmlns="http://java.sun.com/xml/ns/j2ee" + 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/connector_1_5.xsd" + version="1.5"> + <display-name>Simple Resource Adapter</display-name> + <vendor-name>Java Software</vendor-name> + <eis-type>Generic Type</eis-type> + <resourceadapter-version>1.0Alpha</resourceadapter-version> + <resourceadapter> + <resourceadapter-class> + connector.SimpleResourceAdapterImpl + </resourceadapter-class> + <config-property> + <config-property-name> + TestName + </config-property-name> + <config-property-type> + java.lang.String + </config-property-type> + <config-property-value> + ConfigPropertyForRA + </config-property-value> + </config-property> + <inbound-resourceadapter> + <messageadapter> + <messagelistener> + <messagelistener-type> + connector.MyMessageListener + </messagelistener-type> + <activationspec> + <activationspec-class> + connector.SimpleActivationSpec + </activationspec-class> + </activationspec> + </messagelistener> + </messageadapter> + </inbound-resourceadapter> + <adminobject> + <adminobject-interface>connector.MyAdminObject</adminobject-interface> + <adminobject-class>connector.MyAdminObject</adminobject-class> + <config-property> + <config-property-name>ResetControl</config-property-name> + <config-property-type>java.lang.String</config-property-type> + <config-property-value>NORESET</config-property-value> + </config-property> + <config-property> + <config-property-name>ExpectedResult</config-property-name> + <config-property-type>java.lang.Integer</config-property-type> + <config-property-value>88</config-property-value> + </config-property> + </adminobject> + </resourceadapter> +</connector>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/build.xml new file mode 100644 index 0000000..d483e8d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/build.xml
@@ -0,0 +1,83 @@ +<!-- + + Copyright (c) 2002, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ + <!ENTITY common SYSTEM "../../../../../config/common.xml"> + <!ENTITY props SYSTEM "../../../../../config/properties.xml"> +]> + +<project name="connector1.5 RA" default="all" basedir="."> + + <property name="j2ee.home" value="../../.."/> + <property name="earfile" value="generic-ra.rar"/> + + <!-- include common.xml and testcommon.xml --> + &common; + &props; + + <target name="all"> + <ant dir="src" inheritAll="false" target="all"/> + + <jar jarfile="generic-ra.rar" basedir="." + includes="generic-ra.jar, META-INF/ra.xml, META-INF/beans.xml" /> + </target> + + <target name="deploy" depends="init-common"> + <antcall target="asadmin-common"> + <param name="admin.command" value="deploy"/> + <param name="operand.props" value="generic-ra.rar"/> + </antcall> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="asadmin-common"> + <param name="admin.command" value="undeploy"/> + <param name="operand.props" value="generic-ra"/> + </antcall> + </target> + + <target name="testAddAdmin" depends="init-common"> + <antcall target="asadmin-common"> + <param name="admin.command" value="create-admin-object --target ${appserver.instance.name} --restype connector.MyAdminObject --raname generic-embeddedApp#generic-ra --property ResetControl=BEGINNING"/> + <param name="operand.props" value="eis/testAdmin"/> + </antcall> + </target> + + <target name="testDelAdmin" depends="init-common"> + <antcall target="asadmin-common"> + <param name="admin.command" value="delete-admin-object"/> + <param name="operand.props" value="--target ${appserver.instance.name} eis/testAdmin"/> + </antcall> + </target> + + <target name="sendMessage" depends="init-common"> + <echo message="Class path is ${s1astest.classpath}"/> + <java fork="true" classname="connector.Messages" failonerror="true"> + <arg line="add Foo TestMessage"/> + <classpath> + <pathelement location="${s1astest.classpath}"/> + <pathelement location="generic-ra.jar"/> + </classpath> + </java> + </target> + + <target name="clean"> + <ant dir="src" inheritAll="false" target="clean"/> + </target> + +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/build.xml new file mode 100644 index 0000000..ff8bcc2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/build.xml
@@ -0,0 +1,49 @@ +<!-- + + Copyright (c) 2002, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ + <!ENTITY common SYSTEM "../../../../../../config/common.xml"> + <!ENTITY props SYSTEM "../../../../../../config/properties.xml"> +]> + +<project name="connector1.5 RA SRC" default="all" basedir="."> + + + <!-- include common.xml and testcommon.xml --> + &common; + &props; + + <target name="all" depends="init-common" > + <antcall target="compile-common"> + <param name="build.classes.dir" value="classes" /> + <param name="src" value="connector" /> + </antcall> + <jar jarfile="../generic-ra.jar" basedir="classes" + includes="connector/*.class" /> + </target> + + + <target name="clean"> + <antcall target="clean-classes-common"> + <param name="build.classes.dir" value="classes" /> + </antcall> + <delete file="../generic-ra.jar"/> + <delete file="../generic-ra.rar"/> + </target> + +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/Controls.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/Controls.java new file mode 100644 index 0000000..3541235 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/Controls.java
@@ -0,0 +1,27 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +/** + * + * @author Qingqing Ouyang + */ +public class Controls { + public static Object readyLock = new Object(); + public static int expectedResults; + public static boolean done = false; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/DeliveryWork.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/DeliveryWork.java new file mode 100644 index 0000000..f4599fd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/DeliveryWork.java
@@ -0,0 +1,110 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import java.lang.reflect.Method; + +import javax.resource.spi.endpoint.MessageEndpoint; +import javax.resource.spi.work.Work; + +/** + * + * @author Qingqing Ouyang + */ +public class DeliveryWork implements Work { + + private MessageEndpoint ep; + private int num; + private String op; + private boolean keepCount; + private static int counter = 0; + + public DeliveryWork(MessageEndpoint ep, int numOfMessages, String op) { + this.ep = ep; + this.num = numOfMessages; + this.op = op; + this.keepCount = false; + } + + public DeliveryWork(MessageEndpoint ep, int numOfMessages, String op, + boolean keepCount) { + this.ep = ep; + this.num = numOfMessages; + this.op = op; + this.keepCount = keepCount; + } + + public void run() { + + debug("ENTER..."); + + try { + // Method onMessage = getOnMessageMethod(); + // ep.beforeDelivery(onMessage); + + if (!keepCount) { + for (int i = 0; i < num; i++) { + String msgId = String.valueOf(i); + String msgBody = "This is message " + msgId; + String msg = msgId + ":" + msgBody + ":" + op; + ((MyMessageListener) ep).onMessage(msg); + } + } else { + for (int i = 0; i < num; i++) { + String msgId = String.valueOf(i + counter); + String msgBody = "This is message " + msgId; + String msg = msgId + ":" + msgBody + ":" + op; + ((MyMessageListener) ep).onMessage(msg); + } + counter = counter + num; + } + + // ep.afterDelivery(); + + } catch (Exception ex) { + ex.printStackTrace(); + } + + debug("LEAVE..."); + } + + public void release() { + } + + public String toString() { + return op; + } + + private Method getOnMessageMethod() { + + Method onMessageMethod = null; + try { + Class msgListenerClass = connector.MyMessageListener.class; + Class[] paramTypes = { java.lang.String.class }; + onMessageMethod = msgListenerClass.getMethod("onMessage", + paramTypes); + + } catch (NoSuchMethodException ex) { + ex.printStackTrace(); + } + return onMessageMethod; + } + + private void debug(String mesg) { + System.out.println("DeliveryWork[" + op + "] --> " + mesg); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/FakeXAResource.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/FakeXAResource.java new file mode 100644 index 0000000..52d764a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/FakeXAResource.java
@@ -0,0 +1,121 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import javax.transaction.xa.XAException; +import javax.transaction.xa.XAResource; +import javax.transaction.xa.Xid; + +/** + * This is class is used for debugging. It prints out trace information on TM + * calls to XAResource before directing the call to the actual XAResource object + */ +public class FakeXAResource implements XAResource { + + public FakeXAResource() { + } + + public void commit(Xid xid, boolean onePhase) throws XAException { + print("FakeXAResource.commit: " + xidToString(xid) + "," + onePhase); + } + + public void end(Xid xid, int flags) throws XAException { + print("FakeXAResource.end: " + xidToString(xid) + "," + + flagToString(flags)); + } + + public void forget(Xid xid) throws XAException { + print("FakeXAResource.forget: " + xidToString(xid)); + } + + public int getTransactionTimeout() throws XAException { + return 60 * 1000; + } + + public boolean isSameRM(XAResource xares) throws XAException { + return false; + } + + public int prepare(Xid xid) throws XAException { + print("FakeXAResource.prepare: " + xidToString(xid)); + return XAResource.XA_OK; + } + + public Xid[] recover(int flag) throws XAException { + print("FakeXAResource.recover: " + flagToString(flag)); + return null; + } + + public void rollback(Xid xid) throws XAException { + print("FakeXAResource.rollback: " + xidToString(xid)); + } + + public boolean setTransactionTimeout(int seconds) throws XAException { + return false; + } + + public void start(Xid xid, int flags) throws XAException { + print("FakeXAResource.start: " + xidToString(xid) + "," + + flagToString(flags)); + throw new XAException(); + } + + private void print(String s) { + System.out.println(s); + } + + static public String xidToString(Xid xid) { + return String + .valueOf((new String(xid.getGlobalTransactionId()) + new String( + xid.getBranchQualifier())).hashCode()); + } + + static public String flagToString(int flag) { + switch (flag) { + case TMFAIL: + return "TMFAIL"; + case TMJOIN: + return "TMJOIN"; + case TMNOFLAGS: + return "TMNOFLAGS"; + case TMONEPHASE: + return "TMONEPHASE"; + case TMRESUME: + return "TMRESUME"; + case TMSTARTRSCAN: + return "TMSTARTRSCAN"; + case TMENDRSCAN: + return "TMENDRSCAN"; + case TMSUCCESS: + return "TMSUCCESS"; + case TMSUSPEND: + return "TMSUSPEND"; + case XA_RDONLY: + return "XA_RDONLY"; + default: + return "" + Integer.toHexString(flag); + } + } + + public boolean equals(Object obj) { + return false; + } + + public int hashCode() { + return 1; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/Messages.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/Messages.java new file mode 100644 index 0000000..597a34b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/Messages.java
@@ -0,0 +1,67 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import java.util.ArrayList; +import java.util.Hashtable; + +/** + * collection of messages. + * + * @author Qingqing Ouyang + */ +public class Messages { + + private static Hashtable messages = new Hashtable(); + + public static void sendMessage(String destName, String message) { + if (messages.get(destName) != null) { + ((ArrayList) messages.get(destName)).add(message); + } else { + ArrayList list = new ArrayList(); + list.add(message); + messages.put(destName, list); + } + System.out.println("sendMessage. message at foo is " + + Messages.hasMessages("Foo")); + } + + public static boolean hasMessages(String destName) { + return messages.get(destName) != null; + } + + public static ArrayList getMessages(String destName) { + return (ArrayList) messages.get(destName); + } + + public static void main(String[] args) { + if (args.length != 3) { + System.exit(1); + } + + String command = args[0]; + String destName = args[1]; + String message = args[2]; + + if (!"add".equals(command)) { + System.exit(1); + } + + sendMessage(destName, message); + System.out.println("Message : " + message + " sent to " + destName); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/MyAdminObject.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/MyAdminObject.java new file mode 100644 index 0000000..57bf91d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/MyAdminObject.java
@@ -0,0 +1,63 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +public class MyAdminObject implements java.io.Serializable { + + private String resetControl = "NORESET"; + private Integer expectedResults; + + public void setResetControl(String value) { + resetControl = value; + } + + public String getResetControl() { + return resetControl; + } + + public void setExpectedResults(Integer value) { + expectedResults = value; + } + + public Integer getExpectedResults() { + return expectedResults; + } + + public void initialize() { + System.out + .println("[MyAdminObject] Initializing the Controls to false:" + + resetControl); + if (resetControl.equals("BEGINNING")) { + Controls.done = false; + System.out + .println("[MyAdminObject] Initialized the Controls to false"); + } + } + + public boolean done() { + return Controls.done; + } + + public int expectedResults() { + return Controls.expectedResults; + } + + public Object getLockObject() { + return Controls.readyLock; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/MyMessageListener.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/MyMessageListener.java new file mode 100644 index 0000000..9e58d7e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/MyMessageListener.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +public interface MyMessageListener { + public void onMessage(String message); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/MyWork.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/MyWork.java new file mode 100644 index 0000000..7172677 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/MyWork.java
@@ -0,0 +1,101 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import java.lang.reflect.Method; + +import javax.resource.spi.endpoint.MessageEndpointFactory; +import javax.resource.spi.work.Work; +import javax.resource.spi.work.WorkManager; + +/** + * + * @author Qingqing Ouyang + */ +public class MyWork implements Work { + + private String name; + private boolean stop = false; + private MessageEndpointFactory factory; + private WorkManager wm; + + public MyWork(String name, MessageEndpointFactory factory, WorkManager wm) { + this.factory = factory; + this.name = name; + this.wm = wm; + } + + public void run() { + + debug("ENTER..."); + + // try 3 times to create endpoint (in case of failure) + for (int i = 0; i < 3; i++) { + + try { + + Method onMessage = getOnMessageMethod(); + System.out.println("isDeliveryTransacted = " + + factory.isDeliveryTransacted(onMessage)); + + /* + * MessageEndpoint ep = factory.createEndpoint(null); + * ep.beforeDelivery(onMessage); ((MyMessageListener) + * ep).onMessage(name + ": TEST MSG ONE"); ((MyMessageListener) + * ep).onMessage(name + ": TEST MSG TWO"); ((MyMessageListener) + * ep).onMessage(name + ": TEST MSG THREE"); ep.afterDelivery(); + * break; + */ + + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + debug("LEAVE..."); + } + + public void release() { + } + + public void stop() { + this.stop = true; + } + + public String toString() { + return name; + } + + public Method getOnMessageMethod() { + + Method onMessageMethod = null; + try { + Class msgListenerClass = connector.MyMessageListener.class; + Class[] paramTypes = { java.lang.String.class }; + onMessageMethod = msgListenerClass.getMethod("onMessage", + paramTypes); + + } catch (NoSuchMethodException ex) { + ex.printStackTrace(); + } + return onMessageMethod; + } + + private void debug(String mesg) { + System.out.println("MyWork[" + name + "] --> " + mesg); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/SimpleActivationSpec.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/SimpleActivationSpec.java new file mode 100644 index 0000000..4f4840e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/SimpleActivationSpec.java
@@ -0,0 +1,85 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import javax.resource.spi.ActivationSpec; +import javax.resource.spi.ResourceAdapter; + +/** + * This class is supposed to implemented as a JavaBean so that the app server + * can instantiate and configure it at the runtime. + * + * @author Qingqing Ouyang + */ +public class SimpleActivationSpec implements ActivationSpec, + java.io.Serializable { + + private String destinationName; + private String destinationType; + private String testProp; + private ResourceAdapter resourceadapter; + + /** + * Default constructor. + */ + public SimpleActivationSpec() { + } + + public String getDestinationName() { + return this.destinationName; + } + + public void setDestinationName(String name) { + debug("setDestinationName() called... name = " + name); + this.destinationName = name; + } + + public String getDestinationType() { + return this.destinationType; + } + + public void setDestinationType(String type) { + debug("setDestinationType () called... type = " + type); + this.destinationType = type; + } + + public String getTestProp() { + return this.testProp; + } + + public void setTestProp(String testProp) { + debug("setTestProp () called... testProp = " + testProp); + this.testProp = testProp; + } + + public ResourceAdapter getResourceAdapter() { + debug("getResourceAdapter() called... "); + return this.resourceadapter; + } + + public void setResourceAdapter(ResourceAdapter ra) { + debug("setResourceAdapter() called... ra = " + ra); + this.resourceadapter = ra; + } + + public void validate() { + } + + private void debug(String message) { + System.out.println("[SimpleActivationSpec] ==> " + message); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/SimpleResourceAdapterImpl.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/SimpleResourceAdapterImpl.java new file mode 100644 index 0000000..11bfe89 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/SimpleResourceAdapterImpl.java
@@ -0,0 +1,224 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import java.util.Timer; + +import javax.resource.NotSupportedException; +import javax.resource.ResourceException; +import javax.resource.spi.ActivationSpec; +import javax.resource.spi.BootstrapContext; +import javax.resource.spi.ResourceAdapter; +import javax.resource.spi.ResourceAdapterInternalException; +import javax.resource.spi.UnavailableException; +import javax.resource.spi.XATerminator; +import javax.resource.spi.endpoint.MessageEndpointFactory; +import javax.resource.spi.work.ExecutionContext; +import javax.resource.spi.work.Work; +import javax.resource.spi.work.WorkManager; +import javax.transaction.xa.XAResource; +import javax.transaction.xa.Xid; + +/** + * This is a sample resource adapter + * + * @author Qingqing Ouyang + */ +public class SimpleResourceAdapterImpl implements ResourceAdapter, + java.io.Serializable { + + private BootstrapContext ctx; + private WorkManager wm; + private String testName; + + private boolean debug = true; + private Work work; + + public SimpleResourceAdapterImpl() { + debug("constructor..."); + } + + public void start(BootstrapContext ctx) + throws ResourceAdapterInternalException { + + debug("001. Simple RA start..."); + + this.ctx = ctx; + debug("002. Simple RA start..."); + this.wm = ctx.getWorkManager(); + debug("003. Simple RA start..."); + + // testing creat timer + Timer timer = null; + try { + timer = ctx.createTimer(); + } catch (UnavailableException ue) { + System.out.println("Error"); + throw new ResourceAdapterInternalException("Error form bootstrap"); + } + debug("004. Simple RA start..."); + + try { + + XATerminator xa = ctx.getXATerminator(); + + Xid xid1 = new XID(); + System.out.println(" XID1 = " + xid1); + + ExecutionContext ec = new ExecutionContext(); + ec.setXid(xid1); + ec.setTransactionTimeout(5 * 1000); // 5 seconds + TestWMWork outw = new TestWMWork(1000, false, true, ec); + outw.setWorkManager(wm); + try { + wm.doWork(outw, 1 * 1000, ec, null); + xa.commit(xid1, true); + } catch (Exception ex) { + + System.out.println(" ex = " + ex.getMessage()); + xa.rollback(xid1); + } + + Xid xid2 = new XID(); + System.out.println(" XID2 = " + xid2); + + ec = new ExecutionContext(); + ec.setXid(xid2); + ec.setTransactionTimeout(5 * 1000); // 5 seconds + TestWMWork anotherw = new TestWMWork(3000, false); + anotherw.setWorkManager(wm); + try { + wm.doWork(anotherw, 1 * 1000, ec, null); + xa.commit(xid2, true); + } catch (Exception ex) { + xa.rollback(xid2); + } + + } catch (Exception ex) { + ex.printStackTrace(); + } + + for (int i = 0; i < 3; i++) { + TestWMWork w = new TestWMWork(i, false); + try { + wm.doWork(w, 1, null, null); + } catch (Exception ex) { + System.out.println("FAIL: CAUGHT exception : i = " + i); + ex.printStackTrace(); + } + } + + for (int i = 3; i < 6; i++) { + TestWMWork w = new TestWMWork(i, true); + boolean pass = false; + try { + wm.doWork(w, 1, null, null); + } catch (Exception ex) { + pass = true; + System.out.println("PASS: CAUGHT EXPECTED exception : i = " + + i); + ex.printStackTrace(); + } finally { + if (!pass) { + System.out + .println("FAIL: DID NOT GET EXPECTED exception :"); + } + } + } + + for (int i = 6; i < 9; i++) { + TestWMWork w = new TestWMWork(i, false); + try { + wm.doWork(w, 1, null, null); + } catch (Exception ex) { + System.out.println("FAIL: CAUGHT exception : i = " + i); + ex.printStackTrace(); + } + } + + for (int i = 9; i < 12; i++) { + TestWMWork w = new TestWMWork(i, false); + try { + wm.startWork(w); + } catch (Exception ex) { + System.out.println("FAIL: CAUGHT exception : i = " + i); + ex.printStackTrace(); + } + } + + for (int i = 12; i < 15; i++) { + TestWMWork w = new TestWMWork(i, false); + try { + wm.scheduleWork(w); + } catch (Exception ex) { + System.out.println("FAIL: CAUGHT exception : i = " + i); + ex.printStackTrace(); + } + } + + debug("005. Simple RA start..."); + } + + public void stop() { + debug("999. Simple RA stop..."); + if (work != null) { + ((WorkDispatcher) work).stop(); + + synchronized (Controls.readyLock) { + Controls.readyLock.notify(); + } + + } + } + + public void endpointActivation(MessageEndpointFactory factory, + ActivationSpec spec) throws NotSupportedException { + try { + debug("B.000. Create and schedule Dispatcher"); + work = new WorkDispatcher("DISPATCHER", ctx, factory, spec); + wm.scheduleWork(work, 4 * 1000, null, null); + debug("B.001. Scheduled Dispatcher"); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void endpointDeactivation(MessageEndpointFactory endpointFactory, + ActivationSpec spec) { + debug("endpointDeactivation called..."); + ((WorkDispatcher) work).stop(); + } + + public String getTestName() { + return testName; + } + + public void setTestName(String name) { + debug("setTestName called... name = " + name); + testName = name; + } + + public void debug(String message) { + if (debug) + System.out.println("[SimpleResourceAdapterImpl] ==> " + message); + } + + public XAResource[] getXAResources(ActivationSpec[] specs) + throws ResourceException { + throw new UnsupportedOperationException(); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/TestCDIBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/TestCDIBean.java new file mode 100644 index 0000000..c4ec82d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/TestCDIBean.java
@@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +//A test CDI bean that is bundled along with an embedded RAR +public class TestCDIBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/TestWMWork.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/TestWMWork.java new file mode 100644 index 0000000..9458496 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/TestWMWork.java
@@ -0,0 +1,110 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import javax.resource.spi.work.ExecutionContext; +import javax.resource.spi.work.Work; +import javax.resource.spi.work.WorkException; +import javax.resource.spi.work.WorkManager; + +/** + * + * @author Qingqing Ouyang + */ +public class TestWMWork implements Work { + + private boolean stop = false; + private int id; + private boolean isRogue; + private boolean doNest; + private WorkManager wm; + private ExecutionContext ctx; + + public TestWMWork(int id, boolean isRogue) { + this(id, isRogue, false, null); + } + + public TestWMWork(int id, boolean isRogue, boolean doNest, + ExecutionContext ctx) { + this.id = id; + this.isRogue = isRogue; + this.doNest = doNest; + this.ctx = ctx; + } + + public void setWorkManager(WorkManager wm) { + this.wm = wm; + } + + public void run() { + + System.out.println("TestWMWork[" + id + "].start running"); + if (!isRogue) { + try { + Thread.currentThread().sleep(1000); + } catch (Exception ex) { + System.out.println("TestWMWork[" + id + "].interrupted = "); + ex.printStackTrace(); + } + } else { + System.out + .println("TestWMWork: Simulating rogue RA's Work: Expected Arithmetic Exception - divide by Zero"); + int j = 100 / 0; + } + + if (doNest && (wm != null)) { + Work nestedWork = new TestWMWork(8888, false); + try { + wm.doWork(nestedWork, 1 * 1000, ctx, null); + } catch (WorkException ex) { + if (ex.getErrorCode().equals( + WorkException.TX_CONCURRENT_WORK_DISALLOWED)) { + System.out.println("TestWMWork[" + id + "] " + + "PASS: CAUGHT EXPECTED = " + ex.getErrorCode()); + } else { + System.out.println("TestWMWork[" + id + "] " + + "FAIL: CAUGHT UNEXPECTED = " + + ex.getErrorCode()); + } + } + + nestedWork = new TestWMWork(9999, false); + try { + ExecutionContext ec = new ExecutionContext(); + ec.setXid(new XID()); + ec.setTransactionTimeout(5 * 1000); // 5 seconds + wm.doWork(nestedWork, 1 * 1000, ec, null); + } catch (Exception ex) { + System.out.println("TestWMWork[" + id + "] " + + "FAIL: CAUGHT UNEXPECTED = " + ex.getMessage()); + } + } + + System.out.println("TestWMWork[" + id + "].stop running"); + } + + public void release() { + } + + public void stop() { + this.stop = true; + } + + public String toString() { + return String.valueOf(id); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/WorkDispatcher.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/WorkDispatcher.java new file mode 100644 index 0000000..febd104 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/WorkDispatcher.java
@@ -0,0 +1,323 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import java.lang.reflect.Method; + +import javax.resource.spi.ActivationSpec; +import javax.resource.spi.BootstrapContext; +import javax.resource.spi.UnavailableException; +import javax.resource.spi.XATerminator; +import javax.resource.spi.endpoint.MessageEndpoint; +import javax.resource.spi.endpoint.MessageEndpointFactory; +import javax.resource.spi.work.ExecutionContext; +import javax.resource.spi.work.Work; +import javax.resource.spi.work.WorkManager; +import javax.transaction.xa.XAException; +import javax.transaction.xa.XAResource; +import javax.transaction.xa.Xid; + +/** + * + * @author Qingqing Ouyang + */ +public class WorkDispatcher implements Work { + + private boolean stop = false; + private String id; + private MessageEndpointFactory factory; + private BootstrapContext ctx; + private ActivationSpec spec; + private WorkManager wm; + private XATerminator xa; + + public WorkDispatcher(String id, BootstrapContext ctx, + MessageEndpointFactory factory, ActivationSpec spec) { + this.id = id; + this.ctx = ctx; + this.factory = factory; + this.spec = spec; + this.wm = ctx.getWorkManager(); + this.xa = ctx.getXATerminator(); + } + + public void run() { + + debug("ENTER..."); + + try { + synchronized (Controls.readyLock) { + debug("WAIT..."); + Controls.readyLock.wait(); + + if (stop) { + return; + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + + debug("Running..."); + + // try 3 times to create endpoint (in case of failure) + for (int i = 0; i < 3; i++) { + + try { + + Method onMessage = getOnMessageMethod(); + System.out.println("isDeliveryTransacted = " + + factory.isDeliveryTransacted(onMessage)); + + if (!factory.isDeliveryTransacted(onMessage)) { + // MessageEndpoint ep = factory.createEndpoint(null); + // DeliveryWork d = new DeliveryWork("NO_TX", ep); + // wm.doWork(d, 0, null, null); + } else { + + // MessageEndpoint ep = factory.createEndpoint(null); + MessageEndpoint ep = factory + .createEndpoint(new FakeXAResource()); + int numOfMessages = 5; + + // importing transaction + + // write/commit + ExecutionContext ec = startTx(); + debug("Start TX - " + ec.getXid()); + + DeliveryWork w = new DeliveryWork(ep, numOfMessages, + "WRITE"); + wm.doWork(w, 0, ec, null); + xa.commit(ec.getXid(), true); + + debug("DONE WRITE TO DB"); + Controls.expectedResults = numOfMessages; + notifyAndWait(); + + // delete/rollback + ec = startTx(); + debug("Start TX - " + ec.getXid()); + + w = new DeliveryWork(ep, numOfMessages, "DELETE"); + wm.doWork(w, 0, ec, null); + xa.rollback(ec.getXid()); + + debug("DONE ROLLBACK FROM DB"); + Controls.expectedResults = numOfMessages; + notifyAndWait(); + + // delete/commit + ec = startTx(); + debug("Start TX - " + ec.getXid()); + + w = new DeliveryWork(ep, numOfMessages, "DELETE"); + wm.doWork(w, 0, ec, null); + xa.commit(ec.getXid(), true); + + debug("DONE DELETE FROM DB"); + Controls.expectedResults = 0; + notifyAndWait(); + + // write/commit + ec = startTx(); + debug("Start TX - " + ec.getXid()); + + w = new DeliveryWork(ep, numOfMessages, "WRITE"); + wm.doWork(w, 0, ec, null); + xa.commit(ec.getXid(), true); + + debug("DONE WRITE TO DB"); + Controls.expectedResults = numOfMessages; + notifyAndWait(); + + // delete/commit + ec = startTx(); + debug("Start TX - " + ec.getXid()); + + w = new DeliveryWork(ep, numOfMessages, "DELETE"); + wm.doWork(w, 0, ec, null); + xa.commit(ec.getXid(), true); + + debug("DONE DELETE FROM DB"); + Controls.expectedResults = 0; + notifyAndWait(); + + // write multiple times using doWork/commit + ec = startTx(); + debug("Start TX - " + ec.getXid()); + + w = new DeliveryWork(ep, 1, "WRITE", true); + wm.doWork(w, 0, ec, null); + wm.doWork(w, 0, ec, null); + wm.doWork(w, 0, ec, null); + xa.commit(ec.getXid(), true); + + debug("DONE WRITE TO DB"); + Controls.expectedResults = 3; + notifyAndWait(); + + // write multiple times using doWork/rollback + ec = startTx(); + debug("Start TX - " + ec.getXid()); + + w = new DeliveryWork(ep, 1, "WRITE", true); + wm.doWork(w, 0, ec, null); + wm.doWork(w, 0, ec, null); + wm.doWork(w, 0, ec, null); + xa.rollback(ec.getXid()); + + debug("DONE WRITE TO DB"); + Controls.expectedResults = 3; + notifyAndWait(); + + ec = startTx(); + debug("Start TX - " + ec.getXid()); + + // write multiple times using doWork/rollback + w = new DeliveryWork(ep, 2, "WRITE", true); + wm.doWork(w, 0, ec, null); + wm.doWork(w, 0, ec, null); + wm.doWork(w, 0, ec, null); + + if (XAResource.XA_OK == xa.prepare(ec.getXid())) { + xa.commit(ec.getXid(), false); + debug("XA PREPARE/COMMIT. DONE WRITE TO DB "); + Controls.expectedResults = 9; + notifyAndWait(); + } else { + xa.rollback(ec.getXid()); + debug("XA PREPARE UNSUCCESSFUL. DONE ROLLBACK"); + Controls.expectedResults = 3; + notifyAndWait(); + } + + // delete all. + ec = startTx(); + debug("Start TX - " + ec.getXid()); + + w = new DeliveryWork(ep, 1, "DELETE_ALL"); + wm.doWork(w, 0, ec, null); + xa.commit(ec.getXid(), true); + + debug("DONE DELETE ALL FROM DB"); + Controls.expectedResults = 0; + notifyAndWait(); + + done(); + } + + break; + } catch (UnavailableException ex) { + // ex.printStackTrace(); + System.out.println("WorkDispatcher[" + id + + "] Endpoint Unavailable"); + try { + Thread.currentThread().sleep(3 * 1000); // 3 seconds + } catch (Exception e) { + e.printStackTrace(); + } + } catch (XAException ex) { + ex.printStackTrace(); + System.out.println("ERROR CODE = " + ex.errorCode); + done(); + break; + } catch (Exception ex) { + ex.printStackTrace(); + done(); + break; + } + } + + debug("LEAVE..."); + } + + public void release() { + } + + public void stop() { + this.stop = true; + } + + public String toString() { + return id; + } + + public Method getOnMessageMethod() { + + Method onMessageMethod = null; + try { + Class msgListenerClass = connector.MyMessageListener.class; + Class[] paramTypes = { java.lang.String.class }; + onMessageMethod = msgListenerClass.getMethod("onMessage", + paramTypes); + + } catch (NoSuchMethodException ex) { + ex.printStackTrace(); + } + return onMessageMethod; + } + + private ExecutionContext startTx() { + ExecutionContext ec = new ExecutionContext(); + try { + Xid xid = new XID(); + ec.setXid(xid); + ec.setTransactionTimeout(5 * 1000); // 5 seconds + } catch (Exception ex) { + ex.printStackTrace(); + } + return ec; + } + + private void notifyAndWait() { + try { + // Sleep for 5 seconds + // Thread.currentThread().sleep(5*1000); + + synchronized (Controls.readyLock) { + // Notify the client to check the results + Controls.readyLock.notify(); + + // Wait until results are verified by the client + Controls.readyLock.wait(); + + if (stop) { + return; + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + private void done() { + try { + Controls.done = true; + synchronized (Controls.readyLock) { + // Notify the client to check the results + Controls.readyLock.notify(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + private void debug(String mesg) { + System.out.println("Dispatcher[" + id + "] --> " + mesg); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/XID.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/XID.java new file mode 100644 index 0000000..191b904 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/embedded-resource-adapter-as-bean-archive/ra/src/connector/XID.java
@@ -0,0 +1,125 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import javax.transaction.xa.Xid; + +/** + * The XID class provides an implementation of the X/Open transaction identifier + * it implements the javax.transaction.xa.Xid interface. + */ +public class XID implements Xid { + + private static int ID = initializeID(); + + private static int initializeID() { + return (int) (Math.random() * 100000); + } + + public int formatID; // Format identifier + // (-1) means that the XID is null + public int branchQualifier; + public int globalTxID; + + static public final int MAXGTRIDSIZE = 64; + static public final int MAXBQUALSIZE = 64; + + public XID() { + int foo = ID++; + formatID = foo; + branchQualifier = foo; + globalTxID = foo; + } + + public boolean equals(Object o) { + XID other; // The "other" XID + int L; // Combined gtrid_length + bqual_length + int i; + + if (!(o instanceof XID)) // If the other XID isn't an XID + { + return false; // It can't be equal + } + + other = (XID) o; // The other XID, now properly cast + + if (this.formatID == other.formatID + && this.branchQualifier == other.branchQualifier + && this.globalTxID == other.globalTxID) { + return true; + } + + return false; + } + + /** + * Compute the hash code. + * + * @return the computed hashcode + */ + public int hashCode() { + if (formatID == (-1)) { + return (-1); + } + + return formatID + branchQualifier + globalTxID; + + } + + /* + * Convert to String + * + * <p> This is normally used to display the XID when debugging. + */ + + /** + * Return a string representing this XID. + * + * @return the string representation of this XID + */ + public String toString() { + + String s = new String("{XID: " + "formatID(" + formatID + "), " + + "branchQualifier (" + branchQualifier + "), " + + "globalTxID(" + globalTxID + ")}"); + + return s; + } + + /* + * Return branch qualifier + */ + + /** + * Returns the branch qualifier for this XID. + * + * @return the branch qualifier + */ + public byte[] getBranchQualifier() { + String foo = (new Integer(branchQualifier)).toString(); + return foo.getBytes(); + } + + public int getFormatId() { + return formatID; + } + + public byte[] getGlobalTransactionId() { + String foo = (new Integer(globalTxID)).toString(); + return foo.getBytes(); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/README new file mode 100644 index 0000000..4d99b31 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/README
@@ -0,0 +1,3 @@ +Test +- Test whether the proxy to a no-interface local EJB is serializable +Issue 12599 \ No newline at end of file
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/build.properties new file mode 100644 index 0000000..706d46a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/build.properties
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-no-interface-local-view-proxy-serializable"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="persistence.xml" value="descriptor/persistence.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/build.xml new file mode 100644 index 0000000..295d086 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/build.xml
@@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,create-resources,deploy,run,undeploy,delete-resources" /> + + <target name="clean" depends="init-common"> + <antcall target="clean-common" /> + <delete> + <fileset dir="." includes="*.class" /> + <fileset dir="client/test/client" includes="*.class" /> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet" /> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes" /> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes" /> + <param name="webclient.war.classes" value="**/*.class" /> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" includes="test/client/WebTest.java" /> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common" /> + </target> + + <target name="create-resources" depends="init-common"> + <antcall target="create-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + <antcall target="create-jdbc-resource-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + </target> + + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}" /> + <arg value="${http.port}" /> + <arg value="${contextroot}" /> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar" /> + <pathelement location="client" /> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common" /> + </target> + + <target name="delete-resources" depends="init-common"> + <antcall target="delete-jdbc-resource-common"> + <param name="jdbc.resource.name" value="jdbc/jdbc-dev-test-resource" /> + </antcall> + + <antcall target="delete-jdbc-connpool-common"> + <param name="jdbc.connpool.name" value="jdbc-dev-test-pool" /> + </antcall> + </target> + + <target name="usage"> + <antcall target="usage-common" /> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/client/test/client/WebTest.java new file mode 100644 index 0000000..08ed734 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/client/test/client/WebTest.java
@@ -0,0 +1,113 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +@SuppressWarnings("deprecation") +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "no-interface-local-view-proxy-serializable"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for Java EE resource injection"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, SimpleReporterAdapter.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, SimpleReporterAdapter.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, SimpleReporterAdapter.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, SimpleReporterAdapter.FAIL); + } + } + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/descriptor/persistence.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/descriptor/persistence.xml new file mode 100644 index 0000000..82f2d7b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/descriptor/persistence.xml
@@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> + <persistence-unit name="pu1" transaction-type="JTA"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <jta-data-source>jdbc/__default</jta-data-source> + <non-jta-data-source>jdbc/__default</non-jta-data-source> + <class>myapp.Department</class> + <class>myapp.Employee</class> + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> + <property name="eclipselink.logging.level" value="INFO"/> + </properties> + </persistence-unit> +</persistence>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..47668a4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void setState(String s); + public String getState(); + + public void method1(); +} + +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/servlet/test/beans/nonmock/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/servlet/test/beans/nonmock/TestBean.java new file mode 100644 index 0000000..5099e36 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/servlet/test/beans/nonmock/TestBean.java
@@ -0,0 +1,62 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import java.io.Serializable; + +import javax.enterprise.context.SessionScoped; +import javax.inject.Inject; + +import test.beans.TestBeanInterface; +import test.ejb.HelloNoInterfaceLocalViewSfulEJB; +import test.ejb.HelloNoInterfaceLocalViewSlessEJB; + + +@SessionScoped +public class TestBean implements TestBeanInterface, Serializable{ + public static boolean testBeanInvoked = false; + + @Inject + HelloNoInterfaceLocalViewSfulEJB sfulEJB; + + @Inject + HelloNoInterfaceLocalViewSlessEJB slessEJB; + + @Override + public void setState(String s) { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + sfulEJB.setState(s); + } + + @Override + public String getState() { + System.out.println("TestBean::m2 called"); + return sfulEJB.getState(); + } + + @Override + public String toString(){ + return "TestBean::ejb=" + sfulEJB; + } + + @Override + public void method1() { + slessEJB.method1("World"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/servlet/test/ejb/HelloNoInterfaceLocalViewSfulEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/servlet/test/ejb/HelloNoInterfaceLocalViewSfulEJB.java new file mode 100644 index 0000000..0abcba6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/servlet/test/ejb/HelloNoInterfaceLocalViewSfulEJB.java
@@ -0,0 +1,33 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb; + +import javax.ejb.Stateful; + +@Stateful +public class HelloNoInterfaceLocalViewSfulEJB { + + private String message; + public void setState(String msg){ + this.message = msg; + + } + public String getState() { + return this.message; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/servlet/test/ejb/HelloNoInterfaceLocalViewSlessEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/servlet/test/ejb/HelloNoInterfaceLocalViewSlessEJB.java new file mode 100644 index 0000000..4818e1f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/servlet/test/ejb/HelloNoInterfaceLocalViewSlessEJB.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb; + +import javax.ejb.Stateful; + +@Stateful +public class HelloNoInterfaceLocalViewSlessEJB { + public void method1(String msg) { + System.out.println("Hello" + msg); + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/servlet/test/servlet/NoInterfaceProxySerializableEJBTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/servlet/test/servlet/NoInterfaceProxySerializableEJBTestServlet.java new file mode 100644 index 0000000..13a603b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/no-interface-local-view-proxy-serializable/servlet/test/servlet/NoInterfaceProxySerializableEJBTestServlet.java
@@ -0,0 +1,81 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestBeanInterface; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class NoInterfaceProxySerializableEJBTestServlet extends HttpServlet { + + @Inject + TestBeanInterface tbi; + + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, + IOException { + PrintWriter writer = response.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + // set state + tbi.setState("TEST"); + + // Test serializability of EJB in TestBean. + try { + File tmpFile = File.createTempFile("SerializableProxyTest", null); + FileOutputStream fout = new FileOutputStream(tmpFile); + ObjectOutputStream oos = new ObjectOutputStream(fout); + System.out.println("Writing " + tbi + " to file-" + tmpFile); + oos.writeObject(tbi); + oos.close(); + + FileInputStream fin = new FileInputStream(tmpFile); + ObjectInputStream ois = new ObjectInputStream(fin); + System.out.println("Attempting to read " + tbi + " from file-" + + tmpFile); + + TestBeanInterface tb = (TestBeanInterface) ois.readObject(); + // check if we have access to the same stateful session bean + System.out.println(tb.getState().equals("TEST")); + if (!tb.getState().equals("TEST")) + msg += "Failed to serialize stateful bean"; + //check if we can invoke stateless EJB + tb.method1(); + ois.close(); + } catch (Exception e) { + e.printStackTrace(); + msg += "Failed to serialize/deserialize proxy to EJB"; + } + + writer.write(msg + "\n"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/README new file mode 100644 index 0000000..b98ee72 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/README
@@ -0,0 +1,3 @@ +A simple field injection of a session scoped Bean into a Servlet that is bundled in an EAR. +Related GlassFish issue: https://glassfish.dev.java.net/issues/show_bug.cgi?id=14832 +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/build.properties new file mode 100644 index 0000000..e8ca782 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/build.properties
@@ -0,0 +1,28 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi-full-ear"/> +<property name="appname" value="${module}"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="se.client" value="com.acme.Client"/> +<property name="app.type" value="application"/> +<property name="sun-application.xml" value="descriptor/sun-application.xml"/> +<property name="application.xml" value="descriptor/application.xml"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="contextroot" value="${module}"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/build.xml new file mode 100644 index 0000000..5cb4fe7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/build.xml
@@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="cdi-full-ear-App" default="usage" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + + <target name="all" depends="clean,build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="war"/> + </antcall> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="true"/> + </antcall> + <antcall target="compile-common"> + <param name="src" value="ejb"/> + </antcall> + + <javac classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/modules/gf-client.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar" srcdir="client" destdir="${build.classes.dir}" debug="on" failonerror="true"> + <compilerarg line="-endorseddirs ${env.S1AS_HOME}/modules/endorsed"/> + + </javac> +<!-- + <antcall target="compile-common"> + <param name="src" value="client"/> + </antcall> +--> + </target> + + <target name="build" depends="compile"> + <mkdir dir="${assemble.dir}"/> + <antcall target="ejb-jar-common"> + <param name="ejbjar.classes" value="**/Foo.class,**/Hello.class,**/HelloRemote.class,**/Singleton*.class,**/HelloStateless.class,**/HelloSingleton.class,**/FooManagedBean.class,**/BarManagedBean.class, **/FooBarManagedBean.class, **/ManagedSuper.class"/> + </antcall> + <antcall target="ear-common"/> + </target> + + <target name="deploy" + depends="init-common"> + <antcall target="deploy-common"/> + </target> + + <target name="run" depends="init-common"> + <java fork="on" + failonerror="true" + classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/modules/gf-client.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar" + classname="${se.client}"> + <arg line="${contextroot}"/> + <arg line="${http.host}"/> + <arg line="${http.port}"/> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/client/com/acme/Client.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/client/com/acme/Client.java new file mode 100644 index 0000000..4271f2a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/client/com/acme/Client.java
@@ -0,0 +1,93 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import javax.annotation.Resource; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +public class Client { + + private static final String TEST_NAME = "normal-lookup-in-ear"; + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + + private static String appName; + private String host; + private String port; + + @Resource(lookup = "java:app/env/value1") + private static Integer appLevelViaLookup; + + public static void main(String args[]) { + appName = args[0]; + stat.addDescription(appName); + Client client = new Client(args); + client.doTest(); + stat.printSummary(appName + "ID"); + System.out.println("appLevelViaLookup = '" + appLevelViaLookup + "'"); + } + + public Client(String[] args) { + host = args[1]; + port = args[2]; + } + + public void doTest() { + + try { + + String url = "http://" + host + ":" + port + "/" + appName + + "/HelloServlet"; + + System.out.println("invoking webclient servlet at " + url); + + URL u = new URL(url); + + HttpURLConnection c1 = (HttpURLConnection) u.openConnection(); + int code = c1.getResponseCode(); + InputStream is = c1.getInputStream(); + BufferedReader input = new BufferedReader(new InputStreamReader( + is)); + String line = null; + while ((line = input.readLine()) != null) { + System.out.println("<response>:" + line); + if (line.trim().length() > 0) { + stat.addStatus(TEST_NAME, stat.FAIL); + return; + } + } + if (code != 200) { + stat.addStatus(TEST_NAME, stat.FAIL); + return; + } + stat.addStatus(TEST_NAME, stat.PASS); + + } catch (Exception e) { + stat.addStatus(TEST_NAME, stat.FAIL); + e.printStackTrace(); + } + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/descriptor/application.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/descriptor/application.xml new file mode 100644 index 0000000..d9378e7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/descriptor/application.xml
@@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="6" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"> + <display-name>ejb-ejb30-hello-session3App</display-name> + <module> + <ejb>cdi-full-ear-ejb.jar</ejb> + </module> + <module> + <web> + <web-uri>cdi-full-ear-web.war</web-uri> + <context-root>cdi-full-ear</context-root> + </web> + </module> + <env-entry> + <env-entry-name>java:app/env/value1</env-entry-name> + <env-entry-type>java.lang.Integer</env-entry-type> + <env-entry-value>18338</env-entry-value> + </env-entry> + <env-entry> + <env-entry-name>java:app/env/myString</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + <env-entry-value>myString</env-entry-value> + </env-entry> +</application>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/ejb/com/acme/Hello.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/ejb/com/acme/Hello.java new file mode 100644 index 0000000..2ad0681 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/ejb/com/acme/Hello.java
@@ -0,0 +1,25 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + + + +public interface Hello { + + public String hello(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/ejb/com/acme/HelloSingleton.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/ejb/com/acme/HelloSingleton.java new file mode 100644 index 0000000..4a9b9bf --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/ejb/com/acme/HelloSingleton.java
@@ -0,0 +1,73 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.annotation.Resource; +import javax.ejb.EJB; +import javax.ejb.SessionContext; +import javax.ejb.Singleton; +import javax.ejb.Startup; + +@Singleton +@Startup +public class HelloSingleton implements Hello { + + @Resource + SessionContext sessionCtx; + + @Resource(name = "java:app/env/myString") + protected String myString; + + @EJB(name = "java:app/env/appLevelEjbRef") + private Hello hello; + + String appName; + String moduleName; + + @PostConstruct + private void init() { + System.out.println("HelloSingleton::init()"); + + System.out.println("myString = '" + myString + "'"); + if ((myString == null) || !(myString.equals("myString"))) { + throw new RuntimeException("Invalid value " + myString + + " for myString"); + } + + appName = (String) sessionCtx.lookup("java:app/AppName"); + moduleName = (String) sessionCtx.lookup("java:module/ModuleName"); + + System.out.println("AppName = " + appName); + System.out.println("ModuleName = " + moduleName); + + } + + public String hello() { + + System.out.println("HelloSingleton::hello()"); + + return "hello, world!\n"; + } + + @PreDestroy + private void destroy() { + System.out.println("HelloSingleton::destroy()"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/manifest.mf b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/manifest.mf
@@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/war/com/acme/Hello.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/war/com/acme/Hello.java new file mode 100644 index 0000000..2ad0681 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/war/com/acme/Hello.java
@@ -0,0 +1,25 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + + + +public interface Hello { + + public String hello(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/war/com/acme/NormalLookupInEARServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/war/com/acme/NormalLookupInEARServlet.java new file mode 100644 index 0000000..d0ed24f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/war/com/acme/NormalLookupInEARServlet.java
@@ -0,0 +1,105 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.annotation.Resource; +import javax.ejb.EJB; +import javax.enterprise.inject.Instance; +import javax.inject.Inject; +import javax.naming.InitialContext; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@SuppressWarnings("serial") +@WebServlet(urlPatterns = "/HelloServlet", loadOnStartup = 1) +@EJB(name = "java:module/m1", beanName = "HelloSingleton", beanInterface = Hello.class) +public class NormalLookupInEARServlet extends HttpServlet { + + @Resource(name = "java:app/env/myString") + protected String myString; + + private Hello singleton1; + + @Inject + TestBean tw; + + private String msg = ""; + + @Override + public void init(ServletConfig config) throws ServletException { + super.init(config); + + System.out.println("In HelloServlet::init"); + System.out.println("myString = '" + myString + "'"); + if ((myString == null) || !(myString.equals("myString"))) { + msg += "@Resource lookup of myString failed"; + throw new RuntimeException("Invalid value " + myString + + " for myString"); + } + + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + System.out.println("In HelloServlet::doGet"); + resp.setContentType("text/html"); + + PrintWriter out = resp.getWriter(); + try { + InitialContext ic = new InitialContext(); + String appName = (String) ic.lookup("java:app/AppName"); + String moduleName = (String) ic.lookup("java:module/ModuleName"); + checkForNull(appName, "AppName lookup returned null"); + checkForNull(moduleName, "ModuleName lookup returned null"); + + singleton1 = (Hello) ic.lookup("java:module/m1"); + checkForNull(singleton1, + "programmatic lookup of module-level singleton EJB failed"); + + System.out.println("My AppName = " + + ic.lookup("java:app/AppName")); + + System.out.println("My ModuleName = " + + ic.lookup("java:module/ModuleName")); + + } catch (Exception e) { + msg += "Exception occurred during test Exception: " + + e.getMessage(); + e.printStackTrace(); + } + + singleton1.hello(); + + checkForNull(tw, "normal lookup of session scoped bean in war failed"); + + out.println(msg); + + } + + protected void checkForNull(Object o, String errorMessage) { + if (o == null) + msg += " " + errorMessage; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/war/com/acme/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/war/com/acme/TestBean.java new file mode 100644 index 0000000..f0092d7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/war/com/acme/TestBean.java
@@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +public interface TestBean { + public void m1(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/war/com/acme/TestBeanWARImpl.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/war/com/acme/TestBeanWARImpl.java new file mode 100644 index 0000000..8b45c02 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/war/com/acme/TestBeanWARImpl.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.enterprise.context.SessionScoped; + + +@SessionScoped +public class TestBeanWARImpl implements TestBean,java.io.Serializable { + @Override + public void m1() { + System.out.println("TestBean::m1"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/README new file mode 100644 index 0000000..e3888d0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/README
@@ -0,0 +1,4 @@ +A variant of the normal-bean-injection-ear testcase that uses programmatic lookup + +Related GlassFish issue: https://glassfish.dev.java.net/issues/show_bug.cgi?id=14832 +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/build.properties new file mode 100644 index 0000000..e8ca782 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/build.properties
@@ -0,0 +1,28 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi-full-ear"/> +<property name="appname" value="${module}"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="se.client" value="com.acme.Client"/> +<property name="app.type" value="application"/> +<property name="sun-application.xml" value="descriptor/sun-application.xml"/> +<property name="application.xml" value="descriptor/application.xml"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="contextroot" value="${module}"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/build.xml new file mode 100644 index 0000000..5cb4fe7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/build.xml
@@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="cdi-full-ear-App" default="usage" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + + <target name="all" depends="clean,build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="war"/> + </antcall> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="true"/> + </antcall> + <antcall target="compile-common"> + <param name="src" value="ejb"/> + </antcall> + + <javac classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/modules/gf-client.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar" srcdir="client" destdir="${build.classes.dir}" debug="on" failonerror="true"> + <compilerarg line="-endorseddirs ${env.S1AS_HOME}/modules/endorsed"/> + + </javac> +<!-- + <antcall target="compile-common"> + <param name="src" value="client"/> + </antcall> +--> + </target> + + <target name="build" depends="compile"> + <mkdir dir="${assemble.dir}"/> + <antcall target="ejb-jar-common"> + <param name="ejbjar.classes" value="**/Foo.class,**/Hello.class,**/HelloRemote.class,**/Singleton*.class,**/HelloStateless.class,**/HelloSingleton.class,**/FooManagedBean.class,**/BarManagedBean.class, **/FooBarManagedBean.class, **/ManagedSuper.class"/> + </antcall> + <antcall target="ear-common"/> + </target> + + <target name="deploy" + depends="init-common"> + <antcall target="deploy-common"/> + </target> + + <target name="run" depends="init-common"> + <java fork="on" + failonerror="true" + classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/modules/gf-client.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar" + classname="${se.client}"> + <arg line="${contextroot}"/> + <arg line="${http.host}"/> + <arg line="${http.port}"/> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/client/com/acme/Client.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/client/com/acme/Client.java new file mode 100644 index 0000000..1cb4a84 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/client/com/acme/Client.java
@@ -0,0 +1,93 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import javax.annotation.Resource; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +public class Client { + + private static final String TEST_NAME = "programmatic-lookup-in-ear"; + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + + private static String appName; + private String host; + private String port; + + @Resource(lookup = "java:app/env/value1") + private static Integer appLevelViaLookup; + + public static void main(String args[]) { + appName = args[0]; + stat.addDescription(appName); + Client client = new Client(args); + client.doTest(); + stat.printSummary(appName + "ID"); + System.out.println("appLevelViaLookup = '" + appLevelViaLookup + "'"); + } + + public Client(String[] args) { + host = args[1]; + port = args[2]; + } + + public void doTest() { + + try { + + String url = "http://" + host + ":" + port + "/" + appName + + "/HelloServlet"; + + System.out.println("invoking webclient servlet at " + url); + + URL u = new URL(url); + + HttpURLConnection c1 = (HttpURLConnection) u.openConnection(); + int code = c1.getResponseCode(); + InputStream is = c1.getInputStream(); + BufferedReader input = new BufferedReader(new InputStreamReader( + is)); + String line = null; + while ((line = input.readLine()) != null) { + System.out.println("<response>:" + line); + if (line.trim().length() > 0) { + stat.addStatus(TEST_NAME, stat.FAIL); + return; + } + } + if (code != 200) { + stat.addStatus(TEST_NAME, stat.FAIL); + return; + } + stat.addStatus(TEST_NAME, stat.PASS); + + } catch (Exception e) { + stat.addStatus(TEST_NAME, stat.FAIL); + e.printStackTrace(); + } + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/descriptor/application.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/descriptor/application.xml new file mode 100644 index 0000000..d9378e7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/descriptor/application.xml
@@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="6" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"> + <display-name>ejb-ejb30-hello-session3App</display-name> + <module> + <ejb>cdi-full-ear-ejb.jar</ejb> + </module> + <module> + <web> + <web-uri>cdi-full-ear-web.war</web-uri> + <context-root>cdi-full-ear</context-root> + </web> + </module> + <env-entry> + <env-entry-name>java:app/env/value1</env-entry-name> + <env-entry-type>java.lang.Integer</env-entry-type> + <env-entry-value>18338</env-entry-value> + </env-entry> + <env-entry> + <env-entry-name>java:app/env/myString</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + <env-entry-value>myString</env-entry-value> + </env-entry> +</application>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/ejb/com/acme/Hello.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/ejb/com/acme/Hello.java new file mode 100644 index 0000000..2ad0681 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/ejb/com/acme/Hello.java
@@ -0,0 +1,25 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + + + +public interface Hello { + + public String hello(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/ejb/com/acme/HelloSingleton.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/ejb/com/acme/HelloSingleton.java new file mode 100644 index 0000000..4a9b9bf --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/ejb/com/acme/HelloSingleton.java
@@ -0,0 +1,73 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.annotation.Resource; +import javax.ejb.EJB; +import javax.ejb.SessionContext; +import javax.ejb.Singleton; +import javax.ejb.Startup; + +@Singleton +@Startup +public class HelloSingleton implements Hello { + + @Resource + SessionContext sessionCtx; + + @Resource(name = "java:app/env/myString") + protected String myString; + + @EJB(name = "java:app/env/appLevelEjbRef") + private Hello hello; + + String appName; + String moduleName; + + @PostConstruct + private void init() { + System.out.println("HelloSingleton::init()"); + + System.out.println("myString = '" + myString + "'"); + if ((myString == null) || !(myString.equals("myString"))) { + throw new RuntimeException("Invalid value " + myString + + " for myString"); + } + + appName = (String) sessionCtx.lookup("java:app/AppName"); + moduleName = (String) sessionCtx.lookup("java:module/ModuleName"); + + System.out.println("AppName = " + appName); + System.out.println("ModuleName = " + moduleName); + + } + + public String hello() { + + System.out.println("HelloSingleton::hello()"); + + return "hello, world!\n"; + } + + @PreDestroy + private void destroy() { + System.out.println("HelloSingleton::destroy()"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/manifest.mf b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/manifest.mf
@@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/war/com/acme/Hello.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/war/com/acme/Hello.java new file mode 100644 index 0000000..2ad0681 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/war/com/acme/Hello.java
@@ -0,0 +1,25 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + + + +public interface Hello { + + public String hello(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/war/com/acme/ProgrammaticLookupInEARServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/war/com/acme/ProgrammaticLookupInEARServlet.java new file mode 100644 index 0000000..ed75d76 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/war/com/acme/ProgrammaticLookupInEARServlet.java
@@ -0,0 +1,105 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.annotation.Resource; +import javax.ejb.EJB; +import javax.enterprise.inject.Instance; +import javax.inject.Inject; +import javax.naming.InitialContext; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@SuppressWarnings("serial") +@WebServlet(urlPatterns = "/HelloServlet", loadOnStartup = 1) +@EJB(name = "java:module/m1", beanName = "HelloSingleton", beanInterface = Hello.class) +public class ProgrammaticLookupInEARServlet extends HttpServlet { + + @Resource(name = "java:app/env/myString") + protected String myString; + + private Hello singleton1; + + @Inject + Instance<TestBean> programmaticLookup; + + private String msg = ""; + + @Override + public void init(ServletConfig config) throws ServletException { + super.init(config); + + System.out.println("In HelloServlet::init"); + System.out.println("myString = '" + myString + "'"); + if ((myString == null) || !(myString.equals("myString"))) { + msg += "@Resource lookup of myString failed"; + throw new RuntimeException("Invalid value " + myString + + " for myString"); + } + + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + System.out.println("In HelloServlet::doGet"); + resp.setContentType("text/html"); + + PrintWriter out = resp.getWriter(); + try { + InitialContext ic = new InitialContext(); + String appName = (String) ic.lookup("java:app/AppName"); + String moduleName = (String) ic.lookup("java:module/ModuleName"); + checkForNull(appName, "AppName lookup returned null"); + checkForNull(moduleName, "ModuleName lookup returned null"); + + singleton1 = (Hello) ic.lookup("java:module/m1"); + checkForNull(singleton1, + "programmatic lookup of module-level singleton EJB failed"); + + System.out.println("My AppName = " + + ic.lookup("java:app/AppName")); + + System.out.println("My ModuleName = " + + ic.lookup("java:module/ModuleName")); + + } catch (Exception e) { + msg += "Exception occurred during test Exception: " + + e.getMessage(); + e.printStackTrace(); + } + + singleton1.hello(); + + checkForNull(programmaticLookup.get(), "programmatic lookup of session scoped bean in war failed"); + + out.println(msg); + + } + + protected void checkForNull(Object o, String errorMessage) { + if (o == null) + msg += " " + errorMessage; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/war/com/acme/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/war/com/acme/TestBean.java new file mode 100644 index 0000000..f0092d7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/war/com/acme/TestBean.java
@@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +public interface TestBean { + public void m1(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/war/com/acme/TestBeanWARImpl.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/war/com/acme/TestBeanWARImpl.java new file mode 100644 index 0000000..05f6914 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/programmatic-lookup-ear/war/com/acme/TestBeanWARImpl.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import java.io.Serializable; + +import javax.enterprise.context.SessionScoped; + + +@SessionScoped +public class TestBeanWARImpl implements TestBean, Serializable { + @Override + public void m1() { + System.out.println("TestBean::m1"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/README new file mode 100644 index 0000000..2be7b7d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/README
@@ -0,0 +1,5 @@ +Test + - Injection of ServletContext into a Servlet. As CDI does not allow injection of ServletContext, a Bridge +ServletContextListener is used to fire events during the initialization and destruction of ServletContext as suggested in +http://seamframework.org/Community/InjectServletContextIntoManagedBean#comment111596 +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/WebTest.java new file mode 100644 index 0000000..7f47426 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/WebTest.java
@@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "servlet-context-injection-in-cdi"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2 Servlet context: /cdi-servlet-context-injection"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/build.properties new file mode 100644 index 0000000..ca2edae --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-servlet-context-injection"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/build.xml new file mode 100644 index 0000000..83ad666 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/artifacts/Destroyed.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/artifacts/Destroyed.java new file mode 100644 index 0000000..38d4216 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/artifacts/Destroyed.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package tests.cdi.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Destroyed { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/artifacts/Initialized.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/artifacts/Initialized.java new file mode 100644 index 0000000..59788c2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/artifacts/Initialized.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package tests.cdi.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Initialized { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/artifacts/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/artifacts/Preferred.java new file mode 100644 index 0000000..d10f685 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/artifacts/Preferred.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package tests.cdi.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/context/ServletContextBridge.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/context/ServletContextBridge.java new file mode 100644 index 0000000..c978a9b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/context/ServletContextBridge.java
@@ -0,0 +1,66 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package tests.cdi.context; + +import java.lang.annotation.Annotation; + +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; + +import tests.cdi.artifacts.Destroyed; +import tests.cdi.artifacts.Initialized; + +@WebListener +public class ServletContextBridge implements ServletContextListener { + @Inject + private BeanManager beanManager; + + public ServletContextBridge() { + } + + /** + * Servlet context initialized / destroyed events + */ + + public void contextDestroyed(final ServletContextEvent e) { + fireEvent(e, DESTROYED); + } + + public void contextInitialized(final ServletContextEvent e) { + fireEvent(e, INITIALIZED); + } + + private void fireEvent(final Object payload, + final Annotation... qualifiers) { + System.out.println("Firing event #0 with qualifiers #1" + payload + + qualifiers); + beanManager.fireEvent(payload, qualifiers); + } + + private static final AnnotationLiteral<Destroyed> DESTROYED = new AnnotationLiteral<Destroyed>() { + private static final long serialVersionUID = -1610281796509557441L; + }; + + private static final AnnotationLiteral<Initialized> INITIALIZED = new AnnotationLiteral<Initialized>() { + private static final long serialVersionUID = -1610281796509557441L; + }; + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/context/ServletContextProducer.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/context/ServletContextProducer.java new file mode 100644 index 0000000..964aac0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/context/ServletContextProducer.java
@@ -0,0 +1,55 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package tests.cdi.context; + +//JJS: With cdi 1.1 the ServletContext is produced by Weld (2.0) and so producing one creates an ambiguous dependency. +//import javax.enterprise.context.ApplicationScoped; +//import javax.enterprise.event.Observes; +//import javax.enterprise.inject.Produces; +//import javax.enterprise.inject.spi.BeanManager; +//import javax.inject.Inject; +//import javax.servlet.ServletContext; +//import javax.servlet.ServletContextEvent; +// +//import tests.cdi.artifacts.Destroyed; +//import tests.cdi.artifacts.Initialized; +// +//@ApplicationScoped +public class ServletContextProducer { +// private ServletContext servletContext; +// +//// @Inject +//// private BeanManager beanManager; +// +// protected void contextInitialized( +// @Observes @Initialized ServletContextEvent e) { +// System.out.println("Servlet context initialized with event -" + e); +// servletContext = e.getServletContext(); +//// servletContext.setAttribute(BeanManager.class.getName(), beanManager); +// } +// +// protected void contextDestroyed(@Observes @Destroyed ServletContextEvent e) { +// System.out.println("Servlet context destroyed with event #0" + e); +// servletContext = null; +// } +// +// @Produces +// @ApplicationScoped +// public ServletContext getServletContext() { +// return servletContext; +// } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/servlet/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/servlet/TestBean.java new file mode 100644 index 0000000..182be84 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/servlet/TestBean.java
@@ -0,0 +1,33 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package tests.cdi.servlet; + +import javax.inject.Inject; +import javax.servlet.ServletContext; + +//Simple TestBean to test CDI. +public class TestBean +{ + @Inject + ServletContext sc; + + public String m1(){ + System.out.println("**********SC = " + sc.getContextPath()); + return sc.getContextPath(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/servlet/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/servlet/TestServlet.java new file mode 100644 index 0000000..8c70b32 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/servlet-context-injection-cdi/servlet/tests/cdi/servlet/TestServlet.java
@@ -0,0 +1,78 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package tests.cdi.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.enterprise.inject.spi.BeanManager; +import javax.inject.Inject; +import javax.naming.InitialContext; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }, initParams = { + @WebInitParam(name = "n1", value = "v1"), + @WebInitParam(name = "n2", value = "v2") }) +public class TestServlet extends HttpServlet { + @Inject + TestBean tb; + @Inject + BeanManager bm; + + BeanManager bm1; + + @Inject + ServletContext sc; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + ", n2=" + + getInitParameter("n2"); + if (tb == null) + msg += "Bean injection into Servlet failed"; + if (bm == null) + msg += "BeanManager Injection via @Inject failed"; + if (sc == null) + msg += "ServletContext Injection via @Inject failed"; + String servletContext = tb.m1(); + try { + bm1 = (BeanManager) ((new InitialContext()) + .lookup("java:comp/BeanManager")); + } catch (Exception ex) { + ex.printStackTrace(); + msg += "BeanManager Injection via component environment lookup failed"; + } + if (bm1 == null) + msg += "BeanManager Injection via component environment lookup failed"; + + System.out.println("BeanManager is " + bm); + System.out.println("BeanManager via lookup is " + bm1); + + msg = "initParams: " + msg + " Servlet context: " + servletContext + "\n"; + writer.write(msg); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/README new file mode 100644 index 0000000..e77c086 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/README
@@ -0,0 +1 @@ +- modification of the simple-managed-bean-interceptor test with non-null package for the managed bean and no no-arg constructor. Though the managed bean spec requires a no-arg constructor, it allows CDI specificaiton and implementations to support ManagedBeans with no no-arg constructor. Deployment would succeed on Weld 1.1 and above.
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/WebTest.java new file mode 100644 index 0000000..d2c69a6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/WebTest.java
@@ -0,0 +1,103 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "simple-managed-bean-interceptor-non-null-package-noarg-constructor-missing"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code == 404|| code == 500) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/build.properties new file mode 100644 index 0000000..4809e75 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-simple-managed-bean-interceptor"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/build.xml new file mode 100644 index 0000000..c25e17e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="WebTest.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/descriptor/beans.xml new file mode 100644 index 0000000..6264a41 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/descriptor/beans.xml
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.interceptors.TestAroundInvokeInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4a7146e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/servlet/test/beans/TestBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +//Simple Bean to test injection into ManagedBeans +public class TestBean { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/servlet/test/beans/TestManagedBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/servlet/test/beans/TestManagedBean.java new file mode 100644 index 0000000..f631ae8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/servlet/test/beans/TestManagedBean.java
@@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +//Simple TestBean to test CDI. +//This bean implements Serializable as it needs to be placed into a Stateful Bean +@javax.annotation.ManagedBean +public class TestManagedBean { + TestBean tb; + boolean postConstructCalled = false; + + //a ManagedBean needs to have a no-arg constructor +/* + public TestManagedBean(){ + } +*/ + + @javax.inject.Inject //Constructor based Injection + public TestManagedBean(TestBean tb){ + this.tb = tb; + } + + + @javax.annotation.PostConstruct + public void init(){ + System.out.println("In ManagedBean:: PostConstruct"); + postConstructCalled = true; + } + + @Tester + public void foo(){ + System.out.println("foo called"); + } + + public boolean testPostConstructCalled(){ + return this.postConstructCalled; + } + + public boolean testInjection(){ + System.out.println("In ManagedBean:: tb=" + tb); + postConstructCalled = true; + return this.tb != null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/servlet/test/beans/Tester.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/servlet/test/beans/Tester.java new file mode 100644 index 0000000..779d213 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/servlet/test/beans/Tester.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.interceptor.*; +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + + +@InterceptorBinding +@Target({METHOD, TYPE}) +@Retention(RUNTIME) +public @interface Tester {}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/servlet/test/interceptors/TestAroundInvokeInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/servlet/test/interceptors/TestAroundInvokeInterceptor.java new file mode 100644 index 0000000..700bf69 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/servlet/test/interceptors/TestAroundInvokeInterceptor.java
@@ -0,0 +1,39 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.interceptors; + +import javax.interceptor.*; + +import test.beans.Tester; + +@Tester @Interceptor +public class TestAroundInvokeInterceptor { + public static int aroundInvokeCount = 0; + + public static void reset(){ + aroundInvokeCount = 0; + } + + @AroundInvoke + public Object testMethod(InvocationContext ctx) throws Exception { + System.out.println("TestAroundInvokeIntercetpr:: aroundInvoke called - target:" + ctx.getTarget() + " , params:"+ ctx.getParameters()); + aroundInvokeCount ++; + ctx.proceed(); + return null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/servlet/test/servlet/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/servlet/test/servlet/TestServlet.java new file mode 100644 index 0000000..58feb50 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-noargconstructor-missing/servlet/test/servlet/TestServlet.java
@@ -0,0 +1,78 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestManagedBean; +import test.interceptors.TestAroundInvokeInterceptor; + +@WebServlet(name="mytest", + urlPatterns={"/myurl"}, + initParams={ @WebInitParam(name="n1", value="v1"), @WebInitParam(name="n2", value="v2") } ) +public class TestServlet extends HttpServlet { + @javax.inject.Inject TestManagedBean tb1; + @javax.annotation.Resource TestManagedBean tb; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + + ", n2=" + getInitParameter("n2"); + + //ManagedBean testing .. add additional messages in the "msg" string, so that the test will FAIL in the client + msg += testManagedBean(tb, " | TestManagedBean injected via @Resource"); + msg += testManagedBean(tb1, " | TestManagedBean injected via @Inject"); + msg += testInterceptors(); + + writer.write("initParams: " + msg + "\n"); + } + + private String testManagedBean(TestManagedBean tb, String info) { + String msg = ""; + if (tb == null) msg += info + " is null!"; + if (tb != null && !tb.testPostConstructCalled()) msg += info + " postConstruct not called"; + if (tb != null && !tb.testInjection()) msg += info + "Bean Injection into ManagedBean failed"; + return msg; + } + + private String testInterceptors(){ + System.out.println("calling foo on an @Resource injected Managed Bean"); + tb.foo(); + System.out.println("calling foo on an @Inject Managed Bean"); + tb1.foo(); //TestAroundInvokeInterceptor is not called in this case + + int count = TestAroundInvokeInterceptor.aroundInvokeCount; + System.out.println("TestAroundInvokeInterceptor called " + count + " times"); + TestAroundInvokeInterceptor.reset(); + if (count == 1) return ""; + else return "Interceptor invocation count" + count + " invalid"; + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/README new file mode 100644 index 0000000..6f3f094 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/README
@@ -0,0 +1 @@ +- modification of the simple-managed-bean-interceptor test with non-null package for the managed bean
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/WebTest.java new file mode 100644 index 0000000..cbd3be2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/WebTest.java
@@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "simple-managed-bean-interceptor-non-null-package"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/build.properties new file mode 100644 index 0000000..4809e75 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-simple-managed-bean-interceptor"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/build.xml new file mode 100644 index 0000000..83ad666 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/descriptor/beans.xml new file mode 100644 index 0000000..6264a41 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/descriptor/beans.xml
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.interceptors.TestAroundInvokeInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4a7146e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/servlet/test/beans/TestBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +//Simple Bean to test injection into ManagedBeans +public class TestBean { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/servlet/test/beans/TestManagedBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/servlet/test/beans/TestManagedBean.java new file mode 100644 index 0000000..2bc9acc --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/servlet/test/beans/TestManagedBean.java
@@ -0,0 +1,57 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +//Simple TestBean to test CDI. +//This bean implements Serializable as it needs to be placed into a Stateful Bean +@javax.annotation.ManagedBean +public class TestManagedBean { + TestBean tb; + boolean postConstructCalled = false; + + //a ManagedBean needs to have a no-arg constructor + public TestManagedBean(){ + } + + @javax.inject.Inject //Constructor based Injection + public TestManagedBean(TestBean tb){ + this.tb = tb; + } + + + @javax.annotation.PostConstruct + public void init(){ + System.out.println("In ManagedBean:: PostConstruct"); + postConstructCalled = true; + } + + @Tester + public void foo(){ + System.out.println("foo called"); + } + + public boolean testPostConstructCalled(){ + return this.postConstructCalled; + } + + public boolean testInjection(){ + System.out.println("In ManagedBean:: tb=" + tb); + postConstructCalled = true; + return this.tb != null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/servlet/test/beans/Tester.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/servlet/test/beans/Tester.java new file mode 100644 index 0000000..779d213 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/servlet/test/beans/Tester.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.interceptor.*; +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + + +@InterceptorBinding +@Target({METHOD, TYPE}) +@Retention(RUNTIME) +public @interface Tester {}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/servlet/test/interceptors/TestAroundInvokeInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/servlet/test/interceptors/TestAroundInvokeInterceptor.java new file mode 100644 index 0000000..700bf69 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/servlet/test/interceptors/TestAroundInvokeInterceptor.java
@@ -0,0 +1,39 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.interceptors; + +import javax.interceptor.*; + +import test.beans.Tester; + +@Tester @Interceptor +public class TestAroundInvokeInterceptor { + public static int aroundInvokeCount = 0; + + public static void reset(){ + aroundInvokeCount = 0; + } + + @AroundInvoke + public Object testMethod(InvocationContext ctx) throws Exception { + System.out.println("TestAroundInvokeIntercetpr:: aroundInvoke called - target:" + ctx.getTarget() + " , params:"+ ctx.getParameters()); + aroundInvokeCount ++; + ctx.proceed(); + return null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/servlet/test/servlet/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/servlet/test/servlet/TestServlet.java new file mode 100644 index 0000000..917a0fe --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/simple-managed-bean-interceptor-nonnull-package/servlet/test/servlet/TestServlet.java
@@ -0,0 +1,78 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestManagedBean; +import test.interceptors.TestAroundInvokeInterceptor; + +@WebServlet(name="mytest", + urlPatterns={"/myurl"}, + initParams={ @WebInitParam(name="n1", value="v1"), @WebInitParam(name="n2", value="v2") } ) +public class TestServlet extends HttpServlet { + @javax.inject.Inject TestManagedBean tb1; + @javax.annotation.Resource TestManagedBean tb; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + + ", n2=" + getInitParameter("n2"); + + //ManagedBean testing .. add additional messages in the "msg" string, so that the test will FAIL in the client + msg += testManagedBean(tb, " | TestManagedBean injected via @Resource"); + msg += testManagedBean(tb1, " | TestManagedBean injected via @Inject"); + msg += testInterceptors(); + + writer.write("initParams: " + msg + "\n"); + } + + private String testManagedBean(TestManagedBean tb, String info) { + String msg = ""; + if (tb == null) msg += info + " is null!"; + if (tb != null && !tb.testPostConstructCalled()) msg += info + " postConstruct not called"; + if (tb != null && !tb.testInjection()) msg += info + "Bean Injection into ManagedBean failed"; + return msg; + } + + private String testInterceptors(){ + System.out.println("calling foo on an @Resource injected Managed Bean"); + tb.foo(); + System.out.println("calling foo on an @Inject Managed Bean"); + tb1.foo(); //TestAroundInvokeInterceptor is not called in this case + + int count = TestAroundInvokeInterceptor.aroundInvokeCount; + System.out.println("TestAroundInvokeInterceptor called " + count + " times"); + TestAroundInvokeInterceptor.reset(); + if (count == 2) return ""; + else return "Interceptor invocation count" + count + " invalid"; + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/README b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/README new file mode 100644 index 0000000..633f9b5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/README
@@ -0,0 +1,12 @@ +- Test support for enabled beans' classes deployed as a standalone RAR +[test originally from connector1.5 test in Connectors developer tests] +section 12.1. Bean archives of JSR 299 spec: + +"Bean classes of enabled beans must be deployed in bean archives. +• A library jar, EJB jar, application client jar or rar archive is a +bean archive if it has a file named beans.xml in the META-INF +directory." + +In this test, a standalone RAR has a TestCDIBean Bean class. This is injected into a MDB in another ejb-jar in the EAR. + +[Note: This test doesn't seem to work now -- need to investigate]
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/META-INF/application.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/META-INF/application.xml new file mode 100644 index 0000000..fe9b32e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/META-INF/application.xml
@@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN' 'http://java.sun.com/dtd/application_1_3.dtd'> +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<application> + <display-name>GenericMessageDrivenBean</display-name> + <description>Application description</description> + <module> + <ejb>simplemdb-ejb.jar</ejb> + </module> + <module> + <java>simplemdb-client.jar</java> + </module> +</application>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/build.xml new file mode 100644 index 0000000..210abae --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/build.xml
@@ -0,0 +1,85 @@ +<!-- + + Copyright (c) 2002, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ + <!ENTITY common SYSTEM "../../../../../config/common.xml"> + <!ENTITY testcommon SYSTEM "../../../../../config/properties.xml"> + <!ENTITY database SYSTEM "../../../config/database.xml"> +]> + +<project name="connector1.5 MDB" default="all" basedir="."> + + <property name="j2ee.home" value="../../.."/> + <property name="earfile" value="simplemdb.ear"/> + + + <!-- include common.xml and testcommon.xml --> + &database; + &common; + &testcommon; + + <target name="all" depends="init-common, clean-common"> + <ant dir="src" inheritAll="false" target="all"/> + <antcall target="ear-common"> + <param name="appname" value="simplemdb"/> + <param name="application.xml" value="META-INF/application.xml"/> + </antcall> + </target> + + <target name="setupJdbc" depends="init-common"> + <antcall target="create-jdbc-conpool-connector"> + <param name="db.class" value="org.apache.derby.jdbc.ClientXADataSource"/> + <param name="jdbc.conpool.name" value="jdbc-pointbase-pool1"/> + <param name="jdbc.resource.type" value="javax.sql.XADataSource"/> + </antcall> + + <antcall target="create-jdbc-resource-common"> + <param name="jdbc.conpool.name" value="jdbc-pointbase-pool1"/> + <param name="jdbc.resource.name" value="jdbc/XAPointbase"/> + </antcall> + + <antcall target="execute-sql-connector"> + <param name="sql.file" value="createdb.sql"/> + </antcall> + </target> + + <target name="unsetJdbc" depends="init-common"> + <antcall target="delete-jdbc-resource-common"> + <param name="jdbc.resource.name" value="jdbc/XAPointbase"/> + </antcall> + <antcall target="delete-jdbc-connpool-common"> + <param name="jdbc.conpool.name" value="jdbc-pointbase-pool1"/> + </antcall> + </target> + + <target name="deploy-ear" depends="init-common"> + <antcall target="deploy-common"> + <param name="appname" value="simplemdb"/> + </antcall> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-common"> + <param name="appname" value="simplemdb"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="clean-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/createdb.sql b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/createdb.sql new file mode 100644 index 0000000..7d93610 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/createdb.sql
@@ -0,0 +1,2 @@ +drop table MESSAGES; +create table MESSAGES (messageId CHAR(50), message varchar(80));
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/application-client.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/application-client.xml new file mode 100644 index 0000000..75d2e9a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/application-client.xml
@@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE application-client PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN' 'http://java.sun.com/dtd/application-client_1_3.dtd'> +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<application-client> + <display-name>simplemdbClient</display-name> +</application-client> +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/ejb-jar.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/ejb-jar.xml new file mode 100644 index 0000000..4bdcc6f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/ejb-jar.xml
@@ -0,0 +1,122 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" + 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" + version="2.1"> + <display-name>Ejb1</display-name> + <enterprise-beans> + <message-driven> + <display-name>Generic_Message_Bean</display-name> + <ejb-name>GenericMessageBean</ejb-name> + <ejb-class>mdb.MyMessageBean</ejb-class> + <messaging-type>connector.MyMessageListener</messaging-type> + <transaction-type>Container</transaction-type> + <activation-config> + <activation-config-property> + <activation-config-property-name> + DestinationType + </activation-config-property-name> + <activation-config-property-value> + java.lang.String + </activation-config-property-value> + </activation-config-property> + <activation-config-property> + <activation-config-property-name> + TestProp + </activation-config-property-name> + <activation-config-property-value> + WrongValue + </activation-config-property-value> + </activation-config-property> + <!-- non-String activation spec property --> + <activation-config-property> + <activation-config-property-name> + TestIntegerProp + </activation-config-property-name> + <activation-config-property-value> + 1 + </activation-config-property-value> + </activation-config-property> + + </activation-config> + <resource-ref> + <description>description</description> + <res-ref-name>MyDB</res-ref-name> + <res-type>javax.sql.DataSource</res-type> + <res-auth>Container</res-auth> + <res-sharing-scope>Shareable</res-sharing-scope> + </resource-ref> + </message-driven> + <session> + <display-name>MyMessageChecker</display-name> + <ejb-name>MyMessageChecker</ejb-name> + <home>beans.MessageCheckerHome</home> + <remote>beans.MessageChecker</remote> + <ejb-class>beans.MessageCheckerEJB</ejb-class> + <session-type>Stateless</session-type> + <transaction-type>Container</transaction-type> + <env-entry> + <env-entry-name>user</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + <env-entry-value>PBPUBLIC</env-entry-value> + </env-entry> + <env-entry> + <env-entry-name>password</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + <env-entry-value>PBPUBLIC</env-entry-value> + </env-entry> + <resource-ref> + <res-ref-name>MyDB</res-ref-name> + <res-type>javax.sql.DataSource</res-type> + <res-auth>Container</res-auth> + <res-sharing-scope>Shareable</res-sharing-scope> + </resource-ref> + <resource-env-ref> + <resource-env-ref-name>eis/testAdmin</resource-env-ref-name> + <resource-env-ref-type>connector.MyAdminObject</resource-env-ref-type> + </resource-env-ref> + <security-identity> + <use-caller-identity/> + </security-identity> + </session> + </enterprise-beans> + <assembly-descriptor> + <container-transaction> + <method> + <ejb-name>GenericMessageBean</ejb-name> + <method-name>onMessage</method-name> + <method-params> + <method-param>java.lang.String</method-param> + </method-params> + </method> + <trans-attribute>Required</trans-attribute> + </container-transaction> + <container-transaction> + <method> + <ejb-name>MyMessageChecker</ejb-name> + <method-intf>Remote</method-intf> + <method-name>getMessageCount</method-name> + </method> + <trans-attribute>Required</trans-attribute> + </container-transaction> + </assembly-descriptor> +</ejb-jar>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/sun-application-client.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/sun-application-client.xml new file mode 100644 index 0000000..2b9166a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/sun-application-client.xml
@@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE sun-application-client PUBLIC "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Application Client 1.3//EN" "http://www.sun.com/software/sunone/appserver/dtds/sun-application-client_1_3-0.dtd"> +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<sun-application-client> +</sun-application-client> +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/sun-ejb-jar.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/sun-ejb-jar.xml new file mode 100644 index 0000000..42cd604 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/META-INF/sun-ejb-jar.xml
@@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 EJB 2.0//EN" "http://www.sun.com/software/sun +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +one/appserver/dtds/sun-ejb-jar_2_0-0.dtd"> + + +<sun-ejb-jar> + <enterprise-beans> + <module-name>ejb.jar</module-name> + <unique-id>1</unique-id> + <ejb> + <ejb-name>GenericMessageBean</ejb-name> + <mdb-resource-adapter> + <resource-adapter-mid>generic-ra</resource-adapter-mid> + <activation-config> + <!-- override prop value --> + <activation-config-property> + <activation-config-property-name> + TestIntegerProp + </activation-config-property-name> + <activation-config-property-value> + 2 + </activation-config-property-value> + </activation-config-property> + </activation-config> + </mdb-resource-adapter> + <ior-security-config> + <transport-config> + <integrity>supported</integrity> + <confidentiality>supported</confidentiality> + <establish-trust-in-target>supported</establish-trust-in-target> + <establish-trust-in-client>supported</establish-trust-in-client> + </transport-config> + <as-context> + <auth-method>username_password</auth-method> + <realm>default</realm> + <required>true</required> + </as-context> + <sas-context> + <caller-propagation>supported</caller-propagation> + </sas-context> + </ior-security-config> + <resource-ref> + <res-ref-name>MyDB</res-ref-name> + <jndi-name>jdbc/XAPointbase</jndi-name> + </resource-ref> + <gen-classes /> + </ejb> + <ejb> + <ejb-name>MyMessageChecker</ejb-name> + <jndi-name>MyMessageChecker</jndi-name> + <ior-security-config> + <transport-config> + <integrity>supported</integrity> + <confidentiality>supported</confidentiality> + <establish-trust-in-target>supported</establish-trust-in-target> + <establish-trust-in-client>supported</establish-trust-in-client> + </transport-config> + <as-context> + <auth-method>username_password</auth-method> + <realm>default</realm> + <required>false</required> + </as-context> + <sas-context> + <caller-propagation>supported</caller-propagation> + </sas-context> + </ior-security-config> + <resource-ref> + <res-ref-name>MyDB</res-ref-name> + <jndi-name>jdbc/XAPointbase</jndi-name> + </resource-ref> + <resource-env-ref> + <resource-env-ref-name>eis/testAdmin</resource-env-ref-name> + <jndi-name>eis/testAdmin</jndi-name> + </resource-env-ref> + <gen-classes/> + </ejb> + </enterprise-beans> +</sun-ejb-jar>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageChecker.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageChecker.java new file mode 100644 index 0000000..48573f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageChecker.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package beans; + +import javax.ejb.EJBObject; +import java.rmi.RemoteException; +import java.sql.SQLException; + +public interface MessageChecker extends EJBObject { + int getMessageCount() throws RemoteException; + boolean done() throws RemoteException; + int expectedResults() throws RemoteException; + void notifyAndWait() throws RemoteException; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerEJB.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerEJB.java new file mode 100644 index 0000000..bdc3f62 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerEJB.java
@@ -0,0 +1,188 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package beans; + +import connector.MyAdminObject; +import javax.rmi.PortableRemoteObject; +import javax.ejb.SessionBean; +import javax.ejb.SessionContext; +import javax.ejb.EJBException; +import javax.ejb.CreateException; +import java.util.Properties; +import java.util.Vector; +import java.sql.*; +import java.rmi.RemoteException; + +import javax.transaction.UserTransaction; +import javax.naming.*; +import javax.sql.*; + +public class MessageCheckerEJB implements SessionBean { + + private int WAIT_TIME = 15; + private String user = "j2ee"; + private String password = "j2ee"; + private Properties beanProps = null; + private SessionContext sessionContext = null; + private Connection heldCon = null; + private MyAdminObject Controls; + + public MessageCheckerEJB() {} + + public void ejbCreate() + throws CreateException { + System.out.println("bean removed"); + heldCon = null; + /* + if (holdConnection) { + try { + heldCon = getDBConnection(); + } catch (Exception ex) { + ex.printStackTrace(); + throw new CreateException("Error in ejbCreate"); + } + } + */ + } + + public boolean done() { + return Controls.done(); + } + + public int expectedResults() { + return Controls.expectedResults(); + } + + public void notifyAndWait() { + try { + synchronized (Controls.getLockObject()) { + //Tell the resource adapter the client is ready to run + Controls.getLockObject().notifyAll(); + + debug("NOTIFIED... START WAITING"); + //Wait until being told to read from the database + Controls.getLockObject().wait(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public int getMessageCount() { + try { + Connection con = getFreshConnection(); + int count1 = getCount(con); + con.close(); + + /* + synchronized(Controls.getLockObject()) { + Controls.getLockObject().notify(); + } + */ + + return count1; + } catch (Exception e) { + e.printStackTrace(System.out); + throw new EJBException(e); + } + } + + private int getCount(Connection con) throws SQLException { + Statement stmt = con.createStatement(); + int count = 0; + String messages = ""; + ResultSet result = stmt.executeQuery( + "SELECT messageId, message "+ "FROM messages"); + while (result.next()) { + count++; + messages = messages + " - " + result.getString("messageId")+" "+ + result.getString("message") + "\n"; + } + messages = messages + "count = " + count; + System.out.println(messages); + stmt.close(); + return count; + } + + public void setSessionContext(SessionContext context) { + sessionContext = context; + try { + Context ic = new InitialContext(); + user = (String) ic.lookup("java:comp/env/user"); + password = (String) ic.lookup("java:comp/env/password"); + Controls = (MyAdminObject) ic.lookup("java:comp/env/eis/testAdmin"); + System.out.println("CALLING INITILIZE ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"); + Controls.initialize(); + System.out.println("CALLED INITILIZE ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void ejbRemove() { + System.out.println("bean removed"); + } + + public void ejbActivate() { + System.out.println("bean activated"); + } + + public void ejbPassivate() { + System.out.println("bean passivated"); + } + + private Connection getFreshConnection() throws Exception { + Connection oldHeldCon = heldCon; + heldCon = null; + Connection result = getDBConnection(); + heldCon = oldHeldCon; + return result; + } + + private Connection getDBConnection() throws Exception { + if (heldCon != null) return heldCon; + Connection con = null; + try { + Context ic = new InitialContext(); + DataSource ds = (DataSource) ic.lookup("java:comp/env/MyDB"); + debug("Looked up Datasource\n"); + debug("Get JDBC connection, auto sign on"); + con = ds.getConnection(); + + if (con != null) { + return con; + } else { + throw new Exception("Unable to get database connection "); + } + } catch (SQLException ex1) { + //ex1.printStackTrace(); + throw ex1; + } + } + + private void closeConnection(Connection con) throws SQLException { + if (heldCon != null) { + return; + } else { + con.close(); + } + } + + private void debug(String msg) { + System.out.println("[MessageCheckerEJB]:: -> " + msg); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerHome.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerHome.java new file mode 100644 index 0000000..4bcc578 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/beans/MessageCheckerHome.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package beans; + +import java.rmi.RemoteException; +import javax.ejb.EJBHome; +import javax.ejb.CreateException; + +public interface MessageCheckerHome extends EJBHome { + MessageChecker create() throws RemoteException, CreateException; + boolean done() throws RemoteException, CreateException; + int expectedResults() throws RemoteException, CreateException; + void notifyAndWait() throws RemoteException, CreateException; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/build.properties b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/build.properties new file mode 100644 index 0000000..dad207b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/build.properties
@@ -0,0 +1,21 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +ejb-jar.xml=META-INF/ejb-jar.xml +sun-ejb-jar.xml=META-INF/sun-ejb-jar.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/build.xml new file mode 100644 index 0000000..24e1832 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/build.xml
@@ -0,0 +1,68 @@ +<!-- + + Copyright (c) 2002, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ + <!ENTITY common SYSTEM "../../../../../../config/common.xml"> + <!ENTITY testcommon SYSTEM "../../../../../../config/properties.xml"> +]> + +<project name="connector1.5 MDB" default="all" basedir="."> + + <property name="j2ee.home" value="../../../.."/> + + <!-- include common.xml and testcommon.xml --> + &common; + &testcommon; + + <target name="all" depends="init-common"> + <antcall target="compile-common"> + <param name="src" value="." /> + <param name="s1astest.classpath" value="${s1astest.classpath}:../../ra/src/classes" /> + </antcall> + + <antcall target="ejb-jar-common"> + <param name="ejb-jar.xml" value="META-INF/ejb-jar.xml" /> + <param name="ejbjar.classes" value="mdb/*.class, beans/*.class, connector/*.class" /> + <param name="beans.xml" value="META-INF/beans.xml" /> + <param name="sun-ejb-jar.xml" value="META-INF/sun-ejb-jar.xml" /> + <param name="appname" value="simplemdb" /> + </antcall> + + <antcall target="appclient-jar-common"> + <param name="appname" value="simplemdb" /> + <param name="application-client.xml" value="META-INF/application-client.xml" /> + <param name="appclientjar.classes" value="mdb/*.class, beans/*.class, connector/*.class, client/Client.class" /> + <param name="sun-application-client.xml" value="META-INF/sun-application-client.xml" /> + </antcall> +<!-- + <jar jarfile="../ejb.jar" basedir="classes" + includes="mdb/*.class, beans/*.class, connector/*.class" > + <metainf dir="META-INF"> + <include name="ejb-jar.xml"/> + <include name="sun-ejb-jar.xml"/> + </metainf> + </jar> +--> + </target> + + <target name="clean"> + <antcall target="clean-classes-common"> + <param name="build.classes.dir" value="classes" /> + </antcall> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/client/Client.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/client/Client.java new file mode 100644 index 0000000..f551ce1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/client/Client.java
@@ -0,0 +1,122 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package client; + +import beans.*; +import connector.*; +import java.io.*; +import java.util.*; +import javax.naming.*; +import javax.rmi.PortableRemoteObject; +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +public class Client { + + private static SimpleReporterAdapter stat = + new SimpleReporterAdapter("appserv-tests"); + + public Client (String[] args) { + //super(args); + } + + public static void main(String[] args) { + Client client = new Client(args); + client.doTest(); + } + + public String doTest() { + stat.addDescription("This is to test connector 1.5 "+ + "contracts."); + + String res = "NOT RUN"; + debug("doTest() ENTER..."); + boolean pass = false; + try { + res = "ALL TESTS PASSED"; + int testCount = 1; + while (!done()) { + + notifyAndWait(); + if (!done()) { + debug("Running..."); + pass = checkResults(expectedResults()); + debug("Got expected results = " + pass); + + //do not continue if one test failed + if (!pass) { + res = "SOME TESTS FAILED"; + stat.addStatus("ID Connector 1.5 test - " + testCount, stat.FAIL); + } else { + stat.addStatus("ID Connector 1.5 test - " + testCount, stat.PASS); + } + } else { + break; + } + testCount ++; + } + + } catch (Exception ex) { + System.out.println("Importing transaction test failed."); + ex.printStackTrace(); + res = "TEST FAILED"; + } + stat.printSummary("connector1.5ID"); + + + debug("EXITING... STATUS = " + res); + return res; + } + + private boolean checkResults(int num) throws Exception { + Object o = (new InitialContext()).lookup("MyMessageChecker"); + MessageCheckerHome home = (MessageCheckerHome) + PortableRemoteObject.narrow(o, MessageCheckerHome.class); + MessageChecker checker = home.create(); + int result = checker.getMessageCount(); + return result == num; + } + + private boolean done() throws Exception { + Object o = (new InitialContext()).lookup("MyMessageChecker"); + MessageCheckerHome home = (MessageCheckerHome) + PortableRemoteObject.narrow(o, MessageCheckerHome.class); + MessageChecker checker = home.create(); + return checker.done(); + } + + private int expectedResults() throws Exception { + Object o = (new InitialContext()).lookup("MyMessageChecker"); + MessageCheckerHome home = (MessageCheckerHome) + PortableRemoteObject.narrow(o, MessageCheckerHome.class); + MessageChecker checker = home.create(); + return checker.expectedResults(); + } + + private void notifyAndWait() throws Exception { + Object o = (new InitialContext()).lookup("MyMessageChecker"); + MessageCheckerHome home = (MessageCheckerHome) + PortableRemoteObject.narrow(o, MessageCheckerHome.class); + MessageChecker checker = home.create(); + checker.notifyAndWait(); + } + + + private void debug(String msg) { + System.out.println("[CLIENT]:: --> " + msg); + } +} +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/client/MANIFEST.MF b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/client/MANIFEST.MF new file mode 100644 index 0000000..179cd4d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/client/MANIFEST.MF
@@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Created-By: 1.4.0 (Sun Microsystems Inc.) +Main-Class: client.Client +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/connector/MyMessageListener.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/connector/MyMessageListener.java new file mode 100644 index 0000000..a3928d3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/connector/MyMessageListener.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +public interface MyMessageListener { + public void onMessage (String message); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/mdb/MyMessageBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/mdb/MyMessageBean.java new file mode 100644 index 0000000..3af505b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/app/src/mdb/MyMessageBean.java
@@ -0,0 +1,247 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package mdb; + +import java.sql.Statement; + +import javax.ejb.MessageDrivenBean; +import javax.ejb.MessageDrivenContext; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.sql.DataSource; + +import connector.MyMessageListener; +import javax.ejb.*; +import javax.naming.*; +import java.io.*; +import java.rmi.RemoteException; +import javax.servlet.*; +import javax.servlet.http.*; +import java.sql.*; +import javax.sql.*; +import javax.jms.*; +import javax.transaction.*; + + +/** + */ +public class MyMessageBean implements MessageDrivenBean, + MyMessageListener { + + private transient MessageDrivenContext mdc = null; + private Context context; + + @javax.inject.Inject + private connector.TestCDIBean tb; + + /** + * Constructor, which is public and takes no arguments. + */ + public MyMessageBean() {} + + /** + * setMessageDrivenContext method, declared as public (but + * not final or static), with a return type of void, and + * with one argument of type javax.ejb.MessageDrivenContext. + * + * @param mdc the context to set + */ + public void setMessageDrivenContext(MessageDrivenContext mdc) { + this.mdc = mdc; + } + + /** + * ejbCreate method, declared as public (but not final or + * static), with a return type of void, and with no + * arguments. + */ + public void ejbCreate() { } + + /** + * onMessage method, declared as public (but not final or + * static), with a return type of void, and with one argument + * of type javax.jms.Message. + * + * Casts the incoming Message to a TextMessage and displays + * the text. + * + * @param inMessage the incoming message + */ + public void onMessage(String inMessage) { + + debug("onMessage:: RECEIVED [" + inMessage + "]"); + debug("TestCDIBean injected:" + tb); + + if (tb == null) + throw new RuntimeException("Injection of enabled Bean " + + "in RAR into a MDB injection point failed"); + + try { + if (inMessage.endsWith("WRITE")) { + doDbStuff("WRITE", + inMessage.substring(0, inMessage.lastIndexOf(":"))); + } else if (inMessage.endsWith("DELETE")) { + doDbStuff("DELETE", + inMessage.substring(0, inMessage.lastIndexOf(":"))); + } else if (inMessage.endsWith("DELETE_ALL")) { + doDbStuff("DELETE_ALL", "::"); + } else { + //unsupported op. + } + } catch (Exception ex) { + debug("UH OH..."); + ex.printStackTrace(); + } + + } + + /** + * ejbRemove method, declared as public (but not final or + * static), with a return type of void, and with no + * arguments. + */ + public void ejbRemove() {} + + + private void doDbStuff(String op, String message) throws Exception { + + java.sql.Connection dbConnection = null; + String id = message.substring(0, message.indexOf(":")); + String body = message.substring(message.indexOf(":")+1); + try { + Context ic = new InitialContext(); + + if ("READ".equals(op)) { + + debug("Reading row from database..."); + + // Creating a database connection + /* + DataSource ds = (DataSource) ic.lookup("java:comp/env/MyDB"); + debug("Looked up Datasource\n"); + debug("Get JDBC connection, auto sign on"); + dbConnection = ds.getConnection(); + + Statement stmt = dbConnection.createStatement(); + String query = + "SELECT id from messages where id = 'QQ'"; + ResultSet results = stmt.executeQuery(query); + results.next(); + System.out.println("QQ has balance " + + results.getInt("balance") + " dollars"); + results.close(); + stmt.close(); + + System.out.println("Read one account\n"); + */ + + } else if ("WRITE".equals(op)) { + + debug("Inserting one message in the database\n"); + + // Creating a database connection + DataSource ds = (DataSource) ic.lookup("java:comp/env/MyDB"); + //debug("Looked up Datasource\n"); + //debug("Get JDBC connection, auto sign on"); + dbConnection = ds.getConnection(); + + createRow(id, body, dbConnection); + System.out.println("Created one message\n"); + + } else if ("DELETE".equals(op)) { + + debug("Deleting one message from the database\n"); + + // Creating a database connection + DataSource ds = (DataSource) ic.lookup("java:comp/env/MyDB"); + //debug("Looked up Datasource\n"); + //debug("Get JDBC connection, auto sign on"); + dbConnection = ds.getConnection(); + + deleteRow(id, dbConnection); + System.out.println("Deleted one message\n"); + } else if ("DELETE_ALL".equals(op)) { + + debug("Deleting all messages from the database\n"); + + // Creating a database connection + DataSource ds = (DataSource) ic.lookup("java:comp/env/MyDB"); + //debug("Looked up Datasource\n"); + //debug("Get JDBC connection, auto sign on"); + dbConnection = ds.getConnection(); + deleteAll(dbConnection); + System.out.println("Deleted all messages\n"); + } else { + //unsupported op + } + + }finally{ + try{ + dbConnection.close(); + }catch(Exception ex){ + debug("Exception occured while closing database con nection."); + } + } + } + + private void createRow(String id, String body, + java.sql.Connection dbConnection) + throws Exception { + + // Create row for this message + debug("CreateRow with ID = " + id + ", BODY = " + body); + Statement stmt = dbConnection.createStatement(); + String query = "INSERT INTO messages (messageId, message)" + + "VALUES ('" + id + "', '" + body + "')"; + int resultCount = stmt.executeUpdate(query); + if ( resultCount != 1 ) { + throw new Exception( + "ERROR in INSERT !! resultCount = "+resultCount); + } + stmt.close(); + } + + private void deleteRow(String id, java.sql.Connection dbConnection) + throws Exception { + + // Delete row for this message + debug("DeleteRow with ID = " + id); + Statement stmt = dbConnection.createStatement(); + String query = "DELETE FROM messages WHERE messageId = '" + id + "'"; + int resultCount = stmt.executeUpdate(query); + if ( resultCount != 1 ) { + throw new Exception( + "ERROR in INSERT !! resultCount = "+resultCount); + } + stmt.close(); + } + + private void deleteAll(java.sql.Connection dbConnection) + throws Exception { + + // Delete row for this message + Statement stmt = dbConnection.createStatement(); + String query = "DELETE FROM messages"; + int resultCount = stmt.executeUpdate(query); + debug("Delete all rows from messages... count = " + resultCount); + stmt.close(); + } + + private void debug(String msg) { + System.out.println("[MyMessageBean] --> " + msg); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/build.xml new file mode 100644 index 0000000..645f1c9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/build.xml
@@ -0,0 +1,98 @@ +<!-- + + Copyright (c) 2002, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ + <!ENTITY common SYSTEM "../../../../config/common.xml"> + <!ENTITY testcommon SYSTEM "../../../../config/properties.xml"> +]> + +<project name="connector1.5 TEST" default="all" basedir="."> +<property name="j2ee.home" value="../.."/> +<property name="client.class" value="client/Client"/> + + <!-- include common.xml and testcommon.xml --> + &common; + &testcommon; + + <target name="all" depends="init-common, build, setup, runtest, unset"/> + <target name="run-dp-test" depends="init-common, build, setup-dp, deploy-dp, runtest, unset-dp, undeploy-dp"/> + <target name="build" depends="init-common"> + <ant dir="ra" inheritAll="false" target="all"/> + <ant dir="app" inheritAll="false" target="all"/> + </target> + + <target name="setup"> + <ant dir="app" inheritAll="false" target="setupJdbc"/> + <ant dir="." inheritAll="false" target="deploy"/> + </target> + + <target name="setup-dp"> + <ant dir="app" inheritAll="false" target="setupJdbc"/> + </target> + + <target name="deploy"> + <ant dir="ra" inheritAll="false" target="deploy"/> + <ant dir="ra" inheritAll="false" target="testAddAdmin"/> + <ant dir="app" inheritAll="false" target="deploy-ear"/> + <ant dir="." inheritAll="false" target="restart"/> + </target> + + <target name="deploy-dp"> + <ant dir="ra" inheritAll="false" target="testAddAdmin"/> + <ant dir="app" inheritAll="false" target="deploy-ear"/> + <ant dir="." inheritAll="false" target="restart"/> + </target> + + <target name="runtest" depends="init-common"> + <antcall target="runclient-common"> + <param name="appname" value="simplemdb" /> + </antcall> + </target> + + <target name="unset"> + <ant dir="app" inheritAll="false" target="unsetJdbc"/> + <ant dir="." inheritAll="false" target="undeploy"/> + <ant dir="." inheritAll="false" target="restart"/> + </target> + + <target name="unset-dp"> + <ant dir="app" inheritAll="false" target="unsetJdbc"/> + <ant dir="." inheritAll="false" target="restart"/> + </target> + + <target name="undeploy"> + <ant dir="app" inheritAll="false" target="undeploy"/> + <ant dir="ra" inheritAll="false" target="testDelAdmin"/> + <ant dir="ra" inheritAll="false" target="undeploy"/> + </target> + + <target name="undeploy-dp"> + <ant dir="app" inheritAll="false" target="undeploy"/> + <ant dir="ra" inheritAll="false" target="testDelAdmin"/> + </target> + + <target name="restart" depends="init-common"> + <echo message="Not required to restart"/> + </target> + + <target name="clean"> + <ant dir="ra" inheritAll="false" target="clean"/> + <ant dir="app" inheritAll="false" target="clean"/> + </target> + +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/createdb.sql b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/createdb.sql new file mode 100644 index 0000000..19f3324 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/createdb.sql
@@ -0,0 +1,2 @@ +drop table messages; +create table messages (messageId CHAR(50), message varchar(80));
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/META-INF/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/META-INF/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/META-INF/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/META-INF/ra.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/META-INF/ra.xml new file mode 100644 index 0000000..2ca2ebc --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/META-INF/ra.xml
@@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!-- +<!DOCTYPE connector PUBLIC '-//Sun Microsystems, Inc.//DTD Connector 1.5//EN' 'http://java.sun.com/dtd/connector_1_5.dtd'> +--> +<connector xmlns="http://java.sun.com/xml/ns/j2ee" + 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/connector_1_5.xsd" + version="1.5"> + <display-name>Simple Resource Adapter</display-name> + <vendor-name>Java Software</vendor-name> + <eis-type>Generic Type</eis-type> + <resourceadapter-version>1.0Alpha</resourceadapter-version> + <resourceadapter> + <resourceadapter-class> + connector.SimpleResourceAdapterImpl + </resourceadapter-class> + <config-property> + <config-property-name> + TestName + </config-property-name> + <config-property-type> + java.lang.String + </config-property-type> + <config-property-value> + ConfigPropertyForRA + </config-property-value> + </config-property> + <inbound-resourceadapter> + <messageadapter> + <messagelistener> + <messagelistener-type> + connector.MyMessageListener + </messagelistener-type> + <activationspec> + <activationspec-class> + connector.SimpleActivationSpec + </activationspec-class> + </activationspec> + </messagelistener> + </messageadapter> + </inbound-resourceadapter> + <adminobject> + <adminobject-interface>connector.MyAdminObject</adminobject-interface> + <adminobject-class>connector.MyAdminObject</adminobject-class> + <config-property> + <config-property-name>ResetControl</config-property-name> + <config-property-type>java.lang.String</config-property-type> + <config-property-value>NORESET</config-property-value> + </config-property> + <config-property> + <config-property-name>ExpectedResult</config-property-name> + <config-property-type>java.lang.Integer</config-property-type> + <config-property-value>88</config-property-value> + </config-property> + </adminobject> + </resourceadapter> +</connector>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/build.xml new file mode 100644 index 0000000..5267dc3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/build.xml
@@ -0,0 +1,81 @@ +<!-- + + Copyright (c) 2002, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ + <!ENTITY common SYSTEM "../../../../../config/common.xml"> + <!ENTITY props SYSTEM "../../../../../config/properties.xml"> +]> + +<project name="connector1.5 RA" default="all" basedir="."> + + <property name="j2ee.home" value="../../.."/> + <property name="earfile" value="generic-ra.rar"/> + + <!-- include common.xml and testcommon.xml --> + &common; + &props; + + <target name="all"> + <ant dir="src" inheritAll="false" target="all"/> + + <jar jarfile="generic-ra.rar" basedir="." + includes="generic-ra.jar, META-INF/ra.xml, META-INF/beans.xml" /> + </target> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-rar-common"> + <param name="rarfile" value="generic-ra.rar"/> + </antcall> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-rar-common"> + <param name="undeployrar" value="generic-ra"/> + </antcall> + </target> + + <target name="testAddAdmin" depends="init-common"> + <antcall target="asadmin-common"> + <param name="admin.command" value="create-admin-object --target ${appserver.instance.name} --restype connector.MyAdminObject --raname generic-ra --property ResetControl=BEGINNING"/> + <param name="operand.props" value="eis/testAdmin"/> + </antcall> + </target> + + <target name="testDelAdmin" depends="init-common"> + <antcall target="asadmin-common"> + <param name="admin.command" value="delete-admin-object"/> + <param name="operand.props" value="--target ${appserver.instance.name} eis/testAdmin"/> + </antcall> + </target> + + <target name="sendMessage" depends="init-common"> + <echo message="Class path is ${s1astest.classpath}"/> + <java fork="true" classname="connector.Messages" failonerror="true"> + <arg line="add Foo TestMessage"/> + <classpath> + <pathelement location="${s1astest.classpath}"/> + <pathelement location="generic-ra.jar"/> + </classpath> + </java> + </target> + + <target name="clean"> + <ant dir="src" inheritAll="false" target="clean"/> + </target> + +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/build.xml new file mode 100644 index 0000000..fad2edb --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/build.xml
@@ -0,0 +1,49 @@ +<!-- + + Copyright (c) 2002, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ + <!ENTITY common SYSTEM "../../../../../../config/common.xml"> + <!ENTITY props SYSTEM "../../../../../../config/properties.xml"> +]> + +<project name="connector1.5 RA SRC" default="all" basedir="."> + + + <!-- include common.xml and testcommon.xml --> + &common; + &props; + + <target name="all" depends="init-common" > + <antcall target="compile-common"> + <param name="build.classes.dir" value="classes" /> + <param name="src" value="connector" /> + </antcall> + <jar jarfile="../generic-ra.jar" basedir="classes" + includes="connector/*.class" /> + </target> + + + <target name="clean"> + <antcall target="clean-classes-common"> + <param name="build.classes.dir" value="classes" /> + </antcall> + <delete file="../generic-ra.jar"/> + <delete file="../generic-ra.rar"/> + </target> + +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/Controls.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/Controls.java new file mode 100644 index 0000000..42188a6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/Controls.java
@@ -0,0 +1,27 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +/** + * + * @author Qingqing Ouyang + */ +public class Controls { + public static Object readyLock = new Object(); + public static int expectedResults; + public static boolean done = false; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/DeliveryWork.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/DeliveryWork.java new file mode 100644 index 0000000..43377e8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/DeliveryWork.java
@@ -0,0 +1,113 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import java.lang.reflect.Method; +import java.util.Iterator; +import javax.resource.spi.endpoint.MessageEndpoint; +import javax.resource.spi.endpoint.MessageEndpointFactory; +import javax.resource.spi.UnavailableException; +import javax.resource.spi.work.Work; +import javax.resource.spi.work.WorkManager; +import javax.resource.spi.work.ExecutionContext; + +/** + * + * @author Qingqing Ouyang + */ +public class DeliveryWork implements Work { + + private MessageEndpoint ep; + private int num; + private String op; + private boolean keepCount; + private static int counter = 0; + + public DeliveryWork(MessageEndpoint ep, int numOfMessages, String op) { + this.ep = ep; + this.num = numOfMessages; + this.op = op; + this.keepCount = false; + } + + public DeliveryWork(MessageEndpoint ep, int numOfMessages, + String op, boolean keepCount) { + this.ep = ep; + this.num = numOfMessages; + this.op = op; + this.keepCount = keepCount; + } + + public void run() { + + debug("ENTER..."); + + try { + //Method onMessage = getOnMessageMethod(); + //ep.beforeDelivery(onMessage); + + if (!keepCount) { + for (int i = 0; i < num; i++) { + String msgId = String.valueOf(i); + String msgBody = "This is message " + msgId; + String msg = msgId + ":" + msgBody + ":" + op; + ((MyMessageListener) ep).onMessage(msg); + } + } else { + for (int i = 0; i < num; i++) { + String msgId = String.valueOf(i+counter); + String msgBody = "This is message " + msgId; + String msg = msgId + ":" + msgBody + ":" + op; + ((MyMessageListener) ep).onMessage(msg); + } + counter = counter + num; + } + + //ep.afterDelivery(); + + } catch (Exception ex) { + ex.printStackTrace(); + } + + debug("LEAVE..."); + } + + public void release() {} + + public String toString() { + return op; + } + + private Method getOnMessageMethod() { + + Method onMessageMethod = null; + try { + Class msgListenerClass = connector.MyMessageListener.class; + Class[] paramTypes = { java.lang.String.class }; + onMessageMethod = + msgListenerClass.getMethod("onMessage", paramTypes); + + } catch (NoSuchMethodException ex) { + ex.printStackTrace(); + } + return onMessageMethod; + } + + private void debug(String mesg) { + System.out.println("DeliveryWork[" + op + "] --> " + mesg); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/FakeXAResource.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/FakeXAResource.java new file mode 100644 index 0000000..97ed09e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/FakeXAResource.java
@@ -0,0 +1,119 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import javax.transaction.xa.*; + +/** + * This is class is used for debugging. It prints out + * trace information on TM calls to XAResource before + * directing the call to the actual XAResource object + */ +public class FakeXAResource implements XAResource { + + public FakeXAResource() {} + + public void commit(Xid xid, boolean onePhase) throws XAException { + print("FakeXAResource.commit: " + xidToString(xid) + "," + onePhase); + } + + public void end(Xid xid, int flags) throws XAException { + print("FakeXAResource.end: " + xidToString(xid) + "," + + flagToString(flags)); + } + + + public void forget(Xid xid) throws XAException { + print("FakeXAResource.forget: " + xidToString(xid)); + } + + public int getTransactionTimeout() throws XAException { + return 60*1000; + } + + public boolean isSameRM(XAResource xares) throws XAException { + return false; + } + + public int prepare(Xid xid) throws XAException { + print("FakeXAResource.prepare: " + xidToString(xid)); + return XAResource.XA_OK; + } + + public Xid[] recover(int flag) throws XAException { + print("FakeXAResource.recover: " + flagToString(flag)); + return null; + } + + public void rollback(Xid xid) throws XAException { + print("FakeXAResource.rollback: " + xidToString(xid)); + } + + public boolean setTransactionTimeout(int seconds) throws XAException { + return false; + } + + public void start(Xid xid, int flags) throws XAException { + print("FakeXAResource.start: " + xidToString(xid) + "," + + flagToString(flags)); + throw new XAException(); + } + + private void print(String s) { + System.out.println(s); + } + + static public String xidToString(Xid xid) { + return String.valueOf((new String(xid.getGlobalTransactionId()) + + new String(xid.getBranchQualifier())).hashCode()); + } + + static public String flagToString(int flag) { + switch (flag) { + case TMFAIL: + return "TMFAIL"; + case TMJOIN: + return "TMJOIN"; + case TMNOFLAGS: + return "TMNOFLAGS"; + case TMONEPHASE: + return "TMONEPHASE"; + case TMRESUME: + return "TMRESUME"; + case TMSTARTRSCAN: + return "TMSTARTRSCAN"; + case TMENDRSCAN: + return "TMENDRSCAN"; + case TMSUCCESS: + return "TMSUCCESS"; + case TMSUSPEND: + return "TMSUSPEND"; + case XA_RDONLY: + return "XA_RDONLY"; + default: + return "" + Integer.toHexString(flag); + } + } + + public boolean equals(Object obj) { + return false; + } + + public int hashCode() { + return 1; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/Messages.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/Messages.java new file mode 100644 index 0000000..84e1c71 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/Messages.java
@@ -0,0 +1,65 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import java.util.*; + +/** + * collection of messages. + * + * @author Qingqing Ouyang + */ +public class Messages { + + private static Hashtable messages = new Hashtable(); + + public static void sendMessage (String destName, String message) { + if (messages.get(destName) != null) { + ((ArrayList) messages.get(destName)).add(message); + } else { + ArrayList list = new ArrayList(); + list.add(message); + messages.put(destName, list); + } + System.out.println("sendMessage. message at foo is " + Messages.hasMessages("Foo")); + } + + public static boolean hasMessages (String destName) { + return messages.get(destName) != null; + } + + public static ArrayList getMessages (String destName) { + return (ArrayList) messages.get(destName); + } + + public static void main (String[] args) { + if (args.length != 3) { + System.exit(1); + } + + String command = args[0]; + String destName = args[1]; + String message = args[2]; + + if (!"add".equals(command)) { + System.exit(1); + } + + sendMessage(destName, message); + System.out.println("Message : " + message + " sent to " + destName); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyAdminObject.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyAdminObject.java new file mode 100644 index 0000000..f33a711 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyAdminObject.java
@@ -0,0 +1,61 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +public class MyAdminObject implements java.io.Serializable { + + private String resetControl="NORESET"; + private Integer expectedResults; + + public void setResetControl (String value) { + resetControl = value; + } + + public String getResetControl () { + return resetControl; + } + + public void setExpectedResults (Integer value) { + expectedResults = value; + } + + public Integer getExpectedResults () { + return expectedResults; + } + + public void initialize() { + System.out.println("[MyAdminObject] Initializing the Controls to false:"+resetControl); + if (resetControl.equals("BEGINNING")) { + Controls.done=false; + System.out.println("[MyAdminObject] Initialized the Controls to false"); + } + } + + public boolean done() { + return Controls.done; + } + + public int expectedResults(){ + return Controls.expectedResults; + } + + public Object getLockObject(){ + return Controls.readyLock; + } + +} +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyMessageListener.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyMessageListener.java new file mode 100644 index 0000000..a3928d3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyMessageListener.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +public interface MyMessageListener { + public void onMessage (String message); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyWork.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyWork.java new file mode 100644 index 0000000..0513628 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/MyWork.java
@@ -0,0 +1,105 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import java.lang.reflect.Method; +import java.util.Iterator; +import javax.resource.spi.endpoint.MessageEndpoint; +import javax.resource.spi.endpoint.MessageEndpointFactory; +import javax.resource.spi.UnavailableException; +import javax.resource.spi.work.Work; +import javax.resource.spi.work.WorkManager; +import javax.resource.spi.work.ExecutionContext; + +/** + * + * @author Qingqing Ouyang + */ +public class MyWork implements Work { + + private String name; + private boolean stop = false; + private MessageEndpointFactory factory; + private WorkManager wm; + + public MyWork( + String name, MessageEndpointFactory factory, WorkManager wm) { + this.factory = factory; + this.name = name; + this.wm = wm; + } + + public void run() { + + debug("ENTER..."); + + //try 3 times to create endpoint (in case of failure) + for (int i = 0; i < 3; i++) { + + try { + + Method onMessage = getOnMessageMethod(); + System.out.println("isDeliveryTransacted = " + + factory.isDeliveryTransacted(onMessage)); + + /* + MessageEndpoint ep = factory.createEndpoint(null); + ep.beforeDelivery(onMessage); + ((MyMessageListener) ep).onMessage(name + ": TEST MSG ONE"); + ((MyMessageListener) ep).onMessage(name + ": TEST MSG TWO"); + ((MyMessageListener) ep).onMessage(name + ": TEST MSG THREE"); + ep.afterDelivery(); + break; + */ + + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + debug("LEAVE..."); + } + + public void release() {} + + public void stop() { + this.stop = true; + } + + public String toString() { + return name; + } + + public Method getOnMessageMethod() { + + Method onMessageMethod = null; + try { + Class msgListenerClass = connector.MyMessageListener.class; + Class[] paramTypes = { java.lang.String.class }; + onMessageMethod = + msgListenerClass.getMethod("onMessage", paramTypes); + + } catch (NoSuchMethodException ex) { + ex.printStackTrace(); + } + return onMessageMethod; + } + + private void debug(String mesg) { + System.out.println("MyWork[" + name + "] --> " + mesg); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/SimpleActivationSpec.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/SimpleActivationSpec.java new file mode 100644 index 0000000..fc14e69 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/SimpleActivationSpec.java
@@ -0,0 +1,103 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import javax.resource.spi.ActivationSpec; +import javax.resource.spi.ResourceAdapter; + +/** + * This class is supposed to implemented as a JavaBean + * so that the app server can instantiate and configure + * it at the runtime. + * + * @author Qingqing Ouyang + */ +public class SimpleActivationSpec + implements ActivationSpec, java.io.Serializable { + + private String destinationName; + private String destinationType; + private String testProp; + private Integer testIntegerProp; + private ResourceAdapter resourceadapter; + + /** + * Default constructor. + */ + public SimpleActivationSpec () {} + + public String getDestinationName () { + return this.destinationName; + } + + public void setDestinationName (String name) { + debug("setDestinationName() called... name = " + name); + this.destinationName = name; + } + + public String getDestinationType() { + return this.destinationType; + } + + public void setDestinationType (String type) { + debug("setDestinationType () called... type = " + type); + this.destinationType= type; + } + + public String getTestProp() { + return this.testProp; + } + + public void setTestProp (String testProp) { + debug("setTestProp () called... testProp = " + testProp); + this.testProp = testProp; + } + + public Integer getTestIntegerProp() { + return this.testIntegerProp; + } + + public void setTestIntegerProp (Integer testProp1) { + debug("setTestIntegerProp () called... testIntegerProp = " + testProp1); + this.testIntegerProp = testProp1; + } + + public ResourceAdapter getResourceAdapter () { + debug("getResourceAdapter() called... "); + return this.resourceadapter; + } + + public void setResourceAdapter (ResourceAdapter ra) { + debug("setResourceAdapter() called... ra = " + ra); + this.resourceadapter = ra; + } + + public void validate() { + if (this.testIntegerProp.intValue() == 2 && this.testProp.equals("WrongValue")) { + //valid + } else { + throw new RuntimeException("Invalid Configuration testIntegerProp: " + this.testIntegerProp.intValue() + " testProp " + this.testProp); + + } + + } + + private void debug (String message) + { + System.out.println("[SimpleActivationSpec] ==> " + message); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/SimpleResourceAdapterImpl.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/SimpleResourceAdapterImpl.java new file mode 100644 index 0000000..4d4d6c4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/SimpleResourceAdapterImpl.java
@@ -0,0 +1,235 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.Properties; +import javax.resource.NotSupportedException; +import javax.resource.ResourceException; +import javax.resource.spi.ActivationSpec; +import javax.resource.spi.ActivationSpec; +import javax.resource.spi.BootstrapContext; +import javax.resource.spi.ResourceAdapter; +import javax.resource.spi.XATerminator; +import javax.resource.spi.endpoint.MessageEndpoint; +import javax.resource.spi.endpoint.MessageEndpointFactory; +import javax.resource.spi.UnavailableException; +import javax.resource.spi.ResourceAdapterInternalException; +import javax.resource.spi.work.ExecutionContext; +import javax.resource.spi.work.Work; +import javax.resource.spi.work.WorkManager; +import javax.transaction.xa.XAResource; +import javax.transaction.xa.Xid; + +/** + * This is a sample resource adapter + * + * @author Qingqing Ouyang + */ +public class SimpleResourceAdapterImpl +implements ResourceAdapter, java.io.Serializable { + + private BootstrapContext ctx; + private WorkManager wm; + private String testName; + + private boolean debug = true; + private Work work; + + public SimpleResourceAdapterImpl () { + debug ("constructor..."); + } + + public void + start(BootstrapContext ctx) throws ResourceAdapterInternalException{ + + debug("001. Simple RA start..."); + + this.ctx = ctx; + debug("002. Simple RA start..."); + this.wm = ctx.getWorkManager(); + debug("003. Simple RA start..."); + + //testing creat timer + Timer timer = null; + try{ + timer = ctx.createTimer(); + } catch(UnavailableException ue) { + System.out.println("Error"); + throw new ResourceAdapterInternalException("Error form bootstrap"); + } + debug("004. Simple RA start..."); + + try { + + XATerminator xa = ctx.getXATerminator(); + + Xid xid1 = new XID(); + System.out.println(" XID1 = " + xid1); + + ExecutionContext ec = new ExecutionContext(); + ec.setXid(xid1); + ec.setTransactionTimeout(5*1000); //5 seconds + TestWMWork outw = new TestWMWork(1000, false, true, ec); + outw.setWorkManager(wm); + try { + wm.doWork(outw, 1*1000, ec, null); + xa.commit(xid1, true); + } catch (Exception ex) { + + System.out.println(" ex = " + ex.getMessage()); + xa.rollback(xid1); + } + + Xid xid2 = new XID(); + System.out.println(" XID2 = " + xid2); + + ec = new ExecutionContext(); + ec.setXid(xid2); + ec.setTransactionTimeout(5*1000); //5 seconds + TestWMWork anotherw = new TestWMWork(3000, false); + anotherw.setWorkManager(wm); + try { + wm.doWork(anotherw, 1*1000, ec, null); + xa.commit(xid2, true); + } catch (Exception ex) { + xa.rollback(xid2); + } + + } catch (Exception ex) { + ex.printStackTrace(); + } + + + for (int i = 0 ; i < 3; i++) { + TestWMWork w = new TestWMWork(i, false); + try { + wm.doWork(w, 1, null, null); + } catch (Exception ex) { + System.out.println("FAIL: CAUGHT exception : i = " + i); + ex.printStackTrace(); + } + } + + for (int i = 3 ; i < 6; i++) { + TestWMWork w = new TestWMWork(i, true); + boolean pass = false; + try { + wm.doWork(w, 1, null, null); + } catch (Exception ex) { + pass = true; + System.out.println("PASS: CAUGHT EXPECTED exception : i = " + i); + ex.printStackTrace(); + } finally { + if (!pass) { + System.out.println("FAIL: DID NOT GET EXPECTED exception :"); + } + } + } + + for (int i = 6 ; i < 9; i++) { + TestWMWork w = new TestWMWork(i, false); + try { + wm.doWork(w, 1, null, null); + } catch (Exception ex) { + System.out.println("FAIL: CAUGHT exception : i = " + i); + ex.printStackTrace(); + } + } + + for (int i = 9 ; i < 12; i++) { + TestWMWork w = new TestWMWork(i, false); + try { + wm.startWork(w); + } catch (Exception ex) { + System.out.println("FAIL: CAUGHT exception : i = " + i); + ex.printStackTrace(); + } + } + + for (int i = 12 ; i < 15; i++) { + TestWMWork w = new TestWMWork(i, false); + try { + wm.scheduleWork(w); + } catch (Exception ex) { + System.out.println("FAIL: CAUGHT exception : i = " + i); + ex.printStackTrace(); + } + } + + debug("005. Simple RA start..."); + } + + public void + stop() { + debug("999. Simple RA stop..."); + if (work != null) { + ((WorkDispatcher) work).stop(); + + synchronized (Controls.readyLock) { + Controls.readyLock.notify(); + } + + } + } + + public void + endpointActivation ( MessageEndpointFactory factory, ActivationSpec spec) + throws NotSupportedException { + try { + debug("B.000. Create and schedule Dispatcher"); + spec.validate(); + work = new WorkDispatcher("DISPATCHER", ctx, factory, spec); + wm.scheduleWork(work, 4*1000, null, null); + debug("B.001. Scheduled Dispatcher"); + } catch (Exception ex) { + ex.printStackTrace(); + throw new RuntimeException(ex); + } + } + + public void + endpointDeactivation ( + MessageEndpointFactory endpointFactory, + ActivationSpec spec) { + debug ("endpointDeactivation called..."); + + ((WorkDispatcher) work).stop(); + } + + public String getTestName() { + return testName; + } + + public void setTestName(String name) { + debug("setTestName called... name = " + name); + testName = name; + } + + public void + debug (String message) { + if (debug) + System.out.println("[SimpleResourceAdapterImpl] ==> " + message); + } + + public XAResource[] getXAResources(ActivationSpec[] specs) + throws ResourceException { + throw new UnsupportedOperationException(); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/TestCDIBean.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/TestCDIBean.java new file mode 100644 index 0000000..c4ec82d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/TestCDIBean.java
@@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +//A test CDI bean that is bundled along with an embedded RAR +public class TestCDIBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/TestWMWork.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/TestWMWork.java new file mode 100644 index 0000000..f132758 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/TestWMWork.java
@@ -0,0 +1,112 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import java.lang.reflect.Method; +import java.util.Iterator; +import javax.resource.spi.endpoint.MessageEndpoint; +import javax.resource.spi.endpoint.MessageEndpointFactory; +import javax.resource.spi.UnavailableException; +import javax.resource.spi.work.ExecutionContext; +import javax.resource.spi.work.Work; +import javax.resource.spi.work.WorkManager; +import javax.resource.spi.work.WorkException; + +/** + * + * @author Qingqing Ouyang + */ +public class TestWMWork implements Work { + + private boolean stop = false; + private int id; + private boolean isRogue; + private boolean doNest; + private WorkManager wm; + private ExecutionContext ctx; + + public TestWMWork(int id, boolean isRogue) { + this(id, isRogue, false, null); + } + + public TestWMWork(int id, boolean isRogue, + boolean doNest, ExecutionContext ctx) { + this.id = id; + this.isRogue = isRogue; + this.doNest = doNest; + this.ctx = ctx; + } + + public void setWorkManager (WorkManager wm) { + this.wm = wm; + } + + public void run() { + + System.out.println("TestWMWork[" + id + "].start running"); + if (!isRogue) { + try { + Thread.currentThread().sleep(1000); + } catch (Exception ex) { + System.out.println("TestWMWork[" + id + "].interrupted = "); + ex.printStackTrace(); + } + } else { + System.out.println("TestWMWork: Simulating rogue RA's Work: Expected Arithmetic Exception - divide by Zero"); + int j = 100/0; + } + + if (doNest && (wm != null)) { + Work nestedWork = new TestWMWork(8888, false); + try { + wm.doWork(nestedWork, 1*1000, ctx, null); + } catch (WorkException ex) { + if (ex.getErrorCode().equals( + WorkException.TX_CONCURRENT_WORK_DISALLOWED)) { + System.out.println("TestWMWork[" + id + "] " + + "PASS: CAUGHT EXPECTED = " + ex.getErrorCode()); + } else { + System.out.println("TestWMWork[" + id + "] " + + "FAIL: CAUGHT UNEXPECTED = " + ex.getErrorCode()); + } + } + + nestedWork = new TestWMWork(9999, false); + try { + ExecutionContext ec = new ExecutionContext(); + ec.setXid(new XID()); + ec.setTransactionTimeout(5*1000); //5 seconds + wm.doWork(nestedWork, 1*1000, ec, null); + } catch (Exception ex) { + System.out.println("TestWMWork[" + id + "] " + + "FAIL: CAUGHT UNEXPECTED = " + ex.getMessage()); + } + } + + System.out.println("TestWMWork[" + id + "].stop running"); + } + + public void release() {} + + public void stop() { + this.stop = true; + } + + public String toString() { + return String.valueOf(id); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/WorkDispatcher.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/WorkDispatcher.java new file mode 100644 index 0000000..5aa436c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/WorkDispatcher.java
@@ -0,0 +1,323 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import java.lang.reflect.Method; +import java.util.Iterator; +import javax.resource.spi.ActivationSpec; +import javax.resource.spi.BootstrapContext; +import javax.resource.spi.XATerminator; +import javax.resource.spi.endpoint.MessageEndpoint; +import javax.resource.spi.endpoint.MessageEndpointFactory; +import javax.resource.spi.UnavailableException; +import javax.resource.spi.work.Work; +import javax.resource.spi.work.WorkManager; +import javax.resource.spi.work.ExecutionContext; +import javax.transaction.xa.Xid; +import javax.transaction.xa.XAException; +import javax.transaction.xa.XAResource; + +/** + * + * @author Qingqing Ouyang + */ +public class WorkDispatcher implements Work { + + private boolean stop = false; + private String id; + private MessageEndpointFactory factory; + private BootstrapContext ctx; + private ActivationSpec spec; + private WorkManager wm; + private XATerminator xa; + + public WorkDispatcher( + String id, + BootstrapContext ctx, + MessageEndpointFactory factory, + ActivationSpec spec) { + this.id = id; + this.ctx = ctx; + this.factory = factory; + this.spec = spec; + this.wm = ctx.getWorkManager(); + this.xa = ctx.getXATerminator(); + } + + public void run() { + + debug("ENTER..."); + + try { + synchronized (Controls.readyLock) { + debug("WAIT..."); + Controls.readyLock.wait(); + + if (stop) { + return; + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + + debug("Running..."); + + //try 3 times to create endpoint (in case of failure) + for (int i = 0; i < 3; i++) { + + try { + + Method onMessage = getOnMessageMethod(); + System.out.println("isDeliveryTransacted = " + + factory.isDeliveryTransacted(onMessage)); + + if (!factory.isDeliveryTransacted(onMessage)) { + //MessageEndpoint ep = factory.createEndpoint(null); + //DeliveryWork d = new DeliveryWork("NO_TX", ep); + //wm.doWork(d, 0, null, null); + } else { + + //MessageEndpoint ep = factory.createEndpoint(null); + MessageEndpoint ep = factory.createEndpoint(new FakeXAResource()); + int numOfMessages = 5; + + //importing transaction + + //write/commit + ExecutionContext ec = startTx(); + debug("Start TX - " + ec.getXid()); + + DeliveryWork w = + new DeliveryWork(ep, numOfMessages, "WRITE"); + wm.doWork(w, 0, ec, null); + xa.commit(ec.getXid(), true); + + debug("DONE WRITE TO DB"); + Controls.expectedResults = numOfMessages; + notifyAndWait(); + + //delete/rollback + ec = startTx(); + debug("Start TX - " + ec.getXid()); + + w = new DeliveryWork(ep, numOfMessages, "DELETE"); + wm.doWork(w, 0, ec, null); + xa.rollback(ec.getXid()); + + debug("DONE ROLLBACK FROM DB"); + Controls.expectedResults = numOfMessages; + notifyAndWait(); + + //delete/commit + ec = startTx(); + debug("Start TX - " + ec.getXid()); + + w = new DeliveryWork(ep, numOfMessages, "DELETE"); + wm.doWork(w, 0, ec, null); + xa.commit(ec.getXid(), true); + + debug("DONE DELETE FROM DB"); + Controls.expectedResults = 0; + notifyAndWait(); + + //write/commit + ec = startTx(); + debug("Start TX - " + ec.getXid()); + + w = new DeliveryWork(ep, numOfMessages, "WRITE"); + wm.doWork(w, 0, ec, null); + xa.commit(ec.getXid(), true); + + debug("DONE WRITE TO DB"); + Controls.expectedResults = numOfMessages; + notifyAndWait(); + + //delete/commit + ec = startTx(); + debug("Start TX - " + ec.getXid()); + + w = new DeliveryWork(ep, numOfMessages, "DELETE"); + wm.doWork(w, 0, ec, null); + xa.commit(ec.getXid(), true); + + debug("DONE DELETE FROM DB"); + Controls.expectedResults = 0; + notifyAndWait(); + + //write multiple times using doWork/commit + ec = startTx(); + debug("Start TX - " + ec.getXid()); + + w = new DeliveryWork(ep, 1, "WRITE", true); + wm.doWork(w, 0, ec, null); + wm.doWork(w, 0, ec, null); + wm.doWork(w, 0, ec, null); + xa.commit(ec.getXid(), true); + + debug("DONE WRITE TO DB"); + Controls.expectedResults = 3; + notifyAndWait(); + + //write multiple times using doWork/rollback + ec = startTx(); + debug("Start TX - " + ec.getXid()); + + w = new DeliveryWork(ep, 1, "WRITE", true); + wm.doWork(w, 0, ec, null); + wm.doWork(w, 0, ec, null); + wm.doWork(w, 0, ec, null); + xa.rollback(ec.getXid()); + + debug("DONE WRITE TO DB"); + Controls.expectedResults = 3; + notifyAndWait(); + + ec = startTx(); + debug("Start TX - " + ec.getXid()); + + //write multiple times using doWork/rollback + w = new DeliveryWork(ep, 2, "WRITE", true); + wm.doWork(w, 0, ec, null); + wm.doWork(w, 0, ec, null); + wm.doWork(w, 0, ec, null); + + if (XAResource.XA_OK == xa.prepare(ec.getXid())) { + xa.commit(ec.getXid(), false); + debug("XA PREPARE/COMMIT. DONE WRITE TO DB "); + Controls.expectedResults = 9; + notifyAndWait(); + } else { + xa.rollback(ec.getXid()); + debug("XA PREPARE UNSUCCESSFUL. DONE ROLLBACK"); + Controls.expectedResults = 3; + notifyAndWait(); + } + + //delete all. + ec = startTx(); + debug("Start TX - " + ec.getXid()); + + w = new DeliveryWork(ep, 1, "DELETE_ALL"); + wm.doWork(w, 0, ec, null); + xa.commit(ec.getXid(), true); + + debug("DONE DELETE ALL FROM DB"); + Controls.expectedResults = 0; + notifyAndWait(); + + done(); + } + + break; + } catch (UnavailableException ex) { + //ex.printStackTrace(); + System.out.println("WorkDispatcher["+id+"] Endpoint Unavailable"); + try { + Thread.currentThread().sleep(3*1000); //3 seconds + } catch (Exception e) { + e.printStackTrace(); + } + } catch (XAException ex) { + ex.printStackTrace(); + System.out.println("ERROR CODE = " + ex.errorCode); + done(); + break; + } catch (Exception ex) { + ex.printStackTrace(); + done(); + break; + } + } + + debug("LEAVE..."); + } + + public void release() {} + + public void stop() { + this.stop = true; + } + + public String toString() { + return id; + } + + public Method getOnMessageMethod() { + + Method onMessageMethod = null; + try { + Class msgListenerClass = connector.MyMessageListener.class; + Class[] paramTypes = { java.lang.String.class }; + onMessageMethod = + msgListenerClass.getMethod("onMessage", paramTypes); + + } catch (NoSuchMethodException ex) { + ex.printStackTrace(); + } + return onMessageMethod; + } + + private ExecutionContext startTx() { + ExecutionContext ec = new ExecutionContext(); + try { + Xid xid = new XID(); + ec.setXid(xid); + ec.setTransactionTimeout(5*1000); //5 seconds + } catch (Exception ex) { + ex.printStackTrace(); + } + return ec; + } + + private void notifyAndWait() { + try { + //Sleep for 5 seconds + //Thread.currentThread().sleep(5*1000); + + synchronized(Controls.readyLock) { + //Notify the client to check the results + Controls.readyLock.notify(); + + //Wait until results are verified by the client + Controls.readyLock.wait(); + + if (stop) { + return; + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + private void done() { + try { + Controls.done = true; + synchronized(Controls.readyLock) { + //Notify the client to check the results + Controls.readyLock.notify(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + private void debug(String mesg) { + System.out.println("Dispatcher[" + id + "] --> " + mesg); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/XID.java b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/XID.java new file mode 100644 index 0000000..138e91b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/standalone-resource-adapter-as-bean-archive/ra/src/connector/XID.java
@@ -0,0 +1,127 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package connector; + +import javax.transaction.xa.Xid; + +/** + * The XID class provides an implementation of the X/Open + * transaction identifier it implements the javax.transaction.xa.Xid interface. + */ +public class XID implements Xid { + + + private static int ID = initializeID(); + + private static int initializeID() { + return (int)(Math.random()*100000); + } + + public int formatID; // Format identifier + // (-1) means that the XID is null + public int branchQualifier; + public int globalTxID; + + static public final int MAXGTRIDSIZE= 64; + static public final int MAXBQUALSIZE= 64; + + public XID() { + int foo = ID++; + formatID = foo; + branchQualifier = foo; + globalTxID = foo; + } + + public boolean equals(Object o) { + XID other; // The "other" XID + int L; // Combined gtrid_length + bqual_length + int i; + + if (!(o instanceof XID)) // If the other XID isn't an XID + { + return false; // It can't be equal + } + + other = (XID)o; // The other XID, now properly cast + + if (this.formatID == other.formatID + && this.branchQualifier == other.branchQualifier + && this.globalTxID == other.globalTxID) { + return true; + } + + return false; + } + + /** + * Compute the hash code. + * + * @return the computed hashcode + */ + public int hashCode() { + if (formatID == (-1)) { + return (-1); + } + + return formatID + branchQualifier + globalTxID; + + } + + /* + * Convert to String + * + * <p> This is normally used to display the XID when debugging. + */ + + /** + * Return a string representing this XID. + * + * @return the string representation of this XID + */ + public String toString() { + + String s = new String("{XID: " + + "formatID(" + formatID + "), " + + "branchQualifier (" + branchQualifier + "), " + + "globalTxID(" + globalTxID + ")}"); + + return s; + } + + /* + * Return branch qualifier + */ + + /** + * Returns the branch qualifier for this XID. + * + * @return the branch qualifier + */ + public byte[] getBranchQualifier() { + String foo = (new Integer(branchQualifier)).toString(); + return foo.getBytes(); + } + + public int getFormatId() { + return formatID; + } + + public byte[] getGlobalTransactionId() { + String foo = (new Integer(globalTxID)).toString(); + return foo.getBytes(); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/lib/ant-contrib-1.0b3.jar b/appserver/tests/appserv-tests/devtests/cdi/lib/ant-contrib-1.0b3.jar new file mode 100644 index 0000000..0625376 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/lib/ant-contrib-1.0b3.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/build.xml b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/build.xml new file mode 100644 index 0000000..5476c34 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/build.xml
@@ -0,0 +1,100 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<project name="managedbeans-test" default="usage" basedir="."> + + <property name="managedbeans-target" value="all"/> + + <target name="run-test"> + <antcall target="managedbeans"> + <param name="managedbeans-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="managedbeans"> + <param name="managedbeans-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="managedbeans"> + <param name="managedbeans-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="managedbeans"> + <param name="managedbeans-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="managedbeans"> + <param name="managedbeans-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="managedbeans"> + <param name="managedbeans-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="managedbeans"> + <param name="managedbeans-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="managedbeans"> + <param name="managedbeans-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="managedbeans"> + <param name="managedbeans-target" value="run"/> + </antcall> + </target> + + <target name="managedbeans"> + <record name="managedbeans.output" action="start" /> +<!-- + <ant dir="managed-bean-via-resource-injection" target="${managedbeans-target}"/> +--> + <ant dir="managed-bean-lifecycle-polymorphism" target="${managedbeans-target}"/> + + <record name="managedbeans.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant all (Executes all the managedbeans tests) + ant clean (cleans all the managedbeans tests) + ant build (builds all the managedbeans tests) + ant setup (sets up all resources for managedbeans tests) + ant deploy (deploys all the managedbeans apps) + ant run (Executes all the managedbeans tests) + ant undeploy (undeploys all the managedbeans apps) + ant unsetup (unsets all resources for managedbeans tests) + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/README b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/README new file mode 100644 index 0000000..c5b2856 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/README
@@ -0,0 +1,3 @@ +GLASSFISH-15148 + +https://issues.jboss.org/browse/WELD-1225
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/WebTest.java new file mode 100644 index 0000000..e736b97 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/WebTest.java
@@ -0,0 +1,112 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "managed-bean-lifecycle-inheritance"; + private static final String EXPECTED_RESPONSE = + "Hello from Servlet 3.0. initParams: n1=v1, n2=v2" + + " | TestManagedBean injected via @Inject : TestManagedBeanExtension#PostConstruct" + + " | pc count = 1"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/build.properties b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/build.properties new file mode 100644 index 0000000..c0f20bb --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/build.properties
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-managed-bean-lifecycle-polymorphism"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/build.xml b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/build.xml new file mode 100644 index 0000000..0a72e12 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="managed-bean-lifecyle-polymorphism" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/descriptor/beans.xml new file mode 100644 index 0000000..5388298 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/descriptor/beans.xml
@@ -0,0 +1,29 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> +<!-- + <interceptors> + <class>com.tests.TestAroundInvokeInterceptor</class> + </interceptors> +--> + <alternatives> + <class>com.tests.TestManagedBeanExtension</class> + </alternatives> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/TestAroundInvokeInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/TestAroundInvokeInterceptor.java new file mode 100644 index 0000000..099911d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/TestAroundInvokeInterceptor.java
@@ -0,0 +1,37 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.tests; + +import javax.interceptor.*; + +@Tester @Interceptor +public class TestAroundInvokeInterceptor { + public static int aroundInvokeCount = 0; + + public static void reset(){ + aroundInvokeCount = 0; + } + + @AroundInvoke + public Object testMethod(InvocationContext ctx) throws Exception { + System.out.println("TestAroundInvokeInterceptor:: aroundInvoke called - target:" + ctx.getTarget() + " , params:"+ ctx.getParameters()); + aroundInvokeCount ++; + ctx.proceed(); + return null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/TestBean.java new file mode 100644 index 0000000..925a588 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/TestBean.java
@@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.tests; + +public class TestBean { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/TestManagedBean.java b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/TestManagedBean.java new file mode 100644 index 0000000..7ab136d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/TestManagedBean.java
@@ -0,0 +1,77 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.tests; + + +@javax.annotation.ManagedBean +public class TestManagedBean { + + public static final String TOSTRING = "TestManagedBean"; + + protected int postConstructCount = 0; + + protected int preDestroyCount = 0; + + protected String postConstructMessage = ""; + + protected String preDestroyMessage = ""; + + @javax.annotation.PostConstruct + public void init() { + postConstructCount++; + postConstructMessage += TOSTRING + "#PostConstruct"; + System.out.println(postConstructMessage); + } + + @javax.annotation.PreDestroy + public void destroy() { + preDestroyCount++; + preDestroyMessage += TOSTRING + "#PreDestroy"; + System.out.println(preDestroyMessage); + } + + @Tester + public void foo() { + System.out.println(toString() + "#foo called"); + } + + public boolean testPostConstructCalled() { + return (postConstructCount > 0); + } + + public int getPostConstructCount() { + return postConstructCount; + } + + public int getPreDestroyCount() { + return preDestroyCount; + } + + public String getPostConstructMessage() { + return postConstructMessage; + } + + public String getPreDestroyMessage() { + return preDestroyMessage; + } + + @Override + public String toString() { + return TOSTRING; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/TestManagedBeanExtension.java b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/TestManagedBeanExtension.java new file mode 100644 index 0000000..19fed61 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/TestManagedBeanExtension.java
@@ -0,0 +1,45 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.tests; + +@javax.enterprise.inject.Alternative +@javax.annotation.ManagedBean +public class TestManagedBeanExtension extends TestManagedBean { + + public static final String TOSTRING_EXT = "TestManagedBeanExtension"; + + @javax.annotation.PostConstruct + public void init() { + postConstructCount++; + postConstructMessage += TOSTRING_EXT + "#PostConstruct"; + System.out.println(postConstructMessage); + } + + @javax.annotation.PreDestroy + public void destroy() { + preDestroyCount++; + preDestroyMessage += TOSTRING_EXT + "#PreDestroy"; + System.out.println(preDestroyMessage); + } + + + @Override + public String toString() { + return TOSTRING_EXT; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/TestServlet.java new file mode 100644 index 0000000..94a067b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/TestServlet.java
@@ -0,0 +1,72 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.tests; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.annotation.Generated; +import javax.annotation.Resource; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@SuppressWarnings("serial") +@WebServlet(name="mytest", + urlPatterns={"/myurl"}, + initParams={ @WebInitParam(name="n1", value="v1"), @WebInitParam(name="n2", value="v2") } ) +public class TestServlet extends HttpServlet { + + @javax.inject.Inject + TestManagedBean testResource; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + + ", n2=" + getInitParameter("n2"); + + msg += testManagedBean(testResource, " | TestManagedBean injected via @Inject"); + msg += testOverriddenMethods(); + + writer.write("initParams: " + msg + "\n"); + } + + private String testOverriddenMethods() { + return " | pc count = " + String.valueOf(testResource.getPostConstructCount()); + } + + private String testManagedBean(TestManagedBean tb, String info) { + String msg = info; + if (tb == null) { + msg += " is null!"; + } else { + if (!tb.testPostConstructCalled()) { + msg += " postConstruct not called"; + } else { + msg += " : " + tb.getPostConstructMessage(); + } + } + return msg; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/Tester.java b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/Tester.java new file mode 100644 index 0000000..a966727 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-lifecycle-polymorphism/servlet/com/tests/Tester.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.tests; + +import javax.interceptor.*; +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + + +@InterceptorBinding +@Target({METHOD, TYPE}) +@Retention(RUNTIME) +public @interface Tester {}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/README b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/README new file mode 100644 index 0000000..a15008e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/README
@@ -0,0 +1,2 @@ +Non-CDI usecase +Injection of a ManagedBean into a servlet through @Resource and invoking an overridden toString on that ManagedBean reference. [see issue 11528]
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/WebTest.java new file mode 100644 index 0000000..6a28a08 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/WebTest.java
@@ -0,0 +1,109 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "managed-bean-resource-injection"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/build.properties b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/build.properties new file mode 100644 index 0000000..91ab983 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/build.properties
@@ -0,0 +1,26 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-simple-managed-bean-interceptor"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<!-- +<property name="beans.xml" value="descriptor/beans.xml"> +-->
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/build.xml b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/build.xml new file mode 100644 index 0000000..83ad666 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/descriptor/beans.xml new file mode 100644 index 0000000..a52bc90 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/descriptor/beans.xml
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>com.tests.TestAroundInvokeInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/servlet/com/tests/TestAroundInvokeInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/servlet/com/tests/TestAroundInvokeInterceptor.java new file mode 100644 index 0000000..379dfbf --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/servlet/com/tests/TestAroundInvokeInterceptor.java
@@ -0,0 +1,37 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.tests; + +import javax.interceptor.*; + +@Tester @Interceptor +public class TestAroundInvokeInterceptor { + public static int aroundInvokeCount = 0; + + public static void reset(){ + aroundInvokeCount = 0; + } + + @AroundInvoke + public Object testMethod(InvocationContext ctx) throws Exception { + System.out.println("TestAroundInvokeIntercetpr:: aroundInvoke called - target:" + ctx.getTarget() + " , params:"+ ctx.getParameters()); + aroundInvokeCount ++; + ctx.proceed(); + return null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/servlet/com/tests/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/servlet/com/tests/TestBean.java new file mode 100644 index 0000000..8de8781 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/servlet/com/tests/TestBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.tests; + +//Simple Bean to test injection into ManagedBeans +public class TestBean { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/servlet/com/tests/TestManagedBean.java b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/servlet/com/tests/TestManagedBean.java new file mode 100644 index 0000000..366e381 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/servlet/com/tests/TestManagedBean.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.tests; + +//Simple TestBean to test CDI. +//This bean implements Serializable as it needs to be placed into a Stateful Bean +@javax.annotation.ManagedBean +public class TestManagedBean { + boolean postConstructCalled = false; + + public static final String TOSTRING = "TestManagedBean"; + + // A Managed Bean needs to have a no-arg constructor + public TestManagedBean() { + } + + @javax.annotation.PostConstruct + public void init() { + System.out.println("In ManagedBean:: PostConstruct"); + postConstructCalled = true; + } + + @Tester + public void foo() { + System.out.println("foo called"); + } + + public boolean testPostConstructCalled() { + return this.postConstructCalled; + } + + @Override + public String toString() { + return TestManagedBean.TOSTRING; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/servlet/com/tests/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/servlet/com/tests/TestServlet.java new file mode 100644 index 0000000..a55d437 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/servlet/com/tests/TestServlet.java
@@ -0,0 +1,65 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.tests; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@SuppressWarnings("serial") +@WebServlet(name="mytest", + urlPatterns={"/myurl"}, + initParams={ @WebInitParam(name="n1", value="v1"), @WebInitParam(name="n2", value="v2") } ) +public class TestServlet extends HttpServlet { + @javax.annotation.Resource TestManagedBean testResource; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + + ", n2=" + getInitParameter("n2"); + + msg += testManagedBean(testResource, " | TestManagedBean injected via @Resource"); + msg += testOverriddenMethods(); + + writer.write("initParams: " + msg + "\n"); + } + + private String testOverriddenMethods() { + String s = ""; + System.out.println("toString returned:" +testResource.toString()); + if (!testResource.toString().equals(TestManagedBean.TOSTRING)) + s += "TestManagedBean obtained via @Resource toString method invocation failed"; + return s; + } + + private String testManagedBean(TestManagedBean tb, String info) { + String msg = ""; + if (tb == null) msg += info + " is null!"; + if (tb != null && !tb.testPostConstructCalled()) msg += info + " postConstruct not called"; + return msg; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/servlet/com/tests/Tester.java b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/servlet/com/tests/Tester.java new file mode 100644 index 0000000..a966727 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/managed-beans/managed-bean-via-resource-injection/servlet/com/tests/Tester.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.tests; + +import javax.interceptor.*; +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + + +@InterceptorBinding +@Target({METHOD, TYPE}) +@Retention(RUNTIME) +public @interface Tester {}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/open-issues/build.xml b/appserver/tests/appserv-tests/devtests/cdi/open-issues/build.xml new file mode 100644 index 0000000..3488ae8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/open-issues/build.xml
@@ -0,0 +1,99 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<project name="openissues-test" default="usage" basedir="."> + + <property name="openissues-target" value="all"/> + + <target name="run-test"> + <antcall target="openissues"> + <param name="openissues-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="openissues"> + <param name="openissues-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="openissues"> + <param name="openissues-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="openissues"> + <param name="openissues-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="openissues"> + <param name="openissues-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="openissues"> + <param name="openissues-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="openissues"> + <param name="openissues-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="openissues"> + <param name="openissues-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="openissues"> + <param name="openissues-target" value="run"/> + </antcall> + </target> + + <target name="openissues"> + <record name="openissues.output" action="start" /> + <ant dir="../smoke-tests/simple-managed-bean-interceptor" target="${openissues-target}"/> <!-- WELD 728 --> + <ant dir="../managed-beans/managed-bean-via-resource-injection" target="${openissues-target}"/> <!-- IT 11528 --> + <ant dir="../javaee-component-resources/em-resource-injection-extended-transaction-context" target="${openissues-targer"/> <!--IT 11805 --> + <ant dir="../smoke-tests/singleton-startup/hello" target="${openissues-target}"/> <!-- IT 13072 --> + <record name="openissues.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant all (Executes all the openissues tests) + ant clean (cleans all the openissues tests) + ant build (builds all the openissues tests) + ant setup (sets up all resources for openissues tests) + ant deploy (deploys all the openissues apps) + ant run (Executes all the openissues tests) + ant undeploy (undeploys all the openissues apps) + ant unsetup (unsets all resources for openissues tests) + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/build.xml b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/build.xml new file mode 100644 index 0000000..bc0588f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/build.xml
@@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<project name="osgi-cdi-test" default="usage" basedir="."> + + <property name="osgi-cdi-target" value="all"/> + + <target name="run-test"> + <antcall target="osgi-cdi"> + <param name="osgi-cdi-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="osgi-cdi"> + <param name="osgi-cdi-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="osgi-cdi"> + <param name="osgi-cdi-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="osgi-cdi"> + <param name="osgi-cdi-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="osgi-cdi"> + <param name="osgi-cdi-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="osgi-cdi"> + <param name="osgi-cdi-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="osgi-cdi"> + <param name="osgi-cdi-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="osgi-cdi"> + <param name="osgi-cdi-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="osgi-cdi"> + <param name="osgi-cdi-target" value="run"/> + </antcall> + </target> + + <target name="osgi-cdi"> + <record name="osgi-cdi.output" action="start" /> + <ant dir="simple-wab-with-cdi" target="${osgi-cdi-target}"/> + <record name="osgi-cdi.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant all (Executes all the osgi-cdi tests) + ant clean (cleans all the osgi-cdi tests) + ant build (builds all the osgi-cdi tests) + ant setup (sets up all resources for osgi-cdi tests) + ant deploy (deploys all the osgi-cdi apps) + ant run (Executes all the osgi-cdi tests) + ant undeploy (undeploys all the osgi-cdi apps) + ant unsetup (unsets all resources for osgi-cdi tests) + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/common.xml b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/common.xml new file mode 100644 index 0000000..f396e66 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/common.xml
@@ -0,0 +1,1946 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!-- + This is the top level build file that should be + imported into all the leaf level build files +--> + +<!-- ================================================================ --> +<!-- Targets to clean class files and jars files --> +<!-- +Variables used: + ${build.classes.dir} + ${assemble.dir} +--> +<!-- ================================================================ --> +<target name="clean-classes-common" depends="init-common"> + <echo message="common.xml: Cleaning test source files: ${build.base.dir}" + level="verbose"/> + <delete dir="${build.base.dir}"/> +</target> + +<target name="clean-jars-common" depends="init-common"> + <delete dir="${assemble.dir}"/> +</target> + +<target name="clean-common" depends="init-common"> + <antcall target="clean-classes-common"/> + <antcall target="clean-jars-common"/> +</target> + +<!-- ================================================================ --> +<!-- Target to compile the java source files --> +<!-- +Variables used: + ${build.classes.dir} + ${s1astest.classpath} + ${src} +--> +<!-- ================================================================ --> +<target name="compile-common" depends="init-common"> + <mkdir dir="${build.classes.dir}"/> + <echo message="common.xml: Compiling test source files" level="verbose"/> + <mkdir dir="${src}"/> + <javac srcdir="${src}" + destdir="${build.classes.dir}" + classpath="${s1astest.classpath}" + debug="on" + failonerror="true"/> +</target> + +<!-- ================================================================ --> +<!-- This is the external target war-common to be called up build files +usage: +<antcall target="war-common"> +<param name="war.classes" value="MyServlet.class,MyOtherServlet.class"/> +</antcall> +Assumption: All the static content is placed in webcontent directory + +Variables Used: + ${war.file} + ${build.classes.dir} + ${appname} + ${assemble.dir} + ${web.xml} + ${beans.xml} + ${tlds} + ${tagfiles} + ${APS_HOME} + ${webclient.war.files} + ${webclient.war.classes} +--> +<!-- ================================================================ --> + +<target name="webclient-war-common" if="hasWebclient" depends="init-common"> + <mkdir dir="${assemble.dir}"/> + <antcall target="package-war-common"> + <param name="war.classes" value="${build.classes.dir}"/> + <param name="war.file" value="${assemble.dir}/${appname}-web.war"/> + </antcall> +</target> + +<target name="webclient-wab-common" if="hasWebclient" depends="init-common"> + <mkdir dir="${assemble.dir}"/> + <antcall target="package-wab-common"> + <param name="war.classes" value="${build.classes.dir}"/> + <param name="war.file" value="${assemble.dir}/${appname}-web.war"/> + </antcall> +</target> + + +<target name="publish-war-common" depends="init-common"> + <mkdir dir="${build.webapps.dir}"/> + <copy file="${assemble.dir}/${appname}-web.war" + tofile="${build.webapps.dir}/${appname}.war" + overwrite="true" /> +</target> + +<target name="clean-webapps-common" depends="init-common"> + <delete dir="${build.webapps.dir}" quiet="true" /> +</target> + +<target name="clear"> + <delete file="${war.file}"/> +</target> + +<target name="copy-tlds" if="tlds-exist" depends="clear,test-tlds-exist"> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF/tlds"/> + <copy todir="${build.classes.dir}/tmp/WEB-INF/tlds" failonerror="false"> + <fileset dir="${tlds}"> + <include name="**/*.tld"/> + </fileset> + </copy> +</target> + +<target name="copy-tagfiles" if="tagfiles-exist" depends="clear,test-tagfiles-exist"> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF/tags"/> + <copy todir="${build.classes.dir}/tmp/WEB-INF/tags" failonerror="false"> + <fileset dir="${tagfiles}"> + <include name="**/*.tag"/> + <include name="**/*.tagx"/> + </fileset> + </copy> +</target> + +<target name="package-war-common" depends="copy-tlds,copy-tagfiles"> + <echo message="my build classes dir is:${build.classes.dir}" level="verbose"/> + <mkdir dir="${build.classes.dir}/tmp"/> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF"/> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF/classes"/> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF/lib"/> + <mkdir dir="lib"/> + <copy file="${glassfish-web.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/glassfish-web.xml" failonerror="false"/> + <copy file="${sun-web.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/sun-web.xml" failonerror="false"/> + <copy file="${weblogic.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/weblogic.xml" failonerror="false"/> + <copy file="${glassfish-resources.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/glassfish-resources.xml" failonerror="false"/> + <copy todir="${build.classes.dir}/tmp/WEB-INF/lib" failonerror="false"> + <fileset dir="lib"> + <include name="**/*.jar"/> + <include name="**/*.zip"/> + </fileset> + </copy> + <copy file="${webservices.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/webservices.xml" + failonerror="false"/> + <copy file="${mappingfile.location}/${mappingfile.name}" + tofile="${build.classes.dir}/tmp/${mappingfile.name}" + failonerror="false"/> + <copy file="${wsdlfile.location}/${wsdlfile.name}" + tofile="${build.classes.dir}/tmp/WEB-INF/wsdl/${wsdlfile.name}" + failonerror="false"/> + <copy file="${tagPlugins.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/tagPlugins.xml" + failonerror="false"/> + <copy file="${web.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/web.xml" + failonerror="false"/> + <copy file="${persistence.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/classes/META-INF/persistence.xml" + failonerror="false"/> + <copy file="${beans.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/beans.xml" + failonerror="false"/> + <copy file="${context.xml}" + tofile="${build.classes.dir}/tmp/META-INF/context.xml" failonerror="false"/> + <copy file="${cdi-extension.service}" + tofile="${build.classes.dir}/tmp/WEB-INF/classes/META-INF/services/javax.enterprise.inject.spi.Extension" failonerror="false"/> + + <copy todir="${build.classes.dir}/tmp/WEB-INF/classes"> + <fileset dir="${war.classes}"> + <include name="**/*.class"/> + </fileset> + </copy> + <echo message="Creating war file ${war.file}" level="verbose"/> + <mkdir dir="${basedir}/docroot"/> + <jar jarfile="${war.file}" update="true"> + <fileset dir="${build.classes.dir}/tmp" casesensitive="yes"> + <include name="**/*class*"/> + </fileset> + <fileset dir="${basedir}/docroot" casesensitive="yes"> + <include name="**/*.html"/> + <include name="**/*.HTML"/> + <include name="**/*.xhtml"/> + <include name="**/*.jsp"/> + <include name="**/*.jspx"/> + <include name="**/*.jspf"/> + <include name="**/*.gif"/> + <include name="**/*.do"/> + <include name="**/*.txt"/> + <include name="**/*.shtml"/> + <include name="**/*.jar"/> + <exclude name="**/*.java,**/*.xml,**/*.properties"/> + </fileset> + <fileset dir="${build.classes.dir}/tmp/" casesensitive="true"> + <include name="WEB-INF/web.xml"/> + <include name="WEB-INF/glassfish-web.xml"/> + <include name="WEB-INF/glassfish-resources.xml"/> + <include name="WEB-INF/sun-web.xml"/> + <include name="WEB-INF/beans.xml"/> + <include name="WEB-INF/weblogic.xml"/> + <include name="WEB-INF/webservices.xml"/> + <include name="WEB-INF/tagPlugins.xml"/> + <include name="WEB-INF/lib/*"/> + <include name="WEB-INF/lib/extra/*"/> + <include name="WEB-INF/tlds/*"/> + <include name="WEB-INF/tags/*"/> + <include name="WEB-INF/wsdl/${wsdlfile.name}"/> + <include name="${mappingfile.name}"/> + <include name="META-INF/context.xml"/> + <include name="WEB-INF/classes/META-INF/services/javax.enterprise.inject.spi.Extension"/> + <include name="WEB-INF/classes/META-INF/persistence.xml"/> + </fileset> + </jar> + <echo message="created war file ${war.file}" level="verbose"/> + <delete dir="${build.classes.dir}/tmp/WEB-INF" failonerror="false"/> + <echo message="my webclient war classes are:${webclient.war.classes}" + level="verbose"/> +</target> + +<target name="package-wab-common" depends="copy-tlds,copy-tagfiles"> + <echo message="my build classes dir is:${build.classes.dir}" level="verbose"/> + <mkdir dir="${build.classes.dir}/tmp"/> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF"/> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF/classes"/> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF/lib"/> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF/META-INF"/> + <mkdir dir="lib"/> + <copy file="${glassfish-web.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/glassfish-web.xml" failonerror="false"/> + <copy file="${sun-web.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/sun-web.xml" failonerror="false"/> + <copy file="${weblogic.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/weblogic.xml" failonerror="false"/> + <copy file="${glassfish-resources.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/glassfish-resources.xml" failonerror="false"/> + <copy todir="${build.classes.dir}/tmp/WEB-INF/lib" failonerror="false"> + <fileset dir="lib"> + <include name="**/*.jar"/> + <include name="**/*.zip"/> + </fileset> + </copy> + <copy file="${webservices.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/webservices.xml" + failonerror="false"/> + <copy file="${mappingfile.location}/${mappingfile.name}" + tofile="${build.classes.dir}/tmp/${mappingfile.name}" + failonerror="false"/> + <copy file="${wsdlfile.location}/${wsdlfile.name}" + tofile="${build.classes.dir}/tmp/WEB-INF/wsdl/${wsdlfile.name}" + failonerror="false"/> + <copy file="${tagPlugins.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/tagPlugins.xml" + failonerror="false"/> + <copy file="${web.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/web.xml" + failonerror="false"/> + <copy file="${persistence.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/classes/META-INF/persistence.xml" + failonerror="false"/> + <copy file="${beans.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/beans.xml" + failonerror="false"/> + + <copy file="${bundle.descriptor}" + tofile="${build.classes.dir}/tmp/WEB-INF/classes/META-INF/MANIFEST.MF" + failonerror="false"/> + <copy file="${context.xml}" + tofile="${build.classes.dir}/tmp/META-INF/context.xml" failonerror="false"/> + <copy file="${cdi-extension.service}" + tofile="${build.classes.dir}/tmp/WEB-INF/classes/META-INF/services/javax.enterprise.inject.spi.Extension" failonerror="false"/> + + <copy todir="${build.classes.dir}/tmp/WEB-INF/classes"> + <fileset dir="${war.classes}"> + <include name="**/*.class"/> + </fileset> + </copy> + <echo message="Creating war file ${war.file}" level="verbose"/> + <mkdir dir="${basedir}/docroot"/> + <jar manifest="${bundle.descriptor}" jarfile="${war.file}" update="true"> + <fileset dir="${build.classes.dir}/tmp" casesensitive="yes"> + <include name="**/*class*"/> + </fileset> + <fileset dir="${basedir}/docroot" casesensitive="yes"> + <include name="**/*.html"/> + <include name="**/*.HTML"/> + <include name="**/*.xhtml"/> + <include name="**/*.jsp"/> + <include name="**/*.jspx"/> + <include name="**/*.jspf"/> + <include name="**/*.gif"/> + <include name="**/*.do"/> + <include name="**/*.txt"/> + <include name="**/*.shtml"/> + <include name="**/*.jar"/> + <exclude name="**/*.java,**/*.xml,**/*.properties"/> + </fileset> + <fileset dir="${build.classes.dir}/tmp/" casesensitive="true"> + <include name="WEB-INF/web.xml"/> + <include name="WEB-INF/glassfish-web.xml"/> + <include name="WEB-INF/glassfish-resources.xml"/> + <include name="WEB-INF/sun-web.xml"/> + <include name="WEB-INF/beans.xml"/> + <include name="WEB-INF/weblogic.xml"/> + <include name="WEB-INF/webservices.xml"/> + <include name="WEB-INF/tagPlugins.xml"/> + <include name="WEB-INF/lib/*"/> + <include name="WEB-INF/lib/extra/*"/> + <include name="WEB-INF/tlds/*"/> + <include name="WEB-INF/tags/*"/> + <include name="WEB-INF/wsdl/${wsdlfile.name}"/> + <include name="${mappingfile.name}"/> + <include name="META-INF/context.xml"/> + <include name="WEB-INF/classes/META-INF/services/javax.enterprise.inject.spi.Extension"/> + <include name="WEB-INF/classes/META-INF/persistence.xml"/> + </fileset> + </jar> + <echo message="created WAB file ${war.file}" level="verbose"/> + <delete dir="${build.classes.dir}/tmp/WEB-INF" failonerror="false"/> + <echo message="my webclient WAB classes are:${webclient.war.classes}" + level="verbose"/> +</target> + + +<target name="test-tlds-exist"> + <available file="${tlds}" property="tlds-exist"/> +</target> + +<target name="test-tagfiles-exist"> + <available file="${tagfiles}" property="tagfiles-exist"/> +</target> + +<!-- ================================================================ --> +<!-- Target to package the ejb application to jar file --> +<!-- +Variables Used: + ${ejb.jar} + ${build.classes.dir} + ${ejb-jar.xml} + ${beans.xml} + ${persistence-orm.xml} + ${sun-ejb-jar.xml} + ${glassfish-ejb-jar.xml} + ${sun-cmp-mappings.xml} + ${metainf.dir} + ${ejbjar.files} + ${dbschema} +--> +<!-- ================================================================ --> +<target name="package-ejbjar-common"> + <delete file="${ejb.jar}"/> + <echo message="common.xml: Generating ejb-jar inside build directory" + level="verbose"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <copy file="${ejb-jar.xml}" + tofile="${build.classes.dir}/META-INF/ejb-jar.xml" + failonerror="false"/> + <copy file="${persistence-orm.xml}" + tofile="${build.classes.dir}/META-INF/persistence-orm.xml" + failonerror="false"/> + <copy file="${webservices.xml}" + tofile="${build.classes.dir}/META-INF/webservices.xml" + failonerror="false"/> + <copy file="${sun-ejb-jar.xml}" + tofile="${build.classes.dir}/META-INF/sun-ejb-jar.xml" + failonerror="false"/> + <copy file="${glassfish-ejb-jar.xml}" + tofile="${build.classes.dir}/META-INF/glassfish-ejb-jar.xml" + failonerror="false"/> + <copy file="${glassfish-resources.xml}" + tofile="${build.classes.dir}/META-INF/glassfish-resources.xml" + failonerror="false"/> + <copy file="${sun-cmp-mappings.xml}" + tofile="${build.classes.dir}/META-INF/sun-cmp-mappings.xml" + failonerror="false"/> + <copy file="${beans.xml}" + tofile="${build.classes.dir}/META-INF/beans.xml" + failonerror="false"/> + <copy file="${dbschema}" todir="${build.classes.dir}" failonerror="false"/> + <jar jarfile="${ejb.jar}" basedir="${ejbjar.files}" update="true" + includes ="${ejbjar.classes}"> + <metainf dir="${build.classes.dir}/META-INF"> + <include name="ejb-jar.xml"/> + <include name="persistence-orm.xml"/> + <include name="webservices.xml"/> + <include name="sun-ejb-jar.xml"/> + <include name="glassfish-resources.xml"/> + <include name="glassfish-ejb-jar.xml"/> + <include name="sun-cmp-mappings.xml"/> + <include name="beans.xml"/> + </metainf> + </jar> + <delete dir="${build.classes.dir}/META-INF" failonerror="false"/> + <delete file="${build.classes.dir}/*.dbschema" failonerror="false"/> +</target> + +<!-- ================================================================ --> +<!-- Target to package the appclient application to jar file --> +<!-- +Variables Used: + ${appclient.jar} + ${appclientjar.classes} + ${appclientjar.files} + ${build.classes.dir} + ${application-client.xml} + ${sun-application-client.xml} +--> +<!-- ================================================================ --> +<target name="package-appclientjar-common"> + <delete file="${appclient.jar}"/> + <echo message="common.xml: Generating appclient-jar inside build directory" + level="verbose"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <copy file="${application-client.xml}" + tofile="${build.classes.dir}/META-INF/application-client.xml" + failonerror="false"/> + <copy file="${sun-application-client.xml}" tofile="${build.classes.dir}/META-INF/sun-application-client.xml" + failonerror="false"/> + <jar jarfile="${appclient.jar}" basedir="${appclientjar.files}" + update="true" includes ="${appclientjar.classes}" + manifest="./client/MANIFEST.MF"> + <metainf dir="${build.classes.dir}/META-INF"> + <include name="application-client.xml"/> + <include name="sun-application-client.xml"/> + </metainf> + </jar> +</target> + +<!-- ================================================================ --> +<!-- Target to create the ejb application jar file --> +<!-- ================================================================ --> +<target name="ejb-jar-common" depends="init-common"> + <mkdir dir="${assemble.dir}"/> + <antcall target="package-ejbjar-common"> + <param name="ejbjar.files" value="${build.classes.dir}"/> + <param name="ejb.jar" value="${assemble.dir}/${appname}-ejb.jar"/> + </antcall> +</target> + +<!-- ================================================================ --> +<!-- Target to create the appclient jar file --> +<!-- ================================================================ --> +<target name="appclient-jar-common" depends="init-common"> + <mkdir dir="${assemble.dir}"/> + <antcall target="package-appclientjar-common"> + <param name="appclientjar.files" + value="${build.classes.dir}"/> + <param name="appclient.jar" + value="${assemble.dir}/${appname}-client.jar"/> + </antcall> +</target> + +<!-- ===== package par ===== --> +<target name="package-persistence-common" depends="init-common" if="ejb30-persistence"> + <echo message="CREATING Persistence archive: common.xml: ${build.classes.dir}, ${assemble.dir}"/> + <mkdir dir="${assemble.dir}"/> + <delete file="${assemble.dir}/${appname}-persistence.jar" failonerror="false"/> + <echo message="common.xml: Generating PAR inside build directory"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <copy file="${persistence.xml}" tofile="${build.classes.dir}/META-INF/persistence.xml" failonerror="false"/> + <copy file="${mapping.xml}" tofile="${build.classes.dir}/META-INF/entity-mapping.xml" failonerror="false"/> + <!-- make a jar --> + <jar jarfile="${assemble.dir}/${appname}-persistence.jar" basedir="${build.classes.dir}" update="true" includes ="**/*.class" excludes="**/*Local*.class,**/*Remote*.class,**/*Home*.class,**/*Bean*.class,**/*EJB*.class,**/*Exception.class"> + <metainf dir="${build.classes.dir}/META-INF"> + <include name="**/*.xml"/> + </metainf> + </jar> + <delete dir="${build.classes.dir}/META-INF" failonerror="false"/> +</target> + +<!-- ================================================================ --> +<!-- Target to assemble the ejb application to ear file --> +<!-- ================================================================ --> +<target name="build-ear-common" depends="fixFiles,package-persistence-common,ejb-jar-common,appclient-jar-common,webclient-war-common"> + <delete file="${assemble.dir}/${appname}.ear"/> + <mkdir dir="${assemble.dir}"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <copy file="${sun-application.xml}" tofile="${build.classes.dir}/META-INF/sun-application.xml" failonerror="false"/> + <copy file="${application.xml}" tofile="${build.classes.dir}/META-INF/application.xml" failonerror="false"/> + <copy file="${glassfish-resources-ear.xml}" tofile="${build.classes.dir}/META-INF/glassfish-resources.xml" failonerror="false" filtering="true"/> + <jar jarfile="${assemble.dir}/${appname}App.ear"> + <fileset dir="${assemble.dir}"> + <include name="*.jar"/> + <include name="*.war"/> + </fileset> + <fileset dir="${build.classes.dir}"> + <include name="META-INF/sun-application.xml"/> + <include name="META-INF/application.xml"/> + <include name="META-INF/glassfish-resources.xml"/> + </fileset> + <fileset dir="${env.APS_HOME}" includes="lib/reporter.jar"/> + </jar> +</target> + + +<!-- ================================================================ --> +<!-- Target to assemble the ejb application to ear file --> +<!-- ================================================================ --> +<target name="ear-common" depends="fixFiles,init-common"> + <delete file="${assemble.dir}/${appname}.ear"/> + <mkdir dir="${assemble.dir}"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <copy file="${sun-application.xml}" tofile="${build.classes.dir}/META-INF/sun-application.xml" failonerror="false"/> + <copy file="${glassfish-resources-ear.xml}" tofile="${build.classes.dir}/META-INF/glassfish-resources.xml" failonerror="false" filtering="true"/> + <ear earfile="${assemble.dir}/${appname}App.ear" + appxml="${application.xml}"> + <fileset dir="${assemble.dir}"> + <include name="*.jar"/> + <include name="*.war"/> + </fileset> + <fileset dir="${build.classes.dir}"> + <include name="META-INF/sun-application.xml"/> + <include name="META-INF/glassfish-resources.xml"/> + </fileset> + <fileset dir="${env.APS_HOME}" includes="lib/reporter.jar"/> + </ear> +</target> + + +<!-- run Verifier on the ear file --> +<target name="verifier" depends="init-common"> + <echo message="Running verifier + ear file ${assemble.dir}/${appname}App.ear " level="verbose"/> + <antcall target="verifier-common"> + <param name="verifier.command" value=" -n -rw "/> + <param name="operand.props" value="${assemble.dir}/${appname}App.ear"/> + </antcall> + <echo message="Validate the static check results" level="verbose"/> +</target> + +<target name="verifier-common"> + <echo message="Operand ${operand.props}" level="verbose"/> + <exec executable="${VERIFIER}" failonerror="true"> + <arg line="${verifier.command} ${operand.props}" /> + </exec> +</target> + +<!-- ================================================================ --> +<!-- Target to execute asadmin commands --> +<!-- ================================================================ --> +<target name="asadmin-common"> + <echo message="Doing admin task ${admin.command}" level="verbose"/> + <echo message="Operand ${operand.props}" level="verbose"/> + <echo message="asadmin ${admin.command} ${as.props} ${operand.props}"/> + <exec executable="${ASADMIN}" failonerror="true"> + <arg line="${admin.command} ${as.props} ${operand.props}" /> + </exec> +</target> + +<target name="asadmin-common-ignore-fail"> + <echo message="Doing admin task ${admin.command} (ignore failures)" + level="verbose"/> + <echo message="Operand ${operand.props}" level="verbose"/> + <echo message="asadmin ${admin.command} ${as.props} ${operand.props}"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="${admin.command} ${as.props} ${operand.props}" /> + </exec> +</target> + + +<!-- Target to execute a batchfile of asadmin commands --> +<!-- ================================================================ --> +<target name="asadmin-batch-common"> + <echo message="Doing admin batch task ${admin.command} --file" + level="verbose"/> +<property name="user.password.file" value="asadminuserpassword.txt"/> +<echo file="${user.password.file}" append="false"> +AS_ADMIN_USERPASSWORD=${password} +AS_ADMIN_PASSWORD=${admin.password} +AS_ADMIN_ADMINPASSWORD=${admin.password} +AS_ADMIN_MASTERPASSWORD=${master.password} +</echo> + <exec executable="${ASADMIN}" failonerror="true"> + <arg line="--user ${admin.user} --passwordfile ${user.password.file} --host ${admin.host} --port ${admin.port} --echo=true --terse=true"/> + <arg line="multimode --file ${asadmin.file}" /> + </exec> + <delete file="${user.password.file}" failonerror="false"/> +</target> + +<!-- ================================================================ --> + +<!-- ================================================================ --> +<!-- Target to create the user in file realm the AppServ --> +<!-- ================================================================ --> +<target name="create-user-common" depends="init-common"> +<property name="user.password.file" value="asadminuserpassword.txt"/> +<echo file="${user.password.file}" append="false"> +AS_ADMIN_USERPASSWORD=${password} +AS_ADMIN_PASSWORD=${admin.password} +AS_ADMIN_ADMINPASSWORD=${admin.password} +AS_ADMIN_MASTERPASSWORD=${master.password} +</echo> + <exec executable="${ASADMIN}"> + <arg line="create-file-user"/> + <arg line="--user ${admin.user} --passwordfile ${user.password.file} --host ${admin.host} --port ${admin.port} --echo=true --terse=true"/> + <arg line="--groups ${groups}"/> + <arg line="--authrealmname ${authrealmname}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${user}"/> + </exec> + <delete file="${user.password.file}" failonerror="false"/> +</target> + +<!-- ================================================================ --> +<!-- Target to delete the user in file realm the AppServ --> +<!-- ================================================================ --> +<target name="delete-user-common" depends="init-common"> +<echo message="Deleting user ${user} in file realm" level="verbose"/> +<exec executable="${ASADMIN}"> + <arg line="delete-file-user"/> + <arg line="${as.props}"/> + <arg line="--authrealmname ${authrealmname}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${user}"/> +</exec> +</target> + +<!-- ================================================================ --> +<!-- J2EE Connector related targets --> +<!-- ================================================================ --> + +<target name="create-connector-connpool-common" + depends="init-common, create-connector-connpool"/> + +<target name="create-connector-connpool" depends="init-common"> + <property name="failonerror" value="false"/> + <property name="extra-params" value=""/> + <echo message="asadmin create-connector-connection-pool ${as.props} --raname ${ra.name} --connectiondefinition ${connection.defname} --target ${appserver.instance.name} ${connector.conpool.name}"/> + <exec executable="${ASADMIN}" failonerror="${failonerror}"> + <arg line="create-connector-connection-pool"/> + <arg line="${as.props}"/> + <arg line="--raname ${ra.name}"/> + <arg line="${extra-params}"/> + <arg line="--connectiondefinition ${connection.defname}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${connector.conpool.name}"/> + </exec> +</target> + +<target name="delete-connector-connpool-common" depends="init-common"> + <echo message="asadmin delete-connector-connection-pool ${as.props} --cascade=true ${connector.conpool.name}"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="delete-connector-connection-pool"/> + <arg line="${as.props}"/> + <arg line="--cascade=true"/> + <arg line="${connector.conpool.name}"/> + </exec> +</target> + +<!-- create/delete Connector resource --> +<target name="create-connector-resource-common" depends="init-common"> + <property name="failonerror" value="false"/> + <echo message="asadmin create-connector-resource ${as.props} --poolname ${connector.conpool.name} --target ${appserver.instance.name} ${connector.jndi.name}"/> + <exec executable="${ASADMIN}" failonerror="${failonerror}"> + <arg line="create-connector-resource"/> + <arg line="${as.props}"/> + <arg line="--poolname ${connector.conpool.name}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${connector.jndi.name}"/> + </exec> +</target> + +<target name="delete-connector-resource-common" depends="init-common"> + <echo message="asadmin delete-connector-resource ${as.props} ${connector.jndi.name}"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="delete-connector-resource"/> + <arg line="${as.props}"/> + <arg line="${connector.jndi.name}"/> + </exec> +</target> + +<!-- deploy/undeploy RAR files --> +<target name="deploy-rar-common" depends="init-common"> + <echo message="Deploying ${rarfile}" level="verbose"/> + <echo message="asadmin deploy ${as.props} --target ${appserver.instance.name} --force=${force} ${rarfile}"/> + <property name="force" value="false"/> + <property name="extra-params" value=""/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="${extra-params}"/> + <arg line="--force=${force}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${rarfile}"/> + </exec> + <echo message="Deploying ${rarfile} on ${appserver.instance.name}"/> +</target> + +<target name="undeploy-rar-common" depends="init-common"> + <echo message="Undeploying ${undeployrar}" level="verbose"/> + <echo message="asadmin undeploy ${as.props} --target ${appserver.instance.name} --cascade=${cascade} ${undeployrar}"/> + <property name="cascade" value="false"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="undeploy"/> + <arg line="${as.props}"/> + <arg line="--cascade=${cascade}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${undeployrar}"/> + </exec> +</target> + +<!-- ================================================================ --> +<!-- Target to create JDBC connection pool --> +<!-- ================================================================ --> +<target name="create-jdbc-connpool-common" depends="init-common"> +<echo message="created jdbc connection pool ${jdbc.conpool.name}" + level="verbose"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="create-jdbc-connection-pool"/> + <arg line="--datasourceclassname ${db.class}"/> + <arg line="--restype ${jdbc.resource.type}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${as.props}"/> + <arg line="${jdbc.conpool.name}"/> + </exec> + <antcall target="set-${db.type}-connpool-props"/> +</target> + +<target name="create-jdbc-driver-connpool-common" depends="init-common"> +<echo message="created jdbc connection pool ${jdbc.conpool.name}" + level="verbose"/> + <property name="extra-params" value=""/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="create-jdbc-connection-pool"/> + <arg line="--driverclassname ${db.class}"/> + <arg line="--restype ${jdbc.resource.type}"/> + <arg line="${extra-params}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${as.props}"/> + <arg line="${jdbc.conpool.name}"/> + </exec> + <antcall target="set-${db.type}-driver-connpool-props"/> +</target> + +<target name="set-pointbase-connpool-props"> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.jdbc-connection-pool.${jdbc.conpool.name}.property.DatabaseName=${db.url}"/> + </antcall> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.jdbc-connection-pool.${jdbc.conpool.name}.property.User=${db.user}" /> + </antcall> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.jdbc-connection-pool.${jdbc.conpool.name}.property.Password=${db.pwd}" /> + </antcall> +</target> + +<target name="set-pointbase-driver-connpool-props"> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.jdbc-connection-pool.${jdbc.conpool.name}.property.URL=${db.url};user=${db.user};password=${db.pwd}"/> + </antcall> +</target> + +<target name="set-derby-connpool-props"> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="set"/> + <arg line="${as.props}"/> + <arg line="domain.resources.jdbc-connection-pool.${jdbc.conpool.name}.property.User=${db.user}"/> + </exec> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="set"/> + <arg line="${as.props}"/> + <arg line="domain.resources.jdbc-connection-pool.${jdbc.conpool.name}.property.Password=${db.pwd}"/> + </exec> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="set"/> + <arg line="${as.props}"/> + <arg line="domain.resources.jdbc-connection-pool.${jdbc.conpool.name}.property.driverType=4"/> + </exec> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="set"/> + <arg line="${as.props}"/> + <arg line="domain.resources.jdbc-connection-pool.${jdbc.conpool.name}.property.portNumber=${db.port}"/> + </exec> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="set"/> + <arg line="${as.props}"/> + <arg line="domain.resources.jdbc-connection-pool.${jdbc.conpool.name}.property.dataBaseName=${db.name}"/> + </exec> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="set"/> + <arg line="${as.props}"/> + <arg line="domain.resources.jdbc-connection-pool.${jdbc.conpool.name}.property.retrieveMessagesFromServerOnGetMessage=true"/> + </exec> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="set"/> + <arg line="${as.props}"/> + <arg line="domain.resources.jdbc-connection-pool.${jdbc.conpool.name}.property.create=true"/> + </exec> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="set"/> + <arg line="${as.props}"/> + <arg line="domain.resources.jdbc-connection-pool.${jdbc.conpool.name}.property.serverName=${db.host}"/> + </exec> +</target> + +<target name="set-derby-driver-connpool-props"> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.jdbc-connection-pool.${jdbc.conpool.name}.property.URL=${db.url};user=${db.user};password=${db.pwd}"/> + </antcall> +</target> + +<!-- ================================================================ --> +<!-- Target to delete JDBC connection-pool --> +<!-- ================================================================ --> +<target name="delete-jdbc-connpool-common" depends="init-common"> +<echo message="asadmin delete-jdbc-connection-pool ${as.props} --cascade=true --target ${appserver.instance.name} ${jdbc.conpool.name}"/> +<exec executable="${ASADMIN}" failonerror="false"> + <arg line="delete-jdbc-connection-pool"/> + <arg line="${as.props}"/> + <arg line="--cascade=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${jdbc.conpool.name}"/> + </exec> + <echo message="cmd executed for ${appserver.instance.name}"/> +</target> + +<!-- ================================================================ --> +<!-- Target to create JDBC resource --> +<!-- ================================================================ --> +<target name="create-jdbc-resource-common" depends="init-common"> +<echo message="Creating jdbc resource pool ${jdbc.resource.name}" + level="verbose"/> + <echo message="asadmin create-jdbc-resource ${as.props} --connectionpoolid ${jdbc.conpool.name} --target ${appserver.instance.name} ${jdbc.resource.name}"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="create-jdbc-resource"/> + <arg line="${as.props}"/> + <arg line="--connectionpoolid ${jdbc.conpool.name}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${jdbc.resource.name}"/> + </exec> + <echo message="cmd executed for ${appserver.instance.name}"/> +</target> + +<!-- ================================================================ --> +<!-- Target to delete JDBC resource --> +<!-- ================================================================ --> +<target name="delete-jdbc-resource-common" depends="init-common"> +<echo message="asadmin delete-jdbc-resource ${as.props} --target ${appserver.instance.name} ${jdbc.resource.name}"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="delete-jdbc-resource"/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${jdbc.resource.name}"/> + </exec> + <echo message="cmd executed for ${appserver.instance.name}"/> +</target> + +<!-- ================================================================ --> +<!-- Target to deploy JDBC resources --> +<!-- ================================================================ --> +<target name="deploy-jdbc-common" depends="init-common"> + <antcall target="create-jdbc-connpool-common" /> + <antcall target="create-jdbc-resource-common" /> +</target> + +<target name="deploy-jdbc-driver-common" depends="init-common"> + <antcall target="create-jdbc-driver-connpool-common" /> + <antcall target="create-jdbc-resource-common" /> +</target> + +<!-- ================================================================ --> +<!-- Target to undeploy JDBC resources --> +<!-- ================================================================ --> +<target name="undeploy-jdbc-common" depends="init-common"> + <antcall target="delete-jdbc-resource-common" /> + <antcall target="delete-jdbc-connpool-common" /> +</target> + +<!-- ================================================================ --> +<!-- Target to create persistence resource --> +<!-- ================================================================ --> +<target name="create-persistence-resource-common" depends="init-common"> +<echo message="Creating pm resource at ${pm.resource.name}" + level="verbose"/> + <echo message="asadmin create-persistence-resource ${as.props} --target ${appserver.instance.name} ${pm.resource.name}"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="create-persistence-resource"/> + <arg line="${as.props}"/> + <arg line="--port ${admin.port}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${pm.resource.name}"/> + </exec> + <echo message="Created ${pm.resource.name} --target ${appserver.instance.name}"/> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set"/> + <param name="operand.props" + value="${resources.dottedname.prefix}.persistence-manager-factory-resource.${pm.resource.name}.factory_class=${pm.factory.class}"/> + </antcall> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.persistence-manager-factory-resource.${pm.resource.name}.jdbc_resource_jndi_name=${jdbc.resource.name}" /> + </antcall> +</target> + +<!-- ================================================================ --> +<!-- Target to delete persistence resource --> +<!-- ================================================================ --> +<target name="delete-persistence-resource-common" depends="init-common"> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" + value="delete-persistence-resource + --target ${appserver.instance.name}" /> + <param name="operand.props" value="${pm.resource.name}" /> + </antcall> +</target> + +<target name="execute-sql-common" depends="init-common"> +<echo message="Executing sql statement at ${basedir} from ${sql.file}" + level="verbose"/> + <sql + driver="${db.driver}" + url="${db.url}" + userid="${db.user}" + password="${db.pwd}" + src="${sql.file}" + onerror="continue" + print="yes" + classpath="${s1astest.classpath}"/> +</target> + + +<target name="execute-ejb-sql-common" depends="init-common"> +<echo message="Executing sql statement at ${basedir} from ${sql.file}" + level="verbose"/> + <sql + driver="${db.driver}" + url="jdbc:derby://localhost:1527/sun-appserv-samples;create=true;" + userid="APP" + password="APP" + src="${sql.file}" + onerror="continue" + print="yes" + output="${build.classes.dir}/setupDBTables.out" + classpath="${s1astest.classpath}" /> +</target> + +<!-- ================================================================ --> +<!-- Target to create/delete javamail resources --> +<!-- + Properties required: + mailhost + fromaddress + debug + enabled + javamail.resource.name (e.g. mail/MySession) +--> +<!-- ================================================================ --> +<target name="create-javamail-resource-common"> + <exec executable="${ASADMIN}"> + <arg line="create-javamail-resource"/> + <arg line="--port ${admin.port}"/> + <arg line="--mailhost ${mailhost}"/> + <arg line="--mailuser ${mailuser}"/> + <arg line="--fromaddress ${fromaddress}"/> + <arg line="--storeprotocol=imap"/> + <arg line="--storeprotocolclass=com.sun.mail.imap.IMAPStore"/> + <arg line="--transprotocol=smtp"/> + <arg line="--transprotocolclass=com.sun.mail.smtp.SMTPTransport"/> + <arg line="--debug=${debug}"/> + <arg line="--enabled=${enabled}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${as.props}"/> + <arg line="${javamail.resource.name}"/> + </exec> +</target> + +<target name="delete-javamail-resource-common"> + <exec executable="${ASADMIN}"> + <arg line="delete-javamail-resource"/> + <arg line="--port ${admin.port}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${as.props}"/> + <arg line="${javamail.resource.name}"/> + </exec> +</target> + +<!-- ================================================================ --> +<!-- Target to create database table through SQL file --> +<!-- ================================================================ --> +<target name="create-sql-common" depends="init-common"> +<echo message="creating tables from ${basedir}/sql/${db.create}" + level="verbose"/> + <sql + driver="${db.driver}" + url="${db.url}" + userid="${db.user}" + password="${db.pwd}" + src="sql/${db.create}" + onerror="continue" + print="yes" + output="${build.classes.dir}/setupDBTables.out" + classpath="${s1astest.classpath}" + /> +</target> + +<!-- ================================================================ --> +<!-- Target to delete database table through SQL file --> +<!-- ================================================================ --> +<target name="delete-sql-common" depends="init-common"> +<echo message="dropping tables from ${basedir}/sql/${db.drop}" + level="verbose"/> + <sql + driver="${db.driver}" + url="${db.url}" + userid="${db.user}" + password="${db.pwd}" + src="sql/${db.drop}" + onerror="continue" + print="yes" + output="${build.classes.dir}/setupDBTables.out" + classpath="${s1astest.classpath}" + /> +</target> + +<!-- ======================================================= --> +<!-- Taget to create JMS Connection --> +<!-- ======================================================= --> +<target name="create-jms-connection-common" depends="init-common"> + <echo message="Creating JMS connection factory with name ${jms.factory.name}" + level="verbose"/> + <exec executable="${ASADMIN}"> + <arg line="create-jms-resource "/> + <arg line="--restype ${jms.factory.type}"/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${jms.factory.name}" /> + </exec> +</target> + +<!-- ======================================================= --> +<!-- Taget to delete JMS Connection --> +<!-- ======================================================= --> +<target name="delete-jms-connection-common" depends="init-common"> + <echo message="Delete JMS connection factory with name ${jms.factory.name}" + level="verbose"/> + <exec executable="${ASADMIN}"> + <arg line="delete-jms-resource "/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${jms.factory.name}"/> + </exec> +</target> + +<!-- JMS: create/delete Destination Resource Targets --> +<target name="create-jms-resource-common" depends="init-common"> + <echo message="Creating JMS resource with name ${jms.resource.name}" + level="verbose"/> + + <exec executable="${ASADMIN}"> + <arg line="create-jmsdest --desttype ${dest.type} "/> + <arg line="${as.props}"/> + <arg line="${dest.name}"/> + </exec> + + <exec executable="${ASADMIN}"> + <arg line="create-jms-resource "/> + <arg line="--restype ${jms.resource.type}"/> + <arg line="--property imqDestinationName=${dest.name}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${as.props}"/> + <arg line="${jms.resource.name}"/> + </exec> +</target> + +<target name="delete-jms-resource-common" depends="init-common"> + <echo message="Delete JMS resource with name ${jms.resource.name}" + level="verbose"/> + + <exec executable="${ASADMIN}"> + <arg line="delete-jms-resource "/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${as.props} ${jms.resource.name}"/> + </exec> + + <exec executable="${ASADMIN}"> + <arg line="delete-jmsdest --desttype ${dest.type} "/> + <arg line="${as.props} ${dest.name}"/> + </exec> +</target> + +<!-- deploy/undeploy JMS resources --> +<target name="deploy-jms-common" depends="init-common"> + <antcall target="create-jms-connection-common" /> + <antcall target="create-jms-resource-common" /> +</target> + +<target name="undeploy-jms-common" depends="init-common"> + <antcall target="delete-jms-connection-common" /> + <antcall target="delete-jms-resource-common" /> +</target> + + +<!-- run StaticCheck on the ear file --> +<target name="staticCheck-common" depends="init-common"> + <echo message="Running StaticCheck -b on + ear file ${assemble.dir}/${appname}App.ear " level="verbose"/> + <antcall target="verifier-common"> + <param name="static-check.command" value=" -b "/> + <param name="operand.props" value="${assemble.dir}/${appname}App.ear"/> + </antcall> + <echo message="Validate the static check results" level="verbose"/> +</target> + +<target name="deploy-dir" depends="init-common"> + <echo message="Deploying files: ${assemble.dir}" level="verbose"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--contextroot ${contextroot}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--name ${appname}-web"/> + <arg line="${assemble.dir}"/> + </exec> +</target> + +<!-- deploy the applications in AppServ --> +<target name="deploy-common" depends="init-common"> + <antcall target="deploy-common-pe"/> + <antcall target="deploy-common-ee"/> +</target> + +<target name="deploy-verify-common" depends="init-common"> + <antcall target="deploy-verify-common-pe"/> + <antcall target="deploy-verify-common-ee"/> +</target> + +<target name="deploy-common-pe" depends="init-common" unless="ee"> + <property name="deployed.app" value="${assemble.dir}/${appname}App.ear"/> + <property name="extra-params" value=""/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="${extra-params}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--retrieve ${assemble.dir}"/> + <arg line="--libraries ${libraries}"/> +<!-- deployed.app defaults to ${assemble.dir}/${appname}App.ear defined in properties.xml--> + <arg line="${deployed.app}"/> + </exec> + <echo message="Deployment on target server ${appserver.instance.name} successful"/> + </target> + +<target name="deploy-common-ee" depends="init-common" if="ee"> + <echo message="Deploying in EE..."/> + <property name="deployed.app" value="${assemble.dir}/${appname}App.ear"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--retrieve ${assemble.dir}"/> + <arg line="--libraries ${libraries}"/> +<!-- deployed.app defaults to ${assemble.dir}/${appname}App.ear defined in properties.xml--> + <arg line="${deployed.app}"/> + </exec> + <echo message="Deployment on target server ${appserver.instance.name} successful"/> +</target> + +<target name="deploy-verify-common-pe" depends="init-common" unless="ee"> + <property name="deployed.app" value="${assemble.dir}/${appname}App.ear"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--verify=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--retrieve ${assemble.dir}"/> + <arg line="${deployed.app}"/> + </exec> + <echo message="Deployment on target server ${appserver.instance.name} successful"/> + </target> + +<target name="deploy-verify-common-ee" depends="init-common" if="ee"> + <echo message="Deploying in EE..."/> + <property name="deployed.app" value="${assemble.dir}/${appname}App.ear"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--verify=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--retrieve ${assemble.dir}"/> + <arg line="${deployed.app}"/> + </exec> + <echo message="Deployment on target server ${appserver.instance.name} successful"/> +</target> + +<!-- deploy the web application in AppServ --> +<target name="deploy-jsp-common" depends="init-common"> + <echo message="Deploying ${deploy.file} from ${basedir}." level="verbose"/> + <property name="precompilejsp" value="true"/> + <exec executable="${ASADMIN}" failonerror="true"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--precompilejsp=${precompilejsp}"/> + <arg line="--upload true"/> + <arg line="--retrieve ${assemble.dir}"/> + <arg line="--target ${appserver.instance.name}"/> + </exec> +</target> + +<target name="deploy-war-name" depends="init-common"> + <echo message="Deploying ${warname} from ${basedir}." + level="verbose"/> + <property name="force" value="false"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--contextroot ${contextroot}"/> + <arg line="--precompilejsp=${precompilejsp}"/> + <arg line="--force=${force}"/> + <arg line="--upload=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--libraries ${libraries}"/> + <arg line="${warname}.war"/> + </exec> +</target> + +<!-- deploy the standalone war in AppServ --> +<target name="deploy-war-common"> +<antcall target ="deploy-war-commonpe"/> +<antcall target ="deploy-war-commonee"/> +</target> + +<target name="deploy-wab-common"> +<antcall target ="deploy-wab-commonpe"/> +</target> + +<target name="deploy-wab-commonpe" depends="init-common" unless="ee"> + <echo message="Deploying WAB ${assemble.dir}/${appname}-web.war from ${basedir}." + level="verbose"/> + <property name="precompilejsp" value="true"/> + <property name="force" value="false"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--precompilejsp=${precompilejsp}"/> + <arg line="--force=${force}"/> + <arg line="--upload=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--libraries ${libraries}"/> + <arg line="--type=osgi"/> + <arg line="${assemble.dir}/${appname}-web.war"/> + </exec> +</target> + + + +<target name="deploy-war-commonpe" depends="init-common" unless="ee"> + <echo message="Deploying ${assemble.dir}/${appname}-web.war from ${basedir}." + level="verbose"/> + <property name="precompilejsp" value="true"/> + <property name="force" value="false"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--contextroot ${contextroot}"/> + <arg line="--precompilejsp=${precompilejsp}"/> + <arg line="--force=${force}"/> + <arg line="--upload=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--libraries ${libraries}"/> + <arg line="${assemble.dir}/${appname}-web.war"/> + </exec> +</target> + +<target name="deploy-war-commonee" if="ee"> + <property name="precompilejsp" value="true"/> + <property name="force" value="false"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--type web"/> + <arg line="--contextroot ${contextroot}"/> + <arg line="--precompilejsp=${precompilejsp}"/> + <arg line="--force=${force}"/> + <arg line="--upload=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--libraries ${libraries}"/> + <arg line="${assemble.dir}/${appname}-web.war"/> + </exec> +</target> + +<!-- deploy the standalone war in AppServ without specifying any + contextroot argument, so that the context-root specified in + sun-web.xml takes effect +--> +<target name="deploy-war-no-context-root" depends="init-common"> + <antcall target ="deploy-war-no-context-root-pe"/> + <antcall target ="deploy-war-no-context-root-ee"/> +</target> + +<target name="deploy-war-no-context-root-pe" unless="ee"> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="--user ${admin.user}"/> + <arg line="--passwordfile ${admin.password.file}"/> + <arg line="--host ${admin.host}"/> + <arg line="--port ${admin.port}"/> + <arg line="--upload=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--libraries ${libraries}"/> + <arg line="${assemble.dir}/${appname}-web.war"/> + </exec> +</target> + +<target name="deploy-war-no-context-root-ee" if="ee"> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="--user ${admin.user}"/> + <arg line="--passwordfile ${admin.password.file}"/> + <arg line="--host ${admin.host}"/> + <arg line="--port ${admin.port}"/> + <arg line="--type web"/> + <arg line="--upload=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--libraries ${libraries}"/> + <arg line="${assemble.dir}/${appname}-web.war"/> + </exec> +</target> + +<!-- deploy the standalone jar in AppServ --> +<target name="deploy-jar-common" depends="init-common"> + <exec executable="${ASADMIN}" failonerror="true"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--upload=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${assemble.dir}/${appname}-ejb.jar"/> + </exec> +</target> + +<!-- deploy the standalone jar in AppServ --> +<target name="deploy-client-common" depends="init-common"> + <exec executable="${ASADMIN}" failonerror="true"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--upload=true"/> + <arg line="--retrieve ${assemble.dir}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${assemble.dir}/${appname}-client.jar"/> + </exec> +</target> + +<target name="undeploy-war-name" depends="init-common"> + <property name="deployedapp.name" value="${warname}"/> + <property name="extra-params" value=""/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="undeploy"/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${extra-params}"/> +<!-- deployedapp.name defaults to {appname}App.declared in properties.xml--> + <arg line="${deployedapp.name}"/> + </exec> +</target> + +<!-- undeploy the applications in AppServ --> +<target name="undeploy-common" depends="init-common"> + <property name="deployedapp.name" value="${appname}App"/> + <property name="extra-params" value=""/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="undeploy"/> + <arg line="${as.props}"/> +<!-- +<arg line=type ${apptype}/> +--> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${extra-params}"/> +<!-- deployedapp.name defaults to {appname}App.declared in properties.xml--> + <arg line="${deployedapp.name}"/> + </exec> +</target> + +<!-- undeploy the standalone war in AppServ --> +<target name="undeploy-war-common" depends="init-common"> + <echo message="Undeploying warfile ${appname}-web from + ${assemble.dir}/${appname}-web.war from ${basedir}." level="verbose"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="undeploy"/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${appname}-web"/> + </exec> +</target> + + +<!-- undeploy the standalone war in AppServ --> +<target name="undeploy-jar-common" depends="init-common"> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="undeploy"/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${appname}-ejb"/> + </exec> +</target> + +<!-- undeploy the standalone client in AppServ --> +<target name="undeploy-client-common" depends="init-common"> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="undeploy"/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${appname}-client"/> + </exec> +</target> + + +<!-- run appclient in AppServ --> +<target name="runclient-common" depends="init-common"> + <echo message="appclient -client ${assemble.dir}/${appname}AppClient.jar -name ${appname}Client -textauth -user j2ee -password j2ee -xml ${admin.domain.dir}/${admin.domain}/config/glassfish-acc.xml ${appclient.application.args}"/> + <exec executable="${APPCLIENT}" failonerror="false"> + <!-- set APPCPATH to include reporter.jar so that all app clients + don't have to package the test framework in their apps --> + <env key="APPCPATH" file="${env.APS_HOME}/lib/reporter.jar"/> + <arg line="-client ${assemble.dir}/${appname}AppClient.jar"/> + <arg line="-name ${appname}Client"/> + <arg line="-textauth"/> + <arg line="-user j2ee"/> + <arg line="-password j2ee"/> + <arg line="-xml ${admin.domain.dir}/${admin.domain}/config/glassfish-acc.xml"/> + <arg line="${appclient.application.args}"/> + </exec> + +<!-- confirming report generation... --> + <antcall target="checkReporting-common"> + <param name="test.name" value="${appname}"/> + <param name="test.description" value="${test.description}"/> + <param name="test.count" value="${test.count}"/> + </antcall> +</target> + +<!-- run web client in AppServ --> +<target name="runwebclient-common" depends="init-common"> + <echo message="Running Web Test from ${basedir}" level="verbose"/> + <echo message="http host: ${http.host}" level="verbose"/> + <echo message="http port: ${http.port}" level="verbose"/> + <java + fork="on" failonerror="false" + classpath="${env.APS_HOME}/lib/webtest.jar:${s1astest.classpath}" + classname="com.sun.ejte.ccl.webrunner.webtest.WebTest"> + <arg value="script.txt"/> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="appserv-tests"/> + <arg value="${testsuite.id}"/> + </java> +</target> + +<!-- prepare Pointbase servers --> +<target name="preparePB" depends="init-common"> + <echo message="Starting Pointbase servers" level="verbose"/> + <copy file="${env.APS_HOME}/lib/pointbase.ini" + tofile="${db.dir}/pointbase.ini"/> + <replace file="${db.dir}/pointbase.ini" token="@@@" value="${db.dir}"/> +</target> + +<!-- start/stop Pointbase servers --> +<target name="startPB" depends="preparePB"> + <java classname="com.pointbase.net.netServer" + classpath="${db.classpath}" fork="true" spawn="true"> + <arg line="/port:9092"/> + <arg line="/pointbase.ini=${db.dir}/pointbase.ini"/> + <arg line="/noconsole"/> + </java> + <java classname="com.pointbase.net.netServer" + classpath="${db.classpath}" fork="true" spawn="true"> + <arg line="/port:9093"/> + <arg line="/pointbase.ini=${db.dir}/pointbase.ini"/> + <arg line="/noconsole"/> + </java> +</target> + +<!-- target name="startPB" depends="preparePB"> + <parallel> + <java classname="com.pointbase.net.netServer" + classpath="${db.classpath}" failonerror="false" fork="true"> + <arg line="/port:9092"/> + <arg line="/pointbase.ini=${db.dir}/pointbase.ini"/> + </java> + <java classname="com.pointbase.net.netServer" + classpath="${db.classpath}" failonerror="true" fork="true"> + <arg line="/port:9093"/> + <arg line="/pointbase.ini=${db.dir}/pointbase.ini"/> + </java> + </parallel> +</target --> + +<!-- start Derby Database --> +<target name="startDerby"> + <condition property="darwin"> + <os name="Mac OS X"/> + </condition> + <antcall target="startDerbyNonMac"/> + <antcall target="startDerbyMac"/> +</target> + +<target name="startDerbyNonMac" depends="init-common" unless="darwin"> + <echo message="StaRTing Derby DB servers in the Network Mode"/> + <parallel> + <java classname="org.apache.derby.drda.NetworkServerControl" + classpath="${db.classpath}" fork="true" spawn="true"> + <arg line="-h localhost -p 1527 start"/> + </java> + <java classname="org.apache.derby.drda.NetworkServerControl" + classpath="${db.classpath}" fork="true" spawn="true"> + <arg line="-h localhost -p 1528 start"/> + </java> + </parallel> +</target> + +<target name="startDerbyMac" depends="init-common" if="darwin"> + <echo message="StaRTing Derby DB servers in the Network Mode"/> + <parallel> + <java classname="org.apache.derby.drda.NetworkServerControl" + classpath="${db.classpath}" fork="true" spawn="true"> + <sysproperty key="derby.storage.fileSyncTransactionLog" value="true"/> + <arg line="-h localhost -p 1527 start"/> + </java> + <java classname="org.apache.derby.drda.NetworkServerControl" + classpath="${db.classpath}" fork="true" spawn="true"> + <sysproperty key="derby.storage.fileSyncTransactionLog" value="true"/> + <arg line="-h localhost -p 1528 start"/> + </java> + </parallel> +</target> + +<!-- start Derby Database --> +<target name="stopDerby" depends="init-common"> + <echo message="Stopping Derby DB servers ..."/> + <parallel> + <java classname="org.apache.derby.drda.NetworkServerControl" + classpath="${db.classpath}" failonerror="true" fork="true"> + <arg line="-h localhost -p 1527 shutdown"/> + </java> + <java classname="org.apache.derby.drda.NetworkServerControl" + classpath="${db.classpath}" failonerror="true" fork="true"> + <arg line="-h localhost -p 1528 shutdown"/> + </java> + </parallel> +</target> + +<target name="pb"> + <echo message="So you are using pointbase ... !"/> + <property file="${env.APS_HOME}/config/pointbase.properties"/> +</target> + +<!-- setup IMQ for RI Build --> +<target name="setup-mq-common" depends="init-common"> + <echo message="Executing Datastore setup for S1MQ. Required only for RI" + level="verbose"/> + <echo message="${IMQDBMGR} -javahome ${java.home} + -b ${admin.domain}_${appserver.instance.name} create all" + level="verbose"/> + <exec executable="${IMQDBMGR}" failonerror="true"> + <arg line="-javahome ${java.home} -b ${admin.domain}_${appserver.instance.name} create all" /> + </exec> +</target> + +<target name="import-wsdl" depends="init-common"> + <mkdir dir="${build.classes.dir}"/> + <exec executable="${WSCOMPILE}"> +<!-- + <arg line="-classpath ${s1astest.classpath}"/> +--> + <arg line="-classpath ${build.classes.dir}"/> + <arg line="-import"/> + <arg line="-source 1.1.2"/> + <arg line="-keep"/> + <arg line="-d "/> + <arg path="${build.classes.dir}"/> + <!-- + <arg line="-s "/> + <arg path="${basedir}/gensource"/> + --> + <arg line="-mapping ${build.classes.dir}/${mapping.file}"/> + <arg line="${config-wsdl.file}"/> + </exec> +</target> + +<!-- Confirm Report Generation --> + +<target name="checkReporting-common"> + <available file="RepRunConf.txt" type="file" property="isReported"/> + <antcall target="confirmReportPresent-common"/> + <antcall target="confirmMissingReport-common"/> +</target> + +<target name="confirmReportPresent-common" if="isReported"> + <echo message="file RepRunConf.txt is present."/> + <echo message="Test seems to be reported fine"/> + <delete file="RepRunConf.txt"/> +</target> + +<target name="confirmMissingReport-common" unless="isReported"> + <echo message="file RepRunConf.txt is missing!!!"/> + <echo message="Test does not seem to have been reported"/> + <echo message="Adding status 'did not run' into report..."/> + <java classname="com.sun.ejte.ccl.reporter.ReporterClient"> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reporter.jar"/> + <pathelement location="."/> + </classpath> + <arg value="${test.name}"/> + <arg value="${test.description}"/> + <arg value="${test.count}"/> + </java> + <delete file="RepRunConf.txt"/> +</target> + + +<!-- usage --> +<target name="usage-common"> + <echo> + ant clean Remove all classes files + ant build Build the application + ant deploy Deploy the ear files to S1AS + ant run Run the application + ant undeploy Undeploy the ear files from S1AS + ant usage Display this message + </echo> +</target> + + +<!-- EE Targets 8.1 --> +<!--Added Feb 5th 2004 by Deepa Singh --> +<target name="ee" depends="ee-common"> + <echo message="So you are using Enterprise Edition"/> + <property name="ee" value="Enterprise Edition"/> + <property file="${env.APS_HOME}/eeconfig/ee-config.properties"/> + <loadfile property="target-server-port" srcFile="${admin.domain.dir}/${admin.domain}/config/glassfish-acc.xml"/> + <condition property="orbPortSet" value="true"> + <contains string="${target-server-port}" substring="${orb.port}"/> + </condition> + <antcall target="change-orb-port"/> +</target> + +<target name="change-orb-port" unless="orbPortSet"> + <echo message="changing orb port from the default [3700] to ${orb.port}"/> + <replace file="${admin.domain.dir}/${admin.domain}/config/glassfish-acc.xml" token="3700" value="${orb.port}"/> +</target> + + +<target name="restart-instance"> + <echo message="Restarting remote server instance,until this gets fixed"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="stop-instance"/> + <arg line="${as.props}"/> + <arg line="${appserver.instance.name}"/> + </exec> + <sleep seconds="30"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="start-instance"/> + <arg line="${as.props}"/> + <arg line="${appserver.instance.name}"/> + </exec> +</target> + +<target name="testTimer" depends="init-common"> + +<echo message="creating timer table from ${env.APS_HOME}/lib/ejbtimer_${db.type}.sql"/> + <sql + driver="${db.driver}" + url="${db.url}" + userid="${db.user}" + password="${db.pwd}" + src="${env.APS_HOME}/lib/ejbtimer_${db.type}.sql" + onerror="continue" + print="yes" + classpath="${s1astest.classpath}"/> + +</target> + +<target name="setupTimer" depends="init-common" if="ee"> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="create-resource-ref"/> + <arg line="${as.props}"/> + <arg line="--target server"/> + <arg line="${jdbc.resource.name}"/> + </exec> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${appserver.instance.name}-config.ejb-container.ejb-timer-service.timer-datasource=${jdbc.resource.name}"/> + </antcall> + + <echo message="creating timer table from ${env.APS_HOME}/lib/ejbtimer_{db.type}.sql"/> + <sql + driver="${db.driver}" + url="${db.url}" + userid="${db.user}" + password="${db.pwd}" + src="${env.APS_HOME}/lib/ejbtimer_${db.type}.sql" + onerror="continue" + print="yes" + classpath="${s1astest.classpath}"/> + + <antcall target="restart-instance"/> +</target> + +<target name="unsetupTimer" depends="init-common" if="ee"> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="delete-resource-ref"/> + <arg line="${as.props}"/> + <arg line="--target server"/> + <arg line="${jdbc.resource.name}"/> + </exec> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="unset"/> + <arg line="${appserver.instance.name}-config.ejb-container.ejb-timer-service.timer-datasource"/> + </exec> + + <echo message="dropping timer table from ${env.APS_HOME}/lib/ejbtimer_${db.type}_drop.sql"/> + <sql + driver="${db.driver}" + url="${db.url}" + userid="${db.user}" + password="${db.pwd}" + src="${env.APS_HOME}/lib/ejbtimer_${db.type}_drop.sql" + onerror="continue" + print="yes" + classpath="${s1astest.classpath}"/> +</target> + +<target name="prepare-truststore-common" depends="init-common"> + <property name="truststore.db.file" location="${build.base.dir}/cacerts.jks"/> + <property name="cert.rfc.file" location="${build.base.dir}/${cert.nickname}.rfc"/> + + <delete quiet="true" file="${truststore.db.file}"/> + <delete quiet="true" file="${cert.rfc.file}"/> + + <!-- + Determine if we need to use the certutil or the keytool command to + access the certificate keystore + --> + <property name="certutil.db.dir" location="${admin.domain.dir}/${admin.domain}/config"/> + <condition property="use.certutil"> + <and> + <or> + <available file="${env.S1AS_HOME}/lib/certutil"/> + <available file="${env.S1AS_HOME}/lib/certutil.exe"/> + </or> + <available file="${certutil.db.dir}/cert8.db"/> + <available file="${certutil.db.dir}/key3.db"/> + <available file="${certutil.db.dir}/secmod.db"/> + </and> + </condition> + <antcall target="prepare-truststore-certutil-common"/> + <antcall target="prepare-truststore-keytool-common"/> +</target> + +<target name="prepare-truststore-certutil-common" depends="init-common" if="use.certutil"> + <exec executable="${env.S1AS_HOME}/lib/certutil" failonerror="true" output="${cert.rfc.file}"> + <!-- + LD_LIBRARY_PATH is needed on Unix platforms and should have no + effect on Windows + --> + <env key="LD_LIBRARY_PATH" path="${env.S1AS_HOME}/lib"/> + <arg line="-L -n '${cert.nickname}' -a"/> + <arg value="-d"/> + <arg file="${certutil.db.dir}"/> + </exec> + <exec executable="${java.home}/bin/keytool" failonerror="true"> + <arg line="-import -trustcacerts -alias '${cert.nickname}' -storepass '${ssl.password}' -noprompt"/> + <arg value="-file"/> + <arg file="${cert.rfc.file}"/> + <arg value="-keystore"/> + <arg file="${truststore.db.file}"/> + </exec> +</target> + + +<target name="prepare-truststore-keytool-common" depends="init-common" unless="use.certutil"> + <copy file="${admin.domain.dir}/${admin.domain}/config/cacerts.jks" tofile="${truststore.db.file}"/> +</target> + + +<target name="prepare-keystore-common" depends="init-common"> + <property name="keystore.db.file" location="${build.base.dir}/keystore.jks"/> + <delete quiet="true" file="${keystore.db.file}"/> + <copy file="${admin.domain.dir}/${admin.domain}/config/keystore.jks" tofile="${keystore.db.file}" failonerror="false"/> +</target> + +<target name="get-version-common" depends="init-common"> + <exec executable="${ASADMIN}" failonerror="false" outputproperty="appserver.version"> + <arg line="version"/> + <arg line="${as.props}"/> + <arg line="--verbose"/> + </exec> + <condition property="platform" value="true"> + <contains string="${appserver.version}" substring="Platform" casesensitive="false"/> + </condition> + <condition property="enterprise" value="true"> + <contains string="${appserver.version}" substring="Enterprise" casesensitive="false"/> + </condition> + <antcall target="platform-common"/> + <antcall target="enterprise-common"/> +</target> + +<target name="platform-common" if="platform"> + <echo message="This is Platform Version***"/> +</target> + +<target name="enterprise-common" if="enterprise"> + <echo message="This is Enterprise Version***"/> +</target> + +<target name="create-PermSize" depends="init-common"> + <echo message="asadmin create-jvm-options ${as.props} -- -XX:MaxPermSize=${jvm.maxpermsize}"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="create-jvm-options"/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="-- -XX\:MaxPermSize=${jvm.maxpermsize}"/> + </exec> +</target> + + <target name="restart-server"> + <antcall target="stop-server"/> + <sleep seconds="5"/> + <antcall target="start-server"/> + + </target> + + <target name="stop-server" depends="setOSConditions"> + <antcall target="stop-server-unix"/> + <antcall target="stop-server-windows"/> + </target> + + <target name="stop-server-unix" if="isUnix"> + <echo message="stopping server on unix ..."/> + <exec executable="${env.S1AS_HOME}/bin/asadmin"> + <arg value="stop-domain"/> + </exec> + <sleep seconds="10"/> + </target> + + <target name="stop-server-windows" if="isWindows"> + <echo message="Stopping server on windows ..."/> + <exec executable="cmd"> + <arg value="/c"/> + <arg value="${env.S1AS_HOME}\bin\asadmin.bat"/> + <arg value="stop-domain"/> + </exec> + <sleep seconds="5"/> + </target> + + <target name="start-server" depends="setOSConditions"> + + <echo>+-----------------------------+</echo> + <echo>| |</echo> + <echo>| S T A R T I N G GLASSFISH |</echo> + <echo>| in Felix mode |</echo> + <echo>| |</echo> + <echo>+-----------------------------+</echo> + + <antcall target="start-server-unix"/> + <antcall target="start-server-windows"/> + </target> + + <target name="start-server-unix" if="isUnix"> + <exec executable="${env.S1AS_HOME}/bin/asadmin"> + <env key="GlassFish_Platform" value="Felix"/> + <arg value="start-domain"/> + </exec> + <sleep seconds="10"/> + </target> + + <target name="start-server-windows" if="isWindows"> + <exec executable="cmd" spawn="true"> + <env key="GlassFish_Platform" value="Felix"/> + <arg value="/c"/> + <arg value="${env.S1AS_HOME}\bin\asadmin.bat"/> + <arg value="start-domain"/> + </exec> + <sleep seconds="5"/> + </target> + + <target name="create-jvm-options" depends="init-common"> + <exec executable="${ASADMIN}"> + <arg line="create-jvm-options"/> + <arg line="--user ${admin.user} --host ${admin.host} --port ${admin.port} --echo=true --terse=true"/> + <arg line="${option}"/> + </exec> + <echo message="REQUIRED TO RESTART SERVER......."/> + </target> + + <target name="delete-jvm-options" depends="init-common"> + <exec executable="${ASADMIN}"> + <arg line="delete-jvm-options"/> + <arg line="--user ${admin.user} --host ${admin.host} --port ${admin.port} --echo=true --terse=true"/> + <arg line="${option}"/> + </exec> + <echo message="REQUIRED TO RESTART SERVER......."/> + </target> + +<!-- ================================================================ --> +<!-- Target to Flush connection pool --> +<!-- ================================================================ --> +<target name="flush-connpool-common" depends="init-common"> +<echo message="Flush connection pool ${jdbc.conpool.name}" + level="verbose"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="flush-connection-pool"/> + <arg line="${as.props}"/> + <arg line="${jdbc.conpool.name}"/> + </exec> +</target> + +<!-- ================================================================ --> +<!-- Target to generate a neat Html report --> +<!-- ================================================================ --> +<target name="dev-report" depends="init-common"> + <java classname="com.sun.appserv.test.util.results.HtmlReportProducer" fork="true" failonerror="false" + classpath="${env.APS_HOME}/lib/reportbuilder.jar"> + <arg value="${env.APS_HOME}/test_results.xml"/> + </java> +</target> + +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/README b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/README new file mode 100644 index 0000000..117389b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/README
@@ -0,0 +1,3 @@ +Test +- Simple WAB (Web Application Bundle) that is CDI enabled. +- Test injection of beans, access to BeanManager within WAB
diff --git a/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/WebTest.java new file mode 100644 index 0000000..09cdfca --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/WebTest.java
@@ -0,0 +1,109 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "cdi-wab"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + Thread.sleep(2000); //WORKAROUND @XXX + String url = "http://" + host + ":" + port + contextRoot; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/build.properties b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/build.properties new file mode 100644 index 0000000..38d97bd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/build.properties
@@ -0,0 +1,26 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-wab"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/test"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="web.xml" value="descriptor/web.xml"/> +<property name="bundle.descriptor" value="descriptor/MANIFEST.MF"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/build.xml b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/build.xml new file mode 100644 index 0000000..c410fd0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/build.xml
@@ -0,0 +1,92 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!-- +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +--> +<!ENTITY commonBuild SYSTEM "../common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-wab-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-wab-common"/> + <echo message="sleeping for 10 seconds to allow the WAB deployment"/> + <sleep seconds="10"/> + + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/descriptor/MANIFEST.MF b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/descriptor/MANIFEST.MF new file mode 100644 index 0000000..5b53761 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/descriptor/MANIFEST.MF
@@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Archiver-Version: Plexus Archiver +Created-By: 1.6.0_20 (Sun Microsystems Inc.) +Built-By: siva +Build-Jdk: 1.6.0_20 +Extension-Name: simple-cdi-osgi-test +Implementation-Title: simple-cdi-osgi-test +Implementation-Version: 1.0 +Bundle-ClassPath: WEB-INF/classes/ +Private-Package: tests.cdi;version="1.0" +Export-EJB: ALL +Bundle-Version: 1.0 +Tool: Bnd-0.0.311 +Bundle-Name: Test CDI OSGI +Bnd-LastModified: 1283184402694 +Bundle-ManifestVersion: 2 +Bundle-SymbolicName: tests.cdi.simple-cdi-osgi-test +Web-ContextPath: /test +Import-Package: javax.enterprise.context,javax.enterprise.inject,javax + .inject,javax.enterprise.inject.spi,javax.servlet,javax.servlet.annotation,javax.servlet.http,javax.naming +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/descriptor/web.xml b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/descriptor/web.xml new file mode 100644 index 0000000..4812478 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/descriptor/web.xml
@@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> +<!-- IT's AN EMPTY FILE. Needed to satisfy maven-war-plugin. +--> +</web-app>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/servlet/tests/cdi/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/servlet/tests/cdi/TestBean.java new file mode 100644 index 0000000..fad6896 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/servlet/tests/cdi/TestBean.java
@@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package tests.cdi; + +//Simple TestBean to test CDI. +//This bean implements Serializable as it needs to be placed into a Stateful Bean +public class TestBean +{}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/servlet/tests/cdi/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/servlet/tests/cdi/TestServlet.java new file mode 100644 index 0000000..9e733d8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/osgi-cdi/simple-wab-with-cdi/servlet/tests/cdi/TestServlet.java
@@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package tests.cdi; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.inject.Inject; +import javax.enterprise.inject.spi.BeanManager; +import javax.naming.InitialContext; + +@WebServlet(urlPatterns={"/*"}) +public class TestServlet extends HttpServlet { + @Inject TestBean tb; + @Inject BeanManager bm; + BeanManager bm1; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0"); + String msg = ""; + if (tb == null) msg += "Bean injection into Servlet failed"; + if (bm == null) msg += "BeanManager Injection via @Inject failed"; + try { + bm1 = (BeanManager)((new InitialContext()).lookup("java:comp/BeanManager")); + } catch (Exception ex) { + ex.printStackTrace(); + msg += "BeanManager Injection via component environment lookup failed"; + } + if (bm1 == null) msg += "BeanManager Injection via component environment lookup failed"; + + System.out.println("BeanManager is " + bm); + System.out.println("BeanManager via lookup is " + bm1); + writer.write(msg + "\n"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/pom.xml b/appserver/tests/appserv-tests/devtests/cdi/pom.xml new file mode 100644 index 0000000..a7f5fbe --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/pom.xml
@@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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.glassfish.main</groupId> + <artifactId>glassfish-parent</artifactId> + <version>5.0.1-SNAPSHOT</version> + </parent> + <groupId>org.glassfish.main.tests</groupId> + <artifactId>tests</artifactId> + <packaging>pom</packaging> + <name>GlassFish devtests cdi</name> + <modules> + <!-- module>quicklook</module --> + </modules> + <dependencies> + <dependency> + <groupId>ant-contrib</groupId> + <artifactId>ant-contrib</artifactId> + <version>1.0b3</version> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <artifactId>maven-antrun-plugin</artifactId> + <version>1.8</version> + <dependencies> + <dependency> + <groupId>com.sun</groupId> + <artifactId>tools</artifactId> + <version>1.8.0</version> + <scope>system</scope> + <systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath> + </dependency> + </dependencies> + <executions> + <execution> + <id>id.test.1</id> + <phase>test</phase> + <configuration> + <target name="mvnUsage" unless="testMods"> + <ant antfile="build.xml" target="mvnUsage"/> + </target> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + <execution> + <id>id.test.2</id> + <phase>test</phase> + <configuration> + <target name="antTests" if="testMods"> + <ant antfile="build.xml" target="antTests"/> + </target> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + + <execution> + <id>id.clean</id> + <phase>clean</phase> + <configuration> + <target name="clean-result"> + <ant antfile="build.xml" target="clean-result"/> + </target> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + + </executions> + </plugin> + </plugins> + </build> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/README b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/README new file mode 100644 index 0000000..6569307 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/README
@@ -0,0 +1,4 @@ +Test +- Testing portable extensions support + - Using Bean Interface to discover metadata about discovered beans + - check for the absence of a bean that was vetoed by the portable Extension \ No newline at end of file
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/build.properties b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/build.properties new file mode 100644 index 0000000..f6975d1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-bean-interface"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/build.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/build.xml new file mode 100644 index 0000000..8894688 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/build.xml
@@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + <param name="cdi-extension.service" value="cdi-extension.service"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/cdi-extension.service b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/cdi-extension.service new file mode 100644 index 0000000..4d6314f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/cdi-extension.service
@@ -0,0 +1 @@ +test.extension.MyExtension
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/client/test/client/WebTest.java new file mode 100644 index 0000000..6eb31e4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/client/test/client/WebTest.java
@@ -0,0 +1,107 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "portable-extensions-bean-interface"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for portable extensions"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/descriptor/beans.xml new file mode 100644 index 0000000..f075638 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/descriptor/beans.xml
@@ -0,0 +1,28 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.TransactionInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/DuplicateTestBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/DuplicateTestBean.java new file mode 100644 index 0000000..6b766bc --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/DuplicateTestBean.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +@Transactional +@RequestScoped +@Preferred +@Named("duplicate_test_bean") +public class DuplicateTestBean extends TestBean{ + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..fa8fdb7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4792d26 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/TestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class TestBean { + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/TestDependentBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/TestDependentBean.java new file mode 100644 index 0000000..1c15313 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/TestDependentBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public class TestDependentBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/TestNamedBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/TestNamedBean.java new file mode 100644 index 0000000..1c7c311 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/TestNamedBean.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +@Named("test_named_bean") +@RequestScoped +public class TestNamedBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/TransactionInterceptor.java new file mode 100644 index 0000000..0b78e5f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/TransactionInterceptor.java
@@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import test.extension.MyExtension; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @Inject + TransactionInterceptor(MyExtension myex){ //Injection of portable extension in a bean + if(myex == null) { + errorMessage += "Portable Extension Injection in Interceptor failed"; + } + } + + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage += "Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/Transactional.java new file mode 100644 index 0000000..eef70c9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/beans/Transactional.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/extension/MyExtension.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/extension/MyExtension.java new file mode 100644 index 0000000..be36563 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/extension/MyExtension.java
@@ -0,0 +1,57 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.extension; + +import javax.enterprise.event.Observes; +import javax.enterprise.inject.spi.AfterBeanDiscovery; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.inject.spi.BeforeBeanDiscovery; +import javax.enterprise.inject.spi.Extension; +import javax.enterprise.inject.spi.ProcessAnnotatedType; + +import test.beans.DuplicateTestBean; + +public class MyExtension implements Extension{ + public static boolean beforeBeanDiscoveryCalled = false; + public static boolean afterBeanDiscoveryCalled = false; + public static boolean processAnnotatedTypeCalled = false; + + void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bdd){ + System.out.println("MyExtension::beforeBeanDiscovery" + bdd); + beforeBeanDiscoveryCalled = true; + } + + <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat){ + System.out.println("MyExtension:Process annotated type" + pat.getAnnotatedType().getBaseType()); + processAnnotatedTypeCalled = true; + //Vetoing the processing of DuplicateTestBean + //If this is not vetoed, at the InjectionPoint in Servlet, there would be + //an ambiguous dependency due to TestBean and DuplicateTestBean + if (pat.getAnnotatedType().getBaseType().equals(DuplicateTestBean.class)){ + pat.veto(); + } + } + + void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm){ + System.out.println("MyExtension: abd: " + abd + " BeanManager: " + bm); + + if (bm != null) { + //ensure a valid BeanManager is injected + afterBeanDiscoveryCalled = true; + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/servlet/PortableExtensionBeanInterfaceTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/servlet/PortableExtensionBeanInterfaceTestServlet.java new file mode 100644 index 0000000..5012ab8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-interface/servlet/test/servlet/PortableExtensionBeanInterfaceTestServlet.java
@@ -0,0 +1,220 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.annotation.Annotation; +import java.util.Iterator; +import java.util.NoSuchElementException; +import java.util.Set; + +import javax.enterprise.context.ConversationScoped; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.context.SessionScoped; +import javax.enterprise.inject.Any; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.DuplicateTestBean; +import test.beans.Preferred; +import test.beans.TestBean; +import test.beans.TransactionInterceptor; +import test.beans.Transactional; +import test.extension.MyExtension; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class PortableExtensionBeanInterfaceTestServlet extends HttpServlet { + @Inject + @Preferred + TestBean tb; + + @Inject + BeanManager bm; + + String msg = ""; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + + if (tb == null) + msg += "Injection of request scoped bean failed"; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + // check if our portable extension was called + if (!MyExtension.beforeBeanDiscoveryCalled) + msg += "Portable Extension lifecycle observer method: " + + "beforeBeanDiscovery not called"; + + if (!MyExtension.afterBeanDiscoveryCalled) + msg += "Portable Extension lifecycle observer method: " + + "afterBeanDiscovery not called or injection of BeanManager " + + "in an observer method failed"; + + if (!MyExtension.processAnnotatedTypeCalled) + msg += "Portable Extension lifecycle observer method: process " + + "annotated type not called"; + + // BeanManager lookup + if (bm == null) + msg += "Injection of BeanManager into servlet failed"; + + try { + BeanManager bm1 = (BeanManager) (new InitialContext()) + .lookup("java:comp/BeanManager"); + if (bm1 == null) + msg += "lookup of BeanManager via component context failed"; + } catch (NamingException e) { + e.printStackTrace(); + msg += "NamingException during lookup of BeanManager via component context"; + } + + testBeanManager(bm); + testBeanInterface(bm); + + writer.write(msg + "\n"); + } + + private void testBeanInterface(BeanManager bm2) { + // all beans in the application + System.out.println(bm.getBeans(Object.class, + new AnnotationLiteral<Any>() { + }).size()); + Set<Bean<?>> s = bm.getBeans(Object.class, + new AnnotationLiteral<Any>() { + }); + boolean foundInAllBeansInApplication = false; + for (Iterator iterator = s.iterator(); iterator.hasNext();) { + Bean<?> bean = (Bean<?>) iterator.next(); + if (bean.getBeanClass().equals(TestBean.class)) { + // found + foundInAllBeansInApplication = true; + testTestBeanMetadata(bean, + "Testing TestBean obtained through a lookup for all beans in application"); + } + } + if (!foundInAllBeansInApplication) + msg += "TestBean was not found among all the beans in the application"; + Bean<?> testBeanThroughType = bm + .getBeans(TestBean.class, new AnnotationLiteral<Any>() { + }).iterator().next(); + testTestBeanMetadata( + testBeanThroughType, + "Testing TestBean obtained through a lookup of TestBean.class with @Any Qualifier"); + Bean<?> testBeanThroughQualifier = bm + .getBeans(Object.class, new AnnotationLiteral<Preferred>() { + }).iterator().next(); + testTestBeanMetadata( + testBeanThroughQualifier, + "Testing TestBean obtained through a lookup of all beans with @Preferred Qualifier"); + + //There should be no Bean for DuplicateTestBean + try { + Bean<?> duplicateTestBeanThroughType = bm.getBeans( + DuplicateTestBean.class, new AnnotationLiteral<Any>() {}). + iterator().next(); + if (duplicateTestBeanThroughType != null) + msg += "Duplicate test bean that has been vetoed by the portable " + + "extension is still present as a valid Bean"; + } catch(NoSuchElementException nsee){ + //Expected. + } + + } + + private void testTestBeanMetadata(Bean<?> bean, String message) { + System.out.println("++++++" + message + "++++++"); + System.out.println("EL Name:" + bean.getName()); + check((bean.getName() == null), + "TestBean(whose EL name was unspecified)'s ELName is not null"); + System.out.println(bean.getBeanClass()); + check((bean.getBeanClass().equals(TestBean.class)), + "TestBean(whose EL name was unspecified) Bean's class is not TestBean"); + System.out.println(bean.getScope()); + check((bean.getScope().equals(RequestScoped.class)), + "TestBean(whose EL name was unspecified) Bean's scope is not RequestScoped"); + System.out.println(bean.getTypes()); // Object, TestBean + check((bean.getTypes().size() == 2), + "TestBean(whose EL name was unspecified) Bean's types unexpected. Should have been Object and TestBean, instead got " + + bean.getTypes()); + System.out.println(bean.getQualifiers()); // Any, Preferred + check((bean.getQualifiers().size() == 2), + "TestBean(whose EL name was unspecified) Bean's qualifiers unexpected. Should have been Any and Preferred, instead got " + + bean.getTypes()); + Set<Annotation> x = bean.getQualifiers(); + boolean qualifierFound = false; + for (Iterator iterator = x.iterator(); iterator.hasNext();) { + Annotation annotation = (Annotation) iterator.next(); + if (annotation.annotationType().equals(Preferred.class)) { + qualifierFound = true; + } + } + check(qualifierFound, + "TestBean's qualifiers does not have Preferred."); + } + + private void testBeanManager(BeanManager bm) { + // Using BeanManager + check((bm.getBeans("test_named_bean").size() == 1), + "Invalid number of Named Beans"); + check((bm.getBeans("duplicate_test_bean").size() == 0), + "Invalid number of Duplicate Test Bean"); + check(bm.getELResolver() != null, "ELResolver is null"); + check(bm.isInterceptorBinding(Transactional.class), + "Transactional is not an interceptor binding"); + check(bm.isNormalScope(RequestScoped.class), + "RequestScoped is not normal scope"); + check(bm.isPassivatingScope(SessionScoped.class), + "SessionScoped is not passivating scope"); + check(bm.isQualifier(Preferred.class), "Preferred is not a Qualifier"); + check(!(bm.isScope(Preferred.class)), "Preferred is a Scope class"); + check(bm.isScope(ConversationScoped.class), + "ConversationScoped is not a Scope class"); + + } + + private void check(boolean condition, String errorMessage) { + if (!condition) { + System.out.println("PROBLEM"); + msg += errorMessage; + } + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/README b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/README new file mode 100644 index 0000000..7ae113a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/README
@@ -0,0 +1,4 @@ +Test +- Testing portable extensions support + - Injection and lookup of BeanManager in a Servlet + - Use of BeanManager to make checks about Beans, Interceptors, Scopes etc \ No newline at end of file
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/build.properties b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/build.properties new file mode 100644 index 0000000..ff05db0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-bean-manager"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/build.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/build.xml new file mode 100644 index 0000000..8894688 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/build.xml
@@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + <param name="cdi-extension.service" value="cdi-extension.service"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/cdi-extension.service b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/cdi-extension.service new file mode 100644 index 0000000..4d6314f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/cdi-extension.service
@@ -0,0 +1 @@ +test.extension.MyExtension
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/client/test/client/WebTest.java new file mode 100644 index 0000000..83cd4ab --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/client/test/client/WebTest.java
@@ -0,0 +1,107 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "portable-extensions-bean-manager"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for portable extensions"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/descriptor/beans.xml new file mode 100644 index 0000000..f075638 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/descriptor/beans.xml
@@ -0,0 +1,28 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.TransactionInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/DuplicateTestBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/DuplicateTestBean.java new file mode 100644 index 0000000..6b766bc --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/DuplicateTestBean.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +@Transactional +@RequestScoped +@Preferred +@Named("duplicate_test_bean") +public class DuplicateTestBean extends TestBean{ + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..fa8fdb7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4792d26 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/TestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class TestBean { + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/TestDependentBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/TestDependentBean.java new file mode 100644 index 0000000..1c15313 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/TestDependentBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public class TestDependentBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/TestNamedBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/TestNamedBean.java new file mode 100644 index 0000000..1c7c311 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/TestNamedBean.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +@Named("test_named_bean") +@RequestScoped +public class TestNamedBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/TransactionInterceptor.java new file mode 100644 index 0000000..0b78e5f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/TransactionInterceptor.java
@@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import test.extension.MyExtension; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @Inject + TransactionInterceptor(MyExtension myex){ //Injection of portable extension in a bean + if(myex == null) { + errorMessage += "Portable Extension Injection in Interceptor failed"; + } + } + + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage += "Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/Transactional.java new file mode 100644 index 0000000..eef70c9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/beans/Transactional.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/extension/MyExtension.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/extension/MyExtension.java new file mode 100644 index 0000000..be36563 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/extension/MyExtension.java
@@ -0,0 +1,57 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.extension; + +import javax.enterprise.event.Observes; +import javax.enterprise.inject.spi.AfterBeanDiscovery; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.inject.spi.BeforeBeanDiscovery; +import javax.enterprise.inject.spi.Extension; +import javax.enterprise.inject.spi.ProcessAnnotatedType; + +import test.beans.DuplicateTestBean; + +public class MyExtension implements Extension{ + public static boolean beforeBeanDiscoveryCalled = false; + public static boolean afterBeanDiscoveryCalled = false; + public static boolean processAnnotatedTypeCalled = false; + + void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bdd){ + System.out.println("MyExtension::beforeBeanDiscovery" + bdd); + beforeBeanDiscoveryCalled = true; + } + + <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat){ + System.out.println("MyExtension:Process annotated type" + pat.getAnnotatedType().getBaseType()); + processAnnotatedTypeCalled = true; + //Vetoing the processing of DuplicateTestBean + //If this is not vetoed, at the InjectionPoint in Servlet, there would be + //an ambiguous dependency due to TestBean and DuplicateTestBean + if (pat.getAnnotatedType().getBaseType().equals(DuplicateTestBean.class)){ + pat.veto(); + } + } + + void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm){ + System.out.println("MyExtension: abd: " + abd + " BeanManager: " + bm); + + if (bm != null) { + //ensure a valid BeanManager is injected + afterBeanDiscoveryCalled = true; + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/servlet/PortableExtensionBeanManagerTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/servlet/PortableExtensionBeanManagerTestServlet.java new file mode 100644 index 0000000..b182c37 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/bean-manager/servlet/test/servlet/PortableExtensionBeanManagerTestServlet.java
@@ -0,0 +1,124 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.enterprise.context.ConversationScoped; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.context.SessionScoped; +import javax.enterprise.inject.Default; +import javax.enterprise.inject.spi.BeanManager; +import javax.inject.Inject; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.Preferred; +import test.beans.TestBean; +import test.beans.TransactionInterceptor; +import test.beans.Transactional; +import test.extension.MyExtension; + + + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class PortableExtensionBeanManagerTestServlet extends HttpServlet { + @Inject + @Preferred + TestBean tb; + + @Inject + BeanManager bm; + + String msg = ""; + + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + + if (tb == null) + msg += "Injection of request scoped bean failed"; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + //check if our portable extension was called + if (!MyExtension.beforeBeanDiscoveryCalled) + msg += "Portable Extension lifecycle observer method: " + + "beforeBeanDiscovery not called"; + + if (!MyExtension.afterBeanDiscoveryCalled) + msg += "Portable Extension lifecycle observer method: " + + "afterBeanDiscovery not called or injection of BeanManager " + + "in an observer method failed"; + + if (!MyExtension.processAnnotatedTypeCalled) + msg += "Portable Extension lifecycle observer method: process " + + "annotated type not called"; + + //BeanManager lookup + if (bm == null) + msg += "Injection of BeanManager into servlet failed"; + + try { + BeanManager bm1 = (BeanManager) (new InitialContext()).lookup("java:comp/BeanManager"); + if (bm1 == null) + msg += "lookup of BeanManager via component context failed"; + } catch (NamingException e) { + e.printStackTrace(); + msg += "NamingException during lookup of BeanManager via component context"; + } + + //Using BeanManager + check((bm.getBeans("test_named_bean").size() == 1), "Invalid number of Named Beans"); + check((bm.getBeans("duplicate_test_bean").size() == 0), "Invalid number of Duplicate Test Beans"); + check(bm.getELResolver() != null, "ELResolver is null"); + check(bm.isInterceptorBinding(Transactional.class), "Transactional is not an interceptor binding"); + check(bm.isNormalScope(RequestScoped.class), "RequestScoped is not normal scope"); + check(bm.isPassivatingScope(SessionScoped.class), "SessionScoped is not passivating scope"); + check(bm.isQualifier(Preferred.class), "Preferred is not a Qualifier"); + check(!(bm.isScope(Preferred.class)), "Preferred is a Scope class"); + check(bm.isScope(ConversationScoped.class), "ConversationScoped is not a Scope class"); + writer.write(msg + "\n"); + } + + + private void check(boolean condition, String errorMessage) { + if(!condition){ + msg += errorMessage; + } + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/build.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/build.xml new file mode 100644 index 0000000..78368ab --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/build.xml
@@ -0,0 +1,102 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<project name="portable-extensions-test" default="usage" basedir="."> + + <property name="portable-extensions-target" value="all"/> + + <target name="run-test"> + <antcall target="portable-extensions"> + <param name="portable-extensions-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="portable-extensions"> + <param name="portable-extensions-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="portable-extensions"> + <param name="portable-extensions-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="portable-extensions"> + <param name="portable-extensions-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="portable-extensions"> + <param name="portable-extensions-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="portable-extensions"> + <param name="portable-extensions-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="portable-extensions"> + <param name="portable-extensions-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="portable-extensions"> + <param name="portable-extensions-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="portable-extensions"> + <param name="portable-extensions-target" value="run"/> + </antcall> + </target> + + <target name="portable-extensions"> + <record name="portable-extensions.output" action="start" /> + <ant dir="simple-portable-extension" target="${portable-extensions-target}"/> + <ant dir="bean-interface" target="${portable-extensions-target}"/> + <ant dir="bean-manager" target="${portable-extensions-target}"/> + <ant dir="injection-target" target="${portable-extensions-target}"/> + <ant dir="new-bean-registration" target="${portable-extensions-target}"/> + <ant dir="new-bean-registration-extension-in-lib" target="${portable-extensions-target}"/> + <ant dir="package-private-extension-constructor" target="${portable-extensions-target}"/> + <record name="portable-extensions.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant all (Executes all the portable-extensions tests) + ant clean (cleans all the portable-extensions tests) + ant build (builds all the portable-extensions tests) + ant setup (sets up all resources for portable-extensions tests) + ant deploy (deploys all the portable-extensions apps) + ant run (Executes all the portable-extensions tests) + ant undeploy (undeploys all the portable-extensions apps) + ant unsetup (unsets all resources for portable-extensions tests) + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/README b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/README new file mode 100644 index 0000000..d1db00a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/README
@@ -0,0 +1,8 @@ +Test +- Testing portable extensions support + - Use of Injection Target to inject CDI beans into a framework class that + is not under the control of CDI. + - 2 usecases: + - Constructor injection (fwk bean instantiation via CDI SPI) + - setter and field method (fwk bean instantiation by the framework) + \ No newline at end of file
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/build.properties b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/build.properties new file mode 100644 index 0000000..74b15e1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-injection-target"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/build.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/build.xml new file mode 100644 index 0000000..8894688 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/build.xml
@@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + <param name="cdi-extension.service" value="cdi-extension.service"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/cdi-extension.service b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/cdi-extension.service new file mode 100644 index 0000000..4d6314f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/cdi-extension.service
@@ -0,0 +1 @@ +test.extension.MyExtension
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/client/test/client/WebTest.java new file mode 100644 index 0000000..9b01e09 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/client/test/client/WebTest.java
@@ -0,0 +1,107 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "portable-extensions-injection-target"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for portable extensions"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/descriptor/beans.xml new file mode 100644 index 0000000..f075638 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/descriptor/beans.xml
@@ -0,0 +1,28 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.TransactionInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/DuplicateTestBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/DuplicateTestBean.java new file mode 100644 index 0000000..6b766bc --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/DuplicateTestBean.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +@Transactional +@RequestScoped +@Preferred +@Named("duplicate_test_bean") +public class DuplicateTestBean extends TestBean{ + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..fa8fdb7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4792d26 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/TestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class TestBean { + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/TestDependentBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/TestDependentBean.java new file mode 100644 index 0000000..1c15313 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/TestDependentBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public class TestDependentBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/TestNamedBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/TestNamedBean.java new file mode 100644 index 0000000..1c7c311 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/TestNamedBean.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +@Named("test_named_bean") +@RequestScoped +public class TestNamedBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/TransactionInterceptor.java new file mode 100644 index 0000000..0b78e5f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/TransactionInterceptor.java
@@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import test.extension.MyExtension; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @Inject + TransactionInterceptor(MyExtension myex){ //Injection of portable extension in a bean + if(myex == null) { + errorMessage += "Portable Extension Injection in Interceptor failed"; + } + } + + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage += "Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/Transactional.java new file mode 100644 index 0000000..eef70c9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/beans/Transactional.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/extension/MyExtension.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/extension/MyExtension.java new file mode 100644 index 0000000..be36563 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/extension/MyExtension.java
@@ -0,0 +1,57 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.extension; + +import javax.enterprise.event.Observes; +import javax.enterprise.inject.spi.AfterBeanDiscovery; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.inject.spi.BeforeBeanDiscovery; +import javax.enterprise.inject.spi.Extension; +import javax.enterprise.inject.spi.ProcessAnnotatedType; + +import test.beans.DuplicateTestBean; + +public class MyExtension implements Extension{ + public static boolean beforeBeanDiscoveryCalled = false; + public static boolean afterBeanDiscoveryCalled = false; + public static boolean processAnnotatedTypeCalled = false; + + void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bdd){ + System.out.println("MyExtension::beforeBeanDiscovery" + bdd); + beforeBeanDiscoveryCalled = true; + } + + <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat){ + System.out.println("MyExtension:Process annotated type" + pat.getAnnotatedType().getBaseType()); + processAnnotatedTypeCalled = true; + //Vetoing the processing of DuplicateTestBean + //If this is not vetoed, at the InjectionPoint in Servlet, there would be + //an ambiguous dependency due to TestBean and DuplicateTestBean + if (pat.getAnnotatedType().getBaseType().equals(DuplicateTestBean.class)){ + pat.veto(); + } + } + + void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm){ + System.out.println("MyExtension: abd: " + abd + " BeanManager: " + bm); + + if (bm != null) { + //ensure a valid BeanManager is injected + afterBeanDiscoveryCalled = true; + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/framework/TestFrameworkClassWithConstructorInjection.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/framework/TestFrameworkClassWithConstructorInjection.java new file mode 100644 index 0000000..3d57751 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/framework/TestFrameworkClassWithConstructorInjection.java
@@ -0,0 +1,76 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.framework; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; + +import test.beans.Preferred; +import test.beans.TestBean; +import test.beans.TestNamedBean; + +public class TestFrameworkClassWithConstructorInjection { + + @Inject + TestNamedBean tnb; + + private TestBean tb; + private String msg = ""; + + private boolean postConstructCalled = false; + private boolean preDestroyCalled = false; + + @Inject + public TestFrameworkClassWithConstructorInjection(@Preferred TestBean tb) { + System.out.println("constructor based injection " + + "into a framework class" + tb); + this.tb = tb; + if (tb == null) { + msg += "Constructor injection in a test framework class failed"; + } + + } + + @PostConstruct + private void beanPostConstruct() { + this.postConstructCalled = true; + if (tnb == null) { + msg += "regular field injection in a test framework class failed"; + } + } + + @PreDestroy + private void beanPreDestroy() { + this.preDestroyCalled = true; + } + + public String getInitialTestResults() { + if (!postConstructCalled) + msg += "PostConstruct was not called in test framework class"; + String response = msg; + msg = ""; + return response; + } + + public String getFinalTestResults() { + if (!preDestroyCalled) + msg += "PreDestroy was not called " + "in test framework class"; + return msg; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/framework/TestFrameworkClassWithSetterAndFieldInjection.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/framework/TestFrameworkClassWithSetterAndFieldInjection.java new file mode 100644 index 0000000..3053e38 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/framework/TestFrameworkClassWithSetterAndFieldInjection.java
@@ -0,0 +1,84 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.framework; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; + +import test.beans.Preferred; +import test.beans.TestBean; +import test.beans.TestNamedBean; + + +public class TestFrameworkClassWithSetterAndFieldInjection { + + @Inject TestNamedBean tnb; + + private TestBean tb; + + private String msg = ""; + + private boolean postConstructCalled = false; + private boolean preDestroyCalled = false; + + // must have default no-arg constructor or weld will puke + public TestFrameworkClassWithSetterAndFieldInjection() { + } + + public TestFrameworkClassWithSetterAndFieldInjection(String magicKey){ + if(!magicKey.equals("test")) throw new RuntimeException(); + } + + + @Inject + public void setTestBean(@Preferred TestBean tb){ + System.out.println("Setter based injection " + + "into a framework class" + tb); + this.tb = tb; + if (tb == null) { + msg += "Constructor injection in a test framework class failed"; + } + + } + + @PostConstruct + private void beanPostConstruct() { + this.postConstructCalled = true; + if (tnb == null) { + msg += "regular field injection in a test framework class failed"; + } + } + + @PreDestroy + private void beanPreDestroy() { + this.preDestroyCalled = true; + } + + public String getInitialTestResults() { + if (!postConstructCalled) + msg += "PostConstruct was not called in test framework class"; + String response = msg; + msg = ""; + return response; + } + + public String getFinalTestResults() { + if (!preDestroyCalled) + msg += "PreDestroy was not called " + "in test framework class"; + return msg; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/servlet/PortableExtensionInjectionTargetTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/servlet/PortableExtensionInjectionTargetTestServlet.java new file mode 100644 index 0000000..9d21265 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/injection-target/servlet/test/servlet/PortableExtensionInjectionTargetTestServlet.java
@@ -0,0 +1,139 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.enterprise.context.ConversationScoped; +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; +import javax.inject.Inject; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.sun.xml.bind.v2.schemagen.xmlschema.Annotated; + +import test.beans.Preferred; +import test.beans.TestBean; +import test.beans.TransactionInterceptor; +import test.beans.Transactional; +import test.extension.MyExtension; +import test.framework.TestFrameworkClassWithConstructorInjection; +import test.framework.TestFrameworkClassWithSetterAndFieldInjection; + + + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class PortableExtensionInjectionTargetTestServlet extends HttpServlet { + @Inject + @Preferred + TestBean tb; + + @Inject + BeanManager bm; + + String msg = ""; + + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + + if (tb == null) + msg += "Injection of request scoped bean failed"; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + //check if our portable extension was called + if (!MyExtension.beforeBeanDiscoveryCalled) + msg += "Portable Extension lifecycle observer method: " + + "beforeBeanDiscovery not called"; + + if (!MyExtension.afterBeanDiscoveryCalled) + msg += "Portable Extension lifecycle observer method: " + + "afterBeanDiscovery not called or injection of BeanManager " + + "in an observer method failed"; + + if (!MyExtension.processAnnotatedTypeCalled) + msg += "Portable Extension lifecycle observer method: process " + + "annotated type not called"; + + //BeanManager lookup + if (bm == null) + msg += "Injection of BeanManager into servlet failed"; + + AnnotatedType<TestFrameworkClassWithConstructorInjection> atfc = + bm.createAnnotatedType(TestFrameworkClassWithConstructorInjection.class); + //First: Constructor Injection Framework class + CreationalContext ctx = bm.createCreationalContext(null); + InjectionTarget<TestFrameworkClassWithConstructorInjection> it = bm.createInjectionTarget(atfc); + TestFrameworkClassWithConstructorInjection ctorInstance = it.produce(ctx); + //Since this framework class needs to support constructor based injection + //we need to ask the CDI runtime to produce the instance. + it.inject(ctorInstance, ctx); + it.postConstruct(ctorInstance); + msg += ctorInstance.getInitialTestResults(); + it.preDestroy(ctorInstance); + it.dispose(ctorInstance); + msg += ctorInstance.getFinalTestResults(); + + //Second: Setter and Field based Injection into a Framework class + AnnotatedType<TestFrameworkClassWithSetterAndFieldInjection> atsfi = + bm.createAnnotatedType(TestFrameworkClassWithSetterAndFieldInjection.class); + InjectionTarget<TestFrameworkClassWithSetterAndFieldInjection> it_set = bm.createInjectionTarget(atsfi); + TestFrameworkClassWithSetterAndFieldInjection setterInstance = + new TestFrameworkClassWithSetterAndFieldInjection("test"); + it_set.inject(setterInstance, ctx); + it_set.postConstruct(setterInstance); + msg += setterInstance.getInitialTestResults(); + it_set.preDestroy(setterInstance); + it_set.dispose(setterInstance); + msg += setterInstance.getFinalTestResults(); + + writer.write(msg + "\n"); + } + + + private void check(boolean condition, String errorMessage) { + if(!condition){ + msg += errorMessage; + } + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/README b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/README new file mode 100644 index 0000000..64b0a7c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/README
@@ -0,0 +1,5 @@ +Test +- Testing portable extensions support + - Bean interface + - getting all beans that exists in the application + - Registering a new Framework bean and ensure that is available for injection \ No newline at end of file
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/build.properties b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/build.properties new file mode 100644 index 0000000..a3a1b42 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/build.properties
@@ -0,0 +1,26 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-make-framework-bean-available-for-injection-extension-in-lib"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="cdi.extension" value="cdi-extension.service"/> +<property name="extension.jar" value="weld-extension.jar"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/build.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/build.xml new file mode 100644 index 0000000..747aac5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/build.xml
@@ -0,0 +1,117 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete failonerror="false"> + <fileset dir="." includes="*.class"/> + <fileset dir="lib" includes="*.jar"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <!-- compile and build extension jar --> + <antcall target="compile-common"> + <param name="src" value="extension"/> + </antcall> + + <mkdir dir="lib"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <mkdir dir="${build.classes.dir}/META-INF/services"/> + <copy file="${cdi.extension}" + tofile="${build.classes.dir}/META-INF/services/javax.enterprise.inject.spi.Extension" + failonerror="false"/> + <copy file="${beans.xml}" + tofile="${build.classes.dir}/META-INF/beans.xml" + failonerror="false"/> + <jar jarfile="lib/${extension.jar}" basedir="${build.classes.dir}" update="true" includes ="${build.classes.dir}"> + <metainf dir="${build.classes.dir}/META-INF"> + <include name="services/javax.enterprise.inject.spi.Extension"/> + </metainf> + <fileset dir="${build.classes.dir}/" casesensitive="yes"> + <include name="**/*class*"/> + </fileset> + </jar> + + <delete dir="${build.classes.dir}/META-INF"/> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + + <delete dir="${build.classes.dir}/test/fwk"/> + <delete dir="${build.classes.dir}/test/extension"/> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> + + +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/cdi-extension.service b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/cdi-extension.service new file mode 100644 index 0000000..80fa6f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/cdi-extension.service
@@ -0,0 +1 @@ +test.extension.ServiceFrameworkExtension
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/client/test/client/WebTest.java new file mode 100644 index 0000000..384c383 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/client/test/client/WebTest.java
@@ -0,0 +1,112 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "portable-extension-make-framework-bean-available-for-injection-extension-in-lib"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for portable extensions"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/descriptor/beans.xml new file mode 100644 index 0000000..f075638 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/descriptor/beans.xml
@@ -0,0 +1,28 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.TransactionInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/extension/test/extension/FrameworkServiceFactory.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/extension/test/extension/FrameworkServiceFactory.java new file mode 100644 index 0000000..44e2f7f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/extension/test/extension/FrameworkServiceFactory.java
@@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.extension; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.lang.reflect.Type; + +import test.fwk.FrameworkService; + + +/** + * A simple Service Factory class that provides the ability to obtain/get + * references to a service implementation (obtained from a service registry) + * and also provides a mechanism to unget or return a service after its usage + * is completed. + * + * @author Sivakumar Thyagarajan + */ +public class FrameworkServiceFactory { + private static final boolean DEBUG_ENABLED = false; + + /** + * Get a reference to the service of the provided <code>Type</code> + */ + public static Object getService(final Type type, final FrameworkService fs){ + debug("getService " + type + " FS:" + fs); + Object instance = lookupService(type, fs.waitTimeout()); + + //If the service is marked as dynamic, when a method is invoked on a + //a service proxy, an attempt is made to get a reference to the service + //and then the method is invoked on the newly obtained service. + //This scheme should work for statless and/or idempotent service + //implementations that have a dynamic lifecycle that is not linked to + //the service consumer [service dynamism] + if (fs.dynamic()) { + InvocationHandler proxyInvHndlr = new InvocationHandler() { + @Override + public Object invoke(Object proxy, Method method, Object[] args) + throws Throwable { + debug("Method " + method + " called on proxy"); + //Always lookup the service and invoke the method in this. + return method.invoke(lookupService(type, fs.waitTimeout()), args); + } + }; + instance = Proxy.newProxyInstance( + Thread.currentThread().getContextClassLoader(), + new Class[]{(Class)type}, + proxyInvHndlr); + } + return instance; + } + + //NOTE:hard-coded service instantiation for this test, + //but ideally should get the + //service implementation from the framework's service registry + private static Object lookupService(Type type, int waitTimeout) { + String clazzName = ((Class)type).getName() + "Impl"; + System.out.println("LOADING " + clazzName); + try { + return FrameworkServiceFactory.class.getClassLoader().loadClass(clazzName).newInstance(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + /** + * Unget the service + */ + public static void ungetService(Object serviceInstance, + Type type, FrameworkService frameworkService){ + //unget the service instance from the service registry + } + + private static void debug(String string) { + if(DEBUG_ENABLED) + System.out.println("ServiceFactory:: " + string); + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/extension/test/extension/ServiceFrameworkExtension.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/extension/test/extension/ServiceFrameworkExtension.java new file mode 100644 index 0000000..c9361f9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/extension/test/extension/ServiceFrameworkExtension.java
@@ -0,0 +1,323 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.extension; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import javax.enterprise.context.Dependent; +import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.event.Observes; +import javax.enterprise.inject.Any; +import javax.enterprise.inject.Default; +import javax.enterprise.inject.spi.AfterBeanDiscovery; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.BeforeBeanDiscovery; +import javax.enterprise.inject.spi.Extension; +import javax.enterprise.inject.spi.InjectionPoint; +import javax.enterprise.inject.spi.ProcessAnnotatedType; +import javax.enterprise.inject.spi.ProcessBean; +import javax.enterprise.inject.spi.ProcessInjectionTarget; +import javax.enterprise.util.AnnotationLiteral; + +import test.fwk.FrameworkService; +import test.fwk.SomeFwkServiceImpl; +import test.fwk.SomeFwkService; + +/** + * A portable extension that supports injection of custom framework + * services into Beans. + * + * @author Sivakumar Thyagarajan + */ +public class ServiceFrameworkExtension implements Extension{ + + public static boolean beforeBeanDiscoveryCalled = false; + public static boolean afterBeanDiscoveryCalled = false; + public static boolean afterProcessBeanCalled = false; + public static boolean processAnnotatedTypeCalled = false; + + /* + * A map of Framework Service Types to be injected and additional metadata + * about the FrameworkService to be injected. + */ + private HashMap<Type, Set<FrameworkService>> frameworkServicesToBeInjected + = new HashMap<Type, Set<FrameworkService>>(); + private static final boolean DEBUG_ENABLED = false; + + + //Observers for container lifecycle events + void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bdd){ + debug("beforeBeanDiscovery" + bdd); + beforeBeanDiscoveryCalled = true; + } + + <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat){ + debug("Process annotated type" + pat.getAnnotatedType().getBaseType()); + processAnnotatedTypeCalled = true; + } + + /** + * Observer for <code>ProcessInjectionTarget</code> events. This event is + * fired for every Java EE component class supporting injection that may be + * instantiated by the container at runtime. Injections points of every + * discovered enabled Java EE component is checked to see if there is a + * request for injection of a framework service. + */ + void afterProcessInjectionTarget(@Observes ProcessInjectionTarget<?> pb){ + debug("AfterProcessInjectionTarget" + pb.getAnnotatedType().getBaseType()); + Set<InjectionPoint> ips = pb.getInjectionTarget().getInjectionPoints(); + discoverServiceInjectionPoints(ips); + } + + /** + * Observer for <code>ProcessInjectionTarget</code> events. This event is + * fired fire an event for each enabled bean, interceptor or decorator + * deployed in a bean archive, before registering the Bean object. + * Injections points of every discovered enabled Java EE component is + * checked to see if there is a request for injection of a framework + * service. + */ + void afterProcessBean(@Observes ProcessBean pb){ + afterProcessBeanCalled = true; + debug("afterProcessBean - " + pb.getAnnotated().getBaseType()); + Set<InjectionPoint> ips = pb.getBean().getInjectionPoints(); + discoverServiceInjectionPoints(ips); + } + + /* + * Discover injection points where the framework service is requested + * through the <code>FrameworkService</code> qualifier and a map is + * populated for all framework services that have been requested. + */ + private void discoverServiceInjectionPoints(Set<InjectionPoint> ips) { + for (Iterator<InjectionPoint> iterator = ips.iterator(); + iterator.hasNext();) { + InjectionPoint injectionPoint = iterator.next(); + Set<Annotation> qualifs = injectionPoint.getQualifiers(); + for (Iterator<Annotation> qualifIter = qualifs.iterator(); + qualifIter.hasNext();) { + Annotation annotation = qualifIter.next(); + if (annotation.annotationType().equals(FrameworkService.class)){ + printDebugForInjectionPoint(injectionPoint); + //Keep track of service-type and its attributes + System.out.println("---- Injection requested for " + + "framework service type " + injectionPoint.getType() + + " and annotated with dynamic=" + + injectionPoint.getAnnotated() + .getAnnotation(FrameworkService.class) + .dynamic() + + ", serviceCriteria=" + + injectionPoint.getAnnotated() + .getAnnotation(FrameworkService.class) + .serviceCriteria()); + //Add to list of framework services to be injected + Type key = injectionPoint.getType(); + FrameworkService value = injectionPoint.getAnnotated() + .getAnnotation(FrameworkService.class); + if (!frameworkServicesToBeInjected.containsKey(key)){ + frameworkServicesToBeInjected.put(key, new HashSet<FrameworkService>()); + } + frameworkServicesToBeInjected.get(key).add(value); + System.out.println(frameworkServicesToBeInjected.get(key).size()); + + } + } + } + } + + /** + * Observer for <code>AfterBeanDiscovery</code> events. This + * observer method is used to register <code>Bean</code>s for the framework + * services that have been requested to be injected. + */ + void afterBeanDiscovery(@Observes AfterBeanDiscovery abd){ + afterBeanDiscoveryCalled = true; + debug("After Bean Discovery"); + for (Iterator<Type> iterator = this.frameworkServicesToBeInjected.keySet().iterator(); + iterator.hasNext();) { + Type type = iterator.next(); + //If the injection point's type is not a Class or Interface, we + //don't know how to handle this. + if (!(type instanceof Class)) { + System.out.println("Unknown type:" + type); + abd.addDefinitionError(new UnsupportedOperationException( + "Injection target type " + type + "not supported")); + break; //abort deployment + } + //Add the Bean representing the framework service so that it + //is available for injection + addBean(abd, type, this.frameworkServicesToBeInjected.get(type)); + } + } + + /* + * Add a <code>Bean</code> for the framework service requested. Instantiate + * or discover the bean from the framework service registry, + * and return a reference to the service if a dynamic reference is requested. + */ + private void addBean(AfterBeanDiscovery abd, final Type type, + final Set<FrameworkService> frameworkServices) { + for (Iterator<FrameworkService> iterator = frameworkServices.iterator(); iterator + .hasNext();) { + final FrameworkService frameworkService = iterator.next(); + System.out.println(" --- Adding a framework service BEAN " + type + " for " + frameworkService); + abd.addBean(new FrameworkServiceBean(type, frameworkService)); + } + } + + + private final class FrameworkServiceBean implements Bean { + private final Type type; + private final FrameworkService frameworkService; + + private FrameworkServiceBean(Type type, + FrameworkService frameworkService) { + this.type = type; + this.frameworkService = frameworkService; + } + + @Override + public Object create(CreationalContext arg0) { + //get the service from the service registry + return FrameworkServiceFactory.getService(type, frameworkService); + } + + @Override + public void destroy(Object instance, + CreationalContext creationalContext) { + System.out.println("destroy::" + instance); + //unget the service reference + FrameworkServiceFactory.ungetService(instance, type, frameworkService); + } + + @Override + public Class getBeanClass() { + return (Class)type; + } + + @Override + public Set<InjectionPoint> getInjectionPoints() { + return Collections.emptySet(); + } + + @Override + public String getName() { + return type + "_dynamic_" + frameworkService.dynamic() + + "_criteria_" + frameworkService.serviceCriteria() + + "_waitTimeout" + frameworkService.waitTimeout(); + } + + @Override + public Set<Annotation> getQualifiers() { + Set<Annotation> s = new HashSet<Annotation>(); + s.add(new AnnotationLiteral<Default>() {}); + s.add(new AnnotationLiteral<Any>() {}); + //Add the appropriate parameters to the FrameworkService qualifier + //as requested in the injection point + s.add(new FrameworkServiceQualifierType(frameworkService)); + return s; + } + + @Override + public Class<? extends Annotation> getScope() { + return Dependent.class; + } + + @Override + public Set<Class<? extends Annotation>> getStereotypes() { + return Collections.emptySet(); + } + + @Override + public Set<Type> getTypes() { + Set<Type> s = new HashSet<Type>(); + s.add(type); + s.add(Object.class); + return s; + } + + @Override + public boolean isAlternative() { + return false; + } + + @Override + public boolean isNullable() { + return false; + } + } + + /* + * Represents an annotation type instance of FrameworkService + * with parameters equal to those specified in the injection point + */ + private final class FrameworkServiceQualifierType + extends AnnotationLiteral<FrameworkService> implements FrameworkService { + private String serviceCriteria = ""; + private boolean dynamic = false; + private int waitTimeout = -1; + + public FrameworkServiceQualifierType(FrameworkService frameworkService){ + this.serviceCriteria = frameworkService.serviceCriteria(); + this.dynamic = frameworkService.dynamic(); + this.waitTimeout = frameworkService.waitTimeout(); + } + @Override + public String serviceCriteria(){ + return this.serviceCriteria; + } + + @Override + public boolean dynamic() { + return this.dynamic; + } + + @Override + public int waitTimeout() { + return this.waitTimeout; + } + } + + private void debug(String string) { + if(DEBUG_ENABLED) + System.out.println("MyExtension:: " + string); + + } + + private void printDebugForInjectionPoint(InjectionPoint injectionPoint) { + if (DEBUG_ENABLED) { + System.out.println("@@@@@@@ INJECTION-POINT: Annotation:" + + injectionPoint.getAnnotated()); // annotatedfield + System.out.print(" ,Bean:" + injectionPoint.getBean());// bean + System.out.print(" ,Class:" + injectionPoint.getClass()); // r untime + // class? + System.out.print(" ,Member:" + injectionPoint.getMember());// Field + System.out.print(" ,Qualifiers:" + injectionPoint.getQualifiers());// qualifiers + System.out.print(" ,Type:" + injectionPoint.getType());// type of + // injection + // point + } + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/extension/test/fwk/FrameworkService.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/extension/test/fwk/FrameworkService.java new file mode 100644 index 0000000..542eef2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/extension/test/fwk/FrameworkService.java
@@ -0,0 +1,58 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.fwk; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) + +/** + * A CDI Qualifier that represents a reference to a + * service in the framework. If this qualifiers annotates an injection point, + * the framework extension discovers and instantiates + * a service implementing the service interface type of the injection point + * and makes it available for injection to that injection point. + */ +public @interface FrameworkService { + /** + * Determines if the service reference that is injected + * refers to a dynamic proxy or the actual service reference obtained + * from the framework service registry + */ + boolean dynamic() default false; //dynamic + + /** + * service discovery criteria + */ + String serviceCriteria() default ""; + + /** + * wait specified in millis. -1 indicates indefinite wait + */ + int waitTimeout() default -1; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/extension/test/fwk/SomeFwkService.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/extension/test/fwk/SomeFwkService.java new file mode 100644 index 0000000..3504168 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/extension/test/fwk/SomeFwkService.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.fwk; + +public interface SomeFwkService { + public boolean fooMethod(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/extension/test/fwk/SomeFwkServiceImpl.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/extension/test/fwk/SomeFwkServiceImpl.java new file mode 100644 index 0000000..643744d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/extension/test/fwk/SomeFwkServiceImpl.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.fwk; + +public class SomeFwkServiceImpl implements SomeFwkService { + + public SomeFwkServiceImpl(){ + System.out.println("SomeFrameworkClass:"); + } + + @Override + public boolean fooMethod() { + System.out.println("SomeFwkServiceImpl::fooMethod called"); + return true; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..fa8fdb7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/servlet/test/beans/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4792d26 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/servlet/test/beans/TestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class TestBean { + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/servlet/test/beans/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/servlet/test/beans/TransactionInterceptor.java new file mode 100644 index 0000000..374113e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/servlet/test/beans/TransactionInterceptor.java
@@ -0,0 +1,53 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import test.extension.ServiceFrameworkExtension; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TransactionInterceptor(ServiceFrameworkExtension myex){ //Injection of portable extension in a bean + if(myex == null) { + errorMessage += "Portable Extension Injection in Interceptor failed"; + } + } + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("TransactionInterceptor::AroundInvoke"); + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/servlet/test/beans/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/servlet/test/beans/Transactional.java new file mode 100644 index 0000000..eef70c9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/servlet/test/beans/Transactional.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/servlet/test/servlet/PortableExtensionBeanRegistrationTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/servlet/test/servlet/PortableExtensionBeanRegistrationTestServlet.java new file mode 100644 index 0000000..110f809 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration-extension-in-lib/servlet/test/servlet/PortableExtensionBeanRegistrationTestServlet.java
@@ -0,0 +1,159 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.Proxy; +import java.util.Iterator; +import java.util.Set; + +import javax.enterprise.context.Dependent; +import javax.enterprise.inject.Any; +import javax.enterprise.inject.Default; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.Preferred; +import test.beans.TestBean; +import test.beans.TransactionInterceptor; +import test.extension.ServiceFrameworkExtension; +import test.fwk.FrameworkService; +import test.fwk.SomeFwkServiceImpl; +import test.fwk.SomeFwkService; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class PortableExtensionBeanRegistrationTestServlet extends HttpServlet { + @Inject + @Preferred + TestBean tb; + + @Inject + BeanManager bm; + + @Inject + @FrameworkService(serviceCriteria="TEST", dynamic=true) + SomeFwkService sfc_proxy; + +// @Inject +// @FrameworkService(serviceCriteria="FOO", dynamic=false) +// SomeFwkService sfc_unproxied; + + String msg = ""; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + + if (tb == null) + msg += "Injection of request scoped bean failed"; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + //check if our portable extension was called + if (!ServiceFrameworkExtension.beforeBeanDiscoveryCalled) + msg += "Portable Extension lifecycle observer method: " + + "beforeBeanDiscovery not called"; + + if (!ServiceFrameworkExtension.afterBeanDiscoveryCalled) + msg += "Portable Extension lifecycle observer method: " + + "afterBeanDiscovery not called or injection of BeanManager " + + "in an observer method failed"; + + if (!ServiceFrameworkExtension.processAnnotatedTypeCalled) + msg += "Portable Extension lifecycle observer method: process " + + "annotated type not called"; + + //BeanManager lookup + if (bm == null) + msg += "Injection of BeanManager into servlet failed"; + + //Get all beans and count the number of beans in the test package + Set<Bean<?>> allBeans = bm.getBeans(Object.class, new AnnotationLiteral<Any>(){}); + + if (sfc_proxy == null) + msg += "Injection of (proxied) service bean added via extension not available"; + +// if (sfc_unproxied == null) +// msg += "Injection of (unproxied) service bean added via extension not available"; + + //check if proxied service reference is indeed proxied + if (!Proxy.isProxyClass(sfc_proxy.getClass())) + msg += "Expected Proxied service reference, but got back an " + + "unproxied service reference "; + //invoke a method o + if(!sfc_proxy.fooMethod()) + msg += "invocation of method on proxied service failed"; + +// //check if unproxied service reference is not proxied +// if (Proxy.isProxyClass(sfc_unproxied.getClass())) +// msg += "Expected unProxied service reference, but got back an " + +// "proxied service reference "; +// //invoke a method o +// if(!sfc_unproxied.fooMethod()) +// msg += "invocation of method on unproxied service failed"; + + for (Iterator<Bean<?>> iterator = allBeans.iterator(); iterator.hasNext();) { + Bean<?> bean = iterator.next(); + if (bean.getBeanClass().getName().contains("SomeFramework")){ + msg += testFrameworkBean(bean); + } + } + + if (!ServiceFrameworkExtension.afterProcessBeanCalled) + msg += "Portable Extension lifecycle observer method: after " + + "ProcessBean not called for a bean registered by the portable" + + "extension"; + + writer.write(msg + "\n"); + } + + + private String testFrameworkBean(Bean<?> bean) { + String msg = ""; + if (!bean.getQualifiers().contains(new AnnotationLiteral<Any>() {}) + || !bean.getQualifiers().contains(new AnnotationLiteral<Default>() {})) + msg += "FrameworkBean does not have the default expected qualifiers"; + + if (!bean.getScope().equals(Dependent.class)) + msg += "FrameworkBean scope is not dependent"; + + if(!bean.getBeanClass().getName().equals(SomeFwkServiceImpl.class.getName())) + msg += "Framework Bean: Incorrect bean class"; + return msg; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/README b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/README new file mode 100644 index 0000000..64b0a7c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/README
@@ -0,0 +1,5 @@ +Test +- Testing portable extensions support + - Bean interface + - getting all beans that exists in the application + - Registering a new Framework bean and ensure that is available for injection \ No newline at end of file
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/build.properties b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/build.properties new file mode 100644 index 0000000..3583686 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-make-framework-bean-available-for-injection"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/build.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/build.xml new file mode 100644 index 0000000..8894688 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/build.xml
@@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + <param name="cdi-extension.service" value="cdi-extension.service"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/cdi-extension.service b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/cdi-extension.service new file mode 100644 index 0000000..80fa6f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/cdi-extension.service
@@ -0,0 +1 @@ +test.extension.ServiceFrameworkExtension
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/client/test/client/WebTest.java new file mode 100644 index 0000000..2c3167e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/client/test/client/WebTest.java
@@ -0,0 +1,112 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "portable-extension-make-framework-bean-available-for-injection"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for portable extensions"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/descriptor/beans.xml new file mode 100644 index 0000000..f075638 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/descriptor/beans.xml
@@ -0,0 +1,28 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.TransactionInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..fa8fdb7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/beans/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4792d26 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/beans/TestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class TestBean { + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/beans/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/beans/TransactionInterceptor.java new file mode 100644 index 0000000..374113e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/beans/TransactionInterceptor.java
@@ -0,0 +1,53 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import test.extension.ServiceFrameworkExtension; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TransactionInterceptor(ServiceFrameworkExtension myex){ //Injection of portable extension in a bean + if(myex == null) { + errorMessage += "Portable Extension Injection in Interceptor failed"; + } + } + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("TransactionInterceptor::AroundInvoke"); + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/beans/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/beans/Transactional.java new file mode 100644 index 0000000..eef70c9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/beans/Transactional.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/extension/FrameworkServiceFactory.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/extension/FrameworkServiceFactory.java new file mode 100644 index 0000000..ae66fd9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/extension/FrameworkServiceFactory.java
@@ -0,0 +1,62 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.extension; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.lang.reflect.Type; + +import test.fwk.FrameworkService; +import test.fwk.SomeFwkServiceImpl; +import test.fwk.SomeFwkServiceInterface; + +public class FrameworkServiceFactory { + public static Object getService(final Type type, final FrameworkService fs){ + //NOTE:hard-coded for this test, but ideally should get the + //service implementation from the service registry + SomeFwkServiceInterface instance = + (SomeFwkServiceInterface) lookupService(type, fs.waitTimeout()); + + if (fs.dynamic()) { + InvocationHandler ih = new InvocationHandler() { + @Override + public Object invoke(Object proxy, Method method, Object[] args) + throws Throwable { + System.out.println("****************** Method " + method + " called on proxy"); + return method.invoke(lookupService(type, fs.waitTimeout()), args); + } + }; + instance = (SomeFwkServiceInterface) + Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), + new Class[]{SomeFwkServiceInterface.class}, ih); + } + return instance; + } + + private static Object lookupService(Type type, int waitTimeout) { + if (type.equals(SomeFwkServiceInterface.class)){ + return new SomeFwkServiceImpl("test"); + } + return null; + } + + public static void ungetService(Object serviceInstance){ + //unget the service instance from the service registry + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/extension/ServiceFrameworkExtension.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/extension/ServiceFrameworkExtension.java new file mode 100644 index 0000000..8a9f5b8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/extension/ServiceFrameworkExtension.java
@@ -0,0 +1,323 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.extension; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import javax.enterprise.context.Dependent; +import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.event.Observes; +import javax.enterprise.inject.Any; +import javax.enterprise.inject.Default; +import javax.enterprise.inject.spi.AfterBeanDiscovery; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.BeforeBeanDiscovery; +import javax.enterprise.inject.spi.Extension; +import javax.enterprise.inject.spi.InjectionPoint; +import javax.enterprise.inject.spi.ProcessAnnotatedType; +import javax.enterprise.inject.spi.ProcessBean; +import javax.enterprise.inject.spi.ProcessInjectionTarget; +import javax.enterprise.util.AnnotationLiteral; + +import test.fwk.FrameworkService; +import test.fwk.SomeFwkServiceImpl; +import test.fwk.SomeFwkServiceInterface; + +/** + * A portable extension that supports injection of custom framework + * services into Beans. + * + * @author Sivakumar Thyagarajan + */ +public class ServiceFrameworkExtension implements Extension{ + + public static boolean beforeBeanDiscoveryCalled = false; + public static boolean afterBeanDiscoveryCalled = false; + public static boolean afterProcessBeanCalled = false; + public static boolean processAnnotatedTypeCalled = false; + + /* + * A map of Framework Service Types to be injected and additional metadata + * about the FrameworkService to be injected. + */ + private HashMap<Type, Set<FrameworkService>> frameworkServicesToBeInjected + = new HashMap<Type, Set<FrameworkService>>(); + private static final boolean DEBUG_ENABLED = false; + + + //Observers for container lifecycle events + void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bdd){ + debug("beforeBeanDiscovery" + bdd); + beforeBeanDiscoveryCalled = true; + } + + <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat){ + debug("Process annotated type" + pat.getAnnotatedType().getBaseType()); + processAnnotatedTypeCalled = true; + } + + /** + * Observer for <code>ProcessInjectionTarget</code> events. This event is + * fired for every Java EE component class supporting injection that may be + * instantiated by the container at runtime. Injections points of every + * discovered enabled Java EE component is checked to see if there is a + * request for injection of a framework service. + */ + void afterProcessInjectionTarget(@Observes ProcessInjectionTarget<?> pb){ + debug("AfterProcessInjectionTarget" + pb.getAnnotatedType().getBaseType()); + Set<InjectionPoint> ips = pb.getInjectionTarget().getInjectionPoints(); + discoverServiceInjectionPoints(ips); + } + + /** + * Observer for <code>ProcessInjectionTarget</code> events. This event is + * fired fire an event for each enabled bean, interceptor or decorator + * deployed in a bean archive, before registering the Bean object. + * Injections points of every discovered enabled Java EE component is + * checked to see if there is a request for injection of a framework + * service. + */ + void afterProcessBean(@Observes ProcessBean pb){ + afterProcessBeanCalled = true; + debug("afterProcessBean - " + pb.getAnnotated().getBaseType()); + Set<InjectionPoint> ips = pb.getBean().getInjectionPoints(); + discoverServiceInjectionPoints(ips); + } + + /* + * Discover injection points where the framework service is requested + * through the <code>FrameworkService</code> qualifier and a map is + * populated for all framework services that have been requested. + */ + private void discoverServiceInjectionPoints(Set<InjectionPoint> ips) { + for (Iterator<InjectionPoint> iterator = ips.iterator(); + iterator.hasNext();) { + InjectionPoint injectionPoint = iterator.next(); + Set<Annotation> qualifs = injectionPoint.getQualifiers(); + for (Iterator<Annotation> qualifIter = qualifs.iterator(); + qualifIter.hasNext();) { + Annotation annotation = qualifIter.next(); + if (annotation.annotationType().equals(FrameworkService.class)){ + printDebugForInjectionPoint(injectionPoint); + //Keep track of service-type and its attributes + System.out.println("---- Injection requested for " + + "framework service type " + injectionPoint.getType() + + " and annotated with dynamic=" + + injectionPoint.getAnnotated() + .getAnnotation(FrameworkService.class) + .dynamic() + + ", serviceCriteria=" + + injectionPoint.getAnnotated() + .getAnnotation(FrameworkService.class) + .serviceCriteria()); + //Add to list of framework services to be injected + Type key = injectionPoint.getType(); + FrameworkService value = injectionPoint.getAnnotated() + .getAnnotation(FrameworkService.class); + if (!frameworkServicesToBeInjected.containsKey(key)){ + frameworkServicesToBeInjected.put(key, new HashSet<FrameworkService>()); + } + frameworkServicesToBeInjected.get(key).add(value); + System.out.println(frameworkServicesToBeInjected.size()); + + } + } + } + } + + /** + * Observer for <code>AfterBeanDiscovery</code> events. This + * observer method is used to register <code>Bean</code>s for the framework + * services that have been requested to be injected. + */ + void afterBeanDiscovery(@Observes AfterBeanDiscovery abd){ + afterBeanDiscoveryCalled = true; + debug("After Bean Discovery"); + for (Iterator<Type> iterator = this.frameworkServicesToBeInjected.keySet().iterator(); + iterator.hasNext();) { + Type type = iterator.next(); + //If the injection point's type is not a Class or Interface, we + //don't know how to handle this. + if (!(type instanceof Class)) { + System.out.println("Unknown type:" + type); + abd.addDefinitionError(new UnsupportedOperationException( + "Injection target type " + type + "not supported")); + break; //abort deployment + } + //Add the Bean representing the framework service so that it + //is available for injection + addBean(abd, type, this.frameworkServicesToBeInjected.get(type)); + } + } + + /* + * Add a <code>Bean</code> for the framework service requested. Instantiate + * or discover the bean from the framework service registry, + * and return a reference to the service if a dynamic reference is requested. + */ + private void addBean(AfterBeanDiscovery abd, final Type type, + final Set<FrameworkService> frameworkServices) { + for (Iterator<FrameworkService> iterator = frameworkServices.iterator(); iterator + .hasNext();) { + final FrameworkService frameworkService = iterator.next(); + System.out.println(" --- Adding a framework service BEAN " + type + " for " + frameworkService); + abd.addBean(new FrameworkServiceBean(type, frameworkService)); + } + } + + + private final class FrameworkServiceBean implements Bean { + private final Type type; + private final FrameworkService frameworkService; + + private FrameworkServiceBean(Type type, + FrameworkService frameworkService) { + this.type = type; + this.frameworkService = frameworkService; + } + + @Override + public Object create(CreationalContext arg0) { + //get the service from the service registry + return FrameworkServiceFactory.getService(type, frameworkService); + } + + @Override + public void destroy(Object instance, + CreationalContext creationalContext) { + System.out.println("destroy::" + instance); + //unget the service reference + FrameworkServiceFactory.ungetService(instance); + } + + @Override + public Class getBeanClass() { + return (Class)type; + } + + @Override + public Set<InjectionPoint> getInjectionPoints() { + return Collections.emptySet(); + } + + @Override + public String getName() { + return type + "_dynamic_" + frameworkService.dynamic() + + "_criteria_" + frameworkService.serviceCriteria() + + "_waitTimeout" + frameworkService.waitTimeout(); + } + + @Override + public Set<Annotation> getQualifiers() { + Set<Annotation> s = new HashSet<Annotation>(); + s.add(new AnnotationLiteral<Default>() {}); + s.add(new AnnotationLiteral<Any>() {}); + //Add the appropriate parameters to the FrameworkService qualifier + //as requested in the injection point + s.add(new FrameworkServiceQualifierType(frameworkService)); + return s; + } + + @Override + public Class<? extends Annotation> getScope() { + return Dependent.class; + } + + @Override + public Set<Class<? extends Annotation>> getStereotypes() { + return Collections.emptySet(); + } + + @Override + public Set<Type> getTypes() { + Set<Type> s = new HashSet<Type>(); + s.add(type); + s.add(Object.class); + return s; + } + + @Override + public boolean isAlternative() { + return false; + } + + @Override + public boolean isNullable() { + return false; + } + } + + /* + * Represents an annotation type instance of FrameworkService + * with parameters equal to those specified in the injection point + */ + private final class FrameworkServiceQualifierType + extends AnnotationLiteral<FrameworkService> implements FrameworkService { + private String serviceCriteria = ""; + private boolean dynamic = false; + private int waitTimeout = -1; + + public FrameworkServiceQualifierType(FrameworkService frameworkService){ + this.serviceCriteria = frameworkService.serviceCriteria(); + this.dynamic = frameworkService.dynamic(); + this.waitTimeout = frameworkService.waitTimeout(); + } + @Override + public String serviceCriteria(){ + return this.serviceCriteria; + } + + @Override + public boolean dynamic() { + return this.dynamic; + } + + @Override + public int waitTimeout() { + return this.waitTimeout; + } + } + + private void debug(String string) { + if(DEBUG_ENABLED) + System.out.println("MyExtension:: " + string); + + } + + private void printDebugForInjectionPoint(InjectionPoint injectionPoint) { + if (DEBUG_ENABLED) { + System.out.println("@@@@@@@ INJECTION-POINT: Annotation:" + + injectionPoint.getAnnotated()); // annotatedfield + System.out.print(" ,Bean:" + injectionPoint.getBean());// bean + System.out.print(" ,Class:" + injectionPoint.getClass()); // r untime + // class? + System.out.print(" ,Member:" + injectionPoint.getMember());// Field + System.out.print(" ,Qualifiers:" + injectionPoint.getQualifiers());// qualifiers + System.out.print(" ,Type:" + injectionPoint.getType());// type of + // injection + // point + } + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/fwk/FrameworkService.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/fwk/FrameworkService.java new file mode 100644 index 0000000..542eef2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/fwk/FrameworkService.java
@@ -0,0 +1,58 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.fwk; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) + +/** + * A CDI Qualifier that represents a reference to a + * service in the framework. If this qualifiers annotates an injection point, + * the framework extension discovers and instantiates + * a service implementing the service interface type of the injection point + * and makes it available for injection to that injection point. + */ +public @interface FrameworkService { + /** + * Determines if the service reference that is injected + * refers to a dynamic proxy or the actual service reference obtained + * from the framework service registry + */ + boolean dynamic() default false; //dynamic + + /** + * service discovery criteria + */ + String serviceCriteria() default ""; + + /** + * wait specified in millis. -1 indicates indefinite wait + */ + int waitTimeout() default -1; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/fwk/SomeFwkServiceImpl.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/fwk/SomeFwkServiceImpl.java new file mode 100644 index 0000000..fb08b08 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/fwk/SomeFwkServiceImpl.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.fwk; + +public class SomeFwkServiceImpl implements SomeFwkServiceInterface { + + public SomeFwkServiceImpl(String t){ + System.out.println("SomeFrameworkClass:" + t); + } + + @Override + public boolean fooMethod() { + System.out.println("SomeFwkServiceImpl::fooMethod called"); + return true; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/fwk/SomeFwkServiceInterface.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/fwk/SomeFwkServiceInterface.java new file mode 100644 index 0000000..809bbe0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/fwk/SomeFwkServiceInterface.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.fwk; + +public interface SomeFwkServiceInterface { + public boolean fooMethod(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/servlet/PortableExtensionBeanRegistrationTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/servlet/PortableExtensionBeanRegistrationTestServlet.java new file mode 100644 index 0000000..f64b749 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/new-bean-registration/servlet/test/servlet/PortableExtensionBeanRegistrationTestServlet.java
@@ -0,0 +1,159 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.Proxy; +import java.util.Iterator; +import java.util.Set; + +import javax.enterprise.context.Dependent; +import javax.enterprise.inject.Any; +import javax.enterprise.inject.Default; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.Preferred; +import test.beans.TestBean; +import test.beans.TransactionInterceptor; +import test.extension.ServiceFrameworkExtension; +import test.fwk.FrameworkService; +import test.fwk.SomeFwkServiceImpl; +import test.fwk.SomeFwkServiceInterface; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class PortableExtensionBeanRegistrationTestServlet extends HttpServlet { + @Inject + @Preferred + TestBean tb; + + @Inject + BeanManager bm; + + @Inject + @FrameworkService(serviceCriteria="TEST", dynamic=true) + SomeFwkServiceInterface sfc_proxy; + + @Inject + @FrameworkService(serviceCriteria="FOO", dynamic=false) + SomeFwkServiceInterface sfc_unproxied; + + String msg = ""; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + + if (tb == null) + msg += "Injection of request scoped bean failed"; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + //check if our portable extension was called + if (!ServiceFrameworkExtension.beforeBeanDiscoveryCalled) + msg += "Portable Extension lifecycle observer method: " + + "beforeBeanDiscovery not called"; + + if (!ServiceFrameworkExtension.afterBeanDiscoveryCalled) + msg += "Portable Extension lifecycle observer method: " + + "afterBeanDiscovery not called or injection of BeanManager " + + "in an observer method failed"; + + if (!ServiceFrameworkExtension.processAnnotatedTypeCalled) + msg += "Portable Extension lifecycle observer method: process " + + "annotated type not called"; + + //BeanManager lookup + if (bm == null) + msg += "Injection of BeanManager into servlet failed"; + + //Get all beans and count the number of beans in the test package + Set<Bean<?>> allBeans = bm.getBeans(Object.class, new AnnotationLiteral<Any>(){}); + + if (sfc_proxy == null) + msg += "Injection of (proxied) service bean added via extension not available"; + + if (sfc_unproxied == null) + msg += "Injection of (unproxied) service bean added via extension not available"; + + //check if proxied service reference is indeed proxied + if (!Proxy.isProxyClass(sfc_proxy.getClass())) + msg += "Expected Proxied service reference, but got back an " + + "unproxied service reference "; + //invoke a method o + if(!sfc_proxy.fooMethod()) + msg += "invocation of method on proxied service failed"; + + //check if unproxied service reference is not proxied + if (Proxy.isProxyClass(sfc_unproxied.getClass())) + msg += "Expected unProxied service reference, but got back an " + + "proxied service reference "; + //invoke a method o + if(!sfc_unproxied.fooMethod()) + msg += "invocation of method on unproxied service failed"; + + for (Iterator<Bean<?>> iterator = allBeans.iterator(); iterator.hasNext();) { + Bean<?> bean = iterator.next(); + if (bean.getBeanClass().getName().contains("SomeFramework")){ + msg += testFrameworkBean(bean); + } + } + + if (!ServiceFrameworkExtension.afterProcessBeanCalled) + msg += "Portable Extension lifecycle observer method: after " + + "ProcessBean not called for a bean registered by the portable" + + "extension"; + + writer.write(msg + "\n"); + } + + + private String testFrameworkBean(Bean<?> bean) { + String msg = ""; + if (!bean.getQualifiers().contains(new AnnotationLiteral<Any>() {}) + || !bean.getQualifiers().contains(new AnnotationLiteral<Default>() {})) + msg += "FrameworkBean does not have the default expected qualifiers"; + + if (!bean.getScope().equals(Dependent.class)) + msg += "FrameworkBean scope is not dependent"; + + if(!bean.getBeanClass().getName().equals(SomeFwkServiceImpl.class.getName())) + msg += "Framework Bean: Incorrect bean class"; + return msg; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/README b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/README new file mode 100644 index 0000000..19a31f9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/README
@@ -0,0 +1,2 @@ +Test to reproduce issue 11923 +package private constructor for an Extension
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/build.properties b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/build.properties new file mode 100644 index 0000000..8dd1c12 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-package-private-constructor-in-portable-extension"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/build.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/build.xml new file mode 100644 index 0000000..8894688 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/build.xml
@@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + <param name="cdi-extension.service" value="cdi-extension.service"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/cdi-extension.service b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/cdi-extension.service new file mode 100644 index 0000000..dc65430 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/cdi-extension.service
@@ -0,0 +1 @@ +test.extension.PackagePrivateConstructorExtension
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/client/test/client/WebTest.java new file mode 100644 index 0000000..61bcfa7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/client/test/client/WebTest.java
@@ -0,0 +1,107 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "package-private-constructor-in-portable-extension"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for portable extensions"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/descriptor/beans.xml new file mode 100644 index 0000000..f075638 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/descriptor/beans.xml
@@ -0,0 +1,28 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.TransactionInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/DuplicateTestBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/DuplicateTestBean.java new file mode 100644 index 0000000..e44cd09 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/DuplicateTestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class DuplicateTestBean extends TestBean{ + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..fa8fdb7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4792d26 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/TestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class TestBean { + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/TestDependentBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/TestDependentBean.java new file mode 100644 index 0000000..1c15313 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/TestDependentBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public class TestDependentBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/TransactionInterceptor.java new file mode 100644 index 0000000..13d1aea --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/TransactionInterceptor.java
@@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import test.extension.PackagePrivateConstructorExtension; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @Inject + TransactionInterceptor(PackagePrivateConstructorExtension myex){ //Injection of portable extension in a bean + if(myex == null) { + errorMessage += "Portable Extension Injection in Interceptor failed"; + } + } + + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage += "Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/Transactional.java new file mode 100644 index 0000000..eef70c9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/beans/Transactional.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/extension/Interceptors.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/extension/Interceptors.java new file mode 100644 index 0000000..b4c87e5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/extension/Interceptors.java
@@ -0,0 +1,37 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.extension; + + +import javax.inject.Inject; + +public class Interceptors +{ + + @Inject + private PackagePrivateConstructorExtension interceptorExtension; + + private Interceptors() + { + } + + public boolean isInterceptorEnabled(Class<?> clazz) + { + return interceptorExtension.getEnabledInterceptors().contains(clazz); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/extension/PackagePrivateConstructorExtension.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/extension/PackagePrivateConstructorExtension.java new file mode 100644 index 0000000..87c672b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/extension/PackagePrivateConstructorExtension.java
@@ -0,0 +1,85 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.extension; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; + +import javax.enterprise.event.Observes; +import javax.enterprise.inject.spi.AfterBeanDiscovery; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.inject.spi.BeforeBeanDiscovery; +import javax.enterprise.inject.spi.Extension; +import javax.enterprise.inject.spi.Interceptor; +import javax.enterprise.inject.spi.ProcessAnnotatedType; +import javax.enterprise.inject.spi.ProcessBean; + +import test.beans.DuplicateTestBean; + +public class PackagePrivateConstructorExtension implements Extension{ + public static boolean beforeBeanDiscoveryCalled = false; + public static boolean afterBeanDiscoveryCalled = false; + public static boolean processAnnotatedTypeCalled = false; + public static boolean packagePrivateConstructorCalled = false; + private Collection<Class<?>> enabledInterceptors; + /* package private */ PackagePrivateConstructorExtension(){ + System.out.println("In MyExtension ctor"); + PackagePrivateConstructorExtension.packagePrivateConstructorCalled = true; + this.enabledInterceptors = Collections.synchronizedSet(new + HashSet<Class<?>>()); + } + + @SuppressWarnings("unused") + void observeInterceptors(@Observes ProcessBean<?> pmb) + { + if (pmb.getBean() instanceof Interceptor<?>) + { + this.enabledInterceptors.add(pmb.getBean().getBeanClass()); + } + } + + Collection<Class<?>> getEnabledInterceptors() + { + return enabledInterceptors; + } + + void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bdd){ + System.out.println("MyExtension::beforeBeanDiscovery" + bdd); + beforeBeanDiscoveryCalled = true; + } + + <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat){ + System.out.println("MyExtension:Process annotated type" + pat.getAnnotatedType().getBaseType()); + processAnnotatedTypeCalled = true; + //Vetoing the processing of DuplicateTestBean + //If this is not vetoed, at the InjectionPoint in Servlet, there would be + //an ambiguous dependency due to TestBean and DuplicateTestBean + if (pat.getAnnotatedType().getBaseType().equals(DuplicateTestBean.class)){ + pat.veto(); + } + } + + void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm){ + System.out.println("MyExtension: abd: " + abd + " BeanManager: " + bm); + + if (bm != null) { + //ensure a valid BeanManager is injected + afterBeanDiscoveryCalled = true; + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/servlet/PackagePrivateConstructorInPortableExtensionTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/servlet/PackagePrivateConstructorInPortableExtensionTestServlet.java new file mode 100644 index 0000000..8f312d1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/package-private-extension-constructor/servlet/test/servlet/PackagePrivateConstructorInPortableExtensionTestServlet.java
@@ -0,0 +1,91 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.enterprise.inject.Any; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.Preferred; +import test.beans.TestBean; +import test.beans.TransactionInterceptor; +import test.extension.PackagePrivateConstructorExtension; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class PackagePrivateConstructorInPortableExtensionTestServlet extends HttpServlet { + @Inject + @Preferred + TestBean tb; + + @Inject + BeanManager bm; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (tb == null) + msg += "Injection of request scoped bean failed"; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + //check if our portable extension was called + if (!PackagePrivateConstructorExtension.packagePrivateConstructorCalled) + msg += "Portable Extension package private constructor: not called"; + + if (!PackagePrivateConstructorExtension.beforeBeanDiscoveryCalled) + msg += "Portable Extension lifecycle observer method: " + + "beforeBeanDiscovery not called"; + + if (!PackagePrivateConstructorExtension.afterBeanDiscoveryCalled) + msg += "Portable Extension lifecycle observer method: " + + "afterBeanDiscovery not called or injection of BeanManager " + + "in an observer method failed"; + + if (!PackagePrivateConstructorExtension.processAnnotatedTypeCalled) + msg += "Portable Extension lifecycle observer method: process " + + "annotated type not called"; + + if((bm.getBeans(PackagePrivateConstructorExtension.class, new AnnotationLiteral<Any>(){}).iterator().next().getClass()) == null) + msg += "Portable Extension not available for lookup through BeanManager"; + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/README b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/README new file mode 100644 index 0000000..eac5e9a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/README
@@ -0,0 +1,4 @@ +Test + Test for issue: 11135 + Extension sets its own InjectionTarget and check if that object is used + for injection
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/build.properties b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/build.properties new file mode 100644 index 0000000..e72b444 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-process-injection-target"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/build.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/build.xml new file mode 100644 index 0000000..8894688 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/build.xml
@@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + <param name="cdi-extension.service" value="cdi-extension.service"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/cdi-extension.service b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/cdi-extension.service new file mode 100644 index 0000000..4d6314f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/cdi-extension.service
@@ -0,0 +1 @@ +test.extension.MyExtension
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/client/test/client/WebTest.java new file mode 100644 index 0000000..c574dfd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/client/test/client/WebTest.java
@@ -0,0 +1,77 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * @author Jitendra Kotamraju + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = + "portable-extensions-process-injection-target"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private final String host; + private final String port; + private final String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for process injection target extension"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + + InputStream in = new URL(url).openStream(); + BufferedReader rdr = new BufferedReader(new InputStreamReader(in)); + String line = rdr.readLine(); + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + rdr.close(); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/servlet/test/extension/MyExtension.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/servlet/test/extension/MyExtension.java new file mode 100644 index 0000000..6472681 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/servlet/test/extension/MyExtension.java
@@ -0,0 +1,71 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.extension; + +import javax.enterprise.event.Observes; +import javax.enterprise.inject.spi.*; +import javax.enterprise.context.spi.*; + +import test.servlet.PortableExtensionInjectionTargetTestServlet; + +import java.util.Set; + +/** + * Test for issue: 11135 + * + * Extension sets its own injection target and check if that object is used + * for injection + * + * @author Jitendra Kotamraju + */ +public class MyExtension implements Extension { + public static boolean processAnnotatedTypeCalled = false; + + public void observe(final @Observes ProcessInjectionTarget<PortableExtensionInjectionTargetTestServlet> pit) { + PortableExtensionInjectionTargetTestServlet.pitCalled = true; + + final InjectionTarget<PortableExtensionInjectionTargetTestServlet> it = pit.getInjectionTarget(); + pit.setInjectionTarget(new InjectionTarget<PortableExtensionInjectionTargetTestServlet>() { + + public void inject(PortableExtensionInjectionTargetTestServlet instance, CreationalContext<PortableExtensionInjectionTargetTestServlet> ctx) { + it.inject(instance, ctx); + instance.pitsInjectionTargetUsed = true; + } + + public void postConstruct(PortableExtensionInjectionTargetTestServlet instance) { + it.postConstruct(instance); + } + + public void preDestroy(PortableExtensionInjectionTargetTestServlet instance) { + it.preDestroy(instance); + } + + public void dispose(PortableExtensionInjectionTargetTestServlet instance) { + } + + public Set<InjectionPoint> getInjectionPoints() { + return it.getInjectionPoints(); + } + + public PortableExtensionInjectionTargetTestServlet produce(CreationalContext<PortableExtensionInjectionTargetTestServlet> ctx) { + return it.produce(ctx); + } + + }); + + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/servlet/test/servlet/PortableExtensionInjectionTargetTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/servlet/test/servlet/PortableExtensionInjectionTargetTestServlet.java new file mode 100644 index 0000000..e2e9d9d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/process-injection-target/servlet/test/servlet/PortableExtensionInjectionTargetTestServlet.java
@@ -0,0 +1,69 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.enterprise.context.ConversationScoped; +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; +import javax.inject.Inject; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @author Jitendra Kotamraju + */ +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class PortableExtensionInjectionTargetTestServlet extends HttpServlet { + +// @Inject +// BeanManager bm; + + String msg = ""; + + public static volatile boolean pitCalled; + public volatile boolean pitsInjectionTargetUsed; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + + if (!pitCalled) { + msg += " MyExtension's observe(ProcessInjectionTarget) is not called"; + } + + if (!pitsInjectionTargetUsed) { + msg += " MyExtension's replaced InjectionTarget is not used"; + } + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/README b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/README new file mode 100644 index 0000000..bd0e702 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/README
@@ -0,0 +1,9 @@ +Test +- Testing portable extensions support + - Creating a portable extension and registering the extension as a + service provider + - Injection of Extension in Beans(Interceptor) + - Extensions can observe container lifecycle events + - Extensions can modify container's metamodel (veto an annotated type's + processing) + - Extension's observer method may inject a BeanManager
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/build.properties b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/build.properties new file mode 100644 index 0000000..e784675 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-simple-portable-extension"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/build.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/build.xml new file mode 100644 index 0000000..8894688 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/build.xml
@@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + <param name="cdi-extension.service" value="cdi-extension.service"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/cdi-extension.service b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/cdi-extension.service new file mode 100644 index 0000000..4d6314f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/cdi-extension.service
@@ -0,0 +1 @@ +test.extension.MyExtension
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/client/test/client/WebTest.java new file mode 100644 index 0000000..174d171 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/client/test/client/WebTest.java
@@ -0,0 +1,107 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "portable-extensions-simple-extension"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for portable extensions"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/descriptor/beans.xml new file mode 100644 index 0000000..f075638 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/descriptor/beans.xml
@@ -0,0 +1,28 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.TransactionInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/DuplicateTestBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/DuplicateTestBean.java new file mode 100644 index 0000000..e44cd09 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/DuplicateTestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class DuplicateTestBean extends TestBean{ + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..fa8fdb7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4792d26 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/TestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class TestBean { + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/TestDependentBean.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/TestDependentBean.java new file mode 100644 index 0000000..1c15313 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/TestDependentBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public class TestDependentBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/TransactionInterceptor.java new file mode 100644 index 0000000..0b78e5f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/TransactionInterceptor.java
@@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import test.extension.MyExtension; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @Inject + TransactionInterceptor(MyExtension myex){ //Injection of portable extension in a bean + if(myex == null) { + errorMessage += "Portable Extension Injection in Interceptor failed"; + } + } + + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage += "Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/Transactional.java new file mode 100644 index 0000000..eef70c9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/beans/Transactional.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/extension/MyExtension.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/extension/MyExtension.java new file mode 100644 index 0000000..22c7415 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/extension/MyExtension.java
@@ -0,0 +1,61 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.extension; + +import javax.enterprise.event.Observes; +import javax.enterprise.inject.spi.AfterBeanDiscovery; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.inject.spi.BeforeBeanDiscovery; +import javax.enterprise.inject.spi.Extension; +import javax.enterprise.inject.spi.ProcessAnnotatedType; + +import test.beans.DuplicateTestBean; + +public class MyExtension implements Extension{ + public static boolean beforeBeanDiscoveryCalled = false; + public static boolean afterBeanDiscoveryCalled = false; + public static boolean processAnnotatedTypeCalled = false; + public MyExtension(){ + System.out.println("In MyExtension ctor"); + //new Throwable().printStackTrace(); + } + + void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bdd){ + System.out.println("MyExtension::beforeBeanDiscovery" + bdd); + beforeBeanDiscoveryCalled = true; + } + + <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat){ + System.out.println("MyExtension:Process annotated type" + pat.getAnnotatedType().getBaseType()); + processAnnotatedTypeCalled = true; + //Vetoing the processing of DuplicateTestBean + //If this is not vetoed, at the InjectionPoint in Servlet, there would be + //an ambiguous dependency due to TestBean and DuplicateTestBean + if (pat.getAnnotatedType().getBaseType().equals(DuplicateTestBean.class)){ + pat.veto(); + } + } + + void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm){ + System.out.println("MyExtension: abd: " + abd + " BeanManager: " + bm); + + if (bm != null) { + //ensure a valid BeanManager is injected + afterBeanDiscoveryCalled = true; + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/servlet/SimplePortableExtensionTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/servlet/SimplePortableExtensionTestServlet.java new file mode 100644 index 0000000..032fefd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/portable-extensions/simple-portable-extension/servlet/test/servlet/SimplePortableExtensionTestServlet.java
@@ -0,0 +1,88 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.enterprise.inject.Any; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.Preferred; +import test.beans.TestBean; +import test.beans.TransactionInterceptor; +import test.extension.MyExtension; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class SimplePortableExtensionTestServlet extends HttpServlet { + @Inject + @Preferred + TestBean tb; + + @Inject + BeanManager bm; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (tb == null) + msg += "Injection of request scoped bean failed"; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + //check if our portable extension was called + if (!MyExtension.beforeBeanDiscoveryCalled) + msg += "Portable Extension lifecycle observer method: " + + "beforeBeanDiscovery not called"; + + if (!MyExtension.afterBeanDiscoveryCalled) + msg += "Portable Extension lifecycle observer method: " + + "afterBeanDiscovery not called or injection of BeanManager " + + "in an observer method failed"; + + if (!MyExtension.processAnnotatedTypeCalled) + msg += "Portable Extension lifecycle observer method: process " + + "annotated type not called"; + + if((bm.getBeans(MyExtension.class, new AnnotationLiteral<Any>(){}).iterator().next().getClass()) == null) + msg += "Portable Extension not available for lookup through BeanManager"; + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/build.xml b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/build.xml new file mode 100644 index 0000000..b1febf6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/build.xml
@@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<project name="prodmeth-test" default="usage" basedir="."> + + <property name="prodmeth-target" value="all"/> + + <target name="run-test"> + <antcall target="prodmeth"> + <param name="prodmeth-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="prodmeth"> + <param name="prodmeth-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="prodmeth"> + <param name="prodmeth-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="prodmeth"> + <param name="prodmeth-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="prodmeth"> + <param name="prodmeth-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="prodmeth"> + <param name="prodmeth-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="prodmeth"> + <param name="prodmeth-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="prodmeth"> + <param name="prodmeth-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="prodmeth"> + <param name="prodmeth-target" value="run"/> + </antcall> + </target> + + <target name="prodmeth"> + <record name="prodmeth.output" action="start" /> + <ant dir="producer-method-disposes" target="${prodmeth-target}"/> + <ant dir="producer-method-qualifiers" target="${prodmeth-target}"/> + <ant dir="producer-method-runtimepolymorphism" target="${prodmeth-target}"/> + <record name="prodmeth.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant all (Executes all the prodmeth tests) + ant clean (cleans all the prodmeth tests) + ant build (builds all the prodmeth tests) + ant setup (sets up all resources for prodmeth tests) + ant deploy (deploys all the prodmeth apps) + ant run (Executes all the prodmeth tests) + ant undeploy (undeploys all the prodmeth apps) + ant unsetup (unsets all resources for prodmeth tests) + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/README b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/README new file mode 100644 index 0000000..96ee3ef --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/README
@@ -0,0 +1,3 @@ +Test +- Destruction of a bean by a matching disposer method, defined by the same class as the producer method +- Test injection of method parameters into disposer methods \ No newline at end of file
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/build.properties b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/build.properties new file mode 100644 index 0000000..99e385b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-producer-methods-disposermethods"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/build.xml b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/client/test/client/WebTest.java new file mode 100644 index 0000000..c007bb6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/client/test/client/WebTest.java
@@ -0,0 +1,110 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "producer-methods-disposer"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for producer methods"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception{ + actual_invoke("myurl1"); + actual_invoke("myurl2"); + } + private void actual_invoke(String urlFragment) throws Exception { + String url = "http://" + host + ":" + port + contextRoot + + "/" + urlFragment; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/beans/BeanSetup.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/beans/BeanSetup.java new file mode 100644 index 0000000..1736754 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/beans/BeanSetup.java
@@ -0,0 +1,58 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; +import javax.enterprise.inject.Disposes; +import javax.enterprise.inject.Produces; + +public class BeanSetup { + public static boolean disposeCalledForPreferred = false; + public static String disposeCalledForTestQualifierError = ""; + + @RequestScoped + @Produces + @Preferred + public TestRequestScopedBean get(TestRequestScopedBean trs) { + return trs; + } + + void dispose(@Disposes @Preferred TestRequestScopedBean trs) { + System.out + .println("Dispose method in BeanSetup for Preferred called"); + disposeCalledForPreferred = true; + } + + @RequestScoped + @Produces + @TestQualifier + public TestRequestScopedBean getTestQualifier(TestRequestScopedBean trs) { + return trs; + } + + //test injection of TestBean in this disposer method + void disposeTestQualifier( + @Disposes @TestQualifier TestRequestScopedBean trs, TestBean tb) { + System.out + .println("Dispose method in BeanSetup for testQualifier called"); + if (tb != null) { + disposeCalledForTestQualifierError = "dispose method for testqualifier " + + "called without injecting TestBean"; + } + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..e8dfef4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/beans/Preferred.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..49b95c1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/beans/TestBean.java
@@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + + +public class TestBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/beans/TestQualifier.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/beans/TestQualifier.java new file mode 100644 index 0000000..971a9a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/beans/TestQualifier.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestQualifier { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/beans/TestRequestScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/beans/TestRequestScopedBean.java new file mode 100644 index 0000000..69a8672 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/beans/TestRequestScopedBean.java
@@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + + +public class TestRequestScopedBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/servlet/ProducerMethodDisposesTestServlet1.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/servlet/ProducerMethodDisposesTestServlet1.java new file mode 100644 index 0000000..ac4dea8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/servlet/ProducerMethodDisposesTestServlet1.java
@@ -0,0 +1,61 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.Preferred; +import test.beans.TestQualifier; +import test.beans.TestRequestScopedBean; + +@WebServlet(name = "mytest1", urlPatterns = { "/myurl1" }) +public class ProducerMethodDisposesTestServlet1 extends HttpServlet { + + @Inject @Preferred + TestRequestScopedBean trs; + + @Inject @TestQualifier + TestRequestScopedBean trs2; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + System.out.println("trs: " + trs); + String msg = ""; + + if (trs == null) + msg += "RequestScoped Bean injection into Servlet of Bean created through " + + "programmatic instantiation in producer method (Preferred) failed"; + if (trs2 == null) + msg += "RequestScoped Bean injection into Servlet of Bean created through " + + "programmatic instantiation in producer method (TestQualifier) failed"; + + writer.write(msg + "\n"); + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/servlet/ProducerMethodDisposesTestServlet2.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/servlet/ProducerMethodDisposesTestServlet2.java new file mode 100644 index 0000000..70fa961 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-disposes/servlet/test/servlet/ProducerMethodDisposesTestServlet2.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.BeanSetup; +import test.beans.TestRequestScopedBean; + +@WebServlet(name = "mytest2", urlPatterns = { "/myurl2" }) +public class ProducerMethodDisposesTestServlet2 extends HttpServlet { + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (!BeanSetup.disposeCalledForPreferred) + msg += "Disposer method for preferred not called"; + if (!(BeanSetup.disposeCalledForTestQualifierError.trim().length() == 0)) + msg += BeanSetup.disposeCalledForTestQualifierError; + + writer.write(msg + "\n"); + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/README b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/README new file mode 100644 index 0000000..2be97bf --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/README
@@ -0,0 +1,4 @@ +Test +- Use of Producer Methods to act as a source of injectable bean instances +- Qualifiers in Producer Methods to dynamically provide an instance of a bean type for injection +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/WebTest.java new file mode 100644 index 0000000..1b6e97c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/WebTest.java
@@ -0,0 +1,105 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "producer-methods-qualifiers"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/build.properties b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/build.properties new file mode 100644 index 0000000..eef7060 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-producer-methods-qualifiers"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/build.xml b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/build.xml new file mode 100644 index 0000000..83ad666 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/BeanToTestQualiferInProducerMethods.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/BeanToTestQualiferInProducerMethods.java new file mode 100644 index 0000000..0f5641e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/BeanToTestQualiferInProducerMethods.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import javax.enterprise.inject.Produces; +import javax.inject.Named; + +@Named +public class BeanToTestQualiferInProducerMethods { + + private static final boolean lesserThanHundred = true; + //choose a number lesser than hundred + + @Produces + int getRandomInt( + @RandomGreaterThanHundred int greater, + @RandomLessThanOrEqualToHundred int lesser) { + if (lesserThanHundred) { + return lesser; + } else { + return greater; + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/ProducerMethodTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/ProducerMethodTestServlet.java new file mode 100644 index 0000000..641a6d8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/ProducerMethodTestServlet.java
@@ -0,0 +1,76 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }, initParams = { + @WebInitParam(name = "n1", value = "v1"), + @WebInitParam(name = "n2", value = "v2") }) +public class ProducerMethodTestServlet extends HttpServlet { + @Inject + TestBean tb; + + @Inject + @RandomLessThanOrEqualToHundred + int randomNumber; + + @Inject + @RandomLessThanOrEqualToHundred + int randomNumber2; + + @Inject + @RandomGreaterThanHundred + int randomNumber3; + + @Inject + @RandomGreaterThanHundred + int randomNumber4; + + @Inject + int rng; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + System.out.println("RandomNumbers are " + randomNumber + "," + + randomNumber2 + "," + randomNumber3 + "," + randomNumber4); + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + ", n2=" + + getInitParameter("n2"); + if (tb == null) + msg += "Bean injection into Servlet failed"; + boolean randomNumberTestSuccess = (randomNumber < 101) + && (randomNumber2 < 100) && (randomNumber3 > 100) + && (randomNumber3 > 100); + if (!randomNumberTestSuccess) { + msg += "RandomNumber Producer Test Failed"; + } + if (!tb.testProducerMethod()) { + msg += "Producer Method to dynamically select a bean type implementation failed"; + } + writer.write("initParams: " + msg + "\n"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/RandomGreaterThanHundred.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/RandomGreaterThanHundred.java new file mode 100644 index 0000000..eaa4ec0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/RandomGreaterThanHundred.java
@@ -0,0 +1,33 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface RandomGreaterThanHundred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/RandomLessThanOrEqualToHundred.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/RandomLessThanOrEqualToHundred.java new file mode 100644 index 0000000..49ddef8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/RandomLessThanOrEqualToHundred.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import static java.lang.annotation.ElementType.*; + +import javax.inject.Qualifier; + + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface RandomLessThanOrEqualToHundred { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/RandomNumberGenerator.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/RandomNumberGenerator.java new file mode 100644 index 0000000..7774fa5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/RandomNumberGenerator.java
@@ -0,0 +1,37 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.inject.Named; + + +@ApplicationScoped +public class RandomNumberGenerator { + private static int lessThan100 = 99; + private static int greaterThan100 = 101; + + //Generate a number less than or equal to hundred + @Produces @Named @RandomLessThanOrEqualToHundred int getRandomNumber(){ + return lessThan100--; + } + + //Generate a number greater than 100 + @Produces @Named @RandomGreaterThanHundred int getRandomNumberGreatherThanHundred(){ + return greaterThan100++; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/TestBean.java new file mode 100644 index 0000000..1c88c96 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-qualifiers/servlet/TestBean.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import javax.inject.Inject; +public class TestBean { + + //This should use the int chosen in BeanToTestQualiferInProducerMethods + @Inject int rng; + + public boolean testProducerMethod(){ + return rng <= 100; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/README b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/README new file mode 100644 index 0000000..acba5a9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/README
@@ -0,0 +1,7 @@ +Test +- Use of Producer Methods to act as a source of injectable bean instances +- Use of producer methods and qualifiers to enable runtime polymorphism (runtime +selection of beans to inject) + - The beans can either be programmatically instantiated (new) + - or via Injection (if a request-scoped bean is injected and the producer + method is annotated session-scoped, use @New to create a new Dependent object)
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/build.properties b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/build.properties new file mode 100644 index 0000000..eef7060 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-producer-methods-qualifiers"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/build.xml b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/client/test/client/WebTest.java new file mode 100644 index 0000000..1dc1ea1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/client/test/client/WebTest.java
@@ -0,0 +1,107 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "producer-methods-runtimepolymorphism"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for producer methods"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/ChequePaymentStrategy.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/ChequePaymentStrategy.java new file mode 100644 index 0000000..ccbc64b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/ChequePaymentStrategy.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.io.Serializable; + +public class ChequePaymentStrategy implements PaymentStrategy, Serializable { + + @Override + public boolean credit(int val) { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/CreditCardPaymentStrategy.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/CreditCardPaymentStrategy.java new file mode 100644 index 0000000..0e3e7c9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/CreditCardPaymentStrategy.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.io.Serializable; + +import javax.enterprise.context.RequestScoped; + +@RequestScoped +//Note: This is request scoped bean +public class CreditCardPaymentStrategy implements PaymentStrategy, Serializable { + + @Override + public boolean credit(int val) { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/PayPalPaymentStrategy.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/PayPalPaymentStrategy.java new file mode 100644 index 0000000..204c482 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/PayPalPaymentStrategy.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.io.Serializable; + +public class PayPalPaymentStrategy implements PaymentStrategy, Serializable { + + @Override + public boolean credit(int val) { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/PaymentStrategy.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/PaymentStrategy.java new file mode 100644 index 0000000..9c87550 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/PaymentStrategy.java
@@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface PaymentStrategy { + boolean credit(int val); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/PaymentStrategyType.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/PaymentStrategyType.java new file mode 100644 index 0000000..73e5a9f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/PaymentStrategyType.java
@@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public enum PaymentStrategyType { + CREDIT_CARD, CHECK, PAYPAL; + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/Preferences.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/Preferences.java new file mode 100644 index 0000000..46091cb --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/Preferences.java
@@ -0,0 +1,80 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.io.Serializable; + +import javax.enterprise.context.SessionScoped; +import javax.enterprise.inject.New; +import javax.enterprise.inject.Produces; + +public class Preferences implements Serializable { + + private PaymentStrategyType paymentStrategy; + + @Produces + @Preferred_CreatedProgrammatically + //In this producer method, we are manually creating the + //bean instance + public PaymentStrategy getPaymentStrategy() { + if (true) + paymentStrategy = PaymentStrategyType.CREDIT_CARD; + // set CREDIT_CARD as preferred always + + switch (paymentStrategy) { + case CREDIT_CARD: + return new CreditCardPaymentStrategy(); + case CHECK: + return new ChequePaymentStrategy(); + case PAYPAL: + return new PayPalPaymentStrategy(); + default: + return null; + } + } + + @Produces + @Preferred_CreatedViaInjection + @SessionScoped + // This class is SessionScoped, so if we inject CreditCardPaymentStrategy + // (which is RequestScoped) + // we would incorrectly be promoting a request scoped object to a + // session-scoped object + // so we use @New for CreditCardPaymentStrategy alone. The rest of the + // payment + // strategies are Dependent anyway as they are not scoped explicitly in + // their + // classes + public PaymentStrategy getPaymentStrategy( + @New CreditCardPaymentStrategy ccps, ChequePaymentStrategy cps, + PayPalPaymentStrategy pps) { + // set CREDIT_CARD as preferred always + paymentStrategy = PaymentStrategyType.CREDIT_CARD; + + switch (paymentStrategy) { + case CREDIT_CARD: + return ccps; + case CHECK: + return cps; + case PAYPAL: + return pps; + default: + return null; + } + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/Preferred_CreatedProgrammatically.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/Preferred_CreatedProgrammatically.java new file mode 100644 index 0000000..f797a5a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/Preferred_CreatedProgrammatically.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred_CreatedProgrammatically { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/Preferred_CreatedViaInjection.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/Preferred_CreatedViaInjection.java new file mode 100644 index 0000000..d71a27c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/beans/Preferred_CreatedViaInjection.java
@@ -0,0 +1,37 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred_CreatedViaInjection { + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/servlet/ProducerMethodRuntimePolymorhpismTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/servlet/ProducerMethodRuntimePolymorhpismTestServlet.java new file mode 100644 index 0000000..7cfb8c3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/producer-methods/producer-method-runtimepolymorphism/servlet/test/servlet/ProducerMethodRuntimePolymorhpismTestServlet.java
@@ -0,0 +1,105 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.enterprise.context.SessionScoped; +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.CreditCardPaymentStrategy; +import test.beans.PaymentStrategy; +import test.beans.Preferred_CreatedProgrammatically; +import test.beans.Preferred_CreatedViaInjection; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class ProducerMethodRuntimePolymorhpismTestServlet extends HttpServlet { + + @Inject + @Preferred_CreatedProgrammatically + PaymentStrategy payCreate; + + @Inject + @Preferred_CreatedViaInjection + PaymentStrategy payInject; + + @Inject + @Preferred_CreatedViaInjection + PaymentStrategy payInject2; + + @Inject + CreditCardPaymentStrategy ccps;// This should be the request-scoped + // instance. + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + if (payCreate == null) + msg += "Bean injection into Servlet of Bean created through " + + "programmatic instantiation in producer method failed"; + + if (payInject == null) + msg += "Bean injection into Servlet of Bean created through " + + "injection into producer method failed"; + + if (!(payCreate instanceof PaymentStrategy)) + msg += "Bean runtime polymorphism in producer method " + + "in Preferences failed"; + if (!(payInject instanceof PaymentStrategy)) + msg += "Bean runtime polymorphism in producer method(dep injection " + + "in method parameters in Preferences failed"; + + if (areInjectedInstancesEqual(ccps, payInject)) + msg += "Use of @New to create new Dependent object while injecting " + + "in producer method failed"; + + if (!areInjectedInstancesEqual(payInject, payInject2)) + msg += "Session-scoped producer method created Bean injected in " + + "different injection points are not equal"; + + writer.write(msg + "\n"); + } + + private boolean areInjectedInstancesEqual(Object o1, Object o2) { + return (o1.equals(o2)) & (o1 == o2); + } + + // Tests if the bean instance is a client proxy + private boolean testIsClientProxy(Object beanInstance, Class beanType) { + boolean isSameClass = beanInstance.getClass().equals(beanType); + boolean isProxyAssignable = beanType.isAssignableFrom(beanInstance + .getClass()); + System.out.println(beanInstance + "whose class is " + + beanInstance.getClass() + " is same class of " + beanType + + " = " + isSameClass); + System.out.println(beanType + " is assignable from " + beanInstance + + " = " + isProxyAssignable); + boolean isAClientProxy = !isSameClass && isProxyAssignable; + return isAClientProxy; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/README b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/README new file mode 100644 index 0000000..e59123b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/README
@@ -0,0 +1,4 @@ +Test +- Programmatic lookup: specifying bean type and qualifiers(with +and without members) dynamically at runtime, @Any +- Injection of @Dependent unproxyable deps
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/WebTest.java new file mode 100644 index 0000000..35f7518 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/WebTest.java
@@ -0,0 +1,105 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "programmatic-lookup-tests"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Testing Programmatic Lookup"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + System.out.println("TESTNAME " + TEST_NAME); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/build.properties b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/build.properties new file mode 100644 index 0000000..57ba5ff --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi-programmatic-lookup"/> +<property name="appname" value="${module}-servlet-annotation"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/build.xml b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/build.xml new file mode 100644 index 0000000..c0d904d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/descriptor/beans.xml new file mode 100644 index 0000000..c0da4fc --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/descriptor/beans.xml
@@ -0,0 +1,26 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <alternatives> + <class>test.artifacts.MockPaymentProcessor</class> + </alternatives> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/Asynchronous.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/Asynchronous.java new file mode 100644 index 0000000..ca0dd14 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/Asynchronous.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) + +public @interface Asynchronous { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/AsynchronousPaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/AsynchronousPaymentProcessor.java new file mode 100644 index 0000000..9e0c62b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/AsynchronousPaymentProcessor.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +@Asynchronous +public class AsynchronousPaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/CashReliablePaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/CashReliablePaymentProcessor.java new file mode 100644 index 0000000..a72f9db --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/CashReliablePaymentProcessor.java
@@ -0,0 +1,27 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +@PayBy(value=PaymentMethod.CASH) @Reliable +//To test multiple qualifiers +public class CashReliablePaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/ChequePaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/ChequePaymentProcessor.java new file mode 100644 index 0000000..9fe824b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/ChequePaymentProcessor.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +@PayBy(PaymentMethod.CHEQUE) +public class ChequePaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/MockPaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/MockPaymentProcessor.java new file mode 100644 index 0000000..8d736e2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/MockPaymentProcessor.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +import javax.enterprise.inject.Alternative; + +@Alternative @Asynchronous @Synchronous +public class MockPaymentProcessor implements PaymentProcessor{ + + @Override + public boolean processPayment() { + return true; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/PayBy.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/PayBy.java new file mode 100644 index 0000000..179aca6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/PayBy.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.enterprise.util.Nonbinding; +import javax.inject.Qualifier; + +@Qualifier +@Target( { TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface PayBy { + PaymentMethod value() default PaymentMethod.CHEQUE; + + @Nonbinding + String comment() default ""; // A Non-Binding member. Is ignored during + // dependency resolution +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/PaymentMethod.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/PaymentMethod.java new file mode 100644 index 0000000..82e7eb6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/PaymentMethod.java
@@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +public enum PaymentMethod { + CHEQUE, CASH +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/PaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/PaymentProcessor.java new file mode 100644 index 0000000..3e25336 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/PaymentProcessor.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +public interface PaymentProcessor { + boolean processPayment(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/Reliable.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/Reliable.java new file mode 100644 index 0000000..8ece693 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/Reliable.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Reliable { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/Synchronous.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/Synchronous.java new file mode 100644 index 0000000..b4c5d7e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/Synchronous.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Synchronous { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/SynchronousPaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/SynchronousPaymentProcessor.java new file mode 100644 index 0000000..921cd3e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/SynchronousPaymentProcessor.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +@Synchronous +public class SynchronousPaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/TestApplicationScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/TestApplicationScopedBean.java new file mode 100644 index 0000000..c8a651c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/TestApplicationScopedBean.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; + +@ApplicationScoped +public class TestApplicationScopedBean { + @Inject + TestSessionScopedBean tsb; + + public TestSessionScopedBean getSessionScopedBean(){ + return tsb; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/TestSessionScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/TestSessionScopedBean.java new file mode 100644 index 0000000..272d946 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/TestSessionScopedBean.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +import java.io.Serializable; + +import javax.enterprise.context.SessionScoped; + +@SessionScoped +public class TestSessionScopedBean implements Serializable{ + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/UnproxyableFinalClass.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/UnproxyableFinalClass.java new file mode 100644 index 0000000..cd00eed --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/UnproxyableFinalClass.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +import java.io.Serializable; + +import javax.enterprise.context.Dependent; + +@Dependent +public final class UnproxyableFinalClass implements UnproxyableType, Serializable{ + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/UnproxyableType.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/UnproxyableType.java new file mode 100644 index 0000000..4a93c39 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/UnproxyableType.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +public interface UnproxyableType { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/UnproxyableTypeWithNoPublicNullConstructor.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/UnproxyableTypeWithNoPublicNullConstructor.java new file mode 100644 index 0000000..a92bd4d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/artifacts/UnproxyableTypeWithNoPublicNullConstructor.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +import java.io.Serializable; + +import javax.enterprise.context.Dependent; + +@Dependent +public class UnproxyableTypeWithNoPublicNullConstructor implements UnproxyableType, Serializable{ + //private null ctor + private UnproxyableTypeWithNoPublicNullConstructor(){ + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/beans/BeanToTestProgrammaticLookup.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/beans/BeanToTestProgrammaticLookup.java new file mode 100644 index 0000000..15122d6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/beans/BeanToTestProgrammaticLookup.java
@@ -0,0 +1,75 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.inject.Any; +import javax.enterprise.inject.Instance; +import javax.inject.Inject; + +import test.artifacts.Asynchronous; +import test.artifacts.MockPaymentProcessor; +import test.artifacts.PaymentProcessor; +import test.artifacts.Synchronous; +import test.artifacts.UnproxyableType; + +//Alternatives injection and test for availability of other beans via @Any +public class BeanToTestProgrammaticLookup { + private int numberOfPaymentProcessors = 0; + private int numberOfUnproxyableTypes = 0; + + @Inject + @Asynchronous + @Synchronous + private PaymentProcessor pp; + + @Inject + public void initPaymentProcessors( + @Any Instance<PaymentProcessor> payInstances) { + for (PaymentProcessor p : payInstances) { + System.out.println("Payment Processor #" + + numberOfPaymentProcessors + ":" + p); + numberOfPaymentProcessors++; + } + } + + @Inject + public void initUnproxyableTypes( + @Any Instance<UnproxyableType> unproxyableTypes) { + for (UnproxyableType p : unproxyableTypes) { + System.out.println("UnproxyableType #" + numberOfUnproxyableTypes + + ":" + p); + numberOfUnproxyableTypes++; + } + } + + public boolean testInjection() { + System.out.println("# of Payment processors:" + + numberOfPaymentProcessors); + System.out.println("# of Unproxyable types:" + + numberOfUnproxyableTypes); + System.out.println("mock payment procssor:" + pp); + + return (numberOfPaymentProcessors == 5) + // Async, Sync, Cheque, + // ReliableCash, + // MockPaymentProcessor + && (numberOfUnproxyableTypes == 2) + // UnproxyableFinalClass + // UnproxyableTypeWithNoPublicNullConstructor + && (pp instanceof MockPaymentProcessor); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/servlets/ProgrammaticLookupServlet.java b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/servlets/ProgrammaticLookupServlet.java new file mode 100644 index 0000000..a24772c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/programmatic-lookup/servlet/test/servlets/ProgrammaticLookupServlet.java
@@ -0,0 +1,184 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlets; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Iterator; + +import javax.enterprise.inject.Any; +import javax.enterprise.inject.Instance; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.artifacts.Asynchronous; +import test.artifacts.ChequePaymentProcessor; +import test.artifacts.MockPaymentProcessor; +import test.artifacts.PayBy; +import test.artifacts.PaymentMethod; +import test.artifacts.PaymentProcessor; +import test.artifacts.Synchronous; +import test.artifacts.TestApplicationScopedBean; +import test.artifacts.TestSessionScopedBean; +import test.artifacts.UnproxyableType; +import test.beans.BeanToTestProgrammaticLookup; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }, initParams = { + @WebInitParam(name = "n1", value = "v1"), + @WebInitParam(name = "n2", value = "v2") }) +public class ProgrammaticLookupServlet extends HttpServlet { + + @Inject + BeanToTestProgrammaticLookup tb; + + @Inject + @Synchronous + Instance<PaymentProcessor> synchronousPaymentProcessor; + + @Inject + @Asynchronous + Instance<PaymentProcessor> asynchronousPaymentProcessor; + + @Inject + @Any + Instance<PaymentProcessor> anyPaymentProcessors; + + @Inject + @Any + Instance<UnproxyableType> unpnc; + + @Inject + TestApplicationScopedBean tasb; + + @Inject + TestSessionScopedBean tssb; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + ", n2=" + + getInitParameter("n2"); + + if (!tb.testInjection()) + msg += "Alternatives injection and test for availability of other " + + "beans via @Any Failed"; + + boolean specifiedAtInjectionPoint = synchronousPaymentProcessor.get() instanceof MockPaymentProcessor + && asynchronousPaymentProcessor.get() instanceof MockPaymentProcessor; + if (!specifiedAtInjectionPoint) + msg += "Qualifier based(specified at injection point) programmatic " + + "injection into Servlet Failed"; + + PaymentProcessor pp1, pp2; + // using anonymous inner classes + pp1 = anyPaymentProcessors.select( + new AnnotationLiteral<Asynchronous>() { + }).get(); + pp2 = anyPaymentProcessors.select( + new AnnotationLiteral<Synchronous>() { + }).get(); + boolean specifiedQualifierDynamically = pp1 instanceof MockPaymentProcessor + && pp2 instanceof MockPaymentProcessor; + if (!specifiedQualifierDynamically) + msg += "Qualifier based(specified dynamically through " + + "instance.select()) programmatic injection into Servlet Failed"; + + // using concrete implementations of the annotation type + pp1 = anyPaymentProcessors.select(new AsynchronousQualifier()).get(); + pp2 = anyPaymentProcessors.select(new SynchronousQualifier()).get(); + boolean specifiedQualifierDynamicallyThroughConcreteTypes = pp1 instanceof MockPaymentProcessor + && pp2 instanceof MockPaymentProcessor; + if (!specifiedQualifierDynamicallyThroughConcreteTypes) + msg += "Qualifier based(specified dynamically through " + + "instance.select() through a concrete annotation type " + + "implementation) programmatic injection into Servlet Failed"; + + PaymentProcessor chequePaymentProcessor = anyPaymentProcessors + .select(new ChequeQualifier()).get(); + boolean specifiedQualifierWithMembersDynamicallyThroughConcreteTypes = chequePaymentProcessor instanceof ChequePaymentProcessor; + if (!specifiedQualifierWithMembersDynamicallyThroughConcreteTypes) + msg += "Qualifier with members based(specified dynamically through " + + "instance.select() through a concrete annotation type " + + "implementation) programmatic injection into Servlet Failed"; + + // Ensure unproxabletypes are injectable + for (Iterator iterator = unpnc.iterator(); iterator.hasNext();) { + UnproxyableType type = (UnproxyableType) iterator.next(); + if (type == null) { + System.out.println("UnproxyableType is null " + + type.getClass()); + msg += "Unproxyable type (class with non-public null constructor) Injection failed"; + } + } + + // Ensure application-scoped bean has a reference to a session-scoped + // bean + // via a client proxy + TestSessionScopedBean tsb = tasb.getSessionScopedBean(); + boolean isAClientProxy = testIsClientProxy(tsb, + TestSessionScopedBean.class); + if (!isAClientProxy) + msg += "Session scoped bean is not a proxy class"; + + writer.write("initParams: " + msg + "\n"); + } + + // Tests if the bean instance is a client proxy + private boolean testIsClientProxy(Object beanInstance, Class beanType) { + boolean isSameClass = beanInstance.getClass().equals(beanType); + boolean isProxyAssignable = beanType.isAssignableFrom(beanInstance + .getClass()); + System.out.println(beanInstance + "whose class is " + + beanInstance.getClass() + " is same class of " + beanType + + " = " + isSameClass); + System.out.println(beanType + " is assignable from " + beanInstance + + " = " + isProxyAssignable); + boolean isAClientProxy = !isSameClass && isProxyAssignable; + return isAClientProxy; + } + + // concrete implementations of the qualifier annotation types to be used in + // Instance.select() + class AsynchronousQualifier extends AnnotationLiteral<Asynchronous> + implements Asynchronous { + } + + class SynchronousQualifier extends AnnotationLiteral<Synchronous> + implements Synchronous { + } + + class ChequeQualifier extends AnnotationLiteral<PayBy> implements PayBy { + @Override + public PaymentMethod value() { + return PaymentMethod.CHEQUE; + } + + @Override + public String comment() { + return ""; + } + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/README b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/README new file mode 100644 index 0000000..5c7e1c2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/README
@@ -0,0 +1,7 @@ +Test +- Use Qualifier annotations to specify exactly which bean instnace should be injected +- @Any +- @Default +- Constructor, Initializer Method and Field injection of Qualified Bean types +- Qualifiers with members, non-binding members +- Multiple Qualifiers
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/WebTest.java new file mode 100644 index 0000000..64c7643 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/WebTest.java
@@ -0,0 +1,105 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "qualifier-tests"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Testing Qualifiers"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + System.out.println("TESTNAME " + TEST_NAME); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/build.properties b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/build.properties new file mode 100644 index 0000000..0a1ecbd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi-qualifiers"/> +<property name="appname" value="${module}-servlet-annotation"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/build.xml b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/build.xml new file mode 100644 index 0000000..c0d904d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/QualifierServlet.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/QualifierServlet.java new file mode 100644 index 0000000..2123b1e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/QualifierServlet.java
@@ -0,0 +1,86 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.artifacts.Asynchronous; +import test.artifacts.AsynchronousPaymentProcessor; +import test.artifacts.PaymentProcessor; +import test.artifacts.Synchronous; +import test.artifacts.SynchronousPaymentProcessor; +import test.beans.BeanToTestAny; +import test.beans.BeanToTestConstructorInjection; +import test.beans.BeanToTestInitializerMethodInjection; +import test.beans.BeanToTestMultipleQualifiers; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }, initParams = { + @WebInitParam(name = "n1", value = "v1"), + @WebInitParam(name = "n2", value = "v2") }) +public class QualifierServlet extends HttpServlet { + + @Inject + BeanToTestInitializerMethodInjection tb; + + @Inject + BeanToTestConstructorInjection tb2; + + @Inject + BeanToTestAny tb3; + + @Inject + BeanToTestMultipleQualifiers tb4; + + @Inject + @Synchronous + PaymentProcessor synchronousPaymentProcessor; + @Inject + @Asynchronous + PaymentProcessor asynchronousPaymentProcessor; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + ", n2=" + + getInitParameter("n2"); + if (tb == null) + msg += "Bean injection into Servlet failed"; + + boolean qualifierTestSuccess = synchronousPaymentProcessor instanceof SynchronousPaymentProcessor + && asynchronousPaymentProcessor instanceof AsynchronousPaymentProcessor; + if (!qualifierTestSuccess) + msg += "Qualifier based injection into Servlet Failed"; + if (!tb.testInjection()) + msg += "Qualifier based injection into BeanToTestInitializerMethodInjection (initializer method injection) Failed"; + if (!tb2.testInjection()) + msg += "Qualifier based injection into BeanToTestConstructorMethodInjection (constructor method injection) Failed"; + if (!tb3.testInjection()) + msg += "Qualifier based @Any injection into BeanToTestAny Failed"; + if (!tb4.testInjection()) + msg += "Multiple qualifiers test failed"; + + writer.write("initParams: " + msg + "\n"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/Asynchronous.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/Asynchronous.java new file mode 100644 index 0000000..ca0dd14 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/Asynchronous.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) + +public @interface Asynchronous { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/AsynchronousPaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/AsynchronousPaymentProcessor.java new file mode 100644 index 0000000..9e0c62b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/AsynchronousPaymentProcessor.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +@Asynchronous +public class AsynchronousPaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/CashReliablePaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/CashReliablePaymentProcessor.java new file mode 100644 index 0000000..a72f9db --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/CashReliablePaymentProcessor.java
@@ -0,0 +1,27 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +@PayBy(value=PaymentMethod.CASH) @Reliable +//To test multiple qualifiers +public class CashReliablePaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/ChequePaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/ChequePaymentProcessor.java new file mode 100644 index 0000000..9fe824b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/ChequePaymentProcessor.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +@PayBy(PaymentMethod.CHEQUE) +public class ChequePaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/PayBy.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/PayBy.java new file mode 100644 index 0000000..179aca6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/PayBy.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.enterprise.util.Nonbinding; +import javax.inject.Qualifier; + +@Qualifier +@Target( { TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface PayBy { + PaymentMethod value() default PaymentMethod.CHEQUE; + + @Nonbinding + String comment() default ""; // A Non-Binding member. Is ignored during + // dependency resolution +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/PaymentMethod.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/PaymentMethod.java new file mode 100644 index 0000000..82e7eb6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/PaymentMethod.java
@@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +public enum PaymentMethod { + CHEQUE, CASH +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/PaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/PaymentProcessor.java new file mode 100644 index 0000000..3e25336 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/PaymentProcessor.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +public interface PaymentProcessor { + boolean processPayment(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/Reliable.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/Reliable.java new file mode 100644 index 0000000..8ece693 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/Reliable.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Reliable { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/Synchronous.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/Synchronous.java new file mode 100644 index 0000000..b4c5d7e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/Synchronous.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +import static java.lang.annotation.ElementType.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({TYPE, METHOD, PARAMETER, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Synchronous { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/SynchronousPaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/SynchronousPaymentProcessor.java new file mode 100644 index 0000000..921cd3e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/artifacts/SynchronousPaymentProcessor.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; +@Synchronous +public class SynchronousPaymentProcessor implements PaymentProcessor { + + @Override + public boolean processPayment() { + return false; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/beans/BeanToTestAny.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/beans/BeanToTestAny.java new file mode 100644 index 0000000..688b54d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/beans/BeanToTestAny.java
@@ -0,0 +1,40 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.inject.Any; +import javax.enterprise.inject.Instance; +import javax.inject.Inject; + +import test.artifacts.PaymentProcessor; + +public class BeanToTestAny { + private int numberOfPaymentProcessors = 0; + + @Inject + public void init(@Any Instance<PaymentProcessor> payInstances) { + for (PaymentProcessor p : payInstances) { + System.out.println("Payment Processor #" + + numberOfPaymentProcessors + ":" + p); + numberOfPaymentProcessors++; + } + } + + public boolean testInjection() { + return (numberOfPaymentProcessors == 4); //Async, Sync, Cheque, ReliableCash + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/beans/BeanToTestConstructorInjection.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/beans/BeanToTestConstructorInjection.java new file mode 100644 index 0000000..620cc44 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/beans/BeanToTestConstructorInjection.java
@@ -0,0 +1,44 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; + +import test.artifacts.Asynchronous; +import test.artifacts.AsynchronousPaymentProcessor; +import test.artifacts.PaymentProcessor; +import test.artifacts.Synchronous; +import test.artifacts.SynchronousPaymentProcessor; + + +public class BeanToTestConstructorInjection { + private PaymentProcessor syncPay; + private PaymentProcessor asyncPay; + + @Inject + public BeanToTestConstructorInjection(@Synchronous PaymentProcessor syncPay, + @Asynchronous PaymentProcessor asyncPay) { + this.syncPay = syncPay; + this.asyncPay = asyncPay; + } + + public boolean testInjection(){ + return (syncPay instanceof SynchronousPaymentProcessor && + asyncPay instanceof AsynchronousPaymentProcessor); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/beans/BeanToTestInitializerMethodInjection.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/beans/BeanToTestInitializerMethodInjection.java new file mode 100644 index 0000000..9562fd6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/beans/BeanToTestInitializerMethodInjection.java
@@ -0,0 +1,42 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; + +import test.artifacts.Asynchronous; +import test.artifacts.AsynchronousPaymentProcessor; +import test.artifacts.PaymentProcessor; +import test.artifacts.Synchronous; +import test.artifacts.SynchronousPaymentProcessor; + +public class BeanToTestInitializerMethodInjection { + private PaymentProcessor syncPay; + private PaymentProcessor asyncPay; + + @Inject + public void setPaymentProcessor(@Synchronous PaymentProcessor syncPay, + @Asynchronous PaymentProcessor asyncPay) { + this.syncPay = syncPay; + this.asyncPay = asyncPay; + } + + public boolean testInjection(){ + return (syncPay instanceof SynchronousPaymentProcessor && + asyncPay instanceof AsynchronousPaymentProcessor); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/beans/BeanToTestMultipleQualifiers.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/beans/BeanToTestMultipleQualifiers.java new file mode 100644 index 0000000..6e94fa1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/beans/BeanToTestMultipleQualifiers.java
@@ -0,0 +1,37 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; + +import test.artifacts.CashReliablePaymentProcessor; +import test.artifacts.PayBy; +import test.artifacts.PaymentMethod; +import test.artifacts.PaymentProcessor; +import test.artifacts.Reliable; + +public class BeanToTestMultipleQualifiers { + PaymentProcessor pp; + @Inject + public void init(@Reliable @PayBy(PaymentMethod.CASH) PaymentProcessor cashProcessor) { + this.pp = cashProcessor; + } + + public boolean testInjection() { + return ((this.pp != null) && (this.pp instanceof CashReliablePaymentProcessor)); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/beans/BeanToTestQualifierWithMembers.java b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/beans/BeanToTestQualifierWithMembers.java new file mode 100644 index 0000000..14c8550 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/qualifiers/servlet/test/beans/BeanToTestQualifierWithMembers.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; + +import test.artifacts.ChequePaymentProcessor; +import test.artifacts.PayBy; +import test.artifacts.PaymentMethod; +import test.artifacts.PaymentProcessor; + +public class BeanToTestQualifierWithMembers { + @Inject + @PayBy(value = PaymentMethod.CHEQUE, comment = "Test Comment") + PaymentProcessor pp; + + public boolean testInjection() { + return pp instanceof ChequePaymentProcessor; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/report.xml b/appserver/tests/appserv-tests/devtests/cdi/report.xml new file mode 100644 index 0000000..dde5850 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/report.xml
@@ -0,0 +1,42 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<property name="stylesheet" value="${env.APS_HOME}/config/j2eeReporter.xsl" /> +<property name="xmlfile" value="${env.APS_HOME}/test_resultsValid.xml" /> +<property name="htmlfile" value="${env.APS_HOME}/test_results.html" /> + +<target name="report"> +<echo message="Comparing results with expected results"/> + + + <xslt style="${stylesheet}" + in="${xmlfile}" + out="${htmlfile}" + basedir="." + destdir="."/> + <antcall target="report-sh"/> + <!-- + <ant dir="${env.APS_HOME}/util/filediff" target="modifyReport"/> + --> +</target> + +<target name="report-sh"> + <exec executable="sh"> + <arg value="./resultCount.sh"/> + </exec> +</target>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/resultCount.sh b/appserver/tests/appserv-tests/devtests/cdi/resultCount.sh new file mode 100755 index 0000000..f3d7be7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/resultCount.sh
@@ -0,0 +1,51 @@ +#!/bin/sh +# +# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + + +#FILE=$APS_HOME/devtests/cdi/cdi.output +FILE=$APS_HOME/test_resultsValid.xml +echo "input file=$FILE" + +TOTAL=119 +PASSED=`grep "\"pass\"" $FILE | wc -l` +FAILED=`grep "\"fail\"" $FILE | wc -l` +TOTAL_RUN=`expr $PASSED + $FAILED ` +DNR=`expr $TOTAL - $TOTAL_RUN ` + +echo "" +echo "************************" +echo "PASSED= $PASSED" +echo "------------ =========" +echo "FAILED= $FAILED" +echo "------------ =========" +echo "DID NOT RUN= $DNR" +echo "------------ =========" +echo "Total Expected=$TOTAL" +echo "************************" +echo "" + +echo "************************">>$APS_HOME/devtests/cdi/count.txt; +date>>$APS_HOME/devtests/cdi/count.txt; +echo "-----------------------">>$APS_HOME/devtests/cdi/count.txt; +echo "PASSED= $PASSED">>$APS_HOME/devtests/cdi/count.txt; +echo "------------ =========">>$APS_HOME/devtests/cdi/count.txt; +echo "FAILED= $FAILED">>$APS_HOME/devtests/cdi/count.txt; +echo "------------ =========">>$APS_HOME/devtests/cdi/count.txt; +echo "DID NOT RUN= $DNR">>$APS_HOME/devtests/cdi/count.txt; +echo "------------ =========">>$APS_HOME/devtests/cdi/count.txt; +echo "Total Expected=$TOTAL">>$APS_HOME/devtests/cdi/count.txt; +echo "************************">>$APS_HOME/devtests/cdi/count.txt;
diff --git a/appserver/tests/appserv-tests/devtests/cdi/run_test.sh b/appserver/tests/appserv-tests/devtests/cdi/run_test.sh new file mode 100755 index 0000000..7b90362 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/run_test.sh
@@ -0,0 +1,80 @@ +#!/bin/bash -ex +# +# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + +test_run(){ + #Fix for false positive + echo "<property name=\"libraries\" value=\"' '\"/>" >> smoke-tests/simple-wab-with-cdi/build.properties + find . -name "RepRunConf.txt" | xargs rm -f + rm -rf *.output alltests.res $APS_HOME/test_results* + # Run the tests + set +e + ant clean + $S1AS_HOME/bin/asadmin start-domain + $S1AS_HOME/bin/asadmin start-database + ant $TARGET | tee $TEST_RUN_LOG + $S1AS_HOME/bin/asadmin stop-domain + $S1AS_HOME/bin/asadmin stop-database + set -e +} + +get_test_target(){ + case $1 in + cdi_all ) + TARGET=all + export TARGET;; + esac + +} + + +run_test_id(){ + source `dirname $0`/../../../common_test.sh + kill_process + delete_gf + download_test_resources glassfish.zip version-info.txt + unzip_test_resources $WORKSPACE/bundles/glassfish.zip + cd `dirname $0` + test_init + get_test_target $1 + test_run + check_successful_run + generate_junit_report $1 + change_junit_report_class_names +} + +post_test_run(){ + copy_test_artifects + upload_test_results + delete_bundle + cd - +} + + +list_test_ids(){ + echo cdi_all +} + +OPT=$1 +TEST_ID=$2 + +case $OPT in + list_test_ids ) + list_test_ids;; + run_test_id ) + trap post_test_run EXIT + run_test_id $TEST_ID ;; +esac
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/build.xml b/appserver/tests/appserv-tests/devtests/cdi/scopes/build.xml new file mode 100644 index 0000000..7b3acdd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/build.xml
@@ -0,0 +1,105 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<project name="scopes-test" default="usage" basedir="."> + + <property name="scopes-target" value="all"/> + + <target name="run-test"> + <antcall target="scopes"> + <param name="scopes-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="scopes"> + <param name="scopes-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="scopes"> + <param name="scopes-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="scopes"> + <param name="scopes-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="scopes"> + <param name="scopes-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="scopes"> + <param name="scopes-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="scopes"> + <param name="scopes-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="scopes"> + <param name="scopes-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="scopes"> + <param name="scopes-target" value="run"/> + </antcall> + </target> + + <target name="scopes"> + <record name="scopes.output" action="start" /> + <ant dir="dependent-scope" target="${scopes-target}"/> + <ant dir="new-qualifier" target="${scopes-target}"/> + <!-- + Not running until + https://issues.jboss.org/browse/WELD-1345 is fixed. + In 1.1.10.Final the test passes. + In 2.0 Beta it fails. + --> + <ant dir="request-and-application-scope-ejb-mdb" target="${scopes-target}"/> + <ant dir="singleton-scope" target="${scopes-target}"/> + <record name="scopes.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant all (Executes all the scopes tests) + ant clean (cleans all the scopes tests) + ant build (builds all the scopes tests) + ant setup (sets up all resources for scopes tests) + ant deploy (deploys all the scopes apps) + ant run (Executes all the scopes tests) + ant undeploy (undeploys all the scopes apps) + ant unsetup (unsets all resources for scopes tests) + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/README b/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/README new file mode 100644 index 0000000..d1d0427 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/README
@@ -0,0 +1,5 @@ +Test that Dependent scoped +- bean is instantiated once per injection point +- don't have a proxy +- beans injected across two different injection points or differnt clients are +not the same
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/WebTest.java new file mode 100644 index 0000000..ff0180a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/WebTest.java
@@ -0,0 +1,103 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "cdi-scopes-dependent"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/build.properties b/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/build.properties new file mode 100644 index 0000000..c1893f3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-dependent-scope"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/build.xml b/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/build.xml new file mode 100644 index 0000000..83ad666 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/servlet/test/beans/TestDependentScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/servlet/test/beans/TestDependentScopedBean.java new file mode 100644 index 0000000..b978e60 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/servlet/test/beans/TestDependentScopedBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + + + +//Simple TestBean to test CDI dependent pseudo-scope. +//note: NOT serializable. So special care must be taken when injected +//into session scoped or conversation scoped bean +public class TestDependentScopedBean { + private static int instantiationCounter = 0; + + public TestDependentScopedBean(){ + instantiationCounter++; + } + + public int getInstancesCount(){ + return this.instantiationCounter; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/servlet/test/beans/TestRequestScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/servlet/test/beans/TestRequestScopedBean.java new file mode 100644 index 0000000..bcec05a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/servlet/test/beans/TestRequestScopedBean.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; + +@RequestScoped +public class TestRequestScopedBean { + + @Inject + private TestDependentScopedBean tdsb; + + public TestDependentScopedBean getDependentScopedBean(){ + return this.tdsb; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/servlet/test/servlets/DependentScopeTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/servlet/test/servlets/DependentScopeTestServlet.java new file mode 100644 index 0000000..d166a62 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/dependent-scope/servlet/test/servlets/DependentScopeTestServlet.java
@@ -0,0 +1,100 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlets; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.enterprise.inject.spi.BeanManager; +import javax.inject.Inject; +import javax.naming.InitialContext; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestDependentScopedBean; +import test.beans.TestRequestScopedBean; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class DependentScopeTestServlet extends HttpServlet { + @Inject + TestDependentScopedBean tb; + @Inject + TestDependentScopedBean anotherInjectedDependentInstance; + + @Inject + TestRequestScopedBean trsb; + @Inject + BeanManager bm; + BeanManager bm1; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + if (tb == null) + msg += "Singleton pseudo-scope Bean injection into Servlet failed"; + if (bm == null) + msg += "BeanManager Injection via @Inject failed"; + try { + bm1 = (BeanManager) ((new InitialContext()) + .lookup("java:comp/BeanManager")); + } catch (Exception ex) { + ex.printStackTrace(); + msg += "BeanManager Injection via component environment lookup failed"; + } + if (bm1 == null) + msg += "BeanManager Injection via component environment lookup failed"; + if (areInjectecedInstancesEqual(tb, anotherInjectedDependentInstance)) + msg += "Dependent scoped beans across two different injections points must not point to the same bean instance"; + if (areInjectecedInstancesEqual(tb, trsb.getDependentScopedBean())) + msg += "Dependent scoped beans across two different clients must not point to the same bean instance"; + + // 2 to account for the two injections + // in this servlet and 1 more for the injection in TestRequestScopedBean + if (tb.getInstancesCount() != 3) + msg += "Dependent scoped bean created more than the expected number of times"; + + if (testIsClientProxy(tb, TestDependentScopedBean.class)) + msg += "Beans with dependent pseudo-scope should not have a proxy"; + + writer.write(msg + "\n"); + } + + private boolean areInjectecedInstancesEqual(Object o1, Object o2) { + return (o1.equals(o2)) & (o1 == o2); + } + + // Tests if the bean instance is a client proxy + private boolean testIsClientProxy(Object beanInstance, Class beanType) { + boolean isSameClass = beanInstance.getClass().equals(beanType); + boolean isProxyAssignable = beanType.isAssignableFrom(beanInstance + .getClass()); + System.out.println(beanInstance + "whose class is " + + beanInstance.getClass() + " is same class of " + beanType + + " = " + isSameClass); + System.out.println(beanType + " is assignable from " + beanInstance + + " = " + isProxyAssignable); + boolean isAClientProxy = !isSameClass && isProxyAssignable; + return isAClientProxy; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/README b/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/README new file mode 100644 index 0000000..ca575bc --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/README
@@ -0,0 +1,4 @@ +Test that injection points annotated with @New qualifer +- results in a new RequestScoped bean +- is not equal to the actual request scoped bean +- ensure that no more than valid # of instantiations of the request scoped bean happens
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/WebTest.java new file mode 100644 index 0000000..c873c03 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/WebTest.java
@@ -0,0 +1,108 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "cdi-new-qualifier"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/build.properties b/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/build.properties new file mode 100644 index 0000000..eafeb8f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-new-qualifier"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/build.xml b/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/build.xml new file mode 100644 index 0000000..83ad666 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/servlet/test/beans/TestRequestScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/servlet/test/beans/TestRequestScopedBean.java new file mode 100644 index 0000000..e854645 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/servlet/test/beans/TestRequestScopedBean.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@RequestScoped +public class TestRequestScopedBean { + private static int instantiationCount = 0; + + public TestRequestScopedBean(){ + instantiationCount++; + } + + public int getInstantiationCount(){ + System.out.println("Instances of TestRequestScopedBean=" + instantiationCount); + return this.instantiationCount; + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/servlet/test/servlets/NewQualifierTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/servlet/test/servlets/NewQualifierTestServlet.java new file mode 100644 index 0000000..f47409e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/new-qualifier/servlet/test/servlets/NewQualifierTestServlet.java
@@ -0,0 +1,105 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlets; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.enterprise.inject.New; +import javax.enterprise.inject.Instance; +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestRequestScopedBean; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class NewQualifierTestServlet extends HttpServlet { + + @Inject + TestRequestScopedBean trsb; + + @Inject + TestRequestScopedBean anotherRefToRequestScopedBean; + + @Inject + @New + TestRequestScopedBean newRequestScopedBean; + + @Inject + @New + Instance<TestRequestScopedBean> newRequestScopedBeanProgrammaticLookup; + + @Inject + @New(TestRequestScopedBean.class) + Instance<TestRequestScopedBean> newRequestScopedBeanProgrammaticLookup2; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + // 2 to account for the two injections in this servlet + // XXX: For some weld instantiates the request scoped bean thrice(twice + // during + // the instantiation of the servlet and once during the servicing of the + // servlet request + if (!(trsb.getInstantiationCount() == 3)) + msg += "Request scoped bean created more than the expected number of times"; + + if (!areInjectecedInstancesEqual(trsb, anotherRefToRequestScopedBean)) + msg += "Two references to the same request scoped bean are not equal"; + + if (areInjectecedInstancesEqual(trsb, newRequestScopedBean)) + msg += "Request scoped Bean injected with @New qualifier must not be equal to the normal Request scoped bean"; + + if (!testIsClientProxy(trsb, TestRequestScopedBean.class)) + msg += "Request scoped beans must be injected as a client proxy"; + + if(newRequestScopedBeanProgrammaticLookup.get() == null) + msg += "A new instance of Request Scoped Bean obtained through programmatic lookup failed"; + + if(newRequestScopedBeanProgrammaticLookup2.get() == null) + msg += "A new(complex type specification scenario) instance of Request Scoped Bean obtained through programmatic lookup failed"; + + writer.write(msg + "\n"); + } + + private boolean areInjectecedInstancesEqual(Object o1, Object o2) { + return (o1.equals(o2)) & (o1 == o2); + } + + // Tests if the bean instance is a client proxy + private boolean testIsClientProxy(Object beanInstance, Class beanType) { + boolean isSameClass = beanInstance.getClass().equals(beanType); + boolean isProxyAssignable = beanType.isAssignableFrom(beanInstance + .getClass()); + System.out.println(beanInstance + "whose class is " + + beanInstance.getClass() + " is same class of " + beanType + + " = " + isSameClass); + System.out.println(beanType + " is assignable from " + beanInstance + + " = " + isProxyAssignable); + boolean isAClientProxy = !isSameClass && isProxyAssignable; + return isAClientProxy; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/README b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/README new file mode 100644 index 0000000..1d7fbc4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/README
@@ -0,0 +1,8 @@ +Test +- availability of application and request scoped beans in + - invocation of EJB remote methods + - invocation of MDB message delivery + - invocation of EJB timer timeout methods + +- TODO: check availability in invocation of + - async EJB methods, MDB (Connector), WS HAndler
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/build.properties b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/build.properties new file mode 100644 index 0000000..d64848e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/build.properties
@@ -0,0 +1,37 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi-hello-mdb"/> +<property name="appname" value="${module}"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="test.client" + value="Client"/> +<property name="simple.client" value="com.sun.s1asdev.cdi.hello.mdb.client.Client"/> +<property name="application.xml" value="descriptor/application.xml"/> +<property name="sun-application.xml" value="descriptor/sun-application.xml"/> +<property name="ejb-jar.xml" value="descriptor/ejb-jar.xml"/> +<property name="sun-ejb-jar.xml" value="descriptor/sun-ejb-jar.xml"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="application-client.xml" + value="descriptor/application-client.xml"/> +<property name="sun-application-client.xml" + value="descriptor/sun-application-client.xml"/> +<property name="appclientjar.files" value="${build.classes.dir}"/> +<property name="appclient.jar" value="${assemble.dir}/${appname}-client.jar"/> +<property name="app.type" value="application"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/build.xml b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/build.xml new file mode 100644 index 0000000..9f1d49a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/build.xml
@@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="cdi-hello-mdbApp" default="usage" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + + <target name="all" depends="clean,build,create-resources,deploy,run,undeploy,delete-resources"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="src"/> + </antcall> + <antcall target="compile-common"> + <param name="src" value="client"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <antcall target="build-ear-common"> + <param name="ejbjar.classes" + value="**/*Bean*.class,**/*Hello*" /> + <param name="appclientjar.classes" + value="**/*Client*.class, test/ejb/session/HelloSless*.class" /> + </antcall> + </target> + + <target name="deploy" + depends="init-common"> + <antcall target="deploy-common"/> + </target> + + <target name="create-resources" depends="init-common"> + <antcall target="asadmin-batch-common"> + <param name="asadmin.file" value="create_resources.asadmin"/> + </antcall> + </target> + + <target name="delete-resources" depends="init-common"> + <antcall target="asadmin-batch-common"> + <param name="asadmin.file" value="delete_resources.asadmin"/> + </antcall> + </target> + + <target name="run" depends="init-common"> + <antcall target="runclient-common"> + <param name="appclient.application.args" value="1"/> + </antcall> + </target> + + <target name="run_standaloneclient" depends="init-common"> + <java fork="on" + failonerror="true" + classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/modules/javax.jms.jar:${env.S1AS_HOME}/lib/gf-client.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar" + classname="${simple.client}"> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + <echo> + ant create-resources Create all destinations and connection factories + ant delete-resources Delete all destinations and connection factories + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/client/Client.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/client/Client.java new file mode 100644 index 0000000..085a41f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/client/Client.java
@@ -0,0 +1,168 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.s1asdev.cdi.hello.mdb.client; + +import javax.annotation.Resource; +import javax.ejb.EJB; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.QueueConnection; +import javax.jms.QueueConnectionFactory; +import javax.jms.QueueReceiver; +import javax.jms.QueueSender; +import javax.jms.QueueSession; +import javax.jms.Session; +import javax.jms.TextMessage; +import javax.naming.InitialContext; + +import test.ejb.session.HelloSless; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +public class Client { + + // in milli-seconds + private static long TIMEOUT = 90000; + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "request-and-application-scope-ejb-mdb"; + + public static void main(String[] args) { + Client client = new Client(args); + + stat.addDescription("cdi-hello-mdb"); + client.doTest(); + stat.printSummary("cdi-hello-mdbID"); + System.exit(0); + } + + @Resource(name = "FooCF", mappedName = "jms/cdi_hello_mdb_QCF") + private static QueueConnectionFactory queueConFactory; + + @Resource(name = "MsgBeanQueue", mappedName = "jms/cdi_hello_mdb_InQueue") + private static javax.jms.Queue msgBeanQueue; + + @Resource(name = "ClientQueue", mappedName = "foo") + private static javax.jms.Queue clientQueue; + + private QueueConnection queueCon; + private QueueSession queueSession; + private QueueSender queueSender; + private QueueReceiver queueReceiver; + + // Only one target bean with Remote intf SlessSub so no linking info + // necessary + private static @EJB + HelloSless helloStatelessRemoteBean; + + private int numMessages = 2; + + public Client(String[] args) { + + if (args.length == 1) { + numMessages = new Integer(args[0]).intValue(); + } + + } + + private void doTest() { + try { + if (queueConFactory == null) { + + System.out.println("Java SE mode..."); + InitialContext ic = new InitialContext(); + queueConFactory = (javax.jms.QueueConnectionFactory) ic + .lookup("jms/cdi_hello_mdb_QCF"); + msgBeanQueue = (javax.jms.Queue) ic + .lookup("jms/cdi_hello_mdb_InQueue"); + clientQueue = (javax.jms.Queue) ic + .lookup("jms/cdi_hello_mdb_OutQueue"); + + } + + setup(); + doTest(numMessages); + stat.addStatus(TEST_NAME, stat.PASS); + } catch (Throwable t) { + stat.addStatus(TEST_NAME, stat.FAIL); + t.printStackTrace(); + } finally { + cleanup(); + } + } + + private void setup() throws Exception { + queueCon = queueConFactory.createQueueConnection(); + queueSession = queueCon.createQueueSession(false, + Session.AUTO_ACKNOWLEDGE); + // Producer will be specified when actual msg is sent. + queueSender = queueSession.createSender(null); + queueReceiver = queueSession.createReceiver(clientQueue); + queueCon.start(); + } + + private void cleanup() { + try { + if (queueCon != null) { + queueCon.close(); + } + } catch (Throwable t) { + t.printStackTrace(); + } + } + + private void sendMsgs(javax.jms.Queue queue, Message msg, int num) + throws JMSException { + for (int i = 0; i < num; i++) { + System.out.println("Sending message " + i + " to " + queue + + " at time " + System.currentTimeMillis()); + queueSender.send(queue, msg); + System.out.println("Sent message " + i + " to " + queue + + " at time " + System.currentTimeMillis()); + } + } + + private void doTest(int num) throws Exception { + + Destination dest = msgBeanQueue; + + Message message = queueSession.createTextMessage("foo"); + + message.setBooleanProperty("flag", true); + message.setIntProperty("num", 2); + sendMsgs((javax.jms.Queue) dest, message, num); + + System.out.println("remote bean:" + helloStatelessRemoteBean); + String response = helloStatelessRemoteBean.hello(); + if (!response.equals("hello")){ + System.out.println("Expected hello, but instead got" + response); + stat.addStatus(TEST_NAME, stat.FAIL); + } + + System.out.println("Waiting for queue message"); + Message recvdmessage = queueReceiver.receive(TIMEOUT); + if (recvdmessage != null) { + System.out.println("Received message : " + + ((TextMessage) recvdmessage).getText()); + } else { + System.out.println("timeout after " + TIMEOUT + " seconds"); + throw new JMSException("timeout" + TIMEOUT + " seconds"); + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/client/MANIFEST.MF b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/client/MANIFEST.MF new file mode 100644 index 0000000..1ed692b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/client/MANIFEST.MF
@@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Created-By: 1.4.0-beta3 (Sun Microsystems Inc.) +Main-Class: com.sun.s1asdev.cdi.hello.mdb.client.Client +Class-Path: reporter.jar
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/create_resources.asadmin b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/create_resources.asadmin new file mode 100644 index 0000000..78a6f43 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/create_resources.asadmin
@@ -0,0 +1,5 @@ +create-jms-resource --restype javax.jms.QueueConnectionFactory jms/cdi_hello_mdb_QCF +create-jmsdest --desttype queue cdi_hello_mdb_InQueue +create-jms-resource --restype javax.jms.Queue --property imqDestinationName=cdi_hello_mdb_InQueue jms/cdi_hello_mdb_InQueue +create-jmsdest --desttype queue cdi_hello_mdb_OutQueue +create-jms-resource --restype javax.jms.Queue --property imqDestinationName=cdi_hello_mdb_OutQueue jms/cdi_hello_mdb_OutQueue
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/delete_resources.asadmin b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/delete_resources.asadmin new file mode 100644 index 0000000..69af651 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/delete_resources.asadmin
@@ -0,0 +1,5 @@ +delete-jms-resource jms/cdi_hello_mdb_QCF +delete-jms-resource jms/cdi_hello_mdb_InQueue +delete-jmsdest --desttype queue cdi_hello_mdb_InQueue +delete-jms-resource jms/cdi_hello_mdb_OutQueue +delete-jmsdest --desttype queue cdi_hello_mdb_OutQueue
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/descriptor/application.xml b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/descriptor/application.xml new file mode 100644 index 0000000..448b864 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/descriptor/application.xml
@@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"> + <display-name>cdi-hello-mdbApp</display-name> + <module> + <ejb>cdi-hello-mdb-ejb.jar</ejb> + </module> + <module> + <java>cdi-hello-mdb-client.jar</java> + </module> +</application>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/descriptor/sun-application-client.xml b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/descriptor/sun-application-client.xml new file mode 100644 index 0000000..3cb8ad5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/descriptor/sun-application-client.xml
@@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE sun-application-client PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Application Client 5.0//EN" "http://www.sun.com/software/appserver/dtds/sun-application-client_5_0-0.dtd"> +<sun-application-client> + <message-destination-ref> + <message-destination-ref-name>ClientQueue</message-destination-ref-name> + <jndi-name>jms/cdi_hello_mdb_OutQueue</jndi-name> + </message-destination-ref> +</sun-application-client>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/beans/BeanToTestTimerUse.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/beans/BeanToTestTimerUse.java new file mode 100644 index 0000000..ca77e52 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/beans/BeanToTestTimerUse.java
@@ -0,0 +1,37 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Singleton; + + +//Simple TestBean to test CDI. + +@Singleton +public class BeanToTestTimerUse implements java.io.Serializable{ + private boolean testToCheckIfTimerInvoked = false; + + public void setResult(boolean val) { + this.testToCheckIfTimerInvoked = val; + } + + public boolean getResult() { + return this.testToCheckIfTimerInvoked; + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/beans/TestApplicationScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/beans/TestApplicationScopedBean.java new file mode 100644 index 0000000..aa487ef --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/beans/TestApplicationScopedBean.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.ApplicationScoped; + +//Simple TestBean to test CDI. +@ApplicationScoped +public class TestApplicationScopedBean +{}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/beans/TestRequestScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/beans/TestRequestScopedBean.java new file mode 100644 index 0000000..15a8ea0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/beans/TestRequestScopedBean.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +//Simple TestBean to test CDI. +@RequestScoped +public class TestRequestScopedBean +{}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/mdb/MessageBean.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/mdb/MessageBean.java new file mode 100644 index 0000000..665278f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/mdb/MessageBean.java
@@ -0,0 +1,116 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.mdb; + +import javax.annotation.Resource; +import javax.ejb.EJB; +import javax.ejb.MessageDriven; +import javax.ejb.NoSuchEJBException; +import javax.ejb.TransactionManagement; +import javax.ejb.TransactionManagementType; +import javax.enterprise.inject.spi.BeanManager; +import javax.inject.Inject; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.Queue; +import javax.jms.QueueConnection; +import javax.jms.QueueConnectionFactory; +import javax.jms.QueueSender; +import javax.jms.QueueSession; +import javax.jms.Session; +import javax.jms.TextMessage; + +import test.beans.TestApplicationScopedBean; +import test.beans.TestRequestScopedBean; +import test.ejb.session.Hello1; +import test.ejb.session.Hello2; + +@TransactionManagement(TransactionManagementType.BEAN) +@MessageDriven(mappedName = "jms/cdi_hello_mdb_InQueue", description = "mymessagedriven bean description") +public class MessageBean implements MessageListener { + + @EJB + private Hello1 hello1; + @EJB + private Hello2 hello2; + + @Resource(name = "jms/MyQueueConnectionFactory", mappedName = "jms/cdi_hello_mdb_QCF") + QueueConnectionFactory qcFactory; + + @Resource(mappedName = "jms/cdi_hello_mdb_OutQueue") + Queue clientQueue; + + @Inject + TestApplicationScopedBean tasb; + @Inject + TestRequestScopedBean trsb; + + @Inject BeanManager bm; + + public void onMessage(Message message) { + + QueueConnection connection = null; + try { + + System.out.println("Calling hello1 stateless bean"); + hello1.hello("local ejb3.0 stateless"); + System.out.println("Calling hello2 stateful bean"); + hello2.hello("local ejb3.0 stateful"); + hello2.removeMethod(); + try { + hello2.hello("this call should not go through"); + throw new Exception("bean should have been removed " + + "after removeMethod()"); + } catch (NoSuchEJBException e) { + System.out.println("Successfully caught EJBException after " + + " accessing removed SFSB"); + } + + System.out.println("Application scoped test bean:"+ tasb); + System.out.println("Request scoped test bean:"+ trsb); + if (tasb == null) + throw new Exception( + "Injection of application scoped Bean in MDB failed"); + if (trsb == null) + throw new Exception( + "Injection of request scoped Bean in MDB failed"); + + connection = qcFactory.createQueueConnection(); + QueueSession session = connection.createQueueSession(false, + Session.AUTO_ACKNOWLEDGE); + QueueSender sender = session.createSender(clientQueue); + TextMessage tmessage = session.createTextMessage(); + tmessage.setText("mdb() invoked"); + System.out.println("Sending message"); + sender.send(tmessage); + System.out.println("message sent"); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (connection != null) { + connection.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/Hello1.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/Hello1.java new file mode 100644 index 0000000..6773b31 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/Hello1.java
@@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.session; + +public interface Hello1 { + + public void hello(String s); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/Hello2.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/Hello2.java new file mode 100644 index 0000000..0a4d4b9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/Hello2.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.session; + +public interface Hello2 extends java.io.Serializable { + + public void hello(String s); + + public void removeMethod(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/HelloSless.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/HelloSless.java new file mode 100644 index 0000000..37c0953 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/HelloSless.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.session; + +//Remote business interface + +public interface HelloSless +{ + public String hello(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/HelloStateful.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/HelloStateful.java new file mode 100644 index 0000000..7ef8e89 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/HelloStateful.java
@@ -0,0 +1,42 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.session; + +import javax.ejb.Stateful; +import javax.ejb.Remove; +import javax.annotation.PreDestroy; + +@Stateful(description="my stateful bean description") +public class HelloStateful implements Hello2 { + + private String msg; + + public void hello(String s) { + msg = s; + System.out.println("HelloStateful: " + s); + } + + @Remove public void removeMethod() { + System.out.println("Business method marked with @Remove called in " + + msg); + } + + @PreDestroy public void myPreDestroyMethod() { + System.out.println("PRE-DESTROY callback received in " + msg); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/HelloStateless.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/HelloStateless.java new file mode 100644 index 0000000..f3e09ec --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/HelloStateless.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.session; + +import javax.ejb.Stateless; + +// Hello1 interface is not annotated with @Local. If the +// bean only implements one interface it is assumed to be +// a local business interface. + +@Stateless(description="my stateless bean description") +public class HelloStateless implements Hello1 { + + public void hello(String s) { + System.out.println("HelloStateless: " + s); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/HelloStatelessRemoteBean.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/HelloStatelessRemoteBean.java new file mode 100644 index 0000000..f286061 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/session/HelloStatelessRemoteBean.java
@@ -0,0 +1,64 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.session; + +import javax.annotation.PostConstruct; +import javax.ejb.Remote; +import javax.ejb.Stateless; +import javax.enterprise.inject.spi.BeanManager; +import javax.inject.Inject; + +import test.beans.BeanToTestTimerUse; +import test.beans.TestApplicationScopedBean; +import test.beans.TestRequestScopedBean; + +@Stateless +@Remote( { HelloSless.class }) +public class HelloStatelessRemoteBean implements HelloSless { + + @Inject + TestApplicationScopedBean tasb; + @Inject + TestRequestScopedBean trsb; + + @Inject + BeanManager bm; + + @Inject BeanToTestTimerUse timerBeanTest; + + @PostConstruct + public void afterCreate() { + System.out + .println("In StatelessRemoteBean::afterCreate() marked as PostConstruct"); + } + + public String hello() { + System.out.println("In HelloStatelessRemoteBean:hello()"); + String msg = "hello"; + System.out.println("tasb=" + tasb); + System.out.println("trsb=" + trsb); + if (tasb == null) + msg += "Injection of Application scoped bean in EJB remote method failed"; + if (trsb == null) + msg += "Injection of Request scoped bean in EJB remote method failed"; + + if (!timerBeanTest.getResult()) + msg += "Injection of session scoped bean into EJB timer beans failed"; + + return msg; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/timer/TestEJBTimerBean.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/timer/TestEJBTimerBean.java new file mode 100644 index 0000000..22599dd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/request-and-application-scope-ejb-mdb/src/test/ejb/timer/TestEJBTimerBean.java
@@ -0,0 +1,54 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.ejb.timer; + +import javax.ejb.Schedule; +import javax.ejb.Stateless; +import javax.ejb.Timer; +import javax.inject.Inject; + +import test.beans.BeanToTestTimerUse; +import test.beans.TestApplicationScopedBean; +import test.beans.TestRequestScopedBean; + +@Stateless +public class TestEJBTimerBean { + @Inject + BeanToTestTimerUse bean; + @Inject + TestApplicationScopedBean tasb; + @Inject + TestRequestScopedBean trsb; + + /** + * Default constructor. + */ + public TestEJBTimerBean() { + } + + // We assume that the other tests would atleast take 2 seconds + // and this timer bean would get invoked + @SuppressWarnings("unused") + @Schedule(second = "*/2", minute = "*", hour = "*", dayOfWeek = "*", dayOfMonth = "*", month = "*", year = "*", info = "MyTimer") + private void scheduledTimeout(final Timer t) { + System.out.println("@Schedule called at: " + new java.util.Date()); + System.out.println("trsb: " + trsb + " tasb " + tasb); + if (tasb != null && trsb != null) { + bean.setResult(true); + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/README b/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/README new file mode 100644 index 0000000..3618b42 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/README
@@ -0,0 +1,4 @@ +Test that Singleton scoped +- bean is instantiated once +- don't have a proxy +- allow injection of non-serializable singleton scoped beans into serializable beans like SessionScoped beans through Instance<T>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/WebTest.java new file mode 100644 index 0000000..09292da --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/WebTest.java
@@ -0,0 +1,103 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "cdi-scopes-singleton"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/build.properties b/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/build.properties new file mode 100644 index 0000000..45980f4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-singleton-scope"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/build.xml b/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/build.xml new file mode 100644 index 0000000..83ad666 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/servlet/test/beans/TestSessionScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/servlet/test/beans/TestSessionScopedBean.java new file mode 100644 index 0000000..7cb3552 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/servlet/test/beans/TestSessionScopedBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import java.io.Serializable; + +import javax.enterprise.context.SessionScoped; +import javax.enterprise.inject.Instance; +import javax.inject.Inject; + +@SessionScoped +public class TestSessionScopedBean implements Serializable{ + @Inject + Instance<TestSingletonScopedBean> tssInstance; + + public TestSingletonScopedBean getSingletonScopedBean(){ + return tssInstance.get(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/servlet/test/beans/TestSingletonScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/servlet/test/beans/TestSingletonScopedBean.java new file mode 100644 index 0000000..f51d7ca --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/servlet/test/beans/TestSingletonScopedBean.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Singleton; + +//Simple TestBean to test CDI Singleton pseudo-scope. +@Singleton +//note: NOT serializable. So special care must be taken when injected +//into session scoped or conversation scoped bean +public class TestSingletonScopedBean { + private static int instantiationCounter = 0; + + public TestSingletonScopedBean(){ + instantiationCounter++; + } + + public int getInstancesCount(){ + return this.instantiationCounter; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/servlet/test/servlets/SingletonScopedServlet.java b/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/servlet/test/servlets/SingletonScopedServlet.java new file mode 100644 index 0000000..019f00d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/scopes/singleton-scope/servlet/test/servlets/SingletonScopedServlet.java
@@ -0,0 +1,98 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlets; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.enterprise.inject.spi.BeanManager; +import javax.inject.Inject; +import javax.naming.InitialContext; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestSessionScopedBean; +import test.beans.TestSingletonScopedBean; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class SingletonScopedServlet extends HttpServlet { + @Inject + TestSingletonScopedBean tb; + @Inject + TestSingletonScopedBean anotherInjectedSingletonInstance; + + @Inject + BeanManager bm; + BeanManager bm1; + + @Inject + TestSessionScopedBean tssb; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + if (tb == null) + msg += "Singleton pseudo-scope Bean injection into Servlet failed"; + if (bm == null) + msg += "BeanManager Injection via @Inject failed"; + try { + bm1 = (BeanManager) ((new InitialContext()) + .lookup("java:comp/BeanManager")); + } catch (Exception ex) { + ex.printStackTrace(); + msg += "BeanManager Injection via component environment lookup failed"; + } + if (bm1 == null) + msg += "BeanManager Injection via component environment lookup failed"; + if (tb.getInstancesCount() > 1) + msg += "Singleton scoped bean must be created only once"; + if (!areInjectecedInstancesEqual(tb, anotherInjectedSingletonInstance)) + msg += "Two different injection of a Singleton pseudo-scoped Bean must point to the same bean instance"; + if (testIsClientProxy(tb, TestSingletonScopedBean.class)) + msg += "Beans with Singleton pseudo-scope should not have a proxy"; + if (testIsClientProxy(tssb.getSingletonScopedBean(), + TestSingletonScopedBean.class)) + msg += "Non-serializable Beans with Singleton pseudo-scope injected via Instance<T> into a session scoped bean should not have a proxy"; + + writer.write(msg + "\n"); + } + + private boolean areInjectecedInstancesEqual(Object o1, Object o2) { + return (o1.equals(o2)) & (o1 == o2); + } + + // Tests if the bean instance is a client proxy + private boolean testIsClientProxy(Object beanInstance, Class beanType) { + boolean isSameClass = beanInstance.getClass().equals(beanType); + boolean isProxyAssignable = beanType.isAssignableFrom(beanInstance + .getClass()); + System.out.println(beanInstance + "whose class is " + + beanInstance.getClass() + " is same class of " + beanType + + " = " + isSameClass); + System.out.println(beanType + " is assignable from " + beanInstance + + " = " + isProxyAssignable); + boolean isAClientProxy = !isSameClass && isProxyAssignable; + return isAClientProxy; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/README b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/README new file mode 100644 index 0000000..a954e0a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/README
@@ -0,0 +1,10 @@ +This directory has skeleton harnesses for testing CDI usecases. They also test simple typesafe injection. +- Simple EAR +- Simple EJB +- Simple EJB Singleton +- Simple ManagedBean +- Simple ManagedBean with Interceptors +- Simple MDB +- Simple Servlet 3.0 Annotations + +Use these to implement particular CDI usecases.
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/build.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/build.xml new file mode 100644 index 0000000..7dee092 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/build.xml
@@ -0,0 +1,142 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../config/common.xml"> +<!ENTITY commonRun SYSTEM "./../../../config/run.xml"> +<!ENTITY reporting SYSTEM "../report.xml"> +]> + +<project name="smoke-test" default="usage" basedir="."> + + &commonSetup; + &commonBuild; + &commonRun; + &reporting; + + <property name="smoke-target" value="all"/> + + <taskdef resource="net/sf/antcontrib/antcontrib.properties"> + <classpath> + <pathelement location="${env.APS_HOME}/devtests/cdi/lib/ant-contrib-1.0b3.jar"/> + </classpath> + </taskdef> + + <target name="run-test"> + <antcall target="smoke"> + <param name="smoke-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="smoke"> + <param name="smoke-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="smoke"> + <param name="smoke-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="smoke"> + <param name="smoke-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="smoke"> + <param name="smoke-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="smoke"> + <param name="smoke-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="smoke"> + <param name="smoke-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="smoke"> + <param name="smoke-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="smoke"> + <param name="smoke-target" value="run"/> + </antcall> + </target> + + <target name="smoke"> + <record name="smoke.output" action="start" /> + <if> + <equals arg1="${test.embedded.mode}" arg2="true"/> + <then> + <echo> Excluding testcase simple-wab-with-cdi and slf4j-visibility for embedded mode</echo> + </then> + <else> + <ant dir="simple-wab-with-cdi" target="${smoke-target}"/> + <ant dir="slf4j-visibility" target="${smoke-target}"/> + </else> + </if> + <ant dir="simple-ejb-cdi" target="${smoke-target}"/> + + <!-- + Not running until + https://issues.jboss.org/browse/WELD-1345 is fixed. + In 1.1.10.Final the test passes. + In 2.0 Beta it fails. + --> + <ant dir="simple-mdb" target="${smoke-target}"/> + <ant dir="simple-ejb-singleton/hello" target="${smoke-target}"/> +<!-- + <ant dir="singleton-startup/hello" target="${smoke-target}"/> +--> + <ant dir="simple-managed-bean" target="${smoke-target}"/> + <ant dir="simple-managed-bean-interceptor-nonnull-package" target="${smoke-target}"/> + <ant dir="cdi-servlet-3.0-annotation" target="${smoke-target}"/> + <ant dir="cdi-servlet-filter-3.0-annotation" target="${smoke-target}"/> + <ant dir="simple-ear" target="${smoke-target}"/> + <ant dir="optional-unbundled-beans" target="${smoke-target}"/> + <record name="smoke.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant all (Executes all the smoke tests) + ant clean (cleans all the smoke tests) + ant build (builds all the smoke tests) + ant setup (sets up all resources for smoke tests) + ant deploy (deploys all the smoke apps) + ant run (Executes all the smoke tests) + ant undeploy (undeploys all the smoke apps) + ant unsetup (unsets all resources for smoke tests) + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/WebTest.java new file mode 100644 index 0000000..fee7d18 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/WebTest.java
@@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "cdi-servlet-annotation"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/build.properties b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/build.properties new file mode 100644 index 0000000..d2f36aa --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-servlet-annotation"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/build.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/build.xml new file mode 100644 index 0000000..83ad666 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/lib/slf4j-api-1.7.25.jar b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/lib/slf4j-api-1.7.25.jar new file mode 100644 index 0000000..0143c09 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/lib/slf4j-api-1.7.25.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/lib/slf4j-simple-1.7.25.jar b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/lib/slf4j-simple-1.7.25.jar new file mode 100644 index 0000000..a7260f3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/lib/slf4j-simple-1.7.25.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/servlet/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/servlet/TestBean.java new file mode 100644 index 0000000..6d059e2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/servlet/TestBean.java
@@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +//Simple TestBean to test CDI. +//This bean implements Serializable as it needs to be placed into a Stateful Bean +public class TestBean +{}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/servlet/TestLoggerProducer.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/servlet/TestLoggerProducer.java new file mode 100644 index 0000000..04785e9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/servlet/TestLoggerProducer.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import javax.enterprise.inject.Produces; +import org.jboss.logging.Logger; + + +public class TestLoggerProducer { + @Produces + public org.jboss.logging.Logger getLogger(){ + Logger l = Logger.getLogger(TestLoggerProducer.class); + System.out.println("getLogger:: " + l); + return l; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/servlet/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/servlet/TestServlet.java new file mode 100644 index 0000000..baa7aae --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-3.0-annotation/servlet/TestServlet.java
@@ -0,0 +1,63 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.inject.Inject; +import javax.enterprise.inject.spi.BeanManager; +import javax.naming.InitialContext; + +@WebServlet(name="mytest", + urlPatterns={"/myurl"}, + initParams={ @WebInitParam(name="n1", value="v1"), @WebInitParam(name="n2", value="v2") } ) +public class TestServlet extends HttpServlet { + @Inject TestBean tb; + @Inject BeanManager bm; + BeanManager bm1; + + @Inject + private transient org.jboss.logging.Logger log; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + + ", n2=" + getInitParameter("n2"); + if (tb == null) msg += "Bean injection into Servlet failed"; + if (bm == null) msg += "BeanManager Injection via @Inject failed"; + try { + bm1 = (BeanManager)((new InitialContext()).lookup("java:comp/BeanManager")); + } catch (Exception ex) { + ex.printStackTrace(); + msg += "BeanManager Injection via component environment lookup failed"; + } + if (bm1 == null) msg += "BeanManager Injection via component environment lookup failed"; + + System.out.println("BeanManager is " + bm); + System.out.println("BeanManager via lookup is " + bm1); + writer.write("initParams: " + msg + "\n"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/WebTest.java new file mode 100644 index 0000000..b2da7d5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/WebTest.java
@@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "cdi-servlet-filter-annotation"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/build.properties b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/build.properties new file mode 100644 index 0000000..a9ba810 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-servlet-filter-annotation"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/build.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/build.xml new file mode 100644 index 0000000..83ad666 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/servlet/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/servlet/TestBean.java new file mode 100644 index 0000000..6d059e2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/servlet/TestBean.java
@@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +//Simple TestBean to test CDI. +//This bean implements Serializable as it needs to be placed into a Stateful Bean +public class TestBean +{}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/servlet/TestFilter.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/servlet/TestFilter.java new file mode 100644 index 0000000..7137f70 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/servlet/TestFilter.java
@@ -0,0 +1,61 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; + +import javax.enterprise.inject.spi.BeanManager; +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 javax.servlet.annotation.WebFilter; + +@WebFilter(urlPatterns = "/*") +public class TestFilter implements Filter { + @Inject + TestBean tb; + @Inject + BeanManager bm; + + @Override + public void destroy() { + System.out.println("TestFilter:destroy()"); + + } + + @Override + public void doFilter(ServletRequest req, ServletResponse res, + FilterChain fc) throws IOException, ServletException { + System.out.println("TestFilter:doFilter()"); + System.out.println("TestBean injected:"+ tb); + System.out.println("BeanManager injected:"+ bm); + if (tb == null) + throw new ServletException("Injection of TestBean in ServletFilter failed"); + if (bm == null) + throw new ServletException("Injection of BeanManager in ServletFilter failed"); + fc.doFilter(req, res); + } + + @Override + public void init(FilterConfig arg0) throws ServletException { + System.out.println("TestFilter:init()"); + } + +} +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/servlet/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/servlet/TestServlet.java new file mode 100644 index 0000000..475d9fa --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/cdi-servlet-filter-3.0-annotation/servlet/TestServlet.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.enterprise.inject.spi.BeanManager; +import javax.inject.Inject; +import javax.naming.InitialContext; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(name="mytest", urlPatterns={"/myurl"}) +public class TestServlet extends HttpServlet { + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/README b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/README new file mode 100644 index 0000000..b38dca5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/README
@@ -0,0 +1,2 @@ +Regression test for GLASSFISH-16318 +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/WebTest.java new file mode 100644 index 0000000..bcd25ae --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/WebTest.java
@@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "optional-unbundled-beans"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.properties b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.properties new file mode 100644 index 0000000..36b4298 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-optional-unbundled-beans"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml new file mode 100644 index 0000000..2ba7c3a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml
@@ -0,0 +1,90 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + + <!-- remove the class that needs to be unavailable in the deployment archive --> + <delete file="${build.classes.dir}/ClassUnavailableAtRuntime.class"/> + + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/foo.txt b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/foo.txt new file mode 100644 index 0000000..34945c0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/foo.txt
@@ -0,0 +1,1987 @@ +Apache Ant version 1.7.1 compiled on June 27 2008 +Buildfile: build.xml +Detected Java version: 1.6 in: /space/apps/jdk1.6.0_22/jre +Detected OS: Linux +parsing buildfile /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml with URI = file:/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml +Project base dir set to: /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/properties.xml +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/common.xml +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.properties +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/run.xml +[antlib:org.apache.tools.ant] Could not load definitions from resource org/apache/tools/ant/antlib.xml. It could not be found. + [property] Loading Environment env. +Property "BASH_SOURCE" has not been set +Property "LINENO" has not been set +Property "FUNCNAME[0]" has not been set +Property "NEW_PWD" has not been set +Property "build.classes.dir" has not been set + [macrodef] creating macro run-test +Build sequence for target(s) `clean' is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean] +Complete build sequence is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean, restart-instance-common, execute-sql-common, deploy-rar-common, undeploy, deploy-jdbc-common, undeploy-rar-common, set-derby-connpool-props, create-sql-common, deploy-war-no-context-root-pe, verifier-common, start-server-unix, test-tagfiles-exist, create-PermSize, execute-ejb-sql-common, undeploy-client-common, prepare-keystore-common, deploy-verify-common-ee, startDerby, confirmMissingReport-common, create-connector-resource-common, asadmin-common, create-connector-connpool, delete-connector-connpool-common, verifier, start-clean-server, runwebclient-common, deploy-common-ee, startDerbyNonMac, webclient-war-common, flush-connpool-common, stopDerby, clean-webapps-common, delete-jdbc-connpool-common, prepare-truststore-common, deploy-verify-common, run, test-tlds-exist, deploy-verify-common-pe, undeploy-common, undeploy-jar-common, deploy-client-common, enterprise-common, create-javamail-resource-common, package-persistence-common, deploy-war-commonee, startDomainWindows, set-derby-driver-connpool-props, deploy-war-no-context-root, undeploy-jdbc-common, deploy-common-pe, clear, copy-tagfiles, compile, build, deploy, restart-server-instance-common, deploy-jar-common, delete-domain-common, stopPB, compile-common-with-endorsed-dir, import-wsdl, deploy-war-commonpe, compile-common, restart-server, runclient-common, package-appclientjar-common, ee-common, copy-tlds, delete-persistence-resource-common, undeploy-jms-common, asadmin-common-ignore-fail, startDomainUnix, startDomain, fixFiles, ejb-jar-common, appclient-jar-common, build-ear-common, publish-war-common, build-publish-war, stop-server-unix, clean-classes-common, clean-common, create-jdbc-connpool-common, dev-report, startDerbyMac, deploy-jms-common, package-war-common, package-ejbjar-common, delete-connector-resource-common, deploy-jsp-common, unsetupTimer, undeploy-war-common, change-orb-port, delete-javamail-resource-common, deploy-common, create-jms-resource-common, setup-mq-common, delete-jdbc-resource-common, start-server-windows, dumpThreadStack, setupTimer, deploy-war-common, start-server, ee, checkReporting-common, testTimer, stop-server, create-jdbc-driver-connpool-common, all, platform-common, create-jms-connection-common, undeploy-war-name, cleanAS, deploy-dir, preparePB, stop-server-windows, confirmReportPresent-common, delete-jms-resource-common, pb, runtest, create-jvm-options, clean-jars-common, restart-instance, stopDomain, create-connector-connpool-common, set-pointbase-driver-connpool-props, delete-sql-common, deploy-jdbc-driver-common, create-domain-common, delete-jvm-options, create-jdbc-resource-common, prepare-truststore-certutil-common, create-user-common, asadmin-batch-common, delete-user-common, prepare-truststore-keytool-common, convWin, create-persistence-resource-common, get-version-common, startPB, delete-jms-connection-common, usage-common, deploy-war-no-context-root-ee, set-pointbase-connpool-props, usage, convUnix, staticCheck-common, ear-common, deploy-war-name, ] + +setToolWin: +Skipped because property 'isWindows' not set. + +setS1ASclassPath: +[pathconvert] Set property s1as.classpath = /export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/acc-config.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/admin-cli.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/admin-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/admin-util.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/amx-all.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/annotation-framework.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ant.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/antlr-repackaged.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/api-exporter.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/appclient-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/appclient-server-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/appclient.security.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/asm-all-repackaged.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/auto-depends.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/org.apache.felix.bundlerepository.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/org.apache.felix.eventadmin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/org.apache.felix.scr.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/osgi-cdi.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/osgi-ee-resources.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/osgi-ejb-container.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/osgi-javaee-base.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/osgi-jdbc.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/osgi-jpa.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/osgi-jta.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/osgi-web-container.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/backup.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/bean-validator.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/branding.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/class-model.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cli-optional.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cluster-admin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cluster-cli.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cluster-common.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cluster-ssh.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cmp-ejb-mapping.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cmp-enhancer.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cmp-generator-database.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cmp-internal-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cmp-model.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cmp-support-ejb.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cmp-support-sqlstore.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cmp-utility.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/common-util.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/config-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/config-types.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/config.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/connectors-admin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/connectors-inbound-runtime.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/connectors-internal-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/connectors-runtime.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-cluster-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-cluster-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-common-full-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-common-full-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-common-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-common.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-community-branding-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-corba-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-corba-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-ejb-lite-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-ejb-lite-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-ejb-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-ejb-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-jca-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-jca-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-jdbc-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-jdbc-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-jms-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-jms-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-jts-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-jts-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-plugin-service.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-updatecenter-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-web-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-web-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/container-common.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/dataprovider.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/dbschema-repackaged.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/deployment-admin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/deployment-autodeploy.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/deployment-client.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/deployment-common.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/deployment-javaee-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/deployment-javaee-full.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/dol.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ejb-container.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ejb-internal-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ejb.security.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/el-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/endorsed/javax.annotation.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/endorsed/jaxb-api-osgi.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/endorsed/webservices-api-osgi.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/flashlight-extra-jdk-packages.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/flashlight-framework.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/gf-client-module.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/gf-connectors-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/gf-ejb-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/gf-web-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-corba-asm.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-corba-codegen.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-corba-csiv2-idl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-corba-internal-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-corba-newtimer.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-corba-omgapi.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-corba-orb.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-corba-orbgeneric.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-ee-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-extra-jre-packages.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-mbeanserver.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-naming.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-oracle-jdbc-driver-packages.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-registration.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/gmbal-api-only.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/gmbal.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/gms-adapter.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/gms-bootstrap.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-comet.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-config.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-container.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-framework-tests.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-framework.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-http-ajp.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-http-server.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-http-servlet.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-http.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-portunif.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-rcm.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-websockets.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ha-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ha-file-store.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ha-shoal-cache-bootstrap.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ha-shoal-cache-store.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/hk2-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/hk2.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/inmemory.jacc.provider.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/internal-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jackson-core-asl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jackson-jaxrs.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jackson-mapper-asl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jackson-xc.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jaspic.provider.framework.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javaee-kernel.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.ejb.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.enterprise.deploy.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.jms.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.mail.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.management.j2ee.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.persistence.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.resource.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.security.auth.message.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.security.jacc.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.servlet.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.servlet.jsp.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.servlet.jsp.jstl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.transaction.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jaxb-osgi.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jaxrpc-api-osgi.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jdbc-admin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jersey-client.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jersey-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jersey-gf-server.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jersey-gf-statsproviders.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jersey-grizzly2.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jersey-json.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jersey-multipart.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jettison.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jms-admin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jms-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jmxremote_optional-repackaged.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jpa-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jsf-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jsf-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jsf-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jsftemplating.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jsp-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jspcaching-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jsr109-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jstl-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jstl-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jta.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jts.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/kernel.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/launcher.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ldapbp-repackaged.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/libpam4j-repackaged.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/libvirt.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/load-balancer-admin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/logging.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/management-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/metro-glue.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/mimepull.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/monitoring-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/orb-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/orb-enabler.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/orb-iiop.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.apache.felix.configadmin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.apache.felix.fileinstall.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.apache.felix.gogo.command.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.apache.felix.gogo.runtime.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.apache.felix.gogo.shell.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.apache.felix.shell.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.apache.felix.shell.remote.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.apache.felix.shell.tui.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.eclipse.persistence.antlr.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.eclipse.persistence.asm.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.eclipse.persistence.core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.eclipse.persistence.jpa.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.eclipse.persistence.jpa.modelgen.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.eclipse.persistence.oracle.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/osgi-adapter.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/osgi-container.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/osgi-jpa-extension.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/osgi-main.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/osgi-resource-locator.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/persistence-common.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/pkg-client.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/registration-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/registration-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/rest-service.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/scattered-archive-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/schema2beans-repackaged.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/security.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/server-mgmt.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/shoal-cache.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/shoal-gms-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/shoal-gms-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/simple-glassfish-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/soap-tcp.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ssl-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/stats77.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/transaction-internal-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/trilead-ssh2-repackaged.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/virt-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/war-util.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/web-cli.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/web-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/web-embed-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/web-embed-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/web-glue.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/web-gui-plugin-common.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/web-ha.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/web-naming.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/websecurity.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/webservices-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/webservices-extra-jdk-packages.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/webservices-osgi.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/webservices.security.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/weld-integration-fragment.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/weld-integration.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/weld-osgi-bundle.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/woodstox-osgi.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/work-management.jar + +init-common: + [echo] Loading props from file /export/work/workspaces/gfv3/appserv-tests/config.properties + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config.properties + [echo] admin.domain domain1 + [echo] admin.user admin + [echo] admin.port 4848 + [echo] http.port 8080 + [echo] http.host localhost + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config/derby.properties +Property "env.JAVKE_HOME" has not been set +Property "Derby.classpath" has not been set +Override ignored for property "cluster.name" + +clean: +Project base dir set to: /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans + [antcall] calling target(s) [clean-common] in build file /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml +parsing buildfile /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml with URI = file:/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml +Project base dir set to: /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/properties.xml +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/common.xml +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.properties +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/run.xml + [property] Loading Environment env. +Override ignored for property "env.SESSION_MANAGER" +Override ignored for property "env.LESSOPEN" +Override ignored for property "env.NORMBGCOLOR" +Override ignored for property "env.CVSROOT" +Override ignored for property "env.MY_ANT_HOME" +Override ignored for property "env.PWD" +Override ignored for property "env.XDG_SESSION_COOKIE" +Override ignored for property "env.LANG" +Override ignored for property "env.WS" +Override ignored for property "env.AWT_TOOLKIT" +Override ignored for property "env.DEFAULTS_PATH" +Override ignored for property "env.HISTSIZE" +Override ignored for property "env.INSTALL_ROOT" +Override ignored for property "env.DISPLAY" +Override ignored for property "env._" +Override ignored for property "env.USER" +Override ignored for property "env.HISTCONTROL" +Override ignored for property "env.SHELL" +Override ignored for property "env.NLSPATH" +Override ignored for property "env.XDG_DATA_DIRS" +Override ignored for property "env.DESKTOP_SESSION" +Override ignored for property "env.HISTFILESIZE" +Override ignored for property "env.APS_HOME" +Override ignored for property "env.WIDTH" +Override ignored for property "env.JAVANETCVSROOT" +Override ignored for property "env.PATH" +Override ignored for property "env.no_proxy" +Override ignored for property "env.NORMFGCOLOR" +Override ignored for property "env.LC_CTYPE" +Override ignored for property "env.DBUS_SESSION_BUS_ADDRESS" +Override ignored for property "env.REALPLAYER_HOME" +Override ignored for property "env.SSH_AGENT_PID" +Override ignored for property "env.SHLVL" +Override ignored for property "env.GDMSESSION" +Override ignored for property "env.GNOME_DESKTOP_SESSION_ID" +Override ignored for property "env.GDM_KEYBOARD_LAYOUT" +Override ignored for property "env.GNOME_KEYRING_PID" +Override ignored for property "env.OS" +Override ignored for property "env.LOGNAME" +Override ignored for property "env.ALSA_OUTPUT_PORTS" +Override ignored for property "env.SCUMMVM_PORT" +Override ignored for property "env.JAVA_HOME" +Override ignored for property "env.TERM" +Override ignored for property "env.QLTESTRES" +Override ignored for property "env.NO_PROXY" +Override ignored for property "env.GDM_LANG" +Override ignored for property "env.DTACH_HOME" +Override ignored for property "env.OLDPWD" +Override ignored for property "env.DEBUG" +Override ignored for property "env.GCONF_LOCAL_LOCKS" +Override ignored for property "env.M2_HOME" +Override ignored for property "env.EC2_CERT" +Override ignored for property "env.WINDOWID" +Override ignored for property "env.EC2_PRIVATE_KEY" +Override ignored for property "env.REDCVSROOT" +Override ignored for property "env.MOZ_DISABLE_PANGO" +Override ignored for property "env.XFILESEARCHPATH" +Override ignored for property "env.HOME" +Override ignored for property "env.ANT_HOME" +Override ignored for property "env.LD_LIBRARY_PATH" +Override ignored for property "env.MAVEN_OPTS" +Override ignored for property "env.SSH_AUTH_SOCK" +Override ignored for property "env.RBARWIDTH" +Override ignored for property "env.S1AS_HOME" +Property "BASH_SOURCE" has not been set +Property "LINENO" has not been set +Property "FUNCNAME[0]" has not been set +Override ignored for property "env.PS4" +Override ignored for property "env.MAVEN_HOME" +Override ignored for property "env.XAUTHORITY" +Property "NEW_PWD" has not been set +Override ignored for property "env.PS1" +Override ignored for property "env.MANDATORY_PATH" +Override ignored for property "env.SPEECHD_PORT" +Override ignored for property "env.GTK_MODULES" +Override ignored for property "env.WINDOW_MANAGER" +Override ignored for property "env.DTRX_HOME" +Override ignored for property "env.COLORTERM" +Override ignored for property "env.EDITOR" +Override ignored for property "env.MALLOC_CHECK_" +Override ignored for property "env.ORBIT_SOCKETDIR" +Override ignored for property "env.WP_INSTALL_ROOT" +Override ignored for property "env.USERNAME" +Override ignored for property "env.SCALA_HOME" +Override ignored for property "env.COPE_PATH" +Override ignored for property "env.QL_HOME" +Override ignored for property "env.AS_ADMIN_READTIMEOUT" +Override ignored for property "env.MY_SCRIPT_DIR" +Override ignored for property "env.GNOME_KEYRING_CONTROL" +Override ignored for property "env.XDG_CONFIG_DIRS" +Override ignored for property "env.TODOTXT_HOME" +Override ignored for property "env.LESSCLOSE" +Override ignored for property "module" +Override ignored for property "appname" +Override ignored for property "assemble" +Override ignored for property "contextroot" +Override ignored for property "beans.xml" +Override ignored for property "target-to-run" + [macrodef] creating macro run-test +Build sequence for target(s) `clean-common' is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-common] +Complete build sequence is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-common, restart-instance-common, execute-sql-common, deploy-rar-common, undeploy, deploy-jdbc-common, undeploy-rar-common, set-derby-connpool-props, create-sql-common, deploy-war-no-context-root-pe, verifier-common, start-server-unix, test-tagfiles-exist, create-PermSize, execute-ejb-sql-common, undeploy-client-common, prepare-keystore-common, deploy-verify-common-ee, startDerby, confirmMissingReport-common, create-connector-resource-common, asadmin-common, create-connector-connpool, delete-connector-connpool-common, verifier, start-clean-server, runwebclient-common, deploy-common-ee, startDerbyNonMac, webclient-war-common, flush-connpool-common, stopDerby, clean-webapps-common, delete-jdbc-connpool-common, prepare-truststore-common, deploy-verify-common, run, test-tlds-exist, deploy-verify-common-pe, undeploy-common, undeploy-jar-common, deploy-client-common, enterprise-common, create-javamail-resource-common, package-persistence-common, deploy-war-commonee, startDomainWindows, set-derby-driver-connpool-props, deploy-war-no-context-root, undeploy-jdbc-common, deploy-common-pe, clear, copy-tagfiles, clean, compile, build, deploy, restart-server-instance-common, deploy-jar-common, delete-domain-common, stopPB, compile-common-with-endorsed-dir, import-wsdl, deploy-war-commonpe, compile-common, restart-server, runclient-common, package-appclientjar-common, ee-common, copy-tlds, delete-persistence-resource-common, undeploy-jms-common, asadmin-common-ignore-fail, startDomainUnix, startDomain, fixFiles, ejb-jar-common, appclient-jar-common, build-ear-common, publish-war-common, build-publish-war, stop-server-unix, clean-classes-common, create-jdbc-connpool-common, dev-report, startDerbyMac, deploy-jms-common, package-war-common, package-ejbjar-common, delete-connector-resource-common, deploy-jsp-common, unsetupTimer, undeploy-war-common, change-orb-port, delete-javamail-resource-common, deploy-common, create-jms-resource-common, setup-mq-common, delete-jdbc-resource-common, start-server-windows, dumpThreadStack, setupTimer, deploy-war-common, start-server, ee, checkReporting-common, testTimer, stop-server, create-jdbc-driver-connpool-common, all, platform-common, create-jms-connection-common, undeploy-war-name, cleanAS, deploy-dir, preparePB, stop-server-windows, confirmReportPresent-common, delete-jms-resource-common, pb, runtest, create-jvm-options, clean-jars-common, restart-instance, stopDomain, create-connector-connpool-common, set-pointbase-driver-connpool-props, delete-sql-common, deploy-jdbc-driver-common, create-domain-common, delete-jvm-options, create-jdbc-resource-common, prepare-truststore-certutil-common, create-user-common, asadmin-batch-common, delete-user-common, prepare-truststore-keytool-common, convWin, create-persistence-resource-common, get-version-common, startPB, delete-jms-connection-common, usage-common, deploy-war-no-context-root-ee, set-pointbase-connpool-props, usage, convUnix, staticCheck-common, ear-common, deploy-war-name, ] + [antcall] Entering /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml... +Build sequence for target(s) `clean-common' is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-common] +Complete build sequence is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-common, restart-instance-common, execute-sql-common, deploy-rar-common, undeploy, deploy-jdbc-common, undeploy-rar-common, set-derby-connpool-props, create-sql-common, deploy-war-no-context-root-pe, verifier-common, start-server-unix, test-tagfiles-exist, create-PermSize, execute-ejb-sql-common, undeploy-client-common, prepare-keystore-common, deploy-verify-common-ee, startDerby, confirmMissingReport-common, create-connector-resource-common, asadmin-common, create-connector-connpool, delete-connector-connpool-common, verifier, start-clean-server, runwebclient-common, deploy-common-ee, startDerbyNonMac, webclient-war-common, flush-connpool-common, stopDerby, clean-webapps-common, delete-jdbc-connpool-common, prepare-truststore-common, deploy-verify-common, run, test-tlds-exist, deploy-verify-common-pe, undeploy-common, undeploy-jar-common, deploy-client-common, enterprise-common, create-javamail-resource-common, package-persistence-common, deploy-war-commonee, startDomainWindows, set-derby-driver-connpool-props, deploy-war-no-context-root, undeploy-jdbc-common, deploy-common-pe, clear, copy-tagfiles, clean, compile, build, deploy, restart-server-instance-common, deploy-jar-common, delete-domain-common, stopPB, compile-common-with-endorsed-dir, import-wsdl, deploy-war-commonpe, compile-common, restart-server, runclient-common, package-appclientjar-common, ee-common, copy-tlds, delete-persistence-resource-common, undeploy-jms-common, asadmin-common-ignore-fail, startDomainUnix, startDomain, fixFiles, ejb-jar-common, appclient-jar-common, build-ear-common, publish-war-common, build-publish-war, stop-server-unix, clean-classes-common, create-jdbc-connpool-common, dev-report, startDerbyMac, deploy-jms-common, package-war-common, package-ejbjar-common, delete-connector-resource-common, deploy-jsp-common, unsetupTimer, undeploy-war-common, change-orb-port, delete-javamail-resource-common, deploy-common, create-jms-resource-common, setup-mq-common, delete-jdbc-resource-common, start-server-windows, dumpThreadStack, setupTimer, deploy-war-common, start-server, ee, checkReporting-common, testTimer, stop-server, create-jdbc-driver-connpool-common, all, platform-common, create-jms-connection-common, undeploy-war-name, cleanAS, deploy-dir, preparePB, stop-server-windows, confirmReportPresent-common, delete-jms-resource-common, pb, runtest, create-jvm-options, clean-jars-common, restart-instance, stopDomain, create-connector-connpool-common, set-pointbase-driver-connpool-props, delete-sql-common, deploy-jdbc-driver-common, create-domain-common, delete-jvm-options, create-jdbc-resource-common, prepare-truststore-certutil-common, create-user-common, asadmin-batch-common, delete-user-common, prepare-truststore-keytool-common, convWin, create-persistence-resource-common, get-version-common, startPB, delete-jms-connection-common, usage-common, deploy-war-no-context-root-ee, set-pointbase-connpool-props, usage, convUnix, staticCheck-common, ear-common, deploy-war-name, ] + +setOSConditions: +Override ignored for property "isUnix" + +setToolWin: +Skipped because property 'isWindows' not set. + +setToolUnix: +Override ignored for property "APPCLIENT" +Override ignored for property "ASADMIN" +Override ignored for property "ASANT" +Override ignored for property "CAPTURESCHEMA" +Override ignored for property "CHECKPATCH" +Override ignored for property "INSTALLPATCH" +Override ignored for property "JSPC" +Override ignored for property "LISTPATCH" +Override ignored for property "PACKAGE-APPCLIENT" +Override ignored for property "VERIFIER" +Override ignored for property "RMIC" +Override ignored for property "TNAMESERV" +Override ignored for property "WSCOMPILE" +Override ignored for property "WSIMPORT" +Override ignored for property "pb.start.server" +Override ignored for property "pb.start.server1" +Override ignored for property "IMQDBMGR" +Override ignored for property "ld.library.path" + +setS1ASclassPath: +Skipped because property 's1as.classpath' set. + +init-common: + [echo] Loading props from file /export/work/workspaces/gfv3/appserv-tests/config.properties +Override ignored for property "pe" + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config.properties +Override ignored for property "instance.https.port" +Override ignored for property "admin.domain" +Override ignored for property "admin.password" +Override ignored for property "http.address" +Override ignored for property "http.alternate.port" +Override ignored for property "ssl.password" +Override ignored for property "instance.http.port" +Override ignored for property "resources.dottedname.prefix" +Override ignored for property "results.mailer" +Override ignored for property "admin.domain.dir" +Override ignored for property "admin.user" +Override ignored for property "config.dottedname.prefix" +Override ignored for property "instance.name" +Override ignored for property "precompilejsp" +Override ignored for property "admin.password.file" +Override ignored for property "http.port" +Override ignored for property "https.port" +Override ignored for property "results.mailee" +Override ignored for property "appserver.instance.name" +Override ignored for property "master.password" +Override ignored for property "http.host" +Override ignored for property "instance.http.port.3" +Override ignored for property "instance.http.port.2" +Override ignored for property "admin.port" +Override ignored for property "cluster.name" +Override ignored for property "appserver.instance.dir" +Override ignored for property "autodeploy.dir" +Override ignored for property "orb.port" +Override ignored for property "admin.host" +Override ignored for property "instance.name.3" +Override ignored for property "instance.name.2" +Override ignored for property "results.mailhost" + [echo] admin.domain domain1 + [echo] admin.user admin + [echo] admin.port 4848 + [echo] http.port 8080 + [echo] http.host localhost +Override ignored for property "as.props" +Override ignored for property "authrealmname" +Override ignored for property "apptype" +Override ignored for property "db.root" +Override ignored for property "db.dir" +Override ignored for property "db.classpath" + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config/derby.properties +Override ignored for property "db.host" +Override ignored for property "db.url" +Override ignored for property "db.xaclass" +Override ignored for property "db.name" +Override ignored for property "db.driver" +Override ignored for property "db.port" +Override ignored for property "db.port.2" +Override ignored for property "db.class" +Override ignored for property "db.user" +Override ignored for property "db.pwd" +Override ignored for property "db.type" +Property "env.JAVKE_HOME" has not been set +Override ignored for property "javke.home" +Override ignored for property "dest.type" +Override ignored for property "dest.name" +Override ignored for property "jms.factory.name" +Override ignored for property "jms.factory.type" +Override ignored for property "jms.resource.name" +Override ignored for property "jms.resource.type" +Override ignored for property "jdbc.conpool.name" +Override ignored for property "jdbc.resource.name" +Override ignored for property "jdbc.resource.type" +Override ignored for property "pm.resource.name" +Override ignored for property "pm.factory.class" +Override ignored for property "appclient.application.args" +Override ignored for property "build.base.dir" +Override ignored for property "build.webapps.dir" +Override ignored for property "build.classes.dir" +Override ignored for property "assemble.dir" +Override ignored for property "results.dir" +Property "Derby.classpath" has not been set +Override ignored for property "s1astest.classpath" +Override ignored for property "ejbjar.classes" +Override ignored for property "appclientjar.classes" +Override ignored for property "webclient.war.files" +Override ignored for property "webclient.war.classes" +Override ignored for property "test.name" +Override ignored for property "test.description" +Override ignored for property "test.count" +Override ignored for property "cluster.name" +Override ignored for property "clustered.server.name" +Override ignored for property "clustered.server.name.two" +Override ignored for property "nodeagent.name" +Override ignored for property "das.host" +Override ignored for property "das.jmx.port" +Override ignored for property "http.listener1.port" +Override ignored for property "http.listener2.port" +Override ignored for property "orb.listener1.port" +Override ignored for property "ssl.port" +Override ignored for property "ssl.mutualauth.port" +Override ignored for property "jmx.system.connector.port" +Override ignored for property "http.listener1.port.two" +Override ignored for property "http.listener2.port.two" +Override ignored for property "orb.listener1.port.two" +Override ignored for property "ssl.port.two" +Override ignored for property "ssl.mutualauth.port.two" +Override ignored for property "jmx.system.connector.port.two" +Override ignored for property "cert.nickname" + +clean-common: +Project base dir set to: /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans + [antcall] calling target(s) [clean-classes-common] in build file /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml +parsing buildfile /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml with URI = file:/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml +Project base dir set to: /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/properties.xml +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/common.xml +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.properties +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/run.xml + [property] Loading Environment env. +Override ignored for property "env.SESSION_MANAGER" +Override ignored for property "env.LESSOPEN" +Override ignored for property "env.NORMBGCOLOR" +Override ignored for property "env.CVSROOT" +Override ignored for property "env.MY_ANT_HOME" +Override ignored for property "env.PWD" +Override ignored for property "env.XDG_SESSION_COOKIE" +Override ignored for property "env.LANG" +Override ignored for property "env.WS" +Override ignored for property "env.AWT_TOOLKIT" +Override ignored for property "env.DEFAULTS_PATH" +Override ignored for property "env.HISTSIZE" +Override ignored for property "env.INSTALL_ROOT" +Override ignored for property "env.DISPLAY" +Override ignored for property "env._" +Override ignored for property "env.USER" +Override ignored for property "env.HISTCONTROL" +Override ignored for property "env.SHELL" +Override ignored for property "env.NLSPATH" +Override ignored for property "env.XDG_DATA_DIRS" +Override ignored for property "env.DESKTOP_SESSION" +Override ignored for property "env.HISTFILESIZE" +Override ignored for property "env.APS_HOME" +Override ignored for property "env.WIDTH" +Override ignored for property "env.JAVANETCVSROOT" +Override ignored for property "env.PATH" +Override ignored for property "env.no_proxy" +Override ignored for property "env.NORMFGCOLOR" +Override ignored for property "env.LC_CTYPE" +Override ignored for property "env.DBUS_SESSION_BUS_ADDRESS" +Override ignored for property "env.REALPLAYER_HOME" +Override ignored for property "env.SSH_AGENT_PID" +Override ignored for property "env.SHLVL" +Override ignored for property "env.GDMSESSION" +Override ignored for property "env.GNOME_DESKTOP_SESSION_ID" +Override ignored for property "env.GDM_KEYBOARD_LAYOUT" +Override ignored for property "env.GNOME_KEYRING_PID" +Override ignored for property "env.OS" +Override ignored for property "env.LOGNAME" +Override ignored for property "env.ALSA_OUTPUT_PORTS" +Override ignored for property "env.SCUMMVM_PORT" +Override ignored for property "env.JAVA_HOME" +Override ignored for property "env.TERM" +Override ignored for property "env.QLTESTRES" +Override ignored for property "env.NO_PROXY" +Override ignored for property "env.GDM_LANG" +Override ignored for property "env.DTACH_HOME" +Override ignored for property "env.OLDPWD" +Override ignored for property "env.DEBUG" +Override ignored for property "env.GCONF_LOCAL_LOCKS" +Override ignored for property "env.M2_HOME" +Override ignored for property "env.EC2_CERT" +Override ignored for property "env.WINDOWID" +Override ignored for property "env.EC2_PRIVATE_KEY" +Override ignored for property "env.REDCVSROOT" +Override ignored for property "env.MOZ_DISABLE_PANGO" +Override ignored for property "env.XFILESEARCHPATH" +Override ignored for property "env.HOME" +Override ignored for property "env.ANT_HOME" +Override ignored for property "env.LD_LIBRARY_PATH" +Override ignored for property "env.MAVEN_OPTS" +Override ignored for property "env.SSH_AUTH_SOCK" +Override ignored for property "env.RBARWIDTH" +Override ignored for property "env.S1AS_HOME" +Property "BASH_SOURCE" has not been set +Property "LINENO" has not been set +Property "FUNCNAME[0]" has not been set +Override ignored for property "env.PS4" +Override ignored for property "env.MAVEN_HOME" +Override ignored for property "env.XAUTHORITY" +Property "NEW_PWD" has not been set +Override ignored for property "env.PS1" +Override ignored for property "env.MANDATORY_PATH" +Override ignored for property "env.SPEECHD_PORT" +Override ignored for property "env.GTK_MODULES" +Override ignored for property "env.WINDOW_MANAGER" +Override ignored for property "env.DTRX_HOME" +Override ignored for property "env.COLORTERM" +Override ignored for property "env.EDITOR" +Override ignored for property "env.MALLOC_CHECK_" +Override ignored for property "env.ORBIT_SOCKETDIR" +Override ignored for property "env.WP_INSTALL_ROOT" +Override ignored for property "env.USERNAME" +Override ignored for property "env.SCALA_HOME" +Override ignored for property "env.COPE_PATH" +Override ignored for property "env.QL_HOME" +Override ignored for property "env.AS_ADMIN_READTIMEOUT" +Override ignored for property "env.MY_SCRIPT_DIR" +Override ignored for property "env.GNOME_KEYRING_CONTROL" +Override ignored for property "env.XDG_CONFIG_DIRS" +Override ignored for property "env.TODOTXT_HOME" +Override ignored for property "env.LESSCLOSE" +Override ignored for property "module" +Override ignored for property "appname" +Override ignored for property "assemble" +Override ignored for property "contextroot" +Override ignored for property "beans.xml" +Override ignored for property "target-to-run" + [macrodef] creating macro run-test +Build sequence for target(s) `clean-classes-common' is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-classes-common] +Complete build sequence is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-classes-common, restart-instance-common, execute-sql-common, deploy-rar-common, undeploy, deploy-jdbc-common, undeploy-rar-common, set-derby-connpool-props, create-sql-common, deploy-war-no-context-root-pe, verifier-common, start-server-unix, test-tagfiles-exist, create-PermSize, execute-ejb-sql-common, undeploy-client-common, prepare-keystore-common, deploy-verify-common-ee, startDerby, confirmMissingReport-common, create-connector-resource-common, asadmin-common, create-connector-connpool, delete-connector-connpool-common, verifier, start-clean-server, runwebclient-common, deploy-common-ee, startDerbyNonMac, webclient-war-common, flush-connpool-common, stopDerby, clean-webapps-common, delete-jdbc-connpool-common, prepare-truststore-common, deploy-verify-common, run, test-tlds-exist, deploy-verify-common-pe, undeploy-common, undeploy-jar-common, deploy-client-common, enterprise-common, create-javamail-resource-common, package-persistence-common, deploy-war-commonee, startDomainWindows, set-derby-driver-connpool-props, deploy-war-no-context-root, undeploy-jdbc-common, deploy-common-pe, clear, copy-tagfiles, clean, compile, build, deploy, restart-server-instance-common, deploy-jar-common, delete-domain-common, stopPB, compile-common-with-endorsed-dir, import-wsdl, deploy-war-commonpe, compile-common, restart-server, runclient-common, package-appclientjar-common, ee-common, copy-tlds, delete-persistence-resource-common, undeploy-jms-common, asadmin-common-ignore-fail, startDomainUnix, startDomain, fixFiles, ejb-jar-common, appclient-jar-common, build-ear-common, publish-war-common, build-publish-war, stop-server-unix, clean-common, create-jdbc-connpool-common, dev-report, startDerbyMac, deploy-jms-common, package-war-common, package-ejbjar-common, delete-connector-resource-common, deploy-jsp-common, unsetupTimer, undeploy-war-common, change-orb-port, delete-javamail-resource-common, deploy-common, create-jms-resource-common, setup-mq-common, delete-jdbc-resource-common, start-server-windows, dumpThreadStack, setupTimer, deploy-war-common, start-server, ee, checkReporting-common, testTimer, stop-server, create-jdbc-driver-connpool-common, all, platform-common, create-jms-connection-common, undeploy-war-name, cleanAS, deploy-dir, preparePB, stop-server-windows, confirmReportPresent-common, delete-jms-resource-common, pb, runtest, create-jvm-options, clean-jars-common, restart-instance, stopDomain, create-connector-connpool-common, set-pointbase-driver-connpool-props, delete-sql-common, deploy-jdbc-driver-common, create-domain-common, delete-jvm-options, create-jdbc-resource-common, prepare-truststore-certutil-common, create-user-common, asadmin-batch-common, delete-user-common, prepare-truststore-keytool-common, convWin, create-persistence-resource-common, get-version-common, startPB, delete-jms-connection-common, usage-common, deploy-war-no-context-root-ee, set-pointbase-connpool-props, usage, convUnix, staticCheck-common, ear-common, deploy-war-name, ] + [antcall] Entering /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml... +Build sequence for target(s) `clean-classes-common' is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-classes-common] +Complete build sequence is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-classes-common, restart-instance-common, execute-sql-common, deploy-rar-common, undeploy, deploy-jdbc-common, undeploy-rar-common, set-derby-connpool-props, create-sql-common, deploy-war-no-context-root-pe, verifier-common, start-server-unix, test-tagfiles-exist, create-PermSize, execute-ejb-sql-common, undeploy-client-common, prepare-keystore-common, deploy-verify-common-ee, startDerby, confirmMissingReport-common, create-connector-resource-common, asadmin-common, create-connector-connpool, delete-connector-connpool-common, verifier, start-clean-server, runwebclient-common, deploy-common-ee, startDerbyNonMac, webclient-war-common, flush-connpool-common, stopDerby, clean-webapps-common, delete-jdbc-connpool-common, prepare-truststore-common, deploy-verify-common, run, test-tlds-exist, deploy-verify-common-pe, undeploy-common, undeploy-jar-common, deploy-client-common, enterprise-common, create-javamail-resource-common, package-persistence-common, deploy-war-commonee, startDomainWindows, set-derby-driver-connpool-props, deploy-war-no-context-root, undeploy-jdbc-common, deploy-common-pe, clear, copy-tagfiles, clean, compile, build, deploy, restart-server-instance-common, deploy-jar-common, delete-domain-common, stopPB, compile-common-with-endorsed-dir, import-wsdl, deploy-war-commonpe, compile-common, restart-server, runclient-common, package-appclientjar-common, ee-common, copy-tlds, delete-persistence-resource-common, undeploy-jms-common, asadmin-common-ignore-fail, startDomainUnix, startDomain, fixFiles, ejb-jar-common, appclient-jar-common, build-ear-common, publish-war-common, build-publish-war, stop-server-unix, clean-common, create-jdbc-connpool-common, dev-report, startDerbyMac, deploy-jms-common, package-war-common, package-ejbjar-common, delete-connector-resource-common, deploy-jsp-common, unsetupTimer, undeploy-war-common, change-orb-port, delete-javamail-resource-common, deploy-common, create-jms-resource-common, setup-mq-common, delete-jdbc-resource-common, start-server-windows, dumpThreadStack, setupTimer, deploy-war-common, start-server, ee, checkReporting-common, testTimer, stop-server, create-jdbc-driver-connpool-common, all, platform-common, create-jms-connection-common, undeploy-war-name, cleanAS, deploy-dir, preparePB, stop-server-windows, confirmReportPresent-common, delete-jms-resource-common, pb, runtest, create-jvm-options, clean-jars-common, restart-instance, stopDomain, create-connector-connpool-common, set-pointbase-driver-connpool-props, delete-sql-common, deploy-jdbc-driver-common, create-domain-common, delete-jvm-options, create-jdbc-resource-common, prepare-truststore-certutil-common, create-user-common, asadmin-batch-common, delete-user-common, prepare-truststore-keytool-common, convWin, create-persistence-resource-common, get-version-common, startPB, delete-jms-connection-common, usage-common, deploy-war-no-context-root-ee, set-pointbase-connpool-props, usage, convUnix, staticCheck-common, ear-common, deploy-war-name, ] + +setOSConditions: +Override ignored for property "isUnix" + +setToolWin: +Skipped because property 'isWindows' not set. + +setToolUnix: +Override ignored for property "APPCLIENT" +Override ignored for property "ASADMIN" +Override ignored for property "ASANT" +Override ignored for property "CAPTURESCHEMA" +Override ignored for property "CHECKPATCH" +Override ignored for property "INSTALLPATCH" +Override ignored for property "JSPC" +Override ignored for property "LISTPATCH" +Override ignored for property "PACKAGE-APPCLIENT" +Override ignored for property "VERIFIER" +Override ignored for property "RMIC" +Override ignored for property "TNAMESERV" +Override ignored for property "WSCOMPILE" +Override ignored for property "WSIMPORT" +Override ignored for property "pb.start.server" +Override ignored for property "pb.start.server1" +Override ignored for property "IMQDBMGR" +Override ignored for property "ld.library.path" + +setS1ASclassPath: +Skipped because property 's1as.classpath' set. + +init-common: + [echo] Loading props from file /export/work/workspaces/gfv3/appserv-tests/config.properties +Override ignored for property "pe" + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config.properties +Override ignored for property "instance.https.port" +Override ignored for property "admin.domain" +Override ignored for property "admin.password" +Override ignored for property "http.address" +Override ignored for property "http.alternate.port" +Override ignored for property "ssl.password" +Override ignored for property "instance.http.port" +Override ignored for property "resources.dottedname.prefix" +Override ignored for property "results.mailer" +Override ignored for property "admin.domain.dir" +Override ignored for property "admin.user" +Override ignored for property "config.dottedname.prefix" +Override ignored for property "instance.name" +Override ignored for property "precompilejsp" +Override ignored for property "admin.password.file" +Override ignored for property "http.port" +Override ignored for property "https.port" +Override ignored for property "results.mailee" +Override ignored for property "appserver.instance.name" +Override ignored for property "master.password" +Override ignored for property "http.host" +Override ignored for property "instance.http.port.3" +Override ignored for property "instance.http.port.2" +Override ignored for property "admin.port" +Override ignored for property "cluster.name" +Override ignored for property "appserver.instance.dir" +Override ignored for property "autodeploy.dir" +Override ignored for property "orb.port" +Override ignored for property "admin.host" +Override ignored for property "instance.name.3" +Override ignored for property "instance.name.2" +Override ignored for property "results.mailhost" + [echo] admin.domain domain1 + [echo] admin.user admin + [echo] admin.port 4848 + [echo] http.port 8080 + [echo] http.host localhost +Override ignored for property "as.props" +Override ignored for property "authrealmname" +Override ignored for property "apptype" +Override ignored for property "db.root" +Override ignored for property "db.dir" +Override ignored for property "db.classpath" + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config/derby.properties +Override ignored for property "db.host" +Override ignored for property "db.url" +Override ignored for property "db.xaclass" +Override ignored for property "db.name" +Override ignored for property "db.driver" +Override ignored for property "db.port" +Override ignored for property "db.port.2" +Override ignored for property "db.class" +Override ignored for property "db.user" +Override ignored for property "db.pwd" +Override ignored for property "db.type" +Property "env.JAVKE_HOME" has not been set +Override ignored for property "javke.home" +Override ignored for property "dest.type" +Override ignored for property "dest.name" +Override ignored for property "jms.factory.name" +Override ignored for property "jms.factory.type" +Override ignored for property "jms.resource.name" +Override ignored for property "jms.resource.type" +Override ignored for property "jdbc.conpool.name" +Override ignored for property "jdbc.resource.name" +Override ignored for property "jdbc.resource.type" +Override ignored for property "pm.resource.name" +Override ignored for property "pm.factory.class" +Override ignored for property "appclient.application.args" +Override ignored for property "build.base.dir" +Override ignored for property "build.webapps.dir" +Override ignored for property "build.classes.dir" +Override ignored for property "assemble.dir" +Override ignored for property "results.dir" +Property "Derby.classpath" has not been set +Override ignored for property "s1astest.classpath" +Override ignored for property "ejbjar.classes" +Override ignored for property "appclientjar.classes" +Override ignored for property "webclient.war.files" +Override ignored for property "webclient.war.classes" +Override ignored for property "test.name" +Override ignored for property "test.description" +Override ignored for property "test.count" +Override ignored for property "cluster.name" +Override ignored for property "clustered.server.name" +Override ignored for property "clustered.server.name.two" +Override ignored for property "nodeagent.name" +Override ignored for property "das.host" +Override ignored for property "das.jmx.port" +Override ignored for property "http.listener1.port" +Override ignored for property "http.listener2.port" +Override ignored for property "orb.listener1.port" +Override ignored for property "ssl.port" +Override ignored for property "ssl.mutualauth.port" +Override ignored for property "jmx.system.connector.port" +Override ignored for property "http.listener1.port.two" +Override ignored for property "http.listener2.port.two" +Override ignored for property "orb.listener1.port.two" +Override ignored for property "ssl.port.two" +Override ignored for property "ssl.mutualauth.port.two" +Override ignored for property "jmx.system.connector.port.two" +Override ignored for property "cert.nickname" + +clean-classes-common: + [echo] common.xml: Cleaning test source files: /export/work/workspaces/gfv3/appserv-tests/build/module + [delete] Deleting directory /export/work/workspaces/gfv3/appserv-tests/build/module + [delete] Deleting /export/work/workspaces/gfv3/appserv-tests/build/module/classes/TestServlet$1.class + [delete] Deleting /export/work/workspaces/gfv3/appserv-tests/build/module/classes/TestServlet.class + [delete] Deleting /export/work/workspaces/gfv3/appserv-tests/build/module/classes/TestBean.class + [delete] Deleting /export/work/workspaces/gfv3/appserv-tests/build/module/classes/TestLoggerProducer.class + [delete] Deleting /export/work/workspaces/gfv3/appserv-tests/build/module/classes/ClassUnavailableAtRuntime.class + [delete] Deleting /export/work/workspaces/gfv3/appserv-tests/build/module/classes/OptionalService.class + [delete] Deleting directory /export/work/workspaces/gfv3/appserv-tests/build/module/classes + [delete] Deleting directory /export/work/workspaces/gfv3/appserv-tests/build/module + [antcall] Exiting /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml. +Project base dir set to: /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans + [antcall] calling target(s) [clean-jars-common] in build file /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml +parsing buildfile /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml with URI = file:/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml +Project base dir set to: /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/properties.xml +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/common.xml +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.properties +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/run.xml + [property] Loading Environment env. +Override ignored for property "env.SESSION_MANAGER" +Override ignored for property "env.LESSOPEN" +Override ignored for property "env.NORMBGCOLOR" +Override ignored for property "env.CVSROOT" +Override ignored for property "env.MY_ANT_HOME" +Override ignored for property "env.PWD" +Override ignored for property "env.XDG_SESSION_COOKIE" +Override ignored for property "env.LANG" +Override ignored for property "env.WS" +Override ignored for property "env.AWT_TOOLKIT" +Override ignored for property "env.DEFAULTS_PATH" +Override ignored for property "env.HISTSIZE" +Override ignored for property "env.INSTALL_ROOT" +Override ignored for property "env.DISPLAY" +Override ignored for property "env._" +Override ignored for property "env.USER" +Override ignored for property "env.HISTCONTROL" +Override ignored for property "env.SHELL" +Override ignored for property "env.NLSPATH" +Override ignored for property "env.XDG_DATA_DIRS" +Override ignored for property "env.DESKTOP_SESSION" +Override ignored for property "env.HISTFILESIZE" +Override ignored for property "env.APS_HOME" +Override ignored for property "env.WIDTH" +Override ignored for property "env.JAVANETCVSROOT" +Override ignored for property "env.PATH" +Override ignored for property "env.no_proxy" +Override ignored for property "env.NORMFGCOLOR" +Override ignored for property "env.LC_CTYPE" +Override ignored for property "env.DBUS_SESSION_BUS_ADDRESS" +Override ignored for property "env.REALPLAYER_HOME" +Override ignored for property "env.SSH_AGENT_PID" +Override ignored for property "env.SHLVL" +Override ignored for property "env.GDMSESSION" +Override ignored for property "env.GNOME_DESKTOP_SESSION_ID" +Override ignored for property "env.GDM_KEYBOARD_LAYOUT" +Override ignored for property "env.GNOME_KEYRING_PID" +Override ignored for property "env.OS" +Override ignored for property "env.LOGNAME" +Override ignored for property "env.ALSA_OUTPUT_PORTS" +Override ignored for property "env.SCUMMVM_PORT" +Override ignored for property "env.JAVA_HOME" +Override ignored for property "env.TERM" +Override ignored for property "env.QLTESTRES" +Override ignored for property "env.NO_PROXY" +Override ignored for property "env.GDM_LANG" +Override ignored for property "env.DTACH_HOME" +Override ignored for property "env.OLDPWD" +Override ignored for property "env.DEBUG" +Override ignored for property "env.GCONF_LOCAL_LOCKS" +Override ignored for property "env.M2_HOME" +Override ignored for property "env.EC2_CERT" +Override ignored for property "env.WINDOWID" +Override ignored for property "env.EC2_PRIVATE_KEY" +Override ignored for property "env.REDCVSROOT" +Override ignored for property "env.MOZ_DISABLE_PANGO" +Override ignored for property "env.XFILESEARCHPATH" +Override ignored for property "env.HOME" +Override ignored for property "env.ANT_HOME" +Override ignored for property "env.LD_LIBRARY_PATH" +Override ignored for property "env.MAVEN_OPTS" +Override ignored for property "env.SSH_AUTH_SOCK" +Override ignored for property "env.RBARWIDTH" +Override ignored for property "env.S1AS_HOME" +Property "BASH_SOURCE" has not been set +Property "LINENO" has not been set +Property "FUNCNAME[0]" has not been set +Override ignored for property "env.PS4" +Override ignored for property "env.MAVEN_HOME" +Override ignored for property "env.XAUTHORITY" +Property "NEW_PWD" has not been set +Override ignored for property "env.PS1" +Override ignored for property "env.MANDATORY_PATH" +Override ignored for property "env.SPEECHD_PORT" +Override ignored for property "env.GTK_MODULES" +Override ignored for property "env.WINDOW_MANAGER" +Override ignored for property "env.DTRX_HOME" +Override ignored for property "env.COLORTERM" +Override ignored for property "env.EDITOR" +Override ignored for property "env.MALLOC_CHECK_" +Override ignored for property "env.ORBIT_SOCKETDIR" +Override ignored for property "env.WP_INSTALL_ROOT" +Override ignored for property "env.USERNAME" +Override ignored for property "env.SCALA_HOME" +Override ignored for property "env.COPE_PATH" +Override ignored for property "env.QL_HOME" +Override ignored for property "env.AS_ADMIN_READTIMEOUT" +Override ignored for property "env.MY_SCRIPT_DIR" +Override ignored for property "env.GNOME_KEYRING_CONTROL" +Override ignored for property "env.XDG_CONFIG_DIRS" +Override ignored for property "env.TODOTXT_HOME" +Override ignored for property "env.LESSCLOSE" +Override ignored for property "module" +Override ignored for property "appname" +Override ignored for property "assemble" +Override ignored for property "contextroot" +Override ignored for property "beans.xml" +Override ignored for property "target-to-run" + [macrodef] creating macro run-test +Build sequence for target(s) `clean-jars-common' is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-jars-common] +Complete build sequence is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-jars-common, restart-instance-common, execute-sql-common, deploy-rar-common, undeploy, deploy-jdbc-common, undeploy-rar-common, set-derby-connpool-props, create-sql-common, deploy-war-no-context-root-pe, verifier-common, start-server-unix, test-tagfiles-exist, create-PermSize, execute-ejb-sql-common, undeploy-client-common, prepare-keystore-common, deploy-verify-common-ee, startDerby, confirmMissingReport-common, create-connector-resource-common, asadmin-common, create-connector-connpool, delete-connector-connpool-common, verifier, start-clean-server, runwebclient-common, deploy-common-ee, startDerbyNonMac, webclient-war-common, flush-connpool-common, stopDerby, clean-webapps-common, delete-jdbc-connpool-common, prepare-truststore-common, deploy-verify-common, run, test-tlds-exist, deploy-verify-common-pe, undeploy-common, undeploy-jar-common, deploy-client-common, enterprise-common, create-javamail-resource-common, package-persistence-common, deploy-war-commonee, startDomainWindows, set-derby-driver-connpool-props, deploy-war-no-context-root, undeploy-jdbc-common, deploy-common-pe, clear, copy-tagfiles, clean, compile, build, deploy, restart-server-instance-common, deploy-jar-common, delete-domain-common, stopPB, compile-common-with-endorsed-dir, import-wsdl, deploy-war-commonpe, compile-common, restart-server, runclient-common, package-appclientjar-common, ee-common, copy-tlds, delete-persistence-resource-common, undeploy-jms-common, asadmin-common-ignore-fail, startDomainUnix, startDomain, fixFiles, ejb-jar-common, appclient-jar-common, build-ear-common, publish-war-common, build-publish-war, stop-server-unix, clean-classes-common, clean-common, create-jdbc-connpool-common, dev-report, startDerbyMac, deploy-jms-common, package-war-common, package-ejbjar-common, delete-connector-resource-common, deploy-jsp-common, unsetupTimer, undeploy-war-common, change-orb-port, delete-javamail-resource-common, deploy-common, create-jms-resource-common, setup-mq-common, delete-jdbc-resource-common, start-server-windows, dumpThreadStack, setupTimer, deploy-war-common, start-server, ee, checkReporting-common, testTimer, stop-server, create-jdbc-driver-connpool-common, all, platform-common, create-jms-connection-common, undeploy-war-name, cleanAS, deploy-dir, preparePB, stop-server-windows, confirmReportPresent-common, delete-jms-resource-common, pb, runtest, create-jvm-options, restart-instance, stopDomain, create-connector-connpool-common, set-pointbase-driver-connpool-props, delete-sql-common, deploy-jdbc-driver-common, create-domain-common, delete-jvm-options, create-jdbc-resource-common, prepare-truststore-certutil-common, create-user-common, asadmin-batch-common, delete-user-common, prepare-truststore-keytool-common, convWin, create-persistence-resource-common, get-version-common, startPB, delete-jms-connection-common, usage-common, deploy-war-no-context-root-ee, set-pointbase-connpool-props, usage, convUnix, staticCheck-common, ear-common, deploy-war-name, ] + [antcall] Entering /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml... +Build sequence for target(s) `clean-jars-common' is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-jars-common] +Complete build sequence is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-jars-common, restart-instance-common, execute-sql-common, deploy-rar-common, undeploy, deploy-jdbc-common, undeploy-rar-common, set-derby-connpool-props, create-sql-common, deploy-war-no-context-root-pe, verifier-common, start-server-unix, test-tagfiles-exist, create-PermSize, execute-ejb-sql-common, undeploy-client-common, prepare-keystore-common, deploy-verify-common-ee, startDerby, confirmMissingReport-common, create-connector-resource-common, asadmin-common, create-connector-connpool, delete-connector-connpool-common, verifier, start-clean-server, runwebclient-common, deploy-common-ee, startDerbyNonMac, webclient-war-common, flush-connpool-common, stopDerby, clean-webapps-common, delete-jdbc-connpool-common, prepare-truststore-common, deploy-verify-common, run, test-tlds-exist, deploy-verify-common-pe, undeploy-common, undeploy-jar-common, deploy-client-common, enterprise-common, create-javamail-resource-common, package-persistence-common, deploy-war-commonee, startDomainWindows, set-derby-driver-connpool-props, deploy-war-no-context-root, undeploy-jdbc-common, deploy-common-pe, clear, copy-tagfiles, clean, compile, build, deploy, restart-server-instance-common, deploy-jar-common, delete-domain-common, stopPB, compile-common-with-endorsed-dir, import-wsdl, deploy-war-commonpe, compile-common, restart-server, runclient-common, package-appclientjar-common, ee-common, copy-tlds, delete-persistence-resource-common, undeploy-jms-common, asadmin-common-ignore-fail, startDomainUnix, startDomain, fixFiles, ejb-jar-common, appclient-jar-common, build-ear-common, publish-war-common, build-publish-war, stop-server-unix, clean-classes-common, clean-common, create-jdbc-connpool-common, dev-report, startDerbyMac, deploy-jms-common, package-war-common, package-ejbjar-common, delete-connector-resource-common, deploy-jsp-common, unsetupTimer, undeploy-war-common, change-orb-port, delete-javamail-resource-common, deploy-common, create-jms-resource-common, setup-mq-common, delete-jdbc-resource-common, start-server-windows, dumpThreadStack, setupTimer, deploy-war-common, start-server, ee, checkReporting-common, testTimer, stop-server, create-jdbc-driver-connpool-common, all, platform-common, create-jms-connection-common, undeploy-war-name, cleanAS, deploy-dir, preparePB, stop-server-windows, confirmReportPresent-common, delete-jms-resource-common, pb, runtest, create-jvm-options, restart-instance, stopDomain, create-connector-connpool-common, set-pointbase-driver-connpool-props, delete-sql-common, deploy-jdbc-driver-common, create-domain-common, delete-jvm-options, create-jdbc-resource-common, prepare-truststore-certutil-common, create-user-common, asadmin-batch-common, delete-user-common, prepare-truststore-keytool-common, convWin, create-persistence-resource-common, get-version-common, startPB, delete-jms-connection-common, usage-common, deploy-war-no-context-root-ee, set-pointbase-connpool-props, usage, convUnix, staticCheck-common, ear-common, deploy-war-name, ] + +setOSConditions: +Override ignored for property "isUnix" + +setToolWin: +Skipped because property 'isWindows' not set. + +setToolUnix: +Override ignored for property "APPCLIENT" +Override ignored for property "ASADMIN" +Override ignored for property "ASANT" +Override ignored for property "CAPTURESCHEMA" +Override ignored for property "CHECKPATCH" +Override ignored for property "INSTALLPATCH" +Override ignored for property "JSPC" +Override ignored for property "LISTPATCH" +Override ignored for property "PACKAGE-APPCLIENT" +Override ignored for property "VERIFIER" +Override ignored for property "RMIC" +Override ignored for property "TNAMESERV" +Override ignored for property "WSCOMPILE" +Override ignored for property "WSIMPORT" +Override ignored for property "pb.start.server" +Override ignored for property "pb.start.server1" +Override ignored for property "IMQDBMGR" +Override ignored for property "ld.library.path" + +setS1ASclassPath: +Skipped because property 's1as.classpath' set. + +init-common: + [echo] Loading props from file /export/work/workspaces/gfv3/appserv-tests/config.properties +Override ignored for property "pe" + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config.properties +Override ignored for property "instance.https.port" +Override ignored for property "admin.domain" +Override ignored for property "admin.password" +Override ignored for property "http.address" +Override ignored for property "http.alternate.port" +Override ignored for property "ssl.password" +Override ignored for property "instance.http.port" +Override ignored for property "resources.dottedname.prefix" +Override ignored for property "results.mailer" +Override ignored for property "admin.domain.dir" +Override ignored for property "admin.user" +Override ignored for property "config.dottedname.prefix" +Override ignored for property "instance.name" +Override ignored for property "precompilejsp" +Override ignored for property "admin.password.file" +Override ignored for property "http.port" +Override ignored for property "https.port" +Override ignored for property "results.mailee" +Override ignored for property "appserver.instance.name" +Override ignored for property "master.password" +Override ignored for property "http.host" +Override ignored for property "instance.http.port.3" +Override ignored for property "instance.http.port.2" +Override ignored for property "admin.port" +Override ignored for property "cluster.name" +Override ignored for property "appserver.instance.dir" +Override ignored for property "autodeploy.dir" +Override ignored for property "orb.port" +Override ignored for property "admin.host" +Override ignored for property "instance.name.3" +Override ignored for property "instance.name.2" +Override ignored for property "results.mailhost" + [echo] admin.domain domain1 + [echo] admin.user admin + [echo] admin.port 4848 + [echo] http.port 8080 + [echo] http.host localhost +Override ignored for property "as.props" +Override ignored for property "authrealmname" +Override ignored for property "apptype" +Override ignored for property "db.root" +Override ignored for property "db.dir" +Override ignored for property "db.classpath" + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config/derby.properties +Override ignored for property "db.host" +Override ignored for property "db.url" +Override ignored for property "db.xaclass" +Override ignored for property "db.name" +Override ignored for property "db.driver" +Override ignored for property "db.port" +Override ignored for property "db.port.2" +Override ignored for property "db.class" +Override ignored for property "db.user" +Override ignored for property "db.pwd" +Override ignored for property "db.type" +Property "env.JAVKE_HOME" has not been set +Override ignored for property "javke.home" +Override ignored for property "dest.type" +Override ignored for property "dest.name" +Override ignored for property "jms.factory.name" +Override ignored for property "jms.factory.type" +Override ignored for property "jms.resource.name" +Override ignored for property "jms.resource.type" +Override ignored for property "jdbc.conpool.name" +Override ignored for property "jdbc.resource.name" +Override ignored for property "jdbc.resource.type" +Override ignored for property "pm.resource.name" +Override ignored for property "pm.factory.class" +Override ignored for property "appclient.application.args" +Override ignored for property "build.base.dir" +Override ignored for property "build.webapps.dir" +Override ignored for property "build.classes.dir" +Override ignored for property "assemble.dir" +Override ignored for property "results.dir" +Property "Derby.classpath" has not been set +Override ignored for property "s1astest.classpath" +Override ignored for property "ejbjar.classes" +Override ignored for property "appclientjar.classes" +Override ignored for property "webclient.war.files" +Override ignored for property "webclient.war.classes" +Override ignored for property "test.name" +Override ignored for property "test.description" +Override ignored for property "test.count" +Override ignored for property "cluster.name" +Override ignored for property "clustered.server.name" +Override ignored for property "clustered.server.name.two" +Override ignored for property "nodeagent.name" +Override ignored for property "das.host" +Override ignored for property "das.jmx.port" +Override ignored for property "http.listener1.port" +Override ignored for property "http.listener2.port" +Override ignored for property "orb.listener1.port" +Override ignored for property "ssl.port" +Override ignored for property "ssl.mutualauth.port" +Override ignored for property "jmx.system.connector.port" +Override ignored for property "http.listener1.port.two" +Override ignored for property "http.listener2.port.two" +Override ignored for property "orb.listener1.port.two" +Override ignored for property "ssl.port.two" +Override ignored for property "ssl.mutualauth.port.two" +Override ignored for property "jmx.system.connector.port.two" +Override ignored for property "cert.nickname" + [antcall] Exiting /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml. + [antcall] Exiting /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml. +Build sequence for target(s) `compile' is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean, compile] +Complete build sequence is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean, compile, restart-instance-common, execute-sql-common, deploy-rar-common, undeploy, deploy-jdbc-common, undeploy-rar-common, set-derby-connpool-props, create-sql-common, deploy-war-no-context-root-pe, verifier-common, start-server-unix, test-tagfiles-exist, create-PermSize, execute-ejb-sql-common, undeploy-client-common, prepare-keystore-common, deploy-verify-common-ee, startDerby, confirmMissingReport-common, create-connector-resource-common, asadmin-common, create-connector-connpool, delete-connector-connpool-common, verifier, start-clean-server, runwebclient-common, deploy-common-ee, startDerbyNonMac, webclient-war-common, flush-connpool-common, stopDerby, clean-webapps-common, delete-jdbc-connpool-common, prepare-truststore-common, deploy-verify-common, run, test-tlds-exist, deploy-verify-common-pe, undeploy-common, undeploy-jar-common, deploy-client-common, enterprise-common, create-javamail-resource-common, package-persistence-common, deploy-war-commonee, startDomainWindows, set-derby-driver-connpool-props, deploy-war-no-context-root, undeploy-jdbc-common, deploy-common-pe, clear, copy-tagfiles, build, deploy, restart-server-instance-common, deploy-jar-common, delete-domain-common, stopPB, compile-common-with-endorsed-dir, import-wsdl, deploy-war-commonpe, compile-common, restart-server, runclient-common, package-appclientjar-common, ee-common, copy-tlds, delete-persistence-resource-common, undeploy-jms-common, asadmin-common-ignore-fail, startDomainUnix, startDomain, fixFiles, ejb-jar-common, appclient-jar-common, build-ear-common, publish-war-common, build-publish-war, stop-server-unix, clean-classes-common, clean-common, create-jdbc-connpool-common, dev-report, startDerbyMac, deploy-jms-common, package-war-common, package-ejbjar-common, delete-connector-resource-common, deploy-jsp-common, unsetupTimer, undeploy-war-common, change-orb-port, delete-javamail-resource-common, deploy-common, create-jms-resource-common, setup-mq-common, delete-jdbc-resource-common, start-server-windows, dumpThreadStack, setupTimer, deploy-war-common, start-server, ee, checkReporting-common, testTimer, stop-server, create-jdbc-driver-connpool-common, all, platform-common, create-jms-connection-common, undeploy-war-name, cleanAS, deploy-dir, preparePB, stop-server-windows, confirmReportPresent-common, delete-jms-resource-common, pb, runtest, create-jvm-options, clean-jars-common, restart-instance, stopDomain, create-connector-connpool-common, set-pointbase-driver-connpool-props, delete-sql-common, deploy-jdbc-driver-common, create-domain-common, delete-jvm-options, create-jdbc-resource-common, prepare-truststore-certutil-common, create-user-common, asadmin-batch-common, delete-user-common, prepare-truststore-keytool-common, convWin, create-persistence-resource-common, get-version-common, startPB, delete-jms-connection-common, usage-common, deploy-war-no-context-root-ee, set-pointbase-connpool-props, usage, convUnix, staticCheck-common, ear-common, deploy-war-name, ] + +setOSConditions: +Override ignored for property "isUnix" + +setToolWin: +Skipped because property 'isWindows' not set. + +setToolUnix: +Override ignored for property "APPCLIENT" +Override ignored for property "ASADMIN" +Override ignored for property "ASANT" +Override ignored for property "CAPTURESCHEMA" +Override ignored for property "CHECKPATCH" +Override ignored for property "INSTALLPATCH" +Override ignored for property "JSPC" +Override ignored for property "LISTPATCH" +Override ignored for property "PACKAGE-APPCLIENT" +Override ignored for property "VERIFIER" +Override ignored for property "RMIC" +Override ignored for property "TNAMESERV" +Override ignored for property "WSCOMPILE" +Override ignored for property "WSIMPORT" +Override ignored for property "pb.start.server" +Override ignored for property "pb.start.server1" +Override ignored for property "IMQDBMGR" +Override ignored for property "ld.library.path" + +setS1ASclassPath: +Skipped because property 's1as.classpath' set. + +init-common: + [echo] Loading props from file /export/work/workspaces/gfv3/appserv-tests/config.properties +Override ignored for property "pe" + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config.properties +Override ignored for property "instance.https.port" +Override ignored for property "admin.domain" +Override ignored for property "admin.password" +Override ignored for property "http.address" +Override ignored for property "http.alternate.port" +Override ignored for property "ssl.password" +Override ignored for property "instance.http.port" +Override ignored for property "resources.dottedname.prefix" +Override ignored for property "results.mailer" +Override ignored for property "admin.domain.dir" +Override ignored for property "admin.user" +Override ignored for property "config.dottedname.prefix" +Override ignored for property "instance.name" +Override ignored for property "precompilejsp" +Override ignored for property "admin.password.file" +Override ignored for property "http.port" +Override ignored for property "https.port" +Override ignored for property "results.mailee" +Override ignored for property "appserver.instance.name" +Override ignored for property "master.password" +Override ignored for property "http.host" +Override ignored for property "instance.http.port.3" +Override ignored for property "instance.http.port.2" +Override ignored for property "admin.port" +Override ignored for property "cluster.name" +Override ignored for property "appserver.instance.dir" +Override ignored for property "autodeploy.dir" +Override ignored for property "orb.port" +Override ignored for property "admin.host" +Override ignored for property "instance.name.3" +Override ignored for property "instance.name.2" +Override ignored for property "results.mailhost" + [echo] admin.domain domain1 + [echo] admin.user admin + [echo] admin.port 4848 + [echo] http.port 8080 + [echo] http.host localhost +Override ignored for property "as.props" +Override ignored for property "authrealmname" +Override ignored for property "apptype" +Override ignored for property "db.root" +Override ignored for property "db.dir" +Override ignored for property "db.classpath" + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config/derby.properties +Override ignored for property "db.host" +Override ignored for property "db.url" +Override ignored for property "db.xaclass" +Override ignored for property "db.name" +Override ignored for property "db.driver" +Override ignored for property "db.port" +Override ignored for property "db.port.2" +Override ignored for property "db.class" +Override ignored for property "db.user" +Override ignored for property "db.pwd" +Override ignored for property "db.type" +Property "env.JAVKE_HOME" has not been set +Override ignored for property "javke.home" +Override ignored for property "dest.type" +Override ignored for property "dest.name" +Override ignored for property "jms.factory.name" +Override ignored for property "jms.factory.type" +Override ignored for property "jms.resource.name" +Override ignored for property "jms.resource.type" +Override ignored for property "jdbc.conpool.name" +Override ignored for property "jdbc.resource.name" +Override ignored for property "jdbc.resource.type" +Override ignored for property "pm.resource.name" +Override ignored for property "pm.factory.class" +Override ignored for property "appclient.application.args" +Override ignored for property "build.base.dir" +Override ignored for property "build.webapps.dir" +Override ignored for property "build.classes.dir" +Override ignored for property "assemble.dir" +Override ignored for property "results.dir" +Property "Derby.classpath" has not been set +Override ignored for property "s1astest.classpath" +Override ignored for property "ejbjar.classes" +Override ignored for property "appclientjar.classes" +Override ignored for property "webclient.war.files" +Override ignored for property "webclient.war.classes" +Override ignored for property "test.name" +Override ignored for property "test.description" +Override ignored for property "test.count" +Override ignored for property "cluster.name" +Override ignored for property "clustered.server.name" +Override ignored for property "clustered.server.name.two" +Override ignored for property "nodeagent.name" +Override ignored for property "das.host" +Override ignored for property "das.jmx.port" +Override ignored for property "http.listener1.port" +Override ignored for property "http.listener2.port" +Override ignored for property "orb.listener1.port" +Override ignored for property "ssl.port" +Override ignored for property "ssl.mutualauth.port" +Override ignored for property "jmx.system.connector.port" +Override ignored for property "http.listener1.port.two" +Override ignored for property "http.listener2.port.two" +Override ignored for property "orb.listener1.port.two" +Override ignored for property "ssl.port.two" +Override ignored for property "ssl.mutualauth.port.two" +Override ignored for property "jmx.system.connector.port.two" +Override ignored for property "cert.nickname" + +clean: +Project base dir set to: /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans + [antcall] calling target(s) [clean-common] in build file /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml +parsing buildfile /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml with URI = file:/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml +Project base dir set to: /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/properties.xml +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/common.xml +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.properties +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/run.xml + [property] Loading Environment env. +Override ignored for property "env.SESSION_MANAGER" +Override ignored for property "env.LESSOPEN" +Override ignored for property "env.NORMBGCOLOR" +Override ignored for property "env.CVSROOT" +Override ignored for property "env.MY_ANT_HOME" +Override ignored for property "env.PWD" +Override ignored for property "env.XDG_SESSION_COOKIE" +Override ignored for property "env.LANG" +Override ignored for property "env.WS" +Override ignored for property "env.AWT_TOOLKIT" +Override ignored for property "env.DEFAULTS_PATH" +Override ignored for property "env.HISTSIZE" +Override ignored for property "env.INSTALL_ROOT" +Override ignored for property "env.DISPLAY" +Override ignored for property "env._" +Override ignored for property "env.USER" +Override ignored for property "env.HISTCONTROL" +Override ignored for property "env.SHELL" +Override ignored for property "env.NLSPATH" +Override ignored for property "env.XDG_DATA_DIRS" +Override ignored for property "env.DESKTOP_SESSION" +Override ignored for property "env.HISTFILESIZE" +Override ignored for property "env.APS_HOME" +Override ignored for property "env.WIDTH" +Override ignored for property "env.JAVANETCVSROOT" +Override ignored for property "env.PATH" +Override ignored for property "env.no_proxy" +Override ignored for property "env.NORMFGCOLOR" +Override ignored for property "env.LC_CTYPE" +Override ignored for property "env.DBUS_SESSION_BUS_ADDRESS" +Override ignored for property "env.REALPLAYER_HOME" +Override ignored for property "env.SSH_AGENT_PID" +Override ignored for property "env.SHLVL" +Override ignored for property "env.GDMSESSION" +Override ignored for property "env.GNOME_DESKTOP_SESSION_ID" +Override ignored for property "env.GDM_KEYBOARD_LAYOUT" +Override ignored for property "env.GNOME_KEYRING_PID" +Override ignored for property "env.OS" +Override ignored for property "env.LOGNAME" +Override ignored for property "env.ALSA_OUTPUT_PORTS" +Override ignored for property "env.SCUMMVM_PORT" +Override ignored for property "env.JAVA_HOME" +Override ignored for property "env.TERM" +Override ignored for property "env.QLTESTRES" +Override ignored for property "env.NO_PROXY" +Override ignored for property "env.GDM_LANG" +Override ignored for property "env.DTACH_HOME" +Override ignored for property "env.OLDPWD" +Override ignored for property "env.DEBUG" +Override ignored for property "env.GCONF_LOCAL_LOCKS" +Override ignored for property "env.M2_HOME" +Override ignored for property "env.EC2_CERT" +Override ignored for property "env.WINDOWID" +Override ignored for property "env.EC2_PRIVATE_KEY" +Override ignored for property "env.REDCVSROOT" +Override ignored for property "env.MOZ_DISABLE_PANGO" +Override ignored for property "env.XFILESEARCHPATH" +Override ignored for property "env.HOME" +Override ignored for property "env.ANT_HOME" +Override ignored for property "env.LD_LIBRARY_PATH" +Override ignored for property "env.MAVEN_OPTS" +Override ignored for property "env.SSH_AUTH_SOCK" +Override ignored for property "env.RBARWIDTH" +Override ignored for property "env.S1AS_HOME" +Property "BASH_SOURCE" has not been set +Property "LINENO" has not been set +Property "FUNCNAME[0]" has not been set +Override ignored for property "env.PS4" +Override ignored for property "env.MAVEN_HOME" +Override ignored for property "env.XAUTHORITY" +Property "NEW_PWD" has not been set +Override ignored for property "env.PS1" +Override ignored for property "env.MANDATORY_PATH" +Override ignored for property "env.SPEECHD_PORT" +Override ignored for property "env.GTK_MODULES" +Override ignored for property "env.WINDOW_MANAGER" +Override ignored for property "env.DTRX_HOME" +Override ignored for property "env.COLORTERM" +Override ignored for property "env.EDITOR" +Override ignored for property "env.MALLOC_CHECK_" +Override ignored for property "env.ORBIT_SOCKETDIR" +Override ignored for property "env.WP_INSTALL_ROOT" +Override ignored for property "env.USERNAME" +Override ignored for property "env.SCALA_HOME" +Override ignored for property "env.COPE_PATH" +Override ignored for property "env.QL_HOME" +Override ignored for property "env.AS_ADMIN_READTIMEOUT" +Override ignored for property "env.MY_SCRIPT_DIR" +Override ignored for property "env.GNOME_KEYRING_CONTROL" +Override ignored for property "env.XDG_CONFIG_DIRS" +Override ignored for property "env.TODOTXT_HOME" +Override ignored for property "env.LESSCLOSE" +Override ignored for property "module" +Override ignored for property "appname" +Override ignored for property "assemble" +Override ignored for property "contextroot" +Override ignored for property "beans.xml" +Override ignored for property "target-to-run" + [macrodef] creating macro run-test +Build sequence for target(s) `clean-common' is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-common] +Complete build sequence is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-common, restart-instance-common, execute-sql-common, deploy-rar-common, undeploy, deploy-jdbc-common, undeploy-rar-common, set-derby-connpool-props, create-sql-common, deploy-war-no-context-root-pe, verifier-common, start-server-unix, test-tagfiles-exist, create-PermSize, execute-ejb-sql-common, undeploy-client-common, prepare-keystore-common, deploy-verify-common-ee, startDerby, confirmMissingReport-common, create-connector-resource-common, asadmin-common, create-connector-connpool, delete-connector-connpool-common, verifier, start-clean-server, runwebclient-common, deploy-common-ee, startDerbyNonMac, webclient-war-common, flush-connpool-common, stopDerby, clean-webapps-common, delete-jdbc-connpool-common, prepare-truststore-common, deploy-verify-common, run, test-tlds-exist, deploy-verify-common-pe, undeploy-common, undeploy-jar-common, deploy-client-common, enterprise-common, create-javamail-resource-common, package-persistence-common, deploy-war-commonee, startDomainWindows, set-derby-driver-connpool-props, deploy-war-no-context-root, undeploy-jdbc-common, deploy-common-pe, clear, copy-tagfiles, clean, compile, build, deploy, restart-server-instance-common, deploy-jar-common, delete-domain-common, stopPB, compile-common-with-endorsed-dir, import-wsdl, deploy-war-commonpe, compile-common, restart-server, runclient-common, package-appclientjar-common, ee-common, copy-tlds, delete-persistence-resource-common, undeploy-jms-common, asadmin-common-ignore-fail, startDomainUnix, startDomain, fixFiles, ejb-jar-common, appclient-jar-common, build-ear-common, publish-war-common, build-publish-war, stop-server-unix, clean-classes-common, create-jdbc-connpool-common, dev-report, startDerbyMac, deploy-jms-common, package-war-common, package-ejbjar-common, delete-connector-resource-common, deploy-jsp-common, unsetupTimer, undeploy-war-common, change-orb-port, delete-javamail-resource-common, deploy-common, create-jms-resource-common, setup-mq-common, delete-jdbc-resource-common, start-server-windows, dumpThreadStack, setupTimer, deploy-war-common, start-server, ee, checkReporting-common, testTimer, stop-server, create-jdbc-driver-connpool-common, all, platform-common, create-jms-connection-common, undeploy-war-name, cleanAS, deploy-dir, preparePB, stop-server-windows, confirmReportPresent-common, delete-jms-resource-common, pb, runtest, create-jvm-options, clean-jars-common, restart-instance, stopDomain, create-connector-connpool-common, set-pointbase-driver-connpool-props, delete-sql-common, deploy-jdbc-driver-common, create-domain-common, delete-jvm-options, create-jdbc-resource-common, prepare-truststore-certutil-common, create-user-common, asadmin-batch-common, delete-user-common, prepare-truststore-keytool-common, convWin, create-persistence-resource-common, get-version-common, startPB, delete-jms-connection-common, usage-common, deploy-war-no-context-root-ee, set-pointbase-connpool-props, usage, convUnix, staticCheck-common, ear-common, deploy-war-name, ] + [antcall] Entering /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml... +Build sequence for target(s) `clean-common' is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-common] +Complete build sequence is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-common, restart-instance-common, execute-sql-common, deploy-rar-common, undeploy, deploy-jdbc-common, undeploy-rar-common, set-derby-connpool-props, create-sql-common, deploy-war-no-context-root-pe, verifier-common, start-server-unix, test-tagfiles-exist, create-PermSize, execute-ejb-sql-common, undeploy-client-common, prepare-keystore-common, deploy-verify-common-ee, startDerby, confirmMissingReport-common, create-connector-resource-common, asadmin-common, create-connector-connpool, delete-connector-connpool-common, verifier, start-clean-server, runwebclient-common, deploy-common-ee, startDerbyNonMac, webclient-war-common, flush-connpool-common, stopDerby, clean-webapps-common, delete-jdbc-connpool-common, prepare-truststore-common, deploy-verify-common, run, test-tlds-exist, deploy-verify-common-pe, undeploy-common, undeploy-jar-common, deploy-client-common, enterprise-common, create-javamail-resource-common, package-persistence-common, deploy-war-commonee, startDomainWindows, set-derby-driver-connpool-props, deploy-war-no-context-root, undeploy-jdbc-common, deploy-common-pe, clear, copy-tagfiles, clean, compile, build, deploy, restart-server-instance-common, deploy-jar-common, delete-domain-common, stopPB, compile-common-with-endorsed-dir, import-wsdl, deploy-war-commonpe, compile-common, restart-server, runclient-common, package-appclientjar-common, ee-common, copy-tlds, delete-persistence-resource-common, undeploy-jms-common, asadmin-common-ignore-fail, startDomainUnix, startDomain, fixFiles, ejb-jar-common, appclient-jar-common, build-ear-common, publish-war-common, build-publish-war, stop-server-unix, clean-classes-common, create-jdbc-connpool-common, dev-report, startDerbyMac, deploy-jms-common, package-war-common, package-ejbjar-common, delete-connector-resource-common, deploy-jsp-common, unsetupTimer, undeploy-war-common, change-orb-port, delete-javamail-resource-common, deploy-common, create-jms-resource-common, setup-mq-common, delete-jdbc-resource-common, start-server-windows, dumpThreadStack, setupTimer, deploy-war-common, start-server, ee, checkReporting-common, testTimer, stop-server, create-jdbc-driver-connpool-common, all, platform-common, create-jms-connection-common, undeploy-war-name, cleanAS, deploy-dir, preparePB, stop-server-windows, confirmReportPresent-common, delete-jms-resource-common, pb, runtest, create-jvm-options, clean-jars-common, restart-instance, stopDomain, create-connector-connpool-common, set-pointbase-driver-connpool-props, delete-sql-common, deploy-jdbc-driver-common, create-domain-common, delete-jvm-options, create-jdbc-resource-common, prepare-truststore-certutil-common, create-user-common, asadmin-batch-common, delete-user-common, prepare-truststore-keytool-common, convWin, create-persistence-resource-common, get-version-common, startPB, delete-jms-connection-common, usage-common, deploy-war-no-context-root-ee, set-pointbase-connpool-props, usage, convUnix, staticCheck-common, ear-common, deploy-war-name, ] + +setOSConditions: +Override ignored for property "isUnix" + +setToolWin: +Skipped because property 'isWindows' not set. + +setToolUnix: +Override ignored for property "APPCLIENT" +Override ignored for property "ASADMIN" +Override ignored for property "ASANT" +Override ignored for property "CAPTURESCHEMA" +Override ignored for property "CHECKPATCH" +Override ignored for property "INSTALLPATCH" +Override ignored for property "JSPC" +Override ignored for property "LISTPATCH" +Override ignored for property "PACKAGE-APPCLIENT" +Override ignored for property "VERIFIER" +Override ignored for property "RMIC" +Override ignored for property "TNAMESERV" +Override ignored for property "WSCOMPILE" +Override ignored for property "WSIMPORT" +Override ignored for property "pb.start.server" +Override ignored for property "pb.start.server1" +Override ignored for property "IMQDBMGR" +Override ignored for property "ld.library.path" + +setS1ASclassPath: +Skipped because property 's1as.classpath' set. + +init-common: + [echo] Loading props from file /export/work/workspaces/gfv3/appserv-tests/config.properties +Override ignored for property "pe" + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config.properties +Override ignored for property "instance.https.port" +Override ignored for property "admin.domain" +Override ignored for property "admin.password" +Override ignored for property "http.address" +Override ignored for property "http.alternate.port" +Override ignored for property "ssl.password" +Override ignored for property "instance.http.port" +Override ignored for property "resources.dottedname.prefix" +Override ignored for property "results.mailer" +Override ignored for property "admin.domain.dir" +Override ignored for property "admin.user" +Override ignored for property "config.dottedname.prefix" +Override ignored for property "instance.name" +Override ignored for property "precompilejsp" +Override ignored for property "admin.password.file" +Override ignored for property "http.port" +Override ignored for property "https.port" +Override ignored for property "results.mailee" +Override ignored for property "appserver.instance.name" +Override ignored for property "master.password" +Override ignored for property "http.host" +Override ignored for property "instance.http.port.3" +Override ignored for property "instance.http.port.2" +Override ignored for property "admin.port" +Override ignored for property "cluster.name" +Override ignored for property "appserver.instance.dir" +Override ignored for property "autodeploy.dir" +Override ignored for property "orb.port" +Override ignored for property "admin.host" +Override ignored for property "instance.name.3" +Override ignored for property "instance.name.2" +Override ignored for property "results.mailhost" + [echo] admin.domain domain1 + [echo] admin.user admin + [echo] admin.port 4848 + [echo] http.port 8080 + [echo] http.host localhost +Override ignored for property "as.props" +Override ignored for property "authrealmname" +Override ignored for property "apptype" +Override ignored for property "db.root" +Override ignored for property "db.dir" +Override ignored for property "db.classpath" + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config/derby.properties +Override ignored for property "db.host" +Override ignored for property "db.url" +Override ignored for property "db.xaclass" +Override ignored for property "db.name" +Override ignored for property "db.driver" +Override ignored for property "db.port" +Override ignored for property "db.port.2" +Override ignored for property "db.class" +Override ignored for property "db.user" +Override ignored for property "db.pwd" +Override ignored for property "db.type" +Property "env.JAVKE_HOME" has not been set +Override ignored for property "javke.home" +Override ignored for property "dest.type" +Override ignored for property "dest.name" +Override ignored for property "jms.factory.name" +Override ignored for property "jms.factory.type" +Override ignored for property "jms.resource.name" +Override ignored for property "jms.resource.type" +Override ignored for property "jdbc.conpool.name" +Override ignored for property "jdbc.resource.name" +Override ignored for property "jdbc.resource.type" +Override ignored for property "pm.resource.name" +Override ignored for property "pm.factory.class" +Override ignored for property "appclient.application.args" +Override ignored for property "build.base.dir" +Override ignored for property "build.webapps.dir" +Override ignored for property "build.classes.dir" +Override ignored for property "assemble.dir" +Override ignored for property "results.dir" +Property "Derby.classpath" has not been set +Override ignored for property "s1astest.classpath" +Override ignored for property "ejbjar.classes" +Override ignored for property "appclientjar.classes" +Override ignored for property "webclient.war.files" +Override ignored for property "webclient.war.classes" +Override ignored for property "test.name" +Override ignored for property "test.description" +Override ignored for property "test.count" +Override ignored for property "cluster.name" +Override ignored for property "clustered.server.name" +Override ignored for property "clustered.server.name.two" +Override ignored for property "nodeagent.name" +Override ignored for property "das.host" +Override ignored for property "das.jmx.port" +Override ignored for property "http.listener1.port" +Override ignored for property "http.listener2.port" +Override ignored for property "orb.listener1.port" +Override ignored for property "ssl.port" +Override ignored for property "ssl.mutualauth.port" +Override ignored for property "jmx.system.connector.port" +Override ignored for property "http.listener1.port.two" +Override ignored for property "http.listener2.port.two" +Override ignored for property "orb.listener1.port.two" +Override ignored for property "ssl.port.two" +Override ignored for property "ssl.mutualauth.port.two" +Override ignored for property "jmx.system.connector.port.two" +Override ignored for property "cert.nickname" + +clean-common: +Project base dir set to: /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans + [antcall] calling target(s) [clean-classes-common] in build file /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml +parsing buildfile /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml with URI = file:/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml +Project base dir set to: /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/properties.xml +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/common.xml +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.properties +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/run.xml + [property] Loading Environment env. +Override ignored for property "env.SESSION_MANAGER" +Override ignored for property "env.LESSOPEN" +Override ignored for property "env.NORMBGCOLOR" +Override ignored for property "env.CVSROOT" +Override ignored for property "env.MY_ANT_HOME" +Override ignored for property "env.PWD" +Override ignored for property "env.XDG_SESSION_COOKIE" +Override ignored for property "env.LANG" +Override ignored for property "env.WS" +Override ignored for property "env.AWT_TOOLKIT" +Override ignored for property "env.DEFAULTS_PATH" +Override ignored for property "env.HISTSIZE" +Override ignored for property "env.INSTALL_ROOT" +Override ignored for property "env.DISPLAY" +Override ignored for property "env._" +Override ignored for property "env.USER" +Override ignored for property "env.HISTCONTROL" +Override ignored for property "env.SHELL" +Override ignored for property "env.NLSPATH" +Override ignored for property "env.XDG_DATA_DIRS" +Override ignored for property "env.DESKTOP_SESSION" +Override ignored for property "env.HISTFILESIZE" +Override ignored for property "env.APS_HOME" +Override ignored for property "env.WIDTH" +Override ignored for property "env.JAVANETCVSROOT" +Override ignored for property "env.PATH" +Override ignored for property "env.no_proxy" +Override ignored for property "env.NORMFGCOLOR" +Override ignored for property "env.LC_CTYPE" +Override ignored for property "env.DBUS_SESSION_BUS_ADDRESS" +Override ignored for property "env.REALPLAYER_HOME" +Override ignored for property "env.SSH_AGENT_PID" +Override ignored for property "env.SHLVL" +Override ignored for property "env.GDMSESSION" +Override ignored for property "env.GNOME_DESKTOP_SESSION_ID" +Override ignored for property "env.GDM_KEYBOARD_LAYOUT" +Override ignored for property "env.GNOME_KEYRING_PID" +Override ignored for property "env.OS" +Override ignored for property "env.LOGNAME" +Override ignored for property "env.ALSA_OUTPUT_PORTS" +Override ignored for property "env.SCUMMVM_PORT" +Override ignored for property "env.JAVA_HOME" +Override ignored for property "env.TERM" +Override ignored for property "env.QLTESTRES" +Override ignored for property "env.NO_PROXY" +Override ignored for property "env.GDM_LANG" +Override ignored for property "env.DTACH_HOME" +Override ignored for property "env.OLDPWD" +Override ignored for property "env.DEBUG" +Override ignored for property "env.GCONF_LOCAL_LOCKS" +Override ignored for property "env.M2_HOME" +Override ignored for property "env.EC2_CERT" +Override ignored for property "env.WINDOWID" +Override ignored for property "env.EC2_PRIVATE_KEY" +Override ignored for property "env.REDCVSROOT" +Override ignored for property "env.MOZ_DISABLE_PANGO" +Override ignored for property "env.XFILESEARCHPATH" +Override ignored for property "env.HOME" +Override ignored for property "env.ANT_HOME" +Override ignored for property "env.LD_LIBRARY_PATH" +Override ignored for property "env.MAVEN_OPTS" +Override ignored for property "env.SSH_AUTH_SOCK" +Override ignored for property "env.RBARWIDTH" +Override ignored for property "env.S1AS_HOME" +Property "BASH_SOURCE" has not been set +Property "LINENO" has not been set +Property "FUNCNAME[0]" has not been set +Override ignored for property "env.PS4" +Override ignored for property "env.MAVEN_HOME" +Override ignored for property "env.XAUTHORITY" +Property "NEW_PWD" has not been set +Override ignored for property "env.PS1" +Override ignored for property "env.MANDATORY_PATH" +Override ignored for property "env.SPEECHD_PORT" +Override ignored for property "env.GTK_MODULES" +Override ignored for property "env.WINDOW_MANAGER" +Override ignored for property "env.DTRX_HOME" +Override ignored for property "env.COLORTERM" +Override ignored for property "env.EDITOR" +Override ignored for property "env.MALLOC_CHECK_" +Override ignored for property "env.ORBIT_SOCKETDIR" +Override ignored for property "env.WP_INSTALL_ROOT" +Override ignored for property "env.USERNAME" +Override ignored for property "env.SCALA_HOME" +Override ignored for property "env.COPE_PATH" +Override ignored for property "env.QL_HOME" +Override ignored for property "env.AS_ADMIN_READTIMEOUT" +Override ignored for property "env.MY_SCRIPT_DIR" +Override ignored for property "env.GNOME_KEYRING_CONTROL" +Override ignored for property "env.XDG_CONFIG_DIRS" +Override ignored for property "env.TODOTXT_HOME" +Override ignored for property "env.LESSCLOSE" +Override ignored for property "module" +Override ignored for property "appname" +Override ignored for property "assemble" +Override ignored for property "contextroot" +Override ignored for property "beans.xml" +Override ignored for property "target-to-run" + [macrodef] creating macro run-test +Build sequence for target(s) `clean-classes-common' is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-classes-common] +Complete build sequence is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-classes-common, restart-instance-common, execute-sql-common, deploy-rar-common, undeploy, deploy-jdbc-common, undeploy-rar-common, set-derby-connpool-props, create-sql-common, deploy-war-no-context-root-pe, verifier-common, start-server-unix, test-tagfiles-exist, create-PermSize, execute-ejb-sql-common, undeploy-client-common, prepare-keystore-common, deploy-verify-common-ee, startDerby, confirmMissingReport-common, create-connector-resource-common, asadmin-common, create-connector-connpool, delete-connector-connpool-common, verifier, start-clean-server, runwebclient-common, deploy-common-ee, startDerbyNonMac, webclient-war-common, flush-connpool-common, stopDerby, clean-webapps-common, delete-jdbc-connpool-common, prepare-truststore-common, deploy-verify-common, run, test-tlds-exist, deploy-verify-common-pe, undeploy-common, undeploy-jar-common, deploy-client-common, enterprise-common, create-javamail-resource-common, package-persistence-common, deploy-war-commonee, startDomainWindows, set-derby-driver-connpool-props, deploy-war-no-context-root, undeploy-jdbc-common, deploy-common-pe, clear, copy-tagfiles, clean, compile, build, deploy, restart-server-instance-common, deploy-jar-common, delete-domain-common, stopPB, compile-common-with-endorsed-dir, import-wsdl, deploy-war-commonpe, compile-common, restart-server, runclient-common, package-appclientjar-common, ee-common, copy-tlds, delete-persistence-resource-common, undeploy-jms-common, asadmin-common-ignore-fail, startDomainUnix, startDomain, fixFiles, ejb-jar-common, appclient-jar-common, build-ear-common, publish-war-common, build-publish-war, stop-server-unix, clean-common, create-jdbc-connpool-common, dev-report, startDerbyMac, deploy-jms-common, package-war-common, package-ejbjar-common, delete-connector-resource-common, deploy-jsp-common, unsetupTimer, undeploy-war-common, change-orb-port, delete-javamail-resource-common, deploy-common, create-jms-resource-common, setup-mq-common, delete-jdbc-resource-common, start-server-windows, dumpThreadStack, setupTimer, deploy-war-common, start-server, ee, checkReporting-common, testTimer, stop-server, create-jdbc-driver-connpool-common, all, platform-common, create-jms-connection-common, undeploy-war-name, cleanAS, deploy-dir, preparePB, stop-server-windows, confirmReportPresent-common, delete-jms-resource-common, pb, runtest, create-jvm-options, clean-jars-common, restart-instance, stopDomain, create-connector-connpool-common, set-pointbase-driver-connpool-props, delete-sql-common, deploy-jdbc-driver-common, create-domain-common, delete-jvm-options, create-jdbc-resource-common, prepare-truststore-certutil-common, create-user-common, asadmin-batch-common, delete-user-common, prepare-truststore-keytool-common, convWin, create-persistence-resource-common, get-version-common, startPB, delete-jms-connection-common, usage-common, deploy-war-no-context-root-ee, set-pointbase-connpool-props, usage, convUnix, staticCheck-common, ear-common, deploy-war-name, ] + [antcall] Entering /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml... +Build sequence for target(s) `clean-classes-common' is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-classes-common] +Complete build sequence is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-classes-common, restart-instance-common, execute-sql-common, deploy-rar-common, undeploy, deploy-jdbc-common, undeploy-rar-common, set-derby-connpool-props, create-sql-common, deploy-war-no-context-root-pe, verifier-common, start-server-unix, test-tagfiles-exist, create-PermSize, execute-ejb-sql-common, undeploy-client-common, prepare-keystore-common, deploy-verify-common-ee, startDerby, confirmMissingReport-common, create-connector-resource-common, asadmin-common, create-connector-connpool, delete-connector-connpool-common, verifier, start-clean-server, runwebclient-common, deploy-common-ee, startDerbyNonMac, webclient-war-common, flush-connpool-common, stopDerby, clean-webapps-common, delete-jdbc-connpool-common, prepare-truststore-common, deploy-verify-common, run, test-tlds-exist, deploy-verify-common-pe, undeploy-common, undeploy-jar-common, deploy-client-common, enterprise-common, create-javamail-resource-common, package-persistence-common, deploy-war-commonee, startDomainWindows, set-derby-driver-connpool-props, deploy-war-no-context-root, undeploy-jdbc-common, deploy-common-pe, clear, copy-tagfiles, clean, compile, build, deploy, restart-server-instance-common, deploy-jar-common, delete-domain-common, stopPB, compile-common-with-endorsed-dir, import-wsdl, deploy-war-commonpe, compile-common, restart-server, runclient-common, package-appclientjar-common, ee-common, copy-tlds, delete-persistence-resource-common, undeploy-jms-common, asadmin-common-ignore-fail, startDomainUnix, startDomain, fixFiles, ejb-jar-common, appclient-jar-common, build-ear-common, publish-war-common, build-publish-war, stop-server-unix, clean-common, create-jdbc-connpool-common, dev-report, startDerbyMac, deploy-jms-common, package-war-common, package-ejbjar-common, delete-connector-resource-common, deploy-jsp-common, unsetupTimer, undeploy-war-common, change-orb-port, delete-javamail-resource-common, deploy-common, create-jms-resource-common, setup-mq-common, delete-jdbc-resource-common, start-server-windows, dumpThreadStack, setupTimer, deploy-war-common, start-server, ee, checkReporting-common, testTimer, stop-server, create-jdbc-driver-connpool-common, all, platform-common, create-jms-connection-common, undeploy-war-name, cleanAS, deploy-dir, preparePB, stop-server-windows, confirmReportPresent-common, delete-jms-resource-common, pb, runtest, create-jvm-options, clean-jars-common, restart-instance, stopDomain, create-connector-connpool-common, set-pointbase-driver-connpool-props, delete-sql-common, deploy-jdbc-driver-common, create-domain-common, delete-jvm-options, create-jdbc-resource-common, prepare-truststore-certutil-common, create-user-common, asadmin-batch-common, delete-user-common, prepare-truststore-keytool-common, convWin, create-persistence-resource-common, get-version-common, startPB, delete-jms-connection-common, usage-common, deploy-war-no-context-root-ee, set-pointbase-connpool-props, usage, convUnix, staticCheck-common, ear-common, deploy-war-name, ] + +setOSConditions: +Override ignored for property "isUnix" + +setToolWin: +Skipped because property 'isWindows' not set. + +setToolUnix: +Override ignored for property "APPCLIENT" +Override ignored for property "ASADMIN" +Override ignored for property "ASANT" +Override ignored for property "CAPTURESCHEMA" +Override ignored for property "CHECKPATCH" +Override ignored for property "INSTALLPATCH" +Override ignored for property "JSPC" +Override ignored for property "LISTPATCH" +Override ignored for property "PACKAGE-APPCLIENT" +Override ignored for property "VERIFIER" +Override ignored for property "RMIC" +Override ignored for property "TNAMESERV" +Override ignored for property "WSCOMPILE" +Override ignored for property "WSIMPORT" +Override ignored for property "pb.start.server" +Override ignored for property "pb.start.server1" +Override ignored for property "IMQDBMGR" +Override ignored for property "ld.library.path" + +setS1ASclassPath: +Skipped because property 's1as.classpath' set. + +init-common: + [echo] Loading props from file /export/work/workspaces/gfv3/appserv-tests/config.properties +Override ignored for property "pe" + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config.properties +Override ignored for property "instance.https.port" +Override ignored for property "admin.domain" +Override ignored for property "admin.password" +Override ignored for property "http.address" +Override ignored for property "http.alternate.port" +Override ignored for property "ssl.password" +Override ignored for property "instance.http.port" +Override ignored for property "resources.dottedname.prefix" +Override ignored for property "results.mailer" +Override ignored for property "admin.domain.dir" +Override ignored for property "admin.user" +Override ignored for property "config.dottedname.prefix" +Override ignored for property "instance.name" +Override ignored for property "precompilejsp" +Override ignored for property "admin.password.file" +Override ignored for property "http.port" +Override ignored for property "https.port" +Override ignored for property "results.mailee" +Override ignored for property "appserver.instance.name" +Override ignored for property "master.password" +Override ignored for property "http.host" +Override ignored for property "instance.http.port.3" +Override ignored for property "instance.http.port.2" +Override ignored for property "admin.port" +Override ignored for property "cluster.name" +Override ignored for property "appserver.instance.dir" +Override ignored for property "autodeploy.dir" +Override ignored for property "orb.port" +Override ignored for property "admin.host" +Override ignored for property "instance.name.3" +Override ignored for property "instance.name.2" +Override ignored for property "results.mailhost" + [echo] admin.domain domain1 + [echo] admin.user admin + [echo] admin.port 4848 + [echo] http.port 8080 + [echo] http.host localhost +Override ignored for property "as.props" +Override ignored for property "authrealmname" +Override ignored for property "apptype" +Override ignored for property "db.root" +Override ignored for property "db.dir" +Override ignored for property "db.classpath" + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config/derby.properties +Override ignored for property "db.host" +Override ignored for property "db.url" +Override ignored for property "db.xaclass" +Override ignored for property "db.name" +Override ignored for property "db.driver" +Override ignored for property "db.port" +Override ignored for property "db.port.2" +Override ignored for property "db.class" +Override ignored for property "db.user" +Override ignored for property "db.pwd" +Override ignored for property "db.type" +Property "env.JAVKE_HOME" has not been set +Override ignored for property "javke.home" +Override ignored for property "dest.type" +Override ignored for property "dest.name" +Override ignored for property "jms.factory.name" +Override ignored for property "jms.factory.type" +Override ignored for property "jms.resource.name" +Override ignored for property "jms.resource.type" +Override ignored for property "jdbc.conpool.name" +Override ignored for property "jdbc.resource.name" +Override ignored for property "jdbc.resource.type" +Override ignored for property "pm.resource.name" +Override ignored for property "pm.factory.class" +Override ignored for property "appclient.application.args" +Override ignored for property "build.base.dir" +Override ignored for property "build.webapps.dir" +Override ignored for property "build.classes.dir" +Override ignored for property "assemble.dir" +Override ignored for property "results.dir" +Property "Derby.classpath" has not been set +Override ignored for property "s1astest.classpath" +Override ignored for property "ejbjar.classes" +Override ignored for property "appclientjar.classes" +Override ignored for property "webclient.war.files" +Override ignored for property "webclient.war.classes" +Override ignored for property "test.name" +Override ignored for property "test.description" +Override ignored for property "test.count" +Override ignored for property "cluster.name" +Override ignored for property "clustered.server.name" +Override ignored for property "clustered.server.name.two" +Override ignored for property "nodeagent.name" +Override ignored for property "das.host" +Override ignored for property "das.jmx.port" +Override ignored for property "http.listener1.port" +Override ignored for property "http.listener2.port" +Override ignored for property "orb.listener1.port" +Override ignored for property "ssl.port" +Override ignored for property "ssl.mutualauth.port" +Override ignored for property "jmx.system.connector.port" +Override ignored for property "http.listener1.port.two" +Override ignored for property "http.listener2.port.two" +Override ignored for property "orb.listener1.port.two" +Override ignored for property "ssl.port.two" +Override ignored for property "ssl.mutualauth.port.two" +Override ignored for property "jmx.system.connector.port.two" +Override ignored for property "cert.nickname" + +clean-classes-common: + [echo] common.xml: Cleaning test source files: /export/work/workspaces/gfv3/appserv-tests/build/module + [antcall] Exiting /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml. +Project base dir set to: /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans + [antcall] calling target(s) [clean-jars-common] in build file /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml +parsing buildfile /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml with URI = file:/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml +Project base dir set to: /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/properties.xml +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/common.xml +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.properties +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/run.xml + [property] Loading Environment env. +Override ignored for property "env.SESSION_MANAGER" +Override ignored for property "env.LESSOPEN" +Override ignored for property "env.NORMBGCOLOR" +Override ignored for property "env.CVSROOT" +Override ignored for property "env.MY_ANT_HOME" +Override ignored for property "env.PWD" +Override ignored for property "env.XDG_SESSION_COOKIE" +Override ignored for property "env.LANG" +Override ignored for property "env.WS" +Override ignored for property "env.AWT_TOOLKIT" +Override ignored for property "env.DEFAULTS_PATH" +Override ignored for property "env.HISTSIZE" +Override ignored for property "env.INSTALL_ROOT" +Override ignored for property "env.DISPLAY" +Override ignored for property "env._" +Override ignored for property "env.USER" +Override ignored for property "env.HISTCONTROL" +Override ignored for property "env.SHELL" +Override ignored for property "env.NLSPATH" +Override ignored for property "env.XDG_DATA_DIRS" +Override ignored for property "env.DESKTOP_SESSION" +Override ignored for property "env.HISTFILESIZE" +Override ignored for property "env.APS_HOME" +Override ignored for property "env.WIDTH" +Override ignored for property "env.JAVANETCVSROOT" +Override ignored for property "env.PATH" +Override ignored for property "env.no_proxy" +Override ignored for property "env.NORMFGCOLOR" +Override ignored for property "env.LC_CTYPE" +Override ignored for property "env.DBUS_SESSION_BUS_ADDRESS" +Override ignored for property "env.REALPLAYER_HOME" +Override ignored for property "env.SSH_AGENT_PID" +Override ignored for property "env.SHLVL" +Override ignored for property "env.GDMSESSION" +Override ignored for property "env.GNOME_DESKTOP_SESSION_ID" +Override ignored for property "env.GDM_KEYBOARD_LAYOUT" +Override ignored for property "env.GNOME_KEYRING_PID" +Override ignored for property "env.OS" +Override ignored for property "env.LOGNAME" +Override ignored for property "env.ALSA_OUTPUT_PORTS" +Override ignored for property "env.SCUMMVM_PORT" +Override ignored for property "env.JAVA_HOME" +Override ignored for property "env.TERM" +Override ignored for property "env.QLTESTRES" +Override ignored for property "env.NO_PROXY" +Override ignored for property "env.GDM_LANG" +Override ignored for property "env.DTACH_HOME" +Override ignored for property "env.OLDPWD" +Override ignored for property "env.DEBUG" +Override ignored for property "env.GCONF_LOCAL_LOCKS" +Override ignored for property "env.M2_HOME" +Override ignored for property "env.EC2_CERT" +Override ignored for property "env.WINDOWID" +Override ignored for property "env.EC2_PRIVATE_KEY" +Override ignored for property "env.REDCVSROOT" +Override ignored for property "env.MOZ_DISABLE_PANGO" +Override ignored for property "env.XFILESEARCHPATH" +Override ignored for property "env.HOME" +Override ignored for property "env.ANT_HOME" +Override ignored for property "env.LD_LIBRARY_PATH" +Override ignored for property "env.MAVEN_OPTS" +Override ignored for property "env.SSH_AUTH_SOCK" +Override ignored for property "env.RBARWIDTH" +Override ignored for property "env.S1AS_HOME" +Property "BASH_SOURCE" has not been set +Property "LINENO" has not been set +Property "FUNCNAME[0]" has not been set +Override ignored for property "env.PS4" +Override ignored for property "env.MAVEN_HOME" +Override ignored for property "env.XAUTHORITY" +Property "NEW_PWD" has not been set +Override ignored for property "env.PS1" +Override ignored for property "env.MANDATORY_PATH" +Override ignored for property "env.SPEECHD_PORT" +Override ignored for property "env.GTK_MODULES" +Override ignored for property "env.WINDOW_MANAGER" +Override ignored for property "env.DTRX_HOME" +Override ignored for property "env.COLORTERM" +Override ignored for property "env.EDITOR" +Override ignored for property "env.MALLOC_CHECK_" +Override ignored for property "env.ORBIT_SOCKETDIR" +Override ignored for property "env.WP_INSTALL_ROOT" +Override ignored for property "env.USERNAME" +Override ignored for property "env.SCALA_HOME" +Override ignored for property "env.COPE_PATH" +Override ignored for property "env.QL_HOME" +Override ignored for property "env.AS_ADMIN_READTIMEOUT" +Override ignored for property "env.MY_SCRIPT_DIR" +Override ignored for property "env.GNOME_KEYRING_CONTROL" +Override ignored for property "env.XDG_CONFIG_DIRS" +Override ignored for property "env.TODOTXT_HOME" +Override ignored for property "env.LESSCLOSE" +Override ignored for property "module" +Override ignored for property "appname" +Override ignored for property "assemble" +Override ignored for property "contextroot" +Override ignored for property "beans.xml" +Override ignored for property "target-to-run" + [macrodef] creating macro run-test +Build sequence for target(s) `clean-jars-common' is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-jars-common] +Complete build sequence is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-jars-common, restart-instance-common, execute-sql-common, deploy-rar-common, undeploy, deploy-jdbc-common, undeploy-rar-common, set-derby-connpool-props, create-sql-common, deploy-war-no-context-root-pe, verifier-common, start-server-unix, test-tagfiles-exist, create-PermSize, execute-ejb-sql-common, undeploy-client-common, prepare-keystore-common, deploy-verify-common-ee, startDerby, confirmMissingReport-common, create-connector-resource-common, asadmin-common, create-connector-connpool, delete-connector-connpool-common, verifier, start-clean-server, runwebclient-common, deploy-common-ee, startDerbyNonMac, webclient-war-common, flush-connpool-common, stopDerby, clean-webapps-common, delete-jdbc-connpool-common, prepare-truststore-common, deploy-verify-common, run, test-tlds-exist, deploy-verify-common-pe, undeploy-common, undeploy-jar-common, deploy-client-common, enterprise-common, create-javamail-resource-common, package-persistence-common, deploy-war-commonee, startDomainWindows, set-derby-driver-connpool-props, deploy-war-no-context-root, undeploy-jdbc-common, deploy-common-pe, clear, copy-tagfiles, clean, compile, build, deploy, restart-server-instance-common, deploy-jar-common, delete-domain-common, stopPB, compile-common-with-endorsed-dir, import-wsdl, deploy-war-commonpe, compile-common, restart-server, runclient-common, package-appclientjar-common, ee-common, copy-tlds, delete-persistence-resource-common, undeploy-jms-common, asadmin-common-ignore-fail, startDomainUnix, startDomain, fixFiles, ejb-jar-common, appclient-jar-common, build-ear-common, publish-war-common, build-publish-war, stop-server-unix, clean-classes-common, clean-common, create-jdbc-connpool-common, dev-report, startDerbyMac, deploy-jms-common, package-war-common, package-ejbjar-common, delete-connector-resource-common, deploy-jsp-common, unsetupTimer, undeploy-war-common, change-orb-port, delete-javamail-resource-common, deploy-common, create-jms-resource-common, setup-mq-common, delete-jdbc-resource-common, start-server-windows, dumpThreadStack, setupTimer, deploy-war-common, start-server, ee, checkReporting-common, testTimer, stop-server, create-jdbc-driver-connpool-common, all, platform-common, create-jms-connection-common, undeploy-war-name, cleanAS, deploy-dir, preparePB, stop-server-windows, confirmReportPresent-common, delete-jms-resource-common, pb, runtest, create-jvm-options, restart-instance, stopDomain, create-connector-connpool-common, set-pointbase-driver-connpool-props, delete-sql-common, deploy-jdbc-driver-common, create-domain-common, delete-jvm-options, create-jdbc-resource-common, prepare-truststore-certutil-common, create-user-common, asadmin-batch-common, delete-user-common, prepare-truststore-keytool-common, convWin, create-persistence-resource-common, get-version-common, startPB, delete-jms-connection-common, usage-common, deploy-war-no-context-root-ee, set-pointbase-connpool-props, usage, convUnix, staticCheck-common, ear-common, deploy-war-name, ] + [antcall] Entering /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml... +Build sequence for target(s) `clean-jars-common' is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-jars-common] +Complete build sequence is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, clean-jars-common, restart-instance-common, execute-sql-common, deploy-rar-common, undeploy, deploy-jdbc-common, undeploy-rar-common, set-derby-connpool-props, create-sql-common, deploy-war-no-context-root-pe, verifier-common, start-server-unix, test-tagfiles-exist, create-PermSize, execute-ejb-sql-common, undeploy-client-common, prepare-keystore-common, deploy-verify-common-ee, startDerby, confirmMissingReport-common, create-connector-resource-common, asadmin-common, create-connector-connpool, delete-connector-connpool-common, verifier, start-clean-server, runwebclient-common, deploy-common-ee, startDerbyNonMac, webclient-war-common, flush-connpool-common, stopDerby, clean-webapps-common, delete-jdbc-connpool-common, prepare-truststore-common, deploy-verify-common, run, test-tlds-exist, deploy-verify-common-pe, undeploy-common, undeploy-jar-common, deploy-client-common, enterprise-common, create-javamail-resource-common, package-persistence-common, deploy-war-commonee, startDomainWindows, set-derby-driver-connpool-props, deploy-war-no-context-root, undeploy-jdbc-common, deploy-common-pe, clear, copy-tagfiles, clean, compile, build, deploy, restart-server-instance-common, deploy-jar-common, delete-domain-common, stopPB, compile-common-with-endorsed-dir, import-wsdl, deploy-war-commonpe, compile-common, restart-server, runclient-common, package-appclientjar-common, ee-common, copy-tlds, delete-persistence-resource-common, undeploy-jms-common, asadmin-common-ignore-fail, startDomainUnix, startDomain, fixFiles, ejb-jar-common, appclient-jar-common, build-ear-common, publish-war-common, build-publish-war, stop-server-unix, clean-classes-common, clean-common, create-jdbc-connpool-common, dev-report, startDerbyMac, deploy-jms-common, package-war-common, package-ejbjar-common, delete-connector-resource-common, deploy-jsp-common, unsetupTimer, undeploy-war-common, change-orb-port, delete-javamail-resource-common, deploy-common, create-jms-resource-common, setup-mq-common, delete-jdbc-resource-common, start-server-windows, dumpThreadStack, setupTimer, deploy-war-common, start-server, ee, checkReporting-common, testTimer, stop-server, create-jdbc-driver-connpool-common, all, platform-common, create-jms-connection-common, undeploy-war-name, cleanAS, deploy-dir, preparePB, stop-server-windows, confirmReportPresent-common, delete-jms-resource-common, pb, runtest, create-jvm-options, restart-instance, stopDomain, create-connector-connpool-common, set-pointbase-driver-connpool-props, delete-sql-common, deploy-jdbc-driver-common, create-domain-common, delete-jvm-options, create-jdbc-resource-common, prepare-truststore-certutil-common, create-user-common, asadmin-batch-common, delete-user-common, prepare-truststore-keytool-common, convWin, create-persistence-resource-common, get-version-common, startPB, delete-jms-connection-common, usage-common, deploy-war-no-context-root-ee, set-pointbase-connpool-props, usage, convUnix, staticCheck-common, ear-common, deploy-war-name, ] + +setOSConditions: +Override ignored for property "isUnix" + +setToolWin: +Skipped because property 'isWindows' not set. + +setToolUnix: +Override ignored for property "APPCLIENT" +Override ignored for property "ASADMIN" +Override ignored for property "ASANT" +Override ignored for property "CAPTURESCHEMA" +Override ignored for property "CHECKPATCH" +Override ignored for property "INSTALLPATCH" +Override ignored for property "JSPC" +Override ignored for property "LISTPATCH" +Override ignored for property "PACKAGE-APPCLIENT" +Override ignored for property "VERIFIER" +Override ignored for property "RMIC" +Override ignored for property "TNAMESERV" +Override ignored for property "WSCOMPILE" +Override ignored for property "WSIMPORT" +Override ignored for property "pb.start.server" +Override ignored for property "pb.start.server1" +Override ignored for property "IMQDBMGR" +Override ignored for property "ld.library.path" + +setS1ASclassPath: +Skipped because property 's1as.classpath' set. + +init-common: + [echo] Loading props from file /export/work/workspaces/gfv3/appserv-tests/config.properties +Override ignored for property "pe" + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config.properties +Override ignored for property "instance.https.port" +Override ignored for property "admin.domain" +Override ignored for property "admin.password" +Override ignored for property "http.address" +Override ignored for property "http.alternate.port" +Override ignored for property "ssl.password" +Override ignored for property "instance.http.port" +Override ignored for property "resources.dottedname.prefix" +Override ignored for property "results.mailer" +Override ignored for property "admin.domain.dir" +Override ignored for property "admin.user" +Override ignored for property "config.dottedname.prefix" +Override ignored for property "instance.name" +Override ignored for property "precompilejsp" +Override ignored for property "admin.password.file" +Override ignored for property "http.port" +Override ignored for property "https.port" +Override ignored for property "results.mailee" +Override ignored for property "appserver.instance.name" +Override ignored for property "master.password" +Override ignored for property "http.host" +Override ignored for property "instance.http.port.3" +Override ignored for property "instance.http.port.2" +Override ignored for property "admin.port" +Override ignored for property "cluster.name" +Override ignored for property "appserver.instance.dir" +Override ignored for property "autodeploy.dir" +Override ignored for property "orb.port" +Override ignored for property "admin.host" +Override ignored for property "instance.name.3" +Override ignored for property "instance.name.2" +Override ignored for property "results.mailhost" + [echo] admin.domain domain1 + [echo] admin.user admin + [echo] admin.port 4848 + [echo] http.port 8080 + [echo] http.host localhost +Override ignored for property "as.props" +Override ignored for property "authrealmname" +Override ignored for property "apptype" +Override ignored for property "db.root" +Override ignored for property "db.dir" +Override ignored for property "db.classpath" + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config/derby.properties +Override ignored for property "db.host" +Override ignored for property "db.url" +Override ignored for property "db.xaclass" +Override ignored for property "db.name" +Override ignored for property "db.driver" +Override ignored for property "db.port" +Override ignored for property "db.port.2" +Override ignored for property "db.class" +Override ignored for property "db.user" +Override ignored for property "db.pwd" +Override ignored for property "db.type" +Property "env.JAVKE_HOME" has not been set +Override ignored for property "javke.home" +Override ignored for property "dest.type" +Override ignored for property "dest.name" +Override ignored for property "jms.factory.name" +Override ignored for property "jms.factory.type" +Override ignored for property "jms.resource.name" +Override ignored for property "jms.resource.type" +Override ignored for property "jdbc.conpool.name" +Override ignored for property "jdbc.resource.name" +Override ignored for property "jdbc.resource.type" +Override ignored for property "pm.resource.name" +Override ignored for property "pm.factory.class" +Override ignored for property "appclient.application.args" +Override ignored for property "build.base.dir" +Override ignored for property "build.webapps.dir" +Override ignored for property "build.classes.dir" +Override ignored for property "assemble.dir" +Override ignored for property "results.dir" +Property "Derby.classpath" has not been set +Override ignored for property "s1astest.classpath" +Override ignored for property "ejbjar.classes" +Override ignored for property "appclientjar.classes" +Override ignored for property "webclient.war.files" +Override ignored for property "webclient.war.classes" +Override ignored for property "test.name" +Override ignored for property "test.description" +Override ignored for property "test.count" +Override ignored for property "cluster.name" +Override ignored for property "clustered.server.name" +Override ignored for property "clustered.server.name.two" +Override ignored for property "nodeagent.name" +Override ignored for property "das.host" +Override ignored for property "das.jmx.port" +Override ignored for property "http.listener1.port" +Override ignored for property "http.listener2.port" +Override ignored for property "orb.listener1.port" +Override ignored for property "ssl.port" +Override ignored for property "ssl.mutualauth.port" +Override ignored for property "jmx.system.connector.port" +Override ignored for property "http.listener1.port.two" +Override ignored for property "http.listener2.port.two" +Override ignored for property "orb.listener1.port.two" +Override ignored for property "ssl.port.two" +Override ignored for property "ssl.mutualauth.port.two" +Override ignored for property "jmx.system.connector.port.two" +Override ignored for property "cert.nickname" + [antcall] Exiting /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml. + [antcall] Exiting /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml. + +compile: +Project base dir set to: /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans + [antcall] calling target(s) [compile-common] in build file /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml +parsing buildfile /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml with URI = file:/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml +Project base dir set to: /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/properties.xml +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/common.xml +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.properties +resolving systemId: file:/export/work/workspaces/gfv3/appserv-tests/config/run.xml + [property] Loading Environment env. +Override ignored for property "env.SESSION_MANAGER" +Override ignored for property "env.LESSOPEN" +Override ignored for property "env.NORMBGCOLOR" +Override ignored for property "env.CVSROOT" +Override ignored for property "env.MY_ANT_HOME" +Override ignored for property "env.PWD" +Override ignored for property "env.XDG_SESSION_COOKIE" +Override ignored for property "env.LANG" +Override ignored for property "env.WS" +Override ignored for property "env.AWT_TOOLKIT" +Override ignored for property "env.DEFAULTS_PATH" +Override ignored for property "env.HISTSIZE" +Override ignored for property "env.INSTALL_ROOT" +Override ignored for property "env.DISPLAY" +Override ignored for property "env._" +Override ignored for property "env.USER" +Override ignored for property "env.HISTCONTROL" +Override ignored for property "env.SHELL" +Override ignored for property "env.NLSPATH" +Override ignored for property "env.XDG_DATA_DIRS" +Override ignored for property "env.DESKTOP_SESSION" +Override ignored for property "env.HISTFILESIZE" +Override ignored for property "env.APS_HOME" +Override ignored for property "env.WIDTH" +Override ignored for property "env.JAVANETCVSROOT" +Override ignored for property "env.PATH" +Override ignored for property "env.no_proxy" +Override ignored for property "env.NORMFGCOLOR" +Override ignored for property "env.LC_CTYPE" +Override ignored for property "env.DBUS_SESSION_BUS_ADDRESS" +Override ignored for property "env.REALPLAYER_HOME" +Override ignored for property "env.SSH_AGENT_PID" +Override ignored for property "env.SHLVL" +Override ignored for property "env.GDMSESSION" +Override ignored for property "env.GNOME_DESKTOP_SESSION_ID" +Override ignored for property "env.GDM_KEYBOARD_LAYOUT" +Override ignored for property "env.GNOME_KEYRING_PID" +Override ignored for property "env.OS" +Override ignored for property "env.LOGNAME" +Override ignored for property "env.ALSA_OUTPUT_PORTS" +Override ignored for property "env.SCUMMVM_PORT" +Override ignored for property "env.JAVA_HOME" +Override ignored for property "env.TERM" +Override ignored for property "env.QLTESTRES" +Override ignored for property "env.NO_PROXY" +Override ignored for property "env.GDM_LANG" +Override ignored for property "env.DTACH_HOME" +Override ignored for property "env.OLDPWD" +Override ignored for property "env.DEBUG" +Override ignored for property "env.GCONF_LOCAL_LOCKS" +Override ignored for property "env.M2_HOME" +Override ignored for property "env.EC2_CERT" +Override ignored for property "env.WINDOWID" +Override ignored for property "env.EC2_PRIVATE_KEY" +Override ignored for property "env.REDCVSROOT" +Override ignored for property "env.MOZ_DISABLE_PANGO" +Override ignored for property "env.XFILESEARCHPATH" +Override ignored for property "env.HOME" +Override ignored for property "env.ANT_HOME" +Override ignored for property "env.LD_LIBRARY_PATH" +Override ignored for property "env.MAVEN_OPTS" +Override ignored for property "env.SSH_AUTH_SOCK" +Override ignored for property "env.RBARWIDTH" +Override ignored for property "env.S1AS_HOME" +Property "BASH_SOURCE" has not been set +Property "LINENO" has not been set +Property "FUNCNAME[0]" has not been set +Override ignored for property "env.PS4" +Override ignored for property "env.MAVEN_HOME" +Override ignored for property "env.XAUTHORITY" +Property "NEW_PWD" has not been set +Override ignored for property "env.PS1" +Override ignored for property "env.MANDATORY_PATH" +Override ignored for property "env.SPEECHD_PORT" +Override ignored for property "env.GTK_MODULES" +Override ignored for property "env.WINDOW_MANAGER" +Override ignored for property "env.DTRX_HOME" +Override ignored for property "env.COLORTERM" +Override ignored for property "env.EDITOR" +Override ignored for property "env.MALLOC_CHECK_" +Override ignored for property "env.ORBIT_SOCKETDIR" +Override ignored for property "env.WP_INSTALL_ROOT" +Override ignored for property "env.USERNAME" +Override ignored for property "env.SCALA_HOME" +Override ignored for property "env.COPE_PATH" +Override ignored for property "env.QL_HOME" +Override ignored for property "env.AS_ADMIN_READTIMEOUT" +Override ignored for property "env.MY_SCRIPT_DIR" +Override ignored for property "env.GNOME_KEYRING_CONTROL" +Override ignored for property "env.XDG_CONFIG_DIRS" +Override ignored for property "env.TODOTXT_HOME" +Override ignored for property "env.LESSCLOSE" +Override ignored for property "module" +Override ignored for property "appname" +Override ignored for property "assemble" +Override ignored for property "contextroot" +Override ignored for property "beans.xml" +Override ignored for property "target-to-run" + [macrodef] creating macro run-test +Build sequence for target(s) `compile-common' is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, compile-common] +Complete build sequence is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, compile-common, restart-instance-common, execute-sql-common, deploy-rar-common, undeploy, deploy-jdbc-common, undeploy-rar-common, set-derby-connpool-props, create-sql-common, deploy-war-no-context-root-pe, verifier-common, start-server-unix, test-tagfiles-exist, create-PermSize, execute-ejb-sql-common, undeploy-client-common, prepare-keystore-common, deploy-verify-common-ee, startDerby, confirmMissingReport-common, create-connector-resource-common, asadmin-common, create-connector-connpool, delete-connector-connpool-common, verifier, start-clean-server, runwebclient-common, deploy-common-ee, startDerbyNonMac, webclient-war-common, flush-connpool-common, stopDerby, clean-webapps-common, delete-jdbc-connpool-common, prepare-truststore-common, deploy-verify-common, run, test-tlds-exist, deploy-verify-common-pe, undeploy-common, undeploy-jar-common, deploy-client-common, enterprise-common, create-javamail-resource-common, package-persistence-common, deploy-war-commonee, startDomainWindows, set-derby-driver-connpool-props, deploy-war-no-context-root, undeploy-jdbc-common, deploy-common-pe, clear, copy-tagfiles, clean, compile, build, deploy, restart-server-instance-common, deploy-jar-common, delete-domain-common, stopPB, compile-common-with-endorsed-dir, import-wsdl, deploy-war-commonpe, restart-server, runclient-common, package-appclientjar-common, ee-common, copy-tlds, delete-persistence-resource-common, undeploy-jms-common, asadmin-common-ignore-fail, startDomainUnix, startDomain, fixFiles, ejb-jar-common, appclient-jar-common, build-ear-common, publish-war-common, build-publish-war, stop-server-unix, clean-classes-common, clean-common, create-jdbc-connpool-common, dev-report, startDerbyMac, deploy-jms-common, package-war-common, package-ejbjar-common, delete-connector-resource-common, deploy-jsp-common, unsetupTimer, undeploy-war-common, change-orb-port, delete-javamail-resource-common, deploy-common, create-jms-resource-common, setup-mq-common, delete-jdbc-resource-common, start-server-windows, dumpThreadStack, setupTimer, deploy-war-common, start-server, ee, checkReporting-common, testTimer, stop-server, create-jdbc-driver-connpool-common, all, platform-common, create-jms-connection-common, undeploy-war-name, cleanAS, deploy-dir, preparePB, stop-server-windows, confirmReportPresent-common, delete-jms-resource-common, pb, runtest, create-jvm-options, clean-jars-common, restart-instance, stopDomain, create-connector-connpool-common, set-pointbase-driver-connpool-props, delete-sql-common, deploy-jdbc-driver-common, create-domain-common, delete-jvm-options, create-jdbc-resource-common, prepare-truststore-certutil-common, create-user-common, asadmin-batch-common, delete-user-common, prepare-truststore-keytool-common, convWin, create-persistence-resource-common, get-version-common, startPB, delete-jms-connection-common, usage-common, deploy-war-no-context-root-ee, set-pointbase-connpool-props, usage, convUnix, staticCheck-common, ear-common, deploy-war-name, ] + [antcall] Entering /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml... +Build sequence for target(s) `compile-common' is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, compile-common] +Complete build sequence is [setOSConditions, setToolWin, setToolUnix, setToolProperty, setS1ASclassPath, init-common, compile-common, restart-instance-common, execute-sql-common, deploy-rar-common, undeploy, deploy-jdbc-common, undeploy-rar-common, set-derby-connpool-props, create-sql-common, deploy-war-no-context-root-pe, verifier-common, start-server-unix, test-tagfiles-exist, create-PermSize, execute-ejb-sql-common, undeploy-client-common, prepare-keystore-common, deploy-verify-common-ee, startDerby, confirmMissingReport-common, create-connector-resource-common, asadmin-common, create-connector-connpool, delete-connector-connpool-common, verifier, start-clean-server, runwebclient-common, deploy-common-ee, startDerbyNonMac, webclient-war-common, flush-connpool-common, stopDerby, clean-webapps-common, delete-jdbc-connpool-common, prepare-truststore-common, deploy-verify-common, run, test-tlds-exist, deploy-verify-common-pe, undeploy-common, undeploy-jar-common, deploy-client-common, enterprise-common, create-javamail-resource-common, package-persistence-common, deploy-war-commonee, startDomainWindows, set-derby-driver-connpool-props, deploy-war-no-context-root, undeploy-jdbc-common, deploy-common-pe, clear, copy-tagfiles, clean, compile, build, deploy, restart-server-instance-common, deploy-jar-common, delete-domain-common, stopPB, compile-common-with-endorsed-dir, import-wsdl, deploy-war-commonpe, restart-server, runclient-common, package-appclientjar-common, ee-common, copy-tlds, delete-persistence-resource-common, undeploy-jms-common, asadmin-common-ignore-fail, startDomainUnix, startDomain, fixFiles, ejb-jar-common, appclient-jar-common, build-ear-common, publish-war-common, build-publish-war, stop-server-unix, clean-classes-common, clean-common, create-jdbc-connpool-common, dev-report, startDerbyMac, deploy-jms-common, package-war-common, package-ejbjar-common, delete-connector-resource-common, deploy-jsp-common, unsetupTimer, undeploy-war-common, change-orb-port, delete-javamail-resource-common, deploy-common, create-jms-resource-common, setup-mq-common, delete-jdbc-resource-common, start-server-windows, dumpThreadStack, setupTimer, deploy-war-common, start-server, ee, checkReporting-common, testTimer, stop-server, create-jdbc-driver-connpool-common, all, platform-common, create-jms-connection-common, undeploy-war-name, cleanAS, deploy-dir, preparePB, stop-server-windows, confirmReportPresent-common, delete-jms-resource-common, pb, runtest, create-jvm-options, clean-jars-common, restart-instance, stopDomain, create-connector-connpool-common, set-pointbase-driver-connpool-props, delete-sql-common, deploy-jdbc-driver-common, create-domain-common, delete-jvm-options, create-jdbc-resource-common, prepare-truststore-certutil-common, create-user-common, asadmin-batch-common, delete-user-common, prepare-truststore-keytool-common, convWin, create-persistence-resource-common, get-version-common, startPB, delete-jms-connection-common, usage-common, deploy-war-no-context-root-ee, set-pointbase-connpool-props, usage, convUnix, staticCheck-common, ear-common, deploy-war-name, ] + +setOSConditions: +Override ignored for property "isUnix" + +setToolWin: +Skipped because property 'isWindows' not set. + +setToolUnix: +Override ignored for property "APPCLIENT" +Override ignored for property "ASADMIN" +Override ignored for property "ASANT" +Override ignored for property "CAPTURESCHEMA" +Override ignored for property "CHECKPATCH" +Override ignored for property "INSTALLPATCH" +Override ignored for property "JSPC" +Override ignored for property "LISTPATCH" +Override ignored for property "PACKAGE-APPCLIENT" +Override ignored for property "VERIFIER" +Override ignored for property "RMIC" +Override ignored for property "TNAMESERV" +Override ignored for property "WSCOMPILE" +Override ignored for property "WSIMPORT" +Override ignored for property "pb.start.server" +Override ignored for property "pb.start.server1" +Override ignored for property "IMQDBMGR" +Override ignored for property "ld.library.path" + +setS1ASclassPath: +Skipped because property 's1as.classpath' set. + +init-common: + [echo] Loading props from file /export/work/workspaces/gfv3/appserv-tests/config.properties +Override ignored for property "pe" + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config.properties +Override ignored for property "instance.https.port" +Override ignored for property "admin.domain" +Override ignored for property "admin.password" +Override ignored for property "http.address" +Override ignored for property "http.alternate.port" +Override ignored for property "ssl.password" +Override ignored for property "instance.http.port" +Override ignored for property "resources.dottedname.prefix" +Override ignored for property "results.mailer" +Override ignored for property "admin.domain.dir" +Override ignored for property "admin.user" +Override ignored for property "config.dottedname.prefix" +Override ignored for property "instance.name" +Override ignored for property "precompilejsp" +Override ignored for property "admin.password.file" +Override ignored for property "http.port" +Override ignored for property "https.port" +Override ignored for property "results.mailee" +Override ignored for property "appserver.instance.name" +Override ignored for property "master.password" +Override ignored for property "http.host" +Override ignored for property "instance.http.port.3" +Override ignored for property "instance.http.port.2" +Override ignored for property "admin.port" +Override ignored for property "cluster.name" +Override ignored for property "appserver.instance.dir" +Override ignored for property "autodeploy.dir" +Override ignored for property "orb.port" +Override ignored for property "admin.host" +Override ignored for property "instance.name.3" +Override ignored for property "instance.name.2" +Override ignored for property "results.mailhost" + [echo] admin.domain domain1 + [echo] admin.user admin + [echo] admin.port 4848 + [echo] http.port 8080 + [echo] http.host localhost +Override ignored for property "as.props" +Override ignored for property "authrealmname" +Override ignored for property "apptype" +Override ignored for property "db.root" +Override ignored for property "db.dir" +Override ignored for property "db.classpath" + [property] Loading /export/work/workspaces/gfv3/appserv-tests/config/derby.properties +Override ignored for property "db.host" +Override ignored for property "db.url" +Override ignored for property "db.xaclass" +Override ignored for property "db.name" +Override ignored for property "db.driver" +Override ignored for property "db.port" +Override ignored for property "db.port.2" +Override ignored for property "db.class" +Override ignored for property "db.user" +Override ignored for property "db.pwd" +Override ignored for property "db.type" +Property "env.JAVKE_HOME" has not been set +Override ignored for property "javke.home" +Override ignored for property "dest.type" +Override ignored for property "dest.name" +Override ignored for property "jms.factory.name" +Override ignored for property "jms.factory.type" +Override ignored for property "jms.resource.name" +Override ignored for property "jms.resource.type" +Override ignored for property "jdbc.conpool.name" +Override ignored for property "jdbc.resource.name" +Override ignored for property "jdbc.resource.type" +Override ignored for property "pm.resource.name" +Override ignored for property "pm.factory.class" +Override ignored for property "appclient.application.args" +Override ignored for property "build.base.dir" +Override ignored for property "build.webapps.dir" +Override ignored for property "build.classes.dir" +Override ignored for property "assemble.dir" +Override ignored for property "results.dir" +Property "Derby.classpath" has not been set +Override ignored for property "s1astest.classpath" +Override ignored for property "ejbjar.classes" +Override ignored for property "appclientjar.classes" +Override ignored for property "webclient.war.files" +Override ignored for property "webclient.war.classes" +Override ignored for property "test.name" +Override ignored for property "test.description" +Override ignored for property "test.count" +Override ignored for property "cluster.name" +Override ignored for property "clustered.server.name" +Override ignored for property "clustered.server.name.two" +Override ignored for property "nodeagent.name" +Override ignored for property "das.host" +Override ignored for property "das.jmx.port" +Override ignored for property "http.listener1.port" +Override ignored for property "http.listener2.port" +Override ignored for property "orb.listener1.port" +Override ignored for property "ssl.port" +Override ignored for property "ssl.mutualauth.port" +Override ignored for property "jmx.system.connector.port" +Override ignored for property "http.listener1.port.two" +Override ignored for property "http.listener2.port.two" +Override ignored for property "orb.listener1.port.two" +Override ignored for property "ssl.port.two" +Override ignored for property "ssl.mutualauth.port.two" +Override ignored for property "jmx.system.connector.port.two" +Override ignored for property "cert.nickname" + +compile-common: + [mkdir] Created dir: /export/work/workspaces/gfv3/appserv-tests/build/module/classes + [echo] common.xml: Compiling test source files + [mkdir] Skipping /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet because it already exists. + [javac] ClassUnavailableAtRuntime.java added as ClassUnavailableAtRuntime.class doesn't exist. + [javac] OptionalService.java added as OptionalService.class doesn't exist. + [javac] TestBean.java added as TestBean.class doesn't exist. + [javac] TestLoggerProducer.java added as TestLoggerProducer.class doesn't exist. + [javac] TestServlet.java added as TestServlet.class doesn't exist. + [javac] Compiling 5 source files to /export/work/workspaces/gfv3/appserv-tests/build/module/classes + [javac] Using modern compiler +dropping /export/work/workspaces/gfv3/appserv-tests/sqetests/connector/lib/cci-derby-proc.jar from path as it doesn't exist +dropping /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/${Derby.classpath} from path as it doesn't exist + [javac] Compilation arguments: + [javac] '-d' + [javac] '/export/work/workspaces/gfv3/appserv-tests/build/module/classes' + [javac] '-classpath' + [javac] '/export/work/workspaces/gfv3/appserv-tests/build/module/classes:/export/work/workspaces/gfv3/appserv-tests/lib/reporter.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/acc-config.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/admin-cli.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/admin-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/admin-util.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/amx-all.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/annotation-framework.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ant.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/antlr-repackaged.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/api-exporter.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/appclient-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/appclient-server-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/appclient.security.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/asm-all-repackaged.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/auto-depends.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/org.apache.felix.bundlerepository.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/org.apache.felix.eventadmin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/org.apache.felix.scr.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/osgi-cdi.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/osgi-ee-resources.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/osgi-ejb-container.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/osgi-javaee-base.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/osgi-jdbc.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/osgi-jpa.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/osgi-jta.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/autostart/osgi-web-container.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/backup.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/bean-validator.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/branding.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/class-model.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cli-optional.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cluster-admin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cluster-cli.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cluster-common.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cluster-ssh.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cmp-ejb-mapping.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cmp-enhancer.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cmp-generator-database.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cmp-internal-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cmp-model.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cmp-support-ejb.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cmp-support-sqlstore.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/cmp-utility.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/common-util.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/config-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/config-types.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/config.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/connectors-admin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/connectors-inbound-runtime.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/connectors-internal-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/connectors-runtime.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-cluster-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-cluster-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-common-full-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-common-full-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-common-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-common.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-community-branding-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-corba-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-corba-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-ejb-lite-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-ejb-lite-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-ejb-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-ejb-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-jca-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-jca-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-jdbc-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-jdbc-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-jms-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-jms-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-jts-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-jts-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-plugin-service.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-updatecenter-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-web-plugin-help.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/console-web-plugin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/container-common.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/dataprovider.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/dbschema-repackaged.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/deployment-admin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/deployment-autodeploy.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/deployment-client.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/deployment-common.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/deployment-javaee-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/deployment-javaee-full.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/dol.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ejb-container.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ejb-internal-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ejb.security.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/el-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/endorsed/javax.annotation.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/endorsed/jaxb-api-osgi.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/endorsed/webservices-api-osgi.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/flashlight-extra-jdk-packages.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/flashlight-framework.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/gf-client-module.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/gf-connectors-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/gf-ejb-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/gf-web-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-corba-asm.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-corba-codegen.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-corba-csiv2-idl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-corba-internal-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-corba-newtimer.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-corba-omgapi.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-corba-orb.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-corba-orbgeneric.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-ee-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-extra-jre-packages.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-mbeanserver.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-naming.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-oracle-jdbc-driver-packages.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish-registration.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/glassfish.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/gmbal-api-only.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/gmbal.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/gms-adapter.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/gms-bootstrap.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-comet.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-config.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-container.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-framework-tests.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-framework.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-http-ajp.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-http-server.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-http-servlet.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-http.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-portunif.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-rcm.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/grizzly-websockets.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ha-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ha-file-store.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ha-shoal-cache-bootstrap.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ha-shoal-cache-store.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/hk2-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/hk2.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/inmemory.jacc.provider.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/internal-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jackson-core-asl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jackson-jaxrs.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jackson-mapper-asl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jackson-xc.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jaspic.provider.framework.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javaee-kernel.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.ejb.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.enterprise.deploy.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.jms.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.mail.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.management.j2ee.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.persistence.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.resource.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.security.auth.message.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.security.jacc.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.servlet.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.servlet.jsp.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.servlet.jsp.jstl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/javax.transaction.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jaxb-osgi.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jaxrpc-api-osgi.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jdbc-admin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jersey-client.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jersey-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jersey-gf-server.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jersey-gf-statsproviders.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jersey-grizzly2.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jersey-json.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jersey-multipart.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jettison.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jms-admin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jms-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jmxremote_optional-repackaged.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jpa-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jsf-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jsf-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jsf-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jsftemplating.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jsp-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jspcaching-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jsr109-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jstl-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jstl-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jta.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/jts.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/kernel.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/launcher.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ldapbp-repackaged.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/libpam4j-repackaged.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/libvirt.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/load-balancer-admin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/logging.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/management-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/metro-glue.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/mimepull.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/monitoring-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/orb-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/orb-enabler.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/orb-iiop.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.apache.felix.configadmin.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.apache.felix.fileinstall.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.apache.felix.gogo.command.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.apache.felix.gogo.runtime.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.apache.felix.gogo.shell.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.apache.felix.shell.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.apache.felix.shell.remote.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.apache.felix.shell.tui.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.eclipse.persistence.antlr.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.eclipse.persistence.asm.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.eclipse.persistence.core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.eclipse.persistence.jpa.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.eclipse.persistence.jpa.modelgen.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/org.eclipse.persistence.oracle.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/osgi-adapter.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/osgi-container.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/osgi-jpa-extension.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/osgi-main.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/osgi-resource-locator.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/persistence-common.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/pkg-client.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/registration-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/registration-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/rest-service.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/scattered-archive-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/schema2beans-repackaged.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/security.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/server-mgmt.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/shoal-cache.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/shoal-gms-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/shoal-gms-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/simple-glassfish-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/soap-tcp.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/ssl-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/stats77.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/transaction-internal-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/trilead-ssh2-repackaged.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/virt-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/war-util.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/web-cli.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/web-core.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/web-embed-api.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/web-embed-impl.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/web-glue.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/web-gui-plugin-common.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/web-ha.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/web-naming.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/websecurity.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/webservices-connector.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/webservices-extra-jdk-packages.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/webservices-osgi.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/webservices.security.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/weld-integration-fragment.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/weld-integration.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/weld-osgi-bundle.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/woodstox-osgi.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/glassfish/modules/work-management.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/javadb/lib/derby.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/javadb/lib/derbyclient.jar:/export/work/workspaces/gfv3/v3/distributions/glassfish/target/glassfish5/javadb/lib/derbynet.jar:/space/apps/apache-ant-1.7.1/lib/ant-launcher.jar:/space/apps/apache-ant-1.7.1/lib/ant-jai.jar:/space/apps/apache-ant-1.7.1/lib/ant-antlr.jar:/space/apps/apache-ant-1.7.1/lib/ant-starteam.jar:/space/apps/apache-ant-1.7.1/lib/ant-jdepend.jar:/space/apps/apache-ant-1.7.1/lib/ant-apache-oro.jar:/space/apps/apache-ant-1.7.1/lib/ant-trax.jar:/space/apps/apache-ant-1.7.1/lib/ant-apache-regexp.jar:/space/apps/apache-ant-1.7.1/lib/ant-jmf.jar:/space/apps/apache-ant-1.7.1/lib/ant-jsch.jar:/space/apps/apache-ant-1.7.1/lib/ant-apache-bsf.jar:/space/apps/apache-ant-1.7.1/lib/ant-netrexx.jar:/space/apps/apache-ant-1.7.1/lib/ant-swing.jar:/space/apps/apache-ant-1.7.1/lib/xercesImpl.jar:/space/apps/apache-ant-1.7.1/lib/ant-apache-bcel.jar:/space/apps/apache-ant-1.7.1/lib/ant-stylebook.jar:/space/apps/apache-ant-1.7.1/lib/ant-javamail.jar:/space/apps/apache-ant-1.7.1/lib/ant-junit.jar:/space/apps/apache-ant-1.7.1/lib/ant-commons-net.jar:/space/apps/apache-ant-1.7.1/lib/ant-commons-logging.jar:/space/apps/apache-ant-1.7.1/lib/ant-weblogic.jar:/space/apps/apache-ant-1.7.1/lib/ant-apache-log4j.jar:/space/apps/apache-ant-1.7.1/lib/ant.jar:/space/apps/apache-ant-1.7.1/lib/xml-apis.jar:/space/apps/apache-ant-1.7.1/lib/ant-nodeps.jar:/space/apps/apache-ant-1.7.1/lib/ant-testutil.jar:/space/apps/apache-ant-1.7.1/lib/ant-apache-resolver.jar:/space/apps/jdk1.6.0_22/lib/tools.jar' + [javac] '-sourcepath' + [javac] '/export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet' + [javac] '-g' + [javac] + [javac] The ' characters around the executable and arguments are + [javac] not part of the command. + [javac] Files to be compiled: + [javac] /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/ClassUnavailableAtRuntime.java + [javac] /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/OptionalService.java + [javac] /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/TestBean.java + [javac] /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/TestLoggerProducer.java + [javac] /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/TestServlet.java + [antcall] Exiting /export/work/workspaces/gfv3/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/build.xml. + [delete] Deleting: /export/work/workspaces/gfv3/appserv-tests/build/module/classes/ClassUnavailableAtRuntime.class + +BUILD SUCCESSFUL +Total time: 3 seconds
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/lib/slf4j-api-1.7.25.jar b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/lib/slf4j-api-1.7.25.jar new file mode 100644 index 0000000..0143c09 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/lib/slf4j-api-1.7.25.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/lib/slf4j-simple-1.7.25.jar b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/lib/slf4j-simple-1.7.25.jar new file mode 100644 index 0000000..a7260f3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/lib/slf4j-simple-1.7.25.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/ClassUnavailableAtRuntime.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/ClassUnavailableAtRuntime.java new file mode 100644 index 0000000..3bae9d7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/ClassUnavailableAtRuntime.java
@@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +//A Test parent Bean class that is available +//during compilation but is not packaged at runtime +public class ClassUnavailableAtRuntime extends TestService { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/OptionalService.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/OptionalService.java new file mode 100644 index 0000000..1e123a6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/OptionalService.java
@@ -0,0 +1,25 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +//An optional service that extends ClassUnavailableAtRuntime +//This optional service bean is not used +//and the superclass of this bean is unavailable at runtime + +public class OptionalService extends ClassUnavailableAtRuntime{ + public OptionalService(){ + System.out.println("OptionalService instantiated"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/TestBean.java new file mode 100644 index 0000000..6d059e2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/TestBean.java
@@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +//Simple TestBean to test CDI. +//This bean implements Serializable as it needs to be placed into a Stateful Bean +public class TestBean +{}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/TestLoggerProducer.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/TestLoggerProducer.java new file mode 100644 index 0000000..9c2e72e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/TestLoggerProducer.java
@@ -0,0 +1,27 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import javax.enterprise.inject.Produces; + + +public class TestLoggerProducer { + @Produces + public org.jboss.logging.Logger getLogger(){ + org.jboss.logging.Logger l = org.jboss.logging.Logger.getLogger(TestLoggerProducer.class); + System.out.println("getLogger:: " + l); + return l; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/TestService.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/TestService.java new file mode 100644 index 0000000..3a2ccc2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/TestService.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +//A dummy Parent class that is used to test for Bean registration/availability +//in TestServlet +public class TestService { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/TestServlet.java new file mode 100644 index 0000000..7e438a7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/optional-unbundled-beans/servlet/TestServlet.java
@@ -0,0 +1,81 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.Set; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.inject.Inject; +import javax.enterprise.inject.Any; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.util.AnnotationLiteral; +import javax.naming.InitialContext; + +@WebServlet(name="mytest", + urlPatterns={"/myurl"}, + initParams={ @WebInitParam(name="n1", value="v1"), @WebInitParam(name="n2", value="v2") } ) +public class TestServlet extends HttpServlet { + @Inject TestBean tb; + @Inject BeanManager bm; + BeanManager bm1; + + @Inject + private transient org.jboss.logging.Logger log; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + + ", n2=" + getInitParameter("n2"); + if (tb == null) msg += "Bean injection into Servlet failed"; + if (bm == null) msg += "BeanManager Injection via @Inject failed"; + try { + bm1 = (BeanManager)((new InitialContext()).lookup("java:comp/BeanManager")); + } catch (Exception ex) { + ex.printStackTrace(); + msg += "BeanManager Injection via component environment lookup failed"; + } + if (bm1 == null) msg += "BeanManager Injection via component environment lookup failed"; + + //Ensure that the OptionalService Bean is not registered. + Set<Bean<?>> optionalServiceBeans = bm.getBeans(TestService.class,new AnnotationLiteral<Any>() {}); + boolean optionalServiceAvailable = false; + for (Iterator<Bean<?>> iterator = optionalServiceBeans.iterator(); iterator + .hasNext();) { + Bean<?> b = iterator.next(); + System.out.println("-----" + b + " " + b.getClass() + " " + b.getBeanClass().getCanonicalName()); + if (b.getBeanClass().getCanonicalName().contains("Optional")) optionalServiceAvailable = true; + } + + //The OptionalService Bean was not added to the WAR and hence must not available through the BM. + if (optionalServiceAvailable) msg += "OptionalServiceBean is registered, though it was not included in the WAR"; + + System.out.println("BeanManager is " + bm); + System.out.println("BeanManager via lookup is " + bm1); + writer.write("initParams: " + msg + "\n"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/build.properties b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/build.properties new file mode 100644 index 0000000..e8ca782 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/build.properties
@@ -0,0 +1,28 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi-full-ear"/> +<property name="appname" value="${module}"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="se.client" value="com.acme.Client"/> +<property name="app.type" value="application"/> +<property name="sun-application.xml" value="descriptor/sun-application.xml"/> +<property name="application.xml" value="descriptor/application.xml"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="contextroot" value="${module}"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/build.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/build.xml new file mode 100644 index 0000000..1694525 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/build.xml
@@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="cdi-full-ear-App" default="usage" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + + <target name="all" depends="clean,build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="war"/> + </antcall> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="true"/> + </antcall> + <antcall target="compile-common"> + <param name="src" value="ejb"/> + </antcall> + + <javac classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/lib/gf-client.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar" srcdir="client" destdir="${build.classes.dir}" debug="on" failonerror="true"> + <compilerarg line="-endorseddirs ${env.S1AS_HOME}/modules/endorsed"/> + + </javac> +<!-- + <antcall target="compile-common"> + <param name="src" value="client"/> + </antcall> +--> + </target> + + <target name="build" depends="compile"> + <mkdir dir="${assemble.dir}"/> + <antcall target="ejb-jar-common"> + <param name="ejbjar.classes" value="**/Foo.class,**/Hello.class,**/HelloRemote.class,**/Singleton*.class,**/HelloStateless.class,**/HelloSingleton.class,**/FooManagedBean.class,**/BarManagedBean.class, **/FooBarManagedBean.class, **/ManagedSuper.class"/> + </antcall> + <antcall target="ear-common"/> + </target> + + <target name="deploy" + depends="init-common"> + <antcall target="deploy-common"/> + </target> + + <target name="run" depends="init-common"> + <java fork="on" + failonerror="true" + classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/lib/gf-client.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar" + classname="${se.client}"> + <arg line="${contextroot}"/> + <arg line="${http.host}"/> + <arg line="${http.port}"/> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/client/Client.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/client/Client.java new file mode 100644 index 0000000..7517908 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/client/Client.java
@@ -0,0 +1,94 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + + +import java.net.*; +import java.io.*; +import java.util.*; +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import javax.naming.InitialContext; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +public class Client { + + private static SimpleReporterAdapter stat = + new SimpleReporterAdapter("appserv-tests"); + + private static String appName; + private String host; + private String port; + + @Resource(lookup="java:app/env/value1") + private static Integer appLevelViaLookup; + + public static void main(String args[]) { + appName = args[0]; + stat.addDescription(appName); + Client client = new Client(args); + client.doTest(); + stat.printSummary(appName + "ID"); + System.out.println("appLevelViaLookup = '" + + appLevelViaLookup + "'"); + } + + public Client(String[] args) { + host = args[1]; + port = args[2]; + } + + + + public void doTest() { + + try { + + String url = "http://" + host + ":" + port + + "/" + appName + "/HelloServlet"; + + System.out.println("invoking webclient servlet at " + url); + + URL u = new URL(url); + + HttpURLConnection c1 = (HttpURLConnection)u.openConnection(); + int code = c1.getResponseCode(); + InputStream is = c1.getInputStream(); + BufferedReader input = new BufferedReader (new InputStreamReader(is)); + String line = null; + while((line = input.readLine()) != null){ + System.out.println("<response>:"+ line); + if (line.trim().length() > 0) { + stat.addStatus("local main", stat.FAIL); + return; + } + } + if(code != 200) { + stat.addStatus("local main", stat.FAIL); + return; + } + stat.addStatus("local main", stat.PASS); + + } catch(Exception e) { + stat.addStatus("local main", stat.FAIL); + e.printStackTrace(); + } + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/descriptor/application.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/descriptor/application.xml new file mode 100644 index 0000000..d9378e7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/descriptor/application.xml
@@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="6" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"> + <display-name>ejb-ejb30-hello-session3App</display-name> + <module> + <ejb>cdi-full-ear-ejb.jar</ejb> + </module> + <module> + <web> + <web-uri>cdi-full-ear-web.war</web-uri> + <context-root>cdi-full-ear</context-root> + </web> + </module> + <env-entry> + <env-entry-name>java:app/env/value1</env-entry-name> + <env-entry-type>java.lang.Integer</env-entry-type> + <env-entry-value>18338</env-entry-value> + </env-entry> + <env-entry> + <env-entry-name>java:app/env/myString</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + <env-entry-value>myString</env-entry-value> + </env-entry> +</application>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/BarManagedBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/BarManagedBean.java new file mode 100644 index 0000000..473e12b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/BarManagedBean.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.annotation.*; +import javax.ejb.EJB; +import javax.annotation.Resource; +import javax.sql.DataSource; + +@ManagedBean +public class BarManagedBean { + + @EJB Hello s; + @Resource(name="jdbc/__default") DataSource ds; + + @PostConstruct + private void init() { + System.out.println("In BarManagedBean::init() " + this); + } + + public void bar() { + System.out.println("In BarManagedBean::bar() "); + } + + + @PreDestroy + private void destroy() { + System.out.println("In BarManagedBean::destroy() "); + } + + public String toString() { + return "BarManagedBean this = " + super.toString() + + " s = " + s + " , ds = " + ds; + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/Foo.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/Foo.java new file mode 100644 index 0000000..658d9d0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/Foo.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + + +public interface Foo { + + public void foo(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/FooBarManagedBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/FooBarManagedBean.java new file mode 100644 index 0000000..e45f3ee --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/FooBarManagedBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.annotation.*; + +@ManagedBean("foobarmanagedbean") +public class FooBarManagedBean { + + @PostConstruct + private void init() { + System.out.println("In FooBarManagedBean::init() " + this); + } + + @PreDestroy + private void destroy() { + System.out.println("In FooBarManagedBean::destroy() "); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/FooManagedBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/FooManagedBean.java new file mode 100644 index 0000000..4fcb3c4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/FooManagedBean.java
@@ -0,0 +1,66 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.annotation.*; + +import javax.ejb.EJB; +import javax.annotation.Resource; +import org.omg.CORBA.ORB; +import javax.persistence.PersistenceContext; +import javax.persistence.EntityManager; + +@ManagedBean("somemanagedbean") +public class FooManagedBean extends ManagedSuper implements Foo { + + @EJB HelloRemote s; + @Resource ORB orb; + @Resource BarManagedBean bmb; + @PersistenceContext EntityManager em; + + @PostConstruct + private void init() { + System.out.println("In FooManagedBean::init() " + this); + } + + + public String getName() { + return "somemanagedbean"; + } + + public void foo() { + System.out.println("In FooManagedBean::foo() "); + bmb.bar(); + } + + public Object getThis() { + return this; + } + + @PreDestroy + private void destroy() { + System.out.println("In FooManagedBean::destroy() "); + } + + + public String toString() { + return "FooManagedBean this = " + super.toString() + + " s = " + s + " , orb = " + orb + + " , bmb = " + bmb + " , em = " + em; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/Hello.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/Hello.java new file mode 100644 index 0000000..2ad0681 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/Hello.java
@@ -0,0 +1,25 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + + + +public interface Hello { + + public String hello(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/HelloRemote.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/HelloRemote.java new file mode 100644 index 0000000..fc138ad --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/HelloRemote.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.ejb.Remote; + +@Remote +public interface HelloRemote { + + public String hello(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/HelloSingleton.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/HelloSingleton.java new file mode 100644 index 0000000..014cdd7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/HelloSingleton.java
@@ -0,0 +1,119 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.ejb.*; +import javax.annotation.*; + +import org.omg.CORBA.ORB; + + +@Singleton +@Startup + @EJB(name="java:app/env/AS2", beanName="HelloStateless", beanInterface=HelloRemote.class) + @DependsOn("Singleton2") +public class HelloSingleton implements Hello { + + @Resource SessionContext sessionCtx; + + @Resource(mappedName="java:module/foobarmanagedbean") + private FooBarManagedBean fbmb; + + @Resource + private FooBarManagedBean fbmb2; + + @Resource(name="java:module/env/MORB2") + private ORB orb; + + @Resource + private FooManagedBean foo; + + @Resource(name="foo2ref", mappedName="java:module/somemanagedbean") + private FooManagedBean foo2; + + @Resource(name="foo3ref", mappedName="java:module/somemanagedbean") + private Foo foo3; + + private FooManagedBean foo4; + private FooManagedBean foo5; + private Foo foo6; + private FooManagedBean foo7; + private Foo foo8; + + @Resource(name = "java:app/env/myString") + protected String myString; + + @EJB(name="java:app/env/appLevelEjbRef") + private Hello hello; + + String appName; + String moduleName; + + @PostConstruct + private void init() { + System.out.println("HelloSingleton::init()"); + + System.out.println("myString = '" + myString + "'"); + if( (myString == null) || !(myString.equals("myString") ) ) { + throw new RuntimeException("Invalid value " + myString + " for myString"); + } + + appName = (String) sessionCtx.lookup("java:app/AppName"); + moduleName = (String) sessionCtx.lookup("java:module/ModuleName"); + + ORB orb1 = (ORB) sessionCtx.lookup("java:module/MORB1"); + ORB orb2 = (ORB) sessionCtx.lookup("java:module/env/MORB2"); + + System.out.println("AppName = " + appName); + System.out.println("ModuleName = " + moduleName); + + foo4 = (FooManagedBean) sessionCtx.lookup("java:module/somemanagedbean"); + foo5 = (FooManagedBean) sessionCtx.lookup("java:app/" + moduleName + + "/somemanagedbean"); + foo6 = (Foo) sessionCtx.lookup("java:app/" + moduleName + + "/somemanagedbean"); + foo7 = (FooManagedBean) sessionCtx.lookup("java:comp/env/foo2ref"); + foo8 = (Foo) sessionCtx.lookup("java:comp/env/foo3ref"); + } + + public String hello() { + + System.out.println("HelloSingleton::hello()"); + + + foo.foo(); + foo2.foo(); + foo3.foo(); + + foo4.foo(); + foo5.foo(); + foo6.foo(); + foo7.foo(); + foo8.foo(); + + return "hello, world!\n"; + } + + + @PreDestroy + private void destroy() { + System.out.println("HelloSingleton::destroy()"); + } + +} + +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/HelloStateless.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/HelloStateless.java new file mode 100644 index 0000000..ecd8f11 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/HelloStateless.java
@@ -0,0 +1,91 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.ejb.*; +import javax.annotation.*; + +import org.omg.CORBA.ORB; + +@Stateless + @EJB(name="java:global/GS1", beanName="HelloSingleton", beanInterface=Hello.class) +public class HelloStateless implements HelloRemote { + + @EJB(name="java:app/env/AS1", beanName="HelloSingleton") + private Hello h; + + @Resource(name="java:module/MORB1") + private ORB orb; + + @EJB(name="lookupref1", lookup="java:app/env/AS1") + private Hello lookupref1; + + @EJB(name="lookupref2", lookup="java:global/GS1") + private Hello lookupref2; + + @EJB(name="lookupref3", lookup="java:module/HelloStateless!com.acme.HelloRemote") + private HelloRemote lookupref3; + + // declare component-level dependency using fully-qualified + // java:comp/env form. + @Resource(name="java:comp/env/foo") SessionContext sessionCtx; + + @PostConstruct + private void init() { + System.out.println("HelloStateless::init()"); + } + + public String hello() { + System.out.println("In HelloStateless::hello()"); + + String appName = (String) sessionCtx.lookup("java:app/AppName"); + String moduleName = (String) sessionCtx.lookup("java:module/ModuleName"); + System.out.println("AppName = " + appName); + System.out.println("ModuleName = " + moduleName); + + ORB orb1 = (ORB) sessionCtx.lookup("java:module/MORB1"); + ORB orb2 = (ORB) sessionCtx.lookup("java:module/env/MORB2"); + + Hello s1 = (Hello) sessionCtx.lookup("java:global/" + + appName + "/" + + moduleName + "/" + + "HelloSingleton"); + + Hello s2 = (Hello) sessionCtx.lookup("java:app/" + + moduleName + "/" + + "HelloSingleton"); + + // Rely on default to resolve "java:comp/env/ declared resource + SessionContext sc1 = (SessionContext) + sessionCtx.lookup("foo"); + + SessionContext sc2 = (SessionContext) + sc1.lookup("java:comp/env/foo"); + + Integer envEntry = (Integer) + sc1.lookup("java:app/env/value1"); + System.out.println("java:ap/env/value1 = " + envEntry); + + return "hello, world!\n"; + } + + @PreDestroy + private void destroy() { + System.out.println("HelloStateless::destroy()"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/ManagedSuper.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/ManagedSuper.java new file mode 100644 index 0000000..c52c898 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/ManagedSuper.java
@@ -0,0 +1,45 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.annotation.*; +import javax.ejb.EJB; +import javax.annotation.Resource; +import javax.sql.DataSource; + +public class ManagedSuper { + + @EJB Hello s; + @Resource(name="jdbc/__default") DataSource ds; + + @PostConstruct + private void init() { + System.out.println("In ManagedSuper::init() " + this); + } + + @PreDestroy + private void destroy() { + System.out.println("In ManagedSuper::destroy() "); + } + + public String toString() { + return "ManagedSuper this = " + super.toString() + + " s = " + s + " , ds = " + ds; + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/Singleton2.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/Singleton2.java new file mode 100644 index 0000000..18dbb03 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/Singleton2.java
@@ -0,0 +1,39 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.ejb.*; +import javax.annotation.*; + + +@Singleton +@DependsOn("cdi-full-ear-ejb.jar#Singleton3") +public class Singleton2 { + + @PostConstruct + public void init() { + System.out.println("In SingletonBean2::init()"); + } + + @PreDestroy + public void destroy() { + System.out.println("In SingletonBean2::destroy()"); + } + + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/Singleton3.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/Singleton3.java new file mode 100644 index 0000000..364046b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/Singleton3.java
@@ -0,0 +1,39 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.ejb.*; +import javax.annotation.*; + + +@Singleton +@DependsOn("./cdi-full-ear-ejb.jar#Singleton4") +public class Singleton3 { + + @PostConstruct + public void init() { + System.out.println("In SingletonBean3::init()"); + } + + @PreDestroy + public void destroy() { + System.out.println("In SingletonBean3::destroy()"); + } + + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/Singleton4.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/Singleton4.java new file mode 100644 index 0000000..9d3ff4a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/ejb/Singleton4.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.ejb.*; +import javax.annotation.*; + + +@Singleton +public class Singleton4 { + + @PostConstruct + public void init() { + System.out.println("In SingletonBean4::init()"); + } + + @PreDestroy + public void destroy() { + System.out.println("In SingletonBean4::destroy()"); + } + + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/manifest.mf b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/manifest.mf
@@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/Foo.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/Foo.java new file mode 100644 index 0000000..658d9d0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/Foo.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + + +public interface Foo { + + public void foo(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/Foo2ManagedBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/Foo2ManagedBean.java new file mode 100644 index 0000000..e3b9464 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/Foo2ManagedBean.java
@@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.annotation.*; + +import javax.ejb.EJB; +import javax.annotation.Resource; +import org.omg.CORBA.ORB; +import javax.persistence.PersistenceContext; +import javax.persistence.EntityManager; + +@ManagedBean("somemanagedbean") +public class Foo2ManagedBean { + + @EJB HelloRemote s; + @Resource ORB orb; + @PersistenceContext EntityManager em; + + @PostConstruct + private void init() { + System.out.println("In Foo2ManagedBean::init() " + this); + } + + public void foo() { + System.out.println("In Foo2ManagedBean::foo() "); + } + + public Object getThis() { + return this; + } + + @PreDestroy + private void destroy() { + System.out.println("In Foo2ManagedBean::destroy() "); + } + + + public String toString() { + return "Foo2ManagedBean this = " + + " s = " + s + " , orb = " + orb + + " , em = " + em; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/FooBarManagedBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/FooBarManagedBean.java new file mode 100644 index 0000000..e45f3ee --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/FooBarManagedBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.annotation.*; + +@ManagedBean("foobarmanagedbean") +public class FooBarManagedBean { + + @PostConstruct + private void init() { + System.out.println("In FooBarManagedBean::init() " + this); + } + + @PreDestroy + private void destroy() { + System.out.println("In FooBarManagedBean::destroy() "); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/Hello.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/Hello.java new file mode 100644 index 0000000..d08c598 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/Hello.java
@@ -0,0 +1,25 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.ejb.Remote; + +public interface Hello { + + public String hello(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/HelloRemote.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/HelloRemote.java new file mode 100644 index 0000000..fc138ad --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/HelloRemote.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.ejb.Remote; + +@Remote +public interface HelloRemote { + + public String hello(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/HelloServlet.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/HelloServlet.java new file mode 100644 index 0000000..171d1f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ear/war/HelloServlet.java
@@ -0,0 +1,194 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.ejb.EJB; +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.annotation.WebServlet; +import javax.annotation.Resource; +import javax.naming.*; + +@WebServlet(urlPatterns = "/HelloServlet", loadOnStartup = 1) +@EJB(name = "java:module/m1", beanName = "HelloSingleton", beanInterface = Hello.class) +public class HelloServlet extends HttpServlet { + + @Resource(mappedName = "java:module/foobarmanagedbean") + private FooBarManagedBean fbmb; + @Resource + private FooBarManagedBean fbmb2; + + @EJB(name = "java:module/env/m2") + private Hello m1; + @EJB(name = "java:app/a1") + private HelloRemote a1; + @EJB(name = "java:app/env/a2") + private HelloRemote a2; + @Resource(name = "java:app/env/myString") + protected String myString; + private Hello singleton1; + private Hello singleton2; + private Hello singleton3; + private Hello singleton4; + private Hello singleton5; + private HelloRemote stateless1; + private HelloRemote stateless2; + + @Resource + private Foo2ManagedBean foo; + @Resource(name = "foo2ref", mappedName = "java:module/somemanagedbean") + private Foo2ManagedBean foo2; + @Resource(name = "foo3ref", mappedName = "java:app/cdi-full-ear-ejb/somemanagedbean") + private Foo foo3; + private Foo2ManagedBean foo4; + private Foo2ManagedBean foo5; + private Foo foo6; + private Foo2ManagedBean foo7; + private Foo foo8; + + private String msg = ""; + + @Override + public void init(ServletConfig config) throws ServletException { + super.init(config); + + System.out.println("In HelloServlet::init"); + System.out.println("myString = '" + myString + "'"); + if ((myString == null) || !(myString.equals("myString"))) { + msg += "@Resource lookup of myString failed"; + throw new RuntimeException("Invalid value " + myString + " for myString"); + } + + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + System.out.println("In HelloServlet::doGet"); + resp.setContentType("text/html"); + checkForNull(foo, "@Resource lookup of ManagedBean failed"); + checkForNull(foo2, "@Resource lookup of module-level ManagedBean failed"); + checkForNull(foo3, "@Resource lookup of app-level ManagedBean through a super-interface failed"); + + PrintWriter out = resp.getWriter(); + try { + InitialContext ic = new InitialContext(); + String appName = (String) ic.lookup("java:app/AppName"); + String moduleName = (String) ic.lookup("java:module/ModuleName"); + checkForNull(appName, "AppName lookup returned null"); + checkForNull(moduleName, "ModuleName lookup returned null"); + + // lookup via intermediate context + Context appCtx = (Context) ic.lookup("java:app"); + Context appCtxEnv = (Context) appCtx.lookup("env"); + stateless2 = (HelloRemote) appCtxEnv.lookup("AS2"); + checkForNull(stateless2, "lookup of stateless EJB via java:app in intermediate context failed"); + NamingEnumeration<Binding> bindings = appCtxEnv.listBindings(""); + System.out.println("java:app/env/ bindings "); + while (bindings.hasMore()) { + System.out.println("binding : " + bindings.next().getName()); + } + + + foo4 = (Foo2ManagedBean) ic.lookup("java:module/somemanagedbean"); + checkForNull(foo4, "programmatic lookup of module-level managedbean failed"); + foo5 = (Foo2ManagedBean) ic.lookup("java:app/" + moduleName + + "/somemanagedbean"); + checkForNull(foo5, "programmatic lookup of module-level managedbean through application context failed"); + foo6 = (Foo) ic.lookup("java:app/cdi-full-ear-ejb/somemanagedbean"); + checkForNull(foo6, "programmatic lookup of application-level managedbean failed"); + foo7 = (Foo2ManagedBean) ic.lookup("java:comp/env/foo2ref"); + checkForNull(foo7, "programmatic lookup of module-level managedbean through a component reference failed"); + foo8 = (Foo) ic.lookup("java:comp/env/foo3ref"); + checkForNull(foo8, "programmatic lookup of module-level managedbean through a component reference failed"); + + singleton1 = (Hello) ic.lookup("java:module/m1"); + checkForNull(singleton1, "programmatic lookup of module-level singleton EJB failed"); + + // standard java:app name for ejb + singleton2 = (Hello) ic.lookup("java:app/cdi-full-ear-ejb/HelloSingleton"); + checkForNull(singleton2, "programmatic lookup of module-level singleton EJB through app reference failed"); + + singleton3 = (Hello) ic.lookup("java:global/" + appName + "/cdi-full-ear-ejb/HelloSingleton"); + checkForNull(singleton3, "programmatic lookup of module-level singleton EJB through global reference failed"); + + // lookup some java:app defined by ejb-jar + singleton4 = (Hello) ic.lookup("java:app/env/AS1"); + checkForNull(singleton4, "programmatic lookup of module-level singleton EJB through EJB name failed"); + // global dependency + singleton5 = (Hello) ic.lookup("java:global/GS1"); + checkForNull(singleton5, "programmatic lookup of singleton EJB through global name failed"); + + stateless1 = (HelloRemote) ic.lookup("java:app/env/AS2"); + checkForNull(stateless1, "programmatic lookup of app-level stateless EJB failed"); + + System.out.println("My AppName = " + + ic.lookup("java:app/AppName")); + + System.out.println("My ModuleName = " + + ic.lookup("java:module/ModuleName")); + + + + try { + org.omg.CORBA.ORB orb = (org.omg.CORBA.ORB) ic.lookup("java:module/MORB1"); + msg += " Not getting naming exception when we try to see ejb-jar module-level dependency"; + throw new RuntimeException("Should have gotten naming exception"); + } catch (NamingException ne) { + System.out.println("Successfully was *not* able to see ejb-jar module-level dependency"); + } + + } catch (Exception e) { + msg += "Exception occurred during test Exception: " + e.getMessage(); + e.printStackTrace(); + } + + foo.foo(); + foo2.foo(); + foo3.foo(); + + foo4.foo(); + foo5.foo(); + foo6.foo(); + foo7.foo(); + foo8.foo(); + + m1.hello(); + a1.hello(); + a2.hello(); + singleton1.hello(); + singleton2.hello(); + singleton3.hello(); + singleton4.hello(); + singleton5.hello(); + + stateless1.hello(); + stateless2.hello(); + + out.println(msg); + + } + + protected void checkForNull(Object o, String errorMessage){ + if (o == null) msg += " " + errorMessage; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/build.properties b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/build.properties new file mode 100644 index 0000000..e0533ab --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/build.properties
@@ -0,0 +1,38 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="simple-ejb-cdi"/> +<property name="appname" value="${module}"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="simple.client" value="com.sun.s1asdev.ejb.ejb30.hello.session.client.StandaloneClient"/> +<property name="simple.client2" value="com.sun.s1asdev.ejb.ejb30.hello.session.client.StandaloneClient2"/> +<property name="test.client" + value="Client"/> +<property name="application.xml" value="descriptor/application.xml"/> +<property name="sun-application.xml" value="descriptor/sun-application.xml"/> +<property name="ejb-jar.xml" value="descriptor/ejb-jar.xml"/> +<property name="sun-ejb-jar.xml" value="descriptor/sun-ejb-jar.xml"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="application-client.xml" + value="descriptor/application-client.xml"/> +<property name="sun-application-client.xml" + value="descriptor/sun-application-client.xml"/> +<property name="appclientjar.files" value="${build.classes.dir}"/> +<property name="appclient.jar" value="${assemble.dir}/${appname}-client.jar"/> +<property name="app.type" value="application"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/build.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/build.xml new file mode 100644 index 0000000..2dc8d89 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/build.xml
@@ -0,0 +1,106 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="simple-ejb-cdi" default="usage" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete file="client/Client.java"/> + </target> + + <target name="compile" depends="clean"> + <copy file="client/Client.java.token" tofile="client/Client.java"/> + <replace file="client/Client.java" + token="@ORB_PORT@" value="${orb.port}"/> + + <antcall target="compile-common"> + <param name="src" value="ejb"/> + </antcall> + <antcall target="compile-common"> + <param name="src" value="client"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <antcall target="build-ear-common"> + <param name="ejbjar.classes" + value="**/Sful*.class,**/Sless*.class, **/TestBean.class"/> + <param name="appclientjar.classes" + value="**/Client.class,**/Sful.class,**/Sless.class"/> + </antcall> + </target> + + <target name="deploy" + depends="init-common"> + <antcall target="deploy-common"/> + </target> + + <target name="run" depends="init-common"> + <antcall target="runclient-common"/> +<!-- + <antcall target="run_standaloneclient"/> + <antcall target="run_standaloneclient2"/> +--> + </target> + + + <target name="run_standaloneclient" depends="init-common"> + <java fork="on" + failonerror="true" + classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/lib/gf-client.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar" + classname="${simple.client}"> + <sysproperty key="org.omg.CORBA.ORBInitialPort" value="${orb.port}"/> + </java> + </target> + + <target name="run_standaloneclient2" depends="init-common"> + <java fork="on" + failonerror="true" + classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/lib/gf-client.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar" + classname="${simple.client2}"> + <jvmarg + value="-Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory"/> + <jvmarg + value="-Djava.naming.provider.url=iiop://localhost:${orb.port}"/> + <jvmarg + value="-Dorg.omg.CORBA.ORBInitialPort=${orb.port}"/> + + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/client/Client.java.token b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/client/Client.java.token new file mode 100644 index 0000000..39f9798 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/client/Client.java.token
@@ -0,0 +1,111 @@ +/* + * Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.s1asdev.cdi.ejb.hello.session.client; + + +import java.io.*; +import java.util.*; +import javax.ejb.EJB; +import javax.naming.InitialContext; +import com.sun.s1asdev.cdi.ejb.hello.session.*; +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +public class Client { + + private static SimpleReporterAdapter stat = + new SimpleReporterAdapter("appserv-tests"); + + public static void main (String[] args) { + + stat.addDescription("simple-ejb-cdi"); + Client client = new Client(args); + client.doTest(); + stat.printSummary("simple-ejb-cdi"); + } + + public Client (String[] args) { + } + + private static @EJB Sful sful; + + private static @EJB(mappedName="com.sun.s1asdev.cdi.ejb.hello.session.Sless") Sless sless; + + // + // NOTE: Token @ORB_PORT@ will be replaced in @EJB annotations below + // with the value of the port from config.properties during the build + // + private static @EJB(mappedName="corbaname:iiop:localhost:@ORB_PORT@#com.sun.s1asdev.cdi.ejb.hello.session.Sless") Sless sless2; + + private static @EJB(mappedName="corbaname:iiop:localhost:@ORB_PORT@#java:global/simple-ejb-cdiApp/simple-ejb-cdi-ejb/SlessEJB!com.sun.s1asdev.cdi.ejb.hello.session.Sless") Sless sless3; + + private static @EJB(mappedName="corbaname:iiop:localhost:@ORB_PORT@#java:global/simple-ejb-cdiApp/simple-ejb-cdi-ejb/SlessEJB") Sless sless4; + + public void doTest() { + + try { + + System.out.println("Creating InitialContext()"); + InitialContext ic = new InitialContext(); + org.omg.CORBA.ORB orb = (org.omg.CORBA.ORB) ic.lookup("java:comp/ORB"); + Sful sful = (Sful) ic.lookup("com.sun.s1asdev.cdi.ejb.hello.session.Sful"); + Sless sless = (Sless) ic.lookup("com.sun.s1asdev.cdi.ejb.hello.session.Sless"); + + String response = null; + + response = sful.hello(); + testResponse("invoking stateful", response); + + response = sless.hello(); + testResponse("invoking stateless", response); + + response = sless2.hello(); + testResponse("invoking stateless2", response); + + System.out.println("ensuring that sless1 and sless2 are not equal"); + if( !sless.equals(sless2) ) { + stat.addStatus("ensuring that sless1 and sless2 are not equal" , stat.FAIL); + throw new Exception("invalid equality checks on same " + + "sless session beans"); + } + + + response = sless3.hello(); + testResponse("invoking stateless3", response); + response = sless4.hello(); + testResponse("invoking stateless4", response); + + System.out.println("test complete"); + + stat.addStatus("local main", stat.PASS); + + } catch(Exception e) { + e.printStackTrace(); + stat.addStatus("local main" , stat.FAIL); + } + + return; + } + + private void testResponse(String testDescription, String response){ + if(response.equals("hello")) + stat.addStatus(testDescription, stat.PASS); + else + stat.addStatus(testDescription, stat.FAIL); + } + +} +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/client/MANIFEST.MF b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/client/MANIFEST.MF new file mode 100644 index 0000000..0b2b85f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/client/MANIFEST.MF
@@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Created-By: 1.4.0-beta3 (Sun Microsystems Inc.) +Main-Class: com.sun.s1asdev.cdi.ejb.hello.session.client.Client +Class-Path: reporter.jar
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/ejb/Sful.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/ejb/Sful.java new file mode 100644 index 0000000..bd40dc3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/ejb/Sful.java
@@ -0,0 +1,25 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.s1asdev.cdi.ejb.hello.session; + +import javax.ejb.Remote; + +@Remote +public interface Sful +{ + public String hello(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/ejb/SfulEJB.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/ejb/SfulEJB.java new file mode 100644 index 0000000..ded6d50 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/ejb/SfulEJB.java
@@ -0,0 +1,42 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.s1asdev.cdi.ejb.hello.session; + +import javax.ejb.Stateful; +import javax.inject.Inject; + +@Stateful +public class SfulEJB implements Sful +{ + @Inject TestBean tb; // field injection + +/* +@todo: check why constructor injection doesn't work + TestBean tb; + @Inject + public SfulEJB(TestBean tb){ + this.tb = tb; + if (tb == null) throw new RuntimeException("tb is null"); + } +*/ + public String hello() { + System.out.println("In SfulEJB:hello()"); + if (tb != null) return "hello"; + else return null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/ejb/Sless.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/ejb/Sless.java new file mode 100644 index 0000000..97fe185 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/ejb/Sless.java
@@ -0,0 +1,27 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.s1asdev.cdi.ejb.hello.session; + +import javax.ejb.Remote; + +@Remote +public interface Sless +{ + public String hello(); + + public org.glassfish.common.util.timer.TimerSchedule foo (); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/ejb/SlessEJB.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/ejb/SlessEJB.java new file mode 100644 index 0000000..dec52e0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/ejb/SlessEJB.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.s1asdev.cdi.ejb.hello.session; + +import javax.ejb.Stateless; +import javax.inject.Inject; + +@Stateless +public class SlessEJB implements Sless +{ + @Inject TestBean tb; //Field Injection + + public String hello() { + System.out.println("In SlessEJB:hello()"); + if (tb != null) return "hello"; + else return null; + } + + public org.glassfish.common.util.timer.TimerSchedule foo () {return null;} +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/ejb/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/ejb/TestBean.java new file mode 100644 index 0000000..3f97997 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/ejb/TestBean.java
@@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.s1asdev.cdi.ejb.hello.session; + + +//Simple TestBean to test CDI. This bean implements Serializable as it needs to be placed into a Stateful Bean +public class TestBean implements java.io.Serializable +{}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/readme.txt b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/readme.txt new file mode 100644 index 0000000..bad16d6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-cdi/readme.txt
@@ -0,0 +1 @@ +client/Client.java is created during build process from client/Client.java.token via copying it and replacing token @ORB_PORT@ with the ORB port number from config.properties (${orb.pprt}).
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/build.properties b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/build.properties new file mode 100644 index 0000000..982c344 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/build.properties
@@ -0,0 +1,27 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi-singleton-hello"/> +<property name="appname" value="${module}"/> +<property name="jndiroot" value="${appname}-ejb"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="se.client" value="com.acme.Client"/> +<property name="beans.xml" value="descriptor/beans.xml"/> + +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/build.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/build.xml new file mode 100644 index 0000000..ad8c001 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/build.xml
@@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../../config/common.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="cdi-singleton-hello-App" default="usage" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="ejb"/> + </antcall> + <antcall target="compile-common"> + <param name="src" value="client"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <antcall target="ejb-jar-common"> + <param name="ejbjar.classes" + value="**/Foo*.class,**/Test*.class,**/Singleton*.class,**/Hello*.class"/> + </antcall> + </target> + + <target name="deploy" + depends="init-common"> + <antcall target="deploy-jar-common"/> + </target> + + <target name="run" depends="init-common"> + <antcall target="run_se"/> + </target> + + <target name="run_se" depends="init-common"> + <java fork="on" + failonerror="true" + classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/lib/appserv-rt.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar" + classname="${se.client}"> + <sysproperty key="org.omg.CORBA.ORBInitialPort" value="${orb.port}"/> + <arg line="${jndiroot}"/> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-jar-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/client/Client.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/client/Client.java new file mode 100644 index 0000000..cc27565 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/client/Client.java
@@ -0,0 +1,89 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + + +import javax.ejb.*; +import javax.annotation.*; + +import javax.naming.InitialContext; + +import javax.management.j2ee.ManagementHome; +import javax.management.j2ee.Management; +import javax.rmi.PortableRemoteObject; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +public class Client { + + private static SimpleReporterAdapter stat = + new SimpleReporterAdapter("appserv-tests"); + + private static String appName; + + public static void main(String args[]) { + + appName = args[0]; + stat.addDescription(appName); + Client client = new Client(args); + client.doTest(); + stat.printSummary(appName + "ID"); + } + + public Client(String[] args) {} + + public void doTest() { + + try { + + // Ensure that MEJB is registered under all three of its JNDI names + System.out.println("Looking up MEJB Homes"); + ManagementHome mh1Obj = (ManagementHome) new InitialContext().lookup("ejb/mgmt/MEJB"); + ManagementHome mh2Obj = (ManagementHome) new InitialContext().lookup("java:global/mejb/MEJBBean"); + ManagementHome mh3Obj = (ManagementHome) new InitialContext().lookup("java:global/mejb/MEJBBean!javax.management.j2ee.ManagementHome"); + addStatus("mejb relative lookup", (mh1Obj != null)); + addStatus("mejb global lookup", (mh2Obj != null)); + addStatus("mejb global lookup with explicit ManagedHome interface", (mh3Obj != null)); + + Hello hello = (Hello) new InitialContext().lookup("java:global/" + appName + "/SingletonBean"); + String response = hello.hello(); + addStatus("Singleton bean response", response.equals("hello, world!\n")); + + try { + hello.testError(); + addStatus("Expected EJBException from Singleton.testError()", false); + throw new RuntimeException("Expected EJBException"); + } catch(EJBException e) { + addStatus("Expected EJBException from Singleton.testError()", true); + } + + String injectionStatus = hello.testInjection(); + System.out.println("Injection tests in server response"+ injectionStatus); + addStatus("Testing Injection in EJB Singleton" , injectionStatus.trim().equals("")); + + } catch(Exception e) { + stat.addStatus("local main", stat.DID_NOT_RUN); + e.printStackTrace(); + } + } + + private void addStatus(String message, boolean result){ + stat.addStatus(message, (result ? stat.PASS: stat.FAIL)); + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/ejb/Foo.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/ejb/Foo.java new file mode 100644 index 0000000..1d87d9d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/ejb/Foo.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.ejb.*; + +public class Foo { + + @EJB Hello hello; + @javax.inject.Inject TestBean tb; + + public boolean testInjection(){ + return tb != null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/ejb/Hello.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/ejb/Hello.java new file mode 100644 index 0000000..23f4df7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/ejb/Hello.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +public interface Hello { + + String hello(); + + void testError(); + String testInjection(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/ejb/SingletonBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/ejb/SingletonBean.java new file mode 100644 index 0000000..5493293 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/ejb/SingletonBean.java
@@ -0,0 +1,107 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.ejb.*; +import javax.annotation.*; +import org.omg.CORBA.ORB; + +import javax.naming.InitialContext; + +import javax.management.j2ee.ManagementHome; +import javax.inject.Inject; + +@Singleton +@Remote(Hello.class) + @EJB(name="mejb", beanInterface=javax.management.j2ee.ManagementHome.class, mappedName="ejb/mgmt/MEJB") +@Startup +public class SingletonBean { + + @Resource + private ORB orb; + + @Inject Foo foo; + @Inject TestBean tb; + + /*Object returned from IIOP_OBJECT_FACTORY is still ior + @EJB(mappedName="ejb/mgmt/MEJB") + ManagementHome mHome1; + */ + + /* Object returned from IIOP_OBJECT_FACTORY is still ior + @EJB(lookup="java:global/mejb/MEJBBean") + ManagementHome mHome2; + */ + + /* Doesn't work b/c actual MEJB app Home interface is new glassfish + * type, so actual type derived from field declaration is tacked + * onto mappedName and results in NameNotFound + @EJB(mappedName="java:global/mejb/MEJBBean") + ManagementHome mHome2; + */ + + + + + //MEJBHome mHome2; + + @PostConstruct + public void init() { + System.out.println("In SingletonBean::init()"); + System.out.println("orb = " + orb); + if( orb == null ) { + throw new EJBException("null ORB"); + } + try { + // same problem ManagementHome mHomeL = (ManagementHome) new InitialContext().lookup("java:comp/env/mejb"); + // same problem ManagementHome mHomeL2 = (ManagementHome) new InitialContext().lookup("java:global/mejb/MEJBBean"); + // System.out.println("mHomeL = " + mHomeL); + // System.out.println("mHomeL2 = " + mHomeL2); + } catch(Exception e) { + throw new EJBException(e); + } + + // System.out.println("mHome1 = " + mHome1); + // System.out.println("mHome2 = " + mHome2); + + } + + public String hello() { + System.out.println("In SingletonBean::hello()"); + return "hello, world!\n"; + } + + public void testError() { + throw new Error("test java.lang.Error"); + } + + public String testInjection(){ + if (foo == null) return "foo is null"; + if (tb == null) return "tb is null"; + if (!foo.testInjection()) return "testInjection in Foo failed"; + return ""; + } + + + @PreDestroy + public void destroy() { + System.out.println("In SingletonBean::destroy()"); + } + + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/ejb/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/ejb/TestBean.java new file mode 100644 index 0000000..22e521a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-ejb-singleton/hello/ejb/TestBean.java
@@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +//Simple test bean to test injection +public class TestBean {}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/README b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/README new file mode 100644 index 0000000..f6d9f21 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/README
@@ -0,0 +1 @@ + A modification of the simple managed bean intereceptor test that uses non-default packages for the Managed Beans to get around Issue WELD-728
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/WebTest.java new file mode 100644 index 0000000..76b21c9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/WebTest.java
@@ -0,0 +1,109 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "simple-managed-bean-interceptor-with-non-default-packaged-beans"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/build.properties b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/build.properties new file mode 100644 index 0000000..a4d5078 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-simple-managed-bean-interceptor-with-non-default-packages"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/build.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/build.xml new file mode 100644 index 0000000..83ad666 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/descriptor/beans.xml new file mode 100644 index 0000000..a52bc90 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/descriptor/beans.xml
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>com.tests.TestAroundInvokeInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/servlet/com/tests/TestAroundInvokeInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/servlet/com/tests/TestAroundInvokeInterceptor.java new file mode 100644 index 0000000..379dfbf --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/servlet/com/tests/TestAroundInvokeInterceptor.java
@@ -0,0 +1,37 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.tests; + +import javax.interceptor.*; + +@Tester @Interceptor +public class TestAroundInvokeInterceptor { + public static int aroundInvokeCount = 0; + + public static void reset(){ + aroundInvokeCount = 0; + } + + @AroundInvoke + public Object testMethod(InvocationContext ctx) throws Exception { + System.out.println("TestAroundInvokeIntercetpr:: aroundInvoke called - target:" + ctx.getTarget() + " , params:"+ ctx.getParameters()); + aroundInvokeCount ++; + ctx.proceed(); + return null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/servlet/com/tests/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/servlet/com/tests/TestBean.java new file mode 100644 index 0000000..8de8781 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/servlet/com/tests/TestBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.tests; + +//Simple Bean to test injection into ManagedBeans +public class TestBean { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/servlet/com/tests/TestManagedBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/servlet/com/tests/TestManagedBean.java new file mode 100644 index 0000000..b0b60ef --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/servlet/com/tests/TestManagedBean.java
@@ -0,0 +1,56 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.tests; + +//Simple TestBean to test CDI. +//This bean implements Serializable as it needs to be placed into a Stateful Bean +@javax.annotation.ManagedBean +public class TestManagedBean { + TestBean tb; + boolean postConstructCalled = false; + + + //A Managed Bean needs to have a no-arg constructor + public TestManagedBean() {} + @javax.inject.Inject //Constructor based Injection + public TestManagedBean(TestBean tb){ + this.tb = tb; + } + + + @javax.annotation.PostConstruct + public void init(){ + System.out.println("In ManagedBean:: PostConstruct"); + postConstructCalled = true; + } + + @Tester + public void foo(){ + System.out.println("foo called"); + } + + public boolean testPostConstructCalled(){ + return this.postConstructCalled; + } + + public boolean testInjection(){ + System.out.println("In ManagedBean:: tb=" + tb); + postConstructCalled = true; + return this.tb != null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/servlet/com/tests/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/servlet/com/tests/TestServlet.java new file mode 100644 index 0000000..9fac0e4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/servlet/com/tests/TestServlet.java
@@ -0,0 +1,76 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.tests; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(name="mytest", + urlPatterns={"/myurl"}, + initParams={ @WebInitParam(name="n1", value="v1"), @WebInitParam(name="n2", value="v2") } ) +public class TestServlet extends HttpServlet { + @javax.inject.Inject TestManagedBean tb1; + @javax.annotation.Resource TestManagedBean tb; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + + ", n2=" + getInitParameter("n2"); + + //ManagedBean testing .. add additional messages in the "msg" string, so that the test will FAIL in the client + msg += testManagedBean(tb, " | TestManagedBean injected via @Resource"); + msg += testManagedBean(tb1, " | TestManagedBean injected via @Inject"); + msg += testInterceptors(); + + writer.write("initParams: " + msg + "\n"); + } + + private String testManagedBean(TestManagedBean tb, String info) { + String msg = ""; + if (tb == null) msg += info + " is null!"; + if (tb != null && !tb.testPostConstructCalled()) msg += info + " postConstruct not called"; + if (tb != null && !tb.testInjection()) msg += info + "Bean Injection into ManagedBean failed"; + return msg; + } + + private String testInterceptors(){ + // The interceptors should be invoked for both of these cases + System.out.println("calling foo on an @Resource injected Managed Bean"); + tb.foo(); + System.out.println("calling foo on an @Inject Managed Bean"); + tb1.foo(); + + int count = TestAroundInvokeInterceptor.aroundInvokeCount; + System.out.println("TestAroundInvokeInterceptor called " + count + " times"); + TestAroundInvokeInterceptor.reset(); + if (count == 2) return ""; + else return "Interceptor invocation count" + count + " invalid"; + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/servlet/com/tests/Tester.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/servlet/com/tests/Tester.java new file mode 100644 index 0000000..a966727 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor-nonnull-package/servlet/com/tests/Tester.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.tests; + +import javax.interceptor.*; +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + + +@InterceptorBinding +@Target({METHOD, TYPE}) +@Retention(RUNTIME) +public @interface Tester {}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/WebTest.java new file mode 100644 index 0000000..343d171 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/WebTest.java
@@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "simple-managed-bean-interceptor"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/build.properties b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/build.properties new file mode 100644 index 0000000..4809e75 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-simple-managed-bean-interceptor"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/build.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/build.xml new file mode 100644 index 0000000..83ad666 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/descriptor/beans.xml new file mode 100644 index 0000000..173bc72 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/descriptor/beans.xml
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>TestAroundInvokeInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/servlet/TestAroundInvokeInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/servlet/TestAroundInvokeInterceptor.java new file mode 100644 index 0000000..8b2414e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/servlet/TestAroundInvokeInterceptor.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import javax.interceptor.*; + +@Tester @Interceptor +public class TestAroundInvokeInterceptor { + public static int aroundInvokeCount = 0; + + public static void reset(){ + aroundInvokeCount = 0; + } + + @AroundInvoke + public Object testMethod(InvocationContext ctx) throws Exception { + System.out.println("TestAroundInvokeIntercetpr:: aroundInvoke called - target:" + ctx.getTarget() + " , params:"+ ctx.getParameters()); + aroundInvokeCount ++; + ctx.proceed(); + return null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/servlet/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/servlet/TestBean.java new file mode 100644 index 0000000..3dd49b9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/servlet/TestBean.java
@@ -0,0 +1,19 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +//Simple Bean to test injection into ManagedBeans +public class TestBean { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/servlet/TestManagedBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/servlet/TestManagedBean.java new file mode 100644 index 0000000..4905710 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/servlet/TestManagedBean.java
@@ -0,0 +1,54 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +//Simple TestBean to test CDI. +//This bean implements Serializable as it needs to be placed into a Stateful Bean +@javax.annotation.ManagedBean +public class TestManagedBean { + TestBean tb; + boolean postConstructCalled = false; + + + //A Managed Bean needs to have a no-arg constructor + public TestManagedBean() {} + @javax.inject.Inject //Constructor based Injection + public TestManagedBean(TestBean tb){ + this.tb = tb; + } + + + @javax.annotation.PostConstruct + public void init(){ + System.out.println("In ManagedBean:: PostConstruct"); + postConstructCalled = true; + } + + @Tester + public void foo(){ + System.out.println("foo called"); + } + + public boolean testPostConstructCalled(){ + return this.postConstructCalled; + } + + public boolean testInjection(){ + System.out.println("In ManagedBean:: tb=" + tb); + postConstructCalled = true; + return this.tb != null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/servlet/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/servlet/TestServlet.java new file mode 100644 index 0000000..431cdfc --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/servlet/TestServlet.java
@@ -0,0 +1,73 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(name="mytest", + urlPatterns={"/myurl"}, + initParams={ @WebInitParam(name="n1", value="v1"), @WebInitParam(name="n2", value="v2") } ) +public class TestServlet extends HttpServlet { + @javax.inject.Inject TestManagedBean tb1; + @javax.annotation.Resource TestManagedBean tb; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + + ", n2=" + getInitParameter("n2"); + + //ManagedBean testing .. add additional messages in the "msg" string, so that the test will FAIL in the client + msg += testManagedBean(tb, " | TestManagedBean injected via @Resource"); + msg += testManagedBean(tb1, " | TestManagedBean injected via @Inject"); + msg += testInterceptors(); + + writer.write("initParams: " + msg + "\n"); + } + + private String testManagedBean(TestManagedBean tb, String info) { + String msg = ""; + if (tb == null) msg += info + " is null!"; + if (tb != null && !tb.testPostConstructCalled()) msg += info + " postConstruct not called"; + if (tb != null && !tb.testInjection()) msg += info + "Bean Injection into ManagedBean failed"; + return msg; + } + + private String testInterceptors(){ + System.out.println("calling foo on an @Resource injected Managed Bean"); + tb.foo(); + System.out.println("calling foo on an @Inject Managed Bean"); + tb1.foo(); //TestAroundInvokeInterceptor is not called in this case + + int count = TestAroundInvokeInterceptor.aroundInvokeCount; + System.out.println("TestAroundInvokeInterceptor called " + count + " times"); + TestAroundInvokeInterceptor.reset(); + if (count == 1) return ""; + else return "Interceptor invocation count" + count + " invalid"; + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/servlet/Tester.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/servlet/Tester.java new file mode 100644 index 0000000..0555ac6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean-interceptor/servlet/Tester.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import javax.interceptor.*; +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + + +@InterceptorBinding +@Target({METHOD, TYPE}) +@Retention(RUNTIME) +public @interface Tester {}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/WebTest.java new file mode 100644 index 0000000..ff40c2c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/WebTest.java
@@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "simple-managed-bean"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/build.properties b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/build.properties new file mode 100644 index 0000000..712ba4a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-simple-managed-bean"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/build.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/build.xml new file mode 100644 index 0000000..83ad666 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/servlet/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/servlet/TestBean.java new file mode 100644 index 0000000..3dd49b9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/servlet/TestBean.java
@@ -0,0 +1,19 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +//Simple Bean to test injection into ManagedBeans +public class TestBean { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/servlet/TestManagedBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/servlet/TestManagedBean.java new file mode 100644 index 0000000..009ac36 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/servlet/TestManagedBean.java
@@ -0,0 +1,48 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +//Simple TestBean to test CDI. +//This bean implements Serializable as it needs to be placed into a Stateful Bean +@javax.annotation.ManagedBean +public class TestManagedBean { + TestBean tb; + boolean postConstructCalled = false; + + public TestManagedBean(){} + + @javax.inject.Inject //Constructor based Injection + public TestManagedBean(TestBean tb){ + this.tb = tb; + } + + + @javax.annotation.PostConstruct + public void init(){ + System.out.println("In ManagedBean:: PostConstruct"); + postConstructCalled = true; + } + + public boolean testPostConstructCalled(){ + return this.postConstructCalled; + } + + public boolean testInjection(){ + System.out.println("In ManagedBean:: tb=" + tb); + postConstructCalled = true; + return this.tb != null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/servlet/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/servlet/TestServlet.java new file mode 100644 index 0000000..f22bd89 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-managed-bean/servlet/TestServlet.java
@@ -0,0 +1,58 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(name="mytest", + urlPatterns={"/myurl"}, + initParams={ @WebInitParam(name="n1", value="v1"), @WebInitParam(name="n2", value="v2") } ) +public class TestServlet extends HttpServlet { + @javax.inject.Inject TestManagedBean tb1; + @javax.annotation.Resource TestManagedBean tb; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + + ", n2=" + getInitParameter("n2"); + + //ManagedBean testing .. add additional messages in the "msg" string, so that the test will FAIL in the client + msg += testManagedBean(tb, " | TestManagedBean injected via @Resource"); + msg += testManagedBean(tb1, " | TestManagedBean injected via @Inject"); + + writer.write("initParams: " + msg + "\n"); + } + + private String testManagedBean(TestManagedBean tb, String info) { + String msg = ""; + if (tb == null) msg += info + " is null!"; + if (tb != null && !tb.testPostConstructCalled()) msg += info + " postConstruct not called"; + if (tb != null && !tb.testInjection()) msg += info + "Bean Injection into ManagedBean failed"; + return msg; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/build.properties b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/build.properties new file mode 100644 index 0000000..d64848e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/build.properties
@@ -0,0 +1,37 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi-hello-mdb"/> +<property name="appname" value="${module}"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="test.client" + value="Client"/> +<property name="simple.client" value="com.sun.s1asdev.cdi.hello.mdb.client.Client"/> +<property name="application.xml" value="descriptor/application.xml"/> +<property name="sun-application.xml" value="descriptor/sun-application.xml"/> +<property name="ejb-jar.xml" value="descriptor/ejb-jar.xml"/> +<property name="sun-ejb-jar.xml" value="descriptor/sun-ejb-jar.xml"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="application-client.xml" + value="descriptor/application-client.xml"/> +<property name="sun-application-client.xml" + value="descriptor/sun-application-client.xml"/> +<property name="appclientjar.files" value="${build.classes.dir}"/> +<property name="appclient.jar" value="${assemble.dir}/${appname}-client.jar"/> +<property name="app.type" value="application"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/build.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/build.xml new file mode 100644 index 0000000..e71984d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/build.xml
@@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="cdi-hello-mdbApp" default="usage" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + + <target name="all" depends="clean,build,create-resources,deploy,run,undeploy,delete-resources"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="ejb"/> + </antcall> + <antcall target="compile-common"> + <param name="src" value="client"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <antcall target="build-ear-common"> + <param name="ejbjar.classes" + value="**/*Bean*.class,**/*Hello*" /> + <param name="appclientjar.classes" + value="**/*Client*.class" /> + </antcall> + </target> + + <target name="deploy" + depends="init-common"> + <antcall target="deploy-common"/> + </target> + + <target name="create-resources" depends="init-common"> + <antcall target="asadmin-batch-common"> + <param name="asadmin.file" value="create_resources.asadmin"/> + </antcall> + </target> + + <target name="delete-resources" depends="init-common"> + <antcall target="asadmin-batch-common"> + <param name="asadmin.file" value="delete_resources.asadmin"/> + </antcall> + </target> + + <target name="run" depends="init-common"> + <antcall target="runclient-common"> + <param name="appclient.application.args" value="1"/> + </antcall> + </target> + + <target name="run_standaloneclient" depends="init-common"> + <java fork="on" + failonerror="true" + classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/modules/javax.jms.jar:${env.S1AS_HOME}/lib/gf-client.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar" + classname="${simple.client}"> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + <echo> + ant create-resources Create all destinations and connection factories + ant delete-resources Delete all destinations and connection factories + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/client/Client.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/client/Client.java new file mode 100644 index 0000000..a9ba3f0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/client/Client.java
@@ -0,0 +1,151 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.s1asdev.cdi.hello.mdb.client; +import java.io.*; +import java.util.*; +import javax.ejb.EJBHome; +import javax.jms.*; +import javax.annotation.Resource; +import javax.naming.InitialContext; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +public class Client { + + // in milli-seconds + private static long TIMEOUT = 90000; + + private static SimpleReporterAdapter stat = + new SimpleReporterAdapter("appserv-tests"); + + public static void main (String[] args) { + Client client = new Client(args); + + stat.addDescription("cdi-hello-mdb"); + client.doTest(); + stat.printSummary("cdi-hello-mdbID"); + System.exit(0); + } + + + @Resource(name="FooCF", mappedName="jms/cdi_hello_mdb_QCF") + private static QueueConnectionFactory queueConFactory; + + @Resource(name="MsgBeanQueue", mappedName="jms/cdi_hello_mdb_InQueue") + private static javax.jms.Queue msgBeanQueue; + + @Resource(name="ClientQueue", mappedName="foo") + private static javax.jms.Queue clientQueue; + + private QueueConnection queueCon; + private QueueSession queueSession; + private QueueSender queueSender; + private QueueReceiver queueReceiver; + + + private int numMessages = 2; + public Client(String[] args) { + + if( args.length == 1 ) { + numMessages = new Integer(args[0]).intValue(); + } + + } + + public void doTest() { + try { + if( queueConFactory == null ) { + + System.out.println("Java SE mode..."); + InitialContext ic = new InitialContext(); + queueConFactory = (javax.jms.QueueConnectionFactory) ic.lookup("jms/cdi_hello_mdb_QCF"); + msgBeanQueue = (javax.jms.Queue) ic.lookup("jms/cdi_hello_mdb_InQueue"); + clientQueue = (javax.jms.Queue) ic.lookup("jms/cdi_hello_mdb_OutQueue"); + + } + + setup(); + doTest(numMessages); + stat.addStatus("cmt main", stat.PASS); + } catch(Throwable t) { + stat.addStatus("cmt main", stat.FAIL); + t.printStackTrace(); + } finally { + cleanup(); + } + } + + public void setup() throws Exception { + + queueCon = queueConFactory.createQueueConnection(); + + queueSession = queueCon.createQueueSession + (false, Session.AUTO_ACKNOWLEDGE); + + // Producer will be specified when actual msg is sent. + queueSender = queueSession.createSender(null); + + queueReceiver = queueSession.createReceiver(clientQueue); + + queueCon.start(); + + } + + public void cleanup() { + try { + if( queueCon != null ) { + queueCon.close(); + } + } catch(Throwable t) { + t.printStackTrace(); + } + } + + public void sendMsgs(javax.jms.Queue queue, Message msg, int num) + throws JMSException { + for(int i = 0; i < num; i++) { + System.out.println("Sending message " + i + " to " + queue + + " at time " + System.currentTimeMillis()); + queueSender.send(queue, msg); + System.out.println("Sent message " + i + " to " + queue + + " at time " + System.currentTimeMillis()); + } + } + + public void doTest(int num) + throws Exception { + + Destination dest = msgBeanQueue; + + Message message = queueSession.createTextMessage("foo"); + + message.setBooleanProperty("flag", true); + message.setIntProperty("num", 2); + sendMsgs((javax.jms.Queue) dest, message, num); + + System.out.println("Waiting for queue message"); + Message recvdmessage = queueReceiver.receive(TIMEOUT); + if( recvdmessage != null ) { + System.out.println("Received message : " + + ((TextMessage)recvdmessage).getText()); + } else { + System.out.println("timeout after " + TIMEOUT + " seconds"); + throw new JMSException("timeout" + TIMEOUT + " seconds"); + } + } +} +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/client/MANIFEST.MF b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/client/MANIFEST.MF new file mode 100644 index 0000000..1ed692b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/client/MANIFEST.MF
@@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Created-By: 1.4.0-beta3 (Sun Microsystems Inc.) +Main-Class: com.sun.s1asdev.cdi.hello.mdb.client.Client +Class-Path: reporter.jar
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/create_resources.asadmin b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/create_resources.asadmin new file mode 100644 index 0000000..78a6f43 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/create_resources.asadmin
@@ -0,0 +1,5 @@ +create-jms-resource --restype javax.jms.QueueConnectionFactory jms/cdi_hello_mdb_QCF +create-jmsdest --desttype queue cdi_hello_mdb_InQueue +create-jms-resource --restype javax.jms.Queue --property imqDestinationName=cdi_hello_mdb_InQueue jms/cdi_hello_mdb_InQueue +create-jmsdest --desttype queue cdi_hello_mdb_OutQueue +create-jms-resource --restype javax.jms.Queue --property imqDestinationName=cdi_hello_mdb_OutQueue jms/cdi_hello_mdb_OutQueue
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/delete_resources.asadmin b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/delete_resources.asadmin new file mode 100644 index 0000000..69af651 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/delete_resources.asadmin
@@ -0,0 +1,5 @@ +delete-jms-resource jms/cdi_hello_mdb_QCF +delete-jms-resource jms/cdi_hello_mdb_InQueue +delete-jmsdest --desttype queue cdi_hello_mdb_InQueue +delete-jms-resource jms/cdi_hello_mdb_OutQueue +delete-jmsdest --desttype queue cdi_hello_mdb_OutQueue
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/descriptor/application.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/descriptor/application.xml new file mode 100644 index 0000000..448b864 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/descriptor/application.xml
@@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"> + <display-name>cdi-hello-mdbApp</display-name> + <module> + <ejb>cdi-hello-mdb-ejb.jar</ejb> + </module> + <module> + <java>cdi-hello-mdb-client.jar</java> + </module> +</application>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/descriptor/sun-application-client.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/descriptor/sun-application-client.xml new file mode 100644 index 0000000..3cb8ad5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/descriptor/sun-application-client.xml
@@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE sun-application-client PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Application Client 5.0//EN" "http://www.sun.com/software/appserver/dtds/sun-application-client_5_0-0.dtd"> +<sun-application-client> + <message-destination-ref> + <message-destination-ref-name>ClientQueue</message-destination-ref-name> + <jndi-name>jms/cdi_hello_mdb_OutQueue</jndi-name> + </message-destination-ref> +</sun-application-client>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/Hello1.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/Hello1.java new file mode 100644 index 0000000..55f1d9f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/Hello1.java
@@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.s1asdev.cdi.hello.mdb; + +public interface Hello1 { + + public void hello(String s); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/Hello2.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/Hello2.java new file mode 100644 index 0000000..dce0861 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/Hello2.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.s1asdev.cdi.hello.mdb; + +public interface Hello2 extends java.io.Serializable { + + public void hello(String s); + + public void removeMethod(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/HelloStateful.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/HelloStateful.java new file mode 100644 index 0000000..daef982 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/HelloStateful.java
@@ -0,0 +1,44 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.s1asdev.cdi.hello.mdb; + +import javax.ejb.Stateful; +import javax.ejb.Remove; +import javax.annotation.PreDestroy; + +// Hello1 interface is not annotated with @Local. If the +// bean only implements one interface it is assumed to be +// a local business interface. +@Stateful(description="my stateful bean description") +public class HelloStateful implements Hello2 { + + private String msg; + + public void hello(String s) { + msg = s; + System.out.println("HelloStateful: " + s); + } + + @Remove public void removeMethod() { + System.out.println("Business method marked with @Remove called in " + + msg); + } + @PreDestroy public void myPreDestroyMethod() { + System.out.println("PRE-DESTROY callback received in " + msg); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/HelloStateless.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/HelloStateless.java new file mode 100644 index 0000000..fa86bc5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/HelloStateless.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.s1asdev.cdi.hello.mdb; + +import javax.ejb.Stateless; + +// Hello1 interface is not annotated with @Local. If the +// bean only implements one interface it is assumed to be +// a local business interface. +@Stateless(description="my stateless bean description") +public class HelloStateless implements Hello1 { + + public void hello(String s) { + System.out.println("HelloStateless: " + s); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/MessageBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/MessageBean.java new file mode 100644 index 0000000..cdc7786 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/MessageBean.java
@@ -0,0 +1,101 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.s1asdev.cdi.hello.mdb; + +import javax.ejb.MessageDriven; +import javax.ejb.EJBException; +import javax.ejb.NoSuchEJBException; +import javax.ejb.EJB; +import javax.ejb.TransactionManagement; +import javax.ejb.TransactionManagementType; +import javax.ejb.ActivationConfigProperty; + +import javax.jms.MessageListener; +import javax.jms.Message; +import javax.jms.Queue; +import javax.jms.QueueConnectionFactory; +import javax.jms.QueueConnection; +import javax.jms.QueueSession; +import javax.jms.QueueSender; +import javax.jms.TextMessage; +import javax.jms.Session; + +import javax.annotation.Resource; + +@TransactionManagement(TransactionManagementType.BEAN) +@MessageDriven(mappedName="jms/cdi_hello_mdb_InQueue", description="mymessagedriven bean description") + public class MessageBean implements MessageListener { + + @EJB private Hello1 hello1; + @EJB private Hello2 hello2; + + @Resource(name="jms/MyQueueConnectionFactory", + mappedName="jms/cdi_hello_mdb_QCF") + QueueConnectionFactory qcFactory; + + @Resource(mappedName="jms/cdi_hello_mdb_OutQueue") Queue clientQueue; + + @javax.inject.Inject com.sun.s1asdev.cdi.hello.bean.TestBean tb; + + + public void onMessage(Message message) { + System.out.println("Got message!!! tb=" + tb ); + + QueueConnection connection = null; + try { + + System.out.println("Calling hello1 stateless bean"); + hello1.hello("local ejb3.0 stateless"); + System.out.println("Calling hello2 stateful bean"); + hello2.hello("local ejb3.0 stateful"); + hello2.removeMethod(); + try { + hello2.hello("this call should not go through"); + throw new Exception("bean should have been removed " + + "after removeMethod()"); + } catch(NoSuchEJBException e) { + System.out.println("Successfully caught EJBException after " + + " accessing removed SFSB"); + } + + if (tb == null) throw new Exception("Injection of Bean in MDB failed"); + + connection = qcFactory.createQueueConnection(); + QueueSession session = connection.createQueueSession(false, + Session.AUTO_ACKNOWLEDGE); + QueueSender sender = session.createSender(clientQueue); + TextMessage tmessage = session.createTextMessage(); + tmessage.setText("mdb() invoked"); + System.out.println("Sending message"); + sender.send(tmessage); + System.out.println("message sent"); + + } catch(Exception e) { + e.printStackTrace(); + } finally { + try { + if(connection != null) { + connection.close(); + } + } catch(Exception e) { + e.printStackTrace(); + } + } + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/TestBean.java new file mode 100644 index 0000000..0dd4102 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-mdb/ejb/TestBean.java
@@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.s1asdev.cdi.hello.bean; + + + +//Simple TestBean to test CDI. +public class TestBean +{}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/README b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/README new file mode 100644 index 0000000..117389b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/README
@@ -0,0 +1,3 @@ +Test +- Simple WAB (Web Application Bundle) that is CDI enabled. +- Test injection of beans, access to BeanManager within WAB
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/WebTest.java new file mode 100644 index 0000000..09cdfca --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/WebTest.java
@@ -0,0 +1,109 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "cdi-wab"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + Thread.sleep(2000); //WORKAROUND @XXX + String url = "http://" + host + ":" + port + contextRoot; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/build.properties b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/build.properties new file mode 100644 index 0000000..38d97bd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/build.properties
@@ -0,0 +1,26 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-wab"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/test"/> +<property name="beans.xml" value="descriptor/beans.xml"/> +<property name="web.xml" value="descriptor/web.xml"/> +<property name="bundle.descriptor" value="descriptor/MANIFEST.MF"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/build.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/build.xml new file mode 100644 index 0000000..a276cda --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/build.xml
@@ -0,0 +1,90 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!-- +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +--> +<!ENTITY commonBuild SYSTEM "./common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-wab-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-wab-common"/> + </target> + + <target name="run" depends="init-common"> + <sleep seconds="25"/> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/common.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/common.xml new file mode 100644 index 0000000..f396e66 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/common.xml
@@ -0,0 +1,1946 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!-- + This is the top level build file that should be + imported into all the leaf level build files +--> + +<!-- ================================================================ --> +<!-- Targets to clean class files and jars files --> +<!-- +Variables used: + ${build.classes.dir} + ${assemble.dir} +--> +<!-- ================================================================ --> +<target name="clean-classes-common" depends="init-common"> + <echo message="common.xml: Cleaning test source files: ${build.base.dir}" + level="verbose"/> + <delete dir="${build.base.dir}"/> +</target> + +<target name="clean-jars-common" depends="init-common"> + <delete dir="${assemble.dir}"/> +</target> + +<target name="clean-common" depends="init-common"> + <antcall target="clean-classes-common"/> + <antcall target="clean-jars-common"/> +</target> + +<!-- ================================================================ --> +<!-- Target to compile the java source files --> +<!-- +Variables used: + ${build.classes.dir} + ${s1astest.classpath} + ${src} +--> +<!-- ================================================================ --> +<target name="compile-common" depends="init-common"> + <mkdir dir="${build.classes.dir}"/> + <echo message="common.xml: Compiling test source files" level="verbose"/> + <mkdir dir="${src}"/> + <javac srcdir="${src}" + destdir="${build.classes.dir}" + classpath="${s1astest.classpath}" + debug="on" + failonerror="true"/> +</target> + +<!-- ================================================================ --> +<!-- This is the external target war-common to be called up build files +usage: +<antcall target="war-common"> +<param name="war.classes" value="MyServlet.class,MyOtherServlet.class"/> +</antcall> +Assumption: All the static content is placed in webcontent directory + +Variables Used: + ${war.file} + ${build.classes.dir} + ${appname} + ${assemble.dir} + ${web.xml} + ${beans.xml} + ${tlds} + ${tagfiles} + ${APS_HOME} + ${webclient.war.files} + ${webclient.war.classes} +--> +<!-- ================================================================ --> + +<target name="webclient-war-common" if="hasWebclient" depends="init-common"> + <mkdir dir="${assemble.dir}"/> + <antcall target="package-war-common"> + <param name="war.classes" value="${build.classes.dir}"/> + <param name="war.file" value="${assemble.dir}/${appname}-web.war"/> + </antcall> +</target> + +<target name="webclient-wab-common" if="hasWebclient" depends="init-common"> + <mkdir dir="${assemble.dir}"/> + <antcall target="package-wab-common"> + <param name="war.classes" value="${build.classes.dir}"/> + <param name="war.file" value="${assemble.dir}/${appname}-web.war"/> + </antcall> +</target> + + +<target name="publish-war-common" depends="init-common"> + <mkdir dir="${build.webapps.dir}"/> + <copy file="${assemble.dir}/${appname}-web.war" + tofile="${build.webapps.dir}/${appname}.war" + overwrite="true" /> +</target> + +<target name="clean-webapps-common" depends="init-common"> + <delete dir="${build.webapps.dir}" quiet="true" /> +</target> + +<target name="clear"> + <delete file="${war.file}"/> +</target> + +<target name="copy-tlds" if="tlds-exist" depends="clear,test-tlds-exist"> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF/tlds"/> + <copy todir="${build.classes.dir}/tmp/WEB-INF/tlds" failonerror="false"> + <fileset dir="${tlds}"> + <include name="**/*.tld"/> + </fileset> + </copy> +</target> + +<target name="copy-tagfiles" if="tagfiles-exist" depends="clear,test-tagfiles-exist"> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF/tags"/> + <copy todir="${build.classes.dir}/tmp/WEB-INF/tags" failonerror="false"> + <fileset dir="${tagfiles}"> + <include name="**/*.tag"/> + <include name="**/*.tagx"/> + </fileset> + </copy> +</target> + +<target name="package-war-common" depends="copy-tlds,copy-tagfiles"> + <echo message="my build classes dir is:${build.classes.dir}" level="verbose"/> + <mkdir dir="${build.classes.dir}/tmp"/> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF"/> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF/classes"/> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF/lib"/> + <mkdir dir="lib"/> + <copy file="${glassfish-web.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/glassfish-web.xml" failonerror="false"/> + <copy file="${sun-web.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/sun-web.xml" failonerror="false"/> + <copy file="${weblogic.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/weblogic.xml" failonerror="false"/> + <copy file="${glassfish-resources.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/glassfish-resources.xml" failonerror="false"/> + <copy todir="${build.classes.dir}/tmp/WEB-INF/lib" failonerror="false"> + <fileset dir="lib"> + <include name="**/*.jar"/> + <include name="**/*.zip"/> + </fileset> + </copy> + <copy file="${webservices.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/webservices.xml" + failonerror="false"/> + <copy file="${mappingfile.location}/${mappingfile.name}" + tofile="${build.classes.dir}/tmp/${mappingfile.name}" + failonerror="false"/> + <copy file="${wsdlfile.location}/${wsdlfile.name}" + tofile="${build.classes.dir}/tmp/WEB-INF/wsdl/${wsdlfile.name}" + failonerror="false"/> + <copy file="${tagPlugins.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/tagPlugins.xml" + failonerror="false"/> + <copy file="${web.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/web.xml" + failonerror="false"/> + <copy file="${persistence.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/classes/META-INF/persistence.xml" + failonerror="false"/> + <copy file="${beans.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/beans.xml" + failonerror="false"/> + <copy file="${context.xml}" + tofile="${build.classes.dir}/tmp/META-INF/context.xml" failonerror="false"/> + <copy file="${cdi-extension.service}" + tofile="${build.classes.dir}/tmp/WEB-INF/classes/META-INF/services/javax.enterprise.inject.spi.Extension" failonerror="false"/> + + <copy todir="${build.classes.dir}/tmp/WEB-INF/classes"> + <fileset dir="${war.classes}"> + <include name="**/*.class"/> + </fileset> + </copy> + <echo message="Creating war file ${war.file}" level="verbose"/> + <mkdir dir="${basedir}/docroot"/> + <jar jarfile="${war.file}" update="true"> + <fileset dir="${build.classes.dir}/tmp" casesensitive="yes"> + <include name="**/*class*"/> + </fileset> + <fileset dir="${basedir}/docroot" casesensitive="yes"> + <include name="**/*.html"/> + <include name="**/*.HTML"/> + <include name="**/*.xhtml"/> + <include name="**/*.jsp"/> + <include name="**/*.jspx"/> + <include name="**/*.jspf"/> + <include name="**/*.gif"/> + <include name="**/*.do"/> + <include name="**/*.txt"/> + <include name="**/*.shtml"/> + <include name="**/*.jar"/> + <exclude name="**/*.java,**/*.xml,**/*.properties"/> + </fileset> + <fileset dir="${build.classes.dir}/tmp/" casesensitive="true"> + <include name="WEB-INF/web.xml"/> + <include name="WEB-INF/glassfish-web.xml"/> + <include name="WEB-INF/glassfish-resources.xml"/> + <include name="WEB-INF/sun-web.xml"/> + <include name="WEB-INF/beans.xml"/> + <include name="WEB-INF/weblogic.xml"/> + <include name="WEB-INF/webservices.xml"/> + <include name="WEB-INF/tagPlugins.xml"/> + <include name="WEB-INF/lib/*"/> + <include name="WEB-INF/lib/extra/*"/> + <include name="WEB-INF/tlds/*"/> + <include name="WEB-INF/tags/*"/> + <include name="WEB-INF/wsdl/${wsdlfile.name}"/> + <include name="${mappingfile.name}"/> + <include name="META-INF/context.xml"/> + <include name="WEB-INF/classes/META-INF/services/javax.enterprise.inject.spi.Extension"/> + <include name="WEB-INF/classes/META-INF/persistence.xml"/> + </fileset> + </jar> + <echo message="created war file ${war.file}" level="verbose"/> + <delete dir="${build.classes.dir}/tmp/WEB-INF" failonerror="false"/> + <echo message="my webclient war classes are:${webclient.war.classes}" + level="verbose"/> +</target> + +<target name="package-wab-common" depends="copy-tlds,copy-tagfiles"> + <echo message="my build classes dir is:${build.classes.dir}" level="verbose"/> + <mkdir dir="${build.classes.dir}/tmp"/> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF"/> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF/classes"/> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF/lib"/> + <mkdir dir="${build.classes.dir}/tmp/WEB-INF/META-INF"/> + <mkdir dir="lib"/> + <copy file="${glassfish-web.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/glassfish-web.xml" failonerror="false"/> + <copy file="${sun-web.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/sun-web.xml" failonerror="false"/> + <copy file="${weblogic.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/weblogic.xml" failonerror="false"/> + <copy file="${glassfish-resources.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/glassfish-resources.xml" failonerror="false"/> + <copy todir="${build.classes.dir}/tmp/WEB-INF/lib" failonerror="false"> + <fileset dir="lib"> + <include name="**/*.jar"/> + <include name="**/*.zip"/> + </fileset> + </copy> + <copy file="${webservices.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/webservices.xml" + failonerror="false"/> + <copy file="${mappingfile.location}/${mappingfile.name}" + tofile="${build.classes.dir}/tmp/${mappingfile.name}" + failonerror="false"/> + <copy file="${wsdlfile.location}/${wsdlfile.name}" + tofile="${build.classes.dir}/tmp/WEB-INF/wsdl/${wsdlfile.name}" + failonerror="false"/> + <copy file="${tagPlugins.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/tagPlugins.xml" + failonerror="false"/> + <copy file="${web.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/web.xml" + failonerror="false"/> + <copy file="${persistence.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/classes/META-INF/persistence.xml" + failonerror="false"/> + <copy file="${beans.xml}" + tofile="${build.classes.dir}/tmp/WEB-INF/beans.xml" + failonerror="false"/> + + <copy file="${bundle.descriptor}" + tofile="${build.classes.dir}/tmp/WEB-INF/classes/META-INF/MANIFEST.MF" + failonerror="false"/> + <copy file="${context.xml}" + tofile="${build.classes.dir}/tmp/META-INF/context.xml" failonerror="false"/> + <copy file="${cdi-extension.service}" + tofile="${build.classes.dir}/tmp/WEB-INF/classes/META-INF/services/javax.enterprise.inject.spi.Extension" failonerror="false"/> + + <copy todir="${build.classes.dir}/tmp/WEB-INF/classes"> + <fileset dir="${war.classes}"> + <include name="**/*.class"/> + </fileset> + </copy> + <echo message="Creating war file ${war.file}" level="verbose"/> + <mkdir dir="${basedir}/docroot"/> + <jar manifest="${bundle.descriptor}" jarfile="${war.file}" update="true"> + <fileset dir="${build.classes.dir}/tmp" casesensitive="yes"> + <include name="**/*class*"/> + </fileset> + <fileset dir="${basedir}/docroot" casesensitive="yes"> + <include name="**/*.html"/> + <include name="**/*.HTML"/> + <include name="**/*.xhtml"/> + <include name="**/*.jsp"/> + <include name="**/*.jspx"/> + <include name="**/*.jspf"/> + <include name="**/*.gif"/> + <include name="**/*.do"/> + <include name="**/*.txt"/> + <include name="**/*.shtml"/> + <include name="**/*.jar"/> + <exclude name="**/*.java,**/*.xml,**/*.properties"/> + </fileset> + <fileset dir="${build.classes.dir}/tmp/" casesensitive="true"> + <include name="WEB-INF/web.xml"/> + <include name="WEB-INF/glassfish-web.xml"/> + <include name="WEB-INF/glassfish-resources.xml"/> + <include name="WEB-INF/sun-web.xml"/> + <include name="WEB-INF/beans.xml"/> + <include name="WEB-INF/weblogic.xml"/> + <include name="WEB-INF/webservices.xml"/> + <include name="WEB-INF/tagPlugins.xml"/> + <include name="WEB-INF/lib/*"/> + <include name="WEB-INF/lib/extra/*"/> + <include name="WEB-INF/tlds/*"/> + <include name="WEB-INF/tags/*"/> + <include name="WEB-INF/wsdl/${wsdlfile.name}"/> + <include name="${mappingfile.name}"/> + <include name="META-INF/context.xml"/> + <include name="WEB-INF/classes/META-INF/services/javax.enterprise.inject.spi.Extension"/> + <include name="WEB-INF/classes/META-INF/persistence.xml"/> + </fileset> + </jar> + <echo message="created WAB file ${war.file}" level="verbose"/> + <delete dir="${build.classes.dir}/tmp/WEB-INF" failonerror="false"/> + <echo message="my webclient WAB classes are:${webclient.war.classes}" + level="verbose"/> +</target> + + +<target name="test-tlds-exist"> + <available file="${tlds}" property="tlds-exist"/> +</target> + +<target name="test-tagfiles-exist"> + <available file="${tagfiles}" property="tagfiles-exist"/> +</target> + +<!-- ================================================================ --> +<!-- Target to package the ejb application to jar file --> +<!-- +Variables Used: + ${ejb.jar} + ${build.classes.dir} + ${ejb-jar.xml} + ${beans.xml} + ${persistence-orm.xml} + ${sun-ejb-jar.xml} + ${glassfish-ejb-jar.xml} + ${sun-cmp-mappings.xml} + ${metainf.dir} + ${ejbjar.files} + ${dbschema} +--> +<!-- ================================================================ --> +<target name="package-ejbjar-common"> + <delete file="${ejb.jar}"/> + <echo message="common.xml: Generating ejb-jar inside build directory" + level="verbose"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <copy file="${ejb-jar.xml}" + tofile="${build.classes.dir}/META-INF/ejb-jar.xml" + failonerror="false"/> + <copy file="${persistence-orm.xml}" + tofile="${build.classes.dir}/META-INF/persistence-orm.xml" + failonerror="false"/> + <copy file="${webservices.xml}" + tofile="${build.classes.dir}/META-INF/webservices.xml" + failonerror="false"/> + <copy file="${sun-ejb-jar.xml}" + tofile="${build.classes.dir}/META-INF/sun-ejb-jar.xml" + failonerror="false"/> + <copy file="${glassfish-ejb-jar.xml}" + tofile="${build.classes.dir}/META-INF/glassfish-ejb-jar.xml" + failonerror="false"/> + <copy file="${glassfish-resources.xml}" + tofile="${build.classes.dir}/META-INF/glassfish-resources.xml" + failonerror="false"/> + <copy file="${sun-cmp-mappings.xml}" + tofile="${build.classes.dir}/META-INF/sun-cmp-mappings.xml" + failonerror="false"/> + <copy file="${beans.xml}" + tofile="${build.classes.dir}/META-INF/beans.xml" + failonerror="false"/> + <copy file="${dbschema}" todir="${build.classes.dir}" failonerror="false"/> + <jar jarfile="${ejb.jar}" basedir="${ejbjar.files}" update="true" + includes ="${ejbjar.classes}"> + <metainf dir="${build.classes.dir}/META-INF"> + <include name="ejb-jar.xml"/> + <include name="persistence-orm.xml"/> + <include name="webservices.xml"/> + <include name="sun-ejb-jar.xml"/> + <include name="glassfish-resources.xml"/> + <include name="glassfish-ejb-jar.xml"/> + <include name="sun-cmp-mappings.xml"/> + <include name="beans.xml"/> + </metainf> + </jar> + <delete dir="${build.classes.dir}/META-INF" failonerror="false"/> + <delete file="${build.classes.dir}/*.dbschema" failonerror="false"/> +</target> + +<!-- ================================================================ --> +<!-- Target to package the appclient application to jar file --> +<!-- +Variables Used: + ${appclient.jar} + ${appclientjar.classes} + ${appclientjar.files} + ${build.classes.dir} + ${application-client.xml} + ${sun-application-client.xml} +--> +<!-- ================================================================ --> +<target name="package-appclientjar-common"> + <delete file="${appclient.jar}"/> + <echo message="common.xml: Generating appclient-jar inside build directory" + level="verbose"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <copy file="${application-client.xml}" + tofile="${build.classes.dir}/META-INF/application-client.xml" + failonerror="false"/> + <copy file="${sun-application-client.xml}" tofile="${build.classes.dir}/META-INF/sun-application-client.xml" + failonerror="false"/> + <jar jarfile="${appclient.jar}" basedir="${appclientjar.files}" + update="true" includes ="${appclientjar.classes}" + manifest="./client/MANIFEST.MF"> + <metainf dir="${build.classes.dir}/META-INF"> + <include name="application-client.xml"/> + <include name="sun-application-client.xml"/> + </metainf> + </jar> +</target> + +<!-- ================================================================ --> +<!-- Target to create the ejb application jar file --> +<!-- ================================================================ --> +<target name="ejb-jar-common" depends="init-common"> + <mkdir dir="${assemble.dir}"/> + <antcall target="package-ejbjar-common"> + <param name="ejbjar.files" value="${build.classes.dir}"/> + <param name="ejb.jar" value="${assemble.dir}/${appname}-ejb.jar"/> + </antcall> +</target> + +<!-- ================================================================ --> +<!-- Target to create the appclient jar file --> +<!-- ================================================================ --> +<target name="appclient-jar-common" depends="init-common"> + <mkdir dir="${assemble.dir}"/> + <antcall target="package-appclientjar-common"> + <param name="appclientjar.files" + value="${build.classes.dir}"/> + <param name="appclient.jar" + value="${assemble.dir}/${appname}-client.jar"/> + </antcall> +</target> + +<!-- ===== package par ===== --> +<target name="package-persistence-common" depends="init-common" if="ejb30-persistence"> + <echo message="CREATING Persistence archive: common.xml: ${build.classes.dir}, ${assemble.dir}"/> + <mkdir dir="${assemble.dir}"/> + <delete file="${assemble.dir}/${appname}-persistence.jar" failonerror="false"/> + <echo message="common.xml: Generating PAR inside build directory"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <copy file="${persistence.xml}" tofile="${build.classes.dir}/META-INF/persistence.xml" failonerror="false"/> + <copy file="${mapping.xml}" tofile="${build.classes.dir}/META-INF/entity-mapping.xml" failonerror="false"/> + <!-- make a jar --> + <jar jarfile="${assemble.dir}/${appname}-persistence.jar" basedir="${build.classes.dir}" update="true" includes ="**/*.class" excludes="**/*Local*.class,**/*Remote*.class,**/*Home*.class,**/*Bean*.class,**/*EJB*.class,**/*Exception.class"> + <metainf dir="${build.classes.dir}/META-INF"> + <include name="**/*.xml"/> + </metainf> + </jar> + <delete dir="${build.classes.dir}/META-INF" failonerror="false"/> +</target> + +<!-- ================================================================ --> +<!-- Target to assemble the ejb application to ear file --> +<!-- ================================================================ --> +<target name="build-ear-common" depends="fixFiles,package-persistence-common,ejb-jar-common,appclient-jar-common,webclient-war-common"> + <delete file="${assemble.dir}/${appname}.ear"/> + <mkdir dir="${assemble.dir}"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <copy file="${sun-application.xml}" tofile="${build.classes.dir}/META-INF/sun-application.xml" failonerror="false"/> + <copy file="${application.xml}" tofile="${build.classes.dir}/META-INF/application.xml" failonerror="false"/> + <copy file="${glassfish-resources-ear.xml}" tofile="${build.classes.dir}/META-INF/glassfish-resources.xml" failonerror="false" filtering="true"/> + <jar jarfile="${assemble.dir}/${appname}App.ear"> + <fileset dir="${assemble.dir}"> + <include name="*.jar"/> + <include name="*.war"/> + </fileset> + <fileset dir="${build.classes.dir}"> + <include name="META-INF/sun-application.xml"/> + <include name="META-INF/application.xml"/> + <include name="META-INF/glassfish-resources.xml"/> + </fileset> + <fileset dir="${env.APS_HOME}" includes="lib/reporter.jar"/> + </jar> +</target> + + +<!-- ================================================================ --> +<!-- Target to assemble the ejb application to ear file --> +<!-- ================================================================ --> +<target name="ear-common" depends="fixFiles,init-common"> + <delete file="${assemble.dir}/${appname}.ear"/> + <mkdir dir="${assemble.dir}"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <copy file="${sun-application.xml}" tofile="${build.classes.dir}/META-INF/sun-application.xml" failonerror="false"/> + <copy file="${glassfish-resources-ear.xml}" tofile="${build.classes.dir}/META-INF/glassfish-resources.xml" failonerror="false" filtering="true"/> + <ear earfile="${assemble.dir}/${appname}App.ear" + appxml="${application.xml}"> + <fileset dir="${assemble.dir}"> + <include name="*.jar"/> + <include name="*.war"/> + </fileset> + <fileset dir="${build.classes.dir}"> + <include name="META-INF/sun-application.xml"/> + <include name="META-INF/glassfish-resources.xml"/> + </fileset> + <fileset dir="${env.APS_HOME}" includes="lib/reporter.jar"/> + </ear> +</target> + + +<!-- run Verifier on the ear file --> +<target name="verifier" depends="init-common"> + <echo message="Running verifier + ear file ${assemble.dir}/${appname}App.ear " level="verbose"/> + <antcall target="verifier-common"> + <param name="verifier.command" value=" -n -rw "/> + <param name="operand.props" value="${assemble.dir}/${appname}App.ear"/> + </antcall> + <echo message="Validate the static check results" level="verbose"/> +</target> + +<target name="verifier-common"> + <echo message="Operand ${operand.props}" level="verbose"/> + <exec executable="${VERIFIER}" failonerror="true"> + <arg line="${verifier.command} ${operand.props}" /> + </exec> +</target> + +<!-- ================================================================ --> +<!-- Target to execute asadmin commands --> +<!-- ================================================================ --> +<target name="asadmin-common"> + <echo message="Doing admin task ${admin.command}" level="verbose"/> + <echo message="Operand ${operand.props}" level="verbose"/> + <echo message="asadmin ${admin.command} ${as.props} ${operand.props}"/> + <exec executable="${ASADMIN}" failonerror="true"> + <arg line="${admin.command} ${as.props} ${operand.props}" /> + </exec> +</target> + +<target name="asadmin-common-ignore-fail"> + <echo message="Doing admin task ${admin.command} (ignore failures)" + level="verbose"/> + <echo message="Operand ${operand.props}" level="verbose"/> + <echo message="asadmin ${admin.command} ${as.props} ${operand.props}"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="${admin.command} ${as.props} ${operand.props}" /> + </exec> +</target> + + +<!-- Target to execute a batchfile of asadmin commands --> +<!-- ================================================================ --> +<target name="asadmin-batch-common"> + <echo message="Doing admin batch task ${admin.command} --file" + level="verbose"/> +<property name="user.password.file" value="asadminuserpassword.txt"/> +<echo file="${user.password.file}" append="false"> +AS_ADMIN_USERPASSWORD=${password} +AS_ADMIN_PASSWORD=${admin.password} +AS_ADMIN_ADMINPASSWORD=${admin.password} +AS_ADMIN_MASTERPASSWORD=${master.password} +</echo> + <exec executable="${ASADMIN}" failonerror="true"> + <arg line="--user ${admin.user} --passwordfile ${user.password.file} --host ${admin.host} --port ${admin.port} --echo=true --terse=true"/> + <arg line="multimode --file ${asadmin.file}" /> + </exec> + <delete file="${user.password.file}" failonerror="false"/> +</target> + +<!-- ================================================================ --> + +<!-- ================================================================ --> +<!-- Target to create the user in file realm the AppServ --> +<!-- ================================================================ --> +<target name="create-user-common" depends="init-common"> +<property name="user.password.file" value="asadminuserpassword.txt"/> +<echo file="${user.password.file}" append="false"> +AS_ADMIN_USERPASSWORD=${password} +AS_ADMIN_PASSWORD=${admin.password} +AS_ADMIN_ADMINPASSWORD=${admin.password} +AS_ADMIN_MASTERPASSWORD=${master.password} +</echo> + <exec executable="${ASADMIN}"> + <arg line="create-file-user"/> + <arg line="--user ${admin.user} --passwordfile ${user.password.file} --host ${admin.host} --port ${admin.port} --echo=true --terse=true"/> + <arg line="--groups ${groups}"/> + <arg line="--authrealmname ${authrealmname}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${user}"/> + </exec> + <delete file="${user.password.file}" failonerror="false"/> +</target> + +<!-- ================================================================ --> +<!-- Target to delete the user in file realm the AppServ --> +<!-- ================================================================ --> +<target name="delete-user-common" depends="init-common"> +<echo message="Deleting user ${user} in file realm" level="verbose"/> +<exec executable="${ASADMIN}"> + <arg line="delete-file-user"/> + <arg line="${as.props}"/> + <arg line="--authrealmname ${authrealmname}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${user}"/> +</exec> +</target> + +<!-- ================================================================ --> +<!-- J2EE Connector related targets --> +<!-- ================================================================ --> + +<target name="create-connector-connpool-common" + depends="init-common, create-connector-connpool"/> + +<target name="create-connector-connpool" depends="init-common"> + <property name="failonerror" value="false"/> + <property name="extra-params" value=""/> + <echo message="asadmin create-connector-connection-pool ${as.props} --raname ${ra.name} --connectiondefinition ${connection.defname} --target ${appserver.instance.name} ${connector.conpool.name}"/> + <exec executable="${ASADMIN}" failonerror="${failonerror}"> + <arg line="create-connector-connection-pool"/> + <arg line="${as.props}"/> + <arg line="--raname ${ra.name}"/> + <arg line="${extra-params}"/> + <arg line="--connectiondefinition ${connection.defname}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${connector.conpool.name}"/> + </exec> +</target> + +<target name="delete-connector-connpool-common" depends="init-common"> + <echo message="asadmin delete-connector-connection-pool ${as.props} --cascade=true ${connector.conpool.name}"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="delete-connector-connection-pool"/> + <arg line="${as.props}"/> + <arg line="--cascade=true"/> + <arg line="${connector.conpool.name}"/> + </exec> +</target> + +<!-- create/delete Connector resource --> +<target name="create-connector-resource-common" depends="init-common"> + <property name="failonerror" value="false"/> + <echo message="asadmin create-connector-resource ${as.props} --poolname ${connector.conpool.name} --target ${appserver.instance.name} ${connector.jndi.name}"/> + <exec executable="${ASADMIN}" failonerror="${failonerror}"> + <arg line="create-connector-resource"/> + <arg line="${as.props}"/> + <arg line="--poolname ${connector.conpool.name}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${connector.jndi.name}"/> + </exec> +</target> + +<target name="delete-connector-resource-common" depends="init-common"> + <echo message="asadmin delete-connector-resource ${as.props} ${connector.jndi.name}"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="delete-connector-resource"/> + <arg line="${as.props}"/> + <arg line="${connector.jndi.name}"/> + </exec> +</target> + +<!-- deploy/undeploy RAR files --> +<target name="deploy-rar-common" depends="init-common"> + <echo message="Deploying ${rarfile}" level="verbose"/> + <echo message="asadmin deploy ${as.props} --target ${appserver.instance.name} --force=${force} ${rarfile}"/> + <property name="force" value="false"/> + <property name="extra-params" value=""/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="${extra-params}"/> + <arg line="--force=${force}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${rarfile}"/> + </exec> + <echo message="Deploying ${rarfile} on ${appserver.instance.name}"/> +</target> + +<target name="undeploy-rar-common" depends="init-common"> + <echo message="Undeploying ${undeployrar}" level="verbose"/> + <echo message="asadmin undeploy ${as.props} --target ${appserver.instance.name} --cascade=${cascade} ${undeployrar}"/> + <property name="cascade" value="false"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="undeploy"/> + <arg line="${as.props}"/> + <arg line="--cascade=${cascade}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${undeployrar}"/> + </exec> +</target> + +<!-- ================================================================ --> +<!-- Target to create JDBC connection pool --> +<!-- ================================================================ --> +<target name="create-jdbc-connpool-common" depends="init-common"> +<echo message="created jdbc connection pool ${jdbc.conpool.name}" + level="verbose"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="create-jdbc-connection-pool"/> + <arg line="--datasourceclassname ${db.class}"/> + <arg line="--restype ${jdbc.resource.type}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${as.props}"/> + <arg line="${jdbc.conpool.name}"/> + </exec> + <antcall target="set-${db.type}-connpool-props"/> +</target> + +<target name="create-jdbc-driver-connpool-common" depends="init-common"> +<echo message="created jdbc connection pool ${jdbc.conpool.name}" + level="verbose"/> + <property name="extra-params" value=""/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="create-jdbc-connection-pool"/> + <arg line="--driverclassname ${db.class}"/> + <arg line="--restype ${jdbc.resource.type}"/> + <arg line="${extra-params}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${as.props}"/> + <arg line="${jdbc.conpool.name}"/> + </exec> + <antcall target="set-${db.type}-driver-connpool-props"/> +</target> + +<target name="set-pointbase-connpool-props"> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.jdbc-connection-pool.${jdbc.conpool.name}.property.DatabaseName=${db.url}"/> + </antcall> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.jdbc-connection-pool.${jdbc.conpool.name}.property.User=${db.user}" /> + </antcall> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.jdbc-connection-pool.${jdbc.conpool.name}.property.Password=${db.pwd}" /> + </antcall> +</target> + +<target name="set-pointbase-driver-connpool-props"> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.jdbc-connection-pool.${jdbc.conpool.name}.property.URL=${db.url};user=${db.user};password=${db.pwd}"/> + </antcall> +</target> + +<target name="set-derby-connpool-props"> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="set"/> + <arg line="${as.props}"/> + <arg line="domain.resources.jdbc-connection-pool.${jdbc.conpool.name}.property.User=${db.user}"/> + </exec> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="set"/> + <arg line="${as.props}"/> + <arg line="domain.resources.jdbc-connection-pool.${jdbc.conpool.name}.property.Password=${db.pwd}"/> + </exec> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="set"/> + <arg line="${as.props}"/> + <arg line="domain.resources.jdbc-connection-pool.${jdbc.conpool.name}.property.driverType=4"/> + </exec> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="set"/> + <arg line="${as.props}"/> + <arg line="domain.resources.jdbc-connection-pool.${jdbc.conpool.name}.property.portNumber=${db.port}"/> + </exec> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="set"/> + <arg line="${as.props}"/> + <arg line="domain.resources.jdbc-connection-pool.${jdbc.conpool.name}.property.dataBaseName=${db.name}"/> + </exec> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="set"/> + <arg line="${as.props}"/> + <arg line="domain.resources.jdbc-connection-pool.${jdbc.conpool.name}.property.retrieveMessagesFromServerOnGetMessage=true"/> + </exec> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="set"/> + <arg line="${as.props}"/> + <arg line="domain.resources.jdbc-connection-pool.${jdbc.conpool.name}.property.create=true"/> + </exec> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="set"/> + <arg line="${as.props}"/> + <arg line="domain.resources.jdbc-connection-pool.${jdbc.conpool.name}.property.serverName=${db.host}"/> + </exec> +</target> + +<target name="set-derby-driver-connpool-props"> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.jdbc-connection-pool.${jdbc.conpool.name}.property.URL=${db.url};user=${db.user};password=${db.pwd}"/> + </antcall> +</target> + +<!-- ================================================================ --> +<!-- Target to delete JDBC connection-pool --> +<!-- ================================================================ --> +<target name="delete-jdbc-connpool-common" depends="init-common"> +<echo message="asadmin delete-jdbc-connection-pool ${as.props} --cascade=true --target ${appserver.instance.name} ${jdbc.conpool.name}"/> +<exec executable="${ASADMIN}" failonerror="false"> + <arg line="delete-jdbc-connection-pool"/> + <arg line="${as.props}"/> + <arg line="--cascade=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${jdbc.conpool.name}"/> + </exec> + <echo message="cmd executed for ${appserver.instance.name}"/> +</target> + +<!-- ================================================================ --> +<!-- Target to create JDBC resource --> +<!-- ================================================================ --> +<target name="create-jdbc-resource-common" depends="init-common"> +<echo message="Creating jdbc resource pool ${jdbc.resource.name}" + level="verbose"/> + <echo message="asadmin create-jdbc-resource ${as.props} --connectionpoolid ${jdbc.conpool.name} --target ${appserver.instance.name} ${jdbc.resource.name}"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="create-jdbc-resource"/> + <arg line="${as.props}"/> + <arg line="--connectionpoolid ${jdbc.conpool.name}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${jdbc.resource.name}"/> + </exec> + <echo message="cmd executed for ${appserver.instance.name}"/> +</target> + +<!-- ================================================================ --> +<!-- Target to delete JDBC resource --> +<!-- ================================================================ --> +<target name="delete-jdbc-resource-common" depends="init-common"> +<echo message="asadmin delete-jdbc-resource ${as.props} --target ${appserver.instance.name} ${jdbc.resource.name}"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="delete-jdbc-resource"/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${jdbc.resource.name}"/> + </exec> + <echo message="cmd executed for ${appserver.instance.name}"/> +</target> + +<!-- ================================================================ --> +<!-- Target to deploy JDBC resources --> +<!-- ================================================================ --> +<target name="deploy-jdbc-common" depends="init-common"> + <antcall target="create-jdbc-connpool-common" /> + <antcall target="create-jdbc-resource-common" /> +</target> + +<target name="deploy-jdbc-driver-common" depends="init-common"> + <antcall target="create-jdbc-driver-connpool-common" /> + <antcall target="create-jdbc-resource-common" /> +</target> + +<!-- ================================================================ --> +<!-- Target to undeploy JDBC resources --> +<!-- ================================================================ --> +<target name="undeploy-jdbc-common" depends="init-common"> + <antcall target="delete-jdbc-resource-common" /> + <antcall target="delete-jdbc-connpool-common" /> +</target> + +<!-- ================================================================ --> +<!-- Target to create persistence resource --> +<!-- ================================================================ --> +<target name="create-persistence-resource-common" depends="init-common"> +<echo message="Creating pm resource at ${pm.resource.name}" + level="verbose"/> + <echo message="asadmin create-persistence-resource ${as.props} --target ${appserver.instance.name} ${pm.resource.name}"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="create-persistence-resource"/> + <arg line="${as.props}"/> + <arg line="--port ${admin.port}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${pm.resource.name}"/> + </exec> + <echo message="Created ${pm.resource.name} --target ${appserver.instance.name}"/> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set"/> + <param name="operand.props" + value="${resources.dottedname.prefix}.persistence-manager-factory-resource.${pm.resource.name}.factory_class=${pm.factory.class}"/> + </antcall> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${resources.dottedname.prefix}.persistence-manager-factory-resource.${pm.resource.name}.jdbc_resource_jndi_name=${jdbc.resource.name}" /> + </antcall> +</target> + +<!-- ================================================================ --> +<!-- Target to delete persistence resource --> +<!-- ================================================================ --> +<target name="delete-persistence-resource-common" depends="init-common"> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" + value="delete-persistence-resource + --target ${appserver.instance.name}" /> + <param name="operand.props" value="${pm.resource.name}" /> + </antcall> +</target> + +<target name="execute-sql-common" depends="init-common"> +<echo message="Executing sql statement at ${basedir} from ${sql.file}" + level="verbose"/> + <sql + driver="${db.driver}" + url="${db.url}" + userid="${db.user}" + password="${db.pwd}" + src="${sql.file}" + onerror="continue" + print="yes" + classpath="${s1astest.classpath}"/> +</target> + + +<target name="execute-ejb-sql-common" depends="init-common"> +<echo message="Executing sql statement at ${basedir} from ${sql.file}" + level="verbose"/> + <sql + driver="${db.driver}" + url="jdbc:derby://localhost:1527/sun-appserv-samples;create=true;" + userid="APP" + password="APP" + src="${sql.file}" + onerror="continue" + print="yes" + output="${build.classes.dir}/setupDBTables.out" + classpath="${s1astest.classpath}" /> +</target> + +<!-- ================================================================ --> +<!-- Target to create/delete javamail resources --> +<!-- + Properties required: + mailhost + fromaddress + debug + enabled + javamail.resource.name (e.g. mail/MySession) +--> +<!-- ================================================================ --> +<target name="create-javamail-resource-common"> + <exec executable="${ASADMIN}"> + <arg line="create-javamail-resource"/> + <arg line="--port ${admin.port}"/> + <arg line="--mailhost ${mailhost}"/> + <arg line="--mailuser ${mailuser}"/> + <arg line="--fromaddress ${fromaddress}"/> + <arg line="--storeprotocol=imap"/> + <arg line="--storeprotocolclass=com.sun.mail.imap.IMAPStore"/> + <arg line="--transprotocol=smtp"/> + <arg line="--transprotocolclass=com.sun.mail.smtp.SMTPTransport"/> + <arg line="--debug=${debug}"/> + <arg line="--enabled=${enabled}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${as.props}"/> + <arg line="${javamail.resource.name}"/> + </exec> +</target> + +<target name="delete-javamail-resource-common"> + <exec executable="${ASADMIN}"> + <arg line="delete-javamail-resource"/> + <arg line="--port ${admin.port}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${as.props}"/> + <arg line="${javamail.resource.name}"/> + </exec> +</target> + +<!-- ================================================================ --> +<!-- Target to create database table through SQL file --> +<!-- ================================================================ --> +<target name="create-sql-common" depends="init-common"> +<echo message="creating tables from ${basedir}/sql/${db.create}" + level="verbose"/> + <sql + driver="${db.driver}" + url="${db.url}" + userid="${db.user}" + password="${db.pwd}" + src="sql/${db.create}" + onerror="continue" + print="yes" + output="${build.classes.dir}/setupDBTables.out" + classpath="${s1astest.classpath}" + /> +</target> + +<!-- ================================================================ --> +<!-- Target to delete database table through SQL file --> +<!-- ================================================================ --> +<target name="delete-sql-common" depends="init-common"> +<echo message="dropping tables from ${basedir}/sql/${db.drop}" + level="verbose"/> + <sql + driver="${db.driver}" + url="${db.url}" + userid="${db.user}" + password="${db.pwd}" + src="sql/${db.drop}" + onerror="continue" + print="yes" + output="${build.classes.dir}/setupDBTables.out" + classpath="${s1astest.classpath}" + /> +</target> + +<!-- ======================================================= --> +<!-- Taget to create JMS Connection --> +<!-- ======================================================= --> +<target name="create-jms-connection-common" depends="init-common"> + <echo message="Creating JMS connection factory with name ${jms.factory.name}" + level="verbose"/> + <exec executable="${ASADMIN}"> + <arg line="create-jms-resource "/> + <arg line="--restype ${jms.factory.type}"/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${jms.factory.name}" /> + </exec> +</target> + +<!-- ======================================================= --> +<!-- Taget to delete JMS Connection --> +<!-- ======================================================= --> +<target name="delete-jms-connection-common" depends="init-common"> + <echo message="Delete JMS connection factory with name ${jms.factory.name}" + level="verbose"/> + <exec executable="${ASADMIN}"> + <arg line="delete-jms-resource "/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${jms.factory.name}"/> + </exec> +</target> + +<!-- JMS: create/delete Destination Resource Targets --> +<target name="create-jms-resource-common" depends="init-common"> + <echo message="Creating JMS resource with name ${jms.resource.name}" + level="verbose"/> + + <exec executable="${ASADMIN}"> + <arg line="create-jmsdest --desttype ${dest.type} "/> + <arg line="${as.props}"/> + <arg line="${dest.name}"/> + </exec> + + <exec executable="${ASADMIN}"> + <arg line="create-jms-resource "/> + <arg line="--restype ${jms.resource.type}"/> + <arg line="--property imqDestinationName=${dest.name}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${as.props}"/> + <arg line="${jms.resource.name}"/> + </exec> +</target> + +<target name="delete-jms-resource-common" depends="init-common"> + <echo message="Delete JMS resource with name ${jms.resource.name}" + level="verbose"/> + + <exec executable="${ASADMIN}"> + <arg line="delete-jms-resource "/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${as.props} ${jms.resource.name}"/> + </exec> + + <exec executable="${ASADMIN}"> + <arg line="delete-jmsdest --desttype ${dest.type} "/> + <arg line="${as.props} ${dest.name}"/> + </exec> +</target> + +<!-- deploy/undeploy JMS resources --> +<target name="deploy-jms-common" depends="init-common"> + <antcall target="create-jms-connection-common" /> + <antcall target="create-jms-resource-common" /> +</target> + +<target name="undeploy-jms-common" depends="init-common"> + <antcall target="delete-jms-connection-common" /> + <antcall target="delete-jms-resource-common" /> +</target> + + +<!-- run StaticCheck on the ear file --> +<target name="staticCheck-common" depends="init-common"> + <echo message="Running StaticCheck -b on + ear file ${assemble.dir}/${appname}App.ear " level="verbose"/> + <antcall target="verifier-common"> + <param name="static-check.command" value=" -b "/> + <param name="operand.props" value="${assemble.dir}/${appname}App.ear"/> + </antcall> + <echo message="Validate the static check results" level="verbose"/> +</target> + +<target name="deploy-dir" depends="init-common"> + <echo message="Deploying files: ${assemble.dir}" level="verbose"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--contextroot ${contextroot}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--name ${appname}-web"/> + <arg line="${assemble.dir}"/> + </exec> +</target> + +<!-- deploy the applications in AppServ --> +<target name="deploy-common" depends="init-common"> + <antcall target="deploy-common-pe"/> + <antcall target="deploy-common-ee"/> +</target> + +<target name="deploy-verify-common" depends="init-common"> + <antcall target="deploy-verify-common-pe"/> + <antcall target="deploy-verify-common-ee"/> +</target> + +<target name="deploy-common-pe" depends="init-common" unless="ee"> + <property name="deployed.app" value="${assemble.dir}/${appname}App.ear"/> + <property name="extra-params" value=""/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="${extra-params}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--retrieve ${assemble.dir}"/> + <arg line="--libraries ${libraries}"/> +<!-- deployed.app defaults to ${assemble.dir}/${appname}App.ear defined in properties.xml--> + <arg line="${deployed.app}"/> + </exec> + <echo message="Deployment on target server ${appserver.instance.name} successful"/> + </target> + +<target name="deploy-common-ee" depends="init-common" if="ee"> + <echo message="Deploying in EE..."/> + <property name="deployed.app" value="${assemble.dir}/${appname}App.ear"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--retrieve ${assemble.dir}"/> + <arg line="--libraries ${libraries}"/> +<!-- deployed.app defaults to ${assemble.dir}/${appname}App.ear defined in properties.xml--> + <arg line="${deployed.app}"/> + </exec> + <echo message="Deployment on target server ${appserver.instance.name} successful"/> +</target> + +<target name="deploy-verify-common-pe" depends="init-common" unless="ee"> + <property name="deployed.app" value="${assemble.dir}/${appname}App.ear"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--verify=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--retrieve ${assemble.dir}"/> + <arg line="${deployed.app}"/> + </exec> + <echo message="Deployment on target server ${appserver.instance.name} successful"/> + </target> + +<target name="deploy-verify-common-ee" depends="init-common" if="ee"> + <echo message="Deploying in EE..."/> + <property name="deployed.app" value="${assemble.dir}/${appname}App.ear"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--verify=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--retrieve ${assemble.dir}"/> + <arg line="${deployed.app}"/> + </exec> + <echo message="Deployment on target server ${appserver.instance.name} successful"/> +</target> + +<!-- deploy the web application in AppServ --> +<target name="deploy-jsp-common" depends="init-common"> + <echo message="Deploying ${deploy.file} from ${basedir}." level="verbose"/> + <property name="precompilejsp" value="true"/> + <exec executable="${ASADMIN}" failonerror="true"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--precompilejsp=${precompilejsp}"/> + <arg line="--upload true"/> + <arg line="--retrieve ${assemble.dir}"/> + <arg line="--target ${appserver.instance.name}"/> + </exec> +</target> + +<target name="deploy-war-name" depends="init-common"> + <echo message="Deploying ${warname} from ${basedir}." + level="verbose"/> + <property name="force" value="false"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--contextroot ${contextroot}"/> + <arg line="--precompilejsp=${precompilejsp}"/> + <arg line="--force=${force}"/> + <arg line="--upload=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--libraries ${libraries}"/> + <arg line="${warname}.war"/> + </exec> +</target> + +<!-- deploy the standalone war in AppServ --> +<target name="deploy-war-common"> +<antcall target ="deploy-war-commonpe"/> +<antcall target ="deploy-war-commonee"/> +</target> + +<target name="deploy-wab-common"> +<antcall target ="deploy-wab-commonpe"/> +</target> + +<target name="deploy-wab-commonpe" depends="init-common" unless="ee"> + <echo message="Deploying WAB ${assemble.dir}/${appname}-web.war from ${basedir}." + level="verbose"/> + <property name="precompilejsp" value="true"/> + <property name="force" value="false"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--precompilejsp=${precompilejsp}"/> + <arg line="--force=${force}"/> + <arg line="--upload=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--libraries ${libraries}"/> + <arg line="--type=osgi"/> + <arg line="${assemble.dir}/${appname}-web.war"/> + </exec> +</target> + + + +<target name="deploy-war-commonpe" depends="init-common" unless="ee"> + <echo message="Deploying ${assemble.dir}/${appname}-web.war from ${basedir}." + level="verbose"/> + <property name="precompilejsp" value="true"/> + <property name="force" value="false"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--contextroot ${contextroot}"/> + <arg line="--precompilejsp=${precompilejsp}"/> + <arg line="--force=${force}"/> + <arg line="--upload=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--libraries ${libraries}"/> + <arg line="${assemble.dir}/${appname}-web.war"/> + </exec> +</target> + +<target name="deploy-war-commonee" if="ee"> + <property name="precompilejsp" value="true"/> + <property name="force" value="false"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--type web"/> + <arg line="--contextroot ${contextroot}"/> + <arg line="--precompilejsp=${precompilejsp}"/> + <arg line="--force=${force}"/> + <arg line="--upload=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--libraries ${libraries}"/> + <arg line="${assemble.dir}/${appname}-web.war"/> + </exec> +</target> + +<!-- deploy the standalone war in AppServ without specifying any + contextroot argument, so that the context-root specified in + sun-web.xml takes effect +--> +<target name="deploy-war-no-context-root" depends="init-common"> + <antcall target ="deploy-war-no-context-root-pe"/> + <antcall target ="deploy-war-no-context-root-ee"/> +</target> + +<target name="deploy-war-no-context-root-pe" unless="ee"> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="--user ${admin.user}"/> + <arg line="--passwordfile ${admin.password.file}"/> + <arg line="--host ${admin.host}"/> + <arg line="--port ${admin.port}"/> + <arg line="--upload=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--libraries ${libraries}"/> + <arg line="${assemble.dir}/${appname}-web.war"/> + </exec> +</target> + +<target name="deploy-war-no-context-root-ee" if="ee"> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="deploy"/> + <arg line="--user ${admin.user}"/> + <arg line="--passwordfile ${admin.password.file}"/> + <arg line="--host ${admin.host}"/> + <arg line="--port ${admin.port}"/> + <arg line="--type web"/> + <arg line="--upload=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="--libraries ${libraries}"/> + <arg line="${assemble.dir}/${appname}-web.war"/> + </exec> +</target> + +<!-- deploy the standalone jar in AppServ --> +<target name="deploy-jar-common" depends="init-common"> + <exec executable="${ASADMIN}" failonerror="true"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--upload=true"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${assemble.dir}/${appname}-ejb.jar"/> + </exec> +</target> + +<!-- deploy the standalone jar in AppServ --> +<target name="deploy-client-common" depends="init-common"> + <exec executable="${ASADMIN}" failonerror="true"> + <arg line="deploy"/> + <arg line="${as.props}"/> + <arg line="--upload=true"/> + <arg line="--retrieve ${assemble.dir}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${assemble.dir}/${appname}-client.jar"/> + </exec> +</target> + +<target name="undeploy-war-name" depends="init-common"> + <property name="deployedapp.name" value="${warname}"/> + <property name="extra-params" value=""/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="undeploy"/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${extra-params}"/> +<!-- deployedapp.name defaults to {appname}App.declared in properties.xml--> + <arg line="${deployedapp.name}"/> + </exec> +</target> + +<!-- undeploy the applications in AppServ --> +<target name="undeploy-common" depends="init-common"> + <property name="deployedapp.name" value="${appname}App"/> + <property name="extra-params" value=""/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="undeploy"/> + <arg line="${as.props}"/> +<!-- +<arg line=type ${apptype}/> +--> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${extra-params}"/> +<!-- deployedapp.name defaults to {appname}App.declared in properties.xml--> + <arg line="${deployedapp.name}"/> + </exec> +</target> + +<!-- undeploy the standalone war in AppServ --> +<target name="undeploy-war-common" depends="init-common"> + <echo message="Undeploying warfile ${appname}-web from + ${assemble.dir}/${appname}-web.war from ${basedir}." level="verbose"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="undeploy"/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${appname}-web"/> + </exec> +</target> + + +<!-- undeploy the standalone war in AppServ --> +<target name="undeploy-jar-common" depends="init-common"> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="undeploy"/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${appname}-ejb"/> + </exec> +</target> + +<!-- undeploy the standalone client in AppServ --> +<target name="undeploy-client-common" depends="init-common"> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="undeploy"/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="${appname}-client"/> + </exec> +</target> + + +<!-- run appclient in AppServ --> +<target name="runclient-common" depends="init-common"> + <echo message="appclient -client ${assemble.dir}/${appname}AppClient.jar -name ${appname}Client -textauth -user j2ee -password j2ee -xml ${admin.domain.dir}/${admin.domain}/config/glassfish-acc.xml ${appclient.application.args}"/> + <exec executable="${APPCLIENT}" failonerror="false"> + <!-- set APPCPATH to include reporter.jar so that all app clients + don't have to package the test framework in their apps --> + <env key="APPCPATH" file="${env.APS_HOME}/lib/reporter.jar"/> + <arg line="-client ${assemble.dir}/${appname}AppClient.jar"/> + <arg line="-name ${appname}Client"/> + <arg line="-textauth"/> + <arg line="-user j2ee"/> + <arg line="-password j2ee"/> + <arg line="-xml ${admin.domain.dir}/${admin.domain}/config/glassfish-acc.xml"/> + <arg line="${appclient.application.args}"/> + </exec> + +<!-- confirming report generation... --> + <antcall target="checkReporting-common"> + <param name="test.name" value="${appname}"/> + <param name="test.description" value="${test.description}"/> + <param name="test.count" value="${test.count}"/> + </antcall> +</target> + +<!-- run web client in AppServ --> +<target name="runwebclient-common" depends="init-common"> + <echo message="Running Web Test from ${basedir}" level="verbose"/> + <echo message="http host: ${http.host}" level="verbose"/> + <echo message="http port: ${http.port}" level="verbose"/> + <java + fork="on" failonerror="false" + classpath="${env.APS_HOME}/lib/webtest.jar:${s1astest.classpath}" + classname="com.sun.ejte.ccl.webrunner.webtest.WebTest"> + <arg value="script.txt"/> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="appserv-tests"/> + <arg value="${testsuite.id}"/> + </java> +</target> + +<!-- prepare Pointbase servers --> +<target name="preparePB" depends="init-common"> + <echo message="Starting Pointbase servers" level="verbose"/> + <copy file="${env.APS_HOME}/lib/pointbase.ini" + tofile="${db.dir}/pointbase.ini"/> + <replace file="${db.dir}/pointbase.ini" token="@@@" value="${db.dir}"/> +</target> + +<!-- start/stop Pointbase servers --> +<target name="startPB" depends="preparePB"> + <java classname="com.pointbase.net.netServer" + classpath="${db.classpath}" fork="true" spawn="true"> + <arg line="/port:9092"/> + <arg line="/pointbase.ini=${db.dir}/pointbase.ini"/> + <arg line="/noconsole"/> + </java> + <java classname="com.pointbase.net.netServer" + classpath="${db.classpath}" fork="true" spawn="true"> + <arg line="/port:9093"/> + <arg line="/pointbase.ini=${db.dir}/pointbase.ini"/> + <arg line="/noconsole"/> + </java> +</target> + +<!-- target name="startPB" depends="preparePB"> + <parallel> + <java classname="com.pointbase.net.netServer" + classpath="${db.classpath}" failonerror="false" fork="true"> + <arg line="/port:9092"/> + <arg line="/pointbase.ini=${db.dir}/pointbase.ini"/> + </java> + <java classname="com.pointbase.net.netServer" + classpath="${db.classpath}" failonerror="true" fork="true"> + <arg line="/port:9093"/> + <arg line="/pointbase.ini=${db.dir}/pointbase.ini"/> + </java> + </parallel> +</target --> + +<!-- start Derby Database --> +<target name="startDerby"> + <condition property="darwin"> + <os name="Mac OS X"/> + </condition> + <antcall target="startDerbyNonMac"/> + <antcall target="startDerbyMac"/> +</target> + +<target name="startDerbyNonMac" depends="init-common" unless="darwin"> + <echo message="StaRTing Derby DB servers in the Network Mode"/> + <parallel> + <java classname="org.apache.derby.drda.NetworkServerControl" + classpath="${db.classpath}" fork="true" spawn="true"> + <arg line="-h localhost -p 1527 start"/> + </java> + <java classname="org.apache.derby.drda.NetworkServerControl" + classpath="${db.classpath}" fork="true" spawn="true"> + <arg line="-h localhost -p 1528 start"/> + </java> + </parallel> +</target> + +<target name="startDerbyMac" depends="init-common" if="darwin"> + <echo message="StaRTing Derby DB servers in the Network Mode"/> + <parallel> + <java classname="org.apache.derby.drda.NetworkServerControl" + classpath="${db.classpath}" fork="true" spawn="true"> + <sysproperty key="derby.storage.fileSyncTransactionLog" value="true"/> + <arg line="-h localhost -p 1527 start"/> + </java> + <java classname="org.apache.derby.drda.NetworkServerControl" + classpath="${db.classpath}" fork="true" spawn="true"> + <sysproperty key="derby.storage.fileSyncTransactionLog" value="true"/> + <arg line="-h localhost -p 1528 start"/> + </java> + </parallel> +</target> + +<!-- start Derby Database --> +<target name="stopDerby" depends="init-common"> + <echo message="Stopping Derby DB servers ..."/> + <parallel> + <java classname="org.apache.derby.drda.NetworkServerControl" + classpath="${db.classpath}" failonerror="true" fork="true"> + <arg line="-h localhost -p 1527 shutdown"/> + </java> + <java classname="org.apache.derby.drda.NetworkServerControl" + classpath="${db.classpath}" failonerror="true" fork="true"> + <arg line="-h localhost -p 1528 shutdown"/> + </java> + </parallel> +</target> + +<target name="pb"> + <echo message="So you are using pointbase ... !"/> + <property file="${env.APS_HOME}/config/pointbase.properties"/> +</target> + +<!-- setup IMQ for RI Build --> +<target name="setup-mq-common" depends="init-common"> + <echo message="Executing Datastore setup for S1MQ. Required only for RI" + level="verbose"/> + <echo message="${IMQDBMGR} -javahome ${java.home} + -b ${admin.domain}_${appserver.instance.name} create all" + level="verbose"/> + <exec executable="${IMQDBMGR}" failonerror="true"> + <arg line="-javahome ${java.home} -b ${admin.domain}_${appserver.instance.name} create all" /> + </exec> +</target> + +<target name="import-wsdl" depends="init-common"> + <mkdir dir="${build.classes.dir}"/> + <exec executable="${WSCOMPILE}"> +<!-- + <arg line="-classpath ${s1astest.classpath}"/> +--> + <arg line="-classpath ${build.classes.dir}"/> + <arg line="-import"/> + <arg line="-source 1.1.2"/> + <arg line="-keep"/> + <arg line="-d "/> + <arg path="${build.classes.dir}"/> + <!-- + <arg line="-s "/> + <arg path="${basedir}/gensource"/> + --> + <arg line="-mapping ${build.classes.dir}/${mapping.file}"/> + <arg line="${config-wsdl.file}"/> + </exec> +</target> + +<!-- Confirm Report Generation --> + +<target name="checkReporting-common"> + <available file="RepRunConf.txt" type="file" property="isReported"/> + <antcall target="confirmReportPresent-common"/> + <antcall target="confirmMissingReport-common"/> +</target> + +<target name="confirmReportPresent-common" if="isReported"> + <echo message="file RepRunConf.txt is present."/> + <echo message="Test seems to be reported fine"/> + <delete file="RepRunConf.txt"/> +</target> + +<target name="confirmMissingReport-common" unless="isReported"> + <echo message="file RepRunConf.txt is missing!!!"/> + <echo message="Test does not seem to have been reported"/> + <echo message="Adding status 'did not run' into report..."/> + <java classname="com.sun.ejte.ccl.reporter.ReporterClient"> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reporter.jar"/> + <pathelement location="."/> + </classpath> + <arg value="${test.name}"/> + <arg value="${test.description}"/> + <arg value="${test.count}"/> + </java> + <delete file="RepRunConf.txt"/> +</target> + + +<!-- usage --> +<target name="usage-common"> + <echo> + ant clean Remove all classes files + ant build Build the application + ant deploy Deploy the ear files to S1AS + ant run Run the application + ant undeploy Undeploy the ear files from S1AS + ant usage Display this message + </echo> +</target> + + +<!-- EE Targets 8.1 --> +<!--Added Feb 5th 2004 by Deepa Singh --> +<target name="ee" depends="ee-common"> + <echo message="So you are using Enterprise Edition"/> + <property name="ee" value="Enterprise Edition"/> + <property file="${env.APS_HOME}/eeconfig/ee-config.properties"/> + <loadfile property="target-server-port" srcFile="${admin.domain.dir}/${admin.domain}/config/glassfish-acc.xml"/> + <condition property="orbPortSet" value="true"> + <contains string="${target-server-port}" substring="${orb.port}"/> + </condition> + <antcall target="change-orb-port"/> +</target> + +<target name="change-orb-port" unless="orbPortSet"> + <echo message="changing orb port from the default [3700] to ${orb.port}"/> + <replace file="${admin.domain.dir}/${admin.domain}/config/glassfish-acc.xml" token="3700" value="${orb.port}"/> +</target> + + +<target name="restart-instance"> + <echo message="Restarting remote server instance,until this gets fixed"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="stop-instance"/> + <arg line="${as.props}"/> + <arg line="${appserver.instance.name}"/> + </exec> + <sleep seconds="30"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="start-instance"/> + <arg line="${as.props}"/> + <arg line="${appserver.instance.name}"/> + </exec> +</target> + +<target name="testTimer" depends="init-common"> + +<echo message="creating timer table from ${env.APS_HOME}/lib/ejbtimer_${db.type}.sql"/> + <sql + driver="${db.driver}" + url="${db.url}" + userid="${db.user}" + password="${db.pwd}" + src="${env.APS_HOME}/lib/ejbtimer_${db.type}.sql" + onerror="continue" + print="yes" + classpath="${s1astest.classpath}"/> + +</target> + +<target name="setupTimer" depends="init-common" if="ee"> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="create-resource-ref"/> + <arg line="${as.props}"/> + <arg line="--target server"/> + <arg line="${jdbc.resource.name}"/> + </exec> + <antcall target="asadmin-common-ignore-fail"> + <param name="admin.command" value="set" /> + <param name="operand.props" + value="${appserver.instance.name}-config.ejb-container.ejb-timer-service.timer-datasource=${jdbc.resource.name}"/> + </antcall> + + <echo message="creating timer table from ${env.APS_HOME}/lib/ejbtimer_{db.type}.sql"/> + <sql + driver="${db.driver}" + url="${db.url}" + userid="${db.user}" + password="${db.pwd}" + src="${env.APS_HOME}/lib/ejbtimer_${db.type}.sql" + onerror="continue" + print="yes" + classpath="${s1astest.classpath}"/> + + <antcall target="restart-instance"/> +</target> + +<target name="unsetupTimer" depends="init-common" if="ee"> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="delete-resource-ref"/> + <arg line="${as.props}"/> + <arg line="--target server"/> + <arg line="${jdbc.resource.name}"/> + </exec> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="unset"/> + <arg line="${appserver.instance.name}-config.ejb-container.ejb-timer-service.timer-datasource"/> + </exec> + + <echo message="dropping timer table from ${env.APS_HOME}/lib/ejbtimer_${db.type}_drop.sql"/> + <sql + driver="${db.driver}" + url="${db.url}" + userid="${db.user}" + password="${db.pwd}" + src="${env.APS_HOME}/lib/ejbtimer_${db.type}_drop.sql" + onerror="continue" + print="yes" + classpath="${s1astest.classpath}"/> +</target> + +<target name="prepare-truststore-common" depends="init-common"> + <property name="truststore.db.file" location="${build.base.dir}/cacerts.jks"/> + <property name="cert.rfc.file" location="${build.base.dir}/${cert.nickname}.rfc"/> + + <delete quiet="true" file="${truststore.db.file}"/> + <delete quiet="true" file="${cert.rfc.file}"/> + + <!-- + Determine if we need to use the certutil or the keytool command to + access the certificate keystore + --> + <property name="certutil.db.dir" location="${admin.domain.dir}/${admin.domain}/config"/> + <condition property="use.certutil"> + <and> + <or> + <available file="${env.S1AS_HOME}/lib/certutil"/> + <available file="${env.S1AS_HOME}/lib/certutil.exe"/> + </or> + <available file="${certutil.db.dir}/cert8.db"/> + <available file="${certutil.db.dir}/key3.db"/> + <available file="${certutil.db.dir}/secmod.db"/> + </and> + </condition> + <antcall target="prepare-truststore-certutil-common"/> + <antcall target="prepare-truststore-keytool-common"/> +</target> + +<target name="prepare-truststore-certutil-common" depends="init-common" if="use.certutil"> + <exec executable="${env.S1AS_HOME}/lib/certutil" failonerror="true" output="${cert.rfc.file}"> + <!-- + LD_LIBRARY_PATH is needed on Unix platforms and should have no + effect on Windows + --> + <env key="LD_LIBRARY_PATH" path="${env.S1AS_HOME}/lib"/> + <arg line="-L -n '${cert.nickname}' -a"/> + <arg value="-d"/> + <arg file="${certutil.db.dir}"/> + </exec> + <exec executable="${java.home}/bin/keytool" failonerror="true"> + <arg line="-import -trustcacerts -alias '${cert.nickname}' -storepass '${ssl.password}' -noprompt"/> + <arg value="-file"/> + <arg file="${cert.rfc.file}"/> + <arg value="-keystore"/> + <arg file="${truststore.db.file}"/> + </exec> +</target> + + +<target name="prepare-truststore-keytool-common" depends="init-common" unless="use.certutil"> + <copy file="${admin.domain.dir}/${admin.domain}/config/cacerts.jks" tofile="${truststore.db.file}"/> +</target> + + +<target name="prepare-keystore-common" depends="init-common"> + <property name="keystore.db.file" location="${build.base.dir}/keystore.jks"/> + <delete quiet="true" file="${keystore.db.file}"/> + <copy file="${admin.domain.dir}/${admin.domain}/config/keystore.jks" tofile="${keystore.db.file}" failonerror="false"/> +</target> + +<target name="get-version-common" depends="init-common"> + <exec executable="${ASADMIN}" failonerror="false" outputproperty="appserver.version"> + <arg line="version"/> + <arg line="${as.props}"/> + <arg line="--verbose"/> + </exec> + <condition property="platform" value="true"> + <contains string="${appserver.version}" substring="Platform" casesensitive="false"/> + </condition> + <condition property="enterprise" value="true"> + <contains string="${appserver.version}" substring="Enterprise" casesensitive="false"/> + </condition> + <antcall target="platform-common"/> + <antcall target="enterprise-common"/> +</target> + +<target name="platform-common" if="platform"> + <echo message="This is Platform Version***"/> +</target> + +<target name="enterprise-common" if="enterprise"> + <echo message="This is Enterprise Version***"/> +</target> + +<target name="create-PermSize" depends="init-common"> + <echo message="asadmin create-jvm-options ${as.props} -- -XX:MaxPermSize=${jvm.maxpermsize}"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="create-jvm-options"/> + <arg line="${as.props}"/> + <arg line="--target ${appserver.instance.name}"/> + <arg line="-- -XX\:MaxPermSize=${jvm.maxpermsize}"/> + </exec> +</target> + + <target name="restart-server"> + <antcall target="stop-server"/> + <sleep seconds="5"/> + <antcall target="start-server"/> + + </target> + + <target name="stop-server" depends="setOSConditions"> + <antcall target="stop-server-unix"/> + <antcall target="stop-server-windows"/> + </target> + + <target name="stop-server-unix" if="isUnix"> + <echo message="stopping server on unix ..."/> + <exec executable="${env.S1AS_HOME}/bin/asadmin"> + <arg value="stop-domain"/> + </exec> + <sleep seconds="10"/> + </target> + + <target name="stop-server-windows" if="isWindows"> + <echo message="Stopping server on windows ..."/> + <exec executable="cmd"> + <arg value="/c"/> + <arg value="${env.S1AS_HOME}\bin\asadmin.bat"/> + <arg value="stop-domain"/> + </exec> + <sleep seconds="5"/> + </target> + + <target name="start-server" depends="setOSConditions"> + + <echo>+-----------------------------+</echo> + <echo>| |</echo> + <echo>| S T A R T I N G GLASSFISH |</echo> + <echo>| in Felix mode |</echo> + <echo>| |</echo> + <echo>+-----------------------------+</echo> + + <antcall target="start-server-unix"/> + <antcall target="start-server-windows"/> + </target> + + <target name="start-server-unix" if="isUnix"> + <exec executable="${env.S1AS_HOME}/bin/asadmin"> + <env key="GlassFish_Platform" value="Felix"/> + <arg value="start-domain"/> + </exec> + <sleep seconds="10"/> + </target> + + <target name="start-server-windows" if="isWindows"> + <exec executable="cmd" spawn="true"> + <env key="GlassFish_Platform" value="Felix"/> + <arg value="/c"/> + <arg value="${env.S1AS_HOME}\bin\asadmin.bat"/> + <arg value="start-domain"/> + </exec> + <sleep seconds="5"/> + </target> + + <target name="create-jvm-options" depends="init-common"> + <exec executable="${ASADMIN}"> + <arg line="create-jvm-options"/> + <arg line="--user ${admin.user} --host ${admin.host} --port ${admin.port} --echo=true --terse=true"/> + <arg line="${option}"/> + </exec> + <echo message="REQUIRED TO RESTART SERVER......."/> + </target> + + <target name="delete-jvm-options" depends="init-common"> + <exec executable="${ASADMIN}"> + <arg line="delete-jvm-options"/> + <arg line="--user ${admin.user} --host ${admin.host} --port ${admin.port} --echo=true --terse=true"/> + <arg line="${option}"/> + </exec> + <echo message="REQUIRED TO RESTART SERVER......."/> + </target> + +<!-- ================================================================ --> +<!-- Target to Flush connection pool --> +<!-- ================================================================ --> +<target name="flush-connpool-common" depends="init-common"> +<echo message="Flush connection pool ${jdbc.conpool.name}" + level="verbose"/> + <exec executable="${ASADMIN}" failonerror="false"> + <arg line="flush-connection-pool"/> + <arg line="${as.props}"/> + <arg line="${jdbc.conpool.name}"/> + </exec> +</target> + +<!-- ================================================================ --> +<!-- Target to generate a neat Html report --> +<!-- ================================================================ --> +<target name="dev-report" depends="init-common"> + <java classname="com.sun.appserv.test.util.results.HtmlReportProducer" fork="true" failonerror="false" + classpath="${env.APS_HOME}/lib/reportbuilder.jar"> + <arg value="${env.APS_HOME}/test_results.xml"/> + </java> +</target> + +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/descriptor/MANIFEST.MF b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/descriptor/MANIFEST.MF new file mode 100644 index 0000000..5b53761 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/descriptor/MANIFEST.MF
@@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Archiver-Version: Plexus Archiver +Created-By: 1.6.0_20 (Sun Microsystems Inc.) +Built-By: siva +Build-Jdk: 1.6.0_20 +Extension-Name: simple-cdi-osgi-test +Implementation-Title: simple-cdi-osgi-test +Implementation-Version: 1.0 +Bundle-ClassPath: WEB-INF/classes/ +Private-Package: tests.cdi;version="1.0" +Export-EJB: ALL +Bundle-Version: 1.0 +Tool: Bnd-0.0.311 +Bundle-Name: Test CDI OSGI +Bnd-LastModified: 1283184402694 +Bundle-ManifestVersion: 2 +Bundle-SymbolicName: tests.cdi.simple-cdi-osgi-test +Web-ContextPath: /test +Import-Package: javax.enterprise.context,javax.enterprise.inject,javax + .inject,javax.enterprise.inject.spi,javax.servlet,javax.servlet.annotation,javax.servlet.http,javax.naming +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/descriptor/web.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/descriptor/web.xml new file mode 100644 index 0000000..4812478 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/descriptor/web.xml
@@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> +<!-- IT's AN EMPTY FILE. Needed to satisfy maven-war-plugin. +--> +</web-app>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/servlet/tests/cdi/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/servlet/tests/cdi/TestBean.java new file mode 100644 index 0000000..fad6896 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/servlet/tests/cdi/TestBean.java
@@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package tests.cdi; + +//Simple TestBean to test CDI. +//This bean implements Serializable as it needs to be placed into a Stateful Bean +public class TestBean +{}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/servlet/tests/cdi/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/servlet/tests/cdi/TestServlet.java new file mode 100644 index 0000000..9e733d8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/simple-wab-with-cdi/servlet/tests/cdi/TestServlet.java
@@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package tests.cdi; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.inject.Inject; +import javax.enterprise.inject.spi.BeanManager; +import javax.naming.InitialContext; + +@WebServlet(urlPatterns={"/*"}) +public class TestServlet extends HttpServlet { + @Inject TestBean tb; + @Inject BeanManager bm; + BeanManager bm1; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0"); + String msg = ""; + if (tb == null) msg += "Bean injection into Servlet failed"; + if (bm == null) msg += "BeanManager Injection via @Inject failed"; + try { + bm1 = (BeanManager)((new InitialContext()).lookup("java:comp/BeanManager")); + } catch (Exception ex) { + ex.printStackTrace(); + msg += "BeanManager Injection via component environment lookup failed"; + } + if (bm1 == null) msg += "BeanManager Injection via component environment lookup failed"; + + System.out.println("BeanManager is " + bm); + System.out.println("BeanManager via lookup is " + bm1); + writer.write(msg + "\n"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/README b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/README new file mode 100644 index 0000000..96001d0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/README
@@ -0,0 +1 @@ +A Singleton Startup EJB using constructor based injection of CDI beans [issue 13072]
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/build.properties b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/build.properties new file mode 100644 index 0000000..982c344 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/build.properties
@@ -0,0 +1,27 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi-singleton-hello"/> +<property name="appname" value="${module}"/> +<property name="jndiroot" value="${appname}-ejb"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="se.client" value="com.acme.Client"/> +<property name="beans.xml" value="descriptor/beans.xml"/> + +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/build.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/build.xml new file mode 100644 index 0000000..d29250d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/build.xml
@@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../../config/common.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="cdi-singleton-hello-App" default="usage" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="ejb"/> + </antcall> + <antcall target="compile-common"> + <param name="src" value="client"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <antcall target="ejb-jar-common"> + <param name="ejbjar.classes" + value="com/acme/*.class"/> + </antcall> + </target> + + <target name="deploy" + depends="init-common"> + <antcall target="deploy-jar-common"/> + </target> + + <target name="run" depends="init-common"> + <antcall target="run_se"/> + </target> + + <target name="run_se" depends="init-common"> + <java fork="on" + failonerror="true" + classpath="${env.S1AS_HOME}/lib/javaee.jar:${env.S1AS_HOME}/lib/appserv-rt.jar:${build.classes.dir}:${env.APS_HOME}/lib/reporter.jar" + classname="${se.client}"> + <sysproperty key="org.omg.CORBA.ORBInitialPort" value="${orb.port}"/> + <arg line="${jndiroot}"/> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-jar-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/client/Client.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/client/Client.java new file mode 100644 index 0000000..4ec0022 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/client/Client.java
@@ -0,0 +1,90 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + + +import javax.ejb.*; +import javax.annotation.*; + +import javax.naming.InitialContext; + +import javax.management.j2ee.ManagementHome; +import javax.management.j2ee.Management; +import javax.rmi.PortableRemoteObject; + +import com.acme.Hello; +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +public class Client { + + private static SimpleReporterAdapter stat = + new SimpleReporterAdapter("appserv-tests"); + + private static String appName; + + public static void main(String args[]) { + + appName = args[0]; + stat.addDescription(appName); + Client client = new Client(args); + client.doTest(); + stat.printSummary(appName + "ID"); + } + + public Client(String[] args) {} + + public void doTest() { + + try { + + // Ensure that MEJB is registered under all three of its JNDI names + System.out.println("Looking up MEJB Homes"); + ManagementHome mh1Obj = (ManagementHome) new InitialContext().lookup("ejb/mgmt/MEJB"); + ManagementHome mh2Obj = (ManagementHome) new InitialContext().lookup("java:global/mejb/MEJBBean"); + ManagementHome mh3Obj = (ManagementHome) new InitialContext().lookup("java:global/mejb/MEJBBean!javax.management.j2ee.ManagementHome"); + addStatus("mejb relative lookup", (mh1Obj != null)); + addStatus("mejb global lookup", (mh2Obj != null)); + addStatus("mejb global lookup with explicit ManagedHome interface", (mh3Obj != null)); + + Hello hello = (Hello) new InitialContext().lookup("java:global/" + appName + "/SingletonBean"); + String response = hello.hello(); + addStatus("Singleton bean response", response.equals("hello, world!\n")); + + try { + hello.testError(); + addStatus("Expected EJBException from Singleton.testError()", false); + throw new RuntimeException("Expected EJBException"); + } catch(EJBException e) { + addStatus("Expected EJBException from Singleton.testError()", true); + } + + String injectionStatus = hello.testInjection(); + System.out.println("Injection tests in server response"+ injectionStatus); + addStatus("Testing Injection in EJB Singleton" , injectionStatus.trim().equals("")); + + } catch(Exception e) { + stat.addStatus("local main", stat.DID_NOT_RUN); + e.printStackTrace(); + } + } + + private void addStatus(String message, boolean result){ + stat.addStatus(message, (result ? stat.PASS: stat.FAIL)); + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/Bar.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/Bar.java new file mode 100644 index 0000000..07a3880 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/Bar.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.annotation.ManagedBean; + +@ManagedBean +public class Bar implements IBar{ + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/Foo.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/Foo.java new file mode 100644 index 0000000..1d87d9d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/Foo.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.ejb.*; + +public class Foo { + + @EJB Hello hello; + @javax.inject.Inject TestBean tb; + + public boolean testInjection(){ + return tb != null; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/Hello.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/Hello.java new file mode 100644 index 0000000..23f4df7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/Hello.java
@@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +public interface Hello { + + String hello(); + + void testError(); + String testInjection(); + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/IBar.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/IBar.java new file mode 100644 index 0000000..172406e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/IBar.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +public interface IBar { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/SingletonBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/SingletonBean.java new file mode 100644 index 0000000..784bb16 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/SingletonBean.java
@@ -0,0 +1,83 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.annotation.Resource; +import javax.ejb.EJBException; +import javax.ejb.Singleton; +import javax.ejb.Startup; +import javax.inject.Inject; + +import org.omg.CORBA.ORB; + +@Singleton +@Startup +public class SingletonBean { + + @Resource + private ORB orb; + + @Inject + Foo foo; + @Inject + TestBean tb; + + Bar b; + + @Inject + public SingletonBean(Bar b){ + this.b = b; + } + + @PostConstruct + public void init() { + System.out.println("In SingletonBean::init()"); + System.out.println("orb = " + orb); + if (orb == null) { + throw new EJBException("null ORB"); + } + } + + public String hello() { + System.out.println("In SingletonBean::hello()"); + return "hello, world!\n"; + } + + public void testError() { + throw new Error("test java.lang.Error"); + } + + public String testInjection() { + if (foo == null) + return "foo is null"; + if (tb == null) + return "tb is null"; + if (!foo.testInjection()) + return "testInjection in Foo failed"; + if (b == null) + return "Constructor Injection of bean failed"; + return ""; + } + + @PreDestroy + public void destroy() { + System.out.println("In SingletonBean::destroy()"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/TestBean.java new file mode 100644 index 0000000..22e521a --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/singleton-startup/hello/ejb/com/acme/TestBean.java
@@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.acme; + +//Simple test bean to test injection +public class TestBean {}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/README b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/README new file mode 100644 index 0000000..f274683 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/README
@@ -0,0 +1,5 @@ +test for issue GLASSFISH-11683 + +The slf4j api and impl bundled with weld-osgi-bundle must not be exported +to applications and if an application bundles a custom slf4j api and an +implementation bundle, then the bundled SLF4j implmentation must be used
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/WebTest.java new file mode 100644 index 0000000..511806f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/WebTest.java
@@ -0,0 +1,112 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "slf4j-visibility"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for @WebServlet"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (isExpectedResponse(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: org.jboss.logging.JDKLogger and org.jboss.logging.jboss-logging in output" + + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } + + private boolean isExpectedResponse(String line) { + return line.contains("org.jboss.logging.JDKLogger") && line.contains("org.jboss.logging.jboss-logging"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/build.properties b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/build.properties new file mode 100644 index 0000000..14467fd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-slf4j-visibility"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/build.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/build.xml new file mode 100644 index 0000000..83ad666 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/lib/slf4j-api-1.7.25.jar b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/lib/slf4j-api-1.7.25.jar new file mode 100644 index 0000000..0143c09 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/lib/slf4j-api-1.7.25.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/lib/slf4j-simple-1.7.25.jar b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/lib/slf4j-simple-1.7.25.jar new file mode 100644 index 0000000..a7260f3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/lib/slf4j-simple-1.7.25.jar Binary files differ
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/servlet/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/servlet/TestBean.java new file mode 100644 index 0000000..6d059e2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/servlet/TestBean.java
@@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +//Simple TestBean to test CDI. +//This bean implements Serializable as it needs to be placed into a Stateful Bean +public class TestBean +{}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/servlet/TestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/servlet/TestServlet.java new file mode 100644 index 0000000..bc1c99f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/smoke-tests/slf4j-visibility/servlet/TestServlet.java
@@ -0,0 +1,66 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.enterprise.inject.spi.BeanManager; +import javax.inject.Inject; +import javax.naming.InitialContext; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.jboss.logging.Logger; +//import org.slf4j.LoggerFactory; + +@WebServlet(name="mytest", + urlPatterns={"/myurl"}, + initParams={ @WebInitParam(name="n1", value="v1"), @WebInitParam(name="n2", value="v2") } ) +public class TestServlet extends HttpServlet { + @Inject TestBean tb; + @Inject BeanManager bm; + BeanManager bm1; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + String msg = ""; + if (tb == null) msg += "Bean injection into Servlet failed"; + if (bm == null) msg += "BeanManager Injection via @Inject failed"; + try { + bm1 = (BeanManager)((new InitialContext()).lookup("java:comp/BeanManager")); + } catch (Exception ex) { + ex.printStackTrace(); + msg += "BeanManager Injection via component environment lookup failed"; + } + if (bm1 == null) msg += "BeanManager Injection via component environment lookup failed"; + + + System.out.println("BeanManager is " + bm); + System.out.println("BeanManager via lookup is " + bm1); + + Logger l = Logger.getLogger(getClass()); + String s = "[ Hello World is logged by an instance of " + l.getClass() + ", which is loaded by " + l.getClass().getClassLoader() + "]"; + msg += s; + l.info(s); + + writer.write(msg + "\n"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/README b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/README new file mode 100644 index 0000000..e8a542b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/README
@@ -0,0 +1,5 @@ +Test +- Use of Specializes + - tests the problem with alternatives. When an alternative is enabled (either + via an alternative stereotype or explicitly) and a default bean with a qualifier exists + that there is no alternative for, the default bean is injected.
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/build.properties b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/build.properties new file mode 100644 index 0000000..8250682 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-specialization-leak-alternatives"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/build.xml b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/client/test/client/WebTest.java new file mode 100644 index 0000000..98789e4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/client/test/client/WebTest.java
@@ -0,0 +1,111 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "specialization-alternative-leaks"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for stereotypes"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/descriptor/beans.xml new file mode 100644 index 0000000..1cd96c3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/descriptor/beans.xml
@@ -0,0 +1,33 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.artifacts.TransactionInterceptor</class> + <class>test.beans.artifacts.RequiresNewTransactionInterceptor</class> + </interceptors> + <alternatives> + <stereotype>test.beans.artifacts.MockStereotype</stereotype> + </alternatives> + +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..7b4277f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void m1(); + + public void m2(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/LeakQualifier.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/LeakQualifier.java new file mode 100644 index 0000000..38fe2cb --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/LeakQualifier.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface LeakQualifier { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/MockStereotype.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/MockStereotype.java new file mode 100644 index 0000000..35fa89e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/MockStereotype.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.enterprise.inject.Alternative; + + + +@Alternative +@javax.enterprise.inject.Stereotype +@Retention(RetentionPolicy.RUNTIME) +@Target({ TYPE }) +public @interface MockStereotype { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/Preferred.java new file mode 100644 index 0000000..b7584c8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/RequiresNewTransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/RequiresNewTransactionInterceptor.java new file mode 100644 index 0000000..a10a125 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/RequiresNewTransactionInterceptor.java
@@ -0,0 +1,52 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import test.beans.nonmock.TestDependentBean; + +@Interceptor +@Transactional(requiresNew=true, rolesAllowed={"admin", "manager"}) +//the rolesAllowed value must be ignored as it s a non-binding attribute +public class RequiresNewTransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("RequiresNewTransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/TransactionInterceptor.java new file mode 100644 index 0000000..f02f31b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/TransactionInterceptor.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import test.beans.nonmock.TestDependentBean; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/Transactional.java new file mode 100644 index 0000000..79cff9b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/artifacts/Transactional.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.enterprise.util.Nonbinding; +import javax.interceptor.InterceptorBinding; + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + boolean requiresNew() default false; + @Nonbinding String[] rolesAllowed() default {}; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/mock/MockBean.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/mock/MockBean.java new file mode 100644 index 0000000..d309650 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/mock/MockBean.java
@@ -0,0 +1,43 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.mock; + +import javax.enterprise.context.RequestScoped; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.MockStereotype; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.Transactional; + +@MockStereotype +@Preferred +@RequestScoped +@Transactional +public class MockBean implements TestBeanInterface{ + public static boolean mockBeanInvoked = false; + @Override + public void m1() { + mockBeanInvoked = true; + System.out.println("MockBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("MockBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/mock/MockShoppingCart.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/mock/MockShoppingCart.java new file mode 100644 index 0000000..fd60138 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/mock/MockShoppingCart.java
@@ -0,0 +1,37 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.mock; + +import test.beans.artifacts.MockStereotype; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.Transactional; +import test.beans.nonmock.ShoppingCart; + +@Preferred +@Transactional(requiresNew=true) +@MockStereotype + +public class MockShoppingCart extends ShoppingCart{ + public static boolean mockShoppingCartInvoked = false; + + public void addItem(String s) { + mockShoppingCartInvoked = true; + System.out.println("MockShoppingCart::addItem called"); + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/nonmock/AnotherTestBeanWithLeakQualifier.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/nonmock/AnotherTestBeanWithLeakQualifier.java new file mode 100644 index 0000000..a5431cd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/nonmock/AnotherTestBeanWithLeakQualifier.java
@@ -0,0 +1,42 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import javax.enterprise.context.RequestScoped; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.LeakQualifier; +import test.beans.artifacts.Transactional; + +@Transactional +@RequestScoped +@LeakQualifier +public class AnotherTestBeanWithLeakQualifier implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/nonmock/ShoppingCart.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/nonmock/ShoppingCart.java new file mode 100644 index 0000000..5408758 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/nonmock/ShoppingCart.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import test.beans.artifacts.Preferred; +import test.beans.artifacts.Transactional; + + +@Preferred +@Transactional(requiresNew=true) +public class ShoppingCart { + public static boolean shoppingCartInvoked = false; + + public void addItem(String s) { + shoppingCartInvoked = true; + System.out.println("ShoppingCart::addItem called"); + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/nonmock/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/nonmock/TestBean.java new file mode 100644 index 0000000..d1bed8f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/nonmock/TestBean.java
@@ -0,0 +1,42 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import javax.enterprise.context.RequestScoped; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.Transactional; + +@Transactional +@RequestScoped +@Preferred +public class TestBean implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/nonmock/TestDependentBean.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/nonmock/TestDependentBean.java new file mode 100644 index 0000000..46f7f38 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/beans/nonmock/TestDependentBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +public class TestDependentBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/servlet/LeakQualifierTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/servlet/LeakQualifierTestServlet.java new file mode 100644 index 0000000..e8ea1e1 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/alternative-leaks/servlet/test/servlet/LeakQualifierTestServlet.java
@@ -0,0 +1,134 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.LeakQualifier; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.RequiresNewTransactionInterceptor; +import test.beans.artifacts.TransactionInterceptor; +import test.beans.mock.MockBean; +import test.beans.mock.MockShoppingCart; +import test.beans.nonmock.AnotherTestBeanWithLeakQualifier; +import test.beans.nonmock.ShoppingCart; +import test.beans.nonmock.TestBean; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class LeakQualifierTestServlet extends HttpServlet { + @Inject + @Preferred + TestBeanInterface tb; + + @Inject + @LeakQualifier + TestBeanInterface tb_leak; + + @Inject + @Preferred + ShoppingCart sc; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + //TestBean uses normal interceptors placed on it + if (tb == null) + msg += "Injection of request scoped bean failed"; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + if (RequiresNewTransactionInterceptor.aroundInvokeCalled) + msg += "RequiresNew TransactionInterceptor called when " + + "it shouldn't have been called"; + + //test that the mocks are called instead of the actual beans + if (TestBean.testBeanInvoked) + msg += "Test Bean invoked when actually mock bean should " + + "have been invoked"; + + if (!MockBean.mockBeanInvoked) + msg += "Mock bean not invoked"; + + TransactionInterceptor.clear(); + //invoke shopping cart bean. ShoppingCart bean uses a Stereotype to + //assign the requires new transaction interceptor + //This should result in an invocation on + //the RequiresNewTransactional + sc.addItem("Test Item"); + if (!RequiresNewTransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke in requires new " + + "transaction interceptor not called"; + if (RequiresNewTransactionInterceptor.aroundInvokeInvocationCount != 1) + msg += "Business method requires new interceptor invocation on " + + "method-level interceptor annotation count not expected. " + + "expected =1, actual=" + + RequiresNewTransactionInterceptor.aroundInvokeInvocationCount; + if (!RequiresNewTransactionInterceptor.errorMessage.trim().equals("")) + msg += RequiresNewTransactionInterceptor.errorMessage; + + //TransactionInterceptor should not be called + if (TransactionInterceptor.aroundInvokeCalled) + msg += "TranscationInterceptor aroundInvoke called when a requiresnew" + + "transaction interceptor should have been called"; + + //test that the mocks are called instead of the actual beans + if (ShoppingCart.shoppingCartInvoked) + msg += "Test shopping cart invoked when actually mock shopping cart " + + "should have been invoked"; + + if (!MockShoppingCart.mockShoppingCartInvoked) + msg += "Mock shopping cart not invoked"; + + //test AnotherTestBeanWithLeakQualifier was injected for LeakQualifier. + //There are no mocks for a LeakQualifier annotated bean and so + //the actual non-mock AnotherTestBeanWithLeakQualifier is injected + //This is the problem with Alternatives and use of Alternative Stereotypes + //and is overcome by using Specializes + if (tb_leak == null) + msg += "leak bean was not injected"; + + if (!(tb_leak instanceof AnotherTestBeanWithLeakQualifier)) + msg += "leak bean is not an instance of AnotherTestBeanWithLeakQualifier"; + + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/build.xml b/appserver/tests/appserv-tests/devtests/cdi/specialization/build.xml new file mode 100644 index 0000000..f7a2b27 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/build.xml
@@ -0,0 +1,97 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<project name="specialization-test" default="usage" basedir="."> + + <property name="specialization-target" value="all"/> + + <target name="run-test"> + <antcall target="specialization"> + <param name="specialization-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="specialization"> + <param name="specialization-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="specialization"> + <param name="specialization-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="specialization"> + <param name="specialization-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="specialization"> + <param name="specialization-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="specialization"> + <param name="specialization-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="specialization"> + <param name="specialization-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="specialization"> + <param name="specialization-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="specialization"> + <param name="specialization-target" value="run"/> + </antcall> + </target> + + <target name="specialization"> + <record name="specialization.output" action="start" /> + <ant dir="alternative-leaks" target="${specialization-target}"/> + <ant dir="specialization-simple" target="${specialization-target}"/> + <record name="specialization.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant all (Executes all the specialization tests) + ant clean (cleans all the specialization tests) + ant build (builds all the specialization tests) + ant setup (sets up all resources for specialization tests) + ant deploy (deploys all the specialization apps) + ant run (Executes all the specialization tests) + ant undeploy (undeploys all the specialization apps) + ant unsetup (unsets all resources for specialization tests) + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/README b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/README new file mode 100644 index 0000000..3743f31 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/README
@@ -0,0 +1,7 @@ +Test +- Use of Specializes + - tests that the @Specializes annotated bean (X) replaces the other bean(Y) + [ie inherits Qualifiers] in these 2 scenarios + - X extended the other bean Y and marks X as @Specializes + - XProducer overrides the producer method YProducer and markes the + XProducer's producer method as @Specializes.
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/build.properties b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/build.properties new file mode 100644 index 0000000..9a02e14 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-simple-specialization"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/build.xml b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/client/test/client/WebTest.java new file mode 100644 index 0000000..e99de54 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/client/test/client/WebTest.java
@@ -0,0 +1,111 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "specialization-simple-specialization"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for stereotypes"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/descriptor/beans.xml new file mode 100644 index 0000000..1cd96c3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/descriptor/beans.xml
@@ -0,0 +1,33 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.artifacts.TransactionInterceptor</class> + <class>test.beans.artifacts.RequiresNewTransactionInterceptor</class> + </interceptors> + <alternatives> + <stereotype>test.beans.artifacts.MockStereotype</stereotype> + </alternatives> + +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..7b4277f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void m1(); + + public void m2(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/AnotherQualifier.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/AnotherQualifier.java new file mode 100644 index 0000000..3b7f763 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/AnotherQualifier.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface AnotherQualifier { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/MockStereotype.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/MockStereotype.java new file mode 100644 index 0000000..35fa89e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/MockStereotype.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.enterprise.inject.Alternative; + + + +@Alternative +@javax.enterprise.inject.Stereotype +@Retention(RetentionPolicy.RUNTIME) +@Target({ TYPE }) +public @interface MockStereotype { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/Preferred.java new file mode 100644 index 0000000..b7584c8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/RequiresNewTransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/RequiresNewTransactionInterceptor.java new file mode 100644 index 0000000..a10a125 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/RequiresNewTransactionInterceptor.java
@@ -0,0 +1,52 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import test.beans.nonmock.TestDependentBean; + +@Interceptor +@Transactional(requiresNew=true, rolesAllowed={"admin", "manager"}) +//the rolesAllowed value must be ignored as it s a non-binding attribute +public class RequiresNewTransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("RequiresNewTransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/TransactionInterceptor.java new file mode 100644 index 0000000..f02f31b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/TransactionInterceptor.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import test.beans.nonmock.TestDependentBean; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/Transactional.java new file mode 100644 index 0000000..79cff9b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/artifacts/Transactional.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.enterprise.util.Nonbinding; +import javax.interceptor.InterceptorBinding; + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + boolean requiresNew() default false; + @Nonbinding String[] rolesAllowed() default {}; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/mock/MockAnotherQualifierProducer.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/mock/MockAnotherQualifierProducer.java new file mode 100644 index 0000000..dd4d273 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/mock/MockAnotherQualifierProducer.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.mock; + + +import javax.enterprise.inject.Produces; +import javax.enterprise.inject.Specializes; + +import test.beans.TestBeanInterface; +import test.beans.nonmock.AnotherQualifierProducer; +import test.beans.nonmock.TestBeanForAnotherQualifier; + +public class MockAnotherQualifierProducer extends AnotherQualifierProducer{ + @Produces @Specializes + //We don't specify AnotherQualifier here. It is inherited from + //AnotherQualifierProducer.getTestBeanWithAnotherQualifier + //because of the @Specializes annotation + protected TestBeanInterface getTestBeanWithAnotherQualifier() { + return new MockTestBeanForAnotherQualifier(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/mock/MockBean.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/mock/MockBean.java new file mode 100644 index 0000000..d309650 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/mock/MockBean.java
@@ -0,0 +1,43 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.mock; + +import javax.enterprise.context.RequestScoped; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.MockStereotype; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.Transactional; + +@MockStereotype +@Preferred +@RequestScoped +@Transactional +public class MockBean implements TestBeanInterface{ + public static boolean mockBeanInvoked = false; + @Override + public void m1() { + mockBeanInvoked = true; + System.out.println("MockBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("MockBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/mock/MockShoppingCart.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/mock/MockShoppingCart.java new file mode 100644 index 0000000..0e2c7c2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/mock/MockShoppingCart.java
@@ -0,0 +1,43 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.mock; + +import javax.enterprise.inject.Specializes; + +import test.beans.artifacts.MockStereotype; +import test.beans.artifacts.Transactional; +import test.beans.nonmock.ShoppingCart; + + +@MockStereotype +@Specializes +@Transactional(requiresNew=true) +//This alternative (via MockStereotype) does not specify Preferred +//qualifier, but since it specializes ShoppingCart, it +//gets ShoppingCart's qualifers etc +//Interceptors are not inherited and so we need to specify Transactional +//explicitly +public class MockShoppingCart extends ShoppingCart{ + public static boolean mockShoppingCartInvoked = false; + + public void addItem(String s) { + mockShoppingCartInvoked = true; + System.out.println("MockShoppingCart::addItem called"); + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/mock/MockTestBeanForAnotherQualifier.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/mock/MockTestBeanForAnotherQualifier.java new file mode 100644 index 0000000..d1ca5fd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/mock/MockTestBeanForAnotherQualifier.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.mock; + +import test.beans.TestBeanInterface; + +public class MockTestBeanForAnotherQualifier implements TestBeanInterface{ + public static boolean mockBeanInvoked = false; + @Override + public void m1() { + mockBeanInvoked = true; + System.out.println("MockBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("MockBean::m2 called"); + } + + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/nonmock/AnotherQualifierProducer.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/nonmock/AnotherQualifierProducer.java new file mode 100644 index 0000000..cd8d502 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/nonmock/AnotherQualifierProducer.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import javax.enterprise.inject.Produces; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.AnotherQualifier; + +public class AnotherQualifierProducer { + @Produces @AnotherQualifier + protected TestBeanInterface getTestBeanWithAnotherQualifier() { + return new TestBeanForAnotherQualifier(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/nonmock/ShoppingCart.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/nonmock/ShoppingCart.java new file mode 100644 index 0000000..8ecf56f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/nonmock/ShoppingCart.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import test.beans.artifacts.Preferred; +import test.beans.artifacts.Transactional; + + +@Preferred //This qualifier would be inherited by a @Specializes sub-class. +@Transactional(requiresNew=true) +public class ShoppingCart { + public static boolean shoppingCartInvoked = false; + + public void addItem(String s) { + shoppingCartInvoked = true; + System.out.println("ShoppingCart::addItem called"); + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/nonmock/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/nonmock/TestBean.java new file mode 100644 index 0000000..d1bed8f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/nonmock/TestBean.java
@@ -0,0 +1,42 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import javax.enterprise.context.RequestScoped; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.Transactional; + +@Transactional +@RequestScoped +@Preferred +public class TestBean implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/nonmock/TestBeanForAnotherQualifier.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/nonmock/TestBeanForAnotherQualifier.java new file mode 100644 index 0000000..dc9928f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/nonmock/TestBeanForAnotherQualifier.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import test.beans.TestBeanInterface; + +public class TestBeanForAnotherQualifier implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/nonmock/TestDependentBean.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/nonmock/TestDependentBean.java new file mode 100644 index 0000000..46f7f38 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/beans/nonmock/TestDependentBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +public class TestDependentBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/servlet/SimpleSpecializationTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/servlet/SimpleSpecializationTestServlet.java new file mode 100644 index 0000000..3605c52 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/specialization/specialization-simple/servlet/test/servlet/SimpleSpecializationTestServlet.java
@@ -0,0 +1,137 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.AnotherQualifier; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.RequiresNewTransactionInterceptor; +import test.beans.artifacts.TransactionInterceptor; +import test.beans.mock.MockBean; +import test.beans.mock.MockShoppingCart; +import test.beans.mock.MockTestBeanForAnotherQualifier; +import test.beans.nonmock.ShoppingCart; +import test.beans.nonmock.TestBean; +import test.beans.nonmock.TestBeanForAnotherQualifier; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class SimpleSpecializationTestServlet extends HttpServlet { + @Inject + @Preferred + TestBeanInterface tb; + + @Inject + @AnotherQualifier + TestBeanInterface tb_another; + + @Inject + @Preferred + ShoppingCart sc; + + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + //TestBean uses normal interceptors placed on it + if (tb == null) + msg += "Injection of request scoped bean failed"; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + if (RequiresNewTransactionInterceptor.aroundInvokeCalled) + msg += "RequiresNew TransactionInterceptor called when " + + "it shouldn't have been called"; + + if (TestBean.testBeanInvoked) + msg += "Test Bean invoked when actually mock bean should " + + "have been invoked"; + + if (!MockBean.mockBeanInvoked) + msg += "Mock bean not invoked"; + + TransactionInterceptor.clear(); + //invoke shopping cart bean. ShoppingCart bean uses a Stereotype to + //assign the requires new transaction interceptor + //This should result in an invocation on + //the RequiresNewTransactional + + //check that the mock shopping cart bean inherits the qualifiers when the alternative + //bean extends the actual bean and uses @Specializes to inherit the + //Qualifier + + sc.addItem("Test Item"); + if (!RequiresNewTransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke in requires new " + + "transaction interceptor not called"; + if (RequiresNewTransactionInterceptor.aroundInvokeInvocationCount != 1) + msg += "Business method requires new interceptor invocation on " + + "method-level interceptor annotation count not expected. " + + "expected =1, actual=" + + RequiresNewTransactionInterceptor.aroundInvokeInvocationCount; + if (!RequiresNewTransactionInterceptor.errorMessage.trim().equals("")) + msg += RequiresNewTransactionInterceptor.errorMessage; + + //TransactionInterceptor should not be called + if (TransactionInterceptor.aroundInvokeCalled) + msg += "TranscationInterceptor aroundInvoke called when a requiresnew" + + "transaction interceptor should have been called"; + + //test that the mocks are called instead of the actual beans + if (ShoppingCart.shoppingCartInvoked) + msg += "Test shopping cart invoked when actually mock shopping cart " + + "should have been invoked"; + + if (!MockShoppingCart.mockShoppingCartInvoked) + msg += "Mock shopping cart not invoked"; + + //check that the mock bean inherits the qualifiers when the bean is + //produced through a Specializes producer method + if (tb_another == null) + msg += " bean with another qualifier was not injected"; + + if (!(tb_another instanceof MockTestBeanForAnotherQualifier)) + msg += "bean with another qualifier is not an instance of TestBeanWithAnotherQualifier"; + + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/README b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/README new file mode 100644 index 0000000..d675197 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/README
@@ -0,0 +1,3 @@ +Test +- Use of Stereotypes + - stereotype to indicate that all the beans it is applied to are @Alternatives
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/build.properties b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/build.properties new file mode 100644 index 0000000..73652ed --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-alternative-stereotypes"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/build.xml b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/client/test/client/WebTest.java new file mode 100644 index 0000000..26a1de5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/client/test/client/WebTest.java
@@ -0,0 +1,111 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "stereotypes-alternative-stereotypes"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for stereotypes"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/descriptor/beans.xml new file mode 100644 index 0000000..1cd96c3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/descriptor/beans.xml
@@ -0,0 +1,33 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.artifacts.TransactionInterceptor</class> + <class>test.beans.artifacts.RequiresNewTransactionInterceptor</class> + </interceptors> + <alternatives> + <stereotype>test.beans.artifacts.MockStereotype</stereotype> + </alternatives> + +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..7b4277f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void m1(); + + public void m2(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/artifacts/MockStereotype.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/artifacts/MockStereotype.java new file mode 100644 index 0000000..35fa89e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/artifacts/MockStereotype.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.enterprise.inject.Alternative; + + + +@Alternative +@javax.enterprise.inject.Stereotype +@Retention(RetentionPolicy.RUNTIME) +@Target({ TYPE }) +public @interface MockStereotype { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/artifacts/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/artifacts/Preferred.java new file mode 100644 index 0000000..b7584c8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/artifacts/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/artifacts/RequiresNewTransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/artifacts/RequiresNewTransactionInterceptor.java new file mode 100644 index 0000000..a10a125 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/artifacts/RequiresNewTransactionInterceptor.java
@@ -0,0 +1,52 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import test.beans.nonmock.TestDependentBean; + +@Interceptor +@Transactional(requiresNew=true, rolesAllowed={"admin", "manager"}) +//the rolesAllowed value must be ignored as it s a non-binding attribute +public class RequiresNewTransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("RequiresNewTransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/artifacts/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/artifacts/TransactionInterceptor.java new file mode 100644 index 0000000..f02f31b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/artifacts/TransactionInterceptor.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import test.beans.nonmock.TestDependentBean; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/artifacts/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/artifacts/Transactional.java new file mode 100644 index 0000000..79cff9b --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/artifacts/Transactional.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.artifacts; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.enterprise.util.Nonbinding; +import javax.interceptor.InterceptorBinding; + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + boolean requiresNew() default false; + @Nonbinding String[] rolesAllowed() default {}; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/mock/MockBean.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/mock/MockBean.java new file mode 100644 index 0000000..d309650 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/mock/MockBean.java
@@ -0,0 +1,43 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.mock; + +import javax.enterprise.context.RequestScoped; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.MockStereotype; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.Transactional; + +@MockStereotype +@Preferred +@RequestScoped +@Transactional +public class MockBean implements TestBeanInterface{ + public static boolean mockBeanInvoked = false; + @Override + public void m1() { + mockBeanInvoked = true; + System.out.println("MockBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("MockBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/mock/MockShoppingCart.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/mock/MockShoppingCart.java new file mode 100644 index 0000000..fd60138 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/mock/MockShoppingCart.java
@@ -0,0 +1,37 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.mock; + +import test.beans.artifacts.MockStereotype; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.Transactional; +import test.beans.nonmock.ShoppingCart; + +@Preferred +@Transactional(requiresNew=true) +@MockStereotype + +public class MockShoppingCart extends ShoppingCart{ + public static boolean mockShoppingCartInvoked = false; + + public void addItem(String s) { + mockShoppingCartInvoked = true; + System.out.println("MockShoppingCart::addItem called"); + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/nonmock/ShoppingCart.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/nonmock/ShoppingCart.java new file mode 100644 index 0000000..5408758 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/nonmock/ShoppingCart.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import test.beans.artifacts.Preferred; +import test.beans.artifacts.Transactional; + + +@Preferred +@Transactional(requiresNew=true) +public class ShoppingCart { + public static boolean shoppingCartInvoked = false; + + public void addItem(String s) { + shoppingCartInvoked = true; + System.out.println("ShoppingCart::addItem called"); + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/nonmock/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/nonmock/TestBean.java new file mode 100644 index 0000000..d1bed8f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/nonmock/TestBean.java
@@ -0,0 +1,42 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +import javax.enterprise.context.RequestScoped; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.Transactional; + +@Transactional +@RequestScoped +@Preferred +public class TestBean implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/nonmock/TestDependentBean.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/nonmock/TestDependentBean.java new file mode 100644 index 0000000..46f7f38 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/beans/nonmock/TestDependentBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.nonmock; + +public class TestDependentBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/servlet/AlternativeStereotypesTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/servlet/AlternativeStereotypesTestServlet.java new file mode 100644 index 0000000..6903b0d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/alternative-stereotypes/servlet/test/servlet/AlternativeStereotypesTestServlet.java
@@ -0,0 +1,116 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestBeanInterface; +import test.beans.artifacts.Preferred; +import test.beans.artifacts.RequiresNewTransactionInterceptor; +import test.beans.artifacts.TransactionInterceptor; +import test.beans.mock.MockBean; +import test.beans.mock.MockShoppingCart; +import test.beans.nonmock.ShoppingCart; +import test.beans.nonmock.TestBean; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class AlternativeStereotypesTestServlet extends HttpServlet { + @Inject + @Preferred + TestBeanInterface tb; + + @Inject + @Preferred + ShoppingCart sc; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + //TestBean uses normal interceptors placed on it + if (tb == null) + msg += "Injection of request scoped bean failed"; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + if (RequiresNewTransactionInterceptor.aroundInvokeCalled) + msg += "RequiresNew TransactionInterceptor called when " + + "it shouldn't have been called"; + + //test that the mocks are called instead of the actual beans + if (TestBean.testBeanInvoked) + msg += "Test Bean invoked when actually mock bean should " + + "have been invoked"; + + if (!MockBean.mockBeanInvoked) + msg += "Mock bean not invoked"; + + TransactionInterceptor.clear(); + //invoke shopping cart bean. ShoppingCart bean uses a Stereotype to + //assign the requires new transaction interceptor + //This should result in an invocation on + //the RequiresNewTransactional + sc.addItem("Test Item"); + if (!RequiresNewTransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke in requires new " + + "transaction interceptor not called"; + if (RequiresNewTransactionInterceptor.aroundInvokeInvocationCount != 1) + msg += "Business method requires new interceptor invocation on " + + "method-level interceptor annotation count not expected. " + + "expected =1, actual=" + + RequiresNewTransactionInterceptor.aroundInvokeInvocationCount; + if (!RequiresNewTransactionInterceptor.errorMessage.trim().equals("")) + msg += RequiresNewTransactionInterceptor.errorMessage; + + //TransactionInterceptor should not be called + if (TransactionInterceptor.aroundInvokeCalled) + msg += "TranscationInterceptor aroundInvoke called when a requiresnew" + + "transaction interceptor should have been called"; + + //test that the mocks are called instead of the actual beans + if (ShoppingCart.shoppingCartInvoked) + msg += "Test shopping cart invoked when actually mock shopping cart " + + "should have been invoked"; + + if (!MockShoppingCart.mockShoppingCartInvoked) + msg += "Mock shopping cart not invoked"; + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/build.xml b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/build.xml new file mode 100644 index 0000000..e06f8e7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/build.xml
@@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<project name="stereotypes-test" default="usage" basedir="."> + + <property name="stereotypes-target" value="all"/> + + <target name="run-test"> + <antcall target="stereotypes"> + <param name="stereotypes-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="stereotypes"> + <param name="stereotypes-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="stereotypes"> + <param name="stereotypes-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="stereotypes"> + <param name="stereotypes-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="stereotypes"> + <param name="stereotypes-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="stereotypes"> + <param name="stereotypes-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="stereotypes"> + <param name="stereotypes-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="stereotypes"> + <param name="stereotypes-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="stereotypes"> + <param name="stereotypes-target" value="run"/> + </antcall> + </target> + + <target name="stereotypes"> + <record name="stereotypes.output" action="start" /> + <ant dir="alternative-stereotypes" target="${stereotypes-target}"/> + <ant dir="interceptor-bindings-for-stereotypes" target="${stereotypes-target}"/> + <ant dir="stereotype-stacking" target="${stereotypes-target}"/> + <record name="stereotypes.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant all (Executes all the stereotypes tests) + ant clean (cleans all the stereotypes tests) + ant build (builds all the stereotypes tests) + ant setup (sets up all resources for stereotypes tests) + ant deploy (deploys all the stereotypes apps) + ant run (Executes all the stereotypes tests) + ant undeploy (undeploys all the stereotypes apps) + ant unsetup (unsets all resources for stereotypes tests) + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/README b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/README new file mode 100644 index 0000000..436f3cf --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/README
@@ -0,0 +1,4 @@ +Test +- Use of stereotypes + - specifying interceptor bindings in a Stereotype + to be inherited by all beans with that Stereotype
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/build.properties b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/build.properties new file mode 100644 index 0000000..6f7f81c --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-interceptor-binding-for-stereotypes"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/build.xml b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/client/test/client/WebTest.java new file mode 100644 index 0000000..f99cc54 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/client/test/client/WebTest.java
@@ -0,0 +1,111 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "stereotypes-interceptor-bindings-for-stereotypes"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for stereotypes"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/descriptor/beans.xml new file mode 100644 index 0000000..6e5b6a2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/descriptor/beans.xml
@@ -0,0 +1,30 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.TransactionInterceptor</class> + <class>test.beans.RequiresNewTransactionInterceptor</class> + </interceptors> + +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/ActionStereotype.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/ActionStereotype.java new file mode 100644 index 0000000..1e49019 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/ActionStereotype.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.enterprise.context.RequestScoped; + + + +@javax.enterprise.inject.Stereotype +@RequestScoped +@Transactional(requiresNew=true) +@Retention(RetentionPolicy.RUNTIME) +@Target({ TYPE }) +public @interface ActionStereotype { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/Preferred.java new file mode 100644 index 0000000..fa8fdb7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/RequiresNewTransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/RequiresNewTransactionInterceptor.java new file mode 100644 index 0000000..73f5964 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/RequiresNewTransactionInterceptor.java
@@ -0,0 +1,50 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Interceptor +@Transactional(requiresNew=true, rolesAllowed={"admin", "manager"}) +//the rolesAllowed value must be ignored as it s a non-binding attribute +public class RequiresNewTransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("RequiresNewTransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/ShoppingCart.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/ShoppingCart.java new file mode 100644 index 0000000..6175fd6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/ShoppingCart.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + + +@ActionStereotype +@Preferred +public class ShoppingCart { + + public void addItem(String s) { + System.out.println("ShoppingCart::addItem called"); + + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/TestBean.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/TestBean.java new file mode 100644 index 0000000..4792d26 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/TestBean.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +@Transactional +@RequestScoped +@Preferred +public class TestBean { + + public void m1() { + System.out.println("TestBean::m1 called"); + } + + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/TestDependentBean.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/TestDependentBean.java new file mode 100644 index 0000000..38e4f18 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/TestDependentBean.java
@@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + + +public class TestDependentBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/TransactionInterceptor.java new file mode 100644 index 0000000..f762992 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/TransactionInterceptor.java
@@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/Transactional.java new file mode 100644 index 0000000..b8937b9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/beans/Transactional.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.enterprise.util.Nonbinding; +import javax.interceptor.InterceptorBinding; + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { + boolean requiresNew() default false; + @Nonbinding String[] rolesAllowed() default {}; +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/servlet/InterceptorBindingsForStereotypesTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/servlet/InterceptorBindingsForStereotypesTestServlet.java new file mode 100644 index 0000000..3e739ff --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/interceptor-bindings-for-stereotypes/servlet/test/servlet/InterceptorBindingsForStereotypesTestServlet.java
@@ -0,0 +1,97 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.Preferred; +import test.beans.RequiresNewTransactionInterceptor; +import test.beans.ShoppingCart; +import test.beans.TestBean; +import test.beans.TransactionInterceptor; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class InterceptorBindingsForStereotypesTestServlet extends HttpServlet { + @Inject + @Preferred + TestBean tb; + + @Inject + @Preferred + ShoppingCart sc; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + //TestBean uses normal interceptors placed on it + if (tb == null) + msg += "Injection of request scoped bean failed"; + + tb.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + if (RequiresNewTransactionInterceptor.aroundInvokeCalled) + msg += "RequiresNew TransactionInterceptor called when " + + "it shouldn't have been called"; + + TransactionInterceptor.clear(); + //invoke shopping cart bean. ShoppingCart bean uses a Stereotype to + //assign the requires new transaction interceptor + //This should result in an invocation on + //the RequiresNewTransactional + sc.addItem("Test Item"); + if (!RequiresNewTransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke in requires new " + + "transaction interceptor not called"; + if (RequiresNewTransactionInterceptor.aroundInvokeInvocationCount != 1) + msg += "Business method requires new interceptor invocation on " + + "method-level interceptor annotation count not expected. " + + "expected =1, actual=" + + RequiresNewTransactionInterceptor.aroundInvokeInvocationCount; + if (!RequiresNewTransactionInterceptor.errorMessage.trim().equals("")) + msg += RequiresNewTransactionInterceptor.errorMessage; + + //TransactionInterceptor should not be called + if (TransactionInterceptor.aroundInvokeCalled) + msg += "TranscationInterceptor aroundInvoke called when a requiresnew" + + "transaction interceptor should have been called"; + + writer.write(msg + "\n"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/README b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/README new file mode 100644 index 0000000..5682976 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/README
@@ -0,0 +1,3 @@ +Test +- Use of Stereotypes + - stereotypes may declare other stereotypes [stacking] \ No newline at end of file
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/build.properties b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/build.properties new file mode 100644 index 0000000..e8e6008 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-stacking-stereotypes"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/build.xml b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/build.xml new file mode 100644 index 0000000..0b9b3a3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/build.xml
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="client"/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/client/test/client/WebTest.java new file mode 100644 index 0000000..3080ce5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/client/test/client/WebTest.java
@@ -0,0 +1,111 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter( + "appserv-tests"); + private static final String TEST_NAME = "stereotypes-stereotype-stacking"; + + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0."; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Unit test for stereotypes"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)) + .openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/descriptor/beans.xml new file mode 100644 index 0000000..33b2aa7 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/descriptor/beans.xml
@@ -0,0 +1,29 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <interceptors> + <class>test.beans.interceptors.TransactionInterceptor</class> + <class>test.beans.interceptors.SecurityInterceptor</class> + </interceptors> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/TestBeanInterface.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/TestBeanInterface.java new file mode 100644 index 0000000..7b4277f --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/TestBeanInterface.java
@@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public interface TestBeanInterface { + public void m1(); + + public void m2(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/TestDependentBean.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/TestDependentBean.java new file mode 100644 index 0000000..1c15313 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/TestDependentBean.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +public class TestDependentBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/TestSecureBean.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/TestSecureBean.java new file mode 100644 index 0000000..a127308 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/TestSecureBean.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +import test.beans.qualifiers.Preferred; +import test.beans.stereotypes.SecStereotype; + +@SecStereotype +@RequestScoped +@Preferred +public class TestSecureBean implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/TestTxBean.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/TestTxBean.java new file mode 100644 index 0000000..9af2f53 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/TestTxBean.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +import test.beans.qualifiers.Preferred; +import test.beans.stereotypes.TxStereotype; + +@TxStereotype +@RequestScoped +@Preferred +public class TestTxBean implements TestBeanInterface{ + public static boolean testBeanInvoked = false; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/TestTxSecBean.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/TestTxSecBean.java new file mode 100644 index 0000000..cb70ad3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/TestTxSecBean.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.context.RequestScoped; + +import test.beans.qualifiers.Preferred; +import test.beans.stereotypes.TxSecureStereotype; + +@TxSecureStereotype +@RequestScoped +@Preferred +public class TestTxSecBean implements TestBeanInterface { + public static boolean testBeanInvoked = false; + + @Override + public void m1() { + testBeanInvoked = true; + System.out.println("TestBean::m1 called"); + } + + @Override + public void m2() { + System.out.println("TestBean::m2 called"); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/interceptors/Secure.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/interceptors/Secure.java new file mode 100644 index 0000000..187d737 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/interceptors/Secure.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.interceptors; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; +import javax.interceptor.InterceptorBinding; + + +@Target({ TYPE, METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Secure { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/interceptors/SecurityInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/interceptors/SecurityInterceptor.java new file mode 100644 index 0000000..629ecb2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/interceptors/SecurityInterceptor.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.interceptors; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import test.beans.TestDependentBean; + +@Interceptor +@Secure +public class SecurityInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("SecurityInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/interceptors/TransactionInterceptor.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/interceptors/TransactionInterceptor.java new file mode 100644 index 0000000..9380dd8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/interceptors/TransactionInterceptor.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.interceptors; + +import javax.inject.Inject; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import test.beans.TestDependentBean; + +@Interceptor +@Transactional +public class TransactionInterceptor { + public static boolean aroundInvokeCalled = false; + public static int aroundInvokeInvocationCount = 0; + public static String errorMessage = ""; + + @Inject + TestDependentBean tb; + + @AroundInvoke + public Object manageTransaction(InvocationContext ctx) throws Exception { + System.out.println("TransactionInterceptor::AroundInvoke"); + if (tb == null) errorMessage="Dependency Injection " + + "into TransactionInterceptor failed"; + aroundInvokeCalled = true; + aroundInvokeInvocationCount ++; + return ctx.proceed(); + } + + public static void clear() { + aroundInvokeCalled = false; + aroundInvokeInvocationCount = 0; + errorMessage = ""; + } + }
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/interceptors/Transactional.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/interceptors/Transactional.java new file mode 100644 index 0000000..f5b9db3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/interceptors/Transactional.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.interceptors; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.interceptor.InterceptorBinding; + +@Target({TYPE, METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@InterceptorBinding +public @interface Transactional { +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/qualifiers/Preferred.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/qualifiers/Preferred.java new file mode 100644 index 0000000..a839658 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/qualifiers/Preferred.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.qualifiers; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Preferred { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/stereotypes/SecStereotype.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/stereotypes/SecStereotype.java new file mode 100644 index 0000000..9738f58 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/stereotypes/SecStereotype.java
@@ -0,0 +1,33 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.stereotypes; + +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import test.beans.interceptors.Secure; + +@javax.enterprise.inject.Stereotype +@Retention(RetentionPolicy.RUNTIME) +@Target({ TYPE }) +@Secure +public @interface SecStereotype { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/stereotypes/TxSecureStereotype.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/stereotypes/TxSecureStereotype.java new file mode 100644 index 0000000..89f0ccd --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/stereotypes/TxSecureStereotype.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.stereotypes; + +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@TxStereotype +@SecStereotype +@javax.enterprise.inject.Stereotype +@Retention(RetentionPolicy.RUNTIME) +@Target({ TYPE }) +public @interface TxSecureStereotype { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/stereotypes/TxStereotype.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/stereotypes/TxStereotype.java new file mode 100644 index 0000000..0f6fb1e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/beans/stereotypes/TxStereotype.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans.stereotypes; + +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import test.beans.interceptors.Transactional; + + +@javax.enterprise.inject.Stereotype +@Retention(RetentionPolicy.RUNTIME) +@Target({ TYPE }) +@Transactional +public @interface TxStereotype { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/servlet/StereotypeStackingTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/servlet/StereotypeStackingTestServlet.java new file mode 100644 index 0000000..953c845 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/stereotypes/stereotype-stacking/servlet/test/servlet/StereotypeStackingTestServlet.java
@@ -0,0 +1,142 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.beans.TestSecureBean; +import test.beans.TestTxBean; +import test.beans.TestTxSecBean; +import test.beans.interceptors.SecurityInterceptor; +import test.beans.interceptors.TransactionInterceptor; +import test.beans.qualifiers.Preferred; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }) +public class StereotypeStackingTestServlet extends HttpServlet { + @Inject + @Preferred + TestTxBean tb_tx; + + @Inject + @Preferred + TestSecureBean tb_sec; + + @Inject + @Preferred + TestTxSecBean tb_tx_sec; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0."); + String msg = ""; + + // Just Transactional Interceptor + if (tb_tx == null) + msg += "Injection of transactional bean failed"; + + tb_tx.m1(); + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb_tx.m2(); + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor [TransactionInterceptor] " + + "invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + if (SecurityInterceptor.aroundInvokeCalled) + msg += "Security Interceptor called when " + + "it shouldn't have been called"; + + clearInterceptors(); + + //Just security interceptor + if (tb_sec == null) + msg += "Injection of @secure bean failed"; + + tb_sec.m1(); + if (!SecurityInterceptor.aroundInvokeCalled) + msg += "Business method interceptor aroundInvoke not called"; + tb_sec.m2(); + if (SecurityInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation [SecurityInterceptor]" + + "on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + SecurityInterceptor.aroundInvokeInvocationCount; + if (!SecurityInterceptor.errorMessage.trim().equals("")) + msg += SecurityInterceptor.errorMessage; + + if (TransactionInterceptor.aroundInvokeCalled) + msg += "Security Interceptor called when " + + "it shouldn't have been called"; + + clearInterceptors(); + + //Both transaction and security interceptors + if (tb_tx_sec == null) + msg += "Injection of @transactional and @secure bean failed"; + + tb_tx_sec.m1(); + if (!SecurityInterceptor.aroundInvokeCalled) + msg += "Business method interceptor [Security Interceptor] aroundInvoke not called"; + if (!TransactionInterceptor.aroundInvokeCalled) + msg += "Business method interceptor [Transaction Interceptor] aroundInvoke not called"; + + tb_tx_sec.m2(); + if (SecurityInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor invocation [SecurityInterceptor]" + + "on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + SecurityInterceptor.aroundInvokeInvocationCount; + if (TransactionInterceptor.aroundInvokeInvocationCount != 2) + msg += "Business method interceptor [TransactionInterceptor] " + + "invocation on method-level " + + "interceptor annotation count not expected. " + + "expected =2, actual=" + + TransactionInterceptor.aroundInvokeInvocationCount; + + if (!SecurityInterceptor.errorMessage.trim().equals("")) + msg += SecurityInterceptor.errorMessage; + if (!TransactionInterceptor.errorMessage.trim().equals("")) + msg += TransactionInterceptor.errorMessage; + + + writer.write(msg + "\n"); + } + + private void clearInterceptors() { + //clear interceptors + TransactionInterceptor.clear(); + SecurityInterceptor.clear(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/todo.txt b/appserver/tests/appserv-tests/devtests/cdi/todo.txt new file mode 100644 index 0000000..e82d479 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/todo.txt
@@ -0,0 +1,10 @@ +- Emebeddable EJB container: beans deployed wherever EJBs are deployed +- Transactional observers (JPA) - 11.7 +- Use @Model in a JSF application -- 12.6 +- test inheritance of @Named in the specialized alternative bean +- test injection of JMS topics, JavaMail sessions, Connector resources, Remote EJBs and web-services -- 14.1 +- portable extensions: registering a bean (16.6), wrapping an annotated type (16.7), wrapping an injectiontarget (16.8), context interface +- use of CDI in embedded (refer issue 12658 for usecase) +- automated stress test (memory leaks and permgen issues) by deploy-use-undeploy of WicketExamples.war referred to in 11668 +- automate test in http://java.net/jira/browse/GLASSFISH-11825 +
diff --git a/appserver/tests/appserv-tests/devtests/cdi/transactions/build.xml b/appserver/tests/appserv-tests/devtests/cdi/transactions/build.xml new file mode 100644 index 0000000..1524529 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/transactions/build.xml
@@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<project name="transactions-test" default="usage" basedir="."> + + <property name="transactions-target" value="all"/> + + <target name="run-test"> + <antcall target="transactions"> + <param name="transactions-target" value="run-test"/> + </antcall> + </target> + + <target name="all"> + <antcall target="transactions"> + <param name="transactions-target" value="all"/> + </antcall> + </target> + + <target name="clean"> + <antcall target="transactions"> + <param name="transactions-target" value="clean"/> + </antcall> + </target> + + <target name="build"> + <antcall target="transactions"> + <param name="transactions-target" value="build"/> + </antcall> + </target> + + <target name="setup"> + <antcall target="transactions"> + <param name="transactions-target" value="setup"/> + </antcall> + </target> + + <target name="deploy"> + <antcall target="transactions"> + <param name="transactions-target" value="deploy"/> + </antcall> + </target> + + <target name="undeploy"> + <antcall target="transactions"> + <param name="transactions-target" value="undeploy"/> + </antcall> + </target> + + <target name="unsetup"> + <antcall target="transactions"> + <param name="transactions-target" value="unsetup"/> + </antcall> + </target> + + <target name="run"> + <antcall target="transactions"> + <param name="transactions-target" value="run"/> + </antcall> + </target> + + <target name="transactions"> + <record name="transactions.output" action="start" /> + <ant dir="transaction-scoped" target="${transactions-target}"/> + <record name="transactions.output" action="stop" /> + </target> + + <target name="usage"> + <echo> Usage: + ant all (Executes all the transactions tests) + ant clean (cleans all the transactions tests) + ant build (builds all the transactions tests) + ant setup (sets up all resources for transactions tests) + ant deploy (deploys all the transactions apps) + ant run (Executes all the transactions tests) + ant undeploy (undeploys all the transactions apps) + ant unsetup (unsets all resources for transactions tests) + </echo> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/README b/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/README new file mode 100644 index 0000000..14ad13d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/README
@@ -0,0 +1,6 @@ +Test +- Testing @TransactionScoped support + - Annotate multiple beans with @TransactionScoped + - Inject those beans + - Verify identical type of bean is shared within same transaction. + - Verify beans destroyed at end of transaction.
diff --git a/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/build.properties b/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/build.properties new file mode 100644 index 0000000..3719e49 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi"/> +<property name="appname" value="${module}-transaction-scoped"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/build.xml b/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/build.xml new file mode 100644 index 0000000..380dee5 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/build.xml
@@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ + <!ENTITY commonSetup SYSTEM "./../../../../config/properties.xml"> + <!ENTITY commonBuild SYSTEM "./../../../../config/common.xml"> + <!ENTITY run SYSTEM "./../../../../config/run.xml"> + <!ENTITY testproperties SYSTEM "./build.properties"> + ]> + +<project name="transactions_transaction-scoped_devtest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + <fileset dir="client/test/client" includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="client" + classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="test/client/WebTest.java" + debug="true"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="test.client.WebTest" fork="true"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reporter.jar"/> + <pathelement location="client"/> + </classpath> + <!--<jvmarg value="-Xdebug"/>--> + <!--<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"/>--> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/client/test/client/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/client/test/client/WebTest.java new file mode 100644 index 0000000..52e1c74 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/client/test/client/WebTest.java
@@ -0,0 +1,103 @@ +/* + * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.client; + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "transaction-scoped-transactions"; + + private static final String EXPECTED_RESPONSE = "@TransactionScoped Test"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Functional test for @TransactionScoped"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + "/TransactionScopedTestServlet"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) (new URL(url)).openConnection(); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/descriptor/beans.xml new file mode 100644 index 0000000..1d355f8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/descriptor/beans.xml
@@ -0,0 +1,25 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/servlet/test/beans/Bean1.java b/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/servlet/test/beans/Bean1.java new file mode 100644 index 0000000..e0a1268 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/servlet/test/beans/Bean1.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import test.servlet.TransactionScopedTestServlet; + +import javax.annotation.PreDestroy; +import javax.transaction.TransactionScoped; +import java.io.Serializable; + +@TransactionScoped +public class Bean1 implements Serializable { + public String foo() { + return this + ".foo()"; + } + + @PreDestroy + public void preDestroy() { + TransactionScopedTestServlet.bean1PreDestroyCalled = true; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/servlet/test/beans/Bean2.java b/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/servlet/test/beans/Bean2.java new file mode 100644 index 0000000..1fd6b19 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/servlet/test/beans/Bean2.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import test.servlet.TransactionScopedTestServlet; + +import javax.annotation.PreDestroy; +import javax.enterprise.inject.spi.PassivationCapable; +import javax.transaction.TransactionScoped; +import java.io.Serializable; + +@TransactionScoped +public class Bean2 implements PassivationCapable, Serializable { + public String foo() { + return this + ".foo()"; + } + + @PreDestroy + public void preDestroy() { + TransactionScopedTestServlet.bean2PreDestroyCalled = true; + } + + @Override + public String getId() { + return "" + this; + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/servlet/test/servlet/TransactionScopedTestServlet.java b/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/servlet/test/servlet/TransactionScopedTestServlet.java new file mode 100644 index 0000000..15c0da8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/transactions/transaction-scoped/servlet/test/servlet/TransactionScopedTestServlet.java
@@ -0,0 +1,136 @@ +/* + * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.servlet; + +import test.beans.Bean1; +import test.beans.Bean2; + +import javax.enterprise.context.ContextNotActiveException; +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.transaction.UserTransaction; +import java.io.IOException; + +@WebServlet(name = "TransactionScopedTestServlet", urlPatterns = {"/TransactionScopedTestServlet"}) +public class TransactionScopedTestServlet extends HttpServlet { + public static boolean bean1PreDestroyCalled = false; + public static boolean bean2PreDestroyCalled = false; + + @Inject + UserTransaction userTransaction; + + @Inject + Bean1 bean1; + + @Inject + Bean1 bean1_1; + + @Inject + Bean2 bean2; + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + StringBuffer msg = new StringBuffer(); + ServletOutputStream m_out = response.getOutputStream(); + + msg.append( "@TransactionScoped Test"); + try { + userTransaction.begin(); + } catch (Exception e) { + e.printStackTrace(); + } + + bean1PreDestroyCalled = false; + bean2PreDestroyCalled = false; + msg.append(doActiveTransaction("First")); + + try { + userTransaction.commit(); + } catch (Exception e) { + e.printStackTrace(); + } + + msg.append( checkPreDestroyCalled("First") ); + try { + userTransaction.begin(); + } catch (Exception e) { + e.printStackTrace(); + } + + bean1PreDestroyCalled = false; + bean2PreDestroyCalled = false; + msg.append(doActiveTransaction("Second")); + try { + userTransaction.rollback(); + } catch (Exception e) { + e.printStackTrace(); + } + msg.append( checkPreDestroyCalled("Second") ); + + try { + bean1.foo(); + msg.append("Should have gotten a ContextNotActiveException.\n"); + } catch (ContextNotActiveException cnae) { + } + + m_out.print( msg.toString() ); + } + + private String doActiveTransaction( String transNum ) { + StringBuffer msg = new StringBuffer(); + String bean1Foo = bean1.foo(); + String bean1_1Foo = bean1_1.foo(); + String bean2Foo = bean2.foo(); + + if ( bean1PreDestroyCalled ) { + msg.append( transNum + " Transaction bean1.preDestroyCalled initialized incorrectly.\n"); + } + + if ( bean2PreDestroyCalled ) { + msg.append( transNum + " Transaction bean2.preDestroyCalled initialized incorrectly.\n"); + } + + if (!bean1Foo.equals(bean1_1Foo)) { + msg.append( transNum + " Transaction bean1 does not equal bean1_1. It should.\n"); + } + + if (bean2Foo.equals(bean1Foo)) { + msg.append(transNum + " Transaction bean2 equals bean1. It should not.\n"); + } + + return msg.toString(); + } + + private String checkPreDestroyCalled( String transNum ) { + StringBuffer msg = new StringBuffer(); + + if ( ! bean1PreDestroyCalled ) { + msg.append( transNum + " Transaction bean1.preDestroyCalled not called.\n"); + } + + if ( ! bean2PreDestroyCalled ) { + msg.append( transNum + " bean2.preDestroyCalled not called.\n"); + } + + return msg.toString(); + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/README b/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/README new file mode 100644 index 0000000..0dcab93 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/README
@@ -0,0 +1,2 @@ +Test +- Alternatives: MockPaymentProcessor is an Alternative that is enabled through beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/WebTest.java new file mode 100644 index 0000000..3b8c277 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/WebTest.java
@@ -0,0 +1,75 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "unproxyable-deps-tests"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Testing Alternatives"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + System.out.println("TESTNAME " + TEST_NAME); + + int code = conn.getResponseCode(); + if (code != 404) {//This should return a 404 as the application must not deply + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + stat.addStatus(TEST_NAME, stat.PASS); + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/build.properties b/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/build.properties new file mode 100644 index 0000000..317b372 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi-alternatives"/> +<property name="appname" value="${module}-servlet-annotation"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/build.xml b/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/build.xml new file mode 100644 index 0000000..9a442d6 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/build.xml
@@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> +<!-- Nothing to undeply here as the deployment must fail for this test + <antcall target="undeploy-war-common"/> +--> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/descriptor/beans.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/descriptor/beans.xml
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/servlet/UnproxyableDepsTest.java b/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/servlet/UnproxyableDepsTest.java new file mode 100644 index 0000000..26fe8c9 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/servlet/UnproxyableDepsTest.java
@@ -0,0 +1,45 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.artifacts.AppScopedBean; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }, initParams = { + @WebInitParam(name = "n1", value = "v1"), + @WebInitParam(name = "n2", value = "v2") }) +public class UnproxyableDepsTest extends HttpServlet { + + @Inject AppScopedBean ab; + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + ", n2=" + + getInitParameter("n2"); + + writer.write("initParams: " + msg + "\n"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/servlet/test/artifacts/AppScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/servlet/test/artifacts/AppScopedBean.java new file mode 100644 index 0000000..09251a4 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/servlet/test/artifacts/AppScopedBean.java
@@ -0,0 +1,27 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; + +@ApplicationScoped +public class AppScopedBean { + //injecting a request-scoped unproxyable bean + @Inject BeanScopedBean bscopedBean; + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/servlet/test/artifacts/BeanScopedBean.java b/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/servlet/test/artifacts/BeanScopedBean.java new file mode 100644 index 0000000..76307f3 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unproxyable-deps/servlet/test/artifacts/BeanScopedBean.java
@@ -0,0 +1,25 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +import javax.enterprise.context.RequestScoped; + +@RequestScoped +//A request-scoped final class(therefore un-proxyable) +public final class BeanScopedBean { + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/README b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/README new file mode 100644 index 0000000..228b621 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/README
@@ -0,0 +1,2 @@ +Test +- Ensure that presence of an alternative removes an unsatisfied dependency
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/WebTest.java b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/WebTest.java new file mode 100644 index 0000000..9201dcb --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/WebTest.java
@@ -0,0 +1,105 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.*; +import java.net.*; +import com.sun.ejte.ccl.reporter.*; + +/* + * Unit test for @WebServlet + */ +public class WebTest { + + private static SimpleReporterAdapter stat + = new SimpleReporterAdapter("appserv-tests"); + private static final String TEST_NAME = "unsatisfied-dependencies-tests"; + private static final String EXPECTED_RESPONSE = "Hello from Servlet 3.0. initParams: n1=v1, n2=v2"; + + private String host; + private String port; + private String contextRoot; + + public WebTest(String[] args) { + host = args[0]; + port = args[1]; + contextRoot = args[2]; + } + + public static void main(String[] args) { + stat.addDescription("Testing Unsatisfied dependencies"); + WebTest webTest = new WebTest(args); + webTest.doTest(); + stat.printSummary(TEST_NAME); + } + + public void doTest() { + try { + invoke(); + } catch (Exception ex) { + System.out.println(TEST_NAME + " test failed"); + stat.addStatus(TEST_NAME, stat.FAIL); + ex.printStackTrace(); + } + } + + private void invoke() throws Exception { + + String url = "http://" + host + ":" + port + contextRoot + + "/myurl"; + System.out.println("opening connection to " + url); + HttpURLConnection conn = (HttpURLConnection) + (new URL(url)).openConnection(); + System.out.println("TESTNAME " + TEST_NAME); + + int code = conn.getResponseCode(); + if (code != 200) { + System.out.println("Unexpected return code: " + code); + stat.addStatus(TEST_NAME, stat.FAIL); + } else { + InputStream is = null; + BufferedReader input = null; + String line = null; + try { + is = conn.getInputStream(); + input = new BufferedReader(new InputStreamReader(is)); + line = input.readLine(); + System.out.println("line = " + line); + } finally { + try { + if (is != null) { + is.close(); + } + } catch(IOException ioe) { + // ignore + } + try { + if (input != null) { + input.close(); + } + } catch(IOException ioe) { + // ignore + } + } + if (EXPECTED_RESPONSE.equals(line)) { + stat.addStatus(TEST_NAME, stat.PASS); + } else { + System.out.println("Wrong response. Expected: " + + EXPECTED_RESPONSE + ", received: " + line); + stat.addStatus(TEST_NAME, stat.FAIL); + } + } + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/build.properties b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/build.properties new file mode 100644 index 0000000..b44a74e --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/build.properties
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + + +<property name="module" value="cdi-unsatisfieddeps"/> +<property name="appname" value="${module}-servlet-annotation"/> +<property name="assemble" value="${build.classes.dir}/archive"/> +<property name="contextroot" value="/${appname}"/> +<property name="beans.xml" value="descriptor/beans.xml"/>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/build.xml b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/build.xml new file mode 100644 index 0000000..c0d904d --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/build.xml
@@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<!DOCTYPE project [ +<!ENTITY commonSetup SYSTEM "./../../../config/properties.xml"> +<!ENTITY commonBuild SYSTEM "./../../../config/common.xml"> +<!ENTITY run SYSTEM "./../../../config/run.xml"> +<!ENTITY testproperties SYSTEM "./build.properties"> +]> + +<project name="webcontainer_unittest" default="all" basedir="."> + + &commonSetup; + &commonBuild; + &testproperties; + &run; + + <target name="all" depends="build,deploy,run,undeploy"/> + + <target name="clean" depends="init-common"> + <antcall target="clean-common"/> + <delete> + <fileset dir="." includes="*.class"/> + </delete> + </target> + + <target name="compile" depends="clean"> + <antcall target="compile-common"> + <param name="src" value="servlet"/> + </antcall> + </target> + + <target name="build" depends="compile"> + <property name="hasWebclient" value="yes"/> + <antcall target="webclient-war-common"> + <param name="hasWebclient" value="yes"/> + <param name="webclient.war.classes" value="**/*.class"/> + </antcall> + + <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar" + includes="WebTest.java"/> + + </target> + + <target name="build-publish-war" depends="build, publish-war-common" /> + + <target name="deploy" depends="init-common"> + <antcall target="deploy-war-common"/> + </target> + + <target name="run" depends="init-common"> + <java classname="WebTest"> + <arg value="${http.host}"/> + <arg value="${http.port}"/> + <arg value="${contextroot}"/> + <classpath> + <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/> + <pathelement location="."/> + </classpath> + </java> + </target> + + <target name="undeploy" depends="init-common"> + <antcall target="undeploy-war-common"/> + </target> + + <target name="usage"> + <antcall target="usage-common"/> + </target> +</project>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/descriptor/beans.xml b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/descriptor/beans.xml new file mode 100644 index 0000000..47d88ee --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/descriptor/beans.xml
@@ -0,0 +1,27 @@ +<!-- + + Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + +--> + +<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"> + <alternatives> + <!-- This test passes because this alternative is enabled --> + <class>test.artifacts.MockPaymentProcessor</class> + </alternatives> +</beans>
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/servlet/UnsatisfiedDependenciesServlet.java b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/servlet/UnsatisfiedDependenciesServlet.java new file mode 100644 index 0000000..6e739b8 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/servlet/UnsatisfiedDependenciesServlet.java
@@ -0,0 +1,61 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import test.artifacts.MockPaymentProcessor; +import test.artifacts.PaymentProcessor; +import test.beans.BeanToTestUnsatisfiedDependencies; + +@WebServlet(name = "mytest", urlPatterns = { "/myurl" }, initParams = { + @WebInitParam(name = "n1", value = "v1"), + @WebInitParam(name = "n2", value = "v2") }) +public class UnsatisfiedDependenciesServlet extends HttpServlet { + + @Inject + BeanToTestUnsatisfiedDependencies tb; + + @Inject + PaymentProcessor paymentProcessor; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws IOException, ServletException { + PrintWriter writer = res.getWriter(); + writer.write("Hello from Servlet 3.0. "); + String msg = "n1=" + getInitParameter("n1") + ", n2=" + + getInitParameter("n2"); + + if (!tb.testInjection()) + msg += "Injection of Mock dependency Failed"; + + //In the case of ambiguous dependencies such as synchronous and asynchronous payment processors + //the enabled alternative wins + boolean qualifierTestSuccess = paymentProcessor instanceof MockPaymentProcessor; + if (!qualifierTestSuccess) + msg += "Mock dependency injection into Servlet Failed"; + + writer.write("initParams: " + msg + "\n"); + } +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/servlet/test/artifacts/MockPaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/servlet/test/artifacts/MockPaymentProcessor.java new file mode 100644 index 0000000..13686d2 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/servlet/test/artifacts/MockPaymentProcessor.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +import javax.enterprise.inject.Alternative; + +@Alternative +public class MockPaymentProcessor implements PaymentProcessor{ + + @Override + public boolean processPayment() { + return true; + } + +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/servlet/test/artifacts/PaymentProcessor.java b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/servlet/test/artifacts/PaymentProcessor.java new file mode 100644 index 0000000..3e25336 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/servlet/test/artifacts/PaymentProcessor.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.artifacts; + +public interface PaymentProcessor { + boolean processPayment(); +}
diff --git a/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/servlet/test/beans/BeanToTestUnsatisfiedDependencies.java b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/servlet/test/beans/BeanToTestUnsatisfiedDependencies.java new file mode 100644 index 0000000..fd327c0 --- /dev/null +++ b/appserver/tests/appserv-tests/devtests/cdi/unsatisfied-deps/servlet/test/beans/BeanToTestUnsatisfiedDependencies.java
@@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package test.beans; + +import javax.enterprise.inject.Any; +import javax.enterprise.inject.Instance; +import javax.inject.Inject; + +import test.artifacts.MockPaymentProcessor; +import test.artifacts.PaymentProcessor; + +//Alternatives injection and test for availability of other beans via @Any Failed +public class BeanToTestUnsatisfiedDependencies { + private int numberOfPaymentProcessors = 0; + + @Inject + private PaymentProcessor pp; + + @Inject + public void init(@Any Instance<PaymentProcessor> payInstances) { + for (PaymentProcessor p : payInstances) { + System.out.println("Payment Processor #" + + numberOfPaymentProcessors + ":" + p); + numberOfPaymentProcessors++; + } + } + + public boolean testInjection() { + System.out.println("# of Payment processors:" + + numberOfPaymentProcessors); + System.out.println("mock payment procssor:" + pp); + return (numberOfPaymentProcessors == 1) // MockPaymentProcessor + && (pp instanceof MockPaymentProcessor); + } +}