use of com.commercetools.sync.states.StateSync in project commercetools-sync-java by commercetools.
the class StateSyncIT method sync_WithDeletedTransition_ShouldRemoveTransitions.
@Test
void sync_WithDeletedTransition_ShouldRemoveTransitions() {
final StateDraft stateCDraft = createStateDraft(keyC);
final State stateC = createStateInSource(stateCDraft);
final StateDraft tagetStateCDraft = createStateDraft(keyC);
final State targetStateC = createStateInTarget(tagetStateCDraft);
final StateDraft stateBDraft = createStateDraft(keyB, stateC);
final State stateB = createStateInSource(stateBDraft);
final StateDraft tagetStateBDraft = createStateDraft(keyB, targetStateC);
final State targetStateB = createStateInTarget(tagetStateBDraft);
final StateDraft stateADraft = createStateDraft(keyA, stateB);
final State stateA = createStateInSource(stateADraft);
final StateDraft tagetStateADraft = createStateDraft(keyA, targetStateB, targetStateC);
final State targetStateA = createStateInTarget(tagetStateADraft);
Assertions.assertThat(targetStateB.getTransitions().size()).isEqualTo(1);
Assertions.assertThat(targetStateA.getTransitions().size()).isEqualTo(2);
final StateSyncOptions stateSyncOptions = StateSyncOptionsBuilder.of(CTP_TARGET_CLIENT).batchSize(3).build();
final StateSync stateSync = new StateSync(stateSyncOptions);
final List<StateDraft> stateDrafts = StateTransformUtils.toStateDrafts(CTP_SOURCE_CLIENT, referenceIdToKeyCache, Arrays.asList(stateA, stateB, stateC)).join();
// test
final StateSyncStatistics stateSyncStatistics = stateSync.sync(stateDrafts).toCompletableFuture().join();
assertThat(stateSyncStatistics).hasValues(3, 0, 1, 0, 0);
CtpQueryUtils.queryAll(CTP_TARGET_CLIENT, StateQueryBuilder.of().plusPredicates(q -> q.key().is(keyA)).build(), Function.identity()).thenApply(fetchedCategories -> fetchedCategories.stream().flatMap(List::stream).collect(Collectors.toList())).thenAccept(resultStates -> {
Assertions.assertThat(resultStates.size()).isEqualTo(1);
Assertions.assertThat(resultStates.get(0).getTransitions().size()).isEqualTo(1);
}).toCompletableFuture().join();
}
use of com.commercetools.sync.states.StateSync in project commercetools-sync-java by commercetools.
the class StateSyncIT method sync_withNewStateWihCreationException_shouldPrintErrorMessage.
@Test
void sync_withNewStateWihCreationException_shouldPrintErrorMessage() {
final StateDraft stateDraft = StateDraftBuilder.of(keyA, StateType.REVIEW_STATE).roles(asSet(StateRole.REVIEW_INCLUDED_IN_STATISTICS)).build();
final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
final StateCreateCommand command = any(StateCreateCommand.class);
when(spyClient.execute(command)).thenReturn(completedFuture(any(State.class)));
final StateSyncOptions stateSyncOptions = StateSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception.getCause());
}).build();
final StateSync stateSync = new StateSync(stateSyncOptions);
// test
final StateSyncStatistics stateSyncStatistics = stateSync.sync(singletonList(stateDraft)).toCompletableFuture().join();
assertThat(stateSyncStatistics).hasValues(1, 0, 0, 1, 0);
Assertions.assertThat(errorCallBackExceptions).isNotEmpty();
Assertions.assertThat(errorCallBackMessages).isNotEmpty();
Assertions.assertThat(errorCallBackMessages.get(0)).contains(format("Failed to process the StateDraft with key: '%s'", keyA));
Assertions.assertThat(warningCallBackMessages).isEmpty();
}
Aggregations