1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary;
17
18 import org.junit.After;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.kuali.rice.kim.document.IdentityManagementGroupDocument;
22 import org.kuali.rice.kim.document.IdentityManagementKimDocument;
23 import org.kuali.rice.kim.document.IdentityManagementPersonDocument;
24 import org.kuali.rice.krad.bo.AdHocRoutePerson;
25 import org.kuali.rice.krad.bo.AdHocRouteRecipient;
26 import org.kuali.rice.krad.bo.AdHocRouteWorkgroup;
27 import org.kuali.rice.krad.bo.BusinessObject;
28 import org.kuali.rice.krad.datadictionary.exception.ClassValidationException;
29 import org.kuali.rice.krad.document.Document;
30 import org.kuali.rice.krad.document.DocumentBase;
31 import org.kuali.rice.krad.impls.RiceTestTransactionalDocumentDivergent;
32 import org.kuali.rice.krad.impls.RiceTestTransactionalDocumentDivergentParent;
33 import org.kuali.rice.krad.maintenance.MaintenanceDocumentBase;
34 import org.kuali.rice.krad.document.TransactionalDocumentBase;
35 import org.kuali.rice.krad.impls.RiceTestTransactionalDocument2;
36 import org.kuali.rice.krad.impls.RiceTestTransactionalDocument2Parent;
37 import org.kuali.rice.krad.test.document.AccountRequestDocument;
38 import org.kuali.rice.krad.test.document.bo.AccountType2;
39 import org.kuali.rice.krad.test.document.bo.AccountType2Parent;
40 import org.kuali.rice.krad.test.document.bo.AccountTypeDivergent;
41 import org.kuali.rice.krad.test.document.bo.AccountTypeDivergentParent;
42 import org.kuali.test.KRADTestCase;
43
44 import static org.junit.Assert.*;
45
46
47
48
49
50
51
52
53
54 public class BaseBOClassAndBaseDocumentClassTest extends KRADTestCase {
55
56 DataDictionary dd = null;
57
58
59
60
61 @Before
62 public void setUp() throws Exception {
63 super.setUp();
64
65 dd = new DataDictionary();
66
67 dd.addConfigFileLocation("KR-NS", "classpath:org/kuali/rice/krad/uif/UifControlDefinitions.xml");
68 dd.addConfigFileLocation("KR-NS", "classpath:org/kuali/rice/krad/uif/UifFieldDefinitions.xml");
69 dd.addConfigFileLocation("KR-NS", "classpath:org/kuali/rice/krad/uif/UifGroupDefinitions.xml");
70 dd.addConfigFileLocation("KR-NS", "classpath:org/kuali/rice/krad/uif/UifHeaderFooterDefinitions.xml");
71 dd.addConfigFileLocation("KR-NS", "classpath:org/kuali/rice/krad/uif/UifLayoutManagerDefinitions.xml");
72 dd.addConfigFileLocation("KR-NS", "classpath:org/kuali/rice/krad/uif/UifViewPageDefinitions.xml");
73 dd.addConfigFileLocation("KR-NS", "classpath:org/kuali/rice/krad/uif/UifWidgetDefinitions.xml");
74 dd.addConfigFileLocation("KR-NS", "classpath:org/kuali/rice/krad/uif/UifConfigurationDefinitions.xml");
75 dd.addConfigFileLocation("KR-NS", "classpath:org/kuali/rice/krad/uif/UifRiceDefinitions.xml");
76 dd.addConfigFileLocation("KR-NS", "classpath:org/kuali/rice/krad/uif/UifLookupDefinitions.xml");
77 dd.addConfigFileLocation("KR-NS", "classpath:org/kuali/rice/krad/uif/UifInquiryDefinitions.xml");
78 dd.addConfigFileLocation("KR-NS", "classpath:org/kuali/rice/krad/uif/UifMaintenanceDefinitions.xml");
79 dd.addConfigFileLocation("KR-NS", "classpath:org/kuali/rice/krad/uif/UifDocumentDefinitions.xml");
80 dd.addConfigFileLocation("KR-NS", "classpath:org/kuali/rice/krad/uif/UifElementDefinitions.xml");
81 dd.addConfigFileLocation("KR-NS", "classpath:org/kuali/rice/krad/uif/UifActionDefinitions.xml");
82
83 dd.addConfigFileLocation("KR-NS","file:" + getUserDir() + "/../../impl/src/main/resources/org/kuali/rice/krad/bo/datadictionary");
84 dd.addConfigFileLocation("KR-NS","classpath:org/kuali/rice/kns/bo/datadictionary/DataDictionaryBaseTypes.xml");
85 dd.addConfigFileLocation("KR-KIM","classpath:org/kuali/rice/kim/bo/datadictionary/EmploymentStatus.xml");
86 dd.addConfigFileLocation("KR-KIM","classpath:org/kuali/rice/kim/bo/datadictionary/EmploymentType.xml");
87 dd.addConfigFileLocation("KR-KIM","classpath:org/kuali/rice/kim/impl/identity/PersonImpl.xml");
88 dd.addConfigFileLocation("KR-KIM","classpath:org/kuali/rice/kim/bo/datadictionary/KimBaseBeans.xml");
89 dd.addConfigFileLocation("KR-KIM","classpath:org/kuali/rice/kim/impl/group/Group.xml");
90 dd.addConfigFileLocation("KR-KIM","classpath:org/kuali/rice/kim/impl/role/RoleBo.xml");
91 dd.addConfigFileLocation("KR-KIM","classpath:org/kuali/rice/kim/impl/type/KimType.xml");
92 dd.addConfigFileLocation("KR-NS","classpath:org/kuali/rice/krad/test/document/");
93 dd.addConfigFileLocation("KR-NS","file:" + getBaseDir() + "/../../location/web/src/main/resources/org/kuali/rice/location/web/campus/Campus.xml");
94 dd.addConfigFileLocation("KR-NS","file:" + getBaseDir() + "/../../location/web/src/main/resources/org/kuali/rice/location/web/campus/CampusType.xml");
95 dd.addConfigFileLocation("KR-NS","file:" + getBaseDir() + "/../../location/web/src/main/resources/org/kuali/rice/location/web/country/Country.xml");
96 dd.addConfigFileLocation("KR-NS","file:" + getBaseDir() + "/../../location/web/src/main/resources/org/kuali/rice/location/web/state/State.xml");
97 dd.addConfigFileLocation("KR-NS","file:" + getBaseDir() + "/../../location/web/src/main/resources/org/kuali/rice/location/web/county/County.xml");
98 dd.addConfigFileLocation("KR-NS","file:" + getBaseDir() + "/../../location/web/src/main/resources/org/kuali/rice/location/web/postalcode/PostalCode.xml");
99 dd.addConfigFileLocation("KR-NS","file:" + getBaseDir() + "/../../core-service/web/src/main/resources/org/kuali/rice/coreservice/web/parameter/Parameter.xml");
100 dd.addConfigFileLocation("KR-NS","file:" + getBaseDir() + "/../../core-service/web/src/main/resources/org/kuali/rice/coreservice/web/parameter/ParameterType.xml");
101 dd.addConfigFileLocation("KR-NS","file:" + getBaseDir() + "/../../core-service/web/src/main/resources/org/kuali/rice/coreservice/web/namespace/Namespace.xml");
102 dd.addConfigFileLocation("KR-NS","file:" + getBaseDir() + "/../../core-service/web/src/main/resources/org/kuali/rice/coreservice/web/component/Component.xml");
103 dd.parseDataDictionaryConfigurationFiles( false );
104 }
105
106
107
108
109 @After
110 public void tearDown() throws Exception {
111 super.tearDown();
112 dd = null;
113 }
114
115
116
117
118
119
120 @Test
121 public void testValidAndInvalidDDEntries() throws Exception {
122
123 assertExpectedOutcomeOfBOEntryConstruction(AdHocRoutePerson.class, DocumentBase.class, true);
124 assertExpectedOutcomeOfDocEntryConstruction(TransactionalDocumentBase.class, MaintenanceDocumentBase.class, true);
125 assertExpectedOutcomeOfBOEntryConstruction(TransactionalDocumentBase.class, AdHocRouteRecipient.class, true);
126 assertExpectedOutcomeOfDocEntryConstruction(AccountRequestDocument.class, IdentityManagementKimDocument.class, true);
127
128
129 assertExpectedOutcomeOfBOEntryConstruction(AdHocRoutePerson.class, AdHocRouteRecipient.class, true);
130 assertExpectedOutcomeOfDocEntryConstruction(TransactionalDocumentBase.class, DocumentBase.class, true);
131 assertExpectedOutcomeOfBOEntryConstruction(AdHocRouteWorkgroup.class, AdHocRouteRecipient.class, true);
132 assertExpectedOutcomeOfDocEntryConstruction(IdentityManagementPersonDocument.class, IdentityManagementKimDocument.class, true);
133
134
135 assertExpectedOutcomeOfBOEntryConstruction(AdHocRouteRecipient.class, AdHocRoutePerson.class, true);
136 assertExpectedOutcomeOfDocEntryConstruction(IdentityManagementKimDocument.class, IdentityManagementGroupDocument.class, true);
137
138
139
140 assertExpectedOutcomeOfBOEntryConstruction(AdHocRoutePerson.class, AdHocRoutePerson.class, true);
141 assertExpectedOutcomeOfDocEntryConstruction(MaintenanceDocumentBase.class, MaintenanceDocumentBase.class, true);
142 }
143
144
145
146
147
148
149 @Test
150 public void testRetrieveDDEntriesByBaseClass() throws Exception {
151
152 Object[][] tests = {
153 { "AccountType2Parent", "AccountType2",
154 AccountType2.class, AccountType2Parent.class, "accountTypeCode2", "Account Type 2" },
155 { "org.kuali.rice.krad.test.document.bo.AccountType2Parent", "org.kuali.rice.krad.test.document.bo.AccountType2",
156 AccountType2.class, AccountType2Parent.class, "accountTypeCode2", "Account Type 2" },
157 { "AccountTypeDivergentParent", "AccountTypeDivergent",
158 AccountTypeDivergent.class, AccountTypeDivergentParent.class, "accountTypeCode Divergent", "Account Type Divergent" },
159 { "org.kuali.rice.krad.test.document.bo.AccountTypeDivergentParent", "org.kuali.rice.krad.test.document.bo.AccountTypeDivergent",
160 AccountTypeDivergent.class, AccountTypeDivergentParent.class, "accountTypeCode Divergent", "Account Type Divergent" }
161 };
162 for (Object[] test: tests) {
163
164 assertBusinessObjectEntry(dd.getBusinessObjectEntry((String) test[0]), (Class) test[2], (Class) test[3], (String) test[4], (String) test[5]);
165
166 assertBusinessObjectEntry(dd.getBusinessObjectEntry((String) test[1]), (Class) test[2], (Class) test[3], (String) test[4], (String) test[5]);
167 }
168
169
170 tests = new Object[][] {
171 { "RiceTestTransactionalDocument2Parent", "RiceTestTransactionalDocument2",
172 RiceTestTransactionalDocument2.class, RiceTestTransactionalDocument2Parent.class },
173 { "org.kuali.rice.krad.impls.RiceTestTransactionalDocument2Parent", "org.kuali.rice.krad.impls.RiceTestTransactionalDocument2",
174 RiceTestTransactionalDocument2.class, RiceTestTransactionalDocument2Parent.class },
175 { "RiceTestTransactionalDocumentDivergentParent", "RiceTestTransactionalDocumentDivergent",
176 RiceTestTransactionalDocumentDivergent.class, RiceTestTransactionalDocumentDivergentParent.class },
177 { "org.kuali.rice.krad.impls.RiceTestTransactionalDocumentDivergentParent", "org.kuali.rice.krad.impls.RiceTestTransactionalDocumentDivergent",
178 RiceTestTransactionalDocumentDivergent.class, RiceTestTransactionalDocumentDivergentParent.class }
179 };
180 for (Object[] test: tests) {
181
182 assertDocumentEntry(dd.getDocumentEntry((String) test[0]), (Class) test[2], (Class) test[3]);
183
184 assertDocumentEntry(dd.getDocumentEntry((String) test[1]), (Class) test[2], (Class) test[3]);
185 }
186
187
188
189
190 DataDictionaryEntry ddEntry = dd.getDictionaryObjectEntry("AccountType2");
191 assertNotNull("The AccountType2 DD entry from the entriesByJstlKey map should not be null", ddEntry);
192 assertTrue("The DD entry should have been a BusinessObjectEntry", ddEntry instanceof BusinessObjectEntry);
193 assertBusinessObjectEntryIsAccountType2((BusinessObjectEntry) ddEntry);
194 }
195
196
197
198
199
200
201
202
203
204 private void assertExpectedOutcomeOfBOEntryConstruction(Class<? extends BusinessObject> boClass,
205 Class<? extends BusinessObject> boBaseClass, boolean shouldSucceed) throws Exception {
206
207 BusinessObjectEntry boEntry = new BusinessObjectEntry();
208 boEntry.setBusinessObjectClass(boClass);
209 boEntry.setBaseBusinessObjectClass(boBaseClass);
210 boEntry.setObjectLabel(boClass.getSimpleName());
211
212 try {
213 boEntry.completeValidation();
214
215 if (!shouldSucceed) {
216 fail("The BO entry should have thrown a ClassValidationException during the validation process");
217 }
218 }
219 catch (ClassValidationException e) {
220
221 if (shouldSucceed) {
222 fail("The BO entry should not have thrown a ClassValidationException during the validation process");
223 }
224 }
225 }
226
227
228
229
230
231
232
233
234
235 private void assertExpectedOutcomeOfDocEntryConstruction(Class<? extends Document> docClass,
236 Class<? extends Document> docBaseClass, boolean shouldSucceed) throws Exception {
237
238 DocumentEntry docEntry = new TransactionalDocumentEntry();
239 docEntry.setDocumentClass(docClass);
240 docEntry.setBaseDocumentClass(docBaseClass);
241
242 try {
243 docEntry.completeValidation();
244
245 if (!shouldSucceed) {
246 fail("The doc entry should have thrown a ClassValidationException during the validation process");
247 }
248 }
249 catch (ClassValidationException e) {
250
251 if (shouldSucceed) {
252 fail("The doc entry should not have thrown a ClassValidationException during the validation process");
253 }
254 }
255 }
256
257
258
259
260
261
262
263 private void assertBusinessObjectEntryIsAccountType2(BusinessObjectEntry boEntry) throws Exception {
264 assertBusinessObjectEntry(boEntry, AccountType2.class, AccountType2Parent.class, "accountTypeCode2", "Account Type 2");
265 }
266
267
268
269
270
271
272
273 private void assertBusinessObjectEntry(BusinessObjectEntry boEntry, Class boClass, Class boBaseClass, String title, String label) throws Exception {
274 assertNotNull("The DD entry should not be null", boEntry);
275 assertEquals("The DD entry does not represent the " + boClass.getName() + " entry", boClass, boEntry.getBusinessObjectClass());
276 assertEquals("The DD entry does not have the expected base class", boBaseClass, boEntry.getBaseBusinessObjectClass());
277 assertEquals("The DD entry does not have the expected title attribute", title, boEntry.getTitleAttribute());
278 assertEquals("The DD entry does not have the expected object label", label, boEntry.getObjectLabel());
279 }
280
281
282
283
284
285
286
287 private void assertDocumentEntry(DocumentEntry docEntry, Class docClass, Class baseDocClass) throws Exception {
288 assertNotNull("The RiceTestTransactionalDocument2 DD entry should not be null", docEntry);
289 assertEquals("The DD entry does not represent the RiceTestTransactionalDocument2 entry",
290 docClass, docEntry.getDocumentClass());
291 assertEquals("The DD entry does not have the expected base class", baseDocClass, docEntry.getBaseDocumentClass());
292 }
293 }