@Test public void storeShouldThrowExceptionUnknownType(@Mocked MultipartFile mockMultipartFile) { String unknownType = "test123"; try { new FileSystemStorageService(mockOdeProperties).store(mockMultipartFile, unknownType); fail("Expected StorageException"); } catch (Exception e) { assertEquals("Incorrect exception thrown", StorageException.class, e.getClass()); assertTrue("Incorrect message received", e.getMessage().startsWith("File type unknown:")); } new Verifications() { { EventLogger.logger.info(anyString, any, any); } }; }
@Override public void store(MultipartFile file, String type) { Path path; if (("bsmlog").equals(type) || ("obulog").equals(type)) { path = this.logFileLocation.resolve(file.getOriginalFilename()); } else { EventLogger.logger.info("File type unknown: {} {}", type, file.getName()); throw new StorageException("File type unknown: " + type + " " + file.getName()); } if (file.isEmpty()) { EventLogger.logger.info("File is empty: {}", path); throw new StorageException("File is empty: " + path); } try { EventLogger.logger.info("Deleting existing file: {}", path); Files.deleteIfExists(path); } catch (IOException e) { EventLogger.logger.info("Failed to delete existing file: {} ", path); throw new StorageException("Failed to delete existing file: " + path, e); } try { logger.debug("Copying file {} to {}", file.getOriginalFilename(), path); EventLogger.logger.info("Copying file {} to {}", file.getOriginalFilename(), path); Files.copy(file.getInputStream(), path); } catch (Exception e) { EventLogger.logger.info("Failed to store file in shared directory {}", path); throw new StorageException("Failed to store file in shared directory " + path, e); } }
FileSystemStorageService implements StorageService { @Override public void store(MultipartFile file, String type) { Path path; if (("bsmlog").equals(type) || ("obulog").equals(type)) { path = this.logFileLocation.resolve(file.getOriginalFilename()); } else { EventLogger.logger.info("File type unknown: {} {}", type, file.getName()); throw new StorageException("File type unknown: " + type + " " + file.getName()); } if (file.isEmpty()) { EventLogger.logger.info("File is empty: {}", path); throw new StorageException("File is empty: " + path); } try { EventLogger.logger.info("Deleting existing file: {}", path); Files.deleteIfExists(path); } catch (IOException e) { EventLogger.logger.info("Failed to delete existing file: {} ", path); throw new StorageException("Failed to delete existing file: " + path, e); } try { logger.debug("Copying file {} to {}", file.getOriginalFilename(), path); EventLogger.logger.info("Copying file {} to {}", file.getOriginalFilename(), path); Files.copy(file.getInputStream(), path); } catch (Exception e) { EventLogger.logger.info("Failed to store file in shared directory {}", path); throw new StorageException("Failed to store file in shared directory " + path, e); } } }
FileSystemStorageService implements StorageService { @Override public void store(MultipartFile file, String type) { Path path; if (("bsmlog").equals(type) || ("obulog").equals(type)) { path = this.logFileLocation.resolve(file.getOriginalFilename()); } else { EventLogger.logger.info("File type unknown: {} {}", type, file.getName()); throw new StorageException("File type unknown: " + type + " " + file.getName()); } if (file.isEmpty()) { EventLogger.logger.info("File is empty: {}", path); throw new StorageException("File is empty: " + path); } try { EventLogger.logger.info("Deleting existing file: {}", path); Files.deleteIfExists(path); } catch (IOException e) { EventLogger.logger.info("Failed to delete existing file: {} ", path); throw new StorageException("Failed to delete existing file: " + path, e); } try { logger.debug("Copying file {} to {}", file.getOriginalFilename(), path); EventLogger.logger.info("Copying file {} to {}", file.getOriginalFilename(), path); Files.copy(file.getInputStream(), path); } catch (Exception e) { EventLogger.logger.info("Failed to store file in shared directory {}", path); throw new StorageException("Failed to store file in shared directory " + path, e); } } @Autowired  FileSystemStorageService(OdeProperties properties); }
FileSystemStorageService implements StorageService { @Override public void store(MultipartFile file, String type) { Path path; if (("bsmlog").equals(type) || ("obulog").equals(type)) { path = this.logFileLocation.resolve(file.getOriginalFilename()); } else { EventLogger.logger.info("File type unknown: {} {}", type, file.getName()); throw new StorageException("File type unknown: " + type + " " + file.getName()); } if (file.isEmpty()) { EventLogger.logger.info("File is empty: {}", path); throw new StorageException("File is empty: " + path); } try { EventLogger.logger.info("Deleting existing file: {}", path); Files.deleteIfExists(path); } catch (IOException e) { EventLogger.logger.info("Failed to delete existing file: {} ", path); throw new StorageException("Failed to delete existing file: " + path, e); } try { logger.debug("Copying file {} to {}", file.getOriginalFilename(), path); EventLogger.logger.info("Copying file {} to {}", file.getOriginalFilename(), path); Files.copy(file.getInputStream(), path); } catch (Exception e) { EventLogger.logger.info("Failed to store file in shared directory {}", path); throw new StorageException("Failed to store file in shared directory " + path, e); } } @Autowired  FileSystemStorageService(OdeProperties properties); @Override void store(MultipartFile file, String type); @Override Stream<Path> loadAll(); @Override Path load(String filename); @Override Resource loadAsResource(String filename); @Override void deleteAll(); @Override void init(); Path getRootLocation(); void setRootLocation(Path rootLocation); }
FileSystemStorageService implements StorageService { @Override public void store(MultipartFile file, String type) { Path path; if (("bsmlog").equals(type) || ("obulog").equals(type)) { path = this.logFileLocation.resolve(file.getOriginalFilename()); } else { EventLogger.logger.info("File type unknown: {} {}", type, file.getName()); throw new StorageException("File type unknown: " + type + " " + file.getName()); } if (file.isEmpty()) { EventLogger.logger.info("File is empty: {}", path); throw new StorageException("File is empty: " + path); } try { EventLogger.logger.info("Deleting existing file: {}", path); Files.deleteIfExists(path); } catch (IOException e) { EventLogger.logger.info("Failed to delete existing file: {} ", path); throw new StorageException("Failed to delete existing file: " + path, e); } try { logger.debug("Copying file {} to {}", file.getOriginalFilename(), path); EventLogger.logger.info("Copying file {} to {}", file.getOriginalFilename(), path); Files.copy(file.getInputStream(), path); } catch (Exception e) { EventLogger.logger.info("Failed to store file in shared directory {}", path); throw new StorageException("Failed to store file in shared directory " + path, e); } } @Autowired  FileSystemStorageService(OdeProperties properties); @Override void store(MultipartFile file, String type); @Override Stream<Path> loadAll(); @Override Path load(String filename); @Override Resource loadAsResource(String filename); @Override void deleteAll(); @Override void init(); Path getRootLocation(); void setRootLocation(Path rootLocation);  }