Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

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.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

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