Expand my Community achievements bar.

Unit Testing Hands on - For WCMUsePojo | AEM Community Blog Seeding




Unit Testing Hands on - For WCMUsePojo by Myaemlearnings Blog


Quick Recap about WCMUsePojo:
WCMUsePojo initializes the objects associated with Bindings (Eg: WCMBindings/SlingBindings) via its init(Bindings) method which in turn calls activate() method for post initialization tasks.
This init(Bindings bindings) method gets called if the POJO is instantiated in HTL via data-sly-use attribute.
Bindings(javax.script.Bindings) extends Map(java.util.Map) and hence it is basically a map object where key (type String)is the global variable and value is the respective object.
Once when the bindings are initialized, we are able to make use of the global variables which is available to us via methods like getCurrentPage(), getProperties() etc.

Example :
When we call getCurrentPage() to get page object, below happens behind the scene (considering the above flow)
getCurrentPage() -> bindings.get(WCMBindings.CURRENT_PAGE) where WCMBindings.CURRENT_PAGE or WCMBindingsConstants.NAME_CURRENT_PAGE is a scripting variable/reference variable(currentPage) pointing to Page object.

Given the background on WCMUsePojo, writing unit test case for the same involves the following
Mocking Bindings API (javax.script.Bindings)
Dummy implementation for bindings.get() call
Create an instance of WCMUsePojo class
Call init(mockedBindings) method of WCMUsePojo
Call method (under test) of WCMUsePojo

Read Full Blog

Unit Testing Hands on - For WCMUsePojo


Please use this thread to ask the related questions.

Kautuk Sahni

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

0 Replies