1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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 }