Created the below content fragment json.
{
"jcr:primaryType": "cq:ContentFragment",
"jcr:content": {
"jcr:primaryType": "nt:unstructured",
"title": "My Test Content Fragment",
"description": "This is a test content fragment for JUnit.",
"elements": {
"jcr:primaryType": "nt:unstructured",
"headline": {
"jcr:primaryType": "nt:unstructured",
"value": "Test Headline"
},
"body": {
"jcr:primaryType": "nt:unstructured",
"value": "<p>This is the body text of the content fragment.</p>"
}
}
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @SureshVadapalli,
Could you pass the JUnit here to better understand you resolve your query?
Try this:
{
"jcr:primaryType": "dam:Asset",
"jcr:content": {
"jcr:primaryType": "dam:AssetContent",
"data": {
"jcr:primaryType": "nt:resource"
},
"metadata": {
"jcr:primaryType": "nt:unstructured",
"dc:title": "My Test Content Fragment"
},
"contentFragment": true,
"elements": {
"jcr:primaryType": "nt:unstructured",
"headline": {
"jcr:primaryType": "nt:unstructured",
"value": "Test Headline"
},
"body": {
"jcr:primaryType": "nt:unstructured",
"value": "<p>This is the body text of the content fragment.</p>"
}
}
}
}
@ExtendWith(AemContextExtension.class)
class ContentFragmentTest {
private final AemContext context = new AemContext();
@BeforeEach
void setUp() {
context.load().json("/test-content-fragment.json", "/content/dam/test");
}
@Test
void testReadContentFragmentElements() {
Resource cfResource = context.resourceResolver().getResource("/content/dam/test");
ContentFragment contentFragment = cfResource.adaptTo(ContentFragment.class);
assertNotNull(contentFragment);
assertEquals("Test Headline", contentFragment.getElement("headline").getContent());
assertEquals("<p>This is the body text of the content fragment.</p>",
contentFragment.getElement("body").getContent());
}
}
Hi @SureshVadapalli,
Could you pass the JUnit here to better understand you resolve your query?
Try this:
{
"jcr:primaryType": "dam:Asset",
"jcr:content": {
"jcr:primaryType": "dam:AssetContent",
"data": {
"jcr:primaryType": "nt:resource"
},
"metadata": {
"jcr:primaryType": "nt:unstructured",
"dc:title": "My Test Content Fragment"
},
"contentFragment": true,
"elements": {
"jcr:primaryType": "nt:unstructured",
"headline": {
"jcr:primaryType": "nt:unstructured",
"value": "Test Headline"
},
"body": {
"jcr:primaryType": "nt:unstructured",
"value": "<p>This is the body text of the content fragment.</p>"
}
}
}
}
@ExtendWith(AemContextExtension.class)
class ContentFragmentTest {
private final AemContext context = new AemContext();
@BeforeEach
void setUp() {
context.load().json("/test-content-fragment.json", "/content/dam/test");
}
@Test
void testReadContentFragmentElements() {
Resource cfResource = context.resourceResolver().getResource("/content/dam/test");
ContentFragment contentFragment = cfResource.adaptTo(ContentFragment.class);
assertNotNull(contentFragment);
assertEquals("Test Headline", contentFragment.getElement("headline").getContent());
assertEquals("<p>This is the body text of the content fragment.</p>",
contentFragment.getElement("body").getContent());
}
}
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies