Initial Contribution
Signed-off-by: Vinay Vishal <vinay.vishal@oracle.com>
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
+}