package com.xbw.dao;
import static org.junit.Assert.*;
import java.util.Date;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.xbw.dao.basic.HibernateSessionFactory;
import com.xbw.po.Account;
import com.xbw.po.Detail;
public class AccountDAOTest {
AccountDAO accountDAO = new AccountDAO();
DetailDAO detailDAO = new DetailDAO();
Transaction tx;
Session session;
@Before
public void setUp() {
session = HibernateSessionFactory.getSession();
tx = session.beginTransaction();
System.out.println("setUp()...");
}
@Test
public void testFail() {
fail("Fail-Message...");
}
@Test
public void testSave() {
Account account = new Account("u_id", "123", "Mr Tom", true, "c:/1.jpg");
Detail detail = new Detail("id",account, new Date(), "XIAN", "123", "456",
"789@qq.com");
account.setDetail(detail);
detail.setAccount(account);
accountDAO.save(account);
detailDAO.save(detail);
}
@After
public void tearDown() {
try {
session.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
tx.rollback();
HibernateSessionFactory.closeSession();
}
System.out.println("tearDown...");
}
}