You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2024/02/27 09:19:39 UTC

(logging-log4j2) 02/04: Fix OSGi tests

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

pkarwasz pushed a commit to branch fix/rollback-log4j-api
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit c4772695017d76888c3797d64a3f3148c9463313
Author: Piotr P. Karwasz <pi...@karwasz.org>
AuthorDate: Mon Feb 19 14:12:43 2024 +0100

    Fix OSGi tests
---
 .../log4j/osgi/tests/AbstractLoadBundleTest.java   | 38 +++++++++++++---------
 .../logging/log4j/osgi/tests/CoreOsgiTest.java     |  1 +
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/log4j-osgi-test/src/test/java/org/apache/logging/log4j/osgi/tests/AbstractLoadBundleTest.java b/log4j-osgi-test/src/test/java/org/apache/logging/log4j/osgi/tests/AbstractLoadBundleTest.java
index 7b4b5f449c..abc6e8d12f 100644
--- a/log4j-osgi-test/src/test/java/org/apache/logging/log4j/osgi/tests/AbstractLoadBundleTest.java
+++ b/log4j-osgi-test/src/test/java/org/apache/logging/log4j/osgi/tests/AbstractLoadBundleTest.java
@@ -80,6 +80,10 @@ abstract class AbstractLoadBundleTest {
         return installBundle("org.apache.logging.log4j.plugins");
     }
 
+    private Bundle getSdkBundle() throws BundleException {
+        return installBundle("org.apache.logging.log4j.sdk");
+    }
+
     private Bundle getCoreBundle() throws BundleException {
         return installBundle("org.apache.logging.log4j.core");
     }
@@ -101,21 +105,23 @@ abstract class AbstractLoadBundleTest {
         final List<Bundle> spiFly = startApacheSpiFly();
         final Bundle api = getApiBundle();
         final Bundle plugins = getPluginsBundle();
+        final Bundle sdk = getSdkBundle();
         final Bundle core = getCoreBundle();
 
-        Assert.assertEquals("api is not in INSTALLED state", Bundle.INSTALLED, api.getState());
-        Assert.assertEquals("plugins is not in INSTALLED state", Bundle.INSTALLED, plugins.getState());
-        Assert.assertEquals("core is not in INSTALLED state", Bundle.INSTALLED, core.getState());
+        assertEquals("api is not in INSTALLED state", Bundle.INSTALLED, api.getState());
+        assertEquals("plugins is not in INSTALLED state", Bundle.INSTALLED, plugins.getState());
+        assertEquals("sdk is not in INSTALLED state", Bundle.INSTALLED, sdk.getState());
+        assertEquals("core is not in INSTALLED state", Bundle.INSTALLED, core.getState());
 
         // 1st start-stop
-        doOnBundlesAndVerifyState(Bundle::start, Bundle.ACTIVE, api, plugins, core);
-        doOnBundlesAndVerifyState(Bundle::stop, Bundle.RESOLVED, core, plugins, api);
+        doOnBundlesAndVerifyState(Bundle::start, Bundle.ACTIVE, api, sdk, plugins, core);
+        doOnBundlesAndVerifyState(Bundle::stop, Bundle.RESOLVED, core, plugins, sdk, api);
 
         // 2nd start-stop
-        doOnBundlesAndVerifyState(Bundle::start, Bundle.ACTIVE, api, plugins, core);
-        doOnBundlesAndVerifyState(Bundle::stop, Bundle.RESOLVED, core, plugins, api);
+        doOnBundlesAndVerifyState(Bundle::start, Bundle.ACTIVE, api, sdk, plugins, core);
+        doOnBundlesAndVerifyState(Bundle::stop, Bundle.RESOLVED, core, plugins, sdk, api);
 
-        doOnBundlesAndVerifyState(Bundle::uninstall, Bundle.UNINSTALLED, core, plugins, api);
+        doOnBundlesAndVerifyState(Bundle::uninstall, Bundle.UNINSTALLED, core, plugins, sdk, api);
         uninstall(spiFly);
     }
 
@@ -128,9 +134,10 @@ abstract class AbstractLoadBundleTest {
         final List<Bundle> spiFly = startApacheSpiFly();
         final Bundle api = getApiBundle();
         final Bundle plugins = getPluginsBundle();
+        final Bundle sdk = getSdkBundle();
         final Bundle core = getCoreBundle();
 
-        doOnBundlesAndVerifyState(Bundle::start, Bundle.ACTIVE, api, plugins);
+        doOnBundlesAndVerifyState(Bundle::start, Bundle.ACTIVE, api, sdk, plugins);
         // fails if LOG4J2-1637 is not fixed
         try {
             core.start();
@@ -150,8 +157,8 @@ abstract class AbstractLoadBundleTest {
         }
         assertEquals(String.format("`%s` bundle state mismatch", core), Bundle.ACTIVE, core.getState());
 
-        doOnBundlesAndVerifyState(Bundle::stop, Bundle.RESOLVED, core, plugins, api);
-        doOnBundlesAndVerifyState(Bundle::uninstall, Bundle.UNINSTALLED, core, plugins, api);
+        doOnBundlesAndVerifyState(Bundle::stop, Bundle.RESOLVED, core, plugins, sdk, api);
+        doOnBundlesAndVerifyState(Bundle::uninstall, Bundle.UNINSTALLED, core, plugins, sdk, api);
         uninstall(spiFly);
     }
 
@@ -164,17 +171,18 @@ abstract class AbstractLoadBundleTest {
 
         final List<Bundle> spiFly = startApacheSpiFly();
         final Bundle api = getApiBundle();
+        final Bundle sdk = getSdkBundle();
         final Bundle plugins = getPluginsBundle();
         final Bundle core = getCoreBundle();
         final Bundle compat = get12ApiBundle();
 
-        doOnBundlesAndVerifyState(Bundle::start, Bundle.ACTIVE, api, plugins, core);
+        doOnBundlesAndVerifyState(Bundle::start, Bundle.ACTIVE, api, sdk, plugins, core);
 
         final Class<?> coreClassFromCore = core.loadClass("org.apache.logging.log4j.core.Core");
         final Class<?> levelClassFrom12API = core.loadClass("org.apache.log4j.Level");
         final Class<?> levelClassFromAPI = core.loadClass("org.apache.logging.log4j.Level");
 
-        Assert.assertEquals(
+        assertEquals(
                 "expected 1.2 API Level to have the same class loader as Core",
                 levelClassFrom12API.getClassLoader(),
                 coreClassFromCore.getClassLoader());
@@ -183,8 +191,8 @@ abstract class AbstractLoadBundleTest {
                 levelClassFrom12API.getClassLoader(),
                 levelClassFromAPI.getClassLoader());
 
-        doOnBundlesAndVerifyState(Bundle::stop, Bundle.RESOLVED, core, plugins, api);
-        doOnBundlesAndVerifyState(Bundle::uninstall, Bundle.UNINSTALLED, compat, core, plugins, api);
+        doOnBundlesAndVerifyState(Bundle::stop, Bundle.RESOLVED, core, plugins, sdk, api);
+        doOnBundlesAndVerifyState(Bundle::uninstall, Bundle.UNINSTALLED, compat, core, plugins, sdk, api);
         uninstall(spiFly);
     }
 
diff --git a/log4j-osgi-test/src/test/java/org/apache/logging/log4j/osgi/tests/CoreOsgiTest.java b/log4j-osgi-test/src/test/java/org/apache/logging/log4j/osgi/tests/CoreOsgiTest.java
index 2d5ee6c23b..06bf1a029f 100644
--- a/log4j-osgi-test/src/test/java/org/apache/logging/log4j/osgi/tests/CoreOsgiTest.java
+++ b/log4j-osgi-test/src/test/java/org/apache/logging/log4j/osgi/tests/CoreOsgiTest.java
@@ -48,6 +48,7 @@ public class CoreOsgiTest {
         return options(
                 linkBundle("org.apache.logging.log4j.api"),
                 linkBundle("org.apache.logging.log4j.plugins"),
+                linkBundle("org.apache.logging.log4j.sdk"),
                 linkBundle("org.apache.logging.log4j.core"),
                 linkBundle("org.apache.logging.log4j.1.2.api").start(false),
                 // required by Pax Exam's logging