无法初始化JCR_OAK资源解析器工厂-AEM 6.5

时间:2019-05-09 13:17:23

标签: java-8 integration-testing junit5 aem-6 sling-models

我们已从AEM 6.4升级到AEM 6.5。

在我们的应用程序中升级依赖项后,集成测试失败。

测试类。

@ExtendWith(AemContextExtension.class)
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
class TemplateTest {
    private final AemContext context = new AemContext(ResourceResolverType.JCR_OAK);

    @BeforeEach
    void setUp() {
        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"
            }
          }
        }
      }
    }
  }
}

build.gradle

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()
}

运行测试时,我得到了以下堆栈跟踪:

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(ContextResourceResolve rFactory.java:70)

at io.wcm.testing.mock.aem.context.AemContextImpl.newResourceResolverFactory(AemContextImpl. java:76)

at org.apache.sling.testing.mock.sling.context.SlingContextImpl.resourceResolverFactory(Slin gContextImpl.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(AemContextExte nsion.java:55)

at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeTestInstancePostProc essors$5(ClassTestDescriptor.java:349)

at org.junit.jupiter.engine.descriptor.JupiterTestDescriptor.executeAndMaskThrowable(Jupiter TestDescriptor.java:215)

at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeTestInstancePostProc essors$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(StreamSpliterato rs.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.instantiateAndPostProcessTestInst ance(ClassTestDescriptor.java:270)

at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$2(Cla ssTestDescriptor.java:259)

at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$3(Cla ssTestDescriptor.java:263)

at java.util.Optional.orElseGet(Optional.java:267)

at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$4(Cla ssTestDescriptor.java:262)

at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescri ptor.java:82)

at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescri ptor.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(ThrowableCollec tor.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(N odeTestTask.java:112)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollec tor.java:72)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTa sk.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(N odeTestTask.java:112)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollec tor.java:72)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTa sk.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(Hierarchi calTestExecutor.java:57)

at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(Hierarchica lTestEngine.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:18 8)

at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.j ava: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$Colle ctAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:94)

at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$Colle ctAllTestClassesExecutor.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(SuiteTestClassProcesso r.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(ContextClassLoaderDispat ch.java:32)

at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(Pro xyDispatchAdapter.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(ExecutorPo licy.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(ThreadFactoryI mpl.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.jav a:85)

at org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:186)

at org.apache.sling.testing.mock.sling.ResourceResolverFactoryInitializer.registerServiceIfN otPresent(ResourceResolverFactoryInitializer.java:167)

at org.apache.sling.testing.mock.sling.ResourceResolverFactoryInitializer.registerServiceIfN otPresent(ResourceResolverFactoryInitializer.java:152)

at org.apache.sling.testing.mock.sling.ResourceResolverFactoryInitializer.setUp(ResourceReso lverFactoryInitializer.java:63)

at org.apache.sling.testing.mock.sling.MockSling.newResourceResolverFactory(MockSling.java:7 6)

at io.wcm.testing.mock.aem.context.ContextResourceResolverFactory.get(ContextResourceResolve rFactory.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(OakMockSlingRepos itory.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

通过uber-jar:6.4.0的测试

有人有类似的问题吗? 我应该添加一些其他依赖项吗?

预先感谢, 丹尼尔

0 个答案:

没有答案