use of com.commercetools.sync.states.StateSync in project commercetools-sync-java by commercetools.
the class StateSyncIT method sync_WithNullTransitions_TargetStateTransitionsShouldBeNull.
@Test
void sync_WithNullTransitions_TargetStateTransitionsShouldBeNull() {
final StateDraft stateDraft = createStateDraft(keyA);
final State state = createStateInSource(stateDraft);
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(state)).join();
// test
final StateSyncStatistics stateSyncStatistics = stateSync.sync(stateDrafts).toCompletableFuture().join();
assertThat(stateSyncStatistics).hasValues(1, 1, 0, 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()).isNull();
}).toCompletableFuture().join();
}
use of com.commercetools.sync.states.StateSync in project commercetools-sync-java by commercetools.
the class StateSyncIT method sync_WithUpdatedTransition_ShouldUpdateTransitions.
@Test
void sync_WithUpdatedTransition_ShouldUpdateTransitions() {
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, stateC);
final State stateA = createStateInSource(stateADraft);
final StateDraft tagetStateADraft = createStateDraft(keyA, targetStateB);
final State targetStateA = createStateInTarget(tagetStateADraft);
Assertions.assertThat(targetStateB.getTransitions().size()).isEqualTo(1);
Assertions.assertThat(targetStateA.getTransitions().size()).isEqualTo(1);
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(2);
}).toCompletableFuture().join();
}
use of com.commercetools.sync.states.StateSync in project commercetools-sync-java by commercetools.
the class StateSyncIT method sync_withEqualState_shouldNotUpdateState.
@Test
void sync_withEqualState_shouldNotUpdateState() {
StateDraft stateDraft = StateDraftBuilder.of(key, StateType.LINE_ITEM_STATE).name(ofEnglish("state-name")).description(ofEnglish("state-desc")).roles(Collections.singleton(StateRole.RETURN)).initial(false).build();
final StateSyncOptions stateSyncOptions = StateSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
final StateSync stateSync = new StateSync(stateSyncOptions);
// test
final StateSyncStatistics stateSyncStatistics = stateSync.sync(singletonList(stateDraft)).toCompletableFuture().join();
assertThat(stateSyncStatistics).hasValues(1, 0, 0, 0, 0);
}
use of com.commercetools.sync.states.StateSync in project commercetools-sync-java by commercetools.
the class StateSyncIT method sync_withNewStateWithoutRole_shouldDoNothing.
@Test
void sync_withNewStateWithoutRole_shouldDoNothing() {
final StateDraft stateDraft = StateDraftBuilder.of(keyA, StateType.REVIEW_STATE).roles(Collections.emptySet()).build();
final StateDraft stateDraftTarget = StateDraftBuilder.of(keyA, StateType.REVIEW_STATE).roles(Collections.emptySet()).build();
createStateInTarget(stateDraftTarget);
final StateSyncOptions stateSyncOptions = StateSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
final StateSync stateSync = new StateSync(stateSyncOptions);
// test
final StateSyncStatistics stateSyncStatistics = stateSync.sync(singletonList(stateDraft)).toCompletableFuture().join();
assertThat(stateSyncStatistics).hasValues(1, 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).getRoles().isEmpty()).isTrue();
}).toCompletableFuture().join();
}
use of com.commercetools.sync.states.StateSync in project commercetools-sync-java by commercetools.
the class StateSyncIT method sync_withNewStateWithoutRole_shouldRemoveRole.
@Test
void sync_withNewStateWithoutRole_shouldRemoveRole() {
final StateDraft stateDraft = StateDraftBuilder.of(keyA, StateType.REVIEW_STATE).roles(Collections.emptySet()).build();
final StateDraft stateDraftTarget = StateDraftBuilder.of(keyA, StateType.REVIEW_STATE).roles(Collections.singleton(StateRole.REVIEW_INCLUDED_IN_STATISTICS)).build();
createStateInTarget(stateDraftTarget);
final StateSyncOptions stateSyncOptions = StateSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
final StateSync stateSync = new StateSync(stateSyncOptions);
// test
final StateSyncStatistics stateSyncStatistics = stateSync.sync(singletonList(stateDraft)).toCompletableFuture().join();
assertThat(stateSyncStatistics).hasValues(1, 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).getRoles().isEmpty()).isTrue();
}).toCompletableFuture().join();
}
Aggregations