Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Need help with Junit for the below mentioned WCMUse class : Bit Urgent

Avatar

Level 9

Hi All,

public abstract class SampleUse extends WCMUse {

protected List<String> getList(ValueMap resourceProperties) {
        String propertyName = get(Constants.NAME, String.class); 

and so on...

#1] This is like a utility class and has various methods in it, invoked from various places/components. But the requirement is to invoke these methods from SampleUseTest.java even though components are invoking the same code.

#2] The "get" is a WCMUse class, which retrieves arguments passed via sightly [for instance : @ property='Path']. 

#3] From the java code corresponding to the component if "when(bindings.get("property")).thenReturn("Path");" is used then it works fine.

#4] However, when I try the same thing from the above util class, it throws NUllpointer/WCMUse Exception and breaking here.

Any thoughts/pointers on this will be really really helpful.

5 Replies

Avatar

Level 9

Hi All,

Any thoughts on this will be helpful.

Avatar

Level 9

Hi All,

An additional observation as below :

I can see that when any of the WCMUse related methods[https://docs.adobe.com/docs/en/aem/6-0/develop/ref/javadoc/com/adobe/cq/sightly/WCMUse.html#getResou...()]  is being used in the Junit, its failing with Nullpointerexception for those and throwing WCMUseException. However, from other component junit test classes when the same method[i.e, getList() mentioned above]  is called it is working. Not sure where exactly I am going wrong.

Avatar

Level 9

Hi All,

Additional observation:

When I "debug as Junit test", just for this junit class it throws message as seen in screenshot. If i click ok for 3-4 times it then goes to debug mode. Did run couple of builds, restarted eclipse, manually placed core bundle[having java code] into system/console/configMgr, but still the same. Has this got anything to do with the errors its throwing for WCMUse methods.