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 if (udte.getMessage().contains("AccountManagerMaintenanceDocument")) {
54 fail("CI failure - https://jira.kuali.org/browse/KULRICE-9285 " + udte.getMessage() + " " +ExceptionUtils.getStackTrace(udte));
55 }
56 }
57 }
58
59 @Before
60 public void setUpBeforeTest() {
61 GlobalVariables.getMessageMap().clearErrorMessages();
62 }
63
64
65
66
67
68
69 protected String getDocumentTypeName() {
70 return documentTypeName;
71 }
72
73
74
75
76
77
78 protected String getInitiatorPrincipalName() {
79 return initiatorPrincipalName;
80 }
81
82
83
84
85
86
87 protected void setupNewAccountMaintDoc(MaintenanceDocument document) {
88
89 Object am = getNewMaintainableObject();
90
91 document.getOldMaintainableObject().setDataObject(null);
92 document.getOldMaintainableObject().setDataObjectClass(am.getClass());
93 document.getNewMaintainableObject().setDataObject(am);
94 document.getNewMaintainableObject().setDataObjectClass(am.getClass());
95
96 document.getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_NEW_ACTION);
97 }
98
99
100
101
102
103 protected abstract Object getNewMaintainableObject();
104
105
106
107
108
109 protected abstract Object getOldMaintainableObject();
110
111
112
113
114
115
116 protected void setupEditAccountMaintDoc(MaintenanceDocument document) {
117
118 Object newAm = getNewMaintainableObject();
119 Object oldAm = getOldMaintainableObject();
120
121 document.getOldMaintainableObject().setDataObject(oldAm);
122 document.getOldMaintainableObject().setDataObjectClass(oldAm.getClass());
123 document.getNewMaintainableObject().setDataObject(newAm);
124 document.getNewMaintainableObject().setDataObjectClass(newAm.getClass());
125
126 document.getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_EDIT_ACTION);
127 }
128
129 @Test
130
131
132
133 public void test_NewDoc() {
134
135 setupNewAccountMaintDoc(getDocument());
136
137 Assert.assertEquals("Document should indicate New.", true, getDocument().isNew());
138 Assert.assertEquals("Document should not indicate Edit.", false, getDocument().isEdit());
139 Assert.assertEquals("Old BO should not be present.", false, getDocument().isOldDataObjectInDocument());
140 }
141
142 @Test
143
144
145
146 public void test_EditDoc() {
147
148 setupEditAccountMaintDoc(getDocument());
149
150 Assert.assertEquals("Document should not indicate New.", false, getDocument().isNew());
151 Assert.assertEquals("Document should indicate Edit.", true, getDocument().isEdit());
152 Assert.assertEquals("Old BO should be present.", true, getDocument().isOldDataObjectInDocument());
153
154 }
155
156 @Test
157
158
159
160 public void test_CopyDoc() {
161
162 setupEditAccountMaintDoc(getDocument());
163 getDocument().getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_COPY_ACTION);
164
165 Assert.assertEquals("Document should indicate New.", true, getDocument().isNew());
166 Assert.assertEquals("Document should not indicate Edit.", false, getDocument().isEdit());
167 Assert.assertEquals("Old BO should be present.", true, getDocument().isOldDataObjectInDocument());
168
169 }
170
171 @Test
172
173
174
175 public void test_SaveNewDoc() throws WorkflowException {
176 setupNewAccountMaintDoc(getDocument());
177 KRADServiceLocatorWeb.getDocumentService().saveDocument(getDocument());
178 Assert.assertTrue(getDocument().getDocumentHeader().getWorkflowDocument().isSaved());
179 }
180
181
182
183
184
185
186 public MaintenanceDocument getDocument() {
187 return document;
188 }
189
190
191
192
193
194 public void setDocument(MaintenanceDocument document) {
195 this.document = document;
196 }
197 }