1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.helpentry;
17
18 import java.util.Collection;
19 import java.util.List;
20 import java.util.StringTokenizer;
21
22 import org.junit.Ignore;
23 import org.junit.Test;
24 import org.kuali.rice.kew.help.HelpEntry;
25 import org.kuali.rice.kew.help.dao.HelpDAO;
26 import org.kuali.rice.kew.service.KEWServiceLocator;
27 import org.kuali.rice.kew.test.KEWTestCase;
28
29
30
31
32
33
34
35
36
37
38 @Ignore("KULRICE-2090")
39 public class HelpEntryJpaOjbTest extends KEWTestCase {
40
41 private static String HELPKEY = "testhepentry1";
42 private static String HELPKEY2 = "testhelpentry2";
43 private static String HELPKEY3 = "diffhepentry4";
44 private static String NEW_HELPKEY = "brandNewhelpentry5";
45
46
47 private static final String NON_EXISTENT_KEY = "BogusKey";
48 private static final String NAME_PATTERN1 = "test";
49 private static final String NAME_PATTERN2 = "test help";
50 private static final String NAME_PATTERN3 = "TEST";
51 private static final String NAME_PATTERN4 = "test Help";
52 private static final String NAME_PATTERN5 = "diff";
53 private static final String NAME_PATTERN6 = "test diff";
54 private static final String NAME_PATTERN7 = "help";
55
56 private static final String KEY_PATTERN1 = "entry";
57 private static final String KEY_PATTERN2 = "2";
58 private static final String KEY_PATTERN3 = "hep";
59 private static final String KEY_PATTERN4 = "ff";
60 private static final String KEY_PATTERN5 = "testhepentry";
61 private static final String KEY_PATTERN6 = "esthepentry";
62 private static final String KEY_PATTERN7 = "testhepentry3";
63
64 private static final String TEXT_PATTERN1 = "test";
65 private static final String TEXT_PATTERN2 = "help";
66 private static final String TEXT_PATTERN3 = "<";
67 private static final String TEXT_PATTERN4 = "<p>";
68 private static final String TEXT_PATTERN5 = "entry";
69 private static final String TEXT_PATTERN6 = "hep";
70 private static final String TEXT_PATTERN7 = "</p>><a href";
71
72 private static final String COMBO_PATTERN1 = "test,entry1,entry";
73 private static final String COMBO_PATTERN2 = "help,entry,help";
74 private static final String COMBO_PATTERN3 = "help,entry,<p>";
75
76 private String nsArray[] = {NAME_PATTERN1, NAME_PATTERN2, NAME_PATTERN3, NAME_PATTERN4, NAME_PATTERN5, NAME_PATTERN6, NAME_PATTERN7};
77 private String ksArray[] = {KEY_PATTERN1, KEY_PATTERN2, KEY_PATTERN3, KEY_PATTERN4, KEY_PATTERN5, KEY_PATTERN6, KEY_PATTERN7};
78 private String tsArray[] = {TEXT_PATTERN1, TEXT_PATTERN2, TEXT_PATTERN3, TEXT_PATTERN4, TEXT_PATTERN5, TEXT_PATTERN6, TEXT_PATTERN7};
79 private String csArray[] = {COMBO_PATTERN1, COMBO_PATTERN2, COMBO_PATTERN3};
80 private Long idForJpa;
81 private Long idForOjb;
82 private static Long NON_EXISTENT_ID = 999999999l;
83
84 private HelpDAO jpaDao;
85 private HelpDAO ojbDao;
86
87 protected void loadTestData() throws Exception {
88 loadXmlFile("HelpEntryConfig.xml");
89 }
90
91 @Override
92 protected void setUpInternal() throws Exception {
93 super.setUpInternal();
94 this.jpaDao = (HelpDAO) KEWServiceLocator.getBean("enHelpDAO");
95 this.ojbDao = (HelpDAO) KEWServiceLocator.getBean("enHelpOJBDAO");
96
97 }
98
99 @Test
100 public void testFindByKey() {
101
102 HelpEntry helpJdo = ojbDao.findByKey(HELPKEY);
103 HelpEntry helpJpa = jpaDao.findByKey(HELPKEY);
104 if (helpJdo != null && helpJpa != null) {
105 assertTrue("Help names are different between ojb + jpa findByKey ", helpJdo.getHelpName().equals(helpJpa.getHelpName()));
106 assertTrue("Help keys are different between ojb + jpa findByKey ", helpJdo.getHelpKey().equals(helpJpa.getHelpKey()));
107 assertTrue("Help text are different between ojb + jpa findByKey ", helpJdo.getHelpText().equals(helpJpa.getHelpText()));
108 assertTrue("Help id are different between ojb + jpa findByKey ", helpJdo.getHelpId().equals(helpJpa.getHelpId()));
109 assertTrue("Help db_lock are different between ojb + jpa findByKey ", helpJdo.getLockVerNbr().equals(helpJpa.getLockVerNbr()));
110 System.out.println("Name " + helpJpa.getHelpName() + " Key " + helpJpa.getHelpKey() + " Text " + helpJpa.getHelpText() + " ID " + helpJpa.getHelpId() + " Lock " + helpJpa.getLockVerNbr());
111 System.out.println("Name " + helpJdo.getHelpName() + " Key " + helpJdo.getHelpKey() + " Text " + helpJdo.getHelpText() + " ID " + helpJdo.getHelpId() + " Lock " + helpJdo.getLockVerNbr());
112 }
113
114 assertNull("Expected null value not returned by a non-existing findByKey ", ojbDao.findByKey(NON_EXISTENT_KEY));
115 assertNull("Expected null value not returned by a non-existing findByKey ", jpaDao.findByKey(NON_EXISTENT_KEY));
116 System.out.println("Test testFindByKey completed.");
117 }
118
119 @Test
120 public void testFindById() {
121
122 loadHelpID();
123 HelpEntry jpaHE = new HelpEntry();
124 jpaHE.setHelpId(idForJpa);
125 HelpEntry ojbHE = new HelpEntry();
126 ojbHE.setHelpId(idForOjb);
127
128
129 HelpEntry jpa2HE = jpaDao.findById(jpaHE.getHelpId());
130 HelpEntry ojb2HE = ojbDao.findById(ojbHE.getHelpId());
131 if (jpa2HE != null && ojb2HE != null) {
132 assertTrue("Help names are different between ojb + jpa findById ", ojb2HE.getHelpName().equals(jpa2HE.getHelpName()));
133 assertTrue("Help keys are different between ojb + jpa findById ", ojb2HE.getHelpKey().equals(jpa2HE.getHelpKey()));
134 assertTrue("Help text are different between ojb + jpa findById ", ojb2HE.getHelpText().equals(jpa2HE.getHelpText()));
135 assertTrue("Help id are different between ojb + jpa findById ", ojb2HE.getHelpId().equals(jpa2HE.getHelpId()));
136 assertTrue("Help db_lock are different between ojb + jpa findById ", ojb2HE.getLockVerNbr().equals(jpa2HE.getLockVerNbr()));
137 System.out.println("Name= " + jpa2HE.getHelpName() + " Key= " + jpa2HE.getHelpKey() + " Text= " + jpa2HE.getHelpText() + " ID= " + jpa2HE.getHelpId() + " Lock= " + jpa2HE.getLockVerNbr());
138 System.out.println("Name= " + ojb2HE.getHelpName() + " Key= " + ojb2HE.getHelpKey() + " Text= " + ojb2HE.getHelpText() + " ID= " + ojb2HE.getHelpId() + " Lock= " + ojb2HE.getLockVerNbr());
139 } else {
140
141 assertTrue("Expected null values for both objects ", (ojb2HE == null && jpa2HE == null));
142 System.out.println("Unexpected null objects returned from findById ");
143 }
144
145
146 assertNull("Expected null value not returned by a non-existing findById ", ojbDao.findById(NON_EXISTENT_ID));
147 assertNull("Expected null value not returned by a non-existing findById ", jpaDao.findById(NON_EXISTENT_ID));
148 System.out.println("Test testFindById completed.");
149 }
150
151 @Test
152 public void testSearch1() {
153
154 System.out.println("Beginning testSearch");
155 loadHelpID();
156 HelpEntry jpaHE = new HelpEntry();
157 jpaHE.setHelpId(idForJpa);
158 HelpEntry ojbHE = new HelpEntry();
159 ojbHE.setHelpId(idForOjb);
160
161 assertEquals("List size not the same between ojb and jpa ", ojbDao.search(ojbHE).size(), jpaDao.search(jpaHE).size());
162 System.out.println("size of lists returned are equal and = " + ojbDao.search(jpaHE).size());
163
164
165
166
167
168 List<HelpEntry> colOjbHE = ojbDao.search(ojbHE);
169
170
171 List<HelpEntry> colJpaHE = ojbDao.search(jpaHE);
172
173
174
175
176
177 int index = 0;
178 for (HelpEntry helpOjb : colOjbHE) {
179
180 HelpEntry helpJpa = colJpaHE.get(index);
181 index++;
182 assertTrue("A HelpId difference was detected in testSearch ",helpOjb.getHelpId().equals(helpJpa.getHelpId()));
183 assertTrue("A HelpKey difference was detected in testSearch ",helpOjb.getHelpKey().equals(helpJpa.getHelpKey()));
184 assertTrue("A HelpName difference was detected in testSearch ",helpOjb.getHelpName().equals(helpJpa.getHelpName()));
185 assertTrue("A HelpText difference was detected in testSearch ",helpOjb.getHelpText().equals(helpJpa.getHelpText()));
186 assertTrue("A HelpLock difference was detected in testSearch ",helpOjb.getLockVerNbr().equals(helpJpa.getLockVerNbr()));
187 }
188
189 System.out.println("results contain same data. ");
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219 }
220
221 @Test
222 public void testSearch2() {
223 for (String pattern : nsArray) {
224 nameChecks(pattern);
225 }
226
227
228
229 }
230
231 private void nameChecks(String namePattern) {
232
233 HelpEntry ojbHE = new HelpEntry();
234 ojbHE.setHelpName(namePattern);
235 List<HelpEntry> colOjbHE = ojbDao.search(ojbHE);
236 HelpEntry jpaHE = new HelpEntry();
237 jpaHE.setHelpName(ojbHE.getHelpName());
238 List<HelpEntry> colJpaHE = ojbDao.search(jpaHE);
239
240 assertEquals("List size not the same between ojb and jpa ", colOjbHE.size(), colJpaHE.size());
241 System.out.println("Search2 size of lists returned are equal and = " + colJpaHE.size());
242
243 int index = 0;
244 for (HelpEntry helpOjb : colOjbHE) {
245
246 HelpEntry helpJpa = colJpaHE.get(index);
247 index++;
248 assertTrue("A HelpId difference was detected in testSearch2 ",helpOjb.getHelpId().equals(helpJpa.getHelpId()));
249 assertTrue("A HelpKey difference was detected in testSearch2 ",helpOjb.getHelpKey().equals(helpJpa.getHelpKey()));
250 assertTrue("A HelpName difference was detected in testSearch2 ",helpOjb.getHelpName().equals(helpJpa.getHelpName()));
251 assertTrue("A HelpText difference was detected in testSearch2 ",helpOjb.getHelpText().equals(helpJpa.getHelpText()));
252 assertTrue("A HelpLock difference was detected in testSearch2 ",helpOjb.getLockVerNbr().equals(helpJpa.getLockVerNbr()));
253 }
254 System.out.println("Name pattern results contain same data. ");
255 }
256
257 @Test
258 public void testSearch3() {
259 for (String pattern : ksArray) {
260 keyChecks(pattern);
261 }
262
263
264
265 }
266
267 private void keyChecks(String keyPattern) {
268
269 HelpEntry ojbHE = new HelpEntry();
270 ojbHE.setHelpKey(keyPattern);
271 List<HelpEntry> colOjbHE = ojbDao.search(ojbHE);
272 HelpEntry jpaHE = new HelpEntry();
273 jpaHE.setHelpKey(ojbHE.getHelpKey());
274 List<HelpEntry> colJpaHE = ojbDao.search(jpaHE);
275
276 assertEquals("List size not the same between ojb and jpa ", colOjbHE.size(), colJpaHE.size());
277 System.out.println("Search3 size of lists returned are equal and = " + colJpaHE.size());
278
279 int index = 0;
280 for (HelpEntry helpOjb : colOjbHE) {
281
282 HelpEntry helpJpa = colJpaHE.get(index);
283 index++;
284 assertTrue("A HelpId difference was detected in testSearch3 ",helpOjb.getHelpId().equals(helpJpa.getHelpId()));
285 assertTrue("A HelpKey difference was detected in testSearch3 ",helpOjb.getHelpKey().equals(helpJpa.getHelpKey()));
286 assertTrue("A HelpName difference was detected in testSearch3 ",helpOjb.getHelpName().equals(helpJpa.getHelpName()));
287 assertTrue("A HelpText difference was detected in testSearch3 ",helpOjb.getHelpText().equals(helpJpa.getHelpText()));
288 assertTrue("A HelpLock difference was detected in testSearch3 ",helpOjb.getLockVerNbr().equals(helpJpa.getLockVerNbr()));
289 }
290 System.out.println("Key pattern results contain same data. ");
291 }
292
293 @Test
294 public void testSearch4() {
295 for (String pattern : tsArray) {
296 textChecks(pattern);
297 }
298 }
299
300 private void textChecks(String pattern) {
301
302 HelpEntry ojbHE = new HelpEntry();
303 ojbHE.setHelpText(pattern);
304 List<HelpEntry> colOjbHE = ojbDao.search(ojbHE);
305 HelpEntry jpaHE = new HelpEntry();
306 jpaHE.setHelpText(ojbHE.getHelpText());
307 List<HelpEntry> colJpaHE = ojbDao.search(jpaHE);
308
309 assertEquals("List size not the same between ojb and jpa ", colOjbHE.size(), colJpaHE.size());
310 System.out.println("Search4 size of lists returned are equal and = " + colJpaHE.size());
311
312 int index = 0;
313 for (HelpEntry helpOjb : colOjbHE) {
314
315 HelpEntry helpJpa = colJpaHE.get(index);
316 index++;
317 assertTrue("A HelpId difference was detected in testSearch4 ",helpOjb.getHelpId().equals(helpJpa.getHelpId()));
318 assertTrue("A HelpKey difference was detected in testSearch4 ",helpOjb.getHelpKey().equals(helpJpa.getHelpKey()));
319 assertTrue("A HelpName difference was detected in testSearch4 ",helpOjb.getHelpName().equals(helpJpa.getHelpName()));
320 assertTrue("A HelpText difference was detected in testSearch4 ",helpOjb.getHelpText().equals(helpJpa.getHelpText()));
321 assertTrue("A HelpLock difference was detected in testSearch4 ",helpOjb.getLockVerNbr().equals(helpJpa.getLockVerNbr()));
322 }
323 System.out.println("Text pattern results contain same data. ");
324 }
325
326 @Test
327 public void testSearch5() {
328 for (String pattern : csArray) {
329 comboChecks(pattern);
330 }
331 }
332
333 private void comboChecks(String pattern) {
334
335 HelpEntry ojbHE = new HelpEntry();
336
337 StringTokenizer parser = new StringTokenizer(pattern, ",");
338
339 ojbHE.setHelpName(parser.nextToken());
340 ojbHE.setHelpKey(parser.nextToken());
341 ojbHE.setHelpText(parser.nextToken());
342 List<HelpEntry> colOjbHE = ojbDao.search(ojbHE);
343 HelpEntry jpaHE = new HelpEntry();
344 jpaHE.setHelpName(ojbHE.getHelpName());
345 jpaHE.setHelpKey(ojbHE.getHelpKey());
346 jpaHE.setHelpText(ojbHE.getHelpText());
347 List<HelpEntry> colJpaHE = ojbDao.search(jpaHE);
348
349 assertEquals("List size not the same between ojb and jpa ", colOjbHE.size(), colJpaHE.size());
350 System.out.println("Search5 size of lists returned are equal and = " + colJpaHE.size());
351
352 int index = 0;
353 for (HelpEntry helpOjb : colOjbHE) {
354
355 HelpEntry helpJpa = colJpaHE.get(index);
356 index++;
357 assertTrue("A HelpId difference was detected in testSearch5 ",helpOjb.getHelpId().equals(helpJpa.getHelpId()));
358 assertTrue("A HelpKey difference was detected in testSearch5 ",helpOjb.getHelpKey().equals(helpJpa.getHelpKey()));
359 assertTrue("A HelpName difference was detected in testSearch5 ",helpOjb.getHelpName().equals(helpJpa.getHelpName()));
360 assertTrue("A HelpText difference was detected in testSearch5 ",helpOjb.getHelpText().equals(helpJpa.getHelpText()));
361 assertTrue("A HelpLock difference was detected in testSearch5 ",helpOjb.getLockVerNbr().equals(helpJpa.getLockVerNbr()));
362 }
363 System.out.println("Combo pattern results contain same data. ");
364 }
365
366
367 @Test
368 public void testSaveJpa() throws Exception {
369 testSave(jpaDao);
370 System.out.println("Test testSaveJpa completed.");
371 }
372
373 @Test
374 public void testSaveOjb() throws Exception {
375 testSave(ojbDao);
376 System.out.println("Test testSaveOjb completed.");
377 }
378
379 private void testSave(HelpDAO dao) {
380 HelpEntry hE = dao.findByKey(HELPKEY);
381 assertEquals("Incorrect match on findByKey in testSave ", HELPKEY, hE.getHelpKey());
382
383
384 hE.setHelpName("abc");
385 dao.save(hE);
386
387
388 hE = dao.findByKey(HELPKEY);
389 assertEquals("HelpEntry Name value was not properly updated.", "abc", hE.getHelpName());
390 System.out.println("Existing HelpEntry has been updated.");
391
392
393
394 hE = dao.findByKey(NEW_HELPKEY);
395 if (hE != null) {
396 assertEquals("HelpEntry to be inserted already exists.", NEW_HELPKEY, dao.findByKey(NEW_HELPKEY));
397 }
398
399 hE = new HelpEntry();
400 hE.setHelpKey(NEW_HELPKEY);
401 hE.setHelpName("test help name entry 5");
402 hE.setHelpText("test help text entry 5");
403 dao.save(hE);
404
405
406 hE = dao.findByKey(NEW_HELPKEY);
407 System.out.println("inserted helpEntry key=" + hE.getHelpKey() + ", name=" + hE.getHelpName() + ", text=" + hE.getHelpText());
408 assertEquals("HelpEntry key was not found after an insert.", NEW_HELPKEY, hE.getHelpKey());
409 assertEquals("HelpEntry Name did not equal expected value after an insert.", "test help name entry 5", hE.getHelpName());
410 assertEquals("HelpEntry Text did not equal expected value after an insert.", "test help text entry 5", hE.getHelpText());
411 }
412
413
414 @Test
415 public void testDeleteHelpEntryJpa() throws Exception {
416 System.out.println("Test testDeleteHelpEntryJpa starting.");
417
418
419
420 HelpEntry hE = new HelpEntry();
421 hE.setHelpId(NON_EXISTENT_ID);
422 jpaDao.deleteEntry(hE);
423 System.out.println("No exception was thrown from an attempt to delete a NON-existing HelpEntry using JPA loaded primary key field.");
424
425
426 HelpEntry hE2 = jpaDao.findByKey(HELPKEY);
427 jpaDao.deleteEntry(hE2);
428 System.out.println("HelpEntry has been deleted. Key=" + HELPKEY);
429
430 assertNull("HelpEntry KEY was not properly deleted.", jpaDao.findByKey(HELPKEY));
431 System.out.println("Completed a findByName, then delete, then findByKEY again, in testDeleteHelpEntryJPA successfully.");
432
433 assertNull("OJB access of record JPA just deleted not null as expected" , ojbDao.findByKey(HELPKEY));
434
435
436
437
438
439 HelpEntry ojbHE = ojbDao.findByKey(HELPKEY2);
440
441 HelpEntry hE3 = new HelpEntry();
442 hE3.setHelpId(ojbHE.getHelpId());
443 System.out.println("JPA is about to delete HelpEntry with Name=" + ojbHE.getHelpName());
444 jpaDao.deleteEntry(hE3);
445 System.out.println("Deleted an existing HelpEntry db record by creating a new object instance and loading primary key.");
446
447
448
449 HelpEntry ojbHE2 = ojbDao.findByKey(HELPKEY2);
450 System.out.println("ojb re-accessed HelpEntry deleted by JPA, Name=" + ojbHE2.getHelpName());
451
452
453
454
455
456 System.out.println("Test testDeleteHelpEntryJpa completed.");
457 }
458
459
460
461
462 private void showListContents(Collection<HelpEntry> coll) {
463
464 for (HelpEntry help : coll) {
465 System.out.println("Name= " + help.getHelpName() + " Key= " + help.getHelpKey() + " Text= " + help.getHelpText() + " ID= " + help.getHelpId() + " Lock= " + help.getLockVerNbr());
466 }
467 }
468
469 private HelpEntry getObjFromCollection(List<HelpEntry> coll, int index) {
470 return coll.get(index);
471 }
472
473
474 private void loadHelpID() {
475
476
477 HelpEntry helpOjb = ojbDao.findByKey(HELPKEY);
478 HelpEntry helpJpa = jpaDao.findByKey(HELPKEY);
479
480 if (helpOjb == null || helpJpa == null) {
481 assertTrue("Cannot complete this test unless objects are not null ", (1==2));
482 }
483 idForJpa = helpOjb.getHelpId();
484 idForOjb = helpJpa.getHelpId();
485 }
486 }