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