1 7 package org.jfox.petstore.dao.test; 8 9 import java.util.Arrays ; 10 import java.util.List ; 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 25 public class AccountDAOTest { 26 27 static AccountDAO accountDAO = null; 28 29 30 @BeforeClass 31 public static void setup() throws Exception { 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 { 43 List <String > usernames = accountDAO.getUsernameList(); 44 System.out.println(Arrays.toString(usernames.toArray(new String [usernames.size()]))); 45 } 46 47 @Test 48 public void testGetAccountByUsername() throws Exception { 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 { 56 Account account = accountDAO.getAccount("ACID","ACID"); 57 System.out.println("Account: " + account); 58 59 } 60 61 @Test 62 public void testCreateAccount() throws Exception { 63 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 } 86 87 public static void main(String [] args) { 88 89 } 90 } 91 | Popular Tags |