MockitoJUnitRunner bind for WCMUsePojo fails for currentPage and resource in CI (continuous-integration tool)
Hi,
I am using MockitoJUnitRunner for Junit .
As per the below code the bind is not happening in the WCMUsePojo component due to which it shows nullpointer expection for both currentPage and resource that is present in activate method of the component ,but the bind works for request and response.
Also it works in my intellji but the same does not work when same is run in CI tool what could be the issue,with the same code
@9944223
public void activate() throws Exception {
//does not work null pointer
currentPage = getCurrentPage();
resource = getResource();
//picks up
slingHttpServletRequest = getRequest();
slingHttpServletResponse = getResponse();
}
//My code for the component:-
@RunWith(MockitoJUnitRunner.Silent.class)
public class BaseMockTest {
private final TestClass testClass = new TestClass();
@1227241
public final AemContext context = new AemContext(ResourceResolverType.JCR_MOCK);
@Mock
protected MockSlingHttpServletRequest req;
@Mock
protected MockSlingHttpServletResponse res;
@Mock
protected Bindings bindings;
public void initialize(Page page, Resource resource){
when(bindings.get(SlingBindings.REQUEST)).thenReturn(req);
//response
when(bindings.get(SlingBindings.RESPONSE)).thenReturn(res);
//getCurrentPage
when(bindings.get(WCMBindings.CURRENT_PAGE)).thenReturn(page);
when(bindings.get(WCMBindings.RESOURCE_PAGE)).thenReturn(page);
//getPageProperties
when(bindings.get(WCMBindings.PAGE_PROPERTIES)).thenReturn(resource.getValueMap());
//properties
when(bindings.get(WCMBindings.PROPERTIES)).thenReturn(resource.getValueMap());
//getResource
when(bindings.get(SlingBindings.RESOURCE)).thenReturn(context.request().getResource());
//getslingScriptHelper
when(bindings.get(SlingBindings.SLING)).thenReturn(context.slingScriptHelper());
//getInheritedProperties
when(bindings.get(WCMBindings.INHERITED_PAGE_PROPERTIES)).thenReturn(resource.getValueMap());
}
@2785667
public void test() {
req = context.request();
res = context.response();
context.load().json("/metadata.json",
"/content/abc/en/page");
Resource resource = context.create().
resource("/content/abc/en/page/jcr:content/par/nodetest");
context.request().setPathInfo("/content/abc/en/page");
page=context.create().page("/content/abc/en/page");
initialize(page, resource);
testClass.init(bindings);
}}
//pom
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit4</artifactId>
<version>2.7.2</version>
<scope>test</scope>
</dependency>