001: /*
002: * Copyright 2004 Anite - Central Government Division
003: * http://www.anite.com/publicsector
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package com.anite.antelope.security;
019:
020: import java.util.Calendar;
021:
022: import junit.framework.TestCase;
023:
024: import org.apache.fulcrum.security.model.dynamic.DynamicAccessControlList;
025: import org.apache.fulcrum.security.model.dynamic.entity.DynamicGroup;
026: import org.apache.fulcrum.security.model.dynamic.entity.DynamicRole;
027: import org.apache.fulcrum.security.model.dynamic.entity.DynamicUser;
028: import org.apache.fulcrum.security.util.DataBackendException;
029: import org.apache.fulcrum.security.util.EntityExistsException;
030: import org.apache.fulcrum.security.util.RoleSet;
031: import org.apache.fulcrum.security.util.UnknownEntityException;
032:
033: import com.anite.antelope.TurbineTestCase;
034:
035: /**
036: * @author Ben.Gidley
037: */
038: public class UserGroupPermissionsHelperT3st extends TestCase {
039:
040: private String groupName = "z12f9";
041: private String userName = "borrisjohnson";
042:
043: private UserGroupPermissionsHelper helper;
044:
045: /* (non-Javadoc)
046: * @see junit.framework.TestCase#setUp()
047: */
048: protected void setUp() throws Exception {
049: TurbineTestCase.initialiseTurbine();
050:
051: helper = UserGroupPermissionsHelper.getInstance();
052: }
053:
054: public void testCreateGroup() throws Exception {
055:
056: groupName = groupName
057: + Calendar.getInstance().getTimeInMillis();
058:
059: DynamicGroup group = (DynamicGroup) helper
060: .createOrFetchGroup(groupName);
061:
062: assertTrue(helper.getGroupManager().checkExists(groupName));
063: assertTrue(helper.getRoleManager().checkExists(groupName));
064: assertTrue(helper.getPermissionManager().checkExists(groupName));
065:
066: RoleSet roles = group.getRoles();
067: assertTrue(roles.containsName(groupName));
068: DynamicRole role = (DynamicRole) roles.getByName(groupName);
069: assertTrue(role.getPermissions().containsName(groupName));
070:
071: // This time it should load it
072: DynamicGroup groupMk2 = (DynamicGroup) helper
073: .createOrFetchGroup(groupName);
074: assertEquals(groupMk2.getId(), group.getId());
075: }
076:
077: public void testCreateUser() throws Exception {
078: userName = userName + Calendar.getInstance().getTimeInMillis();
079:
080: DynamicUser user = (DynamicUser) helper.createUser(userName,
081: "rabbit");
082:
083: assertTrue(helper.getUserManager().checkExists(userName));
084: assertTrue(helper.getGroupManager().checkExists(userName));
085: assertTrue(helper.getRoleManager().checkExists(userName));
086: assertTrue(helper.getPermissionManager().checkExists(userName));
087:
088: DynamicAccessControlList acl = (DynamicAccessControlList) helper
089: .getUserManager().getACL(user);
090: assertTrue(acl.hasPermission(userName));
091:
092: try {
093: DynamicUser userMk2 = (DynamicUser) helper.createUser(
094: userName, "rabbit");
095: } catch (EntityExistsException e) {
096: //PASS
097: return;
098: } catch (DataBackendException e) {
099: fail();
100: } catch (UnknownEntityException e) {
101: fail();
102: }
103: fail();
104: }
105:
106: }
|