/**
* Simulate a request with authenticated user with specified username for a
* specified duration in nanoseconds.
*
* @param username
* the username
* @param durationInNanoseconds
* the duration in nanoseconds
*/
protected void request(String username, long durationInNanoseconds) {
long now = 1510373758000000000L;
when(registry.getNanos()).thenReturn(now, now + durationInNanoseconds);
if (username != null) {
User user = new User(username, "", new ArrayList<GrantedAuthority>());
Authentication auth = new UsernamePasswordAuthenticationToken(user, null);
SecurityContextHolder.getContext().setAuthentication(auth);
}
try {
filter.doFilterInternal(mock(HttpServletRequest.class), mock(HttpServletResponse.class),
mock(FilterChain.class));
} catch (ServletException | IOException e) {
e.printStackTrace();
}
}
MeasureUserActivityFilterTestBase.java 文件源码
java
阅读 30
收藏 0
点赞 0
评论 0
项目:tqdev-metrics
作者:
评论列表
文章目录