From fa0989071af6988414ed933cbf891cb6390adc11 Mon Sep 17 00:00:00 2001 From: Gurunandan Rao Date: Fri, 1 Dec 2023 11:52:39 +0530 Subject: [PATCH] default porting class fix. Signed-off-by: Gurunandan Rao --- glassfish-runner/saaj-tck/pom.xml | 5 +- glassfishtck/pom.xml | 44 +++++---- .../java/com/sun/ts/lib/porting/TSURL.java | 8 +- .../com/sun/ts/tests/saaj/common/Client.java | 92 +++++++++++++++++++ 4 files changed, 119 insertions(+), 30 deletions(-) create mode 100644 saaj/src/main/java/com/sun/ts/tests/saaj/common/Client.java diff --git a/glassfish-runner/saaj-tck/pom.xml b/glassfish-runner/saaj-tck/pom.xml index 133d954f4b..0f5f803d10 100644 --- a/glassfish-runner/saaj-tck/pom.xml +++ b/glassfish-runner/saaj-tck/pom.xml @@ -154,9 +154,6 @@ verify - **/*Client*.* @@ -169,7 +166,7 @@ ${project.build.directory}/${glassfish.toplevel.dir} localhost 8080 - com.sun.ts.tests.saaj.lib.implementation.sun.common.SunRIURL + com.sun.ts.lib.porting.implementation.SunRIURL diff --git a/glassfishtck/pom.xml b/glassfishtck/pom.xml index b8d324bb03..6a3f89b965 100644 --- a/glassfishtck/pom.xml +++ b/glassfishtck/pom.xml @@ -17,28 +17,26 @@ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 --> - - - 4.0.0 - - - jakartatck - project - 10.0.0-SNAPSHOT - - - glassfishtck - jar - - glassfishtck - glassfishtck - - - - ${project.groupId} - runtime - - + + 4.0.0 + + + jakartatck + project + 10.0.0-SNAPSHOT + + + glassfishtck + jar + + glassfishtck + glassfishtck + + + + ${project.groupId} + runtime + + diff --git a/runtime/src/main/java/com/sun/ts/lib/porting/TSURL.java b/runtime/src/main/java/com/sun/ts/lib/porting/TSURL.java index d5003ca1af..32d4d9db5f 100644 --- a/runtime/src/main/java/com/sun/ts/lib/porting/TSURL.java +++ b/runtime/src/main/java/com/sun/ts/lib/porting/TSURL.java @@ -37,6 +37,8 @@ public class TSURL implements TSURLInterface, Serializable { private TSURLInterface ctsURL = null; private String sClass = "porting.ts.url.class.1"; + + private String portingDefault = "com.sun.ts.lib.porting.implementation.SunRIURL"; public TSURL() { // we'll initialize the impl when the individual method is called @@ -66,7 +68,7 @@ public URL getURL(String protocol, String host, int port, String file) if (ctsURL == null) { try { // create and initialize a new instance of TSURLInterface - Class c = Class.forName(TestUtil.getProperty(sClass)); + Class c = Class.forName(System.getProperty(sClass, portingDefault)); ctsURL = (TSURLInterface) c.newInstance(); } catch (Exception e) { e.printStackTrace(); @@ -95,7 +97,7 @@ public String getURLString(String protocol, String host, int port, if (ctsURL == null) { try { // create and initialize a new instance of TSURLInterface - Class c = Class.forName(TestUtil.getProperty(sClass)); + Class c = Class.forName(System.getProperty(sClass, portingDefault)); ctsURL = (TSURLInterface) c.newInstance(); } catch (Exception e) { e.printStackTrace(); @@ -118,7 +120,7 @@ public String getRequest(String request) { // create and initialize a new instance of TSURLInterface // Class c = Class.forName(TestUtil.getProperty(sClass)); // Use the system property porting.ts.url.class.1 - Class c = Class.forName(System.getProperty(sClass, "com.sun.ts.tests.jaxrs.lib.implementation.sun.common.SunRIURL")); + Class c = Class.forName(System.getProperty(sClass, portingDefault)); ctsURL = (TSURLInterface) c.newInstance(); } catch (Exception e) { e.printStackTrace(); diff --git a/saaj/src/main/java/com/sun/ts/tests/saaj/common/Client.java b/saaj/src/main/java/com/sun/ts/tests/saaj/common/Client.java new file mode 100644 index 0000000000..7be11ced49 --- /dev/null +++ b/saaj/src/main/java/com/sun/ts/tests/saaj/common/Client.java @@ -0,0 +1,92 @@ +package com.sun.ts.tests.saaj.common; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.System.Logger; +import java.net.URL; +import java.net.URLConnection; +import java.util.Properties; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.asset.ByteArrayAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.porting.TSURL; + +@ExtendWith(ArquillianExtension.class) +public class Client { + + protected static final String PROTOCOL = "http"; + + protected static final String HOSTNAME = "localhost"; + + protected static final int PORTNUM = 8000; + + public static final String WEBSERVERHOSTPROP = "webServerHost"; + + public static final String WEBSERVERPORTPROP = "webServerPort"; + + protected TSURL tsurl = new TSURL(); + + protected URL url = null; + + protected URLConnection urlConn = null; + + protected Properties props = new Properties(); + + protected String hostname = HOSTNAME; + + protected int portnum = PORTNUM; + + private static final Logger logger = (Logger) System.getLogger(Client.class.getName()); + + public static void addFilesToArchive(String contentRoot, String[] fileNames, WebArchive archive) + throws IOException { + for (String fileName : fileNames) { + InputStream inStream = Thread.currentThread().getContextClassLoader() + .getResourceAsStream(contentRoot + fileName); + ByteArrayAsset attach = new ByteArrayAsset(inStream); + archive.add(attach, fileName); + } + } + + /* + * @class.setup_props: webServerHost; webServerPort; + */ + @BeforeEach + public void setup() throws Exception { + boolean pass = true; + + try { + hostname = System.getProperty(WEBSERVERHOSTPROP); + if (hostname == null) + pass = false; + else if (hostname.equals("")) + pass = false; + try { + portnum = Integer.parseInt(System.getProperty(WEBSERVERPORTPROP)); + } catch (Exception e) { + pass = false; + } + } catch (Exception e) { + throw new Exception("setup failed:", e); + } + props.put(WEBSERVERHOSTPROP, hostname); + props.put(WEBSERVERPORTPROP, String.valueOf(portnum)); + if (!pass) { + logger.log(Logger.Level.ERROR, "Please specify host & port of web server " + "in config properties: " + + WEBSERVERHOSTPROP + ", " + WEBSERVERPORTPROP); + throw new Exception("setup failed:"); + } + logger.log(Logger.Level.INFO, "setup ok"); + } + + @AfterEach + public void cleanup() throws Exception { + logger.log(Logger.Level.INFO, "cleanup ok"); + } + +}