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.rice.krad.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 dd.addConfigFileLocation("KR-NS",
83 "classpath:org/kuali/rice/krad/datadictionary/DataDictionaryBaseTypes.xml");
84 dd.addConfigFileLocation("KR-NS",
85 "classpath:org/kuali/rice/krad/datadictionary/AttributeReference.xml");
86 dd.addConfigFileLocation("KR-NS","classpath:org/kuali/rice/kns/bo/datadictionary/DataDictionaryBaseTypes.xml");
87 dd.addConfigFileLocation("KR-KIM","classpath:org/kuali/rice/kim/bo/datadictionary/EmploymentStatus.xml");
88 dd.addConfigFileLocation("KR-KIM","classpath:org/kuali/rice/kim/bo/datadictionary/EmploymentType.xml");
89 dd.addConfigFileLocation("KR-KIM","classpath:org/kuali/rice/kim/impl/identity/PersonImpl.xml");
90 dd.addConfigFileLocation("KR-KIM","classpath:org/kuali/rice/kim/bo/datadictionary/KimBaseBeans.xml");
91 dd.addConfigFileLocation("KR-KIM","classpath:org/kuali/rice/kim/impl/group/Group.xml");
92 dd.addConfigFileLocation("KR-KIM","classpath:org/kuali/rice/kim/impl/role/RoleBo.xml");
93 dd.addConfigFileLocation("KR-KIM","classpath:org/kuali/rice/kim/impl/type/KimType.xml");
94 dd.addConfigFileLocation("KR-NS","classpath:org/kuali/rice/krad/test/document/");
95 dd.addConfigFileLocation("KR-NS","classpath:org/kuali/rice/location/web/campus/Campus.xml");
96 dd.addConfigFileLocation("KR-NS","classpath:org/kuali/rice/location/web/campus/CampusType.xml");
97 dd.addConfigFileLocation("KR-NS","classpath:org/kuali/rice/location/web/country/Country.xml");
98 dd.addConfigFileLocation("KR-NS","classpath:org/kuali/rice/location/web/state/State.xml");
99 dd.addConfigFileLocation("KR-NS","classpath:org/kuali/rice/location/web/county/County.xml");
100 dd.addConfigFileLocation("KR-NS","classpath:org/kuali/rice/location/web/postalcode/PostalCode.xml");
101 dd.addConfigFileLocation("KR-NS","classpath:org/kuali/rice/coreservice/web/parameter/Parameter.xml");
102 dd.addConfigFileLocation("KR-NS","classpath:org/kuali/rice/coreservice/web/parameter/ParameterType.xml");
103 dd.addConfigFileLocation("KR-NS","classpath:org/kuali/rice/coreservice/web/namespace/Namespace.xml");
104 dd.addConfigFileLocation("KR-NS","classpath:org/kuali/rice/coreservice/web/component/Component.xml");
105 dd.parseDataDictionaryConfigurationFiles( false );
106 }
107
108
109
110
111 @After
112 public void tearDown() throws Exception {
113 super.tearDown();
114 dd = null;
115 }
116
117
118
119
120
121
122 @Test
123 public void testValidAndInvalidDDEntries() throws Exception {
124
125 assertExpectedOutcomeOfBOEntryConstruction(AdHocRoutePerson.class, DocumentBase.class, true);
126 assertExpectedOutcomeOfDocEntryConstruction(TransactionalDocumentBase.class, MaintenanceDocumentBase.class, true);
127 assertExpectedOutcomeOfBOEntryConstruction(TransactionalDocumentBase.class, AdHocRouteRecipient.class, true);
128 assertExpectedOutcomeOfDocEntryConstruction(AccountRequestDocument.class, IdentityManagementKimDocument.class, true);
129
130
131 assertExpectedOutcomeOfBOEntryConstruction(AdHocRoutePerson.class, AdHocRouteRecipient.class, true);
132 assertExpectedOutcomeOfDocEntryConstruction(TransactionalDocumentBase.class, DocumentBase.class, true);
133 assertExpectedOutcomeOfBOEntryConstruction(AdHocRouteWorkgroup.class, AdHocRouteRecipient.class, true);
134 assertExpectedOutcomeOfDocEntryConstruction(IdentityManagementPersonDocument.class, IdentityManagementKimDocument.class, true);
135
136
137 assertExpectedOutcomeOfBOEntryConstruction(AdHocRouteRecipient.class, AdHocRoutePerson.class, true);
138 assertExpectedOutcomeOfDocEntryConstruction(IdentityManagementKimDocument.class, IdentityManagementGroupDocument.class, true);
139
140
141
142 assertExpectedOutcomeOfBOEntryConstruction(AdHocRoutePerson.class, AdHocRoutePerson.class, true);
143 assertExpectedOutcomeOfDocEntryConstruction(MaintenanceDocumentBase.class, MaintenanceDocumentBase.class, true);
144 }
145
146
147
148
149
150
151 @Test
152 public void testRetrieveDDEntriesByBaseClass() throws Exception {
153
154 Object[][] tests = {
155 { "AccountType2Parent", "AccountType2",
156 AccountType2.class, AccountType2Parent.class, "accountTypeCode2", "Account Type 2" },
157 { "org.kuali.rice.krad.test.document.bo.AccountType2Parent", "org.kuali.rice.krad.test.document.bo.AccountType2",
158 AccountType2.class, AccountType2Parent.class, "accountTypeCode2", "Account Type 2" },
159 { "AccountTypeDivergentParent", "AccountTypeDivergent",
160 AccountTypeDivergent.class, AccountTypeDivergentParent.class, "accountTypeCode Divergent", "Account Type Divergent" },
161 { "org.kuali.rice.krad.test.document.bo.AccountTypeDivergentParent", "org.kuali.rice.krad.test.document.bo.AccountTypeDivergent",
162 AccountTypeDivergent.class, AccountTypeDivergentParent.class, "accountTypeCode Divergent", "Account Type Divergent" }
163 };
164 for (Object[] test: tests) {
165
166 assertBusinessObjectEntry(dd.getBusinessObjectEntry((String) test[0]), (Class) test[2], (Class) test[3], (String) test[4], (String) test[5]);
167
168 assertBusinessObjectEntry(dd.getBusinessObjectEntry((String) test[1]), (Class) test[2], (Class) test[3], (String) test[4], (String) test[5]);
169 }
170
171
172 tests = new Object[][] {
173 { "RiceTestTransactionalDocument2Parent", "RiceTestTransactionalDocument2",
174 RiceTestTransactionalDocument2.class, RiceTestTransactionalDocument2Parent.class },
175 { "org.kuali.rice.krad.impls.RiceTestTransactionalDocument2Parent", "org.kuali.rice.krad.impls.RiceTestTransactionalDocument2",
176 RiceTestTransactionalDocument2.class, RiceTestTransactionalDocument2Parent.class },
177 { "RiceTestTransactionalDocumentDivergentParent", "RiceTestTransactionalDocumentDivergent",
178 RiceTestTransactionalDocumentDivergent.class, RiceTestTransactionalDocumentDivergentParent.class },
179 { "org.kuali.rice.krad.impls.RiceTestTransactionalDocumentDivergentParent", "org.kuali.rice.krad.impls.RiceTestTransactionalDocumentDivergent",
180 RiceTestTransactionalDocumentDivergent.class, RiceTestTransactionalDocumentDivergentParent.class }
181 };
182 for (Object[] test: tests) {
183
184 assertDocumentEntry(dd.getDocumentEntry((String) test[0]), (Class) test[2], (Class) test[3]);
185
186 assertDocumentEntry(dd.getDocumentEntry((String) test[1]), (Class) test[2], (Class) test[3]);
187 }
188
189
190
191
192 DataDictionaryEntry ddEntry = dd.getDictionaryObjectEntry("AccountType2");
193 assertNotNull("The AccountType2 DD entry from the entriesByJstlKey map should not be null", ddEntry);
194 assertTrue("The DD entry should have been a BusinessObjectEntry", ddEntry instanceof BusinessObjectEntry);
195 assertBusinessObjectEntryIsAccountType2((BusinessObjectEntry) ddEntry);
196 }
197
198
199
200
201
202
203
204
205
206 private void assertExpectedOutcomeOfBOEntryConstruction(Class<? extends BusinessObject> boClass,
207 Class<? extends BusinessObject> boBaseClass, boolean shouldSucceed) throws Exception {
208
209 BusinessObjectEntry boEntry = new BusinessObjectEntry();
210 boEntry.setBusinessObjectClass(boClass);
211 boEntry.setBaseBusinessObjectClass(boBaseClass);
212 boEntry.setObjectLabel(boClass.getSimpleName());
213
214 try {
215 boEntry.completeValidation();
216
217 if (!shouldSucceed) {
218 fail("The BO entry should have thrown a ClassValidationException during the validation process");
219 }
220 }
221 catch (ClassValidationException e) {
222
223 if (shouldSucceed) {
224 fail("The BO entry should not have thrown a ClassValidationException during the validation process");
225 }
226 }
227 }
228
229
230
231
232
233
234
235
236
237 private void assertExpectedOutcomeOfDocEntryConstruction(Class<? extends Document> docClass,
238 Class<? extends Document> docBaseClass, boolean shouldSucceed) throws Exception {
239
240 DocumentEntry docEntry = new TransactionalDocumentEntry();
241 docEntry.setDocumentClass(docClass);
242 docEntry.setBaseDocumentClass(docBaseClass);
243
244 try {
245 docEntry.completeValidation();
246
247 if (!shouldSucceed) {
248 fail("The doc entry should have thrown a ClassValidationException during the validation process");
249 }
250 }
251 catch (ClassValidationException e) {
252
253 if (shouldSucceed) {
254 fail("The doc entry should not have thrown a ClassValidationException during the validation process");
255 }
256 }
257 }
258
259
260
261
262
263
264
265 private void assertBusinessObjectEntryIsAccountType2(BusinessObjectEntry boEntry) throws Exception {
266 assertBusinessObjectEntry(boEntry, AccountType2.class, AccountType2Parent.class, "accountTypeCode2", "Account Type 2");
267 }
268
269
270
271
272
273
274
275 private void assertBusinessObjectEntry(BusinessObjectEntry boEntry, Class boClass, Class boBaseClass, String title, String label) throws Exception {
276 assertNotNull("The DD entry should not be null", boEntry);
277 assertEquals("The DD entry does not represent the " + boClass.getName() + " entry", boClass, boEntry.getBusinessObjectClass());
278 assertEquals("The DD entry does not have the expected base class", boBaseClass, boEntry.getBaseBusinessObjectClass());
279 assertEquals("The DD entry does not have the expected title attribute", title, boEntry.getTitleAttribute());
280 assertEquals("The DD entry does not have the expected object label", label, boEntry.getObjectLabel());
281 }
282
283
284
285
286
287
288
289 private void assertDocumentEntry(DocumentEntry docEntry, Class docClass, Class baseDocClass) throws Exception {
290 assertNotNull("The RiceTestTransactionalDocument2 DD entry should not be null", docEntry);
291 assertEquals("The DD entry does not represent the RiceTestTransactionalDocument2 entry",
292 docClass, docEntry.getDocumentClass());
293 assertEquals("The DD entry does not have the expected base class", baseDocClass, docEntry.getBaseDocumentClass());
294 }
295 }