001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/authz/tags/sakai_2-4-1/authz-impl/integration-test/src/test/org/sakaiproject/authz/impl/AuthzIntegrationTest.java $
003: * $Id: AuthzIntegrationTest.java 13789 2006-08-16 19:03:39Z jholtzman@berkeley.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.authz.impl;
021:
022: import java.util.Set;
023:
024: import junit.extensions.TestSetup;
025: import junit.framework.Assert;
026: import junit.framework.Test;
027: import junit.framework.TestSuite;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import org.sakaiproject.authz.api.AuthzGroup;
032: import org.sakaiproject.authz.api.AuthzGroupService;
033: import org.sakaiproject.authz.api.GroupProvider;
034: import org.sakaiproject.test.SakaiTestBase;
035: import org.sakaiproject.tool.api.Session;
036: import org.sakaiproject.tool.api.SessionManager;
037:
038: public class AuthzIntegrationTest extends SakaiTestBase {
039: private static final Log log = LogFactory
040: .getLog(AuthzIntegrationTest.class);
041:
042: private AuthzGroupService authzGroupService;
043:
044: public static Test suite() {
045: TestSetup setup = new TestSetup(new TestSuite(
046: AuthzIntegrationTest.class)) {
047: protected void setUp() throws Exception {
048: log.debug("starting setup");
049: oneTimeSetup();
050: log.debug("finished setup");
051: }
052:
053: protected void tearDown() throws Exception {
054: oneTimeTearDown();
055: }
056: };
057: return setup;
058: }
059:
060: public void setUp() throws Exception {
061: log.debug("Setting up an AuthzIntegrationTest test");
062:
063: // Connect to the authz service
064: authzGroupService = (AuthzGroupService) getService(AuthzGroupService.class
065: .getName());
066:
067: // This test relies on a GroupProvider that uses '+' to concatenate provider IDs.
068: GroupProvider groupProvider = (GroupProvider) getService(GroupProvider.class
069: .getName());
070: Assert.assertNotNull(groupProvider);
071: Assert.assertEquals(2,
072: groupProvider.unpackId("this+that").length);
073:
074: // Log in
075: SessionManager sessionManager = (SessionManager) getService(SessionManager.class
076: .getName());
077: Session session = sessionManager.getCurrentSession();
078: session.setUserId("admin");
079:
080: // Create some authz groups
081: AuthzGroup foo = authzGroupService
082: .addAuthzGroup("internal-foo");
083: foo.setProviderGroupId("enterprise-foo1+enterprise-foo2");
084: authzGroupService.save(foo);
085:
086: AuthzGroup bar = authzGroupService
087: .addAuthzGroup("internal-bar");
088: bar.setProviderGroupId("enterprise-bar");
089: authzGroupService.save(bar);
090: }
091:
092: public void tearDown() throws Exception {
093: log.debug("Tearing down an AuthzIntegrationTest test");
094:
095: // Remove the authz groups created for testing
096: authzGroupService.removeAuthzGroup("internal-foo");
097: authzGroupService.removeAuthzGroup("internal-bar");
098:
099: // Dereference the service
100: authzGroupService = null;
101: }
102:
103: public void testGetProviderIds() throws Exception {
104: Set fooProviderIds = authzGroupService
105: .getProviderIds("internal-foo");
106: Assert.assertEquals(2, fooProviderIds.size());
107: Assert.assertTrue(fooProviderIds.contains("enterprise-foo1"));
108: Assert.assertTrue(fooProviderIds.contains("enterprise-foo2"));
109:
110: Set barProviderIds = authzGroupService
111: .getProviderIds("internal-bar");
112: Assert.assertEquals(1, barProviderIds.size());
113: Assert.assertTrue(barProviderIds.contains("enterprise-bar"));
114: }
115:
116: public void testGetAuthzGroupIds() throws Exception {
117: Set fooAuthzGroupIds = authzGroupService
118: .getAuthzGroupIds("enterprise-foo1");
119: Assert.assertEquals(1, fooAuthzGroupIds.size());
120: Assert.assertTrue(fooAuthzGroupIds.contains("internal-foo"));
121: }
122: }
|