Using Arquillian SPI for extending wars by vendor specific deployments.

Signed-off-by: jansupol <jan.supol@oracle.com>
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/container/requestcontext/security/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/container/requestcontext/security/JAXRSClientIT.java
index 794d21e..e131e58 100644
--- a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/container/requestcontext/security/JAXRSClientIT.java
+++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/container/requestcontext/security/JAXRSClientIT.java
@@ -24,6 +24,7 @@
 
 import jakarta.ws.rs.core.Response.Status;
 
+import org.jboss.arquillian.container.test.api.RunAsClient;
 import org.jboss.arquillian.junit5.ArquillianExtension;
 import org.jboss.arquillian.container.test.api.Deployment;
 import org.jboss.shrinkwrap.api.ShrinkWrap;
@@ -68,7 +69,7 @@
     TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName());
   }
 
-  @Deployment(testable = false)
+  @Deployment(testable = true)
   public static WebArchive createDeployment() throws IOException {
 
     InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/ee/rs/container/requestcontext/security/web.xml.template");
@@ -76,7 +77,7 @@
 
     WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_ee_rs_container_requestcontext_security_web.war");
     archive.addClasses(TSAppConfig.class, Resource.class, RequestFilter.class);
-    archive.addAsWebInfResource("jakarta/ws/rs/tck/ee/rs/container/requestcontext/security/jaxrs_ee_rs_container_requestcontext_security_web.war.sun-web.xml", "sun-web.xml");
+//    archive.addAsWebInfResource("jakarta/ws/rs/tck/ee/rs/container/requestcontext/security/jaxrs_ee_rs_container_requestcontext_security_web.war.sun-web.xml", "sun-web.xml");
     archive.setWebXML(new StringAsset(webXml));
     return archive;
 
@@ -99,6 +100,7 @@
    * @test_Strategy: Get the injectable security context information for the
    * current request, the user is authenticated.
    */
+  @RunAsClient
   @Test
   public void getSecurityContextTest() throws Fault {
     setProperty(Property.BASIC_AUTH_USER, user);
@@ -116,6 +118,7 @@
    * 
    * @test_Strategy: Make sure the authorization is needed
    */
+  @RunAsClient
   @Test
   public void noSecurityTest() throws Fault {
     String request = buildRequest(Request.POST, "");
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/core/securitycontext/basic/JAXRSBasicClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/core/securitycontext/basic/JAXRSBasicClientIT.java
index 3e1d2ba..ea545db 100644
--- a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/core/securitycontext/basic/JAXRSBasicClientIT.java
+++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/core/securitycontext/basic/JAXRSBasicClientIT.java
@@ -24,14 +24,13 @@
 
 import jakarta.ws.rs.core.Response;
 
+import org.jboss.arquillian.container.test.api.RunAsClient;
 import org.jboss.arquillian.junit5.ArquillianExtension;
 import org.jboss.arquillian.container.test.api.Deployment;
 import org.jboss.shrinkwrap.api.ShrinkWrap;
 import org.jboss.shrinkwrap.api.asset.StringAsset;
 import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.api.exporter.ZipExporter;
 
-import static org.junit.jupiter.api.Assertions.fail;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.junit.jupiter.api.TestInfo;
@@ -67,7 +66,7 @@
     TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName());
   }
 
-  @Deployment(testable = false)
+  @Deployment(testable = true)
   public static WebArchive createDeployment() throws IOException {
 
     InputStream inStream = JAXRSBasicClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/ee/rs/core/securitycontext/basic/web.xml.template");
@@ -80,7 +79,7 @@
       jakarta.ws.rs.tck.ee.rs.core.securitycontext.TestServlet.Scheme.class,
       jakarta.ws.rs.tck.ee.rs.core.securitycontext.TestServlet.Role.class);
     archive.setWebXML(new StringAsset(webXml));
-    archive.addAsWebInfResource("jakarta/ws/rs/tck/ee/rs/core/securitycontext/basic/jaxrs_ee_core_securitycontext_basic_web.war.sun-web.xml", "sun-web.xml");
+//    archive.addAsWebInfResource("jakarta/ws/rs/tck/ee/rs/core/securitycontext/basic/jaxrs_ee_core_securitycontext_basic_web.war.sun-web.xml", "sun-web.xml");
     return archive;
 
   }
@@ -95,6 +94,7 @@
    * @test_Strategy: Send no authorization, make sure of 401 response
    */
   @Test
+  @RunAsClient
   public void noAuthorizationTest() throws Fault {
     super.noAuthorizationTest();
   }
@@ -108,6 +108,7 @@
    * @test_Strategy: Send basic authorization, check security context
    */
   @Test
+  @RunAsClient
   public void basicAuthorizationAdminTest() throws Fault {
     setProperty(Property.STATUS_CODE, getStatusCode(Response.Status.OK));
     setProperty(Property.BASIC_AUTH_USER, user);
@@ -128,6 +129,7 @@
    * @test_Strategy: Send basic authorization, check security context
    */
   @Test
+  @RunAsClient
   public void basicAuthorizationIncorrectUserTest() throws Fault {
     setProperty(Property.STATUS_CODE,
         getStatusCode(Response.Status.UNAUTHORIZED));
@@ -144,6 +146,7 @@
    * @test_Strategy: Send basic authorization, check security context
    */
   @Test
+  @RunAsClient
   public void basicAuthorizationIncorrectPasswordTest() throws Fault {
     setProperty(Property.STATUS_CODE,
         getStatusCode(Response.Status.UNAUTHORIZED));
@@ -162,6 +165,7 @@
    * context
    */
   @Test
+  @RunAsClient
   public void basicAuthorizationStandardUserTest() throws Fault {
     setProperty(Property.STATUS_CODE, getStatusCode(Response.Status.OK));
     setProperty(Property.BASIC_AUTH_USER, authuser);
diff --git a/jersey-tck/pom.xml b/jersey-tck/pom.xml
index 0ac8ccb..e4caf57 100644
--- a/jersey-tck/pom.xml
+++ b/jersey-tck/pom.xml
@@ -23,7 +23,7 @@
     <groupId>org.glassfish.jersey.core</groupId>
     <artifactId>jersey-tck</artifactId>
     <version>3.1.0</version>
-    <packaging>pom</packaging>
+    <packaging>jar</packaging>
 
     <name>Jakarta RESTful WS Compliance</name>
     <description>This test verifies the compliance of Eclipse Jersey with Jakarta REST</description>
diff --git a/jersey-tck/src/main/java/org/glassfish/jersey/core/tck/JerseyApplicationArchiveProcessor.java b/jersey-tck/src/main/java/org/glassfish/jersey/core/tck/JerseyApplicationArchiveProcessor.java
new file mode 100644
index 0000000..e250eea
--- /dev/null
+++ b/jersey-tck/src/main/java/org/glassfish/jersey/core/tck/JerseyApplicationArchiveProcessor.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2021 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.core.tck;
+
+import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor;
+import org.jboss.arquillian.test.spi.TestClass;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+
+public class JerseyApplicationArchiveProcessor implements ApplicationArchiveProcessor {
+    @Override
+    public void process(Archive<?> archive, TestClass testClass) {
+        if ("jaxrs_ee_rs_container_requestcontext_security_web.war".equals(archive.getName())) {
+            WebArchive webArchive = (WebArchive) archive;
+            webArchive.addAsWebInfResource("jaxrs_ee_rs_container_requestcontext_security_web.war.sun-web.xml", "sun-web.xml");
+        } else if ("jaxrs_ee_core_securitycontext_basic_web.war".equals(archive.getName())) {
+            WebArchive webArchive = (WebArchive) archive;
+            webArchive.addAsWebInfResource("jaxrs_ee_core_securitycontext_basic_web.war.sun-web.xml", "sun-web.xml");
+        }
+    }
+}
diff --git a/jersey-tck/src/main/java/org/glassfish/jersey/core/tck/JerseyLoadableExtension.java b/jersey-tck/src/main/java/org/glassfish/jersey/core/tck/JerseyLoadableExtension.java
new file mode 100644
index 0000000..968fb6f
--- /dev/null
+++ b/jersey-tck/src/main/java/org/glassfish/jersey/core/tck/JerseyLoadableExtension.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2021 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.core.tck;
+
+import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor;
+import org.jboss.arquillian.core.spi.LoadableExtension;
+
+public class JerseyLoadableExtension implements LoadableExtension {
+    @Override
+    public void register(ExtensionBuilder extensionBuilder) {
+        extensionBuilder.service(ApplicationArchiveProcessor.class, JerseyApplicationArchiveProcessor.class);
+    }
+}
diff --git a/jersey-tck/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension b/jersey-tck/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension
new file mode 100644
index 0000000..577c00f
--- /dev/null
+++ b/jersey-tck/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension
@@ -0,0 +1 @@
+org.glassfish.jersey.core.tck.JerseyLoadableExtension
\ No newline at end of file
diff --git a/jersey-tck/src/main/resources/jaxrs_ee_core_securitycontext_basic_web.war.sun-web.xml b/jersey-tck/src/main/resources/jaxrs_ee_core_securitycontext_basic_web.war.sun-web.xml
new file mode 100644
index 0000000..84d84bc
--- /dev/null
+++ b/jersey-tck/src/main/resources/jaxrs_ee_core_securitycontext_basic_web.war.sun-web.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright (c) 2012, 2021 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 Sun ONE Application Server 8.0 Servlet 2.4//EN" "http://www.sun.com/software/sunone/appserver/dtds/sun-web-app_2_5-0.dtd">
+<sun-web-app>
+  <context-root>jaxrs_ee_core_securitycontext_basic_web</context-root>
+  <security-role-mapping>
+    <role-name>DIRECTOR</role-name>
+    <principal-name>j2ee</principal-name>
+  </security-role-mapping>
+  <security-role-mapping>
+    <role-name>OTHERROLE</role-name>
+    <principal-name>javajoe</principal-name>
+  </security-role-mapping>    
+</sun-web-app>
diff --git a/jersey-tck/src/main/resources/jaxrs_ee_rs_container_requestcontext_security_web.war.sun-web.xml b/jersey-tck/src/main/resources/jaxrs_ee_rs_container_requestcontext_security_web.war.sun-web.xml
new file mode 100644
index 0000000..1ba5a07
--- /dev/null
+++ b/jersey-tck/src/main/resources/jaxrs_ee_rs_container_requestcontext_security_web.war.sun-web.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright (c) 2012, 2021 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 Sun ONE Application Server 8.0 Servlet 2.4//EN" "http://www.sun.com/software/sunone/appserver/dtds/sun-web-app_2_5-0.dtd">
+<sun-web-app>
+  <context-root>jaxrs_ee_rs_container_requestcontext_security_web</context-root>
+  <security-role-mapping>
+    <role-name>DIRECTOR</role-name>
+    <principal-name>j2ee</principal-name>
+  </security-role-mapping>
+</sun-web-app>