View Javadoc

1   /*
2    * Copyright 2007-2008 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Tests DB persistence using JPA and OJB. 
33   * 
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   *
36   */
37  //@KEWTransactionalTest
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 		// ensure both results are identical
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 		// ensure both can handle a not found condition by returning null
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 		// load keys to use.
122 		loadHelpID();
123 		HelpEntry jpaHE = new HelpEntry();
124 		jpaHE.setHelpId(idForJpa);
125 		HelpEntry ojbHE = new HelpEntry();
126 		ojbHE.setHelpId(idForOjb);
127 		
128 		// access db with ojbect that we created that should now have a correct id key loaded. Expect object to be found.
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 			// then both should be null
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 		// ensure both can handle a not found condition by returning null
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 		// load keys to use.
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 		// ensure both results sets are same size
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 		// ensure both results sets contain same contents (cannot use containsAll because object does not implement ".equals" method therefore
165 		// the containsAll defaults to an "==" test which fails because objects have different addresses.)
166 		
167 		// uncomment showListContents to see difference.
168 		List<HelpEntry> colOjbHE = ojbDao.search(ojbHE);
169 		//System.out.println("following list is from OJB");
170 		//showListContents(colOjbHE);
171 		List<HelpEntry> colJpaHE = ojbDao.search(jpaHE);
172 		//System.out.println("following list is from OJB");
173 		//showListContents(colJpaHE);
174 		
175 		
176 		// match fields in OJB collection with fields from Jpa collection.
177 		int index = 0;
178 		for (HelpEntry helpOjb : colOjbHE) {
179 			// return obj from jpa collection at index i.
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 //		Collection<HelpEntry> colOjbHE = ojbDao.search(ojbHE);
196 //		Collection<HelpEntry> colJpaHE = ojbDao.search(jpaHE);
197 //		for (HelpEntry ojbHE2 : colOjbHE) {
198 //			private HelpEntry getJpaFromList(colJpaHe);
199 //		}
200 //		HelpEntry helpJdo = ojbDao.search(hOjb);
201 //		HelpEntry helpJpa = jpaDao.search(HELPID);
202 //		if (helpJdo != null && helpJpa != null) {
203 //			assertTrue("Help names are different between ojb + jpa findSearch ", helpJdo.getHelpName().equals(helpJpa.getHelpName()));
204 //			assertTrue("Help keys  are different between ojb + jpa findSearch ", helpJdo.getHelpKey().equals(helpJpa.getHelpKey()));
205 //		    assertTrue("Help text  are different between ojb + jpa findSearch ", helpJdo.getHelpText().equals(helpJpa.getHelpText()));
206 //		    assertTrue("Help id    are different between ojb + jpa findSearch ", helpJdo.getHelpId().equals(helpJpa.getHelpId()));
207 //		    assertTrue("Help db_lock are different between ojb + jpa findSearch ", helpJdo.getLockVerNbr().equals(helpJpa.getLockVerNbr()));
208 //		    System.out.println("Name " + helpJpa.getHelpName() + " Key " + helpJpa.getHelpKey() + " Text " + helpJpa.getHelpText() + " ID " + helpJpa.getHelpId() + " Lock " + helpJpa.getLockVerNbr());	
209 //		    System.out.println("Name " + helpJdo.getHelpName() + " Key " + helpJdo.getHelpKey() + " Text " + helpJdo.getHelpText() + " ID " + helpJdo.getHelpId() + " Lock " + helpJdo.getLockVerNbr());	
210 //		}  else {
211 //			// then both should be null
212 //			assertTrue("Expected null values for both objects ", (helpJdo == null && helpJpa == null));
213 //			}
214 //
215 //		// ensure both can handle a not found condition by returning null
216 //		assertNull("Expected null value not returned by a non-existing findSearch ", ojbDao.search(helpEntry)(NON_EXISTENT_ID));
217 //		assertNull("Expected null value not returned by a non-existing findSearch ", jpaDao.search(NON_EXISTENT_ID));
218 //		System.out.println("Test testFindSearch completed.");
219 	}
220 	
221 	@Test
222 	public void testSearch2() {	
223 		for (String pattern : nsArray) {
224 			nameChecks(pattern);
225 		}	
226 		// to individually test a name search pattern so data comes fresh into persistence context see below strategy. (found same results whether looping or individual)
227 		// 1) comment out loop above and active below code.
228 		// nameChecks(NAME_PATTERN7); 
229 	}
230 	
231 	private void nameChecks(String namePattern) {
232 		// test pattern usage 
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 		// ensure both results sets are same size
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 		// match fields in OJB collection with fields from Jpa collection.
243 		int index = 0;
244 		for (HelpEntry helpOjb : colOjbHE) {
245 			// return obj from jpa collection at index i.
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 		// to individually test a name search pattern so data comes fresh into persistence context see below strategy. (found same results whether looping or individual)
263 		// 1) comment out loop above and active below code.
264 		// nameChecks(NAME_PATTERN7); 
265 	}
266 	
267 	private void keyChecks(String keyPattern) {
268 		// test pattern usage 
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 		// ensure both results sets are same size
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 		// match fields in OJB collection with fields from Jpa collection.
279 		int index = 0;
280 		for (HelpEntry helpOjb : colOjbHE) {
281 			// return obj from jpa collection at index i.
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 		// test pattern usage 
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 		// ensure both results sets are same size
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 		// match fields in OJB collection with fields from Jpa collection.
312 		int index = 0;
313 		for (HelpEntry helpOjb : colOjbHE) {
314 			// return obj from jpa collection at index i.
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 		// test pattern usage
335 		HelpEntry ojbHE = new HelpEntry();
336 		//parse the multiple tokens and load helpEntry fields.
337 		StringTokenizer parser = new StringTokenizer(pattern, ","); // parse on comma's
338 		// input data must have 3 tokens separated by comma's in Name, Key, Text order.
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 		// ensure both results sets are same size
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 		// match fields in OJB collection with fields from Jpa collection.
352 		int index = 0;
353 		for (HelpEntry helpOjb : colOjbHE) {
354 			// return obj from jpa collection at index i.
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 	// Test update and insert functionality.
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 		// update the value
384 		hE.setHelpName("abc");
385 		dao.save(hE);
386 		
387 		// validate that it was updated correctly.
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 		// insert a new HelpEntry
393 		// First validate it does not exist
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 		// insert a value
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 		// validate that it was inserted
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 	// Test delete functionality.
414 	@Test
415 	public void testDeleteHelpEntryJpa() throws Exception {
416 		System.out.println("Test testDeleteHelpEntryJpa starting.");
417 		
418 		// Attempt to delete a row that does NOT exist. Differences between OJB and JPA exist. OJB throws an exception, JPA does not.
419 		// This difference has been noted in Confluence in KULRICE Global Technical Guides named Object-Relational Mapping Library Differences
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 		// Delete an existing HelpEntry after finding it first.
426 		HelpEntry hE2 = jpaDao.findByKey(HELPKEY);
427 		jpaDao.deleteEntry(hE2);
428 		System.out.println("HelpEntry has been deleted. Key=" + HELPKEY);
429 		// JPA allows a deleted object that priorly came from the db, to be retrieved again - it's value is null, ( it must have already existed and been retrieved from db first.)
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 		// access same record jpa deleted using ojb
433 		assertNull("OJB access of record JPA just deleted not null as expected" , ojbDao.findByKey(HELPKEY));
434 		
435 		
436 		// Delete an existing HelpEntry db record by creating a new object instance and loading the existing db record's primary key, then delete it.
437 		// Need primary key which changes with every test. Get it from an OJB find.
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 		// cannot attempt to access the deleted JPA record which was never retrieved from db (otherwise exception is thrown).
447 
448 		// ojb can still find the record jpa deleted because it found it earlier therefore it is in it's context and is not aware that JPA deleted it.  
449 		HelpEntry ojbHE2 = ojbDao.findByKey(HELPKEY2);
450 		System.out.println("ojb re-accessed HelpEntry deleted by JPA, Name=" + ojbHE2.getHelpName());  
451 		//assertNull("OJB access of record JPA just deleted not null as expected" , ojbDao.findByKey(HELPKEY2));
452 		
453 		// attempt to re-access record JPA deleted. (should cause exception).
454 		//assertNull("HelpEntry KEY was not properly deleted.", jpaDao.findByKey(HELPKEY2));
455 		
456 		System.out.println("Test testDeleteHelpEntryJpa completed.");
457 	}
458 
459 	
460 		
461 	
462 	private void showListContents(Collection<HelpEntry> coll) {
463 		// dump variable contents in list returned from JPA access.
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 		// key is a sequence so it changes each test!
476 		// Strategy - use ojb find by name to get a key for jpa, then load jpa object with the key and perform access.
477 		HelpEntry helpOjb = ojbDao.findByKey(HELPKEY);
478 		HelpEntry helpJpa = jpaDao.findByKey(HELPKEY);
479 		// stop test if either or both are null
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 }