Hi,
We have upgraded from AEM 6.4 to AEM 6.5.
After upgrade dependencies in our application the integration tests fail.
Unable to initialize JCR_OAK resource resolver factory: Unable to invoke method 'activate' for class org.apache.sling.testing.mock.sling.oak.OakMockSlingRepository
java.lang.RuntimeException: Unable to initialize JCR_OAK resource resolver factory: Unable to invoke method 'activate' for class org.apache.sling.testing.mock.sling.oak.OakMockSlingRepository
at io.wcm.testing.mock.aem.context.ContextResourceResolverFactory.get(ContextResourceResolverFactory.java:70)
at io.wcm.testing.mock.aem.context.AemContextImpl.newResourceResolverFactory(AemContextImpl.java:76)
at org.apache.sling.testing.mock.sling.context.SlingContextImpl.resourceResolverFactory(SlingContextImpl.java:142)
at org.apache.sling.testing.mock.sling.context.SlingContextImpl.setUp(SlingContextImpl.java:126)
at io.wcm.testing.mock.aem.context.AemContextImpl.setUp(AemContextImpl.java:81)
at io.wcm.testing.mock.aem.junit5.AemContext.setUpContext(AemContext.java:99)
at io.wcm.testing.mock.aem.junit5.AemContextExtension.postProcessTestInstance(AemContextExtension.java:55)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeTestInstancePostProcessors$5(ClassTestDescriptor.java:349)
at org.junit.jupiter.engine.descriptor.JupiterTestDescriptor.executeAndMaskThrowable(JupiterTestDescriptor.java:215)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeTestInstancePostProcessors$6(ClassTestDescriptor.java:349)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:312)
at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:743)
at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:742)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeTestInstancePostProcessors(ClassTestDescriptor.java:348)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateAndPostProcessTestInstance(ClassTestDescriptor.java:270)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$2(ClassTestDescriptor.java:259)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$3(ClassTestDescriptor.java:263)
at java.util.Optional.orElseGet(Optional.java:267)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$4(ClassTestDescriptor.java:262)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:82)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:59)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$0(NodeTestTask.java:83)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:83)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:69)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74)
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:220)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:94)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$100(JUnitPlatformTestClassProcessor.java:79)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
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.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.stop(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:132)
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.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:175)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:157)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: Unable to invoke method 'activate' for class org.apache.sling.testing.mock.sling.oak.OakMockSlingRepository
at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeMethod(OsgiServiceUtil.java:321)
at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeLifecycleMethod(OsgiServiceUtil.java:150)
at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.activateDeactivate(OsgiServiceUtil.java:85)
at org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:186)
at org.apache.sling.testing.mock.sling.ResourceResolverFactoryInitializer.registerServiceIfNotPresent(ResourceResolverFactoryInitializer.java:167)
at org.apache.sling.testing.mock.sling.ResourceResolverFactoryInitializer.registerServiceIfNotPresent(ResourceResolverFactoryInitializer.java:152)
at org.apache.sling.testing.mock.sling.ResourceResolverFactoryInitializer.setUp(ResourceResolverFactoryInitializer.java:63)
at org.apache.sling.testing.mock.sling.MockSling.newResourceResolverFactory(MockSling.java:76)
at io.wcm.testing.mock.aem.context.ContextResourceResolverFactory.get(ContextResourceResolverFactory.java:48)
... 79 more
Caused by: java.lang.NoClassDefFoundError: org/apache/jackrabbit/oak/security/internal/SecurityProviderBuilder
at org.apache.jackrabbit.oak.Oak$OakDefaultComponents.<init>(Oak.java:976)
at org.apache.jackrabbit.oak.Oak$OakDefaultComponents.<clinit>(Oak.java:958)
at org.apache.jackrabbit.oak.jcr.Jcr.<init>(Jcr.java:101)
at org.apache.jackrabbit.oak.jcr.Jcr.<init>(Jcr.java:122)
at org.apache.sling.testing.mock.sling.oak.OakMockSlingRepository.activate(OakMockSlingRepository.java:73)
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:312)
... 87 more
Caused by: java.lang.ClassNotFoundException: org.apache.jackrabbit.oak.security.internal.SecurityProviderBuilder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 97 more
pl.gp3.TemplateTest > dumbTest() FAILED
java.lang.RuntimeException
Caused by: java.lang.RuntimeException
Caused by: java.lang.NoClassDefFoundError
Caused by: java.lang.ClassNotFoundException
1 test completed, 1 failed
> Task :test FAILED
Views
Replies
Total Likes
There is a simplified version of test (It fails on the setup phase)
GitHub - dkociniewski/aem-65-template-tests
The issue doesn't occur with uber-jar:6.4.0
There is a test class
package pl.gp3;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
@ExtendWith(AemContextExtension.class)@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
class TemplateTest {
private static final String EXISTING_SITE_PATH = "/content/site";
private final AemContext context = new AemContext(ResourceResolverType.JCR_OAK);
@BeforeEach
void setUp() {context.load().json("/template-test/content.json", EXISTING_SITE_PATH);
context.load().json("/template-test/templates.json", "/conf/site");
}@Test
void dumbTest() {Assertions.assertTrue(true);
}}
templates.json
{
"jcr:primaryType": "sling:OrderedFolder",
"jcr:title": "We.Retail",
"cq:templateTypesOrigin": "local",
"cq:templatesOrigin": "local",
"settings": {"jcr:primaryType": "sling:Folder",
"wcm": {"jcr:primaryType": "cq:Page",
"templates": {"jcr:primaryType": "cq:Page",
"hero-page": {"jcr:primaryType": "cq:Template",
"thumbnail.png": {"jcr:primaryType": "nt:file",
"jcr:content": {"jcr:primaryType": "nt:resource",
"jcr:mimeType": "image/png",
":jcr:data": 59357,
"jcr:uuid": "4da9a62e-5ad5-420b-9648-d90505e7b331"
}},
"initial": {"jcr:primaryType": "cq:Page",
"jcr:content": {"cq:template": "/conf/we-retail/settings/wcm/templates/hero-page",
"jcr:created": "Tue May 07 2019 12:48:45 GMT+0200",
"sling:resourceType": "weretail/components/structure/page"
}},
"jcr:content": {"jcr:primaryType": "cq:PageContent",
"jcr:title": "Hero Page",
"status": "enabled",
"cq:templateType": "/conf/we-retail/settings/wcm/template-types/empty-page"
},
"structure": {"jcr:primaryType": "cq:Page",
"jcr:content": {"jcr:primaryType": "cq:PageContent",
"cq:template": "/conf/we-retail/settings/wcm/templates/hero-page",
"cq:deviceGroups": ["mobile/groups/responsive"
],
"sling:resourceType": "weretail/components/structure/page"
}}
}
}
}
}
}
plugins {
id 'java'
}group 'pl.gp3.aem.test'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {mavenCentral()
maven { url = uri("https://repo.adobe.com/nexus/content/groups/public") }
}
configurations {
testImplementation.extendsFrom compileOnly
}dependencies {
// AEM runtime dependencies
compileOnly 'com.adobe.aem:uber-jar:6.5.0:apis'
compileOnly 'org.osgi:osgi.cmpn:6.0.0'
compileOnly 'org.osgi:org.osgi.core:6.0.0'
compileOnly 'javax.servlet:servlet-api:2.5'
compileOnly 'javax.jcr:jcr:2.0'
compileOnly 'org.slf4j:slf4j-api:1.7.25'
compileOnly 'org.apache.geronimo.specs:geronimo-atinject_1.0_spec:1.0'
compileOnly 'org.apache.sling:org.apache.sling.api:2.18.4'
compileOnly 'org.apache.sling:org.apache.sling.jcr.api:2.4.0'
compileOnly 'org.apache.sling:org.apache.sling.models.api:1.3.8'
compileOnly 'org.apache.sling:org.apache.sling.settings:1.3.10'
compileOnly 'com.google.guava:guava:15.0'
compileOnly 'com.google.code.gson:gson:2.8.5'
compileOnly 'joda-time:joda-time:2.9.1'
compileOnly 'org.jetbrains:annotations:13.0'
compileOnly 'org.osgi:org.osgi.compendium:4.2.0'
// Test dependencies
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.3.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.2'
testImplementation 'org.mockito:mockito-core:2.23.4'
testImplementation 'org.mockito:mockito-junit-jupiter:2.23.4'
testImplementation 'org.hamcrest:hamcrest:2.1'
testImplementation 'io.wcm:io.wcm.testing.aem-mock.junit5:2.4.6'
testImplementation 'org.apache.sling:org.apache.sling.testing.sling-mock-oak:2.1.4'
}test {
useJUnitPlatform()
}
build.gradle file
In the dependencies, there seem to be some over-riding classes so the loading order matters. In the core sub-project, the POM file contains these two blocks:
```
<!-- https://mvnrepository.com/artifact/org.apache.sling/org.apache.sling.testing.sling-mock-oak -->
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.sling-mock-oak</artifactId>
<scope>test</scope>
</dependency>
```
and...
```
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>uber-jar</artifactId>
<classifier>apis</classifier>
</dependency>
```
It matters whether the `sling-mock-oak` block is before or after the `uber-jar` (6.5.0) block.
If the `sling-mock-oak` block is after the `uber-jar` block, then the error occurs.
if the `sling-mock-oak` block is before the `uber-jar` block, then the error does not occur.
ALSO: If you're running tests in Eclipse:
You might still get the error even after placing `sling-mock-oak` before `uber-jar`.
If so, go into Eclipse -> Run -> Run Configurations... -> [choose JUnit run configuration you're using] -> ClassPath
Under "User Entries" you should see both ".core" and "Maven Dependencies". Use the "Up" button if necessary to ensure that "Maven Dependencies" is above ".core"
Im working on archetypre AEM as a Cloud Service version 5.1.2, sdk.api
2022.4.7138.20220427T075748Z-220401
, and I was able to get my node property request working by switching to
ResourceResolverType.JCR_MOCK
. And following the dependecies in the main pom.xml of the example project: https://github.com/adobe/aem-guides-wknd
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies