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.maintenance;
017:
018: import java.util.ArrayList;
019: import java.util.List;
020:
021: import org.kuali.core.KualiModule;
022: import org.kuali.core.bo.user.UniversalUser;
023: import org.kuali.core.document.MaintenanceDocumentBase;
024: import org.kuali.core.document.authorization.MaintenanceDocumentAuthorizations;
025: import org.kuali.core.service.DocumentService;
026: import org.kuali.core.service.KualiModuleService;
027: import org.kuali.core.service.MaintenanceDocumentDictionaryService;
028: import org.kuali.core.service.PersistenceStructureService;
029: import org.kuali.core.util.FieldUtils;
030: import org.kuali.core.web.ui.Section;
031: import org.kuali.kfs.KFSConstants;
032: import org.kuali.kfs.context.KualiTestBase;
033: import org.kuali.kfs.context.SpringContext;
034: import org.kuali.module.chart.bo.ChartUser;
035: import org.kuali.test.ConfigureContext;
036: import org.kuali.test.fixtures.UserNameFixture;
037:
038: @ConfigureContext(session=UserNameFixture.KCOPLEY)
039: public class UniversalUserMaintainableTest extends KualiTestBase {
040:
041: private KualiModuleService moduleService;
042: private MaintenanceDocumentBase document;
043: List<KualiModule> modulesWithProperties = new ArrayList<KualiModule>();
044:
045: protected void setUp() throws Exception {
046: moduleService = SpringContext.getBean(KualiModuleService.class);
047: String docTypeName = SpringContext.getBean(
048: MaintenanceDocumentDictionaryService.class)
049: .getDocumentTypeName(UniversalUser.class);
050: assertNotNull("docTypeName should not be null", docTypeName);
051: document = (MaintenanceDocumentBase) SpringContext.getBean(
052: DocumentService.class).getNewDocument(docTypeName);
053: document.getNewMaintainableObject().setBusinessObject(
054: UserNameFixture.CSWINSON.getUniversalUser());
055: for (KualiModule module : moduleService.getInstalledModules()) {
056: if (module.getModuleUserService().getPropertyList().size() > 0) {
057: modulesWithProperties.add(module);
058: }
059: }
060: }
061:
062: /*
063: * Test method for 'org.kuali.core.maintenance.UniversalUserMaintainable.getSections()'
064: */
065: public void testGetSections() {
066: List keyFieldNames = SpringContext.getBean(
067: PersistenceStructureService.class)
068: .listPrimaryKeyFieldNames(UniversalUser.class);
069: List<Section> oldSections = document.getOldMaintainableObject()
070: .getSections(document.getOldMaintainableObject());
071: List<Section> newSections = document.getNewMaintainableObject()
072: .getSections(document.getOldMaintainableObject());
073:
074: // error keys are only correct after meshing
075: List<Section> meshedSections = FieldUtils.meshSections(
076: oldSections, newSections, keyFieldNames,
077: KFSConstants.MAINTENANCE_COPY_ACTION, false,
078: new MaintenanceDocumentAuthorizations());
079:
080: assertEquals(
081: "number of sections - 1 should be equal to the number of module users with defined properties",
082: modulesWithProperties.size(), meshedSections.size() - 1);
083: for (KualiModule module : modulesWithProperties) {
084: boolean sectionFound = false;
085: for (Section section : meshedSections) {
086: if (section.getErrorKey().contains(
087: "moduleUsers(" + module.getModuleId() + ").")) {
088: sectionFound = true;
089: }
090: }
091: assertTrue("section not found for module: "
092: + module.getModuleId(), sectionFound);
093: }
094: // make sure no extra module sections are present
095: for (KualiModule module : moduleService.getInstalledModules()) {
096: if (!modulesWithProperties.contains(module)) {
097: boolean sectionFound = false;
098: for (Section section : meshedSections) {
099: if (section.getErrorKey().contains(
100: "moduleUsers(" + module.getModuleId()
101: + ").")) {
102: sectionFound = true;
103: }
104: }
105: assertFalse("section found for module "
106: + module.getModuleId()
107: + " and there shouldn't have been",
108: sectionFound);
109: }
110: }
111: }
112:
113: public void testSaveBusinessObject() throws Exception {
114: document.getDocumentHeader().setExplanation(
115: "JUnit test document");
116: UniversalUser user = (UniversalUser) document
117: .getNewMaintainableObject().getBusinessObject();
118: ((ChartUser) user.getModuleUser(ChartUser.MODULE_ID))
119: .setUserChartOfAccountsCode("BL");
120: ((ChartUser) user.getModuleUser(ChartUser.MODULE_ID))
121: .setUserOrganizationCode("PSY");
122: document.getNewMaintainableObject().saveBusinessObject();
123:
124: user = UserNameFixture.CSWINSON.getUniversalUser();
125: assertEquals("Org does not match saved org", "PSY",
126: ((ChartUser) user.getModuleUser(ChartUser.MODULE_ID))
127: .getOrganizationCode());
128: }
129:
130: }
|