1717package org .apache .logging .log4j .osgi .tests ;
1818
1919import static org .junit .Assert .assertEquals ;
20- import static org .junit .Assert .assertTrue ;
2120
22- import java .lang .reflect .Method ;
23- import java .util .List ;
24- import java .util .stream .Collectors ;
25- import java .util .stream .Stream ;
26- import org .apache .logging .log4j .util .ServiceLoaderUtil ;
2721import org .junit .Assert ;
2822import org .junit .Before ;
2923import org .junit .Rule ;
@@ -59,6 +53,17 @@ private Bundle installBundle(final String symbolicName) throws BundleException {
5953 return bundleContext .installBundle (url );
6054 }
6155
56+ private Bundle startApacheSpiFly () throws BundleException {
57+ installBundle ("org.objectweb.asm" );
58+ installBundle ("org.objectweb.asm.commons" );
59+ installBundle ("org.objectweb.asm.tree" );
60+ installBundle ("org.objectweb.asm.tree.analysis" );
61+ installBundle ("org.objectweb.asm.util" );
62+ final Bundle spiFly = installBundle ("org.apache.aries.spifly.dynamic.bundle" );
63+ spiFly .start ();
64+ return spiFly ;
65+ }
66+
6267 private Bundle getApiBundle () throws BundleException {
6368 return installBundle ("org.apache.logging.log4j.api" );
6469 }
@@ -85,6 +90,7 @@ private Bundle getApiTestsBundle() throws BundleException {
8590 @ Test
8691 public void testApiCoreStartStopStartStop () throws BundleException {
8792
93+ final Bundle spiFly = startApacheSpiFly ();
8894 final Bundle api = getApiBundle ();
8995 final Bundle plugins = getPluginsBundle ();
9096 final Bundle core = getCoreBundle ();
@@ -102,6 +108,7 @@ public void testApiCoreStartStopStartStop() throws BundleException {
102108 doOnBundlesAndVerifyState (Bundle ::stop , Bundle .RESOLVED , core , plugins , api );
103109
104110 doOnBundlesAndVerifyState (Bundle ::uninstall , Bundle .UNINSTALLED , core , plugins , api );
111+ spiFly .uninstall ();
105112 }
106113
107114 /**
@@ -110,6 +117,7 @@ public void testApiCoreStartStopStartStop() throws BundleException {
110117 @ Test
111118 public void testClassNotFoundErrorLogger () throws BundleException {
112119
120+ final Bundle spiFly = startApacheSpiFly ();
113121 final Bundle api = getApiBundle ();
114122 final Bundle plugins = getPluginsBundle ();
115123 final Bundle core = getCoreBundle ();
@@ -136,6 +144,7 @@ public void testClassNotFoundErrorLogger() throws BundleException {
136144
137145 doOnBundlesAndVerifyState (Bundle ::stop , Bundle .RESOLVED , core , plugins , api );
138146 doOnBundlesAndVerifyState (Bundle ::uninstall , Bundle .UNINSTALLED , core , plugins , api );
147+ spiFly .uninstall ();
139148 }
140149
141150 /**
@@ -145,6 +154,7 @@ public void testClassNotFoundErrorLogger() throws BundleException {
145154 @ Test
146155 public void testLog4J12Fragement () throws BundleException , ReflectiveOperationException {
147156
157+ final Bundle spiFly = startApacheSpiFly ();
148158 final Bundle api = getApiBundle ();
149159 final Bundle plugins = getPluginsBundle ();
150160 final Bundle core = getCoreBundle ();
@@ -167,38 +177,7 @@ public void testLog4J12Fragement() throws BundleException, ReflectiveOperationEx
167177
168178 doOnBundlesAndVerifyState (Bundle ::stop , Bundle .RESOLVED , core , plugins , api );
169179 doOnBundlesAndVerifyState (Bundle ::uninstall , Bundle .UNINSTALLED , compat , core , plugins , api );
170- }
171-
172- /**
173- * Tests whether the {@link ServiceLoaderUtil} finds services in other bundles.
174- */
175- @ Test
176- public void testServiceLoader () throws BundleException , ReflectiveOperationException {
177- final Bundle api = getApiBundle ();
178- final Bundle core = getCoreBundle ();
179- final Bundle apiTests = getApiTestsBundle ();
180-
181- final Class <?> osgiServiceLocator = api .loadClass ("org.apache.logging.log4j.util.OsgiServiceLocator" );
182- assertTrue ("OsgiServiceLocator is active" , (boolean )
183- osgiServiceLocator .getMethod ("isAvailable" ).invoke (null ));
184-
185- doOnBundlesAndVerifyState (Bundle ::start , Bundle .ACTIVE , api , core , apiTests );
186-
187- final Class <?> osgiServiceLocatorTest =
188- apiTests .loadClass ("org.apache.logging.log4j.test.util.OsgiServiceLocatorTest" );
189-
190- final Method loadProviders = osgiServiceLocatorTest .getDeclaredMethod ("loadProviders" );
191- final Object obj = loadProviders .invoke (null );
192- assertTrue (obj instanceof Stream );
193- @ SuppressWarnings ("unchecked" )
194- final List <Object > services = ((Stream <Object >) obj ).collect (Collectors .toList ());
195- assertEquals (1 , services .size ());
196- assertEquals (
197- "org.apache.logging.log4j.core.impl.Log4jProvider" ,
198- services .get (0 ).getClass ().getName ());
199-
200- doOnBundlesAndVerifyState (Bundle ::stop , Bundle .RESOLVED , apiTests , core , api );
201- doOnBundlesAndVerifyState (Bundle ::uninstall , Bundle .UNINSTALLED , apiTests , core , api );
180+ spiFly .uninstall ();
202181 }
203182
204183 private static void doOnBundlesAndVerifyState (
0 commit comments