View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.document;
17  
18  import org.junit.Test;
19  import org.kuali.rice.krad.UserSession;
20  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
21  import org.kuali.rice.krad.test.document.bo.AccountManager;
22  import org.kuali.rice.krad.util.GlobalVariables;
23  import org.kuali.rice.krad.util.KRADConstants;
24  import org.kuali.test.KRADTestCase;
25  
26  import static org.junit.Assert.assertEquals;
27  
28  /**
29   * This class...
30   * 
31   * 
32   */
33  public class MaintenanceDocumentTest extends KRADTestCase {
34  
35      MaintenanceDocument document;
36      
37  
38      @Override
39      public void setUp() throws Exception {
40          super.setUp();
41          GlobalVariables.setUserSession(new UserSession("quickstart"));
42          document = (MaintenanceDocument) KRADServiceLocatorWeb.getDocumentService().getNewDocument("AccountManagerMaintenanceDocument");
43      }
44  
45      private void setupNewAccountMaintDoc(MaintenanceDocument document) {
46  
47          AccountManager am = new AccountManager();
48          am.setAmId(new Long(1));
49          am.setUserName("userName");
50  
51          document.getOldMaintainableObject().setDataObject(null);
52          document.getOldMaintainableObject().setDataObjectClass(am.getClass());
53          document.getNewMaintainableObject().setDataObject(am);
54          document.getNewMaintainableObject().setDataObjectClass(am.getClass());
55  
56      }
57  
58      private void setupEditAccountMaintDoc(MaintenanceDocument document) {
59  
60      	AccountManager fo = new AccountManager();
61      	fo.setAmId(new Long(1));
62      	fo.setUserName("userName");
63  
64          document.getOldMaintainableObject().setDataObject(fo);
65          document.getOldMaintainableObject().setDataObjectClass(fo.getClass());
66          document.getNewMaintainableObject().setDataObject(fo);
67          document.getNewMaintainableObject().setDataObjectClass(fo.getClass());
68  
69      }
70  
71      @Test public void test_NewDoc() {
72  
73          setupNewAccountMaintDoc(document);
74          document.getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_NEW_ACTION);
75  
76          assertEquals("Document should indicate New.", true, document.isNew());
77          assertEquals("Document should not indicate Edit.", false, document.isEdit());
78          assertEquals("Old BO should not be present.", false, document.isOldDataObjectInDocument());
79      }
80  
81      @Test public void test_EditDoc() {
82  
83          setupEditAccountMaintDoc(document);
84          document.getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_EDIT_ACTION);
85  
86          assertEquals("Document should not indicate New.", false, document.isNew());
87          assertEquals("Document should indicate Edit.", true, document.isEdit());
88          assertEquals("Old BO should be present.", true, document.isOldDataObjectInDocument());
89  
90      }
91  
92      @Test public void test_CopyDoc() {
93  
94          setupEditAccountMaintDoc(document);
95          document.getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_COPY_ACTION);
96  
97          assertEquals("Document should indicate New.", true, document.isNew());
98          assertEquals("Document should not indicate Edit.", false, document.isEdit());
99          assertEquals("Old BO should be present.", true, document.isOldDataObjectInDocument());
100 
101     }
102 
103 }