001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-impl/integration-test/src/java/org/sakaiproject/test/section/SectionAwarenessImplTest.java $
003: * $Id: SectionAwarenessImplTest.java 18493 2006-11-28 17:27:43Z jholtzman@berkeley.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
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.test.section;
021:
022: import java.util.List;
023:
024: import junit.framework.Assert;
025:
026: //import org.apache.commons.logging.Log;
027: //import org.apache.commons.logging.LogFactory;
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.sakaiproject.section.api.SectionAwareness;
031: import org.sakaiproject.section.api.coursemanagement.CourseSection;
032: import org.sakaiproject.section.api.coursemanagement.ParticipationRecord;
033: import org.sakaiproject.site.api.Group;
034: import org.sakaiproject.site.api.Site;
035: import org.sakaiproject.site.api.SiteService;
036: import org.sakaiproject.test.SakaiTestBase;
037: import org.sakaiproject.tool.api.Session;
038: import org.sakaiproject.tool.api.SessionManager;
039: import org.sakaiproject.user.api.UserDirectoryService;
040: import org.sakaiproject.user.api.UserEdit;
041:
042: public class SectionAwarenessImplTest extends SakaiTestBase {
043: private static final Log log = LogFactory
044: .getLog(SectionAwarenessImplTest.class);
045:
046: // Services
047: private SectionAwareness sectionAwareness;
048: private SiteService siteService;
049: private UserDirectoryService userDirService;
050: private SessionManager sessionManager;
051:
052: // Shared fields needed in each test (and initialized in setUp())
053: private Site site;
054: private Group group1;
055:
056: // Constants
057: private static final String GROUP1_TITLE = "group1";
058:
059: /**
060: * Setup test fixture (runs once for each test method called)
061: */
062: public void setUp() throws Exception {
063: // Fetch the services we need to run the tests
064: sectionAwareness = (SectionAwareness) getService(SectionAwareness.class
065: .getName());
066: siteService = (SiteService) getService(SiteService.class
067: .getName());
068: userDirService = (UserDirectoryService) getService(UserDirectoryService.class
069: .getName());
070: sessionManager = (SessionManager) getService(SessionManager.class
071: .getName());
072:
073: Session session = sessionManager.getCurrentSession();
074: session.setUserId("admin");
075: session.setUserEid("admin");
076:
077: // Create some users
078: userDirService.addUser("test.user.a", "test.user.a", "Jane",
079: "Doe", "jd@foo.com", "123", null, null);
080: userDirService.addUser("test.user.b", "test.user.b", "Joe",
081: "Schmoe", "js@foo.com", "123", null, null);
082:
083: // Create a site
084: site = siteService.addSite(generateSiteId(), "course");
085:
086: // Create a group for SectionAwareness to, er, become aware of
087: group1 = site.addGroup();
088: group1.setTitle(GROUP1_TITLE);
089:
090: // Save the group
091: siteService.save(site);
092:
093: site.addMember("test.user.a", "Student", true, false);
094:
095: // Save the site and its new member
096: siteService.save(site);
097:
098: // Add a user to a group
099: group1.addMember("test.user.a", "Student", true, false);
100:
101: // Save the group with its new member
102: siteService.saveGroupMembership(site);
103: }
104:
105: /**
106: * Remove the newly created objects, so we can run more tests with a clean slate.
107: */
108: public void tearDown() throws Exception {
109: // Remove the site (along with its groups)
110: siteService.removeSite(site);
111:
112: // Remove the users
113: UserEdit user1 = userDirService.editUser("test.user.a");
114: userDirService.removeUser(user1);
115:
116: UserEdit user2 = userDirService.editUser("test.user.b");
117: userDirService.removeUser(user2);
118:
119: sessionManager.getCurrentSession().invalidate();
120: }
121:
122: public void testGetSectionList() throws Exception {
123: // Ensure that section awareness sees the group
124: List sections = sectionAwareness.getSections(site.getId());
125: Assert.assertEquals(sections.size(), 1);
126: Assert.assertTrue(((CourseSection) sections.get(0)).getTitle()
127: .equals(GROUP1_TITLE));
128: }
129:
130: public void testGetSectionMembership() throws Exception {
131: String groupRef = group1.getReference();
132:
133: List members = sectionAwareness.getSectionMembers(groupRef);
134:
135: Assert.assertTrue(members.size() == 1);
136: ParticipationRecord record = (ParticipationRecord) members
137: .get(0);
138: Assert.assertTrue(record.getUser().getUserUid().equals(
139: "test.user.a"));
140: }
141: }
|