java web西蒙购物网 ——测试(test)

Impl测试类

一、TestUserDaoImpl

1、测试用户登录

2、测试对User表的更新

3、测试User表的插入

4、测试User表通过id删除user用户

5、测试User表通过username查找用户User

6、测试User表查找所有用户User

7、通过id查找用户

二、TestCategoryDaoImpl

1、通过id查找类别category

2、插入类别category

3、通过id删除类别category

4、更新类别category

5、查找全部类别category

三、TestProductDaoImpl

1、根据id查找产品product

2、插入产品信息product

@Test
    public void testInsert(){
        ProductDao productDao = new ProductDaoImpl();
        Product product = new Product();
        product.setId(5);
        product.setName("信签纸");
        product.setPrice(15);
        product.setAddTime(new Date());
        product.setCategoryId(3);

        List<Product> products = productDao.findAll();
        int flay = 0;
        for (Product product1:products) {
            if (product1.getName().equals(product.getName())) {
                flay = 1;
                break;
            }
        }
        if (flay == 0){
            int count = productDao.insert(product);
            if (count > 0) {
                System.out.println("插入成功!");
            } else {
                System.out.println("插入失败!");
            }
        }else {
            System.out.println("有相同的名字插入失败!");
        }
    }

3、根据id删除产品信息product

4、更新产品信息product

5、查找所有产品信息products

6、根据类别ld查找产品信息product

四、TestOrderDaoImpl

1、根据id查找订单order

2、查找全部订单order

二、插入订单信息 

@Test
    public void testInsert(){
        Order order = new Order();
        order.setId(3);
        order.setUsername("小本");
        order.setTotalPrice(3000);
        order.setTelephone("15974158745");
        order.setDeliveryAddress("泸职院国际学院");
        order.setOrderTime(new Date());
        OrderDao orderDao = new OrderDaoImpl();
        int flay = 0;
        List<Order> orders = orderDao.findAll();
        for (Order order1:orders){
            if (order1.getUsername().equals(order.getUsername())){
                flay =1;
                break;
            }
        }
        if (flay == 0){
            int count = orderDao.insert(order);
            if (count > 0) {
                System.out.println("插入成功!");
            } else {
                System.out.println("插入失败!");
            }
        }else {
            System.out.println("有相同的名字插入失败!");
        }


    }

 3、根据id删除订单order

4、更新订单表order

5、输出全部订单order

 

hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/hr/

 

Service测试类

一、TestUserService

package net.lgs.shop.service;

import net.lgs.bean.User;
import net.lgs.dao.UserDao;
import net.lgs.dao.impl.UserDaoImpl;
import net.lgs.service.UserService;
import org.junit.Test;

import java.util.Date;
import java.util.List;

public class TestUserService {
    @Test
    public void testLogin(){
        String username,password;
        username = "admin";
        password="12345";
        UserService userService = new UserService();
        User user = userService.login(username,password);
        if (user != null){
            System.out.println("登陆成功");
        }else {
            System.out.println("登录失败!");
        }
    }

    @Test
    public void testUpdateUser(){
        UserService userService = new UserService();
        User user = userService.findUserById(4);
        user.setPassword("903213");
        user.setTelephone("11411457890");
        int count = userService.updateUser(user);
        if (count > 0) {
            System.out.println("更新成功!");
        }else {
            System.out.println("更新失败!");
        }
    }

    @Test
    public void testAddUser(){
        UserService userService = new UserService();
        User user = new User();
        user.setId(5);
        user.setUsername("涂文");
        user.setPassword("123456");
        user.setTelephone("13541817484");
        user.setRegisterTime(new Date());
        user.setPopedom(1);
        List<User> users = userService.findAllUsers();
        int flay = 0;
        for (User user1:users) {
            if (user1.getUsername().equals(user.getUsername())) {
                flay = 1;
                break;
            }
        }
        if (flay == 0){
            int count = userService.addUser(user);
            if (count > 0) {
                System.out.println("插入成功!");
            } else {
                System.out.println("插入失败!");
            }
        }else {
            System.out.println("有相同的名字插入失败!");
        }
    }

    @Test
    public void testDeleteUserById(){
        UserService userService = new UserService();
        int index = 5;
        int count = userService.deleteUserById(index);
        if (count > 0) {
            System.out.println("删除成功!");
        }else {
            System.out.println("删除失败!");
        }
    }

    @Test
    public void testFindUsersByUsername(){
        UserService userService = new UserService();
        String name = "admin";
        List<User> users = userService.findUsersByUsername(name);
        if (users.size() > 0){
            for (User user:users){
                System.out.println(user);
            }
        }else {
            System.out.println("查询失败");
        }
    }
    @Test
    public void testFindAllUsers(){
        UserService userService = new UserService();
        List<User> users = userService.findAllUsers();
        if (users.size()>0){
            for (User user:users){
                System.out.println(user);
            }
        }else {
            System.out.println("查询失败");
        }

    }
}





实现效果:  

二、TestCategoryService

package net.lgs.shop.service;

import net.lgs.bean.Category;
import net.lgs.dao.CategoryDao;
import net.lgs.dao.impl.CategoryDaoImpl;
import net.lgs.service.CategoryService;
import org.junit.Test;

import java.util.List;

public class TestCategoryService {
    @Test
    public void testAddCategory(){
        Category category = new Category();
        category.setId(5);
        category.setName("AJ用品");
        CategoryService categoryService = new CategoryService();
        int flay = 0;
        List<Category> categories = categoryService.findAllCategories();
        for (Category category1:categories){
            if(category1.getName().equals(category.getName())){
                flay =1;
                break;
            }
        }
        if (flay == 0){
            int count = categoryService.addCategory(category);
            if (count > 0) {
                System.out.println("插入成功!");
            } else {
                System.out.println("插入失败!");
            }

        }else {
            System.out.println("插入失败!有相同的名称的");
        }

    }

    @Test
    public void testDeleteCategoryById(){
        int Id = 5;
        CategoryService categoryService = new CategoryService();
        int count = categoryService.deleteCategoryById(Id);
        if (count > 0) {
            System.out.println("删除成功!");
        } else {
            System.out.println("删除失败!");
        }
    }

    @Test
    public void testUpdateCategory(){
        CategoryService categoryService = new CategoryService();
        Category category = categoryService.findCategoryById(2);
        category.setName("AW用品");
        int count = categoryService.updateCategory(category);
        if (count > 0) {
            System.out.println("更新成功!");
        } else {
            System.out.println("更新失败!");
        }
    }

    @Test
    public void testFindAllCategories(){
        CategoryService categoryService = new CategoryService();
        List<Category> categorys = categoryService.findAllCategories();
        if (categorys.size() > 0){
            for (Category category:categorys){
                System.out.println(category);
            }
        }else {
            System.out.println("没有订单");
        }
    }

}

实现效果:  

 

三、TestProductService

package net.lgs.shop.service;

import net.lgs.bean.Product;
import net.lgs.dao.CategoryDao;
import net.lgs.dao.ProductDao;
import net.lgs.dao.impl.CategoryDaoImpl;
import net.lgs.dao.impl.ProductDaoImpl;
import net.lgs.service.CategoryService;
import net.lgs.service.ProductService;
import org.junit.Test;

import java.util.Date;
import java.util.List;

public class TestProductService {
    @Test
    public void testFindProductsByCategoryId(){
        //创建商品数据访问对象
        ProductService productService = new ProductService();
        int categoryId = 5;
        CategoryService categoryService = new CategoryService();
        if (categoryService.findCategoryById(categoryId)!= null){
            String categoryName = categoryService.findCategoryById(categoryId).getName();
            List<Product> products = productService.findProductsByCategoryId(categoryId);
            if (!products.isEmpty()){
                for (Product product:products){
                    System.out.println(product);
                }
            }else {
                System.out.println("["+categoryName+"]类别没有商品!");
            }
        }
    }

    @Test
    public void testAddProduct(){
        ProductService productService = new ProductService();
        Product product = new Product();
        product.setId(16);
        product.setName("笔");
        product.setPrice(15);
        product.setAddTime(new Date());
        product.setCategoryId(3);

        List<Product> products = productService.findAllProducts();
        int flay = 0;
        for (Product product1:products) {
            if (product1.getName().equals(product.getName())) {
                flay = 1;
                break;
            }
        }
        if (flay == 0){
            int count = productService.addProduct(product);
            if (count > 0) {
                System.out.println("插入成功!");
            } else {
                System.out.println("插入失败!");
            }
        }else {
            System.out.println("有相同的名字插入失败!");
        }
    }

    @Test
    public void testDeleteProductById(){
        int Id = 16;
        ProductService productService = new ProductService();
        int count = productService.deleteProductById(Id);
        if (count > 0) {
            System.out.println("删除成功!");
        }else {
            System.out.println("删除失败!");
        }
    }

    @Test
    public void testUpdateProduct(){
        ProductService productService = new ProductService();
        Product product = productService.findProductById(3);
        product.setName("蓝颜墨水");
        int count = productService.updateProduct(product);
        if (count > 0) {
            System.out.println("更新成功!");
        }else {
            System.out.println("更新失败!");
        }

    }

    @Test
    public void testFindAllProducts(){
        ProductService productService = new ProductService();
        List<Product> productDaos = productService.findAllProducts();
        if (productDaos.size() > 0){
            for (Product product:productDaos){
                System.out.println(product);
            }
        }else {
            System.out.println("查询失败!");
        }

    }

}

实现效果:

 

四、TestOrderService

package net.lgs.shop.service;

import net.lgs.bean.Order;
import net.lgs.dao.OrderDao;
import net.lgs.dao.impl.OrderDaoImpl;
import net.lgs.service.OrderService;
import org.junit.Test;

import java.util.Date;
import java.util.List;

public class TestOrderService {
    @Test
    public void testFindAllOrders(){
        OrderService orderService = new OrderService();
        List<Order> orders = orderService.findAllOrders();
        if (orders.size() > 0){
            for (Order order:orders){
                System.out.println(order);
            }
        }else {
            System.out.println("没有订单");
        }
    }

    @Test
    public void testAddOrder(){
        Order order = new Order();
        order.setId(3);
        order.setUsername("小A");
        order.setTotalPrice(3000);
        order.setTelephone("15974158745");
        order.setDeliveryAddress("泸职院国际学院");
        order.setOrderTime(new Date());
        OrderService orderService = new OrderService();
        int flay = 0;
        List<Order> orders = orderService.findAllOrders();
        for (Order order1:orders){
            if (order1.getUsername().equals(order.getUsername())){
                flay =1;
                break;
            }
        }
        if (flay == 0){
            int count = orderService.addOrder(order);
            if (count > 0) {
                System.out.println("插入成功!");
            } else {
                System.out.println("插入失败!");
            }
        }else {
            System.out.println("有相同的名字插入失败!");
        }


    }

    @Test
    public void testDeleteOrderById(){
        int id = 3;
        OrderService orderService = new OrderService();
        int count = orderService.deleteOrderById(id);
        if (count > 0) {
            System.out.println("删除成功!");
        } else {
            System.out.println("删除失败!");
        }
    }

    @Test
    public void testUpdateOrder(){
        OrderService orderService = new OrderService();
        Order order = orderService.findOrderById(4);
        order.setUsername("小黄");
        int count = orderService.updateOrder(order);
        if (count > 0) {
            System.out.println("更新成功!");
        } else {
            System.out.println("更新失败!");
        }

    }

    @Test
    public void testFindLast(){
        OrderService orderService = new OrderService();
        Order order = orderService.findLastOrder();
        System.out.println(order);
    }
}

实现效果: 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值