@Test(expected = AccessDeniedException.class) public void testSecureMethodWithoutAppropriateAuthority() { TestingAuthenticationToken authentication = new TestingAuthenticationToken("user1", "secret"); SecurityContextHolder.getContext().setAuthentication(authentication); businessService.secureMethod2(); }
@Test public void testSecureMethodWithAppropriateAuthority() { TestingAuthenticationToken authentication = new TestingAuthenticationToken("user1", "secret", "ROLE_EDITOR"); SecurityContextHolder.getContext().setAuthentication(authentication); businessService.secureMethod2(); }
@Test(expected = AuthenticationCredentialsNotFoundException.class) public void testSecureMethodWithoutAuthentication() { businessService.secureMethod2(); }