Hi all,
I am trying to use JUnit 5 AEM Mocks(wcm.io) in our existing AEM project. I have included all the required dependencies and there are no compilation errors. However, I get the below error when I try to run my test. Has anyone seen this error and how did you manage to fix it?
java.lang.RuntimeException: Bind method with name bindEventAdmin not found for reference 'eventAdmin' for class org.apache.sling.testing.mock.sling.MockAdapterManagerImpl
at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeBindUnbindMethod(OsgiServiceUtil.java:717)
at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.injectServiceReference(OsgiServiceUtil.java:646)
Thanks!
Solved! Go to Solution.
Views
Replies
Total Likes
It looks like you have a dependency version mismatch.
1. put your aem-mock test dependencies first, and the uber jar AEM dependencies last in your project
2. import the dependendencies matching to the AEM version you compila against from the dependencies poms listed here http://wcm.io/tooling/maven/aem-dependencies.html
This will not only includes the matching uber jar, but also the versions of some sling implementation bundles required by sling mock and aem mock, matching those of the AEM version you are using.
It looks like you have a dependency version mismatch.
1. put your aem-mock test dependencies first, and the uber jar AEM dependencies last in your project
2. import the dependendencies matching to the AEM version you compila against from the dependencies poms listed here http://wcm.io/tooling/maven/aem-dependencies.html
This will not only includes the matching uber jar, but also the versions of some sling implementation bundles required by sling mock and aem mock, matching those of the AEM version you are using.
I was able to get my node property request's working by switching to ResourceResolverType.JCR_MOCK instead, and correcting my test dependencies to match the pom.xml in the example https://github.com/adobe/aem-guides-wknd
java.lang.RuntimeException: Unable to invoke method 'bindAdapterFactory' for class org.apache.sling.testing.mock.sling.MockAdapterManagerImpl
at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeMethod(OsgiServiceUtil.java:347)
at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeBindUnbindMethod(OsgiServiceUtil.java:667)
at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeBindMethod(OsgiServiceUtil.java:851)
at org.apache.sling.testing.mock.osgi.MockBundleContext.handleRefsUpdateOnRegister(MockBundleContext.java:164)
at org.apache.sling.testing.mock.osgi.MockBundleContext.registerService(MockBundleContext.java:127)
at org.apache.sling.testing.mock.osgi.MockBundleContext.registerService(MockBundleContext.java:112)
at org.apache.sling.models.impl.ModelPackageBundleListener.registerAdapterFactory(ModelPackageBundleListener.java:274)
at org.apache.sling.models.impl.ModelPackageBundleListener.analyzeClass(ModelPackageBundleListener.java:158)
at org.apache.sling.models.impl.ModelPackageBundleListener.addingBundle(ModelPackageBundleListener.java:125)
at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:439)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:261)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:233)
at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:413)
at org.apache.sling.testing.mock.osgi.MockBundleContext.sendBundleEvent(MockBundleContext.java:382)
at org.apache.sling.testing.mock.osgi.MockOsgi.sendBundleEvent(MockOsgi.java:62)
at org.apache.sling.testing.mock.sling.context.ModelAdapterFactoryUtil.addModelsForPackages(ModelAdapterFactoryUtil.java:95)
at org.apache.sling.testing.mock.sling.context.ModelAdapterFactoryUtil.addModelsForManifestEntries(ModelAdapterFactoryUtil.java:128)
at org.apache.sling.testing.mock.sling.context.SlingContextImpl.registerDefaultServices(SlingContextImpl.java:196)
at io.wcm.testing.mock.aem.context.AemContextImpl.registerDefaultServices(AemContextImpl.java:72)
at org.apache.sling.testing.mock.sling.context.SlingContextImpl.setUp(SlingContextImpl.java:137)
at io.wcm.testing.mock.aem.context.AemContextImpl.setUp(AemContextImpl.java:104)
at io.wcm.testing.mock.aem.junit5.AemContext.setUpContext(AemContext.java:100)
at io.wcm.testing.mock.aem.junit5.AemContextExtension.setAemContextInStore(AemContextExtension.java:73)
at io.wcm.testing.mock.aem.junit5.AemContextExtension.postProcessTestInstance(AemContextExtension.java:63)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$5(ClassBasedTestDescriptor.java:341)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.executeAndMaskThrowable(ClassBasedTestDescriptor.java:346)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$6(ClassBasedTestDescriptor.java:341)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:312)
at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)
at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734)
at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeTestInstancePostProcessors(ClassBasedTestDescriptor.java:340)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateAndPostProcessTestInstance(ClassBasedTestDescriptor.java:263)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$2(ClassBasedTestDescriptor.java:256)
at java.base/java.util.Optional.orElseGet(Optional.java:369)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$3(ClassBasedTestDescriptor.java:255)
at org.junit.jupiter.engine.execution.TestInstancesProvider.getTestInstances(TestInstancesProvider.java:29)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$prepare$0(TestMethodTestDescriptor.java:108)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:107)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:71)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$1(NodeTestTask.java:107)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:107)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:75)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:141)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:98)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: java.lang.NoSuchMethodError: org.osgi.framework.BundleContext.registerService(Ljava/lang/Class;Ljava/lang/Object;Ljava/util/Dictionary;)Lorg/osgi/framework/ServiceRegistration;
at org.apache.sling.testing.mock.sling.MockAdapterManagerImpl.registerAdapterFactory(MockAdapterManagerImpl.java:304)
at org.apache.sling.testing.mock.sling.MockAdapterManagerImpl.bindAdapterFactory(MockAdapterManagerImpl.java:215)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeMethod(OsgiServiceUtil.java:338)
... 83 more
Views
Replies
Total Likes