@Test public void test_enrolOrganization_returns_not_found_for_invalid_org() throws CloudFoundryException, BindException { String fakeOrgGuid = "fake-organization-guid"; OrgEnrollmentConfigRequest request = OrgEnrollmentConfigRequest.builder().build(); when(cloudFoundryApi.isValidOrganization(fakeOrgGuid)).thenReturn(false); ResponseEntity<?> response = autoEnrollmentController.enrolOrganization(fakeOrgGuid, request, result); assertTrue(response.getStatusCode() == HttpStatus.NOT_FOUND); }
@RequestMapping(method = RequestMethod.PUT, value = "{organizationId}") public ResponseEntity<OrgEnrollmentConfig> enrolOrganization( @PathVariable String organizationId, @Valid @RequestBody OrgEnrollmentConfigRequest orgEnrollerConfigRequest, BindingResult result) throws CloudFoundryException, BindException { log.debug("enrolOrganization - {}", organizationId); if (result.hasErrors()) { throw new BindException(result); } if (!cloudfoundryApi.isValidOrganization(organizationId)) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } if (orgEnrollmentRepository.exists(organizationId)) { HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.ALLOW, RequestMethod.PATCH.name()); return new ResponseEntity<>(headers, HttpStatus.METHOD_NOT_ALLOWED); } OrgEnrollmentConfig orgEnrollerConfig = OrgEnrollmentConfig.builder() .organizationGuid(organizationId) .idleDuration(orgEnrollerConfigRequest.getIdleDuration() == null ? null : idleDurationReader .readParameter(orgEnrollerConfigRequest.getIdleDuration(), false)) .excludeSpacesFromAutoEnrollment( orgEnrollerConfigRequest.getExcludeSpacesFromAutoEnrollment() == null ? null : excludeFromAutoEnrollmentReader .readParameter( orgEnrollerConfigRequest .getExcludeSpacesFromAutoEnrollment(), false)) .autoEnrollment(orgEnrollerConfigRequest.getAutoEnrollment() == null ? null : autoEnrollmentReader .readParameter(orgEnrollerConfigRequest.getAutoEnrollment(), false)) .state(orgEnrollerConfigRequest.getState() == null ? null : stateReader.readParameter(orgEnrollerConfigRequest.getState(), false)) .build(); orgEnrollmentRepository.save(orgEnrollerConfig); HttpHeaders headers = new HttpHeaders(); headers.add("Location", EnrollmentConfig.Path.ORG_AUTO_ENROLMENT_BASE_PATH + organizationId); return new ResponseEntity<OrgEnrollmentConfig>(orgEnrollerConfig, headers, HttpStatus.CREATED); }
AutoEnrollmentController { @RequestMapping(method = RequestMethod.PUT, value = "{organizationId}") public ResponseEntity<OrgEnrollmentConfig> enrolOrganization( @PathVariable String organizationId, @Valid @RequestBody OrgEnrollmentConfigRequest orgEnrollerConfigRequest, BindingResult result) throws CloudFoundryException, BindException { log.debug("enrolOrganization - {}", organizationId); if (result.hasErrors()) { throw new BindException(result); } if (!cloudfoundryApi.isValidOrganization(organizationId)) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } if (orgEnrollmentRepository.exists(organizationId)) { HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.ALLOW, RequestMethod.PATCH.name()); return new ResponseEntity<>(headers, HttpStatus.METHOD_NOT_ALLOWED); } OrgEnrollmentConfig orgEnrollerConfig = OrgEnrollmentConfig.builder() .organizationGuid(organizationId) .idleDuration(orgEnrollerConfigRequest.getIdleDuration() == null ? null : idleDurationReader .readParameter(orgEnrollerConfigRequest.getIdleDuration(), false)) .excludeSpacesFromAutoEnrollment( orgEnrollerConfigRequest.getExcludeSpacesFromAutoEnrollment() == null ? null : excludeFromAutoEnrollmentReader .readParameter( orgEnrollerConfigRequest .getExcludeSpacesFromAutoEnrollment(), false)) .autoEnrollment(orgEnrollerConfigRequest.getAutoEnrollment() == null ? null : autoEnrollmentReader .readParameter(orgEnrollerConfigRequest.getAutoEnrollment(), false)) .state(orgEnrollerConfigRequest.getState() == null ? null : stateReader.readParameter(orgEnrollerConfigRequest.getState(), false)) .build(); orgEnrollmentRepository.save(orgEnrollerConfig); HttpHeaders headers = new HttpHeaders(); headers.add("Location", EnrollmentConfig.Path.ORG_AUTO_ENROLMENT_BASE_PATH + organizationId); return new ResponseEntity<OrgEnrollmentConfig>(orgEnrollerConfig, headers, HttpStatus.CREATED); } }
AutoEnrollmentController { @RequestMapping(method = RequestMethod.PUT, value = "{organizationId}") public ResponseEntity<OrgEnrollmentConfig> enrolOrganization( @PathVariable String organizationId, @Valid @RequestBody OrgEnrollmentConfigRequest orgEnrollerConfigRequest, BindingResult result) throws CloudFoundryException, BindException { log.debug("enrolOrganization - {}", organizationId); if (result.hasErrors()) { throw new BindException(result); } if (!cloudfoundryApi.isValidOrganization(organizationId)) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } if (orgEnrollmentRepository.exists(organizationId)) { HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.ALLOW, RequestMethod.PATCH.name()); return new ResponseEntity<>(headers, HttpStatus.METHOD_NOT_ALLOWED); } OrgEnrollmentConfig orgEnrollerConfig = OrgEnrollmentConfig.builder() .organizationGuid(organizationId) .idleDuration(orgEnrollerConfigRequest.getIdleDuration() == null ? null : idleDurationReader .readParameter(orgEnrollerConfigRequest.getIdleDuration(), false)) .excludeSpacesFromAutoEnrollment( orgEnrollerConfigRequest.getExcludeSpacesFromAutoEnrollment() == null ? null : excludeFromAutoEnrollmentReader .readParameter( orgEnrollerConfigRequest .getExcludeSpacesFromAutoEnrollment(), false)) .autoEnrollment(orgEnrollerConfigRequest.getAutoEnrollment() == null ? null : autoEnrollmentReader .readParameter(orgEnrollerConfigRequest.getAutoEnrollment(), false)) .state(orgEnrollerConfigRequest.getState() == null ? null : stateReader.readParameter(orgEnrollerConfigRequest.getState(), false)) .build(); orgEnrollmentRepository.save(orgEnrollerConfig); HttpHeaders headers = new HttpHeaders(); headers.add("Location", EnrollmentConfig.Path.ORG_AUTO_ENROLMENT_BASE_PATH + organizationId); return new ResponseEntity<OrgEnrollmentConfig>(orgEnrollerConfig, headers, HttpStatus.CREATED); }  }
AutoEnrollmentController { @RequestMapping(method = RequestMethod.PUT, value = "{organizationId}") public ResponseEntity<OrgEnrollmentConfig> enrolOrganization( @PathVariable String organizationId, @Valid @RequestBody OrgEnrollmentConfigRequest orgEnrollerConfigRequest, BindingResult result) throws CloudFoundryException, BindException { log.debug("enrolOrganization - {}", organizationId); if (result.hasErrors()) { throw new BindException(result); } if (!cloudfoundryApi.isValidOrganization(organizationId)) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } if (orgEnrollmentRepository.exists(organizationId)) { HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.ALLOW, RequestMethod.PATCH.name()); return new ResponseEntity<>(headers, HttpStatus.METHOD_NOT_ALLOWED); } OrgEnrollmentConfig orgEnrollerConfig = OrgEnrollmentConfig.builder() .organizationGuid(organizationId) .idleDuration(orgEnrollerConfigRequest.getIdleDuration() == null ? null : idleDurationReader .readParameter(orgEnrollerConfigRequest.getIdleDuration(), false)) .excludeSpacesFromAutoEnrollment( orgEnrollerConfigRequest.getExcludeSpacesFromAutoEnrollment() == null ? null : excludeFromAutoEnrollmentReader .readParameter( orgEnrollerConfigRequest .getExcludeSpacesFromAutoEnrollment(), false)) .autoEnrollment(orgEnrollerConfigRequest.getAutoEnrollment() == null ? null : autoEnrollmentReader .readParameter(orgEnrollerConfigRequest.getAutoEnrollment(), false)) .state(orgEnrollerConfigRequest.getState() == null ? null : stateReader.readParameter(orgEnrollerConfigRequest.getState(), false)) .build(); orgEnrollmentRepository.save(orgEnrollerConfig); HttpHeaders headers = new HttpHeaders(); headers.add("Location", EnrollmentConfig.Path.ORG_AUTO_ENROLMENT_BASE_PATH + organizationId); return new ResponseEntity<OrgEnrollmentConfig>(orgEnrollerConfig, headers, HttpStatus.CREATED); }  @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.PUT, value = "{organizationId}") public ResponseEntity<OrgEnrollmentConfig> enrolOrganization( @PathVariable String organizationId, @Valid @RequestBody OrgEnrollmentConfigRequest orgEnrollerConfigRequest, BindingResult result) throws CloudFoundryException, BindException { log.debug("enrolOrganization - {}", organizationId); if (result.hasErrors()) { throw new BindException(result); } if (!cloudfoundryApi.isValidOrganization(organizationId)) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } if (orgEnrollmentRepository.exists(organizationId)) { HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.ALLOW, RequestMethod.PATCH.name()); return new ResponseEntity<>(headers, HttpStatus.METHOD_NOT_ALLOWED); } OrgEnrollmentConfig orgEnrollerConfig = OrgEnrollmentConfig.builder() .organizationGuid(organizationId) .idleDuration(orgEnrollerConfigRequest.getIdleDuration() == null ? null : idleDurationReader .readParameter(orgEnrollerConfigRequest.getIdleDuration(), false)) .excludeSpacesFromAutoEnrollment( orgEnrollerConfigRequest.getExcludeSpacesFromAutoEnrollment() == null ? null : excludeFromAutoEnrollmentReader .readParameter( orgEnrollerConfigRequest .getExcludeSpacesFromAutoEnrollment(), false)) .autoEnrollment(orgEnrollerConfigRequest.getAutoEnrollment() == null ? null : autoEnrollmentReader .readParameter(orgEnrollerConfigRequest.getAutoEnrollment(), false)) .state(orgEnrollerConfigRequest.getState() == null ? null : stateReader.readParameter(orgEnrollerConfigRequest.getState(), false)) .build(); orgEnrollmentRepository.save(orgEnrollerConfig); HttpHeaders headers = new HttpHeaders(); headers.add("Location", EnrollmentConfig.Path.ORG_AUTO_ENROLMENT_BASE_PATH + organizationId); return new ResponseEntity<OrgEnrollmentConfig>(orgEnrollerConfig, headers, HttpStatus.CREATED); }  @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);  }