icfnext / prosper

A Spock-based integration testing library for prosperous AEM development.
Other
28 stars 19 forks source link

Unable to initialize JCR_OAK resource resolver factory #7

Closed gerardvh closed 8 years ago

gerardvh commented 8 years ago

Hello,

We are looking at integrating Prosper testing into an existing AEM 6.1 project, but are having some trouble with getting the initial basic test to work.

Initially, after adding Prosper as a test-scoped dependency, we were getting errors with other classes that use the Sling API, so I added an exclusion for the transitive Sling API dependency on the Prosper node in our pom.xml. Now the compiler is able to resolve all the dependencies and compile successfully, but when running the test you suggest in the README.md I get an error excerpted here: com.gerardvh.prosper.ExampleSpec: Unable to initialize JCR_OAK resource resolver factory: Unable to invoke method 'activate' for class org.apache.sling.testing.mock.sling.oak.OakMockSlingRepository. (Full error from surefire available here.)

It's possible there is another dependency conflict with our existing setup, or perhaps something else, but I hoped you might be able to offer some advice to try and resolve the issue. We currently use the AEM 6.1 obfuscated API's and I wonder if there is something conflicting there that we cannot see. In case it's useful I also did a dependency tree analysis that you can see here.

Thanks for your time.

markdaugherty commented 8 years ago

The actual cause of the error is further down the stacktrace. It's due to incompatible versions of the Google Guava library - presumably your pom file has a dependency on an older version than Jackrabbit. Can you try adding an additional exclusion for Guava?

gerardvh commented 8 years ago

Hey, you were right, there was a mismatch in Guava versions between Prosper and the Google gdata bundle, thanks for the pointer!

I'm now able to run the initial hello-world tests for the Prosper project, however I do still see an error on the command line output from Maven (even though the test runs successfully):

1569 [main] ERROR org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProviderFactory - Detected Oak based repository but no executor service available! Unable to use improved JCR Resource listener Exception in thread "Apache Sling JCR Resource Event Queue Processor" java.lang.NoClassDefFoundError: org/osgi/service/event/EventProperties at org.apache.sling.jcr.resource.internal.JcrResourceListener.processOsgiEventQueue(JcrResourceListener.java:386) at org.apache.sling.jcr.resource.internal.JcrResourceListener$1.run(JcrResourceListener.java:107) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.ClassNotFoundException: org.osgi.service.event.EventProperties 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) ... 3 more

Do you think this indicates another issue I should look into, or is it not a big deal if the test runs successfully?

Thanks again for your time.

markdaugherty commented 8 years ago

I encountered this issue myself; yes, it is another dependency conflict. Try adding exclusions for the following:

<dependency>
    <groupId>org.osgi</groupId>
    <artifactId>org.osgi.core</artifactId>
</dependency>
<dependency>
    <groupId>org.osgi</groupId>
    <artifactId>org.osgi.compendium</artifactId>
</dependency>
gerardvh commented 8 years ago

We do have org.osgi.core and org.osgi.compendium as separate dependencies right now (version 4.2.0), and I noticed that Prosper uses version 5.0.0, but I still get the same error when explicitly requiring version 5.0.0 and when excluding core and compendium from the Prosper transitive dependencies.

I've copied the full error here. And the most recent dependency tree here.

If you have any other ideas, I'd be happy to try them, thanks again!

gerardvh commented 8 years ago

Hi Mark,

Just wanted to follow up again and let you know that I solved the issue with your recommendation and a minor modification. Instead of excluding dependencies from the Prosper project, I created a sub-module for tests using Prosper and required the sub-module-under-test with exclusions for the conflicts.

I'm now able to run tests successfully while also having access to the classes I want to test from our project.

Thanks again for your help.

markdaugherty commented 8 years ago

Glad that worked! Thanks for persisting and hope you enjoy using the library.

kalimuthup commented 6 years ago

Hi Team , I am trying to setup Prosper and write Groovy testcase for my AEM Components. But i am getting the error as ExampleSpec.com.amex.gem.beans.ExampleSpec » Runtime Unable to initialize JCR_ I have included the dependency jars as listed below,please let me know whether it is missing any required jars. `

org.objenesis
        <artifactId>objenesis</artifactId>
        <version>2.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
         <version>2.4.1</version>
    </dependency>
    <dependency>
        <groupId>org.spockframework</groupId>
        <artifactId>spock-core</artifactId>
        <version>1.0-groovy-2.4</version>
    </dependency>
    <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>

org.osgi org.osgi.compendium
    <dependency>
<groupId>com.icfolson.aem.prosper</groupId>
<artifactId>prosper</artifactId>
<version>11.1.0</version>
<scope>test</scope>

cglib
        <artifactId>cglib-nodep</artifactId>
       <version>3.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.sling-mock-oak</artifactId>
<version>1.0.0</version>
<scope>test</scope>

`