1 7 package jfox.test.dao; 8 9 import java.util.List ; 10 import javax.persistence.EntityManager; 11 import javax.persistence.Persistence; 12 13 import org.jfox.entity.EntityManagerExt; 14 import org.jfox.entity.MappedEntity; 15 import org.junit.BeforeClass; 16 import org.junit.Test; 17 import org.junit.Assert; 18 import jfox.test.jpa.Account; 19 import jfox.test.ejbcomponent.dao.AccountDAOImpl; 20 import jfox.test.ejbcomponent.dao.AccountDAO; 21 22 25 public class OutContainerDAOTest { 26 27 static AccountDAO accountDAO = null; 28 29 @BeforeClass 30 public static void setup() throws Exception { 31 32 final EntityManager em = Persistence.createEntityManagerFactory("DefaultMysqlDS").createEntityManager(); 33 34 accountDAO = new AccountDAOImpl(){ 35 public EntityManager getEntityManager() { 36 return (EntityManagerExt)em; 37 } 38 }; 39 } 40 41 @Test 42 public void testGetAccount() throws Exception { 43 Account account = accountDAO.getAccountById(1L); 44 System.out.println("Account Address: " + account.getAddress()); 45 Assert.assertEquals(account.getId(),1L); 46 } 47 48 @Test 49 public void testGetAccountBySQL() throws Exception { 50 Account account = accountDAO.getAccountByIdSQL(1L); 51 System.out.println("Account Address: " + account.getAddress()); 52 Assert.assertEquals(account.getId(),1L); 53 } 54 55 @Test 56 public void testGetAccountBySQLResultEntityObject() throws Exception { 57 MappedEntity account = accountDAO.getAccountMappedEntityById(1L); 58 System.out.println("Account: " + account); 59 Assert.assertEquals(account.getColumnValue("ACC_ID"),"1"); 60 } 61 62 @Test 63 public void testGetAllAccounts() throws Exception { 64 List <Account> accounts = accountDAO.getAllAccounts(); 65 for(Account account : accounts){ 66 System.out.println(account); 67 } 68 } 69 70 @Test 71 public void testCreateAccount() throws Exception { 72 Account account = accountDAO.createAccount("Yang","Yong","jfox.young@gmail.com"); 73 Assert.assertEquals(account.getFirstName(), "Yang"); 74 } 75 76 77 public static void main(String [] args) { 78 79 } 80 } 81 | Popular Tags |