@Test public void updateModelSuccess() { byte[] a = hexStringToByteArray("e04fd020ea3a6910a2d808002b30309d"); MultipartFile file = new MockMultipartFile("something.stl", "something.stl", null ,a); PrintModelUpdateRequest request = new PrintModelUpdateRequest(); request.setFile(file); PrintJob printJob = new PrintJob(); printJob.setId(999); printJob.setFilePath("DROPBOX_PATH"); printJob.setFileSharableLink("http: DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>(); response.setSuccess(true); response.setMessage("Successfully updated file to database!"); response.setHttpStatus(HttpStatus.ACCEPTED); List<PrintJob> printJobs = new ArrayList<>(); printJobs.add(printJob); List<BasicPrintJob> basicPrintJobs = new BasicPrintJob().ConvertPrintJobs(printJobs); response.setData(basicPrintJobs); Map<String, String> data = new HashMap<>(); data.put("filePath", "DROPBOX_PATH"); data.put("sharableLink", "http: when(printJobRepo.findPrintJobById(printJob.getId())).thenReturn(printJob); when(fileService.updateFile(printJob, request.getFile())).thenReturn(data); when(printJobRepo.save(printJob)).thenReturn(printJob); DataResponse<BasicPrintJob> opResponse = operations.updateModel(printJob.getId(), request); assert(opResponse.equals(response)); }
public DataResponse<BasicPrintJob> updateModel(Integer printId, PrintModelUpdateRequest model){ model.validate(); DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>("Model could not be updated"); PrintJob printJob = printJobRepo.findPrintJobById(printId); if(printJob == null) { throw new IdeaLabApiException(PRINT_JOB_CANT_FIND_BY_ID); } Map<String, String> data; data = fileService.updateFile(printJob, model.getFile()); printJob.setFilePath(data.get("filePath")); printJob.setFileSharableLink(data.get("sharableLink")); printJob = printJobRepo.save(printJob); return getPrintJobResponse(response, printJob, data, "Successfully updated file to database!"); }
PrintJobOperations { public DataResponse<BasicPrintJob> updateModel(Integer printId, PrintModelUpdateRequest model){ model.validate(); DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>("Model could not be updated"); PrintJob printJob = printJobRepo.findPrintJobById(printId); if(printJob == null) { throw new IdeaLabApiException(PRINT_JOB_CANT_FIND_BY_ID); } Map<String, String> data; data = fileService.updateFile(printJob, model.getFile()); printJob.setFilePath(data.get("filePath")); printJob.setFileSharableLink(data.get("sharableLink")); printJob = printJobRepo.save(printJob); return getPrintJobResponse(response, printJob, data, "Successfully updated file to database!"); } }
PrintJobOperations { public DataResponse<BasicPrintJob> updateModel(Integer printId, PrintModelUpdateRequest model){ model.validate(); DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>("Model could not be updated"); PrintJob printJob = printJobRepo.findPrintJobById(printId); if(printJob == null) { throw new IdeaLabApiException(PRINT_JOB_CANT_FIND_BY_ID); } Map<String, String> data; data = fileService.updateFile(printJob, model.getFile()); printJob.setFilePath(data.get("filePath")); printJob.setFileSharableLink(data.get("sharableLink")); printJob = printJobRepo.save(printJob); return getPrintJobResponse(response, printJob, data, "Successfully updated file to database!"); } PrintJobOperations(FileService fileService, PrintJobRepo printJobRepo,
                              ColorTypeRepo colorTypeRepo, CustomerInfoRepo customerInfoRepo,
                              EmployeeRepo employeeRepo, EmailHashUtil emailHashUtil, QueueRepo queueRepo); }
PrintJobOperations { public DataResponse<BasicPrintJob> updateModel(Integer printId, PrintModelUpdateRequest model){ model.validate(); DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>("Model could not be updated"); PrintJob printJob = printJobRepo.findPrintJobById(printId); if(printJob == null) { throw new IdeaLabApiException(PRINT_JOB_CANT_FIND_BY_ID); } Map<String, String> data; data = fileService.updateFile(printJob, model.getFile()); printJob.setFilePath(data.get("filePath")); printJob.setFileSharableLink(data.get("sharableLink")); printJob = printJobRepo.save(printJob); return getPrintJobResponse(response, printJob, data, "Successfully updated file to database!"); } PrintJobOperations(FileService fileService, PrintJobRepo printJobRepo,
                              ColorTypeRepo colorTypeRepo, CustomerInfoRepo customerInfoRepo,
                              EmployeeRepo employeeRepo, EmailHashUtil emailHashUtil, QueueRepo queueRepo); DataResponse<BasicPrintJob> newPrintJob(PrintJobNewRequest printJobNewRequest, Principal principal); DataResponse<BasicPrintJob> updateModel(Integer printId, PrintModelUpdateRequest model); GenericResponse deleteModel(Integer printId); GenericResponse updatePrintJobStatus(Integer printId, PrintJobUpdateRequest dto); GenericResponse deletePrintJob(PrintJobDeleteRequest dto); DataResponse<BasicPrintJob> getAllPrintJobs(String status); DataResponse<BasicPrintJob> getDeletablePrintJobs(); DataResponse<BasicPrintJob> updatePrintJobProps(Integer printJobId, UpdatePrintJobPropertiesRequest request); DataResponse<BasicPrintJob> getPrintJobById(Integer printJobId); }
PrintJobOperations { public DataResponse<BasicPrintJob> updateModel(Integer printId, PrintModelUpdateRequest model){ model.validate(); DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>("Model could not be updated"); PrintJob printJob = printJobRepo.findPrintJobById(printId); if(printJob == null) { throw new IdeaLabApiException(PRINT_JOB_CANT_FIND_BY_ID); } Map<String, String> data; data = fileService.updateFile(printJob, model.getFile()); printJob.setFilePath(data.get("filePath")); printJob.setFileSharableLink(data.get("sharableLink")); printJob = printJobRepo.save(printJob); return getPrintJobResponse(response, printJob, data, "Successfully updated file to database!"); } PrintJobOperations(FileService fileService, PrintJobRepo printJobRepo,
                              ColorTypeRepo colorTypeRepo, CustomerInfoRepo customerInfoRepo,
                              EmployeeRepo employeeRepo, EmailHashUtil emailHashUtil, QueueRepo queueRepo); DataResponse<BasicPrintJob> newPrintJob(PrintJobNewRequest printJobNewRequest, Principal principal); DataResponse<BasicPrintJob> updateModel(Integer printId, PrintModelUpdateRequest model); GenericResponse deleteModel(Integer printId); GenericResponse updatePrintJobStatus(Integer printId, PrintJobUpdateRequest dto); GenericResponse deletePrintJob(PrintJobDeleteRequest dto); DataResponse<BasicPrintJob> getAllPrintJobs(String status); DataResponse<BasicPrintJob> getDeletablePrintJobs(); DataResponse<BasicPrintJob> updatePrintJobProps(Integer printJobId, UpdatePrintJobPropertiesRequest request); DataResponse<BasicPrintJob> getPrintJobById(Integer printJobId);  }