@Test public void addBackupFails() throws Exception { mockExternalProcessRunnerFail(); try { backupService.generateBackup(); fail("should throw DeviationAwareRuntimeException"); } catch (DeviationAwareRuntimeException expected) { } }
public BackupFile generateBackup() throws InterruptedException { SecurityServerId securityServerId = serverConfService.getSecurityServerId(); String filename = generateBackupFileName(); auditDataHelper.putBackupFilename(backupRepository.getFilePath(filename)); String fullPath = backupRepository.getConfigurationBackupPath() + filename; String[] args = new String[] {"-s", securityServerId.toShortString(), "-f", fullPath}; try { log.info("Run configuration backup with command '" + generateBackupScriptPath + " " + Arrays.toString(args) + "'"); ExternalProcessRunner.ProcessResult processResult = externalProcessRunner .executeAndThrowOnFailure(generateBackupScriptPath, args); log.info(" --- Backup script console output - START --- "); log.info(String.join("\n", processResult.getProcessOutput())); log.info(" --- Backup script console output - END --- "); } catch (ProcessNotExecutableException | ProcessFailedException e) { throw new DeviationAwareRuntimeException(e, new ErrorDeviation(BACKUP_GENERATION_FAILED)); } Optional<BackupFile> backupFile = getBackup(filename); if (!backupFile.isPresent()) { throw new DeviationAwareRuntimeException(getFileNotFoundExceptionMessage(filename), new ErrorDeviation(BACKUP_GENERATION_FAILED)); } return backupFile.get(); }
BackupService { public BackupFile generateBackup() throws InterruptedException { SecurityServerId securityServerId = serverConfService.getSecurityServerId(); String filename = generateBackupFileName(); auditDataHelper.putBackupFilename(backupRepository.getFilePath(filename)); String fullPath = backupRepository.getConfigurationBackupPath() + filename; String[] args = new String[] {"-s", securityServerId.toShortString(), "-f", fullPath}; try { log.info("Run configuration backup with command '" + generateBackupScriptPath + " " + Arrays.toString(args) + "'"); ExternalProcessRunner.ProcessResult processResult = externalProcessRunner .executeAndThrowOnFailure(generateBackupScriptPath, args); log.info(" --- Backup script console output - START --- "); log.info(String.join("\n", processResult.getProcessOutput())); log.info(" --- Backup script console output - END --- "); } catch (ProcessNotExecutableException | ProcessFailedException e) { throw new DeviationAwareRuntimeException(e, new ErrorDeviation(BACKUP_GENERATION_FAILED)); } Optional<BackupFile> backupFile = getBackup(filename); if (!backupFile.isPresent()) { throw new DeviationAwareRuntimeException(getFileNotFoundExceptionMessage(filename), new ErrorDeviation(BACKUP_GENERATION_FAILED)); } return backupFile.get(); } }
BackupService { public BackupFile generateBackup() throws InterruptedException { SecurityServerId securityServerId = serverConfService.getSecurityServerId(); String filename = generateBackupFileName(); auditDataHelper.putBackupFilename(backupRepository.getFilePath(filename)); String fullPath = backupRepository.getConfigurationBackupPath() + filename; String[] args = new String[] {"-s", securityServerId.toShortString(), "-f", fullPath}; try { log.info("Run configuration backup with command '" + generateBackupScriptPath + " " + Arrays.toString(args) + "'"); ExternalProcessRunner.ProcessResult processResult = externalProcessRunner .executeAndThrowOnFailure(generateBackupScriptPath, args); log.info(" --- Backup script console output - START --- "); log.info(String.join("\n", processResult.getProcessOutput())); log.info(" --- Backup script console output - END --- "); } catch (ProcessNotExecutableException | ProcessFailedException e) { throw new DeviationAwareRuntimeException(e, new ErrorDeviation(BACKUP_GENERATION_FAILED)); } Optional<BackupFile> backupFile = getBackup(filename); if (!backupFile.isPresent()) { throw new DeviationAwareRuntimeException(getFileNotFoundExceptionMessage(filename), new ErrorDeviation(BACKUP_GENERATION_FAILED)); } return backupFile.get(); } @Autowired  BackupService(BackupRepository backupRepository, ServerConfService serverConfService,
            ExternalProcessRunner externalProcessRunner,
            @Value("${script.generate-backup.path}") String generateBackupScriptPath,
            AuditDataHelper auditDataHelper); }
BackupService { public BackupFile generateBackup() throws InterruptedException { SecurityServerId securityServerId = serverConfService.getSecurityServerId(); String filename = generateBackupFileName(); auditDataHelper.putBackupFilename(backupRepository.getFilePath(filename)); String fullPath = backupRepository.getConfigurationBackupPath() + filename; String[] args = new String[] {"-s", securityServerId.toShortString(), "-f", fullPath}; try { log.info("Run configuration backup with command '" + generateBackupScriptPath + " " + Arrays.toString(args) + "'"); ExternalProcessRunner.ProcessResult processResult = externalProcessRunner .executeAndThrowOnFailure(generateBackupScriptPath, args); log.info(" --- Backup script console output - START --- "); log.info(String.join("\n", processResult.getProcessOutput())); log.info(" --- Backup script console output - END --- "); } catch (ProcessNotExecutableException | ProcessFailedException e) { throw new DeviationAwareRuntimeException(e, new ErrorDeviation(BACKUP_GENERATION_FAILED)); } Optional<BackupFile> backupFile = getBackup(filename); if (!backupFile.isPresent()) { throw new DeviationAwareRuntimeException(getFileNotFoundExceptionMessage(filename), new ErrorDeviation(BACKUP_GENERATION_FAILED)); } return backupFile.get(); } @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 generateBackup() throws InterruptedException { SecurityServerId securityServerId = serverConfService.getSecurityServerId(); String filename = generateBackupFileName(); auditDataHelper.putBackupFilename(backupRepository.getFilePath(filename)); String fullPath = backupRepository.getConfigurationBackupPath() + filename; String[] args = new String[] {"-s", securityServerId.toShortString(), "-f", fullPath}; try { log.info("Run configuration backup with command '" + generateBackupScriptPath + " " + Arrays.toString(args) + "'"); ExternalProcessRunner.ProcessResult processResult = externalProcessRunner .executeAndThrowOnFailure(generateBackupScriptPath, args); log.info(" --- Backup script console output - START --- "); log.info(String.join("\n", processResult.getProcessOutput())); log.info(" --- Backup script console output - END --- "); } catch (ProcessNotExecutableException | ProcessFailedException e) { throw new DeviationAwareRuntimeException(e, new ErrorDeviation(BACKUP_GENERATION_FAILED)); } Optional<BackupFile> backupFile = getBackup(filename); if (!backupFile.isPresent()) { throw new DeviationAwareRuntimeException(getFileNotFoundExceptionMessage(filename), new ErrorDeviation(BACKUP_GENERATION_FAILED)); } return backupFile.get(); } @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();  }