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);
}
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);
}
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)));
}
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();
}
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);
}
Aggregations