From c02adab00c021813aa0d6bbb0b4609746dd2759f Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Wed, 9 Dec 2015 15:27:03 -0600 Subject: [PATCH] Remove remaining references to ServiceInstance and ServiceInstanceBinding, and mark those classes deprecated. --- .../controller/BaseController.java | 10 +++ .../ServiceInstanceBindingController.java | 25 +----- .../controller/ServiceInstanceController.java | 10 --- .../servicebroker/model/ServiceInstance.java | 3 + .../model/ServiceInstanceBinding.java | 3 + .../ServiceInstanceBindingService.java | 5 +- .../service/ServiceInstanceService.java | 6 -- ...tanceBindingControllerIntegrationTest.java | 86 +++++++++---------- ...viceInstanceControllerIntegrationTest.java | 37 +++++++- .../ServiceInstanceBindingFixture.java | 28 +++--- .../model/fixture/ServiceInstanceFixture.java | 12 --- 11 files changed, 108 insertions(+), 117 deletions(-) diff --git a/src/main/java/org/cloudfoundry/community/servicebroker/controller/BaseController.java b/src/main/java/org/cloudfoundry/community/servicebroker/controller/BaseController.java index 5f943d2..219b3cd 100644 --- a/src/main/java/org/cloudfoundry/community/servicebroker/controller/BaseController.java +++ b/src/main/java/org/cloudfoundry/community/servicebroker/controller/BaseController.java @@ -40,6 +40,16 @@ public ResponseEntity handleException(ServiceBrokerApiVersionExcep return getErrorResponse(ex.getMessage(), HttpStatus.PRECONDITION_FAILED); } + @ExceptionHandler(ServiceInstanceDoesNotExistException.class) + public ResponseEntity handleException(ServiceInstanceDoesNotExistException ex) { + return getErrorResponse(ex.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY); + } + + @ExceptionHandler(ServiceDefinitionDoesNotExistException.class) + public ResponseEntity handleException(ServiceDefinitionDoesNotExistException ex) { + return getErrorResponse(ex.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY); + } + @ExceptionHandler(HttpMessageNotReadableException.class) @ResponseBody public ResponseEntity handleException(HttpMessageNotReadableException ex) { diff --git a/src/main/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceBindingController.java b/src/main/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceBindingController.java index 3bb3524..1c8d0ce 100644 --- a/src/main/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceBindingController.java +++ b/src/main/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceBindingController.java @@ -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; @@ -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) @@ -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); } @@ -84,11 +77,6 @@ public ResponseEntity 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, @@ -104,11 +92,6 @@ public ResponseEntity deleteServiceInstanceBinding( return new ResponseEntity<>("{}", HttpStatus.OK); } - @ExceptionHandler(ServiceInstanceDoesNotExistException.class) - public ResponseEntity handleException(ServiceInstanceDoesNotExistException ex) { - return getErrorResponse(ex.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY); - } - @ExceptionHandler(ServiceInstanceBindingExistsException.class) public ResponseEntity handleException(ServiceInstanceBindingExistsException ex) { return getErrorResponse(ex.getMessage(), HttpStatus.CONFLICT); diff --git a/src/main/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceController.java b/src/main/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceController.java index 68f2f3c..b58bf5f 100644 --- a/src/main/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceController.java +++ b/src/main/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceController.java @@ -149,16 +149,6 @@ public ResponseEntity updateServiceInstance( return new ResponseEntity<>("{}", response.isAsync() ? HttpStatus.ACCEPTED : HttpStatus.OK); } - @ExceptionHandler(ServiceInstanceDoesNotExistException.class) - public ResponseEntity handleException(ServiceInstanceDoesNotExistException ex) { - return getErrorResponse(ex.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY); - } - - @ExceptionHandler(ServiceDefinitionDoesNotExistException.class) - public ResponseEntity handleException(ServiceDefinitionDoesNotExistException ex) { - return getErrorResponse(ex.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY); - } - @ExceptionHandler(ServiceInstanceExistsException.class) public ResponseEntity handleException(ServiceInstanceExistsException ex) { return getErrorResponse(ex.getMessage(), HttpStatus.CONFLICT); diff --git a/src/main/java/org/cloudfoundry/community/servicebroker/model/ServiceInstance.java b/src/main/java/org/cloudfoundry/community/servicebroker/model/ServiceInstance.java index 3e3ce6b..be5ad7c 100644 --- a/src/main/java/org/cloudfoundry/community/servicebroker/model/ServiceInstance.java +++ b/src/main/java/org/cloudfoundry/community/servicebroker/model/ServiceInstance.java @@ -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 { diff --git a/src/main/java/org/cloudfoundry/community/servicebroker/model/ServiceInstanceBinding.java b/src/main/java/org/cloudfoundry/community/servicebroker/model/ServiceInstanceBinding.java index c8f6bb4..8f3f7ec 100644 --- a/src/main/java/org/cloudfoundry/community/servicebroker/model/ServiceInstanceBinding.java +++ b/src/main/java/org/cloudfoundry/community/servicebroker/model/ServiceInstanceBinding.java @@ -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 { diff --git a/src/main/java/org/cloudfoundry/community/servicebroker/service/ServiceInstanceBindingService.java b/src/main/java/org/cloudfoundry/community/servicebroker/service/ServiceInstanceBindingService.java index b0f0af3..eb9fc26 100644 --- a/src/main/java/org/cloudfoundry/community/servicebroker/service/ServiceInstanceBindingService.java +++ b/src/main/java/org/cloudfoundry/community/servicebroker/service/ServiceInstanceBindingService.java @@ -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. @@ -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; } diff --git a/src/main/java/org/cloudfoundry/community/servicebroker/service/ServiceInstanceService.java b/src/main/java/org/cloudfoundry/community/servicebroker/service/ServiceInstanceService.java index f862e41..874d2c5 100644 --- a/src/main/java/org/cloudfoundry/community/servicebroker/service/ServiceInstanceService.java +++ b/src/main/java/org/cloudfoundry/community/servicebroker/service/ServiceInstanceService.java @@ -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 diff --git a/src/test/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceBindingControllerIntegrationTest.java b/src/test/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceBindingControllerIntegrationTest.java index 1191f44..a5543f6 100644 --- a/src/test/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceBindingControllerIntegrationTest.java +++ b/src/test/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceBindingControllerIntegrationTest.java @@ -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; @@ -50,9 +47,6 @@ public class ServiceInstanceBindingControllerIntegrationTest extends ControllerI @Mock private ServiceInstanceBindingService serviceInstanceBindingService; - @Mock - private ServiceInstanceService serviceInstanceService; - private UriComponentsBuilder uriBuilder; private CreateServiceInstanceBindingRequest createRequest; @@ -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(); @@ -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); @@ -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); @@ -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)) @@ -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())); @@ -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("{}"))); @@ -199,17 +191,12 @@ 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()))); @@ -217,30 +204,39 @@ public void deleteBindingWithUnknownInstanceIdFails() throws Exception { @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(); } } diff --git a/src/test/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceControllerIntegrationTest.java b/src/test/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceControllerIntegrationTest.java index a098e33..d99097e 100644 --- a/src/test/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceControllerIntegrationTest.java +++ b/src/test/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceControllerIntegrationTest.java @@ -116,7 +116,7 @@ public void createServiceInstanceWithAsyncSucceeds() throws Exception { } @Test - public void createServiceInstanceWithUnknownServiceDefinitionFails() throws Exception { + public void createServiceInstanceWithUnknownServiceDefinitionIdFails() throws Exception { when(catalogService.getServiceDefinition(eq(syncCreateRequest.getServiceDefinitionId()))) .thenReturn(null); @@ -129,7 +129,7 @@ public void createServiceInstanceWithUnknownServiceDefinitionFails() throws Exce } @Test - public void createDuplicateServiceInstanceFails() throws Exception { + public void createDuplicateServiceInstanceIdFails() throws Exception { when(serviceInstanceService.createServiceInstance(eq(syncCreateRequest))) .thenThrow(new ServiceInstanceExistsException(syncCreateRequest.getServiceInstanceId(), syncCreateRequest.getServiceDefinitionId())); @@ -233,6 +233,20 @@ public void deleteServiceInstanceWithUnknownIdFails() throws Exception { .andExpect(jsonPath("$", is("{}"))); } + @Test + public void deleteServiceInstanceWithUnknownServiceDefinitionIdFails() throws Exception { + when(serviceInstanceService.deleteServiceInstance(eq(syncDeleteRequest))) + .thenThrow(new ServiceInstanceDoesNotExistException(syncDeleteRequest.getServiceInstanceId())); + + when(catalogService.getServiceDefinition(eq(syncDeleteRequest.getServiceDefinitionId()))) + .thenReturn(null); + + mockMvc.perform(delete(buildUrl(syncDeleteRequest)) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isUnprocessableEntity()) + .andExpect(jsonPath("$.description", containsString(syncDeleteRequest.getServiceDefinitionId()))); + } + @Test public void deleteServiceInstanceWithAsyncRequiredFails() throws Exception { when(serviceInstanceService.deleteServiceInstance(eq(syncDeleteRequest))) @@ -310,7 +324,24 @@ public void updateServiceInstanceWithUnknownIdFails() throws Exception { } @Test - public void updateServiceInstanceWithUnknownPlanFails() throws Exception { + public void updateServiceInstanceWithUnknownServiceDefinitionIdFails() throws Exception { + when(serviceInstanceService.updateServiceInstance(eq(syncUpdateRequest))) + .thenThrow(new ServiceInstanceUpdateNotSupportedException("description")); + + when(catalogService.getServiceDefinition(eq(syncUpdateRequest.getServiceDefinitionId()))) + .thenReturn(null); + + mockMvc.perform(patch(buildUrl(syncUpdateRequest)) + .content(toJson(syncUpdateRequest)) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isUnprocessableEntity()) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$.description", containsString(syncUpdateRequest.getServiceDefinitionId()))); + } + + @Test + public void updateServiceInstanceWithUnknownPlanIdFails() throws Exception { when(serviceInstanceService.updateServiceInstance(eq(syncUpdateRequest))) .thenThrow(new ServiceInstanceUpdateNotSupportedException("description")); diff --git a/src/test/java/org/cloudfoundry/community/servicebroker/model/fixture/ServiceInstanceBindingFixture.java b/src/test/java/org/cloudfoundry/community/servicebroker/model/fixture/ServiceInstanceBindingFixture.java index bb85aa6..ede742c 100644 --- a/src/test/java/org/cloudfoundry/community/servicebroker/model/fixture/ServiceInstanceBindingFixture.java +++ b/src/test/java/org/cloudfoundry/community/servicebroker/model/fixture/ServiceInstanceBindingFixture.java @@ -7,18 +7,23 @@ public class ServiceInstanceBindingFixture { + public static final String SERVICE_INSTANCE_BINDING_ID = "service_instance_binding_id"; + public static final String SERVICE_INSTANCE_ID = "service-instance-one-id"; + public static final String SYSLOG_DRAIN_URL = "http://syslog.example.com"; + public static final String APP_GUID = "app_guid"; + public static CreateServiceInstanceBindingRequest buildCreateServiceInstanceBindingRequest() { return new CreateServiceInstanceBindingRequest( ServiceFixture.getService().getId(), PlanFixture.getPlanOne().getId(), - getAppGuid(), + APP_GUID, ParametersFixture.getParameters()) - .withBindingId(getServiceInstanceBindingId()) - .withServiceInstanceId("service-instance-one-id"); + .withBindingId(SERVICE_INSTANCE_BINDING_ID) + .withServiceInstanceId(SERVICE_INSTANCE_ID); } public static CreateServiceInstanceBindingResponse buildCreateServiceInstanceBindingResponse() { - return new CreateServiceInstanceBindingResponse(getCredentials(), getSysLogDrainUrl()); + return new CreateServiceInstanceBindingResponse(getCredentials(), SYSLOG_DRAIN_URL); } public static CreateServiceInstanceBindingResponse buildCreateServiceInstanceBindingResponseWithoutSyslog() { @@ -26,17 +31,12 @@ public static CreateServiceInstanceBindingResponse buildCreateServiceInstanceBin } public static DeleteServiceInstanceBindingRequest buildDeleteServiceInstanceBindingRequest() { - ServiceInstance instance = ServiceInstanceFixture.getServiceInstance(); ServiceDefinition service = ServiceFixture.getService(); - return new DeleteServiceInstanceBindingRequest(instance.getServiceInstanceId(), getServiceInstanceBindingId(), + return new DeleteServiceInstanceBindingRequest(SERVICE_INSTANCE_ID, SERVICE_INSTANCE_BINDING_ID, service.getId(), service.getPlans().get(0).getId(), service); } - public static String getServiceInstanceBindingId() { - return "service_instance_binding_id"; - } - private static Map getCredentials() { Map credentials = new HashMap<>(); credentials.put("uri","http://uri.example.com"); @@ -44,12 +44,4 @@ private static Map getCredentials() { credentials.put("password", "pwd1"); return credentials; } - - private static String getSysLogDrainUrl() { - return "http://syslog.example.com"; - } - - private static String getAppGuid() { - return "app_guid"; - } } diff --git a/src/test/java/org/cloudfoundry/community/servicebroker/model/fixture/ServiceInstanceFixture.java b/src/test/java/org/cloudfoundry/community/servicebroker/model/fixture/ServiceInstanceFixture.java index 50f070c..cd0a87a 100644 --- a/src/test/java/org/cloudfoundry/community/servicebroker/model/fixture/ServiceInstanceFixture.java +++ b/src/test/java/org/cloudfoundry/community/servicebroker/model/fixture/ServiceInstanceFixture.java @@ -6,23 +6,11 @@ import org.cloudfoundry.community.servicebroker.model.DeleteServiceInstanceResponse; import org.cloudfoundry.community.servicebroker.model.GetLastServiceOperationRequest; import org.cloudfoundry.community.servicebroker.model.ServiceDefinition; -import org.cloudfoundry.community.servicebroker.model.ServiceInstance; import org.cloudfoundry.community.servicebroker.model.UpdateServiceInstanceRequest; import org.cloudfoundry.community.servicebroker.model.UpdateServiceInstanceResponse; public class ServiceInstanceFixture { - public static ServiceInstance getServiceInstance() { - return new ServiceInstance(new CreateServiceInstanceRequest( - "service-one-id", - "plan-one-id", - DataFixture.getOrgOneGuid(), - DataFixture.getSpaceOneGuid(), - ParametersFixture.getParameters(), false) - .withServiceInstanceId("service-instance-one-id")) - .withDashboardUrl("dashboard_url"); - } - public static CreateServiceInstanceRequest buildCreateServiceInstanceRequest(boolean acceptsIncomplete) { ServiceDefinition service = ServiceFixture.getService(); return new CreateServiceInstanceRequest(