使用Spring MockMvc 测试spring mvc 生成的EXCEL
来源:互联网 发布:php如何调用静态方法 编辑:程序博客网 时间:2024/06/07 22:58
1. SPRING MVC 生成EXCEL
@RequestMapping(value = "/requestFileByJson", method = RequestMethod.POST)public void getListByCallFunction(@RequestBody String data, HttpServletRequest request,HttpServletResponse response, HttpSession session) throws Exception {response.setContentType("application/ms-excel;charset=UTF-8");response.setHeader("Content-Disposition","attachment;filename=".concat(String.valueOf(URLEncoder.encode(systemID + "_"+JName+".xls", "UTF-8"))));OutputStream out = response.getOutputStream();String sheetName = "导出WEBEDI";String titleNames = null;resultMapList = new ArrayList();HSSFWorkbook excel = excelWordService.getExcelByDataMap(resultMapList,sheetName,titleNames);excel.write(out); out.flush();}
2. 使用MockMvc 进行测试生成的EXCEL
@Testpublic void testInserOneLine() throws Exception {String URI = "/Interface/requestFileByJson?JName=T_PAYMENT&JType=INTERFACE&systemID=HD_FA_PAYMENT&fileType=excel&bizUnitName=voucher_export&token=test";String requestBody = "{\"T_PAYMENT\":\"[{\\\"LINE_ID\\\":" + getUnicID()+ ",\\\"ORG_ID\\\":2094,\\\"GROUP_ID\\\":2101,\\\"PURPOSE_NAME\\\":\\\"业务成本\\\" 1,\\\"CURRENCY_CODE\\\":\\\"CNY\\\",\\\"AMOUNT\\\":21.01}, {\\\"LINE_ID\\\":"+ getUnicID()+ ",\\\"ORG_ID\\\":2094,\\\"GROUP_ID\\\":2101,\\\"PURPOSE_NAME\\\":\\\"业务成本\\\" 1,\\\"CURRENCY_CODE\\\":\\\"CNY\\\",\\\"AMOUNT\\\":55.41} ]\"}";this.mockMvc.perform(post("/Interface/requestFileByJson").param("JName", "T_FUNCTION_LIST").param("JType", "DB").contentType(MediaType.APPLICATION_JSON).content(requestBody).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andDo(new ResultHandler() {@Overridepublic void handle(MvcResult result) throws Exception {result.getResponse().setCharacterEncoding("UTF-8");MockHttpServletResponse contentRespon = result.getResponse();InputStream contentInStream = new ByteArrayInputStream(contentRespon.getContentAsByteArray());HSSFWorkbook resultExcel = new HSSFWorkbook(contentInStream);Assert.assertEquals("application/ms-excel", contentRespon.getContentType());HSSFSheet sheet = resultExcel.getSheet("WEBEDI");Assert.assertNotNull(sheet);String filePath = "test-webedi-export.xls";File file = new File(filePath);// if(file.exists())file.delete();resultExcel.write(file);resultExcel.close();Assert.assertTrue(file.exists());}});}
阅读全文
0 0
- 使用Spring MockMvc 测试spring mvc 生成的EXCEL
- 使用MockMvc测试Spring mvc Controller
- 使用MockMvc测试Spring mvc Controller
- 使用MockMvc测试Spring mvc Controller
- Spring 使用Junit的MockMvc 写测试用例
- Spring下使用MockMvc类进行测试
- 使用MockMvc进行Spring的单元测试
- Spring MVC 生成EXCEL
- 使用Spring MVC生成Excel文档
- 使用Spring MVC生成Excel文档 .
- Spring-MockMvc
- Spring MVC学习总结(14)——SpringMVC测试框架之mockMVC详解
- SpringBoot10-Spring MVC-Spring MVC的测试
- 用spring MVC 生成Excel和PDF
- spring MVC 生成并下载Excel
- 用spring MVC 生成Excel和PDF
- 使用MockMvc测试Controller
- Spring MVC 使用poi sxssf 导出excel 2007 的数据
- magento 通过key下载插件到本地
- Gradle环境变量配置
- 小米海量数据推送服务技术讲解
- http://www.blogjava.net/zJun/archive/2006/06/28/55511.html
- 侧滑
- 使用Spring MockMvc 测试spring mvc 生成的EXCEL
- 进程与线程
- 微信小程序 request请求封装(包括登录)
- Map、Set、List、Queue、Stack的特点与用法
- Spring Cloud中Feign配置详解
- MySQL安装
- HashMap和Hashtable的区别
- WPF 动画执行后属性无法修改
- Java进阶面试问题列表