01: /*
02: * JFox - The most lightweight Java EE Application Server!
03: * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
04: *
05: * JFox is licenced and re-distributable under GNU LGPL.
06: */
07: package jfox.test.dao;
08:
09: 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: /**
23: * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
24: */
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
33: .createEntityManagerFactory("DefaultMysqlDS")
34: .createEntityManager();
35:
36: accountDAO = new AccountDAOImpl() {
37: public EntityManager getEntityManager() {
38: return (EntityManagerExt) em;
39: }
40: };
41: }
42:
43: @Test
44: public void testGetAccount() throws Exception {
45: Account account = accountDAO.getAccountById(1L);
46: System.out.println("Account Address: " + account.getAddress());
47: Assert.assertEquals(account.getId(), 1L);
48: }
49:
50: @Test
51: public void testGetAccountBySQL() throws Exception {
52: Account account = accountDAO.getAccountByIdSQL(1L);
53: System.out.println("Account Address: " + account.getAddress());
54: Assert.assertEquals(account.getId(), 1L);
55: }
56:
57: @Test
58: public void testGetAccountBySQLResultEntityObject()
59: throws Exception {
60: MappedEntity account = accountDAO
61: .getAccountMappedEntityById(1L);
62: System.out.println("Account: " + account);
63: Assert.assertEquals(account.getColumnValue("ACC_ID"), "1");
64: }
65:
66: @Test
67: public void testGetAllAccounts() throws Exception {
68: List<Account> accounts = accountDAO.getAllAccounts();
69: for (Account account : accounts) {
70: System.out.println(account);
71: }
72: }
73:
74: @Test
75: public void testCreateAccount() throws Exception {
76: Account account = accountDAO.createAccount("Yang", "Yong",
77: "jfox.young@gmail.com");
78: Assert.assertEquals(account.getFirstName(), "Yang");
79: }
80:
81: public static void main(String[] args) {
82:
83: }
84: }
|