Exception when using AemContext

1,194 views
Skip to first unread message

Roy Teeuwen

unread,
Dec 21, 2017, 3:13:23 AM12/21/17
to wcm-io Developers
Hey guys,

I am trying to use aem mocks (2.2.8) for the first time in an existing project. When using @SlingContext I don't have any issues, but when using @AemContext, I get the following stacktrace. Looks familiar to anyone or has a suggestion on how to fix?

Thanks!
Roy

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:320)
at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeBindUnbindMethod(OsgiServiceUtil.java:443)
at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeBindMethod(OsgiServiceUtil.java:583)
at org.apache.sling.testing.mock.osgi.MockBundleContext.handleRefsUpdateOnRegister(MockBundleContext.java:153)
at org.apache.sling.testing.mock.osgi.MockBundleContext.registerService(MockBundleContext.java:123)
at org.apache.sling.testing.mock.osgi.MockBundleContext.registerService(MockBundleContext.java:108)
at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerService(OsgiContextImpl.java:117)
at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:155)
at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:141)
at io.wcm.testing.mock.aem.context.AemContextImpl.registerDefaultServices(AemContextImpl.java:58)
at org.apache.sling.testing.mock.sling.context.SlingContextImpl.setUp(SlingContextImpl.java:117)
at io.wcm.testing.mock.aem.context.AemContextImpl.setUp(AemContextImpl.java:74)
at io.wcm.testing.mock.aem.junit.AemContext.access$100(AemContext.java:48)
at io.wcm.testing.mock.aem.junit.AemContext$1.before(AemContext.java:156)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:44)
at org.junit.rules.RunRules.evaluate(RunRules.java:18)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
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.NoSuchMethodError: org.apache.sling.adapter.internal.AdapterFactoryDescriptor.<init>(Lorg/osgi/service/component/ComponentContext;Lorg/osgi/framework/ServiceReference;[Ljava/lang/String;)V
at org.apache.sling.testing.mock.sling.MockAdapterManagerImpl.registerAdapterFactory(MockAdapterManagerImpl.java:275)
at org.apache.sling.testing.mock.sling.MockAdapterManagerImpl.bindAdapterFactory(MockAdapterManagerImpl.java:212)
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:498)
at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeMethod(OsgiServiceUtil.java:311)
... 29 more

Stefan Seifert

unread,
Dec 21, 2017, 3:29:42 AM12/21/17
to wcm-i...@googlegroups.com
it looks as if you have a dependency version mismatch in your build oder test classpath.

ususally the following thinks work:

1. put your aem-mock test dependencies first, and the uber jar AEM deps 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 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.

stefan
>--
>You received this message because you are subscribed to the Google Groups
>"wcm-io Developers" group.
>To unsubscribe from this group and stop receiving emails from it, send an
>email to wcm-io-dev+...@googlegroups.com.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/wcm-io-dev/833b56a2-8c2a-4c65-b7f9-
>eedb7184b961%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages