Hi,
Facing one issue while calling "getTemplate" method of content fragment mock. Please let me know your thoughts on the same.
issue details:
java.lang.UnsupportedOperationException
at io.wcm.testing.mock.aem.MockContentFragment.getTemplate(MockContentFragment.java:232)
Junit code snippet:
contentFragment = contentFragmentResource.adaptTo(ContentFragment.class);
lenient().when(contentFragment.getTemplate().getTitle()).thenReturn("testing");
Thanks,
Ravi Joshi
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @Vijayalakshmi_S ,
Thank you. That was a very helpful explanation. But could you suggest how we can mock "getTemplate()" in the same reference. Or there are any other way to get template or content fragment model title to replace this method invocation.
Thanks,
Ravi Joshi
From the API documentation of com.adobe.cq.dam.cfm.* package, no other alternative way to retrieve the Content Fragment Model/CF's template Title.
Hi I'm facing the same issue, has anyone resolve it already?
Views
Replies
Total Likes
Hi @Vijayalakshmi_S ,
I am trying to write a Junit for below piece of code and getting this error
java.lang.UnsupportedOperationException
at io.wcm.testing.mock.aem.MockContentFragment_ContentElement_Structured.getValue(MockContentFragment_ContentElement_Structured.java:173)
Code snippet
private String getAuthoredDate(ContentFragment contentFragment) {
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy");
ContentElement contentElement = contentFragment.getElement("authoredDate");
Calendar date = (Calendar) contentElement.getValue().getValue();
return sdf.format(date.getTime());
}
Any Idea how can I mock the ContentElement getvalue and FragmentData getvalue functions?
Thanks!
Views
Replies
Total Likes
seems like no update soon from AEM mocks for ContentFragment
https://wcm-io.atlassian.net/browse/WTES-75
Resource contentFragmentResource = resourceResolver.getResource(contentFragmentPath);
String modelPath = contentFragmentResource.getChild("jcr:content/data").getValueMap().get("cq:model").toString();
Resource resource = resourceResolver.getResource(modelPath);
resource.getChild("jcr:content").getValueMap().get("jcr:title")
Views
Replies
Total Likes
Views
Likes
Replies