SuffixedServiceInstanceBindingRequestMapper implements ServiceInstanceBindingRequestMapper { @Override public CreateServiceInstanceBindingRequest map(CreateServiceInstanceBindingRequest request) { return CreateServiceInstanceBindingRequest.builder() .serviceDefinitionId(withoutSuffix(request.getServiceDefinitionId(), serviceOfferingSuffix)) .planId(withoutSuffix(request.getPlanId(), serviceOfferingSuffix)) .bindResource(request.getBindResource()) .parameters(request.getParameters()) .bindingId(request.getBindingId()) .serviceInstanceId(request.getServiceInstanceId()) .build(); } SuffixedServiceInstanceBindingRequestMapper(String suffix); @Override CreateServiceInstanceBindingRequest map(CreateServiceInstanceBindingRequest request); @Override DeleteServiceInstanceBindingRequest map(DeleteServiceInstanceBindingRequest request);  }
@Test public void should_map_create_service_instance_binding_request() { SuffixedServiceInstanceBindingRequestMapper mapper = new SuffixedServiceInstanceBindingRequestMapper("-suffix"); Map<String, Object> bindResource = new HashMap<>(); bindResource.put("resource1", "value1"); Map<String, Object> parameters = new HashMap<>(); parameters.put("parameter1", "value1"); Assert.assertEquals(CreateServiceInstanceBindingRequest.builder() .serviceDefinitionId("serviceDefinitionId") .planId("planId") .bindResource(BindResource.builder() .properties(bindResource) .appGuid("appGuid") .build()) .parameters(parameters) .bindingId("bindingId") .serviceInstanceId("serviceInstanceId") .build(), mapper.map( CreateServiceInstanceBindingRequest.builder() .serviceDefinitionId("serviceDefinitionId-suffix") .planId("planId-suffix") .bindResource(BindResource.builder() .properties(bindResource) .appGuid("appGuid") .build()) .parameters(parameters) .bindingId("bindingId") .serviceInstanceId("serviceInstanceId") .build())); }
@Test public void should_map_delete_service_instance_binding_request() { SuffixedServiceInstanceBindingRequestMapper mapper = new SuffixedServiceInstanceBindingRequestMapper("-suffix"); Assert.assertEquals( DeleteServiceInstanceBindingRequest.builder() .serviceInstanceId("serviceInstanceId") .bindingId("bindingId") .serviceDefinitionId("serviceDefinitionId") .planId("planId") .build(), mapper.map( DeleteServiceInstanceBindingRequest.builder() .serviceInstanceId("serviceInstanceId") .bindingId("bindingId") .serviceDefinitionId("serviceDefinitionId-suffix") .planId("planId-suffix") .build())); }