1 25 package org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.entitymanager; 26 27 import static org.testng.Assert.assertEquals; 28 import static org.testng.Assert.assertTrue; 29 30 import javax.ejb.Remote ; 31 import javax.ejb.Stateless ; 32 import javax.persistence.EntityManager; 33 import javax.persistence.PersistenceContext; 34 import javax.persistence.PersistenceContextType; 35 36 import org.objectweb.easybeans.tests.common.ejbs.entity.ebstore.EBStore; 37 38 44 @Stateless 45 @Remote (ItfEntityManagerTester01.class) 46 public class SLSBEntityManagerTester01 implements ItfEntityManagerTester01 { 47 48 51 @PersistenceContext(type = PersistenceContextType.TRANSACTION) 52 private EntityManager em; 53 54 60 private EBStore completeEBStore(final int id, final String name) { 61 EBStore ebstore = new EBStore(); 62 ebstore.setId(id); 63 ebstore.setName(name); 64 return ebstore; 65 } 66 67 74 public void mergeEBStore(final int id, final String name, final String newName) { 75 EBStore ebstore = completeEBStore(id, name); 76 em.persist(ebstore); 77 em.clear(); 79 ebstore.setName(newName); 81 EBStore ebstoreMerged = em.merge(ebstore); 82 assertEquals(newName, ebstoreMerged.getName(), "The entity was not merged."); 83 } 84 85 90 public void containsEBStore(final int id, final String name) { 91 EBStore ebstore = completeEBStore(id, name); 92 em.persist(ebstore); 93 assertTrue(em.contains(ebstore), "The contains methos does not work properly"); 94 } 95 96 102 public void refreshEBStore(final int id, final String name, final String newName) { 103 EBStore ebstore = completeEBStore(id, name); 104 em.persist(ebstore); 105 em.clear(); 107 ebstore.setName(newName); 109 em.refresh(ebstore); 111 assertEquals(ebstore.getName(), name, "The entity was not refreshed"); 113 } 114 115 119 public void removeEBStore(final int id) { 120 EBStore ebstore = em.find(EBStore.class, new Integer (id)); 121 if(ebstore != null){ 122 em.remove(ebstore); 123 } 124 } 125 } 126 | Popular Tags |