@Before public void setUp() { contextMock = new ApplicationContextMock(); mockAuthentication(); contextMock.putBean("projectManager", mock(ProjectManager.class)); contextMock.putBean(mock(ContextCurrentService.class)); contextMock.putBean("scheduler", mock(SchedulingService.class)); ApplicationLifecycleListener listener = new DummyListener(); WebApplication app = new WicketApplication(listener) { @Override protected void addInjector() { addComponentInstantiationListener( new PaxWicketSpringBeanComponentInjector(this, contextMock, true)); } }; tester = new WicketTester(app); }
private void mockAuthentication() { AuthenticationManager authManager = mock(AuthenticationManager.class); final Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); authorities.add(new GrantedAuthorityImpl("ROLE_USER")); when(authManager.authenticate(any(Authentication.class))) .thenAnswer( new Answer<Authentication>() { @Override public Authentication answer(InvocationOnMock invocation) { Authentication auth = (Authentication) invocation.getArguments()[0]; if (auth.getCredentials().equals("password")) { return new UsernamePasswordAuthenticationToken( auth.getPrincipal(), auth.getCredentials(), authorities); } throw new BadCredentialsException("wrong password"); } }); contextMock.putBean("authenticationManager", authManager); }