how to get content fragment model name from contentfragment object which support junit test case. | Community
Skip to main content
New Participant
March 23, 2023
Solved

how to get content fragment model name from contentfragment object which support junit test case.

  • March 23, 2023
  • 1 reply
  • 722 views

how to get content fragment model name from contentfragment object which support junit test case.
Note: contentFragment.getTemplate().getTitle() is not supportive in junit mocking.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Ritesh_Mittal

Hi @sudarshan1992 ,

 

One solution could be to traverse till <content-fragment-path>/jcr:content/data node as a resource, fetch the 'cq:model' property and fetch using ValueMap.

 

Resource res = resourceResolver.getResource("/content/dam/<yourproject-cf-path>/<cf-name>/jcr:content/data");

 

ValueMap map = res.adaptTo(ValueMap .class);

String modelTitle = map.get("cq:model").toString();

 

Thanks,

Ritesh Mittal

 

1 reply

Ritesh_Mittal
Ritesh_MittalAccepted solution
New Participant
March 23, 2023

Hi @sudarshan1992 ,

 

One solution could be to traverse till <content-fragment-path>/jcr:content/data node as a resource, fetch the 'cq:model' property and fetch using ValueMap.

 

Resource res = resourceResolver.getResource("/content/dam/<yourproject-cf-path>/<cf-name>/jcr:content/data");

 

ValueMap map = res.adaptTo(ValueMap .class);

String modelTitle = map.get("cq:model").toString();

 

Thanks,

Ritesh Mittal