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