@Test public void testImportBlackList() throws Exception { byte[] fileContent = FileCopyUtils .copyToByteArray(Thread.currentThread().getContextClassLoader().getResourceAsStream("BlackList.xls")); MockMultipartFile file = new MockMultipartFile("BlackList.xls", Thread.currentThread().getContextClassLoader().getResourceAsStream("BlackList.xls")); MockMultipartHttpServletRequest req = new MockMultipartHttpServletRequest(); req.setMethod("POST"); String boundary = "JPnJUN6FOo0qLySf-__r_RY1nQE7QOXXJ_nLK1s"; req.setContentType("multipart/form-data; boundary=" + boundary); String start = "--" + boundary + "\r\n Content-Disposition: form-data; name=\"file\"; filename=\"" + "BlackList.xls" + "\"\r\n" + "Content-type: " + "application/vnd.ms-excel" + "\r\n\r\n"; String end = "\r\n--" + boundary + "--"; req.setContent(ArrayUtils.addAll(start.getBytes(), ArrayUtils.addAll(fileContent, end.getBytes()))); req.addHeader("name", "BlackList.xls"); req.addFile(file); ExportAndImportDecisionBlackListEntries controller = new ExportAndImportDecisionBlackListEntries(); MockHttpServletResponse resp = new MockHttpServletResponse(); controller.importBlackListFile(req, resp); assertTrue(resp.getContentAsString().contains("data")); }
@RequestMapping(value = {"/policycreation/importBlackListForDecisionPolicy"}, method = {RequestMethod.POST}) public void importBlackListFile(HttpServletRequest request, HttpServletResponse response) { try { List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); List<String> errorLogs = new ArrayList<>(); Gson mapper = new Gson(); errorLogs.add("error"); Map<String, Object> model = new HashMap<>(); if (items.isEmpty()) { errorLogs.add("The File doesn't have any content and it is invalid."); model.put(BLACKLISTENTRIESDATA, errorLogs); } else { readItems(items, errorLogs, model); } response.getWriter().write(new JSONObject(new JsonMessage(mapper.toJson(model))).toString()); } catch (FileUploadException | IOException e) { policyLogger.error("Exception Occured while importing the BlackListEntry", e); } }
ExportAndImportDecisionBlackListEntries extends RestrictedBaseController { @RequestMapping(value = {"/policycreation/importBlackListForDecisionPolicy"}, method = {RequestMethod.POST}) public void importBlackListFile(HttpServletRequest request, HttpServletResponse response) { try { List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); List<String> errorLogs = new ArrayList<>(); Gson mapper = new Gson(); errorLogs.add("error"); Map<String, Object> model = new HashMap<>(); if (items.isEmpty()) { errorLogs.add("The File doesn't have any content and it is invalid."); model.put(BLACKLISTENTRIESDATA, errorLogs); } else { readItems(items, errorLogs, model); } response.getWriter().write(new JSONObject(new JsonMessage(mapper.toJson(model))).toString()); } catch (FileUploadException | IOException e) { policyLogger.error("Exception Occured while importing the BlackListEntry", e); } } }
ExportAndImportDecisionBlackListEntries extends RestrictedBaseController { @RequestMapping(value = {"/policycreation/importBlackListForDecisionPolicy"}, method = {RequestMethod.POST}) public void importBlackListFile(HttpServletRequest request, HttpServletResponse response) { try { List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); List<String> errorLogs = new ArrayList<>(); Gson mapper = new Gson(); errorLogs.add("error"); Map<String, Object> model = new HashMap<>(); if (items.isEmpty()) { errorLogs.add("The File doesn't have any content and it is invalid."); model.put(BLACKLISTENTRIESDATA, errorLogs); } else { readItems(items, errorLogs, model); } response.getWriter().write(new JSONObject(new JsonMessage(mapper.toJson(model))).toString()); } catch (FileUploadException | IOException e) { policyLogger.error("Exception Occured while importing the BlackListEntry", e); } }  }
ExportAndImportDecisionBlackListEntries extends RestrictedBaseController { @RequestMapping(value = {"/policycreation/importBlackListForDecisionPolicy"}, method = {RequestMethod.POST}) public void importBlackListFile(HttpServletRequest request, HttpServletResponse response) { try { List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); List<String> errorLogs = new ArrayList<>(); Gson mapper = new Gson(); errorLogs.add("error"); Map<String, Object> model = new HashMap<>(); if (items.isEmpty()) { errorLogs.add("The File doesn't have any content and it is invalid."); model.put(BLACKLISTENTRIESDATA, errorLogs); } else { readItems(items, errorLogs, model); } response.getWriter().write(new JSONObject(new JsonMessage(mapper.toJson(model))).toString()); } catch (FileUploadException | IOException e) { policyLogger.error("Exception Occured while importing the BlackListEntry", e); } }  @RequestMapping(value = {"/policycreation/exportDecisionBlackListEntries"}, method = {RequestMethod.POST}) void exportBlackList(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/policycreation/importBlackListForDecisionPolicy"}, method = {RequestMethod.POST}) void importBlackListFile(HttpServletRequest request, HttpServletResponse response); }
ExportAndImportDecisionBlackListEntries extends RestrictedBaseController { @RequestMapping(value = {"/policycreation/importBlackListForDecisionPolicy"}, method = {RequestMethod.POST}) public void importBlackListFile(HttpServletRequest request, HttpServletResponse response) { try { List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); List<String> errorLogs = new ArrayList<>(); Gson mapper = new Gson(); errorLogs.add("error"); Map<String, Object> model = new HashMap<>(); if (items.isEmpty()) { errorLogs.add("The File doesn't have any content and it is invalid."); model.put(BLACKLISTENTRIESDATA, errorLogs); } else { readItems(items, errorLogs, model); } response.getWriter().write(new JSONObject(new JsonMessage(mapper.toJson(model))).toString()); } catch (FileUploadException | IOException e) { policyLogger.error("Exception Occured while importing the BlackListEntry", e); } }  @RequestMapping(value = {"/policycreation/exportDecisionBlackListEntries"}, method = {RequestMethod.POST}) void exportBlackList(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/policycreation/importBlackListForDecisionPolicy"}, method = {RequestMethod.POST}) void importBlackListFile(HttpServletRequest request, HttpServletResponse response);  }