In this test the persistence unit is defined inside an EJB module (.jar)
The actual JPA code being run is not specifically relevant; any kind of JPA operation that uses the data source is okay here. @author Arjan Tijms
787980818283848586878889
assertEquals(eBook.getNumPages(),response.getNumPages()); } @Test public void test3FindEbooks(){ EBookStore eBookStore = eBookStoreService.getPort(EBookStore.class); List<String> titleList=eBookStore.findEBooks("Rings"); assertNotNull(titleList); assertEquals(1, titleList.size()); assertEquals("The Lord of the Rings",titleList.get(0)); }
87888990919293949596979899100
assertEquals(1, titleList.size()); assertEquals("The Lord of the Rings",titleList.get(0)); } @Test public void test4AddAppendix(){ EBookStore eBookStore = eBookStoreService.getPort(EBookStore.class); EBook eBook=eBookStore.takeBook("Oliver Twist"); assertEquals(268,eBook.getNumPages()); EBook eBookResponse=eBookStore.addAppendix(eBook, 5); assertEquals(268,eBook.getNumPages()); assertEquals(273,eBookResponse.getNumPages()); }
22232425262728293031
@PersistenceContext private EntityManager entityManager; public void saveNewEntity() { TestEntity testEntity = new TestEntity(); testEntity.setValue("mytest"); entityManager.persist(testEntity); }
3435363738394041424344454647
public void testGet() throws Exception { assertNotNull(bean); List<Employee> list = bean.get(); assertNotNull(list); assertEquals(8, list.size()); assertFalse(list.contains(new Employee("Penny"))); assertFalse(list.contains(new Employee("Sheldon"))); assertFalse(list.contains(new Employee("Amy"))); assertFalse(list.contains(new Employee("Leonard"))); assertFalse(list.contains(new Employee("Bernadette"))); assertFalse(list.contains(new Employee("Raj"))); assertFalse(list.contains(new Employee("Howard"))); assertFalse(list.contains(new Employee("Priya"))); }
414243444546474849505152
// Nothing inserted yet, data base should not contain any entities // (this tests that a simple query without parameters works as named query created by Criteria) assertTrue(testService.getAll().size() == 0); // Insert one entity TestEntity testEntity = new TestEntity(); testEntity.setValue("myValue"); testService.save(testEntity); // The total amount of entities should be 1 assertTrue(testService.getAll().size() == 1);
686970717273747576777879808182
@Test public void saveInOneGo() { Parent parent = new Parent(); Child child1 = new Child(); child1.setParent(parent); Child child2 = new Child(); child2.setParent(parent); parent.getChildren().add(child1); parent.getChildren().add(child2); parent = indexColumnTesterService.save(parent);
107108109110111112113114115116117118119120121
@Test public void saveParentSeparatelyFirst() { Parent parent = indexColumnTesterService.save(new Parent()); Child child1 = new Child(); child1.setParent(parent); Child child2 = new Child(); child2.setParent(parent); parent.getChildren().add(child1); parent.getChildren().add(child2); parent = indexColumnTesterService.save(parent);
130131132133134135136137138139140141142143144145146147148
@Test public void saveParentWithOneChildFirst() { Parent parent = new Parent(); Child child1 = new Child(); child1.setParent(parent); parent.getChildren().add(child1); // Save parent with 1 child in one go parent = indexColumnTesterService.save(parent); Child child2 = new Child(); child2.setParent(parent); parent.getChildren().add(child2); // Save parent again with second child parent = indexColumnTesterService.save(parent);