You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2023/04/25 16:50:25 UTC

[cxf] 21/39: When running a test within Eclipse or other IDE, try to pickup the same logging.properties file that mvn would use

This is an automated email from the ASF dual-hosted git repository.

dkulp pushed a commit to branch 3.6.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 2b8842320a6cabcb95aec8476e34fdc4ce4525e1
Author: Daniel Kulp <da...@kulp.com>
AuthorDate: Wed Mar 15 14:28:40 2023 -0400

    When running a test within Eclipse or other IDE, try to pickup the same logging.properties file that mvn would use
    
    (cherry picked from commit 3acb68077fd7c47a5297e337de61e60d4ebb0c7b)
---
 .../common/AbstractClientServerTestBase.java       | 32 ++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/testutils/src/main/java/org/apache/cxf/testutil/common/AbstractClientServerTestBase.java b/testutils/src/main/java/org/apache/cxf/testutil/common/AbstractClientServerTestBase.java
index 858b3ea39a..4316563d05 100644
--- a/testutils/src/main/java/org/apache/cxf/testutil/common/AbstractClientServerTestBase.java
+++ b/testutils/src/main/java/org/apache/cxf/testutil/common/AbstractClientServerTestBase.java
@@ -20,10 +20,12 @@
 package org.apache.cxf.testutil.common;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.logging.LogManager;
 
 import org.junit.AfterClass;
 
@@ -32,6 +34,31 @@ import static org.junit.Assert.fail;
 
 public abstract class AbstractClientServerTestBase {
     private static List<ServerLauncher> launchers = new ArrayList<>();
+    private static boolean firstLaunch = true;
+    
+    private static synchronized void checkFirstLaunch(Class<?> cls) {
+        if (firstLaunch) {
+            firstLaunch = false;
+            //make sure we use the logging.properties file for the test class
+            //mvn will pass the system property, but Eclipse or other IDE 
+            //may not so lets just grab the file and make sure we use it
+            //so that we use the same logging setup as mvn on the command
+            //line so things like the logging interceptors on the chain
+            //will match and not have additional side effects compared
+            //to the command line
+            String jdkl = System.getProperty("java.util.logging.config.file");
+            if (jdkl == null) {
+                InputStream in = cls.getResourceAsStream("/logging.properties");
+                if (in != null) {
+                    try {
+                        LogManager.getLogManager().readConfiguration(in);
+                    } catch (SecurityException | IOException e) {
+                        //ignore
+                    }
+                }
+            }
+        }
+    }
 
 
     @AfterClass
@@ -62,6 +89,7 @@ public abstract class AbstractClientServerTestBase {
     public static boolean launchServer(AbstractTestServerBase base) {
         boolean ok = false;
         try {
+            checkFirstLaunch(base.getClass());
             ServerLauncher sl = new ServerLauncher(base);
             ok = sl.launchServer();
             assertTrue("server failed to launch", ok);
@@ -87,6 +115,7 @@ public abstract class AbstractClientServerTestBase {
     public static boolean launchServer(Class<?> clz, boolean inProcess) {
         boolean ok = false;
         try {
+            checkFirstLaunch(clz);
             ServerLauncher sl = new ServerLauncher(clz.getName(), inProcess);
             ok = sl.launchServer();
             assertTrue("server failed to launch", ok);
@@ -113,6 +142,7 @@ public abstract class AbstractClientServerTestBase {
                                 boolean inProcess) {
         boolean ok = false;
         try {
+            checkFirstLaunch(clz);
             ServerLauncher sl = new ServerLauncher(clz.getName(), props, args, inProcess);
             ok = sl.launchServer();
             assertTrue("server failed to launch", ok);
@@ -138,9 +168,11 @@ public abstract class AbstractClientServerTestBase {
         return TestUtil.getPortNumber(s);
     }
     protected static String allocatePort(Class<?> cls) {
+        checkFirstLaunch(cls);
         return TestUtil.getPortNumber(cls);
     }
     protected static String allocatePort(Class<?> cls, int count) {
+        checkFirstLaunch(cls);
         return TestUtil.getPortNumber(cls, count);
     }