Search in sources :

Example 6 with CustomObjectSyncOptions

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

the class CustomObjectSyncIT method sync_withNewCustomObject_shouldCreateCustomObject.

@Test
void sync_withNewCustomObject_shouldCreateCustomObject() {
    final CustomObjectSyncOptions customObjectSyncOptions = CustomObjectSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
    final CustomObjectSync customObjectSync = new CustomObjectSync(customObjectSyncOptions);
    final ObjectNode customObject2Value = JsonNodeFactory.instance.objectNode().put("name", "value1");
    final CustomObjectDraft<JsonNode> customObjectDraft = CustomObjectDraft.ofUnversionedUpsert("container2", "key2", customObject2Value);
    final CustomObjectSyncStatistics customObjectSyncStatistics = customObjectSync.sync(Collections.singletonList(customObjectDraft)).toCompletableFuture().join();
    assertThat(customObjectSyncStatistics).hasValues(1, 1, 0, 0);
}
Also used : CustomObjectSyncOptions(com.commercetools.sync.customobjects.CustomObjectSyncOptions) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) CustomObjectSyncStatistics(com.commercetools.sync.customobjects.helpers.CustomObjectSyncStatistics) CustomObjectSync(com.commercetools.sync.customobjects.CustomObjectSync) Test(org.junit.jupiter.api.Test)

Example 7 with CustomObjectSyncOptions

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

the class CustomObjectSyncIT method sync_withExistingCustomObjectThatHasSameValue_shouldNotUpdateCustomObject.

@Test
void sync_withExistingCustomObjectThatHasSameValue_shouldNotUpdateCustomObject() {
    final CustomObjectDraft<JsonNode> customObjectDraft = CustomObjectDraft.ofUnversionedUpsert("container1", "key1", customObject1Value);
    final CustomObjectSyncOptions customObjectSyncOptions = CustomObjectSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
    final CustomObjectSync customObjectSync = new CustomObjectSync(customObjectSyncOptions);
    final CustomObjectSyncStatistics customObjectSyncStatistics = customObjectSync.sync(Collections.singletonList(customObjectDraft)).toCompletableFuture().join();
    assertThat(customObjectSyncStatistics).hasValues(1, 0, 0, 0);
}
Also used : CustomObjectSyncOptions(com.commercetools.sync.customobjects.CustomObjectSyncOptions) JsonNode(com.fasterxml.jackson.databind.JsonNode) CustomObjectSyncStatistics(com.commercetools.sync.customobjects.helpers.CustomObjectSyncStatistics) CustomObjectSync(com.commercetools.sync.customobjects.CustomObjectSync) Test(org.junit.jupiter.api.Test)

Example 8 with CustomObjectSyncOptions

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

the class CustomObjectSyncIT method sync_withChangedCustomObjectWithBadGatewayExceptionInsideUpdateRetry_shouldFailToUpdate.

@Test
void sync_withChangedCustomObjectWithBadGatewayExceptionInsideUpdateRetry_shouldFailToUpdate() {
    final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
    final CustomObjectUpsertCommand upsertCommand = any(CustomObjectUpsertCommand.class);
    when(spyClient.execute(upsertCommand)).thenReturn(CompletableFutureUtils.exceptionallyCompletedFuture(new ConcurrentModificationException())).thenCallRealMethod();
    final CustomObjectQuery customObjectQuery = any(CustomObjectQuery.class);
    when(spyClient.execute(customObjectQuery)).thenCallRealMethod().thenReturn(CompletableFutureUtils.exceptionallyCompletedFuture(new BadGatewayException()));
    final ObjectNode newCustomObjectValue = JsonNodeFactory.instance.objectNode().put("name", "value2");
    List<String> errorCallBackMessages = new ArrayList<>();
    List<Throwable> errorCallBackExceptions = new ArrayList<>();
    final CustomObjectSyncOptions spyOptions = CustomObjectSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception.getCause());
    }).build();
    final CustomObjectSync customObjectSync = new CustomObjectSync(spyOptions);
    final CustomObjectDraft<JsonNode> customObjectDraft = CustomObjectDraft.ofUnversionedUpsert("container1", "key1", newCustomObjectValue);
    final CustomObjectSyncStatistics customObjectSyncStatistics = customObjectSync.sync(Collections.singletonList(customObjectDraft)).toCompletableFuture().join();
    assertThat(customObjectSyncStatistics).hasValues(1, 0, 0, 1);
    Assertions.assertThat(errorCallBackMessages).hasSize(1);
    Assertions.assertThat(errorCallBackExceptions).hasSize(1);
    Assertions.assertThat(errorCallBackMessages.get(0)).contains(format("Failed to update custom object with key: '%s'. Reason: Failed to fetch from CTP while retrying " + "after concurrency modification.", CustomObjectCompositeIdentifier.of(customObjectDraft)));
}
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) BadRequestException(io.sphere.sdk.client.BadRequestException) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) CustomObjectSyncOptions(com.commercetools.sync.customobjects.CustomObjectSyncOptions) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) SphereClient(io.sphere.sdk.client.SphereClient) Assertions(org.assertj.core.api.Assertions) 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) CustomObjectSyncStatistics(com.commercetools.sync.customobjects.helpers.CustomObjectSyncStatistics) CompletionException(java.util.concurrent.CompletionException) Mockito.when(org.mockito.Mockito.when) String.format(java.lang.String.format) CustomObjectSyncOptionsBuilder(com.commercetools.sync.customobjects.CustomObjectSyncOptionsBuilder) CustomObjectUpsertCommand(io.sphere.sdk.customobjects.commands.CustomObjectUpsertCommand) Test(org.junit.jupiter.api.Test) CustomObjectSync(com.commercetools.sync.customobjects.CustomObjectSync) List(java.util.List) CustomObjectITUtils.createCustomObject(com.commercetools.sync.integration.commons.utils.CustomObjectITUtils.createCustomObject) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) Collections(java.util.Collections) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) CustomObjectUpsertCommand(io.sphere.sdk.customobjects.commands.CustomObjectUpsertCommand) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) CustomObjectSync(com.commercetools.sync.customobjects.CustomObjectSync) CustomObjectSyncOptions(com.commercetools.sync.customobjects.CustomObjectSyncOptions) SphereClient(io.sphere.sdk.client.SphereClient) BadGatewayException(io.sphere.sdk.client.BadGatewayException) CustomObjectSyncStatistics(com.commercetools.sync.customobjects.helpers.CustomObjectSyncStatistics) CustomObjectQuery(io.sphere.sdk.customobjects.queries.CustomObjectQuery) Test(org.junit.jupiter.api.Test)

Example 9 with CustomObjectSyncOptions

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

the class CustomObjectSyncIT method sync_withChangedCustomObjectAndConcurrentModificationException_shouldRetryAndUpdateCustomObject.

@Test
void sync_withChangedCustomObjectAndConcurrentModificationException_shouldRetryAndUpdateCustomObject() {
    final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
    final CustomObjectUpsertCommand customObjectUpsertCommand = any(CustomObjectUpsertCommand.class);
    when(spyClient.execute(customObjectUpsertCommand)).thenReturn(CompletableFutureUtils.exceptionallyCompletedFuture(new ConcurrentModificationException())).thenCallRealMethod();
    final ObjectNode newCustomObjectValue = JsonNodeFactory.instance.objectNode().put("name", "value2");
    List<String> errorCallBackMessages = new ArrayList<>();
    List<String> warningCallBackMessages = new ArrayList<>();
    List<Throwable> errorCallBackExceptions = new ArrayList<>();
    final CustomObjectSyncOptions spyOptions = CustomObjectSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception.getCause());
    }).build();
    final CustomObjectSync customObjectSync = new CustomObjectSync(spyOptions);
    final CustomObjectDraft<JsonNode> customObjectDraft = CustomObjectDraft.ofUnversionedUpsert("container1", "key1", newCustomObjectValue);
    // test
    final CustomObjectSyncStatistics customObjectSyncStatistics = customObjectSync.sync(Collections.singletonList(customObjectDraft)).toCompletableFuture().join();
    assertThat(customObjectSyncStatistics).hasValues(1, 0, 1, 0);
    Assertions.assertThat(errorCallBackExceptions).isEmpty();
    Assertions.assertThat(errorCallBackMessages).isEmpty();
    Assertions.assertThat(warningCallBackMessages).isEmpty();
}
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) BadRequestException(io.sphere.sdk.client.BadRequestException) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) CustomObjectSyncOptions(com.commercetools.sync.customobjects.CustomObjectSyncOptions) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) SphereClient(io.sphere.sdk.client.SphereClient) Assertions(org.assertj.core.api.Assertions) 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) CustomObjectSyncStatistics(com.commercetools.sync.customobjects.helpers.CustomObjectSyncStatistics) CompletionException(java.util.concurrent.CompletionException) Mockito.when(org.mockito.Mockito.when) String.format(java.lang.String.format) CustomObjectSyncOptionsBuilder(com.commercetools.sync.customobjects.CustomObjectSyncOptionsBuilder) CustomObjectUpsertCommand(io.sphere.sdk.customobjects.commands.CustomObjectUpsertCommand) Test(org.junit.jupiter.api.Test) CustomObjectSync(com.commercetools.sync.customobjects.CustomObjectSync) List(java.util.List) CustomObjectITUtils.createCustomObject(com.commercetools.sync.integration.commons.utils.CustomObjectITUtils.createCustomObject) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) Collections(java.util.Collections) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) CustomObjectUpsertCommand(io.sphere.sdk.customobjects.commands.CustomObjectUpsertCommand) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) CustomObjectSync(com.commercetools.sync.customobjects.CustomObjectSync) CustomObjectSyncOptions(com.commercetools.sync.customobjects.CustomObjectSyncOptions) SphereClient(io.sphere.sdk.client.SphereClient) CustomObjectSyncStatistics(com.commercetools.sync.customobjects.helpers.CustomObjectSyncStatistics) Test(org.junit.jupiter.api.Test)

Example 10 with CustomObjectSyncOptions

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

the class CustomObjectSyncIT method sync_withExistingCustomObjectThatHasDifferentValue_shouldUpdateCustomObject.

@Test
void sync_withExistingCustomObjectThatHasDifferentValue_shouldUpdateCustomObject() {
    final CustomObjectSyncOptions customObjectSyncOptions = CustomObjectSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
    final CustomObjectSync customObjectSync = new CustomObjectSync(customObjectSyncOptions);
    final ObjectNode customObject2Value = JsonNodeFactory.instance.objectNode().put("name", "value2");
    final CustomObjectDraft<JsonNode> customObjectDraft = CustomObjectDraft.ofUnversionedUpsert("container1", "key1", customObject2Value);
    final CustomObjectSyncStatistics customObjectSyncStatistics = customObjectSync.sync(Collections.singletonList(customObjectDraft)).toCompletableFuture().join();
    assertThat(customObjectSyncStatistics).hasValues(1, 0, 1, 0);
}
Also used : CustomObjectSyncOptions(com.commercetools.sync.customobjects.CustomObjectSyncOptions) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) CustomObjectSyncStatistics(com.commercetools.sync.customobjects.helpers.CustomObjectSyncStatistics) CustomObjectSync(com.commercetools.sync.customobjects.CustomObjectSync) Test(org.junit.jupiter.api.Test)

Aggregations

CustomObjectSyncOptions (com.commercetools.sync.customobjects.CustomObjectSyncOptions)15 Test (org.junit.jupiter.api.Test)13 JsonNode (com.fasterxml.jackson.databind.JsonNode)11 CustomObjectQuery (io.sphere.sdk.customobjects.queries.CustomObjectQuery)10 CustomObjectCompositeIdentifier (com.commercetools.sync.customobjects.helpers.CustomObjectCompositeIdentifier)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 CustomObjectSync (com.commercetools.sync.customobjects.CustomObjectSync)8 CustomObjectSyncOptionsBuilder (com.commercetools.sync.customobjects.CustomObjectSyncOptionsBuilder)8 CustomObjectSyncStatistics (com.commercetools.sync.customobjects.helpers.CustomObjectSyncStatistics)8 SphereClient (io.sphere.sdk.client.SphereClient)8 CustomObjectDraft (io.sphere.sdk.customobjects.CustomObjectDraft)8 List (java.util.List)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 CustomObjectITUtils.createCustomObject (com.commercetools.sync.integration.commons.utils.CustomObjectITUtils.createCustomObject)7 CustomObjectITUtils.deleteCustomObject (com.commercetools.sync.integration.commons.utils.CustomObjectITUtils.deleteCustomObject)7 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)7 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)7 BadGatewayException (io.sphere.sdk.client.BadGatewayException)7 CompletableFutureUtils (io.sphere.sdk.utils.CompletableFutureUtils)7 ArrayList (java.util.ArrayList)7