I am referring to this guide for Stateless authentication and trying to write unit test case for the same
@Test
public void testIdentityService() throws IOException, ServletException {
// Given
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain filterChain = mock(FilterChain.class);
processEngine = EngineUtil.lookupProcessEngine("default");
// When
when(securityContext.getAuthentication()).thenReturn(authentication);
when(securityContext.getAuthentication().getPrincipal()).thenReturn("random");
SecurityContextHolder.setContext(securityContext);
filter.doFilter(request, response, filterChain);
}
I am getting an exception for
private void clearAuthentication(ProcessEngine engine) {
engine.getIdentityService().clearAuthentication();
}
Debugginf the test tells me that engine
is null. Is there a way to mock ProcessEngine engine = EngineUtil.lookupProcessEngine("default");
in my unit test?
Any help appreciated.