|
32 | 32 | import com.fasterxml.jackson.databind.ObjectMapper; |
33 | 33 | import com.fasterxml.jackson.databind.ObjectWriter; |
34 | 34 | import io.vrap.rmf.base.client.ApiHttpResponse; |
| 35 | +import io.vrap.rmf.base.client.error.NotFoundException; |
35 | 36 | import io.vrap.rmf.base.client.utils.CompletableFutureUtils; |
36 | 37 | import java.nio.charset.StandardCharsets; |
37 | 38 | import java.util.*; |
@@ -405,6 +406,64 @@ void delete_WithUnsuccessfulMockCtpResponse_ShouldReturnProperException() |
405 | 406 | .hasCauseExactlyInstanceOf(BadRequestException.class); |
406 | 407 | } |
407 | 408 |
|
| 409 | + @Test |
| 410 | + void delete_With404NotFoundResponse_ShouldConsiderAsDeleted() throws JsonProcessingException { |
| 411 | + // preparation |
| 412 | + final String key = "product-draft-key"; |
| 413 | + final ProductDraft productDraftMock = |
| 414 | + ProductDraftBuilder.of() |
| 415 | + .productType(ProductTypeResourceIdentifierBuilder.of().key("product-type").build()) |
| 416 | + .key(key) |
| 417 | + .name(LocalizedString.ofEnglish("product-name")) |
| 418 | + .slug(LocalizedString.ofEnglish("product-slug")) |
| 419 | + .build(); |
| 420 | + |
| 421 | + final ApiHttpResponse<State> apiHttpResponse = mock(ApiHttpResponse.class); |
| 422 | + when(apiHttpResponse.getBody()).thenReturn(mock()); |
| 423 | + final ErrorResponse errorResponse = |
| 424 | + ErrorResponseBuilder.of() |
| 425 | + .statusCode(404) |
| 426 | + .errors(Collections.emptyList()) |
| 427 | + .message("test") |
| 428 | + .build(); |
| 429 | + |
| 430 | + final ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); |
| 431 | + final String json = ow.writeValueAsString(errorResponse); |
| 432 | + |
| 433 | + final ByProjectKeyCustomObjectsByContainerByKeyDelete customObjectsDelete = |
| 434 | + mock(ByProjectKeyCustomObjectsByContainerByKeyDelete.class); |
| 435 | + when(customObjectsDelete.execute()) |
| 436 | + .thenReturn( |
| 437 | + CompletableFutureUtils.failed( |
| 438 | + new NotFoundException( |
| 439 | + 404, |
| 440 | + "", |
| 441 | + null, |
| 442 | + "not found", |
| 443 | + new ApiHttpResponse<>(404, null, json.getBytes(StandardCharsets.UTF_8))))); |
| 444 | + when(productSyncOptions |
| 445 | + .getCtpClient() |
| 446 | + .customObjects() |
| 447 | + .withContainerAndKey(anyString(), anyString()) |
| 448 | + .delete()) |
| 449 | + .thenReturn(customObjectsDelete); |
| 450 | + |
| 451 | + // test |
| 452 | + final Optional<WaitingToBeResolvedProducts> toBeResolvedOptional = |
| 453 | + service |
| 454 | + .delete( |
| 455 | + "product-draft-key", |
| 456 | + UnresolvedReferencesServiceImpl.CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, |
| 457 | + WaitingToBeResolvedProducts.class) |
| 458 | + .toCompletableFuture() |
| 459 | + .join(); |
| 460 | + |
| 461 | + // assertions |
| 462 | + assertThat(toBeResolvedOptional).isEmpty(); |
| 463 | + assertThat(errorMessages).hasSize(0); |
| 464 | + assertThat(errorExceptions).hasSize(0); |
| 465 | + } |
| 466 | + |
408 | 467 | @SuppressWarnings("unchecked") |
409 | 468 | @Test |
410 | 469 | void delete_OnSuccess_ShouldRemoveTheResourceObject() { |
|
0 commit comments