Initial Contribution
Signed-off-by: Vinay Vishal <vinay.vishal@oracle.com>
diff --git a/appserver/tests/paas/multiple-db-app-scoped-services/basic/README.txt b/appserver/tests/paas/multiple-db-app-scoped-services/basic/README.txt
new file mode 100644
index 0000000..6e2dd5d
--- /dev/null
+++ b/appserver/tests/paas/multiple-db-app-scoped-services/basic/README.txt
@@ -0,0 +1,15 @@
+This test will create 2 jdbc connection pools referring to different application scoped db services. HR database is located on Derby database whereas Salary database is located on mysql database.
+
+This test specifies the database name and init.sql explicitly in the glassfish-services.xml for the respective database services. A glassfish-resources.xml file is included in the WEB-INF directory that describes the jdbc-connection-pool(s)/jdbc-resource(s) to be used during provisioning.
+
+The corresponding init.sql files are used by the service provisioning engine to load data into the respective databases that are created during provisioning. Application reads data from these database tables and prints the contents onto a servlet.
+
+Works only on KVM as this PaaS application requires Derby and MySQL DB Plugins.
+
+Prerequisities :
+- Make sure both paas.javadbplugin.jar as well as paas.mysqldbplugin.jar are present in the S1AS_HOME/modules directory.
+- Execute the command to make one as the default, say
+
+asadmin register-service-provisioning-engine --type Database --defaultservice=true org.glassfish.paas.javadbplugin.DerbyPlugin
+
+Please refer ../../README.txt for more generic guidelines.
diff --git a/appserver/tests/paas/multiple-db-app-scoped-services/basic/init.hr-service.sql b/appserver/tests/paas/multiple-db-app-scoped-services/basic/init.hr-service.sql
new file mode 100644
index 0000000..67657c1
--- /dev/null
+++ b/appserver/tests/paas/multiple-db-app-scoped-services/basic/init.hr-service.sql
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+CREATE TABLE HR (
+ emp_id integer not null,
+ emp_name char(16)
+);
+
+INSERT INTO HR VALUES(101, 'Robert Frost');
+INSERT INTO HR VALUES(102, 'William Blake');
+INSERT INTO HR VALUES(103, 'Edgar Allan Poe');
+INSERT INTO HR VALUES(104, 'W Shakespeare');
+INSERT INTO HR VALUES(105, 'W Wordsworth');
diff --git a/appserver/tests/paas/multiple-db-app-scoped-services/basic/init.salary-service.sql b/appserver/tests/paas/multiple-db-app-scoped-services/basic/init.salary-service.sql
new file mode 100644
index 0000000..9c7a42c
--- /dev/null
+++ b/appserver/tests/paas/multiple-db-app-scoped-services/basic/init.salary-service.sql
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+CREATE TABLE SALARY (
+ emp_id integer not null,
+ emp_sal float(7, 2)
+);
+
+INSERT INTO SALARY VALUES(101, 11111.12);
+INSERT INTO SALARY VALUES(102, 11221.15);
+INSERT INTO SALARY VALUES(103, 31411.16);
+INSERT INTO SALARY VALUES(104, 14135.72);
+INSERT INTO SALARY VALUES(105, 61114.18);
+
diff --git a/appserver/tests/paas/multiple-db-app-scoped-services/basic/pom.xml b/appserver/tests/paas/multiple-db-app-scoped-services/basic/pom.xml
new file mode 100644
index 0000000..20be062
--- /dev/null
+++ b/appserver/tests/paas/multiple-db-app-scoped-services/basic/pom.xml
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available 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.paas</groupId>
+ <artifactId>multiple-app-scoped-service-test-basic</artifactId>
+ <version>5.0.1-SNAPSHOT</version>
+ <name>Multiple Application Scoped Database Services Basic PaaS Application</name>
+ <packaging>war</packaging>
+ <build>
+ <finalName>multiple_app_scoped_service_test</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <skip>false</skip>
+ <enableAssertions>false</enableAssertions>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>test</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
+ <copy file="init.hr-service.sql"
+ tofile="/tmp/init.hr-service.sql"/>
+ <copy file="init.salary-service.sql"
+ tofile="/tmp/init.salary-service.sql"/>
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish</groupId>
+ <artifactId>javax.servlet</artifactId>
+ <version>3.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.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>
+</project>
diff --git a/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/java/org/glassfish/tests/paas/multipleappscopedservicetest/EmployeeServlet.java b/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/java/org/glassfish/tests/paas/multipleappscopedservicetest/EmployeeServlet.java
new file mode 100644
index 0000000..466d288
--- /dev/null
+++ b/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/java/org/glassfish/tests/paas/multipleappscopedservicetest/EmployeeServlet.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * 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.paas.multipleappscopedservicetest;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.sql.DataSource;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.PreparedStatement;
+import java.sql.DatabaseMetaData;
+import java.util.Enumeration;
+import javax.annotation.Resource;
+
+
+public final class EmployeeServlet extends HttpServlet {
+
+ @Resource(mappedName = "java:app/jdbc/SalaryRes")
+ private DataSource salDs = null;
+
+ @Resource(mappedName = "java:app/jdbc/HrRes")
+ private DataSource hrDs = null;
+
+ /**
+ * Respond to a GET request for the content produced by
+ * this servlet.
+ *
+ * @param request The servlet request we are processing
+ * @param response The servlet response we are producing
+ * @throws IOException if an input/output error occurs
+ * @throws ServletException if a servlet error occurs
+ */
+ public void doGet(HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException {
+
+ System.out.println("Servlet processing do get..");
+
+ response.setContentType("text/html");
+ PrintWriter writer = response.getWriter();
+
+ writer.println("<html>");
+ writer.println("<head>");
+ writer.println("<title>Multiple App Scoped DB Service Test</title>");
+ writer.println("</head>");
+ writer.println("<body bgcolor=white>");
+
+ writer.println("<table border=\"0\">");
+ writer.println("<tr>");
+ writer.println("<td>");
+ writer.println("<img height=\"200\" width=\"200\" src=\"images/numbers.jpg\">");
+ writer.println("</td>");
+ writer.println("<td>");
+ writer.println("<h1>Multiple Application Scoped DB Service PaaS Application</h1>");
+ writer.println("</td>");
+ writer.println("</tr>");
+ writer.println("</table>");
+
+ writer.println("<table border=\"0\" width=\"100%\">");
+ Enumeration names = request.getHeaderNames();
+ while (names.hasMoreElements()) {
+ String name = (String) names.nextElement();
+ writer.println("<tr>");
+ writer.println(" <th align=\"right\">" + name + ":</th>");
+ writer.println(" <td>" + request.getHeader(name) + "</td>");
+ writer.println("</tr>");
+ }
+ writer.println("</table>");
+ if (hrDs != null && salDs != null) {
+ Statement stmt1 = null;
+ PreparedStatement stmt2 = null;
+ try {
+ stmt1 = hrDs.getConnection().createStatement();
+
+ DatabaseMetaData dbMetadata1 = stmt1.getConnection().getMetaData();
+ String dbUrl1 = dbMetadata1.getURL();
+ writer.println("DB URL : " + dbUrl1 + "\n");
+ if (dbUrl1.indexOf("hr_database") == -1) {
+ throw new Exception("Custom Database [hr_database] is not created while provisioning.");
+ }
+
+
+ ResultSet rs1 = stmt1.executeQuery("SELECT emp_id, emp_name from HR");
+ String salQuery = "SELECT emp_sal from SALARY WHERE emp_id = ? ";
+ stmt2 = salDs.getConnection().prepareStatement(salQuery);
+
+ DatabaseMetaData dbMetadata2 = stmt2.getConnection().getMetaData();
+ String dbUrl2 = dbMetadata2.getURL();
+ writer.println("DB URL : " + dbUrl2 + "\n");
+ if (dbUrl2.indexOf("salary_database") == -1) {
+ throw new Exception("Custom Database [salary_database] is not created while provisioning.");
+ }
+
+ writer.println("<table border=\"1\" width=\"100%\">");
+ writer.println("<tr>");
+ writer.println(" <th align=\"left\" colspan=\"2\">" + "Employee Information retrieved" + "</th>");
+ writer.println("</tr>");
+ writer.println("<tr>");
+ writer.println("<td>" + "Employee ID" + "</td>");
+ writer.println("<td>" + "Employee Name" + "</td>");
+ writer.println("<td>" + "Employee Salary" + "</td>");
+ writer.println("</tr>");
+ while (rs1.next()) {
+ writer.println("<tr>");
+ writer.println(" <td>" + rs1.getObject(1) + "</td>");
+ writer.println(" <td>" + rs1.getObject(2) + "</td>");
+ stmt2.setInt(1, (Integer) rs1.getObject(1));
+ ResultSet rs2 = stmt2.executeQuery();
+ while(rs2.next()) {
+ writer.println(" <td>" + rs2.getObject(1) + "</td>");
+ writer.println("</tr>");
+ }
+ }
+ writer.println("</table>");
+ } catch (Exception ex) {
+ ex.printStackTrace(writer);
+ } finally {
+ if (stmt1 != null) {
+ try {
+ stmt1.getConnection().close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ if (stmt2 != null) {
+ try {
+ stmt2.getConnection().close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ } else {
+ }
+ writer.println("</body>");
+ writer.println("</html>");
+ }
+
+}
+
diff --git a/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/WEB-INF/glassfish-resources.xml b/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/WEB-INF/glassfish-resources.xml
new file mode 100644
index 0000000..36abd31
--- /dev/null
+++ b/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/WEB-INF/glassfish-resources.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available 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 resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
+
+<resources>
+ <jdbc-connection-pool datasource-classname="org.apache.derby.jdbc.ClientXADataSource" res-type="javax.sql.DataSource" name="java:app/jdbc/hr_pool">
+ <property name="service-name" value="hr-service"/>
+ </jdbc-connection-pool>
+
+ <jdbc-resource pool-name="java:app/jdbc/hr_pool" jndi-name="java:app/jdbc/HrRes"></jdbc-resource>
+
+ <jdbc-connection-pool datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" res-type="javax.sql.DataSource" name="java:app/jdbc/salary_pool">
+ <property name="service-name" value="salary-service"/>
+ </jdbc-connection-pool>
+ <jdbc-resource pool-name="java:app/jdbc/salary_pool" jndi-name="java:app/jdbc/SalaryRes"></jdbc-resource>
+</resources>
+
diff --git a/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/WEB-INF/glassfish-services.xml b/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/WEB-INF/glassfish-services.xml
new file mode 100644
index 0000000..df573bf
--- /dev/null
+++ b/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/WEB-INF/glassfish-services.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<glassfish-services>
+<service-description name="multiple-app-scoped-service-test" init-type="lazy">
+ <characteristics>
+ <characteristic name="service-type" value="JavaEE"/>
+ </characteristics>
+ <configurations>
+ <configuration name="min.clustersize" value="1"/>
+ <configuration name="max.clustersize" value="2"/>
+ </configurations>
+</service-description>
+<service-description name="hr-service" init-type="lazy">
+ <characteristics>
+ <characteristic name="service-type" value="Database"/>
+ </characteristics>
+ <configurations>
+ <configuration name="database.init.sql" value="/tmp/init.hr-service.sql"/>
+ <configuration name="database.name" value="hr_database"/>
+ </configurations>
+</service-description>
+<service-description name="salary-service" init-type="lazy">
+ <characteristics>
+ <characteristic name="service-type" value="Database"/>
+ <characteristic name="product-vendor" value="MySQL"/>
+ </characteristics>
+ <configurations>
+ <configuration name="database.init.sql" value="/tmp/init.salary-service.sql"/>
+ <configuration name="database.name" value="salary_database"/>
+ </configurations>
+</service-description>
+</glassfish-services>
diff --git a/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/WEB-INF/sun-web.xml b/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/WEB-INF/sun-web.xml
new file mode 100644
index 0000000..fcaa427
--- /dev/null
+++ b/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/WEB-INF/sun-web.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available 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 9.0 Servlet 2.5//EN"
+ "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
+<sun-web-app error-url="">
+</sun-web-app>
diff --git a/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/WEB-INF/web.xml b/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..33009c7
--- /dev/null
+++ b/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<web-app version="2.5"
+ 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/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>EmployeeServlet</servlet-name>
+ <servlet-class>org.glassfish.tests.paas.multipleappscopedservicetest.EmployeeServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>EmployeeServlet</servlet-name>
+ <url-pattern>/EmployeeServlet</url-pattern>
+ </servlet-mapping>
+ <session-config>
+ <session-timeout>
+ 30
+ </session-timeout>
+ </session-config>
+ <resource-ref>
+ <res-ref-name>java:app/jdbc/HrRes</res-ref-name>
+ <res-type>javax.sql.DataSource</res-type>
+ </resource-ref>
+ <resource-ref>
+ <res-ref-name>java:app/jdbc/SalaryRes</res-ref-name>
+ <res-type>javax.sql.DataSource</res-type>
+ </resource-ref>
+ </web-app>
diff --git a/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/images/numbers.jpg b/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/images/numbers.jpg
new file mode 100644
index 0000000..5e90b27
--- /dev/null
+++ b/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/images/numbers.jpg
Binary files differ
diff --git a/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/index.html b/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/index.html
new file mode 100644
index 0000000..7fd6bf2
--- /dev/null
+++ b/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/main/webapp/index.html
@@ -0,0 +1,26 @@
+<!--
+
+ Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<html>
+ <head/>
+ <body>
+ <p>Warm welcome to the Multiple App Scoped Database Services PaaS Application</p>
+ <p>Deployed servlets:</p>
+ <p><a href="EmployeeServlet">EmployeeServlet</a></p>
+ </body>
+</html>
diff --git a/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/test/java/org/glassfish/tests/paas/multipleappscopedservicetest/EmployeeTest.java b/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/test/java/org/glassfish/tests/paas/multipleappscopedservicetest/EmployeeTest.java
new file mode 100644
index 0000000..e64d321
--- /dev/null
+++ b/appserver/tests/paas/multiple-db-app-scoped-services/basic/src/test/java/org/glassfish/tests/paas/multipleappscopedservicetest/EmployeeTest.java
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * 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.paas.multipleappscopedservicetest;
+
+import junit.framework.Assert;
+import org.glassfish.embeddable.CommandResult;
+import org.glassfish.embeddable.CommandRunner;
+import org.glassfish.embeddable.GlassFish;
+import org.glassfish.embeddable.GlassFishProperties;
+import org.glassfish.embeddable.GlassFishRuntime;
+import org.glassfish.embeddable.Deployer;
+import org.junit.Test;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author Shalini M
+ */
+
+public class EmployeeTest {
+
+ @Test
+ public void test() throws Exception {
+
+ // 1. Bootstrap GlassFish DAS in embedded mode.
+ GlassFishProperties glassFishProperties = new GlassFishProperties();
+ glassFishProperties.setInstanceRoot(System.getenv("S1AS_HOME")
+ + "/domains/domain1");
+ glassFishProperties.setConfigFileReadOnly(false);
+ GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(
+ glassFishProperties);
+ PrintStream sysout = System.out;
+ glassfish.start();
+ System.setOut(sysout);
+
+ // 2. Deploy the PaaS application.
+ File archive = new File(System.getProperty("basedir")
+ + "/target/multiple_app_scoped_service_test.war");
+ // TODO :: use mvn apis to get the archive location.
+ Assert.assertTrue(archive.exists());
+
+ Deployer deployer = null;
+ String appName = null;
+ CommandRunner commandRunner = glassfish.getCommandRunner();
+ try {
+
+ //2. Deploy app
+ deployer = glassfish.getDeployer();
+ appName = deployer.deploy(archive);
+
+ System.err.println("Deployed [" + appName + "]");
+ Assert.assertNotNull(appName);
+
+
+ CommandResult result = commandRunner.run("list-services");
+ System.out.println("\nlist-services command output [ "
+ + result.getOutput() + "]");
+
+ // 3. Access the app to make sure PaaS app is correctly provisioned.
+ String HTTP_PORT = (System.getProperty("http.port") != null) ? System
+ .getProperty("http.port") : "28080";
+
+ String instanceIP = getLBIPAddress(glassfish);
+ get("http://" + instanceIP + ":" + HTTP_PORT
+ + "/multiple_app_scoped_service_test/EmployeeServlet",
+ "Employee ID");
+ get("http://" + instanceIP + ":" + HTTP_PORT
+ + "/multiple_app_scoped_service_test/EmployeeServlet",
+ "Employee Salary");
+
+ // 4. Undeploy the PaaS application .
+ } finally {
+ if (appName != null) {
+ deployer.undeploy(appName);
+ System.err.println("Undeployed [" + appName + "]");
+ }
+ }
+
+ }
+
+ 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");
+ }
+
+ private String getLBIPAddress(GlassFish glassfish) {
+ String lbIP = null;
+ String IPAddressPattern = "IP-ADDRESS\\s*\n*(.*)\\s*\n(([01]?\\d*|2[0-4]\\d|25[0-5])\\."
+ + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
+ + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
+ + "([0-9]?\\d\\d?|2[0-4]\\d|25[0-5]))";
+ try {
+ CommandRunner commandRunner = glassfish.getCommandRunner();
+ String result = commandRunner
+ .run("list-services", "--type", "LB",
+ "--output", "IP-ADDRESS").getOutput().toString();
+ if (result.contains("Nothing to list.")) {
+ result = commandRunner
+ .run("list-services", "--type", "JavaEE", "--output",
+ "IP-ADDRESS").getOutput().toString();
+
+ Pattern p = Pattern.compile(IPAddressPattern);
+ Matcher m = p.matcher(result);
+ if (m.find()) {
+ lbIP = m.group(2);
+ } else {
+ lbIP = "localhost";
+ }
+ } else {
+ Pattern p = Pattern.compile(IPAddressPattern);
+ Matcher m = p.matcher(result);
+ if (m.find()) {
+ lbIP = m.group(2);
+ } else {
+ lbIP = "localhost";
+ }
+
+ }
+
+ } catch (Exception e) {
+ System.out.println("Regex has thrown an exception "
+ + e.getMessage());
+ return "localhost";
+ }
+ return lbIP;
+ }
+}