Mocking @Inject Page currentPage; and @Inject @Source("script-bindings") private ValueMap pageProperties is giving null | Community
Skip to main content
Level 2
March 7, 2022
Solved

Mocking @Inject Page currentPage; and @Inject @Source("script-bindings") private ValueMap pageProperties is giving null

  • March 7, 2022
  • 1 reply
  • 4303 views

How to mock

@586265

@source(“script-bindings”)

Page currentPage;

and

@586265

@3200416("script-bindings")

private ValueMap pageProperties; 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Anmol_Bhardwaj

Hi @kanikaa32870678 ,

 

If you're using AEMContext, it would be pretty straight forward. Try this:

 Page page = context.currentPage(CONTAINING_PAGE);
 slingBindings = (SlingBindings) context.request().getAttribute(SlingBindings.class.getName());

You can mock value map similarly.

 

https://wcm.io/testing/aem-mock/usage.html#:~:text=The%20AEM%20mock%20context%20can,in%20parallel%2C%20if%20required).

 

AemContext : https://wcm.io/testing/aem-mock/junit5/apidocs/io/wcm/testing/mock/aem/junit5/AemContext.html

 

1 reply

Anmol_Bhardwaj
Community Advisor
Anmol_BhardwajCommunity AdvisorAccepted solution
Community Advisor
March 8, 2022

Hi @kanikaa32870678 ,

 

If you're using AEMContext, it would be pretty straight forward. Try this:

 Page page = context.currentPage(CONTAINING_PAGE);
 slingBindings = (SlingBindings) context.request().getAttribute(SlingBindings.class.getName());

You can mock value map similarly.

 

https://wcm.io/testing/aem-mock/usage.html#:~:text=The%20AEM%20mock%20context%20can,in%20parallel%2C%20if%20required).

 

AemContext : https://wcm.io/testing/aem-mock/junit5/apidocs/io/wcm/testing/mock/aem/junit5/AemContext.html

 

Level 2
March 9, 2022

I tried that but not working. For currentPage @586265 and @3200416(“script-bindings”) both are used in the sling model. 

Anmol_Bhardwaj
Community Advisor
Community Advisor
March 10, 2022

That's fine, what you need to do is, when you create test class for sling modal, use AemContext and get the injected properties through the way described above