01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.lenya.ac.impl;
18:
19: import org.apache.lenya.ac.AccessControlException;
20: import org.apache.lenya.ac.AccreditableManager;
21: import org.apache.lenya.ac.Identity;
22: import org.apache.lenya.ac.User;
23:
24: /**
25: * Tests the identity
26: */
27: public class IdentityTest extends AbstractAccessControlTest {
28:
29: /**
30: * <code>USER_ID</code> The user id to test
31: */
32: public static final String USER_ID = "lenya";
33:
34: /**
35: * Tests the identity.
36: *
37: * @throws AccessControlException if an error occurs
38: */
39: public void testIdentity() throws AccessControlException {
40: Identity identity = new Identity(getLogger());
41: User user = getAccessController().getAccreditableManager()
42: .getUserManager().getUser(USER_ID);
43: getLogger().info("Adding user to identity: [" + user + "]");
44: identity.addIdentifiable(user);
45:
46: assertSame(user, identity.getUser());
47: }
48:
49: /**
50: * Test the {@link Identity#belongsTo(org.apache.lenya.ac.AccreditableManager)} method.
51: * @throws Exception if an error occurs.
52: */
53: public void testBelongsTo() throws Exception {
54: AccreditableManager testMgr = getAccessController(getSession(),
55: "test").getAccreditableManager();
56: AccreditableManager defaultMgr = getAccessController(
57: getSession(), "default").getAccreditableManager();
58:
59: String userId = "lenya";
60: User testUser = testMgr.getUserManager().getUser(userId);
61: User defaultUser = defaultMgr.getUserManager().getUser(userId);
62:
63: Identity testIdentity = new Identity(getLogger());
64: testIdentity.addIdentifiable(testUser);
65:
66: Identity defaultIdentity = new Identity(getLogger());
67: defaultIdentity.addIdentifiable(defaultUser);
68:
69: assertTrue(testIdentity.belongsTo(testMgr));
70: assertTrue(defaultIdentity.belongsTo(defaultMgr));
71:
72: assertTrue(testIdentity.belongsTo(defaultMgr));
73: assertTrue(defaultIdentity.belongsTo(testMgr));
74: }
75:
76: }
|