1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.test;
18
19 import org.junit.Assert;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.kuali.rice.kew.api.exception.WorkflowException;
23 import org.kuali.rice.krad.UserSession;
24 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
25 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
26 import org.kuali.rice.krad.util.GlobalVariables;
27 import org.kuali.rice.krad.util.KRADConstants;
28 import org.kuali.test.KRADTestCase;
29
30 import static org.junit.Assert.assertEquals;
31
32 public abstract class BaseMaintenanceDocumentTest extends KRADTestCase {
33 private MaintenanceDocument document;
34 private String documentTypeName;
35 private String initiatorPrincipalName;
36
37 @Override
38 public void setUp() throws Exception {
39 super.setUp();
40 GlobalVariables.setUserSession(new UserSession(getInitiatorPrincipalName()));
41 MaintenanceDocument maintenanceDocument =
42 (MaintenanceDocument) KRADServiceLocatorWeb.getDocumentService().getNewDocument(getDocumentTypeName());
43 maintenanceDocument.getDocumentHeader().setDocumentDescription("test maintenance document");
44 setDocument(maintenanceDocument);
45 }
46
47 @Before
48 public void setUpBeforeTest() {
49 GlobalVariables.getMessageMap().clearErrorMessages();
50 }
51
52
53
54
55
56
57 protected String getDocumentTypeName() {
58 return documentTypeName;
59 }
60
61
62
63
64
65
66 protected String getInitiatorPrincipalName() {
67 return initiatorPrincipalName;
68 }
69
70 protected void setupNewAccountMaintDoc(MaintenanceDocument document) {
71
72 Object am = getNewMaintainableObject();
73
74 document.getOldMaintainableObject().setDataObject(null);
75 document.getOldMaintainableObject().setDataObjectClass(am.getClass());
76 document.getNewMaintainableObject().setDataObject(am);
77 document.getNewMaintainableObject().setDataObjectClass(am.getClass());
78
79 document.getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_NEW_ACTION);
80 }
81
82
83
84
85
86 protected abstract Object getNewMaintainableObject();
87
88
89
90
91
92 protected abstract Object getOldMaintainableObject();
93
94
95
96
97
98
99 protected void setupEditAccountMaintDoc(MaintenanceDocument document) {
100
101 Object newAm = getNewMaintainableObject();
102 Object oldAm = getOldMaintainableObject();
103
104 document.getOldMaintainableObject().setDataObject(oldAm);
105 document.getOldMaintainableObject().setDataObjectClass(oldAm.getClass());
106 document.getNewMaintainableObject().setDataObject(newAm);
107 document.getNewMaintainableObject().setDataObjectClass(newAm.getClass());
108
109 document.getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_EDIT_ACTION);
110 }
111
112 @Test
113
114
115
116 public void test_NewDoc() {
117
118 setupNewAccountMaintDoc(getDocument());
119
120 Assert.assertEquals("Document should indicate New.", true, getDocument().isNew());
121 Assert.assertEquals("Document should not indicate Edit.", false, getDocument().isEdit());
122 Assert.assertEquals("Old BO should not be present.", false, getDocument().isOldDataObjectInDocument());
123 }
124
125 @Test
126
127
128
129 public void test_EditDoc() {
130
131 setupEditAccountMaintDoc(getDocument());
132
133 Assert.assertEquals("Document should not indicate New.", false, getDocument().isNew());
134 Assert.assertEquals("Document should indicate Edit.", true, getDocument().isEdit());
135 Assert.assertEquals("Old BO should be present.", true, getDocument().isOldDataObjectInDocument());
136
137 }
138
139 @Test
140
141
142
143 public void test_CopyDoc() {
144
145 setupEditAccountMaintDoc(getDocument());
146 getDocument().getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_COPY_ACTION);
147
148 Assert.assertEquals("Document should indicate New.", true, getDocument().isNew());
149 Assert.assertEquals("Document should not indicate Edit.", false, getDocument().isEdit());
150 Assert.assertEquals("Old BO should be present.", true, getDocument().isOldDataObjectInDocument());
151
152 }
153
154 @Test
155
156
157
158 public void test_SaveNewDoc() throws WorkflowException {
159 setupNewAccountMaintDoc(getDocument());
160 KRADServiceLocatorWeb.getDocumentService().saveDocument(getDocument());
161 Assert.assertTrue(getDocument().getDocumentHeader().getWorkflowDocument().isSaved());
162 }
163
164 public MaintenanceDocument getDocument() {
165 return document;
166 }
167
168 public void setDocument(MaintenanceDocument document) {
169 this.document = document;
170 }
171 }