I would like to confirm if this is happening not just on my machine. If it does, is there any workaround for this?
I am trying to load a page JSON into the test and my code is using the 'jcr:created' property. Unfortunately, this is not being returned when the test page is imported via JSON.
It gets included when I create the page via the `create().page(...)` method though.
I was hoping to do it via JSON import since it will be faster for our team.
I'm using AEM 6.1 and io.wcm.testing.aem-mock 1.7.0.
Here is a sample JSON that I'm using
{
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "English",
"cq:template": "/apps/sample/templates/homepage",
"sling:resourceType": "sample/components/homepage",
"jcr:createdBy": "admin",
"jcr:created": "Thu Aug 07 2014 16:32:59 GMT+0200"
}
}
Here is a JUnit test case
// imports //
...
import io.wcm.testing.mock.aem.junit.AemContext;
public class TestPageContentParsingFromJson {
@Rule
public final AemContext context = new AemContext();
private ResourceResolver resolver;
@Before
public void setUp() throws Exception {
// load page from json
context.load().json("/page.json", "/content/mock/from/json");
// create page via builder
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(1407421979000L); // "Thu Aug 07 2014 16:32:59 GMT+0200"
calendar.setTimeZone(TimeZone.getTimeZone("GMT+0200"));
context.create().page("/content/mock/from/builder",
"/apps/sample/templates/homepage",
ImmutableMap.<String, Object>builder()
.put("jcr:title", "English")
.put("jcr:created", calendar.getTime())
.put("sling:resourceType", "sample/components/homepage")
.put("jcr:createdBy", "admin")
.build()
);
resolver = context.resourceResolver();
}
private Page loadPageFromContext(String path) {
Resource resource = resolver.getResource(path);
Page page = resource.adaptTo(Page.class);
assertNotNull(page);
return page;
}
@Test
public void testEquality() {
Page pageJson = loadPageFromContext("/content/mock/from/json");
System.out.println("\n");
Page pageFromBuilder = loadPageFromContext("/content/mock/from/builder");
ValueMap propsFromJson = pageJson.getProperties();
ValueMap propsFromBuilder = pageFromBuilder.getProperties();
assertEquals("Should be equals to 'sample/components/homepage'", propsFromJson.get("sling:resourceType", Calendar.class), propsFromBuilder.get("sling:resourceType", Calendar.class));
assertEquals("Should be equals to '/apps/sample/templates/homepage'", propsFromJson.get("cq:template", Calendar.class), propsFromBuilder.get("cq:template", Calendar.class));
assertEquals("Should be equals to 'admin'", propsFromJson.get("jcr:createdBy", String.class), propsFromBuilder.get("jcr:createdBy", String.class));
assertEquals("Should be equals to 'English'", propsFromJson.get("jcr:title", Calendar.class), propsFromBuilder.get("jcr:title", Calendar.class));
assertEquals("Should be equals to 'cq:PageContent'", propsFromJson.get("jcr:primaryType", Calendar.class), propsFromBuilder.get("jcr:primaryType", Calendar.class));
// this fails
assertEquals("Should be equals to 'Thu Aug 07 2014 16:32:59 GMT+0200'", propsFromJson.get("jcr:created", Calendar.class), propsFromBuilder.get("jcr:created", Calendar.class));
}
}
Regards,
Ruen
Thanks for pointing that out. That makes sense actually. :)
Regards,
Ruen