001    /*
002     * Copyright 2006-2011 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.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/ecl2.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.rice.krad.document;
017    
018    import org.junit.Test;
019    import org.kuali.rice.krad.UserSession;
020    import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
021    import org.kuali.rice.krad.test.document.bo.AccountManager;
022    import org.kuali.rice.krad.util.GlobalVariables;
023    import org.kuali.rice.krad.util.KRADConstants;
024    import org.kuali.test.KRADTestCase;
025    
026    import static org.junit.Assert.assertEquals;
027    
028    /**
029     * This class...
030     * 
031     * 
032     */
033    public class MaintenanceDocumentTest extends KRADTestCase {
034    
035        MaintenanceDocument document;
036        
037    
038        @Override
039        public void setUp() throws Exception {
040            super.setUp();
041            GlobalVariables.setUserSession(new UserSession("quickstart"));
042            document = (MaintenanceDocument) KRADServiceLocatorWeb.getDocumentService().getNewDocument("AccountManagerMaintenanceDocument");
043        }
044    
045        private void setupNewAccountMaintDoc(MaintenanceDocument document) {
046    
047            AccountManager am = new AccountManager();
048            am.setAmId(new Long(1));
049            am.setUserName("userName");
050    
051            document.getOldMaintainableObject().setDataObject(null);
052            document.getOldMaintainableObject().setDataObjectClass(am.getClass());
053            document.getNewMaintainableObject().setDataObject(am);
054            document.getNewMaintainableObject().setDataObjectClass(am.getClass());
055    
056        }
057    
058        private void setupEditAccountMaintDoc(MaintenanceDocument document) {
059    
060            AccountManager fo = new AccountManager();
061            fo.setAmId(new Long(1));
062            fo.setUserName("userName");
063    
064            document.getOldMaintainableObject().setDataObject(fo);
065            document.getOldMaintainableObject().setDataObjectClass(fo.getClass());
066            document.getNewMaintainableObject().setDataObject(fo);
067            document.getNewMaintainableObject().setDataObjectClass(fo.getClass());
068    
069        }
070    
071        @Test public void test_NewDoc() {
072    
073            setupNewAccountMaintDoc(document);
074            document.getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_NEW_ACTION);
075    
076            assertEquals("Document should indicate New.", true, document.isNew());
077            assertEquals("Document should not indicate Edit.", false, document.isEdit());
078            assertEquals("Old BO should not be present.", false, document.isOldDataObjectInDocument());
079        }
080    
081        @Test public void test_EditDoc() {
082    
083            setupEditAccountMaintDoc(document);
084            document.getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_EDIT_ACTION);
085    
086            assertEquals("Document should not indicate New.", false, document.isNew());
087            assertEquals("Document should indicate Edit.", true, document.isEdit());
088            assertEquals("Old BO should be present.", true, document.isOldDataObjectInDocument());
089    
090        }
091    
092        @Test public void test_CopyDoc() {
093    
094            setupEditAccountMaintDoc(document);
095            document.getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_COPY_ACTION);
096    
097            assertEquals("Document should indicate New.", true, document.isNew());
098            assertEquals("Document should not indicate Edit.", false, document.isEdit());
099            assertEquals("Old BO should be present.", true, document.isOldDataObjectInDocument());
100    
101        }
102    
103    }