Initial Contribution

Signed-off-by: Jan Supol <jan.supol@oracle.com>
diff --git a/tests/integration/j-441/war1/pom.xml b/tests/integration/j-441/war1/pom.xml
new file mode 100644
index 0000000..067ef5e
--- /dev/null
+++ b/tests/integration/j-441/war1/pom.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+
+    This program and the accompanying materials are made available under the
+    terms of the Eclipse Public License v. 2.0, which is available at
+    http://www.eclipse.org/legal/epl-2.0.
+
+    This Source Code may also be made available under the following Secondary
+    Licenses when the conditions for such availability set forth in the
+    Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+    version 2 with the GNU Classpath Exception, which is available 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>
+
+    <parent>
+        <groupId>org.glassfish.jersey.tests.integration</groupId>
+        <artifactId>project</artifactId>
+        <version>2.28-SNAPSHOT</version>
+        <relativePath>../../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>j-441-war1</artifactId>
+    <packaging>war</packaging>
+
+    <name>jersey-tests-integration-j-441-war1</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.glassfish.jersey.containers</groupId>
+            <artifactId>jersey-container-servlet</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>javax.servlet-api</artifactId>
+            <version>${servlet3.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.enterprise</groupId>
+            <artifactId>cdi-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+            <artifactId>jersey-test-framework-provider-bundle</artifactId>
+            <type>pom</type>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-war-plugin</artifactId>
+                <configuration>
+                    <failOnMissingWebXml>false</failOnMissingWebXml>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <skipTests>${skipTests}</skipTests>
+                    <systemPropertyVariables>
+                        <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+                        <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+                    </systemPropertyVariables>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-install-plugin</artifactId>
+                <configuration>
+                    <skip>false</skip>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <properties>
+        <skipTests>true</skipTests>
+        <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+        <testContainerPort>8080</testContainerPort>
+    </properties>
+</project>
diff --git a/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/CdiResource.java b/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/CdiResource.java
new file mode 100644
index 0000000..33ce8da
--- /dev/null
+++ b/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/CdiResource.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * 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.jersey.tests.integration.j441.one;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+
+/**
+ * CDI backed JAX-RS resource.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("/test")
+@RequestScoped
+public class CdiResource {
+
+    @Context
+    private ServletContext scField;
+
+    private ServletContext scCtorParam;
+
+    /* to make CDI happy */
+    public CdiResource() {
+    }
+
+    @Inject
+    public CdiResource(@Context final ServletContext sc) {
+        this.scCtorParam = sc;
+    }
+
+    @GET
+    @Path("ctor-param")
+    public String getCtorParam() {
+        return scCtorParam.getContextPath();
+    }
+
+    @GET
+    @Path("method-param")
+    public String getMethodParam(@Context final ServletContext sc) {
+        return sc.getContextPath();
+    }
+
+    @GET
+    @Path("field")
+    public String getField() {
+        return scField.getContextPath();
+    }
+
+    @GET
+    @Path("exception")
+    public String getException() throws Exception {
+        throw new Exception() {};
+    }
+}
diff --git a/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/CustomExceptionMapper.java b/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/CustomExceptionMapper.java
new file mode 100644
index 0000000..d5aa71c
--- /dev/null
+++ b/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/CustomExceptionMapper.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * 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.jersey.tests.integration.j441.one;
+
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+
+import javax.servlet.ServletContext;
+
+/**
+ * JAX-RS provider added just to make sure the application
+ * deploys fine. Since JAX-RS providers get initialized
+ * at Jersey bootstrapping phase, we would get a deploy
+ * error if something went wrong.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CustomExceptionMapper implements ExceptionMapper<Exception> {
+
+    @Context
+    private ServletContext sc;
+
+    public Response toResponse(final Exception ex) {
+        return Response.status(200).entity(sc.getContextPath()).build();
+    }
+}
diff --git a/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/MyApplication.java b/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/MyApplication.java
new file mode 100644
index 0000000..073b84c
--- /dev/null
+++ b/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/MyApplication.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * 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.jersey.tests.integration.j441.one;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * Test case to ensure proper WAR isolation on Jersey level.
+ * Define JAX-RS application containing a simple CDI backed JAX-RS resource.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/")
+public class MyApplication extends ResourceConfig {
+
+    public MyApplication() {
+        super(CdiResource.class, CustomExceptionMapper.class);
+    }
+}
diff --git a/tests/integration/j-441/war1/src/main/webapp/WEB-INF/beans.xml b/tests/integration/j-441/war1/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..93cfed7
--- /dev/null
+++ b/tests/integration/j-441/war1/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+
+    This program and the accompanying materials are made available under the
+    terms of the Eclipse Public License v. 2.0, which is available at
+    http://www.eclipse.org/legal/epl-2.0.
+
+    This Source Code may also be made available under the following Secondary
+    Licenses when the conditions for such availability set forth in the
+    Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+    version 2 with the GNU Classpath Exception, which is available at
+    https://www.gnu.org/software/classpath/license.html.
+
+    SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+</beans>
diff --git a/tests/integration/j-441/war1/src/test/java/org/glassfish/jersey/tests/integration/j441/one/ContextPathTest.java b/tests/integration/j-441/war1/src/test/java/org/glassfish/jersey/tests/integration/j441/one/ContextPathTest.java
new file mode 100644
index 0000000..285859e
--- /dev/null
+++ b/tests/integration/j-441/war1/src/test/java/org/glassfish/jersey/tests/integration/j441/one/ContextPathTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * 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.jersey.tests.integration.j441.one;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * This is to make sure two Jersey wars are separated well in a single ear.
+ *
+ * @author Michal Gajdos
+ */
+public class ContextPathTest extends JerseyTest {
+
+    @Override
+    protected Application configure() {
+        return new Application();
+    }
+
+    @Override
+    protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+        return new ExternalTestContainerFactory();
+    }
+
+    @Test
+    public void testFieldInjection() {
+        assertThat(target("one/test/field").request().get(String.class), is("/one"));
+    }
+
+    @Test
+    public void testConstructorInjection() {
+        assertThat(target("one/test/ctor-param").request().get(String.class), is("/one"));
+    }
+
+    @Test
+    public void testMethodInjection() {
+        assertThat(target("one/test/method-param").request().get(String.class), is("/one"));
+    }
+
+    @Test
+    public void testExceptionMapperInjection() {
+        assertThat(target("one/test/exception").request().get(String.class), is("/one"));
+    }
+}