KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfox > test > dao > OutContainerDAOTest


1 /*
2  * JFox - The most lightweight Java EE Application Server!
3  * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
4  *
5  * JFox is licenced and re-distributable under GNU LGPL.
6  */

7 package jfox.test.dao;
8
9 import java.util.List JavaDoc;
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
64         List JavaDoc<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 JavaDoc {
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 JavaDoc[] args) {
78
79     }
80 }
81
Popular Tags