01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package org.acegisecurity.providers;
17:
18: import junit.framework.TestCase;
19:
20: import org.acegisecurity.Authentication;
21: import org.acegisecurity.GrantedAuthority;
22: import org.acegisecurity.GrantedAuthorityImpl;
23:
24: /**
25: * Tests {@link TestingAuthenticationProvider}.
26: *
27: * @author Ben Alex
28: * @version $Id: TestingAuthenticationProviderTests.java 1496 2006-05-23 13:38:33Z benalex $
29: */
30: public class TestingAuthenticationProviderTests extends TestCase {
31: //~ Constructors ===================================================================================================
32:
33: public TestingAuthenticationProviderTests() {
34: super ();
35: }
36:
37: public TestingAuthenticationProviderTests(String arg0) {
38: super (arg0);
39: }
40:
41: //~ Methods ========================================================================================================
42:
43: public static void main(String[] args) {
44: junit.textui.TestRunner
45: .run(TestingAuthenticationProviderTests.class);
46: }
47:
48: public final void setUp() throws Exception {
49: super .setUp();
50: }
51:
52: public void testAuthenticates() {
53: TestingAuthenticationProvider provider = new TestingAuthenticationProvider();
54: TestingAuthenticationToken token = new TestingAuthenticationToken(
55: "Test", "Password", new GrantedAuthority[] {
56: new GrantedAuthorityImpl("ROLE_ONE"),
57: new GrantedAuthorityImpl("ROLE_TWO") });
58: Authentication result = provider.authenticate(token);
59:
60: if (!(result instanceof TestingAuthenticationToken)) {
61: fail("Should have returned instance of TestingAuthenticationToken");
62: }
63:
64: TestingAuthenticationToken castResult = (TestingAuthenticationToken) result;
65: assertEquals("Test", castResult.getPrincipal());
66: assertEquals("Password", castResult.getCredentials());
67: assertEquals("ROLE_ONE", castResult.getAuthorities()[0]
68: .getAuthority());
69: assertEquals("ROLE_TWO", castResult.getAuthorities()[1]
70: .getAuthority());
71: }
72:
73: public void testSupports() {
74: TestingAuthenticationProvider provider = new TestingAuthenticationProvider();
75: assertTrue(provider.supports(TestingAuthenticationToken.class));
76: assertTrue(!provider.supports(String.class));
77: }
78: }
|