MaintenanceResource extends JaxRsResource { @POST @ApiOperation(value = "Do maintenance on old workflow instances synchronously", response = MaintenanceResponse.class) public Response cleanupWorkflows( @ApiParam(value = "Parameters for the maintenance process", required = true) MaintenanceRequest request) { return handleExceptions(() -> { MaintenanceConfiguration configuration = converter.convert(request); MaintenanceResults results = maintenanceService.cleanupWorkflows(configuration); return ok(converter.convert(results)); }); }  @POST @ApiOperation(value = "Do maintenance on old workflow instances synchronously", response = MaintenanceResponse.class) Response cleanupWorkflows(
      @ApiParam(value = "Parameters for the maintenance process", required = true) MaintenanceRequest request);  }
@Test public void cleanupWorkflowsDelegatesToMaintenanceService() { int batchSize = 10; ReadablePeriod period1 = months(1); ReadablePeriod period2 = months(2); ReadablePeriod period3 = months(3); MaintenanceResults maintenanceResults = new MaintenanceResults.Builder() .setArchivedWorkflows(batchSize) .setDeletedArchivedWorkflows(batchSize * 2) .setDeletedWorkflows(batchSize * 3) .build(); when(service.cleanupWorkflows(any(MaintenanceConfiguration.class))).thenReturn(maintenanceResults); MaintenanceRequest request = new MaintenanceRequest(); request.archiveWorkflows = new MaintenanceRequestItem(); request.archiveWorkflows.olderThanPeriod = period1; request.archiveWorkflows.batchSize = batchSize; request.deleteArchivedWorkflows = new MaintenanceRequestItem(); request.deleteArchivedWorkflows.olderThanPeriod = period2; request.deleteArchivedWorkflows.batchSize = batchSize * 2; request.deleteWorkflows = new MaintenanceRequestItem(); request.deleteWorkflows.olderThanPeriod = period3; request.deleteWorkflows.batchSize = batchSize * 3; MaintenanceResponse response = resource.cleanupWorkflows(request).readEntity(MaintenanceResponse.class); verify(service).cleanupWorkflows(configCaptor.capture()); MaintenanceConfiguration configuration = configCaptor.getValue(); assertEquals(period1, configuration.archiveWorkflows.olderThanPeriod); assertEquals(batchSize, configuration.archiveWorkflows.batchSize); assertEquals(period2, configuration.deleteArchivedWorkflows.olderThanPeriod); assertEquals(batchSize * 2, configuration.deleteArchivedWorkflows.batchSize); assertEquals(period3, configuration.deleteWorkflows.olderThanPeriod); assertEquals(batchSize * 3, configuration.deleteWorkflows.batchSize); assertEquals(maintenanceResults.archivedWorkflows, response.archivedWorkflows); assertEquals(maintenanceResults.deletedArchivedWorkflows, response.deletedArchivedWorkflows); assertEquals(maintenanceResults.deletedWorkflows, response.deletedWorkflows); }