Getting a LoginException when using AEMContext to load mock content during unit testing.

Avatar

Avatar

Xavier_Dupertio

Avatar

Xavier_Dupertio

Xavier_Dupertio

27-02-2021

I am having a LoginException when loading mock data while testing a servlet using AEMContext in a JUnit test. I want to load a sample node without an exception.

 

I am using AEMContext within a JUnit test for a servlet.

 

 

 

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



    @BeforeEach

    void setUp() throws Exception {

            context.load().json(getClass().getResourceAsStream(getClass().getSimpleName() + ".json"),"/var/dupertious/topic");

    }

 

 

When this code runs, it throws a LoginException:

 

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.032 s <<< FAILURE! - in com.dupertious.servlets.UploadLinksAsCSVTest

[ERROR] testResponseJSON  Time elapsed: 0.989 s  <<< ERROR!

java.lang.RuntimeException: Creating resource resolver failed.

at com.dupertioius.servlets.UploadLinksAsCSVTest.setUp(UploadLinksAsCSVTest.java:27)

Caused by: org.apache.sling.api.resource.LoginException: Calling bundle missing in authentication info

at com.dupertious.servlets.UploadLinksAsCSVTest.setUp(UploadLinksAsCSVTest.java:27)

 

Here's the JSON I am trying to load. I have tried it with and without the ACL.

{
     "jcr:primaryType": "nt:unstructured",
    "sling:resourceType": "arq\/data\/topic\/parent",
    "jcr:mixinTypes": [
       "rep:AccessControllable"
    ],
    "topic-3a953c61-85c4-45d5-a4dc-6ade5f76ef97": {
    "jcr:primaryType": "nt:unstructured",
    "jcr:title": "Topic",
    "id": "3a953c61-85c4-45d5-a4dc-6ade5f76ef97",
    "sling:resourceType": "dupertious\/data\/topic",
    "jcr:content": {
       "jcr:primaryType": "nt:unstructured",
             "links": [],
       }
    },
    "rep:policy": {
          "jcr:primaryType": "rep:ACL",
          "allow": {
                "jcr:primaryType": "rep:GrantACE",
                "rep:principalName": "everyone",
                "rep:privileges": [
                         "jcr:read"
                ]
          }
    }
}

 

AEM Junit

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Jörg_Hoh

Employee

Total Posts

3.1K

Likes

1.1K

Correct Reply

1.1K

Avatar

Jörg_Hoh

Employee

Total Posts

3.1K

Likes

1.1K

Correct Reply

1.1K
Jörg_Hoh
Employee

28-02-2021

I don't think that it has something to do with the content in the JSON, but it's a different issue.

 

java.lang.RuntimeException: Creating resource resolver failed.

 

The code is here, but I can hardly think of a situation where this fails. Can you check if you get an error/warn message before that? What version of AEM Mocks / Sling Mocks are you using?

Answers (1)

Answers (1)

Avatar

Avatar

Xavier_Dupertio

Avatar

Xavier_Dupertio

Xavier_Dupertio

04-03-2021

Hi Jörg,

I changed io.wcm.testing.aem-mock.junit5 to 4.0.0 from 2.5.2. It worked after that.