@Override public Mono<CreateServiceInstanceResponse> createServiceInstance( CreateServiceInstanceRequest request) { if (request.getServiceDefinitionId() == null) { return Mono.error(new ServiceBrokerInvalidParametersException("arrrr")); } return Mono.just(CreateServiceInstanceResponse.builder().build()); }
@Override public Mono<UpdateServiceInstanceResponse> updateServiceInstance( UpdateServiceInstanceRequest request) { if (request.getServiceDefinitionId() == null) { return Mono.error(new ServiceBrokerInvalidParametersException("arrrr")); } return Mono.just(UpdateServiceInstanceResponse.builder().build()); }
@Override public Mono<GetLastServiceOperationResponse> getLastOperation(GetLastServiceOperationRequest request) { if (request.getServiceDefinitionId() == null) { return Mono.error(new ServiceBrokerInvalidParametersException("arrrr")); } return Mono.just(GetLastServiceOperationResponse.builder().build()); } }
@Test public void serviceBrokerInvalidParametersException() { ServiceBrokerInvalidParametersException exception = new ServiceBrokerInvalidParametersException("test message"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isNull(); assertThat(errorMessage.getMessage()).contains("test message"); }
@Test public void createServiceInstanceWithInvalidParametersFails() { setupCatalogService(); setupServiceInstanceService(new ServiceBrokerInvalidParametersException("invalid parameters description")); client.put().uri(buildCreateUpdateUrl()) .contentType(MediaType.APPLICATION_JSON) .syncBody(createRequestBody) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().is4xxClientError() .expectStatus().isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY) .expectBody() .jsonPath("$.description").isNotEmpty() .consumeWith(result -> assertDescriptionContains(result, "invalid parameters description")); }
@Test public void createServiceInstanceWithInvalidParametersFails() throws Exception { setupCatalogService(); setupServiceInstanceService(new ServiceBrokerInvalidParametersException("invalid parameters description")); MvcResult mvcResult = mockMvc.perform(put(buildCreateUpdateUrl()) .content(createRequestBody) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isUnprocessableEntity()) .andExpect(jsonPath("$.description", endsWith("invalid parameters description"))); }