@Test public void uploadBackupWithInvalidFilename() throws UnhandledWarningsException, InvalidBackupFileException, IOException { try { backupService.uploadBackup(true, mockMultipartFile.getOriginalFilename(), mockMultipartFile.getBytes()); fail("should throw InvalidFilenameException"); } catch (InvalidFilenameException expected) { assertEquals(ERROR_INVALID_FILENAME, expected.getErrorDeviation().getCode()); } }
public BackupFile uploadBackup(Boolean ignoreWarnings, String filename, byte[] fileBytes) throws InvalidFilenameException, UnhandledWarningsException, InvalidBackupFileException { auditDataHelper.putBackupFilename(backupRepository.getFilePath(filename)); if (!FormatUtils.isValidBackupFilename(filename)) { throw new InvalidFilenameException("uploading backup file failed because of invalid filename (" + filename + ")"); } if (!ignoreWarnings && backupRepository.fileExists(filename)) { throw new UnhandledWarningsException(new WarningDeviation(WARNING_FILE_ALREADY_EXISTS, filename)); } if (!isValidTarFile(fileBytes)) { throw new InvalidBackupFileException("backup file is not a valid tar file (" + filename + ")"); } OffsetDateTime createdAt = backupRepository.writeBackupFile(filename, fileBytes); BackupFile backupFile = new BackupFile(filename); backupFile.setCreatedAt(createdAt); return backupFile; }
BackupService { public BackupFile uploadBackup(Boolean ignoreWarnings, String filename, byte[] fileBytes) throws InvalidFilenameException, UnhandledWarningsException, InvalidBackupFileException { auditDataHelper.putBackupFilename(backupRepository.getFilePath(filename)); if (!FormatUtils.isValidBackupFilename(filename)) { throw new InvalidFilenameException("uploading backup file failed because of invalid filename (" + filename + ")"); } if (!ignoreWarnings && backupRepository.fileExists(filename)) { throw new UnhandledWarningsException(new WarningDeviation(WARNING_FILE_ALREADY_EXISTS, filename)); } if (!isValidTarFile(fileBytes)) { throw new InvalidBackupFileException("backup file is not a valid tar file (" + filename + ")"); } OffsetDateTime createdAt = backupRepository.writeBackupFile(filename, fileBytes); BackupFile backupFile = new BackupFile(filename); backupFile.setCreatedAt(createdAt); return backupFile; } }
BackupService { public BackupFile uploadBackup(Boolean ignoreWarnings, String filename, byte[] fileBytes) throws InvalidFilenameException, UnhandledWarningsException, InvalidBackupFileException { auditDataHelper.putBackupFilename(backupRepository.getFilePath(filename)); if (!FormatUtils.isValidBackupFilename(filename)) { throw new InvalidFilenameException("uploading backup file failed because of invalid filename (" + filename + ")"); } if (!ignoreWarnings && backupRepository.fileExists(filename)) { throw new UnhandledWarningsException(new WarningDeviation(WARNING_FILE_ALREADY_EXISTS, filename)); } if (!isValidTarFile(fileBytes)) { throw new InvalidBackupFileException("backup file is not a valid tar file (" + filename + ")"); } OffsetDateTime createdAt = backupRepository.writeBackupFile(filename, fileBytes); BackupFile backupFile = new BackupFile(filename); backupFile.setCreatedAt(createdAt); return backupFile; } @Autowired  BackupService(BackupRepository backupRepository, ServerConfService serverConfService,
            ExternalProcessRunner externalProcessRunner,
            @Value("${script.generate-backup.path}") String generateBackupScriptPath,
            AuditDataHelper auditDataHelper); }
BackupService { public BackupFile uploadBackup(Boolean ignoreWarnings, String filename, byte[] fileBytes) throws InvalidFilenameException, UnhandledWarningsException, InvalidBackupFileException { auditDataHelper.putBackupFilename(backupRepository.getFilePath(filename)); if (!FormatUtils.isValidBackupFilename(filename)) { throw new InvalidFilenameException("uploading backup file failed because of invalid filename (" + filename + ")"); } if (!ignoreWarnings && backupRepository.fileExists(filename)) { throw new UnhandledWarningsException(new WarningDeviation(WARNING_FILE_ALREADY_EXISTS, filename)); } if (!isValidTarFile(fileBytes)) { throw new InvalidBackupFileException("backup file is not a valid tar file (" + filename + ")"); } OffsetDateTime createdAt = backupRepository.writeBackupFile(filename, fileBytes); BackupFile backupFile = new BackupFile(filename); backupFile.setCreatedAt(createdAt); return backupFile; } @Autowired  BackupService(BackupRepository backupRepository, ServerConfService serverConfService,
            ExternalProcessRunner externalProcessRunner,
            @Value("${script.generate-backup.path}") String generateBackupScriptPath,
            AuditDataHelper auditDataHelper); List<BackupFile> getBackupFiles(); void deleteBackup(String filename); byte[] readBackupFile(String filename); BackupFile generateBackup(); BackupFile uploadBackup(Boolean ignoreWarnings, String filename, byte[] fileBytes); String generateBackupFileName(); }
BackupService { public BackupFile uploadBackup(Boolean ignoreWarnings, String filename, byte[] fileBytes) throws InvalidFilenameException, UnhandledWarningsException, InvalidBackupFileException { auditDataHelper.putBackupFilename(backupRepository.getFilePath(filename)); if (!FormatUtils.isValidBackupFilename(filename)) { throw new InvalidFilenameException("uploading backup file failed because of invalid filename (" + filename + ")"); } if (!ignoreWarnings && backupRepository.fileExists(filename)) { throw new UnhandledWarningsException(new WarningDeviation(WARNING_FILE_ALREADY_EXISTS, filename)); } if (!isValidTarFile(fileBytes)) { throw new InvalidBackupFileException("backup file is not a valid tar file (" + filename + ")"); } OffsetDateTime createdAt = backupRepository.writeBackupFile(filename, fileBytes); BackupFile backupFile = new BackupFile(filename); backupFile.setCreatedAt(createdAt); return backupFile; } @Autowired  BackupService(BackupRepository backupRepository, ServerConfService serverConfService,
            ExternalProcessRunner externalProcessRunner,
            @Value("${script.generate-backup.path}") String generateBackupScriptPath,
            AuditDataHelper auditDataHelper); List<BackupFile> getBackupFiles(); void deleteBackup(String filename); byte[] readBackupFile(String filename); BackupFile generateBackup(); BackupFile uploadBackup(Boolean ignoreWarnings, String filename, byte[] fileBytes); String generateBackupFileName();  }