@Override public Mono<GetLastServiceOperationResponse> getLastOperation(GetLastServiceOperationRequest request) { assertThat(request).isEqualTo(expectedRequest); return Mono.just(GetLastServiceOperationResponse.builder() .operationState(OperationState.SUCCEEDED) .build()); }
@Test public void responseWithAllValuesIsBuilt() { GetLastServiceOperationResponse response = GetLastServiceOperationResponse.builder() .operationState(OperationState.SUCCEEDED) .description("description") .deleteOperation(true) .build(); assertThat(response.getState()).isEqualTo(OperationState.SUCCEEDED); assertThat(response.getDescription()).isEqualTo("description"); assertThat(response.isDeleteOperation()).isEqualTo(true); DocumentContext json = JsonUtils.toJsonPath(response); assertThat(json).hasPath("$.state").isEqualTo(OperationState.SUCCEEDED.toString()); assertThat(json).hasPath("$.description").isEqualTo("description"); }
@Override public Mono<GetLastServiceOperationResponse> getLastOperation(GetLastServiceOperationRequest request) { String serviceInstanceId = request.getServiceInstanceId(); // // determine the status of the operation in progress // OperationState state = OperationState.SUCCEEDED; GetLastServiceOperationResponse response = GetLastServiceOperationResponse.builder() .operationState(state) .build(); return Mono.just(response); } }
new GetLastOperationResponseAndExpectedStatus( GetLastServiceOperationResponse.builder() .operationState(OperationState.IN_PROGRESS) .description("in progress") .build(), new GetLastOperationResponseAndExpectedStatus( GetLastServiceOperationResponse.builder() .operationState(OperationState.SUCCEEDED) .deleteOperation(false) .build(), new GetLastOperationResponseAndExpectedStatus( GetLastServiceOperationResponse.builder() .operationState(OperationState.SUCCEEDED) .deleteOperation(true) .build(), new GetLastOperationResponseAndExpectedStatus( GetLastServiceOperationResponse.builder() .operationState(OperationState.FAILED) .build(), HttpStatus.OK
@Test public void lastOperationHasSucceededStatus() throws Exception { setupServiceInstanceService(GetLastServiceOperationResponse.builder() .operationState(OperationState.SUCCEEDED) .description("all good") .build()); MvcResult mvcResult = mockMvc.perform(get(buildLastOperationUrl(PLATFORM_INSTANCE_ID)) .header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION) .header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(jsonPath("$.state", is(OperationState.SUCCEEDED.toString()))) .andExpect(jsonPath("$.description", is("all good"))); GetLastServiceOperationRequest actualRequest = verifyLastOperation(); assertHeaderValuesSet(actualRequest); }
@Test public void lastOperationHasSucceededStatus() throws Exception { setupServiceInstanceService(GetLastServiceOperationResponse.builder() .operationState(OperationState.SUCCEEDED) .description("all good") .build()); client.get().uri(buildLastOperationUrl(PLATFORM_INSTANCE_ID)) .header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION) .header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader()) .exchange() .expectStatus().isOk() .expectBody() .jsonPath("$.state").isEqualTo(OperationState.SUCCEEDED.toString()) .jsonPath("$.description").isEqualTo("all good"); GetLastServiceOperationRequest actualRequest = verifyLastOperation(); assertHeaderValuesSet(actualRequest); }
@Test public void lastOperationHasInProgressStatus() throws Exception { setupServiceInstanceService(GetLastServiceOperationResponse.builder() .operationState(OperationState.IN_PROGRESS) .description("working on it") .build()); MvcResult mvcResult = mockMvc.perform(get(buildLastOperationUrl())) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(jsonPath("$.state", is(OperationState.IN_PROGRESS.toString()))) .andExpect(jsonPath("$.description", is("working on it"))); GetLastServiceOperationRequest actualRequest = verifyLastOperation(); assertHeaderValuesNotSet(actualRequest); }
@Test public void lastOperationHasSucceededStatusWithDeletionComplete() { setupServiceInstanceService(GetLastServiceOperationResponse.builder() .operationState(OperationState.SUCCEEDED) .description("all gone") .deleteOperation(true) .build()); client.get().uri(buildLastOperationUrl()) .exchange() .expectStatus().is4xxClientError() .expectStatus().isEqualTo(HttpStatus.GONE) .expectBody() .jsonPath("$.state").isEqualTo(OperationState.SUCCEEDED.toString()) .jsonPath("$.description").isEqualTo("all gone"); }
@Test public void lastOperationHasInProgressStatus() { setupServiceInstanceService(GetLastServiceOperationResponse.builder() .operationState(OperationState.IN_PROGRESS) .description("working on it") .build()); client.get().uri(buildLastOperationUrl()) .exchange() .expectStatus().isOk() .expectBody() .jsonPath("$.state").isEqualTo(OperationState.IN_PROGRESS.toString()) .jsonPath("$.description").isEqualTo("working on it"); GetLastServiceOperationRequest actualRequest = verifyLastOperation(); assertHeaderValuesNotSet(actualRequest); }
@Test public void lastOperationHasSucceededStatusWithDeletionComplete() throws Exception { setupServiceInstanceService(GetLastServiceOperationResponse.builder() .operationState(OperationState.SUCCEEDED) .description("all gone") .deleteOperation(true) .build()); MvcResult mvcResult = mockMvc.perform(get(buildLastOperationUrl())) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isGone()) .andExpect(jsonPath("$.state", is(OperationState.SUCCEEDED.toString()))) .andExpect(jsonPath("$.description", is("all gone"))); }
@Test public void lastOperationHasFailedStatus() throws Exception { setupServiceInstanceService(GetLastServiceOperationResponse.builder() .operationState(OperationState.FAILED) .description("not so good") .build()); MvcResult mvcResult = mockMvc.perform(get(buildLastOperationUrl())) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(jsonPath("$.state", is(OperationState.FAILED.toString()))) .andExpect(jsonPath("$.description", is("not so good"))); }
@Test public void lastOperationHasFailedStatus() { setupServiceInstanceService(GetLastServiceOperationResponse.builder() .operationState(OperationState.FAILED) .description("not so good") .build()); client.get().uri(buildLastOperationUrl()) .exchange() .expectStatus().isOk() .expectBody() .jsonPath("$.state").isEqualTo(OperationState.FAILED.toString()) .jsonPath("$.description").isEqualTo("not so good"); }
private void responseWithStateIsSerializedToJson(OperationState stateValue, String stateString) { GetLastServiceOperationResponse response = GetLastServiceOperationResponse.builder() .operationState(stateValue) .description("description") .build(); DocumentContext json = JsonUtils.toJsonPath(response); assertThat(json).hasPath("$.state").isEqualTo(stateString); assertThat(json).hasPath("$.description").isEqualTo("description"); }