Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

JUnit Mock Test Case for Node Property

Avatar

Community Advisor

Hi All,

Need a help to write a test case to check node property

Below is the method which is adding a property to the node

public Map addStyleProperty( List<String> assetStyles,Resource childToutNode){

Resource childPageResource = childToutNode.getParent();

childPageResource

String toutStyle = assetStyles.stream().collect(Collectors.joining(","));

//log.error("toutStyle {}", toutStyle);

//adding style property to the resource*/

try{

ModifiableValueMap properties = childPageResource.adaptTo(ModifiableValueMap.class);

properties.put("dummyStyle", toutStyle); //write

resourceResolver.commit();

return properties;

}

catch(Exception e){

log.error("Unable to add the style property to the resource {} with exception {}", childPageResource,e);

}

}

for this need to write a test case, please help me if any modification required in above let me know.

Below is the code for reference

   @Test

    public void testShopStylesException() throws  Exception, LoginException {

        Set<String> listStyles;

        Resource resource = resourceResolver.getResource(seasonPagePath);

        Page seasonPage = resource.adaptTo(Page.class);

        when(currentPage.getAbsoluteParent(2)).thenReturn(seasonPage);

        when(shopLookupService.fetchShopCodes(anyString(),anyString(),anyString())).thenThrow(IOException.class);

        //smartTile.activate();

        listStyles = smartTile.getShopStyleCodeList();

        assertTrue(listStyles.isEmpty());

    }

Thanks in Advance, Appreciate your help

1 Accepted Solution

Avatar

Correct answer by
Level 2

I was able to get my node property request's working by switching to ResourceResolverType.JCR_MOCK instead, and correcting my test decencies to match the pom.xml in the example https://github.com/adobe/aem-guides-wknd

View solution in original post

1 Reply

Avatar

Correct answer by
Level 2

I was able to get my node property request's working by switching to ResourceResolverType.JCR_MOCK instead, and correcting my test decencies to match the pom.xml in the example https://github.com/adobe/aem-guides-wknd