Hello again!
Getting this error when I run the test class below at ctx.load().json line. It seems that I can't create an array of objects in the json mock... Is there another way that I could implement the json?
package com.test.core.models.impl.section;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
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 static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith({AemContextExtension.class, MockitoExtension.class})
public class ATest {
private final AemContext ctx = new AemContext();
private A a;
@BeforeEach
public void setUp() throws Exception {
ctx.addModelsForClasses(A.class);
ctx.load().json("/com/test/core/models/impl/section/ATest.json", "/content");
a = ctx.resourceResolver().getResource("/content/a")
.adaptTo(A.class);
}
@test
void testGetCards() {
assertEquals("title", a.getCards().get(0).getTitle());
assertEquals("description", a.getCards().get(1).getDescription());
assertEquals("image", a.getCards().get(2).getFileReference());
assertTrue( a.getCards().size()==1);
}
}
The ATest.json mock
{
"a": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "test/components/a",
"cards": [{
"title":"title",
"description":"description",
"fileReference":"image"
}]
}
}
The models
public class A {
protected static final String RESOURCE_TYPE = "test/components/a";
@ChildResource
private List<ACard> cards;
}
public class ACard implements Card {
@ValueMapValue
private String title;
@ValueMapValue
private String description;
@ValueMapValue
private String fileReference;
}
Solved! Go to Solution.
Views
Replies
Total Likes
Done!
{ "a": { "jcr:primaryType": "nt:unstructured", "sling:resourceType": "consorcio/components/a", "cards": { "jcr:primaryType": "nt:unstructured", "item0": { "title": "Title", "description": "description", "fileReference":"image" } } } }
Done!
{ "a": { "jcr:primaryType": "nt:unstructured", "sling:resourceType": "consorcio/components/a", "cards": { "jcr:primaryType": "nt:unstructured", "item0": { "title": "Title", "description": "description", "fileReference":"image" } } } }