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.document;
017:
018: import org.junit.Test;
019: import org.kuali.RiceConstants;
020: import org.kuali.core.UserSession;
021: import org.kuali.core.util.GlobalVariables;
022: import org.kuali.rice.KNSServiceLocator;
023: import org.kuali.test.KNSTestBase;
024: import org.kuali.test.KNSWithTestSpringContext;
025:
026: import edu.sampleu.travel.bo.FiscalOfficer;
027:
028: /**
029: * This class...
030: *
031: *
032: */
033: @KNSWithTestSpringContext
034: public class MaintenanceDocumentTest extends KNSTestBase {
035:
036: MaintenanceDocument document;
037:
038: @Override
039: public void setUp() throws Exception {
040: super .setUp();
041: GlobalVariables.setUserSession(new UserSession("quickstart"));
042: document = (MaintenanceDocument) KNSServiceLocator
043: .getDocumentService().getNewDocument(
044: "FiscalOfficerMaintenanceDocument");
045: }
046:
047: private void setupNewAccountMaintDoc(MaintenanceDocument document) {
048:
049: FiscalOfficer fo = new FiscalOfficer();
050: fo.setId(new Long(1));
051: fo.setUserName("userName");
052:
053: document.getOldMaintainableObject().setBusinessObject(null);
054: document.getOldMaintainableObject().setBoClass(fo.getClass());
055: document.getNewMaintainableObject().setBusinessObject(fo);
056: document.getNewMaintainableObject().setBoClass(fo.getClass());
057:
058: }
059:
060: private void setupEditAccountMaintDoc(MaintenanceDocument document) {
061:
062: FiscalOfficer fo = new FiscalOfficer();
063: fo.setId(new Long(1));
064: fo.setUserName("userName");
065:
066: document.getOldMaintainableObject().setBusinessObject(fo);
067: document.getOldMaintainableObject().setBoClass(fo.getClass());
068: document.getNewMaintainableObject().setBusinessObject(fo);
069: document.getNewMaintainableObject().setBoClass(fo.getClass());
070:
071: }
072:
073: @Test
074: public void test_NewDoc() {
075:
076: setupNewAccountMaintDoc(document);
077: document.getNewMaintainableObject().setMaintenanceAction(
078: RiceConstants.MAINTENANCE_NEW_ACTION);
079:
080: assertEquals("Document should indicate New.", true, document
081: .isNew());
082: assertEquals("Document should not indicate Edit.", false,
083: document.isEdit());
084: assertEquals("Old BO should not be present.", false, document
085: .isOldBusinessObjectInDocument());
086: }
087:
088: @Test
089: public void test_EditDoc() {
090:
091: setupEditAccountMaintDoc(document);
092: document.getNewMaintainableObject().setMaintenanceAction(
093: RiceConstants.MAINTENANCE_EDIT_ACTION);
094:
095: assertEquals("Document should not indicate New.", false,
096: document.isNew());
097: assertEquals("Document should indicate Edit.", true, document
098: .isEdit());
099: assertEquals("Old BO should be present.", true, document
100: .isOldBusinessObjectInDocument());
101:
102: }
103:
104: @Test
105: public void test_CopyDoc() {
106:
107: setupEditAccountMaintDoc(document);
108: document.getNewMaintainableObject().setMaintenanceAction(
109: RiceConstants.MAINTENANCE_COPY_ACTION);
110:
111: assertEquals("Document should indicate New.", true, document
112: .isNew());
113: assertEquals("Document should not indicate Edit.", false,
114: document.isEdit());
115: assertEquals("Old BO should be present.", true, document
116: .isOldBusinessObjectInDocument());
117:
118: }
119:
120: }
|