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
33
34
35
36
37
38
39 public abstract class BaseMaintenanceDocumentTest extends KRADTestCase {
40 private MaintenanceDocument document;
41 private String documentTypeName;
42 private String initiatorPrincipalName;
43
44 @Override
45 public void setUp() throws Exception {
46 super.setUp();
47 GlobalVariables.setUserSession(new UserSession(getInitiatorPrincipalName()));
48 MaintenanceDocument maintenanceDocument =
49 (MaintenanceDocument) KRADServiceLocatorWeb.getDocumentService().getNewDocument(getDocumentTypeName());
50 maintenanceDocument.getDocumentHeader().setDocumentDescription("test maintenance document");
51 setDocument(maintenanceDocument);
52 }
53
54 @Before
55 public void setUpBeforeTest() {
56 GlobalVariables.getMessageMap().clearErrorMessages();
57 }
58
59
60
61
62
63
64 protected String getDocumentTypeName() {
65 return documentTypeName;
66 }
67
68
69
70
71
72
73 protected String getInitiatorPrincipalName() {
74 return initiatorPrincipalName;
75 }
76
77
78
79
80
81
82 protected void setupNewAccountMaintDoc(MaintenanceDocument document) {
83
84 Object am = getNewMaintainableObject();
85
86 document.getOldMaintainableObject().setDataObject(null);
87 document.getOldMaintainableObject().setDataObjectClass(am.getClass());
88 document.getNewMaintainableObject().setDataObject(am);
89 document.getNewMaintainableObject().setDataObjectClass(am.getClass());
90
91 document.getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_NEW_ACTION);
92 }
93
94
95
96
97
98 protected abstract Object getNewMaintainableObject();
99
100
101
102
103
104 protected abstract Object getOldMaintainableObject();
105
106
107
108
109
110
111 protected void setupEditAccountMaintDoc(MaintenanceDocument document) {
112
113 Object newAm = getNewMaintainableObject();
114 Object oldAm = getOldMaintainableObject();
115
116 document.getOldMaintainableObject().setDataObject(oldAm);
117 document.getOldMaintainableObject().setDataObjectClass(oldAm.getClass());
118 document.getNewMaintainableObject().setDataObject(newAm);
119 document.getNewMaintainableObject().setDataObjectClass(newAm.getClass());
120
121 document.getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_EDIT_ACTION);
122 }
123
124 @Test
125
126
127
128 public void test_NewDoc() {
129
130 setupNewAccountMaintDoc(getDocument());
131
132 Assert.assertEquals("Document should indicate New.", true, getDocument().isNew());
133 Assert.assertEquals("Document should not indicate Edit.", false, getDocument().isEdit());
134 Assert.assertEquals("Old BO should not be present.", false, getDocument().isOldDataObjectInDocument());
135 }
136
137 @Test
138
139
140
141 public void test_EditDoc() {
142
143 setupEditAccountMaintDoc(getDocument());
144
145 Assert.assertEquals("Document should not indicate New.", false, getDocument().isNew());
146 Assert.assertEquals("Document should indicate Edit.", true, getDocument().isEdit());
147 Assert.assertEquals("Old BO should be present.", true, getDocument().isOldDataObjectInDocument());
148
149 }
150
151 @Test
152
153
154
155 public void test_CopyDoc() {
156
157 setupEditAccountMaintDoc(getDocument());
158 getDocument().getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_COPY_ACTION);
159
160 Assert.assertEquals("Document should indicate New.", true, getDocument().isNew());
161 Assert.assertEquals("Document should not indicate Edit.", false, getDocument().isEdit());
162 Assert.assertEquals("Old BO should be present.", true, getDocument().isOldDataObjectInDocument());
163
164 }
165
166 @Test
167
168
169
170 public void test_SaveNewDoc() throws WorkflowException {
171 setupNewAccountMaintDoc(getDocument());
172 KRADServiceLocatorWeb.getDocumentService().saveDocument(getDocument());
173 Assert.assertTrue(getDocument().getDocumentHeader().getWorkflowDocument().isSaved());
174 }
175
176
177
178
179
180
181 public MaintenanceDocument getDocument() {
182 return document;
183 }
184
185
186
187
188
189 public void setDocument(MaintenanceDocument document) {
190 this.document = document;
191 }
192 }