guys.I'm a beginner learning java.And now i have to write a Junit test of Excel upload function in my company demo project.
@RequestMapping(value = "/excelImport")
public ModelAndView excelImport(@RequestParam(value = "filename")MultipartFile file,
ModelAndView mav) {
session.setAttribute("imported",false);//セッションのインポート記録をリセットして、次の操作を影響しないように
List<RetirementPayAndHealthInsurance> errorList= new ArrayList<>();//エラーデータリスト
List<RetirementPayAndHealthInsurance> importList = new ArrayList<>();//導入されたデータリスト
int wnt = 0;//エラー数
int cnt = 0;//正常数
String fileName = file.getOriginalFilename();
if(file.isEmpty()) { //ファイル選択なしにインポートボタンを押す場合
mav.setViewName("redirect:/retailList");
return mav;
}else {
try {
Map<String,List<RetirementPayAndHealthInsurance>> map = retirementPayAndHealthInsuranceService.batchImport(fileName, file);
errorList = map.get("errorList");
importList = map.get("importList");
} catch (Exception e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
if(errorList!=null) {//エラーリストあるの場合
wnt = errorList.size();//エラー数
mav.addObject("errorList",errorList);
session.setAttribute("errorList", errorList);
}
if(importList!=null) {
cnt = importList.size();//正常数
}
//インポートボタン と 導出ボタンを分けるため設定の記録
session.setAttribute("imported",true);
mav.addObject("wnt",wnt);//エラー数
mav.addObject("cnt",cnt);//正常数
mav.setViewName("/retailExcelImport");
return mav;
}
}
i'll explain my logic below.
The excel upload will process and show us the successful imported data number and the error either , service puts the successList,errorList into map and return to controller then count the size of them .Then i could export and reedit the error data and do this process again until it's done.
Now i want to write the junit test of this .But i can't find the similar sample of excel upload test , help me please ,thank you!
Aucun commentaire:
Enregistrer un commentaire