@Test @WithMockUser(authorities = { "BACKUP_CONFIGURATION" }) public void downloadBackup() throws Exception { byte[] bytes = "teststring".getBytes(StandardCharsets.UTF_8); when(backupService.readBackupFile(BACKUP_FILE_1_NAME)).thenReturn(bytes); ResponseEntity<Resource> response = backupsApiController .downloadBackup(BACKUP_FILE_1_NAME); Resource backup = response.getBody(); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals(bytes.length, backup.contentLength()); }
@Override @PreAuthorize("hasAuthority('BACKUP_CONFIGURATION')") public ResponseEntity<Resource> downloadBackup(String filename) { byte[] backupFile = null; try { backupFile = backupService.readBackupFile(filename); } catch (BackupFileNotFoundException e) { throw new ResourceNotFoundException(e); } return ApiUtil.createAttachmentResourceResponse(backupFile, filename); }
BackupsApiController implements BackupsApi { @Override @PreAuthorize("hasAuthority('BACKUP_CONFIGURATION')") public ResponseEntity<Resource> downloadBackup(String filename) { byte[] backupFile = null; try { backupFile = backupService.readBackupFile(filename); } catch (BackupFileNotFoundException e) { throw new ResourceNotFoundException(e); } return ApiUtil.createAttachmentResourceResponse(backupFile, filename); } }
BackupsApiController implements BackupsApi { @Override @PreAuthorize("hasAuthority('BACKUP_CONFIGURATION')") public ResponseEntity<Resource> downloadBackup(String filename) { byte[] backupFile = null; try { backupFile = backupService.readBackupFile(filename); } catch (BackupFileNotFoundException e) { throw new ResourceNotFoundException(e); } return ApiUtil.createAttachmentResourceResponse(backupFile, filename); } @Autowired  BackupsApiController(BackupService backupService,
            RestoreService restoreService, BackupConverter backupConverter,
            TokenService tokenService); }
BackupsApiController implements BackupsApi { @Override @PreAuthorize("hasAuthority('BACKUP_CONFIGURATION')") public ResponseEntity<Resource> downloadBackup(String filename) { byte[] backupFile = null; try { backupFile = backupService.readBackupFile(filename); } catch (BackupFileNotFoundException e) { throw new ResourceNotFoundException(e); } return ApiUtil.createAttachmentResourceResponse(backupFile, filename); } @Autowired  BackupsApiController(BackupService backupService,
            RestoreService restoreService, BackupConverter backupConverter,
            TokenService tokenService); @Override @PreAuthorize("hasAuthority('BACKUP_CONFIGURATION')") ResponseEntity<List<Backup>> getBackups(); @Override @PreAuthorize("hasAuthority('BACKUP_CONFIGURATION')") @AuditEventMethod(event = DELETE_BACKUP) ResponseEntity<Void> deleteBackup(String filename); @Override @PreAuthorize("hasAuthority('BACKUP_CONFIGURATION')") ResponseEntity<Resource> downloadBackup(String filename); @Override @PreAuthorize("hasAuthority('BACKUP_CONFIGURATION')") @AuditEventMethod(event = BACKUP) ResponseEntity<Backup> addBackup(); @Override @PreAuthorize("hasAuthority('BACKUP_CONFIGURATION')") @AuditEventMethod(event = UPLOAD_BACKUP) ResponseEntity<Backup> uploadBackup(Boolean ignoreWarnings, MultipartFile file); @Override @PreAuthorize("hasAuthority('RESTORE_CONFIGURATION')") @AuditEventMethod(event = RESTORE_BACKUP) synchronized ResponseEntity<TokensLoggedOut> restoreBackup(String filename); }
BackupsApiController implements BackupsApi { @Override @PreAuthorize("hasAuthority('BACKUP_CONFIGURATION')") public ResponseEntity<Resource> downloadBackup(String filename) { byte[] backupFile = null; try { backupFile = backupService.readBackupFile(filename); } catch (BackupFileNotFoundException e) { throw new ResourceNotFoundException(e); } return ApiUtil.createAttachmentResourceResponse(backupFile, filename); } @Autowired  BackupsApiController(BackupService backupService,
            RestoreService restoreService, BackupConverter backupConverter,
            TokenService tokenService); @Override @PreAuthorize("hasAuthority('BACKUP_CONFIGURATION')") ResponseEntity<List<Backup>> getBackups(); @Override @PreAuthorize("hasAuthority('BACKUP_CONFIGURATION')") @AuditEventMethod(event = DELETE_BACKUP) ResponseEntity<Void> deleteBackup(String filename); @Override @PreAuthorize("hasAuthority('BACKUP_CONFIGURATION')") ResponseEntity<Resource> downloadBackup(String filename); @Override @PreAuthorize("hasAuthority('BACKUP_CONFIGURATION')") @AuditEventMethod(event = BACKUP) ResponseEntity<Backup> addBackup(); @Override @PreAuthorize("hasAuthority('BACKUP_CONFIGURATION')") @AuditEventMethod(event = UPLOAD_BACKUP) ResponseEntity<Backup> uploadBackup(Boolean ignoreWarnings, MultipartFile file); @Override @PreAuthorize("hasAuthority('RESTORE_CONFIGURATION')") @AuditEventMethod(event = RESTORE_BACKUP) synchronized ResponseEntity<TokensLoggedOut> restoreBackup(String filename); static final String GENERATE_BACKUP_INTERRUPTED; static final String RESTORE_INTERRUPTED; }