Expand my Community achievements bar.

SOLVED

AEM Mocks can not adaptTo(Node.class) from par

Avatar

Level 4

Hello, I try to adapt a parsys to Node, it does work with real AEM instance, but with mocking it returns null as subPageNode. As you see in debug mode the par is there.

Can any explain why this happens?

Br,

Tim

1360574_pastedImage_1.png

1360577_pastedImage_0.png

1 Accepted Solution

Avatar

Correct answer by
Level 4

I found this image which seems to point to use the right Mock ResourceResolver

1360590_pastedImage_0.png

But after adding the following dep to my pom.xml I get an error.

  <dependency>

            <groupId>org.apache.sling</groupId>

            <artifactId>org.apache.sling.testing.sling-mock-oak</artifactId>

            <version>2.0.2</version>

            <scope>test</scope>

        </dependency>

Error:

1784 [main] INFO org.apache.jackrabbit.oak.plugins.index.IndexUpdate - Found a new index node [reference]. Reindexing is requested

1797 [main] INFO org.apache.jackrabbit.oak.plugins.index.IndexUpdate - Reindexing will be performed for following indexes: [/oak:index/slingResourceType, /oak:index/slingAlias, /oak:index/uuid, /oak:index/slingVanityPath, /oak:index/slingResource, /oak:index/jcrLanguage, /oak:index/reference, /oak:index/jcrLockOwner, /oak:index/nodetype]

2063 [main] INFO org.apache.jackrabbit.oak.plugins.index.IndexUpdate - Indexing report

    - /oak:index/nodetype*(1238)

2282 [main] INFO org.apache.jackrabbit.oak.plugins.index.IndexUpdate - Reindexing will be performed for following indexes: [/oak:index/principalName, /oak:index/authorizableId, /oak:index/acPrincipalName]

2295 [main] INFO org.apache.jackrabbit.oak.plugins.index.IndexUpdate - Indexing report

    - /oak:index/principalName*(2)

    - /oak:index/authorizableId*(2)

3501 [main] INFO org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProvider - Detected Oak based repository. Using improved JCR Resource Listener with observation queue length 1000

4676 [main] INFO org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProvider - Detected Oak based repository. Using improved JCR Resource Listener with observation queue length 1000

Disconnected from the target VM, address: '127.0.0.1:60490', transport: 'socket'

java.lang.RuntimeException: Unable to invoke method 'deactivate' 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:142)

at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.activateDeactivate(OsgiServiceUtil.java:84)

at org.apache.sling.testing.mock.osgi.MockOsgi.deactivate(MockOsgi.java:216)

at org.apache.sling.testing.mock.osgi.MockBundleContext.shutdown(MockBundleContext.java:438)

at org.apache.sling.testing.mock.osgi.MockOsgi.shutdown(MockOsgi.java:315)

at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.tearDown(OsgiContextImpl.java:56)

at org.apache.sling.testing.mock.sling.context.SlingContextImpl.tearDown(SlingContextImpl.java:222)

at io.wcm.testing.mock.aem.context.AemContextImpl.tearDown(AemContextImpl.java:79)

at io.wcm.testing.mock.aem.junit.AemContext.access$200(AemContext.java:48)

at io.wcm.testing.mock.aem.junit.AemContext$1.after(AemContext.java:162)

at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:50)

at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)

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.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)

at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)

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.NoSuchMethodError: org.apache.commons.io.IOUtils.closeQuietly(Ljava/io/Closeable;)V

at org.apache.jackrabbit.oak.jcr.repository.RepositoryImpl.shutdown(RepositoryImpl.java:325)

at org.apache.sling.testing.mock.sling.oak.OakMockSlingRepository.deactivate(OakMockSlingRepository.java:92)

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

View solution in original post

2 Replies

Avatar

Correct answer by
Level 4

I found this image which seems to point to use the right Mock ResourceResolver

1360590_pastedImage_0.png

But after adding the following dep to my pom.xml I get an error.

  <dependency>

            <groupId>org.apache.sling</groupId>

            <artifactId>org.apache.sling.testing.sling-mock-oak</artifactId>

            <version>2.0.2</version>

            <scope>test</scope>

        </dependency>

Error:

1784 [main] INFO org.apache.jackrabbit.oak.plugins.index.IndexUpdate - Found a new index node [reference]. Reindexing is requested

1797 [main] INFO org.apache.jackrabbit.oak.plugins.index.IndexUpdate - Reindexing will be performed for following indexes: [/oak:index/slingResourceType, /oak:index/slingAlias, /oak:index/uuid, /oak:index/slingVanityPath, /oak:index/slingResource, /oak:index/jcrLanguage, /oak:index/reference, /oak:index/jcrLockOwner, /oak:index/nodetype]

2063 [main] INFO org.apache.jackrabbit.oak.plugins.index.IndexUpdate - Indexing report

    - /oak:index/nodetype*(1238)

2282 [main] INFO org.apache.jackrabbit.oak.plugins.index.IndexUpdate - Reindexing will be performed for following indexes: [/oak:index/principalName, /oak:index/authorizableId, /oak:index/acPrincipalName]

2295 [main] INFO org.apache.jackrabbit.oak.plugins.index.IndexUpdate - Indexing report

    - /oak:index/principalName*(2)

    - /oak:index/authorizableId*(2)

3501 [main] INFO org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProvider - Detected Oak based repository. Using improved JCR Resource Listener with observation queue length 1000

4676 [main] INFO org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProvider - Detected Oak based repository. Using improved JCR Resource Listener with observation queue length 1000

Disconnected from the target VM, address: '127.0.0.1:60490', transport: 'socket'

java.lang.RuntimeException: Unable to invoke method 'deactivate' 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:142)

at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.activateDeactivate(OsgiServiceUtil.java:84)

at org.apache.sling.testing.mock.osgi.MockOsgi.deactivate(MockOsgi.java:216)

at org.apache.sling.testing.mock.osgi.MockBundleContext.shutdown(MockBundleContext.java:438)

at org.apache.sling.testing.mock.osgi.MockOsgi.shutdown(MockOsgi.java:315)

at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.tearDown(OsgiContextImpl.java:56)

at org.apache.sling.testing.mock.sling.context.SlingContextImpl.tearDown(SlingContextImpl.java:222)

at io.wcm.testing.mock.aem.context.AemContextImpl.tearDown(AemContextImpl.java:79)

at io.wcm.testing.mock.aem.junit.AemContext.access$200(AemContext.java:48)

at io.wcm.testing.mock.aem.junit.AemContext$1.after(AemContext.java:162)

at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:50)

at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)

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.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)

at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)

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.NoSuchMethodError: org.apache.commons.io.IOUtils.closeQuietly(Ljava/io/Closeable;)V

at org.apache.jackrabbit.oak.jcr.repository.RepositoryImpl.shutdown(RepositoryImpl.java:325)

at org.apache.sling.testing.mock.sling.oak.OakMockSlingRepository.deactivate(OakMockSlingRepository.java:92)

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

Avatar

Level 4

I also solved this issue, it was an old version of commons-io in mail jet. After excluding it the error disappeared.

you can look at the dep tree with: mvn dependency:tree -Dverbose

<dependency>
  <groupId>com.mailjet</groupId>
  <artifactId>mailjet-client</artifactId>
  <version>4.0.6-SNAPSHOT</version>
  <exclusions>
  <exclusion>
  <groupId>org.apache.commons</groupId>
  <artifactId>commons-io</artifactId>
  </exclusion>
  </exclusions>
</dependency>