Initial Contribution

Signed-off-by: Vinay Vishal <vinay.vishal@oracle.com>
diff --git a/appserver/tests/embedded/cdi_basic/pom.xml b/appserver/tests/embedded/cdi_basic/pom.xml
new file mode 100644
index 0000000..7431bdd
--- /dev/null
+++ b/appserver/tests/embedded/cdi_basic/pom.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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
+
+-->
+
+<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/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.glassfish.tests.embedded.basic</groupId>
+    <artifactId>cdi_basic</artifactId>
+    <version>5.0.1-SNAPSHOT</version>
+    <name>Basic CDI Test</name>
+    <build>
+        <finalName>cdi_basic</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.6.1</version>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>2.4.2</version>
+                <configuration>
+                    <forkMode>always</forkMode>
+                    <useSystemClassLoader>false</useSystemClassLoader>
+                    <useManifestOnlyJar>false</useManifestOnlyJar>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <profiles>
+        <profile>
+            <id>run-with-uber-jar</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>org.glassfish.main.extras</groupId>
+                    <artifactId>glassfish-embedded-all</artifactId>
+                    <version>5.0.1-SNAPSHOT</version>
+                </dependency>
+                <dependency>
+                    <groupId>junit</groupId>
+                    <artifactId>junit</artifactId>
+                    <version>4.12</version>
+                </dependency>
+            </dependencies>
+        </profile>
+        <profile>
+            <id>run-with-shell-jar</id>
+            <activation>
+                <property>
+                    <name>build</name>
+                    <value>static-shell</value>
+                </property>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>junit</groupId>
+                    <artifactId>junit</artifactId>
+                    <version>4.12</version>
+                </dependency>
+                <dependency>
+                    <groupId>org.glassfish.main.extras</groupId>
+                    <artifactId>glassfish-embedded-static-shell</artifactId>
+                    <version>${project.version}</version>
+                    <scope>system</scope>
+                    <systemPath>${env.S1AS_HOME}/lib/embedded/glassfish-embedded-static-shell.jar
+                    </systemPath>
+                </dependency>
+            </dependencies>
+        </profile>
+    </profiles>
+</project>
diff --git a/appserver/tests/embedded/cdi_basic/src/main/config/.gitkeep_empty_dir b/appserver/tests/embedded/cdi_basic/src/main/config/.gitkeep_empty_dir
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/appserver/tests/embedded/cdi_basic/src/main/config/.gitkeep_empty_dir
diff --git a/appserver/tests/embedded/cdi_basic/src/main/java/org/glassfish/tests/embedded/cdi_basic/BasicCDITestServlet.java b/appserver/tests/embedded/cdi_basic/src/main/java/org/glassfish/tests/embedded/cdi_basic/BasicCDITestServlet.java
new file mode 100644
index 0000000..9edaa12
--- /dev/null
+++ b/appserver/tests/embedded/cdi_basic/src/main/java/org/glassfish/tests/embedded/cdi_basic/BasicCDITestServlet.java
@@ -0,0 +1,55 @@
+/*
+ * 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 org.glassfish.tests.embedded.cdi_basic;
+
+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 java.io.IOException;
+import java.io.PrintWriter;
+
+/**
+ * @author bhavanishankar@dev.java.net
+ */
+@WebServlet(name = "BasicCDITestServlet",
+        urlPatterns = "/BasicCDITestServlet")
+public class BasicCDITestServlet extends HttpServlet {
+
+    @javax.inject.Inject TestBean tb;
+    @javax.inject.Inject TestRequestScopedBean trsb;
+
+    @Override
+    protected void doGet(HttpServletRequest httpServletRequest,
+                         HttpServletResponse httpServletResponse) throws ServletException, IOException {
+        PrintWriter out = httpServletResponse.getWriter();
+        out.println("Hi from BasicCDITestServlet");
+	if(tb == null) {
+	  out.println("TestBean not injected.");
+	} else if(trsb == null) {
+	  out.println("TestRequestScopeBean not injected.");
+	} else {
+	  out.println("TestBean injected. [" + tb + "]");
+	  out.println("TestRequestScopeBean injected. [ " + trsb + "]");
+	  out.println("All CDI beans have been injected.");
+	}
+        out.flush();
+        out.close();
+    }
+}
+
diff --git a/appserver/tests/embedded/cdi_basic/src/main/java/org/glassfish/tests/embedded/cdi_basic/TestBean.java b/appserver/tests/embedded/cdi_basic/src/main/java/org/glassfish/tests/embedded/cdi_basic/TestBean.java
new file mode 100644
index 0000000..1d819c4
--- /dev/null
+++ b/appserver/tests/embedded/cdi_basic/src/main/java/org/glassfish/tests/embedded/cdi_basic/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 org.glassfish.tests.embedded.cdi_basic;
+
+//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/embedded/cdi_basic/src/main/java/org/glassfish/tests/embedded/cdi_basic/TestRequestScopedBean.java b/appserver/tests/embedded/cdi_basic/src/main/java/org/glassfish/tests/embedded/cdi_basic/TestRequestScopedBean.java
new file mode 100644
index 0000000..0138242
--- /dev/null
+++ b/appserver/tests/embedded/cdi_basic/src/main/java/org/glassfish/tests/embedded/cdi_basic/TestRequestScopedBean.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 org.glassfish.tests.embedded.cdi_basic;
+
+//Simple RequestScoped TestBean to test CDI. 
+//This bean implements Serializable as it needs to be placed into a Stateful Bean
+@javax.enterprise.context.RequestScoped
+public class TestRequestScopedBean
+{}
diff --git a/appserver/tests/embedded/cdi_basic/src/main/resources/.gitkeep_empty_dir b/appserver/tests/embedded/cdi_basic/src/main/resources/.gitkeep_empty_dir
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/appserver/tests/embedded/cdi_basic/src/main/resources/.gitkeep_empty_dir
diff --git a/appserver/tests/embedded/cdi_basic/src/main/webapp/WEB-INF/beans.xml b/appserver/tests/embedded/cdi_basic/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/appserver/tests/embedded/cdi_basic/src/main/webapp/WEB-INF/beans.xml
diff --git a/appserver/tests/embedded/cdi_basic/src/main/webapp/WEB-INF/sun-web.xml b/appserver/tests/embedded/cdi_basic/src/main/webapp/WEB-INF/sun-web.xml
new file mode 100644
index 0000000..67d7bfc
--- /dev/null
+++ b/appserver/tests/embedded/cdi_basic/src/main/webapp/WEB-INF/sun-web.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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
+
+-->
+
+<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 8.1 Servlet 2.4//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_4-1.dtd">
+<sun-web-app>
+  <context-root>/cdi_basic</context-root> 
+</sun-web-app>
diff --git a/appserver/tests/embedded/cdi_basic/src/main/webapp/WEB-INF/web.xml b/appserver/tests/embedded/cdi_basic/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..af71778
--- /dev/null
+++ b/appserver/tests/embedded/cdi_basic/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
+  <display-name>cdi_basic</display-name>  
+  <distributable/>
+</web-app>
diff --git a/appserver/tests/embedded/cdi_basic/src/main/webapp/images/.gitkeep_empty_dir b/appserver/tests/embedded/cdi_basic/src/main/webapp/images/.gitkeep_empty_dir
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/appserver/tests/embedded/cdi_basic/src/main/webapp/images/.gitkeep_empty_dir
diff --git a/appserver/tests/embedded/cdi_basic/src/test/java/org/glassfish/tests/embedded/cdi_basic/BasicCDITest.java b/appserver/tests/embedded/cdi_basic/src/test/java/org/glassfish/tests/embedded/cdi_basic/BasicCDITest.java
new file mode 100644
index 0000000..d0298db
--- /dev/null
+++ b/appserver/tests/embedded/cdi_basic/src/test/java/org/glassfish/tests/embedded/cdi_basic/BasicCDITest.java
@@ -0,0 +1,115 @@
+/*
+ * 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 org.glassfish.tests.embedded.cdi_basic;
+
+import junit.framework.Assert;
+import org.glassfish.embeddable.Deployer;
+import org.glassfish.embeddable.GlassFish;
+import org.glassfish.embeddable.GlassFishProperties;
+import org.glassfish.embeddable.GlassFishRuntime;
+import org.glassfish.embeddable.archive.ScatteredArchive;
+import org.glassfish.embeddable.archive.ScatteredEnterpriseArchive;
+import org.glassfish.embeddable.web.HttpListener;
+import org.glassfish.embeddable.web.WebContainer;
+import org.junit.Test;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+ * @author bhavanishankar@dev.java.net
+ */
+
+public class BasicCDITest{
+
+    @Test
+    public void test() throws Exception {
+
+        GlassFishProperties props = new GlassFishProperties();
+        props.setPort("http-listener", 8080);
+        GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(props);
+        glassfish.start();
+
+        // Test Scattered Web Archive
+        ScatteredArchive sa = new ScatteredArchive("cdi_basic",
+                ScatteredArchive.Type.WAR, new File("src/main/webapp"));
+        sa.addClassPath(new File("target/classes"));
+        sa.addClassPath(new File("src/main/resources"));
+        URI warURI = sa.toURI();
+        printContents(warURI);
+
+        // Deploy archive
+        Deployer deployer = glassfish.getDeployer();
+        String appname = deployer.deploy(warURI);
+        System.out.println("Deployed [" + appname + "]");
+        Assert.assertEquals(appname, "cdi_basic");
+
+        // Now create a http listener and access the app.
+        WebContainer webcontainer = glassfish.getService(WebContainer.class);
+        HttpListener listener = new HttpListener();
+        listener.setId("my-listener");
+        listener.setPort(9090);
+        webcontainer.addWebListener(listener);
+
+        get("http://localhost:8080/cdi_basic/BasicCDITestServlet",
+                "All CDI beans have been injected.");
+
+        deployer.undeploy(appname);
+
+        glassfish.dispose();
+
+    }
+
+    private void get(String urlStr, String result) throws Exception {
+        URL url = new URL(urlStr);
+        URLConnection yc = url.openConnection();
+        System.out.println("\nURLConnection [" + yc + "] : ");
+        BufferedReader in = new BufferedReader(new InputStreamReader(
+                yc.getInputStream()));
+        String line = null;
+        boolean found = false;
+        while ((line = in.readLine()) != null) {
+            System.out.println(line);
+            if (line.indexOf(result) != -1) {
+                found = true;
+            }
+        }
+        Assert.assertTrue(found);
+        System.out.println("\n***** SUCCESS **** Found [" + result + "] in the response.*****\n");
+    }
+
+    void printContents(URI jarURI) throws IOException {
+        JarFile jarfile = new JarFile(new File(jarURI));
+        System.out.println("\n\n[" + jarURI + "] contents : \n");
+        Enumeration<JarEntry> entries = jarfile.entries();
+        while (entries.hasMoreElements()) {
+            JarEntry entry = entries.nextElement();
+            System.out.println(entry.getSize() + "\t" + new Date(entry.getTime()) +
+                    "\t" + entry.getName());
+        }
+        System.out.println();
+    }
+}