Skip to content

Commit

Permalink
Remove remaining references to ServiceInstance and ServiceInstanceBin…
Browse files Browse the repository at this point in the history
…ding, and mark those classes deprecated.
  • Loading branch information
scottfrederick committed Dec 9, 2015
1 parent ea65115 commit c02adab
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public ResponseEntity<ErrorMessage> handleException(ServiceBrokerApiVersionExcep
return getErrorResponse(ex.getMessage(), HttpStatus.PRECONDITION_FAILED);
}

@ExceptionHandler(ServiceInstanceDoesNotExistException.class)
public ResponseEntity<ErrorMessage> handleException(ServiceInstanceDoesNotExistException ex) {
return getErrorResponse(ex.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY);
}

@ExceptionHandler(ServiceDefinitionDoesNotExistException.class)
public ResponseEntity<ErrorMessage> handleException(ServiceDefinitionDoesNotExistException ex) {
return getErrorResponse(ex.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY);
}

@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseBody
public ResponseEntity<ErrorMessage> handleException(HttpMessageNotReadableException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.cloudfoundry.community.servicebroker.model.*;
import org.cloudfoundry.community.servicebroker.service.CatalogService;
import org.cloudfoundry.community.servicebroker.service.ServiceInstanceBindingService;
import org.cloudfoundry.community.servicebroker.service.ServiceInstanceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -32,15 +31,12 @@ public class ServiceInstanceBindingController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(ServiceInstanceBindingController.class);

private ServiceInstanceBindingService serviceInstanceBindingService;
private ServiceInstanceService serviceInstanceService;


@Autowired
public ServiceInstanceBindingController(CatalogService catalogService,
ServiceInstanceService serviceInstanceService,
ServiceInstanceBindingService serviceInstanceBindingService) {
super(catalogService);
this.serviceInstanceBindingService = serviceInstanceBindingService;
this.serviceInstanceService = serviceInstanceService;
}

@RequestMapping(method = RequestMethod.PUT)
Expand All @@ -54,18 +50,15 @@ public ResponseEntity<?> createServiceInstanceBinding(
+ "serviceInstanceId=" + serviceInstanceId
+ ", bindingId=" + bindingId);

ServiceInstance instance = serviceInstanceService.getServiceInstance(serviceInstanceId);
if (instance == null) {
throw new ServiceInstanceDoesNotExistException(serviceInstanceId);
}

request.withServiceInstanceId(serviceInstanceId)
.withBindingId(bindingId)
.withServiceDefinition(getServiceDefinition(request.getServiceDefinitionId()));

CreateServiceInstanceBindingResponse response = serviceInstanceBindingService.createServiceInstanceBinding(request);

logger.debug("createServiceInstanceBinding(): succeeded: bindingId=" + bindingId);
logger.debug("createServiceInstanceBinding(): succeeded: "
+ "serviceInstanceId=" + serviceInstanceId
+ "bindingId=" + bindingId);

return new ResponseEntity<>(response, HttpStatus.CREATED);
}
Expand All @@ -84,11 +77,6 @@ public ResponseEntity<String> deleteServiceInstanceBinding(
+ ", serviceDefinitionId=" + serviceDefinitionId
+ ", planId=" + planId);

ServiceInstance instance = serviceInstanceService.getServiceInstance(serviceInstanceId);
if (instance == null) {
throw new ServiceInstanceDoesNotExistException(serviceInstanceId);
}

try {
DeleteServiceInstanceBindingRequest request =
new DeleteServiceInstanceBindingRequest(serviceInstanceId, bindingId, serviceDefinitionId, planId,
Expand All @@ -104,11 +92,6 @@ public ResponseEntity<String> deleteServiceInstanceBinding(
return new ResponseEntity<>("{}", HttpStatus.OK);
}

@ExceptionHandler(ServiceInstanceDoesNotExistException.class)
public ResponseEntity<ErrorMessage> handleException(ServiceInstanceDoesNotExistException ex) {
return getErrorResponse(ex.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY);
}

@ExceptionHandler(ServiceInstanceBindingExistsException.class)
public ResponseEntity<ErrorMessage> handleException(ServiceInstanceBindingExistsException ex) {
return getErrorResponse(ex.getMessage(), HttpStatus.CONFLICT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,6 @@ public ResponseEntity<String> updateServiceInstance(
return new ResponseEntity<>("{}", response.isAsync() ? HttpStatus.ACCEPTED : HttpStatus.OK);
}

@ExceptionHandler(ServiceInstanceDoesNotExistException.class)
public ResponseEntity<ErrorMessage> handleException(ServiceInstanceDoesNotExistException ex) {
return getErrorResponse(ex.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY);
}

@ExceptionHandler(ServiceDefinitionDoesNotExistException.class)
public ResponseEntity<ErrorMessage> handleException(ServiceDefinitionDoesNotExistException ex) {
return getErrorResponse(ex.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY);
}

@ExceptionHandler(ServiceInstanceExistsException.class)
public ResponseEntity<ErrorMessage> handleException(ServiceInstanceExistsException ex) {
return getErrorResponse(ex.getMessage(), HttpStatus.CONFLICT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*
* @author sgreenberg@gopivotal.com
*
* @deprecated This class is no longer used internally to represent service instances. Implementing brokers should
* create their own class to represent service instances and persist them as necessary. The will remain in the project
* for a time as a convenience, but it should no longer be used by implementing brokers.
*/
@JsonAutoDetect(getterVisibility = JsonAutoDetect.Visibility.NONE)
public class ServiceInstance {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
*
* @author sgreenberg@gopivotal.com
*
* @deprecated This class is no longer used internally to represent service instance bindings. Implementing brokers should
* create their own class to represent service instances bindings and persist them as necessary. The will remain in the project
* for a time as a convenience, but it should no longer be used by implementing brokers.
*/
public class ServiceInstanceBinding {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ public interface ServiceInstanceBindingService {
* @param request containing parameters sent from Cloud Controller
* @return a CreateServiceInstanceBindingResponse
* @throws ServiceInstanceBindingExistsException if the same binding already exists
* @throws ServiceInstanceDoesNotExistException if the service instance ID is not valid
* @throws ServiceBrokerException on internal failure
*/
CreateServiceInstanceBindingResponse createServiceInstanceBinding(CreateServiceInstanceBindingRequest request)
throws ServiceInstanceBindingExistsException, ServiceBrokerException;
throws ServiceInstanceBindingExistsException, ServiceInstanceDoesNotExistException, ServiceBrokerException;

/**
* Delete the service instance binding.
Expand All @@ -30,5 +31,5 @@ CreateServiceInstanceBindingResponse createServiceInstanceBinding(CreateServiceI
* @throws ServiceInstanceBindingDoesNotExistException if the service instance binding ID is not valid
*/
void deleteServiceInstanceBinding(DeleteServiceInstanceBindingRequest request)
throws ServiceBrokerException, ServiceInstanceDoesNotExistException, ServiceInstanceBindingDoesNotExistException;
throws ServiceInstanceDoesNotExistException, ServiceInstanceBindingDoesNotExistException, ServiceBrokerException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ public interface ServiceInstanceService {
*/
CreateServiceInstanceResponse createServiceInstance(CreateServiceInstanceRequest request)
throws ServiceInstanceExistsException, ServiceBrokerException, ServiceBrokerAsyncRequiredException;

/**
* @param serviceInstanceId The id of the serviceInstance
* @return The ServiceInstance with the given id or null if one does not exist
*/
ServiceInstance getServiceInstance(String serviceInstanceId);

/**
* @param request containing the parameters from Cloud Controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import org.cloudfoundry.community.servicebroker.model.CreateServiceInstanceBindingRequest;
import org.cloudfoundry.community.servicebroker.model.CreateServiceInstanceBindingResponse;
import org.cloudfoundry.community.servicebroker.model.DeleteServiceInstanceBindingRequest;
import org.cloudfoundry.community.servicebroker.model.ServiceInstance;
import org.cloudfoundry.community.servicebroker.model.fixture.ServiceInstanceFixture;
import org.cloudfoundry.community.servicebroker.service.ServiceInstanceBindingService;
import org.cloudfoundry.community.servicebroker.service.ServiceInstanceService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -50,9 +47,6 @@ public class ServiceInstanceBindingControllerIntegrationTest extends ControllerI
@Mock
private ServiceInstanceBindingService serviceInstanceBindingService;

@Mock
private ServiceInstanceService serviceInstanceService;

private UriComponentsBuilder uriBuilder;

private CreateServiceInstanceBindingRequest createRequest;
Expand All @@ -66,7 +60,7 @@ public void setup() {
.setMessageConverters(new MappingJackson2HttpMessageConverter()).build();

uriBuilder = UriComponentsBuilder.fromPath("/v2/service_instances/")
.pathSegment(ServiceInstanceFixture.getServiceInstance().getServiceInstanceId(), "service_bindings");
.pathSegment("service-instance-one-id", "service_bindings");

createRequest = buildCreateServiceInstanceBindingRequest();
createResponse = buildCreateServiceInstanceBindingResponse();
Expand All @@ -76,11 +70,6 @@ public void setup() {

@Test
public void createBindingSucceeds() throws Exception {
ServiceInstance instance = ServiceInstanceFixture.getServiceInstance();

when(serviceInstanceService.getServiceInstance(eq(createRequest.getServiceInstanceId())))
.thenReturn(instance);

when(serviceInstanceBindingService.createServiceInstanceBinding(eq(createRequest)))
.thenReturn(createResponse);

Expand All @@ -99,11 +88,6 @@ public void createBindingSucceeds() throws Exception {

@Test
public void createBindingWithoutSyslogDrainUrlSucceeds() throws Exception {
ServiceInstance instance = ServiceInstanceFixture.getServiceInstance();

when(serviceInstanceService.getServiceInstance(eq(createRequest.getServiceInstanceId())))
.thenReturn(instance);

CreateServiceInstanceBindingResponse response = buildCreateServiceInstanceBindingResponseWithoutSyslog();
when(serviceInstanceBindingService.createServiceInstanceBinding(eq(createRequest)))
.thenReturn(response);
Expand All @@ -122,9 +106,11 @@ public void createBindingWithoutSyslogDrainUrlSucceeds() throws Exception {
}

@Test
public void createBindingWithUnknownIdFails() throws Exception {
when(serviceInstanceService.getServiceInstance(eq(createRequest.getServiceInstanceId())))
.thenReturn(null);
public void createBindingWithUnknownServiceInstanceIdFails() throws Exception {
when(serviceInstanceBindingService.createServiceInstanceBinding(eq(createRequest)))
.thenThrow(new ServiceInstanceDoesNotExistException(createRequest.getServiceInstanceId()));

setupCatalogService(createRequest.getServiceDefinitionId());

mockMvc.perform(put(buildUrl(createRequest))
.content(toJson(createRequest))
Expand All @@ -135,12 +121,23 @@ public void createBindingWithUnknownIdFails() throws Exception {
}

@Test
public void createBindingWithDuplicateIdFails() throws Exception {
ServiceInstance instance = ServiceInstanceFixture.getServiceInstance();
public void createBindingWithUnknownServiceDefinitionIdFails() throws Exception {
when(serviceInstanceBindingService.createServiceInstanceBinding(eq(createRequest)))
.thenReturn(createResponse);

when(serviceInstanceService.getServiceInstance(eq(createRequest.getServiceInstanceId())))
.thenReturn(instance);
when(catalogService.getServiceDefinition(eq(createRequest.getServiceDefinitionId())))
.thenReturn(null);

mockMvc.perform(put(buildUrl(createRequest))
.content(toJson(createRequest))
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isUnprocessableEntity())
.andExpect(jsonPath("$.description", containsString(createRequest.getServiceDefinitionId())));
}

@Test
public void createBindingWithDuplicateIdFails() throws Exception {
when(serviceInstanceBindingService.createServiceInstanceBinding(eq(createRequest)))
.thenThrow(new ServiceInstanceBindingExistsException(createRequest.getServiceInstanceId(), createRequest.getBindingId()));

Expand Down Expand Up @@ -182,14 +179,9 @@ public void createBindingWithMissingFieldsFails() throws Exception {

@Test
public void deleteBindingSucceeds() throws Exception {
ServiceInstance instance = ServiceInstanceFixture.getServiceInstance();

when(serviceInstanceService.getServiceInstance(eq(deleteRequest.getServiceInstanceId())))
.thenReturn(instance);

setupCatalogService(deleteRequest.getServiceDefinitionId());

mockMvc.perform(delete(buildUrl(deleteRequest, instance))
mockMvc.perform(delete(buildUrl(deleteRequest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$", is("{}")));
Expand All @@ -199,48 +191,52 @@ public void deleteBindingSucceeds() throws Exception {

@Test
public void deleteBindingWithUnknownInstanceIdFails() throws Exception {
ServiceInstance instance = ServiceInstanceFixture.getServiceInstance();

when(serviceInstanceService.getServiceInstance(eq(deleteRequest.getServiceInstanceId())))
.thenReturn(instance);

doThrow(new ServiceInstanceDoesNotExistException(deleteRequest.getServiceInstanceId()))
.when(serviceInstanceBindingService).deleteServiceInstanceBinding(eq(deleteRequest));

setupCatalogService(deleteRequest.getServiceDefinitionId());

mockMvc.perform(delete(buildUrl(deleteRequest, instance))
mockMvc.perform(delete(buildUrl(deleteRequest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isUnprocessableEntity())
.andExpect(jsonPath("$.description", containsString(deleteRequest.getServiceInstanceId())));
}

@Test
public void deleteBindingWithUnknownBindingIdFails() throws Exception {
ServiceInstance instance = ServiceInstanceFixture.getServiceInstance();

when(serviceInstanceService.getServiceInstance(eq(deleteRequest.getServiceInstanceId())))
.thenReturn(instance);

doThrow(new ServiceInstanceBindingDoesNotExistException(deleteRequest.getBindingId()))
.when(serviceInstanceBindingService).deleteServiceInstanceBinding(eq(deleteRequest));

setupCatalogService(deleteRequest.getServiceDefinitionId());

mockMvc.perform(delete(buildUrl(deleteRequest, instance))
mockMvc.perform(delete(buildUrl(deleteRequest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isGone())
.andExpect(jsonPath("$", is("{}")));
}

@Test
public void deleteBindingWithUnknownServiceDefinitionIdFails() throws Exception {
doThrow(new ServiceInstanceDoesNotExistException(deleteRequest.getServiceInstanceId()))
.when(serviceInstanceBindingService).deleteServiceInstanceBinding(eq(deleteRequest));

when(catalogService.getServiceDefinition(eq(deleteRequest.getServiceDefinitionId())))
.thenReturn(null);

mockMvc.perform(delete(buildUrl(deleteRequest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isUnprocessableEntity())
.andExpect(jsonPath("$.description", containsString(deleteRequest.getServiceDefinitionId())));
}

private String buildUrl(CreateServiceInstanceBindingRequest request) {
return uriBuilder.path(request.getBindingId()).toUriString();
}

private String buildUrl(DeleteServiceInstanceBindingRequest request, ServiceInstance instance) {
private String buildUrl(DeleteServiceInstanceBindingRequest request) {
return uriBuilder.path(request.getBindingId())
.queryParam("service_id", instance.getServiceDefinitionId())
.queryParam("plan_id", instance.getPlanId())
.queryParam("service_id", request.getServiceDefinitionId())
.queryParam("plan_id", request.getPlanId())
.toUriString();
}
}
Loading

0 comments on commit c02adab

Please sign in to comment.