单元测试类案例-java

2021/7/16 11:16:00

本文主要是介绍单元测试类案例-java,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

package com.szjz.web.invoice.invoiceInfo;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.json.JSONUtil;
import com.szjz.common.entity.UserInfo;
import com.szjz.common.utils.AjaxJson;
import com.szjz.facade.invoice.facade.InvoiceInfoDockFacade;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liu.chengjie
 * @desc 发票夹对外接口单元测试
 * @date 2021-1-11 10:04
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/spring/spring-context.xml" })
@WebAppConfiguration
public class InvoiceInfoTest {

    @Autowired
    private InvoiceInfoDockFacade invoiceInfoDockFacade;

    private Map<String,Object> paramMap = new HashMap<>();

    private String user119 = "{\"orgName\":\"计划财务部\",\"isFirstLogin\":\"YES\",\"year\":\"2021\",\"roleId\":\"402881bf6efd1cd3016efe197263000c\",\"userName\":\"119\",\"userId\":\"4028808466ce78380166f64e0b4a1334\",\"userCode\":\"119\",\"orgId\":\"4028801f5eb82bae015ebc98c008000c\",\"xmkPage\":false,\"lastLoginTime\":\"2021-01-07 17:23:32\",\"wechatNum\":\"\",\"phone\":\"EGFBCDCBCDE\",\"parentOrgId\":\"b0f54c42b7c64b65af0bae4d63b0bf8f\",\"orgCode\":\"109\",\"loginName\":\"119\",\"roleName\":\"超级管理员角色\",\"userType\":\"10001\"}";

    private UserInfo userInfo;

    @Before
    public void setUp() throws Exception {
        userInfo = JSONUtil.toBean(user119, UserInfo.class);
    }

    @After
    public void tearDown() throws Exception {
    }

    /*--------------------------------------------------------测试需要数据库有对应的授权信息,发票附件信息及单据信息--------------------------------------*/
    /**
     * @Description: 发票夹-报账查询授权列表(查询当前授权全部,不传订单号)
     * @Param: [userId, 用户ID  empowerObjectId 授权ID , year 年度, orderNo 报销单号, userInfo 用户信息, paramMap 其他参数]
     * @return: com.szjz.common.utils.AjaxJson
     * @Author: liu.chengjie
     * @Date: 2021-1-13
     */
    @Test
    public void queryInvoiceInfoForBill01() throws Exception{
        AjaxJson ajaxJson = invoiceInfoDockFacade.queryInvoiceInfoForBill("4028808466ce78380166f64e0b4a1334","","2021","",userInfo,paramMap);
        Console.log(JSONUtil.toJsonStr(ajaxJson));
    }

    /**
     * @Description: 报账授权数据第一次保存(根据单号,附件ID及授权进行保存)
     * @Param: [request, response, paramMap]
     * @return: com.szjz.common.utils.AjaxJson
     * @Author: liu.chengjie
     * @Date: 2021-1-8
     */
    @Test
    public void saveAccSelectInvoice01() throws Exception{
        List<Map<String,Object>> infoList = new ArrayList<>();
        Map<String,Object> map01 = CollUtil.newHashMap();
        Map<String,Object> map02 = CollUtil.newHashMap();
        Map<String,Object> map03 = CollUtil.newHashMap();
        Map<String,Object> map04 = CollUtil.newHashMap();
        map01.put("empowerId","8a818aaa7a9f3519017a9f3f8041000c");
        map01.put("sysFileId","8a818aaa7a9f3519017a9f3f790b0009");
        map01.put("useMoney","0");

        infoList.add(map01);
        AjaxJson ajaxJson = invoiceInfoDockFacade.saveAccSelectInvoice("BX2021010200007",infoList,paramMap,userInfo);
        Console.log(JSONUtil.toJsonStr(ajaxJson));
    }

    /**
     * @Description: 发票夹-报账查询授权列表(修改查询,根据当前单号查询本单号使用的和未使用的,剩余金额小于零的不查出来,同一个附件两个授权取小的剩余金额)
     * @Param: [userId, 用户ID  empowerObjectId 授权ID , year 年度, orderNo 报销单号, userInfo 用户信息, paramMap 其他参数]
     * @return: com.szjz.common.utils.AjaxJson
     * @Author: liu.chengjie
     * @Date: 2021-1-13
     */
    @Test
    public void queryInvoiceInfoForBill02() throws Exception{
        AjaxJson ajaxJson = invoiceInfoDockFacade.queryInvoiceInfoForBill("4028808466ce78380166f64e0b4a1334","","2021","BX2021010200007",userInfo,paramMap);
        Console.log(JSONUtil.toJsonStr(ajaxJson));
    }

    /**
     * @Description: 报账授权数据第二次保存(删除其中一条,新增另一条,改变其中一条数据)
     * @Param: [request, response, paramMap]
     * @return: com.szjz.common.utils.AjaxJson
     * @Author: liu.chengjie
     * @Date: 2021-1-8
     */
    @Test
    public void saveAccSelectInvoice02() throws Exception{
        List<Map<String,Object>> infoList = new ArrayList<>();
        Map<String,Object> map01 = CollUtil.newHashMap();
        Map<String,Object> map02 = CollUtil.newHashMap();
        Map<String,Object> map05 = CollUtil.newHashMap();
        Map<String,Object> map04 = CollUtil.newHashMap();
        map01.put("empowerId","8a818a9576f94e980176fa617681009c");
        map01.put("sysFileId","8a818a9576f94e980176fa60f68d0092");
        map01.put("useMoney","115");

        map02.put("empowerId","8a818a9576f94e980176fa627bf3009e");
        map02.put("sysFileId","8a818a9576f94e980176fa60f68d0092");
        map02.put("useMoney","100");

        map04.put("empowerId","8a818a9576f94e980176fa5d7f740083");
        map04.put("sysFileId","8a818a9576f94e980176fa5d72dc007e");
        map04.put("useMoney","2");

        map05.put("empowerId","8a818a9576fadddf0176fae18d650015");
        map05.put("sysFileId","8a818a9576fadddf0176fae180b10010");
        map05.put("useMoney","3");

        infoList.add(map01);
        infoList.add(map02);
        infoList.add(map05);
        infoList.add(map04);
        AjaxJson ajaxJson = invoiceInfoDockFacade.saveAccSelectInvoice("BX2021010200007",infoList,paramMap,userInfo);
        Console.log(JSONUtil.toJsonStr(ajaxJson));
    }


    /**
     * @Description: 发票夹-报账查询授权列表(再次查询当前数据,检查数据是否正常(删除单据是否还钱,新增是否扣钱,修改是否成功))
     * @Param: [userId, 用户ID  empowerObjectId 授权ID , year 年度, orderNo 报销单号, userInfo 用户信息, paramMap 其他参数]
     * @return: com.szjz.common.utils.AjaxJson
     * @Author: liu.chengjie
     * @Date: 2021-1-13
     */
    @Test
    public void queryInvoiceInfoForBill03() throws Exception{
        AjaxJson ajaxJson = invoiceInfoDockFacade.queryInvoiceInfoForBill("4028808466ce78380166f64e0b4a1334","4028808466ce78380166f64e0b4a1334","2020","BX2021010200007",userInfo,paramMap);
        Console.log(JSONUtil.toJsonStr(ajaxJson));
    }




    /***
     * @Description: 发票夹-报账发票授权删除(根据orderNo和empowerId固定删除其中一条授权使用记录)
     * @Param: [orderNo 报销单号, sysFileIds 附件ID, empowerId 授权ID, userInfo 用户信息, paramMap 其他参数]
     * @return: com.szjz.common.utils.AjaxJson
     * @Author: liu.chengjie
     * @Date: 2021-1-13
     */
    @Test
    public void deleteInvoiceInfoForBill01() throws Exception{
        AjaxJson ajaxJson = invoiceInfoDockFacade.deleteInvoiceInfoForBill("BX2021010200007","","8a818a9576fadddf0176fae18d650015",userInfo,paramMap);
        assert ajaxJson.isSuccess();
    }

    /***
     * @Description: 发票夹-报账发票授权删除(根据orderNo删除相关的全部授权使用记录)
     * @Param: [orderNo 报销单号, sysFileIds 附件ID, empowerId 授权ID, userInfo 用户信息, paramMap 其他参数]
     * @return: com.szjz.common.utils.AjaxJson
     * @Author: liu.chengjie
     * @Date: 2021-1-13
     */
    @Test
    public void deleteInvoiceInfoForBill02() throws Exception{
        AjaxJson ajaxJson = invoiceInfoDockFacade.deleteInvoiceInfoForBill("BX2021010200007","","",userInfo,paramMap);
        assert ajaxJson.isSuccess();
    }

    /**
     * @Description: 报账票据类型查询
     * @Param: [request, response, paramMap]
     * @return: com.szjz.common.utils.AjaxJson
     * @Author: liu.chengjie
     * @Date: 2021-1-8
     */
    @Test
    public void findInvoiceType() throws Exception{
        AjaxJson ajaxJson = invoiceInfoDockFacade.findInvoiceType(paramMap);
        Console.log(JSONUtil.toJsonStr(ajaxJson));
    }

    /**
     * @Description: 报账授权数据第一次保存(保存申请金额传零测试)
     * @Param: [request, response, paramMap]
     * @return: com.szjz.common.utils.AjaxJson
     * @Author: liu.chengjie
     * @Date: 2021-1-8
     */
    @Test
    public void saveAccSelectInvoice03() throws Exception{
        List<Map<String,Object>> infoList = new ArrayList<>();
        Map<String,Object> map01 = CollUtil.newHashMap();
        map01.put("empowerId","8a818a9576f94e980176fa617681009c");
        map01.put("sysFileId","8a818a9576f94e980176fa60f68d0092");
        map01.put("useMoney","0");
        infoList.add(map01);
        AjaxJson ajaxJson = invoiceInfoDockFacade.saveAccSelectInvoice("BX2021010200007",infoList,paramMap,userInfo);
        Console.log(JSONUtil.toJsonStr(ajaxJson));
    }

    /**
     * @Description: 报账授权数据第一次保存(保存申请超额测试)
     * @Param: [request, response, paramMap]
     * @return: com.szjz.common.utils.AjaxJson
     * @Author: liu.chengjie
     * @Date: 2021-1-8
     */
    @Test
    public void saveAccSelectInvoice04() throws Exception{
        List<Map<String,Object>> infoList = new ArrayList<>();
        Map<String,Object> map01 = CollUtil.newHashMap();
        map01.put("empowerId","8a818a9576f94e980176fa627bf3009e");
        map01.put("sysFileId","8a818a9576f94e980176fa60f68d0092");
        map01.put("useMoney","101");
        infoList.add(map01);
        AjaxJson ajaxJson = invoiceInfoDockFacade.saveAccSelectInvoice("BX2021010200007",infoList,paramMap,userInfo);
        Console.log(JSONUtil.toJsonStr(ajaxJson));
    }

    /**
     * @Description: 报账授权数据第一次保存(测试传upload)
     * @Param: [request, response, paramMap]
     * @return: com.szjz.common.utils.AjaxJson
     * @Author: liu.chengjie
     * @Date: 2021-1-8
     */
    @Test
    public void saveAccSelectInvoice05() throws Exception{
        List<Map<String,Object>> infoList = new ArrayList<>();
        Map<String,Object> map01 = CollUtil.newHashMap();
        map01.put("empowerId","8a818a9576f94e980176fa5d7f740083");
        map01.put("sysFileId","8a818a9576f94e980176fa5d72dc007e");
        map01.put("useMoney","0");
        map01.put("saveType","upload");
        infoList.add(map01);
        AjaxJson ajaxJson = invoiceInfoDockFacade.saveAccSelectInvoice("BX2021010200007",infoList,paramMap,userInfo);
        Console.log(JSONUtil.toJsonStr(ajaxJson));
    }


    /**
     * @Description: 报账删除发票夹单元测试
     * @Param: [request, response, paramMap]
     * @return: com.szjz.common.utils.AjaxJson
     * @Author: liu.chengjie
     * @Date: 2021-1-8
     */
    @Test
    public void deleteInvoiceInfo() throws Exception{
        AjaxJson ajaxJson = invoiceInfoDockFacade.accDelInvoice("8a818aaa7a5a869c017a5a888c060001",userInfo,paramMap);
        assert ajaxJson.isSuccess();
    }

}

 



这篇关于单元测试类案例-java的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程