Search in sources :

Example 16 with WaitingToBeResolvedProducts

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

the class UnresolvedReferencesServiceImplTest method delete_OnSuccess_ShouldRemoveTheResourceObject.

@SuppressWarnings("unchecked")
@Test
void delete_OnSuccess_ShouldRemoveTheResourceObject() {
    // 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));
    // test
    final Optional<WaitingToBeResolvedProducts> toBeResolvedOptional = service.delete("product-draft-key", CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class).toCompletableFuture().join();
    // assertions
    assertThat(toBeResolvedOptional).contains(waitingDraft);
}
Also used : CustomObject(io.sphere.sdk.customobjects.CustomObject) ProductDraft(io.sphere.sdk.products.ProductDraft) WaitingToBeResolvedProducts(com.commercetools.sync.commons.models.WaitingToBeResolvedProducts) CustomObjectDeleteCommand(io.sphere.sdk.customobjects.commands.CustomObjectDeleteCommand) Test(org.junit.jupiter.api.Test)

Example 17 with WaitingToBeResolvedProducts

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

the class UnresolvedReferencesServiceImplTest method fetch_OnSuccess_ShouldRequestHashedKeys.

@SuppressWarnings("unchecked")
@Test
void fetch_OnSuccess_ShouldRequestHashedKeys() {
    // preparation
    final CustomObject customObjectMock = mock(CustomObject.class);
    final ProductDraft productDraftMock = mock(ProductDraft.class);
    when(productDraftMock.getKey()).thenReturn("product-draft-key");
    final WaitingToBeResolvedProducts waitingToBeResolved = new WaitingToBeResolvedProducts(productDraftMock, singleton("test-ref"));
    when(customObjectMock.getValue()).thenReturn(waitingToBeResolved);
    final PagedQueryResult result = getMockPagedQueryResult(singletonList(customObjectMock));
    when(productSyncOptions.getCtpClient().execute(any(CustomObjectQuery.class))).thenReturn(completedFuture(result));
    final ArgumentCaptor<CustomObjectQuery<WaitingToBeResolved>> requestArgumentCaptor = ArgumentCaptor.forClass(CustomObjectQuery.class);
    // test
    final Set<String> setOfSpecialCharKeys = asSet("Get a $100 Visa® Reward Card because you’re ordering TV", "product$", "Visa®", "Visa©");
    final Set<WaitingToBeResolvedProducts> toBeResolvedOptional = service.fetch(setOfSpecialCharKeys, CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class).toCompletableFuture().join();
    // assertions
    verify(productSyncOptions.getCtpClient()).execute(requestArgumentCaptor.capture());
    assertThat(toBeResolvedOptional).containsOnly(waitingToBeResolved);
    setOfSpecialCharKeys.forEach(key -> assertThat(requestArgumentCaptor.getValue().httpRequestIntent().getPath()).contains(sha1Hex(key)));
}
Also used : PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) CustomObject(io.sphere.sdk.customobjects.CustomObject) ProductDraft(io.sphere.sdk.products.ProductDraft) WaitingToBeResolvedProducts(com.commercetools.sync.commons.models.WaitingToBeResolvedProducts) CustomObjectQuery(io.sphere.sdk.customobjects.queries.CustomObjectQuery) Test(org.junit.jupiter.api.Test)

Example 18 with WaitingToBeResolvedProducts

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

the class UnresolvedReferencesServiceImplTest method save_WithUnsuccessfulMockCtpResponse_ShouldNotSaveMock.

@Test
void save_WithUnsuccessfulMockCtpResponse_ShouldNotSaveMock() {
    // preparation
    final String productKey = "product-draft-key";
    final ProductDraft productDraftMock = mock(ProductDraft.class);
    when(productDraftMock.getKey()).thenReturn(productKey);
    final WaitingToBeResolvedProducts waitingToBeResolved = new WaitingToBeResolvedProducts(productDraftMock, singleton("test-ref"));
    when(productSyncOptions.getCtpClient().execute(any())).thenReturn(CompletableFutureUtils.failed(new BadRequestException("bad request")));
    // test
    final Optional<WaitingToBeResolvedProducts> result = service.save(waitingToBeResolved, CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class).toCompletableFuture().join();
    // assertions
    assertThat(result).isEmpty();
    assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).contains(format("Failed to save CustomObject with key: '%s' (hash of product key: '%s').", sha1Hex(productKey), productKey));
    assertThat(errorExceptions).hasSize(1).singleElement(as(THROWABLE)).isExactlyInstanceOf(SyncException.class).hasCauseExactlyInstanceOf(BadRequestException.class);
}
Also used : ProductDraft(io.sphere.sdk.products.ProductDraft) WaitingToBeResolvedProducts(com.commercetools.sync.commons.models.WaitingToBeResolvedProducts) BadRequestException(io.sphere.sdk.client.BadRequestException) SyncException(com.commercetools.sync.commons.exceptions.SyncException) Test(org.junit.jupiter.api.Test)

Example 19 with WaitingToBeResolvedProducts

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

the class UnresolvedReferencesServiceImplTest method delete_WithUnsuccessfulMockCtpResponse_ShouldReturnProperException.

@Test
void delete_WithUnsuccessfulMockCtpResponse_ShouldReturnProperException() {
    // preparation
    final ProductDraft productDraftMock = mock(ProductDraft.class);
    final String key = "product-draft-key";
    when(productDraftMock.getKey()).thenReturn(key);
    when(productSyncOptions.getCtpClient().execute(any())).thenReturn(CompletableFutureUtils.failed(new BadRequestException("bad request")));
    // test
    final Optional<WaitingToBeResolvedProducts> toBeResolvedOptional = service.delete("product-draft-key", CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class).toCompletableFuture().join();
    // assertions
    assertThat(toBeResolvedOptional).isEmpty();
    assertThat(errorMessages).hasSize(1);
    assertThat(errorExceptions).hasSize(1);
    assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).contains(format("Failed to delete CustomObject with key: '%s' (hash of product key: '%s')", sha1Hex(key), key));
    assertThat(errorExceptions).hasSize(1).singleElement(as(THROWABLE)).isExactlyInstanceOf(SyncException.class).hasCauseExactlyInstanceOf(BadRequestException.class);
}
Also used : ProductDraft(io.sphere.sdk.products.ProductDraft) WaitingToBeResolvedProducts(com.commercetools.sync.commons.models.WaitingToBeResolvedProducts) BadRequestException(io.sphere.sdk.client.BadRequestException) SyncException(com.commercetools.sync.commons.exceptions.SyncException) Test(org.junit.jupiter.api.Test)

Aggregations

WaitingToBeResolvedProducts (com.commercetools.sync.commons.models.WaitingToBeResolvedProducts)19 ProductDraft (io.sphere.sdk.products.ProductDraft)19 Test (org.junit.jupiter.api.Test)18 UnresolvedReferencesServiceImpl (com.commercetools.sync.services.impl.UnresolvedReferencesServiceImpl)8 ProductSyncStatistics (com.commercetools.sync.products.helpers.ProductSyncStatistics)7 CustomObject (io.sphere.sdk.customobjects.CustomObject)7 ProductSync (com.commercetools.sync.products.ProductSync)6 AttributeDraft (io.sphere.sdk.products.attributes.AttributeDraft)6 SyncException (com.commercetools.sync.commons.exceptions.SyncException)4 ProductVariantDraft (io.sphere.sdk.products.ProductVariantDraft)4 UnresolvedReferencesService (com.commercetools.sync.services.UnresolvedReferencesService)3 CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY (com.commercetools.sync.services.impl.UnresolvedReferencesServiceImpl.CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 CustomObjectQuery (io.sphere.sdk.customobjects.queries.CustomObjectQuery)3 Reference (io.sphere.sdk.models.Reference)3 Product (io.sphere.sdk.products.Product)3 PagedQueryResult (io.sphere.sdk.queries.PagedQueryResult)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3