001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-impl/integration-support/src/test/org/sakaiproject/test/section/integration/IntegrationSupportTest.java $
003: * $Id: IntegrationSupportTest.java 18134 2006-11-14 18:59:25Z 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.integration;
021:
022: import java.util.List;
023: import java.util.Set;
024:
025: import junit.framework.Assert;
026:
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029: import org.sakaiproject.section.api.coursemanagement.Course;
030: import org.sakaiproject.section.api.coursemanagement.CourseSection;
031: import org.sakaiproject.section.api.coursemanagement.ParticipationRecord;
032: import org.sakaiproject.section.api.coursemanagement.User;
033: import org.sakaiproject.section.api.facade.Role;
034: import org.sakaiproject.component.section.support.IntegrationSupport;
035: import org.springframework.test.AbstractTransactionalSpringContextTests;
036:
037: public class IntegrationSupportTest extends
038: AbstractTransactionalSpringContextTests {
039: private static final Log log = LogFactory
040: .getLog(IntegrationSupportTest.class);
041:
042: protected String[] getConfigLocations() {
043: String[] configLocations = {
044: "org/sakaiproject/component/section/spring-beans.xml",
045: "org/sakaiproject/component/section/spring-db.xml",
046: "org/sakaiproject/component/section/support/spring-hib-test.xml",
047: "org/sakaiproject/component/section/support/spring-services-test.xml",
048: "org/sakaiproject/component/section/support/spring-integrationSupport.xml" };
049: return configLocations;
050: }
051:
052: private IntegrationSupport integrationSupport;
053:
054: protected void onSetUpInTransaction() throws Exception {
055: integrationSupport = (IntegrationSupport) applicationContext
056: .getBean("org.sakaiproject.component.section.support.IntegrationSupport");
057: }
058:
059: public void testUserIntegration() throws Exception {
060: User user1 = integrationSupport.createUser(
061: "integrationUserId1", "Integration 1 User",
062: "User, Integration 1", "intUser1");
063: Assert.assertTrue(user1 != null);
064: User foundUser = integrationSupport
065: .findUser("integrationUserId1");
066: Assert.assertEquals(user1, foundUser);
067: }
068:
069: public void testSiteMembership() throws Exception {
070: String SITE_CONTEXT_1 = "site_context_1";
071: String INSTRUCTOR_UUID_1 = "integration_instructor1";
072:
073: log.info("Creating course...");
074: integrationSupport.createCourse(SITE_CONTEXT_1, "Site 1",
075: false, false, false);
076:
077: log.info("Creating user...");
078: integrationSupport.createUser(INSTRUCTOR_UUID_1,
079: "Instructor One", "One, Instructor", "inst1");
080:
081: log.info("Creating instructor membership...");
082: ParticipationRecord instMembership1 = integrationSupport
083: .addSiteMembership(INSTRUCTOR_UUID_1, SITE_CONTEXT_1,
084: Role.INSTRUCTOR);
085:
086: // Ensure that we can find the set of sites for this user
087: List siteMemberships = integrationSupport
088: .getAllSiteMemberships(INSTRUCTOR_UUID_1);
089:
090: Assert.assertEquals(siteMemberships.size(), 1);
091: Assert.assertTrue(siteMemberships.contains(instMembership1));
092:
093: // Ensure that we can find the correct set of sites for this user after removing them from a site
094: log.info("Removing instructor membership...");
095: integrationSupport.removeSiteMembership(INSTRUCTOR_UUID_1,
096: SITE_CONTEXT_1);
097: siteMemberships = integrationSupport
098: .getAllSiteMemberships(INSTRUCTOR_UUID_1);
099:
100: Assert.assertEquals(siteMemberships.size(), 0);
101:
102: }
103:
104: public void testSectionMembership() throws Exception {
105: String SITE_CONTEXT_1 = "site_context_1";
106: log.info("Creating course...");
107: Course course = integrationSupport.createCourse(SITE_CONTEXT_1,
108: "Site 1", false, false, false);
109:
110: log.info("Creating user...");
111: User user1 = integrationSupport.createUser(
112: "integrationUserId1", "Integration 1 User",
113: "User, Integration 1", "intUser1");
114:
115: log.info("Creating section...");
116:
117: CourseSection section1 = integrationSupport.createSection(
118: course.getUuid(), "Lecture 1", "category.lecture",
119: new Integer(100), "noplace special", null, null, false,
120: false, false, false, false, false, false);
121:
122: log.info("Adding site membership");
123: ParticipationRecord siteMembership = integrationSupport
124: .addSiteMembership(user1.getUserUid(), SITE_CONTEXT_1,
125: Role.STUDENT);
126:
127: log.info("Adding section membership");
128: ParticipationRecord sectionMembership = integrationSupport
129: .addSectionMembership(user1.getUserUid(), section1
130: .getUuid(), Role.STUDENT);
131:
132: // Ensure that we can find the set of sections for this user
133: Set foundSectionMemberhsips = integrationSupport
134: .getAllSectionMemberships(user1.getUserUid(),
135: SITE_CONTEXT_1);
136: Assert.assertEquals(foundSectionMemberhsips.size(), 1);
137: Assert.assertTrue(foundSectionMemberhsips
138: .contains(sectionMembership));
139:
140: // Remove the user from the section, and ensure that the query no longer returns the enrollment
141: log.info("Remove section membership");
142: integrationSupport.removeSectionMembership(user1.getUserUid(),
143: section1.getUuid());
144: foundSectionMemberhsips = integrationSupport
145: .getAllSectionMemberships(user1.getUserUid(),
146: SITE_CONTEXT_1);
147: Assert.assertEquals(foundSectionMemberhsips.size(), 0);
148:
149: // Ensure that we know which site the user belongs to
150: List siteMemberships = integrationSupport
151: .getAllSiteMemberships(user1.getUserUid());
152: Assert.assertTrue(siteMemberships.contains(siteMembership));
153: }
154:
155: }
|