@Test public void duplicateServiceInstanceCreationFails() throws Exception { ServiceInstance instance = ServiceInstanceFixture.getServiceInstance(); String url = ServiceInstanceController.BASE_PATH + "/" + instance.getId(); String body = ServiceInstanceFixture.getCreateServiceInstanceRequestJson(); serviceInstanceService.createServiceInstance( ServiceFixture.getService(), instance.getId(), instance.getPlanId(), instance.getOrganizationGuid(), instance.getSpaceGuid()); mockMvc .perform( put(url) .contentType(MediaType.APPLICATION_JSON) .content(body) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isConflict()); serviceInstanceService.deleteServiceInstance( instance.getId(), instance.getServiceDefinitionId(), instance.getPlanId()); }
@Test public void testCreateInstance_success_shouldStoreInstanceDataInBrokerStore() throws Exception { ServiceInstance instance = getServiceInstance("instanceId2", "fake-bare-plan"); CreateServiceInstanceRequest request = getCreateInstanceRequest(instance); instanceService.createServiceInstance(request); ServiceInstance serviceInstance = instanceService.getServiceInstance("instanceId2"); assertThat(request.getServiceInstanceId(), equalTo(serviceInstance.getServiceInstanceId())); // todo: compare all of the fields }
@RequestMapping(value = BASE_PATH + "/{bindingId}", method = RequestMethod.PUT) public ResponseEntity<ServiceInstanceBindingResponse> bindServiceInstance( @PathVariable("instanceId") String instanceId, @PathVariable("bindingId") String bindingId, @Valid @RequestBody ServiceInstanceBindingRequest request) throws ServiceInstanceDoesNotExistException, ServiceInstanceBindingExistsException, ServiceBrokerException { logger.debug( "PUT: " + BASE_PATH + "/{bindingId}" + ", bindServiceInstance(), serviceInstance.id = " + instanceId + ", bindingId = " + bindingId); ServiceInstance instance = serviceInstanceService.getServiceInstance(instanceId); if (instance == null) { throw new ServiceInstanceDoesNotExistException(instanceId); } ServiceInstanceBinding binding = serviceInstanceBindingService.createServiceInstanceBinding( bindingId, instance, request.getServiceDefinitionId(), request.getPlanId(), request.getAppGuid()); logger.debug("ServiceInstanceBinding Created: " + binding.getId()); return new ResponseEntity<ServiceInstanceBindingResponse>( new ServiceInstanceBindingResponse(binding), HttpStatus.CREATED); }
@Test public void serviceInstanceIsDeletedSuccessfully() throws Exception { ServiceInstance instance = ServiceInstanceFixture.getServiceInstance(); String createUrl = ServiceInstanceController.BASE_PATH + "/" + instance.getId(); String body = ServiceInstanceFixture.getCreateServiceInstanceRequestJson(); String deleteUrl = ServiceInstanceController.BASE_PATH + "/" + instance.getId() + "?service_id=" + instance.getServiceDefinitionId() + "&plan_id=" + instance.getPlanId(); mockMvc .perform( put(createUrl) .contentType(MediaType.APPLICATION_JSON) .content(body) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isCreated()) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)); serviceInstanceService.getServiceInstance(instance.getId()); mockMvc .perform(delete(deleteUrl).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)); }
@Test public void testCreateInstance_success_shouldNotCreateHBaseNamespace() throws Exception { // given HBaseAdmin hBaseAdmin = utility.getHBaseAdmin(); int numberOfNamespacesBeforeServiceCreation = hBaseAdmin.listNamespaceDescriptors().length; // when ServiceInstance instance = getServiceInstance("instanceId", "fake-bare-plan"); instanceService.createServiceInstance(getCreateInstanceRequest(instance)); // then int numberOfNamespacesAfterServiceCreation = hBaseAdmin.listNamespaceDescriptors().length; assertThat( numberOfNamespacesBeforeServiceCreation, equalTo(numberOfNamespacesAfterServiceCreation)); }
@Test public void testCreateInstanceBinding_success_shouldStoreInstanceBindingDataInBrokerStore() throws Exception { ServiceInstance instance = getServiceInstance("instanceId3", "fake-bare-plan"); instanceService.createServiceInstance(getCreateInstanceRequest(instance)); CreateServiceInstanceBindingRequest request = getCreateBindingRequest("instanceId3").withBindingId("bindingId2"); bindingService.createServiceInstanceBinding(request); Optional<CreateServiceInstanceBindingRequest> bindingInstance = bindingBrokerStore.getById(Location.newInstance("bindingId2", "instanceId3")); assertThat(bindingInstance.get().getAppGuid(), equalTo(request.getAppGuid())); assertThat( bindingInstance.get().getServiceDefinitionId(), equalTo(request.getServiceDefinitionId())); assertThat(bindingInstance.get().getPlanId(), equalTo(request.getPlanId())); }