@Test public void test_deleteOrganization_ok() throws CloudFoundryException { String fakeOrgGuid = "fake-organization-guid"; OrgEnrollmentConfig orgConfig = OrgEnrollmentConfig.builder().organizationGuid(fakeOrgGuid) .state(EnrollmentState.enrolled).build(); when(orgEnrollmentConfigRepository.findOne(fakeOrgGuid)).thenReturn(orgConfig); ResponseEntity<OrgEnrollmentConfig> response = autoEnrollmentController .deleteOrganization(fakeOrgGuid); assertTrue(response.getStatusCode() == HttpStatus.OK); verify(orgEnrollmentConfigRepository, times(1)).save(any(OrgEnrollmentConfig.class)); assertTrue(orgConfig .getState() == EnrollmentState.backoffice_opted_out); }
@RequestMapping(method = RequestMethod.DELETE, value = "/{organizationId}") public ResponseEntity<OrgEnrollmentConfig> deleteOrganization( @PathVariable String organizationId) { log.debug("deleteEnrolledOrganization - {}", organizationId); OrgEnrollmentConfig orgConfig = orgEnrollmentRepository.findOne(organizationId); if (orgConfig == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } orgConfig.setState( EnrollmentConfig.EnrollmentParameters.EnrollmentState.backoffice_opted_out); orgConfig = orgEnrollmentRepository.save(orgConfig); return new ResponseEntity<OrgEnrollmentConfig>(orgConfig, HttpStatus.OK); }
AutoEnrollmentController { @RequestMapping(method = RequestMethod.DELETE, value = "/{organizationId}") public ResponseEntity<OrgEnrollmentConfig> deleteOrganization( @PathVariable String organizationId) { log.debug("deleteEnrolledOrganization - {}", organizationId); OrgEnrollmentConfig orgConfig = orgEnrollmentRepository.findOne(organizationId); if (orgConfig == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } orgConfig.setState( EnrollmentConfig.EnrollmentParameters.EnrollmentState.backoffice_opted_out); orgConfig = orgEnrollmentRepository.save(orgConfig); return new ResponseEntity<OrgEnrollmentConfig>(orgConfig, HttpStatus.OK); } }
AutoEnrollmentController { @RequestMapping(method = RequestMethod.DELETE, value = "/{organizationId}") public ResponseEntity<OrgEnrollmentConfig> deleteOrganization( @PathVariable String organizationId) { log.debug("deleteEnrolledOrganization - {}", organizationId); OrgEnrollmentConfig orgConfig = orgEnrollmentRepository.findOne(organizationId); if (orgConfig == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } orgConfig.setState( EnrollmentConfig.EnrollmentParameters.EnrollmentState.backoffice_opted_out); orgConfig = orgEnrollmentRepository.save(orgConfig); return new ResponseEntity<OrgEnrollmentConfig>(orgConfig, HttpStatus.OK); }  }
AutoEnrollmentController { @RequestMapping(method = RequestMethod.DELETE, value = "/{organizationId}") public ResponseEntity<OrgEnrollmentConfig> deleteOrganization( @PathVariable String organizationId) { log.debug("deleteEnrolledOrganization - {}", organizationId); OrgEnrollmentConfig orgConfig = orgEnrollmentRepository.findOne(organizationId); if (orgConfig == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } orgConfig.setState( EnrollmentConfig.EnrollmentParameters.EnrollmentState.backoffice_opted_out); orgConfig = orgEnrollmentRepository.save(orgConfig); return new ResponseEntity<OrgEnrollmentConfig>(orgConfig, HttpStatus.OK); }  @RequestMapping(method = RequestMethod.GET, value = "/{organizationId}") ResponseEntity<OrgEnrollmentConfig> getEnrolledOrganization(
            @PathVariable String organizationId); @RequestMapping(method = RequestMethod.DELETE, value = "/{organizationId}") ResponseEntity<OrgEnrollmentConfig> deleteOrganization(
            @PathVariable String organizationId); @RequestMapping(method = RequestMethod.PUT, value = "{organizationId}") ResponseEntity<OrgEnrollmentConfig> enrolOrganization(
            @PathVariable String organizationId,
            @Valid @RequestBody OrgEnrollmentConfigRequest orgEnrollerConfigRequest,
            BindingResult result); @InitBinder void initBinder(WebDataBinder binder); @ExceptionHandler({ CloudFoundryException.class }) ResponseEntity<Object> handleCloudFoundryException(CloudFoundryException cfe,
            HttpServletResponse response); @ExceptionHandler({ BindException.class }) ResponseEntity<List<ObjectError>> handleBindException(BindException be,
            HttpServletResponse response); }
AutoEnrollmentController { @RequestMapping(method = RequestMethod.DELETE, value = "/{organizationId}") public ResponseEntity<OrgEnrollmentConfig> deleteOrganization( @PathVariable String organizationId) { log.debug("deleteEnrolledOrganization - {}", organizationId); OrgEnrollmentConfig orgConfig = orgEnrollmentRepository.findOne(organizationId); if (orgConfig == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } orgConfig.setState( EnrollmentConfig.EnrollmentParameters.EnrollmentState.backoffice_opted_out); orgConfig = orgEnrollmentRepository.save(orgConfig); return new ResponseEntity<OrgEnrollmentConfig>(orgConfig, HttpStatus.OK); }  @RequestMapping(method = RequestMethod.GET, value = "/{organizationId}") ResponseEntity<OrgEnrollmentConfig> getEnrolledOrganization(
            @PathVariable String organizationId); @RequestMapping(method = RequestMethod.DELETE, value = "/{organizationId}") ResponseEntity<OrgEnrollmentConfig> deleteOrganization(
            @PathVariable String organizationId); @RequestMapping(method = RequestMethod.PUT, value = "{organizationId}") ResponseEntity<OrgEnrollmentConfig> enrolOrganization(
            @PathVariable String organizationId,
            @Valid @RequestBody OrgEnrollmentConfigRequest orgEnrollerConfigRequest,
            BindingResult result); @InitBinder void initBinder(WebDataBinder binder); @ExceptionHandler({ CloudFoundryException.class }) ResponseEntity<Object> handleCloudFoundryException(CloudFoundryException cfe,
            HttpServletResponse response); @ExceptionHandler({ BindException.class }) ResponseEntity<List<ObjectError>> handleBindException(BindException be,
            HttpServletResponse response);  }