001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.service.impl;
017:
018: import java.util.List;
019: import java.util.Map;
020:
021: import org.kuali.core.KualiModule;
022: import org.kuali.core.authorization.AuthorizationType;
023: import org.kuali.core.bo.user.KualiModuleUser;
024: import org.kuali.core.service.KualiModuleService;
025: import org.kuali.kfs.context.KualiTestBase;
026: import org.kuali.kfs.context.SpringContext;
027: import org.kuali.module.chart.bo.Account;
028: import org.kuali.module.chart.bo.ChartUser;
029: import org.kuali.test.ConfigureContext;
030: import org.kuali.test.fixtures.UserNameFixture;
031:
032: @ConfigureContext
033: public class KualiModuleServiceImplTest extends KualiTestBase {
034:
035: private KualiModuleService moduleService;
036:
037: @Override
038: protected void setUp() throws Exception {
039: moduleService = SpringContext.getBean(KualiModuleService.class);
040: }
041:
042: /*
043: * Test method for 'org.kuali.core.service.impl.KualiModuleServiceImpl.getInstalledModules()'
044: */
045: public void testGetInstalledModules() {
046: List<KualiModule> modules = moduleService.getInstalledModules();
047: assertNotNull("installed module list must not be null", modules);
048: assertTrue("installed module list size must not be 0", modules
049: .size() > 0);
050: boolean chartModulePresent = false;
051: for (KualiModule module : modules) {
052: if (module.getModuleId().equals("chart")) {
053: chartModulePresent = true;
054: }
055: }
056: assertTrue("chart module must be present", chartModulePresent);
057: }
058:
059: /*
060: * Test method for 'org.kuali.core.service.impl.KualiModuleServiceImpl.getModuleUsers(UniversalUser)'
061: */
062: public void testGetModuleUsers() throws Exception {
063: List<KualiModule> modules = moduleService.getInstalledModules();
064: Map<String, KualiModuleUser> moduleUsers = moduleService
065: .getModuleUsers(UserNameFixture.KHUNTLEY
066: .getUniversalUser());
067: assertNotNull("module user list must not be null", moduleUsers);
068: assertEquals(
069: "module user list size same as the number of installed modules",
070: modules.size(), moduleUsers.size());
071: KualiModuleUser user = moduleUsers.get(ChartUser.MODULE_ID);
072: assertNotNull("chart module user list must not be null", user);
073: assertTrue("chart module user must be active", user.isActive());
074: assertEquals(
075: "chart module user must have the same UUID as the universal user",
076: UserNameFixture.KHUNTLEY.getUniversalUser()
077: .getPersonUniversalIdentifier(), user
078: .getPersonUniversalIdentifier());
079: }
080:
081: /*
082: * Test method for 'org.kuali.core.service.impl.KualiModuleServiceImpl.getModuleUserList(UniversalUser)'
083: */
084: public void testGetModuleUserList() throws Exception {
085: List<KualiModule> modules = moduleService.getInstalledModules();
086: List<KualiModuleUser> moduleUsers = moduleService
087: .getModuleUserList(UserNameFixture.KHUNTLEY
088: .getUniversalUser());
089: assertNotNull("module user list must not be null", moduleUsers);
090: assertEquals(
091: "module user list size same as the number of installed modules",
092: modules.size(), moduleUsers.size());
093: }
094:
095: /*
096: * Test method for 'org.kuali.core.service.impl.KualiModuleServiceImpl.getModule(String)'
097: */
098: public void testGetModule() {
099: KualiModule module = moduleService
100: .getModule(ChartUser.MODULE_ID);
101: assertNotNull("chart module must not be null", module);
102: }
103:
104: /*
105: * Test method for 'org.kuali.core.service.impl.KualiModuleServiceImpl.isModuleInstalled(String)'
106: */
107: public void testIsModuleInstalled() {
108: assertTrue("chart module must report as installed",
109: moduleService.isModuleInstalled(ChartUser.MODULE_ID));
110: }
111:
112: /*
113: * Test method for 'org.kuali.core.service.impl.KualiModuleServiceImpl.getResponsibleModule(Class)'
114: */
115: public void testGetResponsibleModule() {
116: KualiModule module = moduleService
117: .getResponsibleModule(Account.class);
118: assertNotNull("module must not be null", module);
119: assertEquals("must be chart module", ChartUser.MODULE_ID,
120: module.getModuleId());
121: }
122:
123: /*
124: * Test method for 'org.kuali.core.service.impl.KualiModuleServiceImpl.isAuthorized(UniversalUser, Class, AuthorizationType)'
125: */
126: public void testIsAuthorized() throws Exception {
127: assertTrue("user should be authorized to do account lookups",
128: moduleService.isAuthorized(UserNameFixture.KHUNTLEY
129: .getUniversalUser(),
130: new AuthorizationType.Lookup(Account.class)));
131: }
132:
133: }
|