-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide default implementation of ServiceInstanceBindingService for u…
…se with service brokers that do not provide bindable service offerings.
- Loading branch information
1 parent
013c259
commit bd9ad52
Showing
6 changed files
with
129 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...springframework/cloud/servicebroker/service/NonBindableServiceInstanceBindingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.springframework.cloud.servicebroker.service; | ||
|
||
import org.springframework.cloud.servicebroker.model.CreateServiceInstanceBindingRequest; | ||
import org.springframework.cloud.servicebroker.model.CreateServiceInstanceBindingResponse; | ||
import org.springframework.cloud.servicebroker.model.DeleteServiceInstanceBindingRequest; | ||
|
||
/** | ||
* Default implementation of ServiceInstanceBindingService for service brokers that do not support bindable services. | ||
* | ||
* See http://docs.cloudfoundry.org/services/api.html#binding | ||
* | ||
* @author Scott Frederick | ||
*/ | ||
public class NonBindableServiceInstanceBindingService implements ServiceInstanceBindingService { | ||
@Override | ||
public CreateServiceInstanceBindingResponse createServiceInstanceBinding(CreateServiceInstanceBindingRequest request) { | ||
throw nonBindableException(); | ||
} | ||
|
||
@Override | ||
public void deleteServiceInstanceBinding(DeleteServiceInstanceBindingRequest request) { | ||
throw nonBindableException(); | ||
} | ||
|
||
private UnsupportedOperationException nonBindableException() { | ||
return new UnsupportedOperationException("This service broker does not support bindable services. " + | ||
"The service broker should set 'bindable: false' in the service catalog for all service offerings, " + | ||
"or provide an implementation of this service."); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
.../servicebroker/controller/NonBindableServiceInstanceBindingControllerIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.springframework.cloud.servicebroker.controller; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
import org.springframework.cloud.servicebroker.model.fixture.DataFixture; | ||
import org.springframework.cloud.servicebroker.service.NonBindableServiceInstanceBindingService; | ||
import org.springframework.cloud.servicebroker.service.ServiceInstanceBindingService; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class NonBindableServiceInstanceBindingControllerIntegrationTest extends ServiceInstanceBindingIntegrationTest { | ||
|
||
private MockMvc mockMvc; | ||
|
||
@Before | ||
public void setup() { | ||
ServiceInstanceBindingService serviceInstanceBindingService = new NonBindableServiceInstanceBindingService(); | ||
ServiceInstanceBindingController controller = | ||
new ServiceInstanceBindingController(catalogService, serviceInstanceBindingService); | ||
|
||
this.mockMvc = MockMvcBuilders.standaloneSetup(controller) | ||
.setMessageConverters(new MappingJackson2HttpMessageConverter()).build(); | ||
} | ||
|
||
@Test | ||
public void createBindingToAppFails() throws Exception { | ||
setupCatalogService(createRequest.getServiceDefinitionId()); | ||
|
||
mockMvc.perform(put(buildUrl(createRequest)) | ||
.content(DataFixture.toJson(createRequest)) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isInternalServerError()); | ||
} | ||
|
||
@Test | ||
public void deleteBindingFails() throws Exception { | ||
setupCatalogService(deleteRequest.getServiceDefinitionId()); | ||
|
||
mockMvc.perform(delete(buildUrl(deleteRequest)) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isInternalServerError()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...springframework/cloud/servicebroker/controller/ServiceInstanceBindingIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.springframework.cloud.servicebroker.controller; | ||
|
||
import org.junit.Before; | ||
import org.springframework.cloud.servicebroker.model.CreateServiceInstanceBindingRequest; | ||
import org.springframework.cloud.servicebroker.model.DeleteServiceInstanceBindingRequest; | ||
import org.springframework.cloud.servicebroker.model.fixture.ServiceInstanceBindingFixture; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
public abstract class ServiceInstanceBindingIntegrationTest extends ControllerIntegrationTest { | ||
protected UriComponentsBuilder uriBuilder; | ||
|
||
protected CreateServiceInstanceBindingRequest createRequest; | ||
protected DeleteServiceInstanceBindingRequest deleteRequest; | ||
|
||
@Before | ||
public void setupBase() { | ||
uriBuilder = UriComponentsBuilder.fromPath("/v2/service_instances/") | ||
.pathSegment("service-instance-one-id", "service_bindings"); | ||
|
||
createRequest = ServiceInstanceBindingFixture.buildCreateAppBindingRequest(); | ||
|
||
deleteRequest = ServiceInstanceBindingFixture.buildDeleteServiceInstanceBindingRequest(); | ||
} | ||
|
||
protected String buildUrl(CreateServiceInstanceBindingRequest request) { | ||
return uriBuilder.path(request.getBindingId()).toUriString(); | ||
} | ||
|
||
protected String buildUrl(DeleteServiceInstanceBindingRequest request) { | ||
return uriBuilder.path(request.getBindingId()) | ||
.queryParam("service_id", request.getServiceDefinitionId()) | ||
.queryParam("plan_id", request.getPlanId()) | ||
.toUriString(); | ||
} | ||
} |