How to get the file using path for Junit with Jmockit

Viewed 37

I want to cover the file upload functionality so that Created folder File and place db_value in that folder but It throws nio.fileNotFoundException. pls help guys

MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(mockRequest));
UploadItemVO uploadItemVO=new UploadItemVO();
mockRequest.setContextPath("/NPI_LAE");
        try {
            Path path=Paths.get(mockRequest.getContextPath()+"/NPI-Maven/Files/db_value.txt");
            byte[] data = Files.readAllBytes(path);
            MultipartFile file=new MockMultipartFile("db_value.txt","db_value.txt","text/plain",data);
            CommonsMultipartFile f=(CommonsMultipartFile)file;
            mockRequest.addFile(file);
            mockRequest.setMethod("POST");
            uploadItemVO.setMessages("Updating...");
            uploadItemVO.setAdminTemplate(f);
        }catch(Exception e) {
            e.getMessage();
        }
0 Answers
Related