This conversation has been locked due to inactivity. Please create a new post.
This conversation has been locked due to inactivity. Please create a new post.
Hi Team,
Hope you are doing well
Can anyone please help to write test case for this function
public List<Map<String, String>> getSliderDetail() {
List<Map<String, String>> sliderDetailsMap=new ArrayList<>();
try {
Resource sliderDetail = resource.getChild("sliderDetails");
if(sliderDetail!=null){
for (Resource slider : sliderDetail.getChildren()) {
Map<String,String> sliderMap=new HashMap<>();
sliderMap.put("title",slider.getValueMap().get("title",String.class));
sliderMap.put("description",slider.getValueMap().get("description",String.class));
sliderDetailsMap.add(sliderMap);
}
}
}catch (Exception e){
LOG.info("\n Model Error : {} ",e.getMessage());
}
return sliderDetailsMap;
}
private final AemContext context = AppAemContext.newAemContext();
@Test
void getSliderDetail() {
Resource resource = context.resourceResolver().getResource(JCR_CONTENT+"demo-aem/components/Customslider");
Resource sliderDetail = resource.getChild("sliderDetails");
assertNotNull(resource);
assertNotNull(sliderDetail);
}
I have tried with this but don't know how can I pass
Resource resource = context.resourceResolver().getResource(JCR_CONTENT+"demo-aem/components/Customslider");
In test cases
any link or suggestion please
Thanks
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @bhagchand
Please refer these links to write test classes for sling models.
https://sling.apache.org/documentation/development/sling-mock.html#sling-models
Hi @bhagchand
Please refer these links to write test classes for sling models.
https://sling.apache.org/documentation/development/sling-mock.html#sling-models
Hi @bhagchand ,
I would configure a page with component(ex:Customslider) whose sling model you are testing and get the json of page with ".infinity.json" extension and use that JSON(ex: modelToTest.json) as the resource in the junit test code. Once you have the JSON uploaded into "bundle/src/test/resources" folder , you can pass it to context
private AemContext context = new AemContext(ResourceResolverType.JCR_MOCK);
context.load().json("modelToTest.json", "/content");
context.currentResource("/content/page1/Customslider");
Make sure you have "sliderDetails" object list in the JSON by configuring it in the page.
Hope that helps!
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies