AEM 6.3 JUnit test AemContext issue | Community
Skip to main content
June 19, 2017
Solved

AEM 6.3 JUnit test AemContext issue

  • June 19, 2017
  • 3 replies
  • 6333 views

Hi,

I have updated my project from AEM6.2 to AEM6.3, and almost everything works except for the unit tests using the io.wcm.testing.mock.aem.junit.AemContext.

@Rule
public final AemContext context = new AemContext(ResourceResolverType.JCR_MOCK);

I tried to match the dependencies of the AEM WCM Core project​ and the one mentioned in the blog here​ as the issues mentioned there, I'm also experiencing.

I have also tried changing the order of the dependencies, but then NoSuchMethodError is presenting for another class.

Example of the error I'm getting

java.lang.NoSuchMethodError: org.apache.sling.api.resource.ResourceMetadata.setParameterMap(Ljava/util/Map;)V

  at org.apache.sling.jcr.resource.internal.helper.jcr.JcrItemResourceFactory.createResource(JcrItemResourceFactory.java:115)

  at org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProvider.getResource(JcrResourceProvider.java:283)

  at org.apache.sling.resourceresolver.impl.providers.stateful.AuthenticatedResourceProvider.getResource(AuthenticatedResourceProvider.java:135)

  at org.apache.sling.resourceresolver.impl.helper.ResourceResolverControl.getResource(ResourceResolverControl.java:218)

  at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.getAbsoluteResourceInternal(ResourceResolverImpl.java:1055)

  at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.getResourceInternal(ResourceResolverImpl.java:688)

  at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.getResource(ResourceResolverImpl.java:642)

  at org.apache.sling.testing.mock.sling.loader.ContentLoader.createResourceHierarchy(ContentLoader.java:195)

  at org.apache.sling.testing.mock.sling.loader.ContentLoader.createResourceHierarchy(ContentLoader.java:197)

  at org.apache.sling.testing.mock.sling.loader.ContentLoader.json(ContentLoader.java:171)

  at org.apache.sling.testing.mock.sling.loader.ContentLoader.json(ContentLoader.java:136)

  at nl.valtech.aem.common.seocomponents.components.PaginatorComponentTest.setUp(PaginatorComponentTest.java:39)

  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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

  at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)

  at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)

  at org.junit.rules.RunRules.evaluate(RunRules.java:20)

Below a list of properties containing my versions of the dependecies (The names are based on the artifactId)

<!-- DEPENDENCIES -->
<aem.api.version>6.0.0.1</aem.api.version>
<org.apache.felix.scr.version>1.6.0</org.apache.felix.scr.version>
<org.apache.felix.scr.annotations.version>1.9.6</org.apache.felix.scr.annotations.version>
<bndlib.version>1.50.0</bndlib.version>
<org.osgi.core.osgi.version>4.2.0</org.osgi.core.osgi.version>
<org.osgi.core.felix.version>1.4.0</org.osgi.core.felix.version>
<org.osgi.compendium.version>4.2.0</org.osgi.compendium.version>
<slf4j.api.version>1.7.6</slf4j.api.version>
<servlet.api.version>2.4</servlet.api.version>
<jsp.api.version>2.1</jsp.api.version>
<jcr.version>2.0</jcr.version>
<geronimo.atinject.spec.version>1.0</geronimo.atinject.spec.version>
<org.apache.sling.models.api.version>1.3.4</org.apache.sling.models.api.version>
<org.apache.sling.models.impl.version>1.3.0</org.apache.sling.models.impl.version>
<org.apache.sling.jcr.api.version>2.0.4</org.apache.sling.jcr.api.version>
<org.apache.sling.commons.osgi.version>2.2.0</org.apache.sling.commons.osgi.version>
<jackrabbit.core.version>2.4.3</jackrabbit.core.version>
<jackrabbit.jcr.commons.version>2.4.3</jackrabbit.jcr.commons.version>
<org.apache.sling.api.version>2.7.0</org.apache.sling.api.version>
<javax.inject.version>1</javax.inject.version>
<cq.wcm.taglib.version>5.7.4</cq.wcm.taglib.version>
<commons.lang3.version>3.4</commons.lang3.version>
<com.google.code.findbugs.annotations.version>2.0.1</com.google.code.findbugs.annotations.version>
<com.google.code.findbugs.jsr305.version>2.0.0</com.google.code.findbugs.jsr305.version>

<!-- DEPENDENCIES TESTING -->
<junit.version>4.12</junit.version>
<slf4j.simple.version>1.7.6</slf4j.simple.version>
<!--<mockito.all.version>1.10.19</mockito.all.version>-->
<mockito.core.version>1.10.19</mockito.core.version>
<junit.addons.version>1.4</junit.addons.version>
<org.apache.commons.commons.imaging.version>1.0-R1534292</org.apache.commons.commons.imaging.version>
<powermock.api.mockito.version>1.6.4</powermock.api.mockito.version>
<io.wcm.testing.aem.mock.version>2.2.6</io.wcm.testing.aem.mock.version>

<!-- OSGi Framework version -->
<org.osgi.version>6.0.0</org.osgi.version>
<org.apache.felix.framework.version>5.0.0</org.apache.felix.framework.version>
<org.osgi.service.component.annotations.version>1.3.0</org.osgi.service.component.annotations.version>
<org.osgi.service.metatype.annotations.version>1.3.0</org.osgi.service.metatype.annotations.version>
<osgi.annotation.version>6.0.1</osgi.annotation.version>

Anybody an idea what is causing this error?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by evelinealbers

Using the versions I already had and the Maven Archetype 11 fixes the issue (Archetype 10 gives the same errors). I have put dependencies in the order its in there and then put all my additional dependencies after that. I didn't have to change the versions of any of my dependencies. (see my question for all the versions for AEM6.3)

<!-- OSGi Dependencies -->

        <dependency>

            <groupId>org.osgi</groupId>

            <artifactId>osgi.core</artifactId>

        </dependency>

        <dependency>

            <groupId>org.osgi</groupId>

            <artifactId>osgi.cmpn</artifactId>

        </dependency>

        <dependency>

            <groupId>org.osgi</groupId>

            <artifactId>osgi.annotation</artifactId>

        </dependency>

        <!-- Other Dependencies -->

        <dependency>

            <groupId>org.slf4j</groupId>

            <artifactId>slf4j-api</artifactId>

        </dependency>

        <dependency>

            <groupId>javax.jcr</groupId>

            <artifactId>jcr</artifactId>

        </dependency>

        <dependency>

            <groupId>javax.servlet</groupId>

            <artifactId>servlet-api</artifactId>

        </dependency>

        <dependency>

            <groupId>com.adobe.aem</groupId>

            <artifactId>uber-jar</artifactId>

            <classifier>apis</classifier>

        </dependency>

        <dependency>

            <groupId>org.apache.sling</groupId>

            <artifactId>org.apache.sling.models.api</artifactId>

        </dependency>

        <dependency>

            <groupId>junit</groupId>

            <artifactId>junit</artifactId>

        </dependency>

        <dependency>

            <groupId>org.mockito</groupId>

            <artifactId>mockito-core</artifactId>

        </dependency>

        <dependency>

            <groupId>junit-addons</groupId>

            <artifactId>junit-addons</artifactId>

        </dependency>

        <dependency>

            <groupId>javax.inject</groupId>

            <artifactId>javax.inject</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.geronimo.specs</groupId>

            <artifactId>geronimo-atinject_1.0_spec</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.felix</groupId>

            <artifactId>org.apache.felix.scr</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.felix</groupId>

            <artifactId>org.apache.felix.scr.annotations</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.sling</groupId>

            <artifactId>org.apache.sling.models.impl</artifactId>

            <scope>test</scope>

        </dependency>

        <dependency>

            <groupId>io.wcm</groupId>

            <artifactId>io.wcm.testing.aem-mock</artifactId>

            <exclusions>

                <exclusion>

                    <artifactId>org.apache.sling.models.impl</artifactId>

                    <groupId>org.apache.sling</groupId>

                </exclusion>

            </exclusions>

        </dependency>

3 replies

smacdonald2008
Level 10
June 19, 2017

If you develop an Maven Archetype 10 project using the Uber 6.3 JAR - look at the generated POMs. The default project has some JUNIT classes.

Adobe Employee
July 3, 2017

Double-check your POMs (Parent AND bundle/core) to make sure you are using the proper uberjar and NOT directly specifying the dependency version for:

<dependency>

<groupId>org.apache.sling</groupId>

<artifactId>org.apache.sling.api</artifactId>

<version>x.x.x</version>

<scope>provided</scope>

</dependency>

I can all but guarantee you were including a dependency for the org.apache.sling.api artifact with an old(er) version that does not have the setParameter(..) methods. Ideally you consume the appropriate version through the uberjar (6.2 and 6.3 both use the sling.resource.api dep that exposes this method)

HTH

evelinealbersAuthorAccepted solution
July 4, 2017

Using the versions I already had and the Maven Archetype 11 fixes the issue (Archetype 10 gives the same errors). I have put dependencies in the order its in there and then put all my additional dependencies after that. I didn't have to change the versions of any of my dependencies. (see my question for all the versions for AEM6.3)

<!-- OSGi Dependencies -->

        <dependency>

            <groupId>org.osgi</groupId>

            <artifactId>osgi.core</artifactId>

        </dependency>

        <dependency>

            <groupId>org.osgi</groupId>

            <artifactId>osgi.cmpn</artifactId>

        </dependency>

        <dependency>

            <groupId>org.osgi</groupId>

            <artifactId>osgi.annotation</artifactId>

        </dependency>

        <!-- Other Dependencies -->

        <dependency>

            <groupId>org.slf4j</groupId>

            <artifactId>slf4j-api</artifactId>

        </dependency>

        <dependency>

            <groupId>javax.jcr</groupId>

            <artifactId>jcr</artifactId>

        </dependency>

        <dependency>

            <groupId>javax.servlet</groupId>

            <artifactId>servlet-api</artifactId>

        </dependency>

        <dependency>

            <groupId>com.adobe.aem</groupId>

            <artifactId>uber-jar</artifactId>

            <classifier>apis</classifier>

        </dependency>

        <dependency>

            <groupId>org.apache.sling</groupId>

            <artifactId>org.apache.sling.models.api</artifactId>

        </dependency>

        <dependency>

            <groupId>junit</groupId>

            <artifactId>junit</artifactId>

        </dependency>

        <dependency>

            <groupId>org.mockito</groupId>

            <artifactId>mockito-core</artifactId>

        </dependency>

        <dependency>

            <groupId>junit-addons</groupId>

            <artifactId>junit-addons</artifactId>

        </dependency>

        <dependency>

            <groupId>javax.inject</groupId>

            <artifactId>javax.inject</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.geronimo.specs</groupId>

            <artifactId>geronimo-atinject_1.0_spec</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.felix</groupId>

            <artifactId>org.apache.felix.scr</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.felix</groupId>

            <artifactId>org.apache.felix.scr.annotations</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.sling</groupId>

            <artifactId>org.apache.sling.models.impl</artifactId>

            <scope>test</scope>

        </dependency>

        <dependency>

            <groupId>io.wcm</groupId>

            <artifactId>io.wcm.testing.aem-mock</artifactId>

            <exclusions>

                <exclusion>

                    <artifactId>org.apache.sling.models.impl</artifactId>

                    <groupId>org.apache.sling</groupId>

                </exclusion>

            </exclusions>

        </dependency>