工具包的简单测试类
程序员文章站
2022-04-19 23:13:10
...
package junit.test;
import java.util.List;
import org.junit.Test;
import com.yunchow.user.Product;
import com.yunchow.user.Users;
import com.yunchow.util.DaoSupport;
import com.yunchow.util.MyDataSource;
/**
* DaoSupport测试类
* @author Administrator
*
*/
public class TestUser {
@Test
public void testUpdate() {
DaoSupport<Users> gd = new DaoSupport<Users>(Users.class);
Users us = new Users();
us.setUserId(11);
us.setUserName("修改Tom");
us.setEmail("xxx");
us.setPassword("tomtomtom");
System.out.println("保存结果 为:" + gd.update(us));
}
@Test
public void testSave() {
DaoSupport<Users> gd = new DaoSupport<Users>(Users.class);
Users us = new Users();
us.setUserName("Tom");
us.setEmail("xxx");
us.setPassword("ttttt");
System.out.println(us.getRegDate());
System.out.println("保存结果 为:" + gd.save(us));
}
@Test
public void testRemove() {
DaoSupport<Users> gd = new DaoSupport<Users>(Users.class);
Users us = new Users();
us.setUserName("Tom");
us.setEmail("xxx");
us.setPassword("ttttt");
gd.remove(us);
}
@Test
public void testCount() {
DaoSupport<Users> gd = new DaoSupport<Users>(Users.class);
System.out.println(gd.count("userId > 5"));
}
@Test
public void testFindAll() {
DaoSupport<Users> gd = new DaoSupport<Users>(Users.class);
List<Users> userList = gd.find(5, 1, "", "userId desc");
System.out.println("------------------");
for(Users user : userList) {
//System.out.print(user.getUserName() + ",");
System.out.print(user.getUserId());
System.out.println();
}
}
@Test
public void testDaoSupport() {
DaoSupport<Product> gd = new DaoSupport<Product>(Product.class);
List<Product> l = gd.findAll();
for(Product p : l) {
System.out.println(p.getPrice());
}
}
@Test
public void test0() {
DaoSupport<Users> gd = new DaoSupport<Users>(Users.class);
List<Users> userList = gd.findAll();
for(Users user : userList) {
System.out.print(user.getUserName() + ",");
System.out.print(user.getRegDate());
System.out.println();
}
}
@Test
public void test1() {
DaoSupport<Users> gd = new DaoSupport<Users>(Users.class);
Users us = new Users();
us.setUserName("Tom");
us.setEmail("xxx");
gd.remove(us);
}
public void testds() {
MyDataSource ds = new MyDataSource();
System.out.println(ds);
}
public static void main(String[] args) throws Exception {
MyDataSource ds = new MyDataSource();
System.out.println(ds);
}
}