SuffixedServiceInstanceRequestMapper implements ServiceInstanceRequestMapper { @Override public CreateServiceInstanceRequest map(CreateServiceInstanceRequest request) { return CreateServiceInstanceRequest.builder() .serviceDefinitionId(withoutSuffix(request.getServiceDefinitionId(), serviceOfferingSuffix)) .planId(withoutSuffix(request.getPlanId(), serviceOfferingSuffix)) .context(request.getContext()) .parameters(request.getParameters()) .serviceInstanceId(request.getServiceInstanceId()) .asyncAccepted(request.isAsyncAccepted()) .build(); } SuffixedServiceInstanceRequestMapper(String serviceOfferingSuffix); @Override CreateServiceInstanceRequest map(CreateServiceInstanceRequest request); @Override DeleteServiceInstanceRequest map(DeleteServiceInstanceRequest request); @Override UpdateServiceInstanceRequest map(UpdateServiceInstanceRequest request); @Override GetLastServiceOperationRequest map(GetLastServiceOperationRequest request);  }
@Test public void should_map_create_service_instance_request() { SuffixedServiceInstanceRequestMapper mapper = new SuffixedServiceInstanceRequestMapper("-suffixed"); Map<String, Object> parameters = new HashMap<>(); parameters.put("key1", "value1"); Assert.assertEquals( CreateServiceInstanceRequest.builder() .serviceDefinitionId("serviceDefinitionId") .planId("planId") .context(CloudFoundryContext.builder() .organizationGuid("organizationGuid") .spaceGuid("spaceGuid") .build()) .parameters(parameters) .serviceInstanceId("serviceInstanceId") .asyncAccepted(true) .build() , mapper.map( CreateServiceInstanceRequest.builder() .serviceDefinitionId("serviceDefinitionId-suffixed") .planId("planId-suffixed") .context(CloudFoundryContext.builder() .organizationGuid("organizationGuid") .spaceGuid("spaceGuid") .build()) .parameters(parameters) .serviceInstanceId("serviceInstanceId") .asyncAccepted(true).build())); }
@Test public void should_map_delete_service_instance_request() throws Exception { SuffixedServiceInstanceRequestMapper mapper = new SuffixedServiceInstanceRequestMapper("-suffixed"); Assert.assertEquals(DeleteServiceInstanceRequest.builder() .serviceInstanceId("serviceInstanceId") .serviceDefinitionId("serviceDefinitionId") .planId("planId") .asyncAccepted(true) .build(), mapper.map(DeleteServiceInstanceRequest.builder() .serviceInstanceId("serviceInstanceId") .serviceDefinitionId("serviceDefinitionId-suffixed") .planId("planId-suffixed") .asyncAccepted(true) .build())); }
@Test public void should_map_update_service_instance_request() throws Exception { SuffixedServiceInstanceRequestMapper mapper = new SuffixedServiceInstanceRequestMapper("-suffixed"); Map<String, Object> parameters = new HashMap<>(); parameters.put("key1", "value1"); Assert.assertEquals(UpdateServiceInstanceRequest.builder() .serviceDefinitionId("serviceDefinitionId") .planId("planId") .parameters(parameters) .serviceInstanceId("serviceInstanceId") .asyncAccepted(true) .build(), mapper.map(UpdateServiceInstanceRequest.builder() .serviceDefinitionId("serviceDefinitionId-suffixed") .planId("planId-suffixed") .parameters(parameters) .serviceInstanceId("serviceInstanceId") .asyncAccepted(true) .build())); }
@Test public void should_map_get_last_service_operation_request() throws Exception { SuffixedServiceInstanceRequestMapper mapper = new SuffixedServiceInstanceRequestMapper("-suffixed"); Assert.assertEquals(GetLastServiceOperationRequest.builder() .serviceInstanceId("serviceInstanceId") .build(), mapper.map(GetLastServiceOperationRequest.builder() .serviceInstanceId("serviceInstanceId") .build())); }