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/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 "";
+    }
+
+}