Jens Lauterbach created SLING-7195: -------------------------------------- Summary: Sling Mock Oak not working with AEM uber-jar 6.3.0 Key: SLING-7195 URL: https://issues.apache.org/jira/browse/SLING-7195 Project: Sling Issue Type: Bug Components: Testing Affects Versions: Testing Sling Mock Oak 2.0.2 Environment: AEM 6.3.0 Reporter: Jens Lauterbach Priority: Minor
When running unit tests using the Sling Mock Oak repository the tests will fail if AEMs {{uber-jar}} is present in the classpath. This happens with the following versions: # {{org.apache.sling:org.apache.sling.testing.sling-mock-oak:2.0.2}} # {{com.adobe.aem:uber-jar:6.3.0}} h2. Exception {code} java.lang.RuntimeException: Unable to initialize JCR_OAK resource resolver factory: Unable to invoke method 'activate' for class org.apache.sling.testing.mock.sling.oak.OakMockSlingRepository at org.apache.sling.testing.mock.sling.context.ContextResourceResolverFactory.get(ContextResourceResolverFactory.java:66) at org.apache.sling.testing.mock.sling.context.SlingContextImpl.newResourceResolverFactory(SlingContextImpl.java:154) at org.apache.sling.testing.mock.sling.context.SlingContextImpl.setUp(SlingContextImpl.java:145) at org.apache.sling.testing.mock.sling.junit.SlingContext.access$100(SlingContext.java:40) at org.apache.sling.testing.mock.sling.junit.SlingContext$1.before(SlingContext.java:127) at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: java.lang.RuntimeException: Unable to invoke method 'activate' for class org.apache.sling.testing.mock.sling.oak.OakMockSlingRepository at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeMethod(OsgiServiceUtil.java:320) at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeLifecycleMethod(OsgiServiceUtil.java:149) at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.activateDeactivate(OsgiServiceUtil.java:84) at org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:169) at org.apache.sling.testing.mock.sling.ResourceResolverFactoryInitializer.registerServiceIfNotPresent(ResourceResolverFactoryInitializer.java:155) at org.apache.sling.testing.mock.sling.ResourceResolverFactoryInitializer.registerServiceIfNotPresent(ResourceResolverFactoryInitializer.java:140) at org.apache.sling.testing.mock.sling.ResourceResolverFactoryInitializer.setUp(ResourceResolverFactoryInitializer.java:62) at org.apache.sling.testing.mock.sling.MockSling.newResourceResolverFactory(MockSling.java:75) at org.apache.sling.testing.mock.sling.context.ContextResourceResolverFactory.get(ContextResourceResolverFactory.java:45) ... 20 more Caused by: java.lang.NoClassDefFoundError: org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingConfigInitializer at org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent.initialize(InitialContent.java:88) at org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent.createInitialContent(InitialContent.java:61) at org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent.<clinit>(InitialContent.java:57) at org.apache.jackrabbit.oak.jcr.Jcr.<init>(Jcr.java:114) at org.apache.jackrabbit.oak.jcr.Jcr.<init>(Jcr.java:141) at org.apache.sling.testing.mock.sling.oak.OakMockSlingRepository.activate(OakMockSlingRepository.java:75) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeMethod(OsgiServiceUtil.java:311) ... 28 more Caused by: java.lang.ClassNotFoundException: org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingConfigInitializer at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 39 more {code} h2. Cause I debugged for a while and came to the conclusion that the main problem is that there are two versions of the {{org.apache.jackrabbit:oak-core}} and {{org.apache.jackrabbit:oak-jcr}} library present: # {{org.apache.sling:org.apache.sling.testing.sling-mock-oak:2.0.2}} provides/requires version {{1.4.1}} of both dependencies. # {{com.adobe.aem:uber-jar:6.3.0}} provides/requires version {{1.6.1}} of both dependencies. The exception is caused when {{org.apache.jackrabbit.oak.jcr.Jcr}} is instantiated. The constructor instantiates {{org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent}}. This class imports {{org.apache.jackrabbit.oak.plugins.document.bundlor.BundlingConfigInitializer}} in version {{1.6.1}} but not in version {{1.4.1}}. This is where the exception (see above) should be coming from. h2. Reproduce To reproduce this issue I have attached a small demo project. Just do the following: # Download and extract archive. # Run {{mvn clean test}}. # There will be no error. # Open {{pom.xml}} and make uber-jar dependency available by removing the comments. # Run {{mvn clean test}}. # Exception will appear. -- This message was sent by Atlassian JIRA (v6.4.14#64029)