Search in sources :

Example 11 with CustomObjectCompositeIdentifier

use of com.commercetools.sync.customobjects.helpers.CustomObjectCompositeIdentifier in project commercetools-sync-java by commercetools.

the class CustomObjectServiceImplIT method fetchMatchingCustomObjectsByCompositeIdentifiers_WithBadGateWayExceptionAlways_ShouldFail.

@Test
void fetchMatchingCustomObjectsByCompositeIdentifiers_WithBadGateWayExceptionAlways_ShouldFail() {
    // Mock sphere client to return BadGatewayException on any request.
    final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
    when(spyClient.execute(any(CustomObjectQuery.class))).thenReturn(CompletableFutureUtils.exceptionallyCompletedFuture(new BadGatewayException())).thenCallRealMethod();
    final CustomObjectSyncOptions spyOptions = CustomObjectSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception.getCause());
    }).build();
    final CustomObjectService spyCustomObjectService = new CustomObjectServiceImpl(spyOptions);
    final Set<CustomObjectCompositeIdentifier> customObjectCompositeIdentifiers = new HashSet<>();
    customObjectCompositeIdentifiers.add(CustomObjectCompositeIdentifier.of(OLD_CUSTOM_OBJECT_KEY, OLD_CUSTOM_OBJECT_CONTAINER));
    // test and assert
    assertThat(errorCallBackExceptions).isEmpty();
    assertThat(errorCallBackMessages).isEmpty();
    assertThat(spyCustomObjectService.fetchMatchingCustomObjects(customObjectCompositeIdentifiers)).failsWithin(10, TimeUnit.SECONDS).withThrowableOfType(ExecutionException.class).withCauseExactlyInstanceOf(BadGatewayException.class);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CustomObjectITUtils.deleteCustomObject(com.commercetools.sync.integration.commons.utils.CustomObjectITUtils.deleteCustomObject) CustomObjectQuery(io.sphere.sdk.customobjects.queries.CustomObjectQuery) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CustomObjectSyncOptions(com.commercetools.sync.customobjects.CustomObjectSyncOptions) CustomObject(io.sphere.sdk.customobjects.CustomObject) Mockito.spy(org.mockito.Mockito.spy) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AfterAll(org.junit.jupiter.api.AfterAll) SphereClient(io.sphere.sdk.client.SphereClient) JsonNode(com.fasterxml.jackson.databind.JsonNode) CustomObjectCompositeIdentifier(com.commercetools.sync.customobjects.helpers.CustomObjectCompositeIdentifier) BadGatewayException(io.sphere.sdk.client.BadGatewayException) CustomObjectDraft(io.sphere.sdk.customobjects.CustomObjectDraft) CompletionStageUtil.executeBlocking(com.commercetools.tests.utils.CompletionStageUtil.executeBlocking) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) CustomObjectSyncOptionsBuilder(com.commercetools.sync.customobjects.CustomObjectSyncOptionsBuilder) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) CustomObjectITUtils.createCustomObject(com.commercetools.sync.integration.commons.utils.CustomObjectITUtils.createCustomObject) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Optional(java.util.Optional) CustomObjectServiceImpl(com.commercetools.sync.services.impl.CustomObjectServiceImpl) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) CustomObjectService(com.commercetools.sync.services.CustomObjectService) CustomObjectService(com.commercetools.sync.services.CustomObjectService) CustomObjectSyncOptions(com.commercetools.sync.customobjects.CustomObjectSyncOptions) SphereClient(io.sphere.sdk.client.SphereClient) CustomObjectServiceImpl(com.commercetools.sync.services.impl.CustomObjectServiceImpl) BadGatewayException(io.sphere.sdk.client.BadGatewayException) CustomObjectCompositeIdentifier(com.commercetools.sync.customobjects.helpers.CustomObjectCompositeIdentifier) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

CustomObjectCompositeIdentifier (com.commercetools.sync.customobjects.helpers.CustomObjectCompositeIdentifier)11 Test (org.junit.jupiter.api.Test)9 CustomObject (io.sphere.sdk.customobjects.CustomObject)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ProductVariantDraft (io.sphere.sdk.products.ProductVariantDraft)5 CustomObjectService (com.commercetools.sync.services.CustomObjectService)4 Optional (java.util.Optional)4 ProductSyncMockUtils.getReferenceSetAttributeDraft (com.commercetools.sync.products.ProductSyncMockUtils.getReferenceSetAttributeDraft)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 SphereClient (io.sphere.sdk.client.SphereClient)3 CustomObjectQuery (io.sphere.sdk.customobjects.queries.CustomObjectQuery)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Set (java.util.Set)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 CustomObjectSyncOptions (com.commercetools.sync.customobjects.CustomObjectSyncOptions)2 ProductSyncMockUtils.createReferenceObject (com.commercetools.sync.products.ProductSyncMockUtils.createReferenceObject)2 ProductSyncMockUtils.getMockCustomObjectService (com.commercetools.sync.products.ProductSyncMockUtils.getMockCustomObjectService)2 ProductSyncOptions (com.commercetools.sync.products.ProductSyncOptions)2 ProductSyncOptionsBuilder (com.commercetools.sync.products.ProductSyncOptionsBuilder)2