📄 userdaotest.java
字号:
package com.netctoss.liping.test;
import static org.junit.Assert.*;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.netctoss.liping.pricing.Pricing;
import com.netctoss.liping.userManage.User;
import com.netctoss.liping.userManage.UserService;
import com.netctoss.liping.userManage.dao.IUserDAO;
/**
* User实体类的设计:
1 map 的查询:1>findByLoginNameAndPass 2>findByLoginName 3>findUserByUserId
4>updateStatusById
2 不能自己更新的属性:id,login_name,status(0:正常,1:暂停,2:删除),关联的对象services ,enroll_date,close_date
3 不能为空的属性:id,login_name,login_password,name,gender(0,1),status(0:正常,1:暂停,2:删除),email
4 延迟加载的属性:enroll_date,close_date,关联的对象services
5 不需要生成insert的属性:enroll_date,close_date,关联的对象services
UserService实体类的设计
1 map 的查询 1>updatePassByUserServiceById 2>findUserServiceById
2 不能自己更新的属性 除lab_login_password
3 不能为空的属性 全部
4 延迟加载的属性 enroll_date,close_date ,关联的对象user,pricing
5 不需要生成insert的属性 :enroll_date,close_date,关联的对象user ,pricing
* @author Administrator
*
*/
public class UserDAOTest {
IUserDAO ius;
User user;
UserService us;
@Before
public void setUp() throws Exception {
//
ApplicationContext ct = new ClassPathXmlApplicationContext("user-userservice-config.xml");
ius = (IUserDAO) ct.getBean("userDAOProxy");
//
user = new User();
user.setLogin_name("tarena");
user.setLogin_password("12356");
user.setName( "tarenatest");
user.setGender("0");
user.setStatus(0);
user.setEmail( "liping@tarena.com.cn");
//
Pricing p = new Pricing();
p.setId( new Long(1));
p.setOption(0);
User u = new User();
u.setId( new Long(3));
us = new UserService();
us.setLab_ip("openlab");
us.setLab_login_name("hjd");
us.setLab_login_password("12356");
us.setUser_status("0");
us.setPricing( p );
us.setUser( u );
}
@After
public void tearDown() throws Exception {
}
/**
* Hibernate:
insert
into
liping_user
(address, career, company, email, gender, login_name, login_password, name, nationality, payment_style, phone, post_code, status, user_id)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
*/
//@Test
public final void testInsert() {
System.out.println( ius.insert(user));
}
/**
* 为什么会生成一个select语句,去掉@Generated(GenerationTime.ALWAYS)就不会产生,查下原因
* update
liping_user
set
address=?,
career=?,
company=?,
login_password=?,
name=?,
nationality=?,
payment_style=?,
phone=?,
post_code=?
where
user_id=?
Hibernate:
select
user_.close_date as close4_1_,
user_.enroll_date as enroll7_1_
from
liping_user user_
where
user_.user_id=?
*/
//@Test
public final void testUpdate() {
user.setId( new Long(3));
user.setName("tarena123");
ius.update(user);
}
/**实现了延迟加载关联的对象
* select
this_.user_id as user1_1_0_,
this_.address as address1_0_,
this_.career as career1_0_,
this_.close_date as close4_1_0_,
this_.company as company1_0_,
this_.email as email1_0_,
this_.enroll_date as enroll7_1_0_,
this_.gender as gender1_0_,
this_.login_name as login9_1_0_,
this_.login_password as login10_1_0_,
this_.name as name1_0_,
this_.nationality as nationa12_1_0_,
this_.payment_style as payment13_1_0_,
this_.phone as phone1_0_,
this_.post_code as post15_1_0_,
this_.status as status1_0_
from
liping_user this_
*/
//@Test
public final void testList() {
System.out.println(ius.list());
}
/**延迟加载时间没有实现
* select
user0_.user_id as user1_1_0_,
user0_.address as address1_0_,
user0_.career as career1_0_,
user0_.close_date as close4_1_0_,
user0_.company as company1_0_,
user0_.email as email1_0_,
user0_.enroll_date as enroll7_1_0_,
user0_.gender as gender1_0_,
user0_.login_name as login9_1_0_,
user0_.login_password as login10_1_0_,
user0_.name as name1_0_,
user0_.nationality as nationa12_1_0_,
user0_.payment_style as payment13_1_0_,
user0_.phone as phone1_0_,
user0_.post_code as post15_1_0_,
user0_.status as status1_0_
from
liping_user user0_
where
user0_.user_id=?
*/
//@Test
public final void testFind() {
System.out.println(ius.find( new Long(3)));
}
//@Test
public final void testDelete() {
fail("Not yet implemented"); // TODO
}
//@Test
public final void testUpdateStatus() {
user.setStatus( 1);
ius.updateStatus( new Long(3), 1);
}
//@Test
public final void testFindUserByLoginName() {
System.out.println( ius.findUserByLoginName("tarena"));
}
//@Test
public final void testFindByInfo() {
System.out.println( ius.findByInfo("tarena", "123056"));
}
//@Test
public final void testAddService() {
ius.addService(us);
}
//@Test
public final void testFindUserServiceById() {
ius.findUserServiceById( new Long(19));
}
@Test
public final void testUpdatePass() {
us.setLab_login_password("123456");
ius.updatePass(new Long(19), "123456");
}
@Test
public final void testUpdateServiceStatus() {
ius.updateServiceStatus( new Long(19), 3);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -