⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 managerserivcetest.java

📁 是Eclipse web开发从入门到精通的源码
💻 JAVA
字号:
package com.REP.test;


import java.math.BigDecimal;

import junit.framework.TestCase;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.REP.DAO.AccountDAO;
import com.REP.DAO.EmployeeDAO;
import com.REP.ServiceImpl.ManagerServiceImpl;
import com.REP.bean.Account;
import com.REP.bean.Employee;
import com.REP.excptions.AccountNotExistException;

public class ManagerSerivceTest extends TestCase {
    public ManagerServiceImpl managerservice = new ManagerServiceImpl();
    public Account account = new Account();
    public AccountDAO accountdao =  new AccountDAO();
    public EmployeeDAO employeedao = new EmployeeDAO();
    protected void setUp() throws Exception {
        //Hibernate初始化
        Configuration config = new Configuration().configure("com/REP/hbm/hibernate.cfg.xml");
        SessionFactory sessionfactory = config.buildSessionFactory();
        //在DAO对象中注入SessionFactory对象
        accountdao.setSessionFactory(sessionfactory);
        employeedao.setSessionFactory(sessionfactory);
        
        managerservice.setAccountdao(accountdao);
        //保存一个Employee对象
        Employee employee = new Employee();
        employee.setIdcard("111102197210080000");
        employee.setName("ddd");
        employeedao.save(employee);
        //保存一个帐户对象
        account.setLoginName("zs");
        account.setBalance(new BigDecimal("20"));
        account.setOverdrawNumber(2);
        account.setEmployee(employee);
        accountdao.save(account);
        
    }

    
    /*
     * Test method for 'com.REP.ServiceImpl.ManagerServiceImpl.modifyAccount(Account)'
     */
    public void testModifyAccount() {
           
           try {
            account.setOverdrawNumber(3);
            managerservice.modifyAccount(account);
        }catch(Exception e){
            System.out.println("the account is not exist");
            e.printStackTrace();
        }
        
    }

    /*
     * Test method for 'com.REP.ServiceImpl.ManagerServiceImpl.fillAccount(Account, String)'
     */
    public void testFillAccount() {
           try {
            managerservice.fillAccount(account,"60");
        } catch (AccountNotExistException e) {
            System.out.println("the account is not exist");
        }
    }
    
    /*
     * Test method for 'com.REP.ServiceImpl.ManagerServiceImpl.delAccount(Account)'
     */
    public void testDelAccount() {
            try {
                managerservice.delAccount(account);
            } catch (AccountNotExistException e) {
                System.out.println("the account is not exist");
            }
    }
   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -