Expand my Community achievements bar.

SOLVED

Runtime error while running JUnit5 AEM Mocks test (After setup failed )

Avatar

Level 2

java.lang.RuntimeException: After setup failed (com.adobe.cq.wcm.core.components.testing.mock.ContextPlugins$1@5baaae4c): com/adobe/cq/wcm/core/components/internal/link/DefaultPathProcessor
at org.apache.sling.testing.mock.osgi.context.ContextPlugins.executeAfterSetUpCallback(ContextPlugins.java:218)
at io.wcm.testing.mock.aem.junit5.AemContextExtension.lambda$beforeEach$1(AemContextExtension.java:129)
at io.wcm.testing.mock.aem.junit5.AemContextExtension.applyAemContext(AemContextExtension.java:180)
at io.wcm.testing.mock.aem.junit5.AemContextExtension.beforeEach(AemContextExtension.java:127)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeEachCallbacks$2(TestMethodTestDescriptor.java:163)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeMethodsOrCallbacksUntilExceptionOccurs$6(TestMethodTestDescriptor.java:199)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeMethodsOrCallbacksUntilExceptionOccurs(TestMethodTestDescriptor.java:199)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeEachCallbacks(TestMethodTestDescriptor.java:162)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:129)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:95)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:91)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:60)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:98)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: java.lang.NoClassDefFoundError: com/adobe/cq/wcm/core/components/internal/link/DefaultPathProcessor
at com.adobe.cq.wcm.core.components.testing.mock.ContextPlugins.setUp(ContextPlugins.java:52)
at com.adobe.cq.wcm.core.components.testing.mock.ContextPlugins$1.afterSetUp(ContextPlugins.java:41)
at com.adobe.cq.wcm.core.components.testing.mock.ContextPlugins$1.afterSetUp(ContextPlugins.java:38)
at org.apache.sling.testing.mock.osgi.context.ContextPlugins.executeAfterSetUpCallback(ContextPlugins.java:215)
... 56 more
Caused by: java.lang.ClassNotFoundException: com.adobe.cq.wcm.core.components.internal.link.DefaultPathProcessor
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 60 more

 

1 Accepted Solution

Avatar

Correct answer by
Level 2

It is working fine after changing the  AemContext initialization in different way .

View solution in original post

5 Replies

Avatar

Community Advisor

Hi @asarafali ,

I see there is a ClassNotFoundException and assuming you are getting this error in eclipse, try following and see if either of them resolves the issue-

 

1. Try using latest version of eclipse, which might help overcoming JUNIT libraries issue.

2. Try below threads-

https://stackoverflow.com/questions/4228047/java-lang-noclassdeffounderror-in-junit

https://www.baeldung.com/junit-noclassdeffounderror

 

Hope it helps!

 

Avatar

Community Advisor

Can you profile the test case structure here, as to how you are initializing the AemContext and the dependencies for unit tests. Some more information and context will be helpful.

Avatar

Correct answer by
Level 2

It is working fine after changing the  AemContext initialization in different way .

Avatar

Level 1

I am also facing this issue, getting runtime error 

java.lang.RuntimeException: After setup failed (com.adobe.cq.wcm.core.components.testing.mock.ContextPlugins$1@497570fb): com/adobe/cq/wcm/core/components/internal/link/DefaultPathProcessor. I have initialized the AemContext like following

 

private final AemContext context = new AemContextBuilder().plugin(CORE_COMPONENTS).build();
How do we need to initialize this AemContext to overcome this runtime exception

Avatar

Level 1

This runtime exception 

"java.lang.RuntimeException: After setup failed (com.adobe.cq.wcm.core.components.testing.mock.ContextPlugins$1@5baaae4c): com/adobe/cq/wcm/core/components/internal/link/DefaultPathProcessor"

is resolved once I added the following wcm-components-core dependency

 

 

<dependency>
   <groupId>com.adobe.cq</groupId>
   <artifactId>core.wcm.components.core</artifactId>
   <version>2.x.x</version>
   <scope>test</scope>
</dependency>​

 

and on AemContext initialization as

 

private final AemContext context = new AemContextBuilder(ResourceResolverType.JCR_MOCK).plugin(CORE_COMPONENTS).build();