KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > petstore > dao > test > AccountDAOTest


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 org.jfox.petstore.dao.test;
8
9 import java.util.Arrays JavaDoc;
10 import java.util.List JavaDoc;
11 import javax.persistence.EntityManager;
12 import javax.persistence.Persistence;
13
14 import org.jfox.entity.EntityManagerExt;
15 import org.jfox.entity.dao.DAOSupport;
16 import org.jfox.petstore.dao.AccountDAO;
17 import org.jfox.petstore.dao.AccountDAOImpl;
18 import org.jfox.petstore.entity.Account;
19 import org.junit.BeforeClass;
20 import org.junit.Test;
21
22 /**
23  * @author <a HREF="mailto:jfox.young@gmail.com">Young Yang</a>
24  */

25 public class AccountDAOTest {
26     
27     static AccountDAO accountDAO = null;
28
29
30     @BeforeClass
31     public static void setup() throws Exception JavaDoc {
32         final EntityManager em = Persistence.createEntityManagerFactory("JPetstoreMysqlDS").createEntityManager();
33
34         accountDAO = new AccountDAOImpl(){
35             public EntityManager getEntityManager() {
36                 return (EntityManagerExt)em;
37             }
38         };
39     }
40
41     @Test
42     public void testGetUsernameList() throws Exception JavaDoc {
43         List JavaDoc<String JavaDoc> usernames = accountDAO.getUsernameList();
44         System.out.println(Arrays.toString(usernames.toArray(new String JavaDoc[usernames.size()])));
45     }
46     
47     @Test
48     public void testGetAccountByUsername() throws Exception JavaDoc {
49         Account account = accountDAO.getAccount("j2ee");
50         System.out.println("Account: " + account);
51         System.out.println("bannerOptions: " + Account.AccountHelper.isBannerOption(account));
52     }
53
54     @Test
55     public void testGetAccountByUsernameAndPassword() throws Exception JavaDoc {
56         Account account = accountDAO.getAccount("ACID","ACID");
57         System.out.println("Account: " + account);
58
59     }
60     
61     @Test
62     public void testCreateAccount() throws Exception JavaDoc {
63 // ((DAOSupport)accountDAO).getEntityManager().getTransaction().begin();
64
Account account = DAOSupport.newEntityObject(Account.class);
65         account.setAddress1("Haidian");
66         account.setAddress2("DongWangzhuang");
67         account.setBannerName("yangyong");
68         account.setBannerOption(1);
69         account.setCity("Beijing");
70         account.setCountry("China");
71         account.setEmail("yangyong@live.com");
72         account.setFavouriteCategoryId("TestCategoryId");
73         account.setFirstName("Yang");
74         account.setLanguagePreference("chinese");
75         account.setLastName("Yong");
76         account.setListOption(1);
77         account.setPassword("YY");
78         account.setPhone("13988888888");
79         account.setState("Hunan");
80         account.setStatus("OK");
81         account.setUsername("YangYong");
82         account.setZip("1234567");
83         accountDAO.insertAccount(account);
84 // ((DAOSupport)accountDAO).getEntityManager().getTransaction().commit();
85
}
86
87     public static void main(String JavaDoc[] args) {
88
89     }
90 }
91
Popular Tags