Search in sources :

Example 1 with WaitingToBeResolved

use of com.commercetools.sync.commons.models.WaitingToBeResolved in project commercetools-sync-java by commercetools.

the class UnresolvedReferencesServiceImplTest method delete_OnSuccess_ShouldMakeRequestWithSha1HashedKey.

@SuppressWarnings("unchecked")
@Test
void delete_OnSuccess_ShouldMakeRequestWithSha1HashedKey() {
    // preparation
    final CustomObject customObjectMock = mock(CustomObject.class);
    final ProductDraft productDraftMock = mock(ProductDraft.class);
    when(productDraftMock.getKey()).thenReturn("product-draft-key");
    final WaitingToBeResolvedProducts waitingDraft = new WaitingToBeResolvedProducts(productDraftMock, singleton("test-ref"));
    when(customObjectMock.getValue()).thenReturn(waitingDraft);
    when(productSyncOptions.getCtpClient().execute(any(CustomObjectDeleteCommand.class))).thenReturn(completedFuture(customObjectMock));
    final ArgumentCaptor<CustomObjectDeleteCommand<WaitingToBeResolved>> requestArgumentCaptor = ArgumentCaptor.forClass(CustomObjectDeleteCommand.class);
    // test
    final Optional<WaitingToBeResolvedProducts> toBeResolvedOptional = service.delete("product-draft-key", CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class).toCompletableFuture().join();
    // assertions
    verify(productSyncOptions.getCtpClient()).execute(requestArgumentCaptor.capture());
    assertThat(toBeResolvedOptional).contains(waitingDraft);
    final CustomObjectDeleteCommand<WaitingToBeResolved> value = requestArgumentCaptor.getValue();
    assertThat(value.httpRequestIntent().getPath()).contains(sha1Hex(productDraftMock.getKey()));
}
Also used : CustomObject(io.sphere.sdk.customobjects.CustomObject) ProductDraft(io.sphere.sdk.products.ProductDraft) WaitingToBeResolvedProducts(com.commercetools.sync.commons.models.WaitingToBeResolvedProducts) WaitingToBeResolved(com.commercetools.sync.commons.models.WaitingToBeResolved) CustomObjectDeleteCommand(io.sphere.sdk.customobjects.commands.CustomObjectDeleteCommand) Test(org.junit.jupiter.api.Test)

Aggregations

WaitingToBeResolved (com.commercetools.sync.commons.models.WaitingToBeResolved)1 WaitingToBeResolvedProducts (com.commercetools.sync.commons.models.WaitingToBeResolvedProducts)1 CustomObject (io.sphere.sdk.customobjects.CustomObject)1 CustomObjectDeleteCommand (io.sphere.sdk.customobjects.commands.CustomObjectDeleteCommand)1 ProductDraft (io.sphere.sdk.products.ProductDraft)1 Test (org.junit.jupiter.api.Test)1