I am using AEM Mocks (with JUnit 5). I create my context as follows:
private final AemContext aemContext = new AemContext(ResourceResolverType.JCR_OAK);
Note the use of JCR_OAK
. Everything works fine if I try to use JCR_MOCK
instead. When trying to inject certain services, I get the following error:
java.lang.RuntimeException: Unable to initialize JCR_OAK resource resolver factory: Unable to invoke method 'activate' for class org.apache.sling.resourceresolver.impl.ResourceResolverFactoryActivator
I already tried the advice described here - inverting the sling-mock-oak
and uber-jar
dependencies - but this can't be done. If sling-mock-oak
comes before the uber-jar
, other errors are thrown.
Below is a partial list of dependencies:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junitVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.wcm.maven</groupId>
<artifactId>io.wcm.maven.aem-dependencies</artifactId>
<version>6.4.8.0002</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.logging-mock</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.resourceresolver-mock</artifactId>
<version>1.1.24</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4jVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4jVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-core</artifactId>
<version>3.0.4</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.21.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>2.23.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.sling-mock-oak</artifactId>
<version>2.1.10-1.16.0</version>
<scope>test</scope>
</dependency>
Can someone please tell me why I get the error above?
Thank you!
I was able to get my node property request's working by switching to ResourceResolverType.JCR_MOCK instead, and correcting my test decencies to match the pom.xml in the example https://github.com/adobe/aem-guides-wknd