use of com.commercetools.sync.states.StateSyncOptions in project commercetools-sync-java by commercetools.
the class StateReferenceResolverTest method resolveReferences_WithNullStateReferences_ShouldNotResolveReferences.
@Test
void resolveReferences_WithNullStateReferences_ShouldNotResolveReferences() {
// preparation
final StateSyncOptions stateSyncOptions = StateSyncOptionsBuilder.of(mock(SphereClient.class)).build();
final StateService mockStateService = mock(StateService.class);
when(mockStateService.fetchMatchingStatesByKeysWithTransitions(any())).thenReturn(CompletableFuture.completedFuture(new HashSet<>()));
final StateDraft stateDraft = StateDraftBuilder.of("state-key", StateType.LINE_ITEM_STATE).build();
final StateReferenceResolver stateReferenceResolver = new StateReferenceResolver(stateSyncOptions, mockStateService);
// test and assertion
assertThat(stateReferenceResolver.resolveReferences(stateDraft).toCompletableFuture()).isCompletedWithValueMatching(resolvedDraft -> resolvedDraft.getTransitions() == null);
}
use of com.commercetools.sync.states.StateSyncOptions in project commercetools-sync-java by commercetools.
the class StateReferenceResolverTest method resolveReferences_WithNullTransitionOnTransitionsList_ShouldNotFail.
@Test
void resolveReferences_WithNullTransitionOnTransitionsList_ShouldNotFail() {
// preparation
final StateSyncOptions stateSyncOptions = StateSyncOptionsBuilder.of(mock(SphereClient.class)).build();
final StateService mockStateService = mock(StateService.class);
when(mockStateService.fetchMatchingStatesByKeysWithTransitions(any())).thenReturn(CompletableFuture.completedFuture(new HashSet<>()));
final StateDraft stateDraft = StateDraftBuilder.of("state-key", StateType.LINE_ITEM_STATE).transitions(singleton(null)).build();
final StateReferenceResolver stateReferenceResolver = new StateReferenceResolver(stateSyncOptions, mockStateService);
assertThat(stateReferenceResolver.resolveReferences(stateDraft).toCompletableFuture()).isCompleted();
}
use of com.commercetools.sync.states.StateSyncOptions in project commercetools-sync-java by commercetools.
the class StateReferenceResolverTest method resolveReferences_WithEmptyIdOnStateReference_ShouldNotResolveReference.
@Test
void resolveReferences_WithEmptyIdOnStateReference_ShouldNotResolveReference() {
// preparation
final StateSyncOptions stateSyncOptions = StateSyncOptionsBuilder.of(mock(SphereClient.class)).build();
final StateService mockStateService = mock(StateService.class);
when(mockStateService.fetchMatchingStatesByKeysWithTransitions(any())).thenReturn(CompletableFuture.completedFuture(new HashSet<>()));
final StateDraft stateDraft = StateDraftBuilder.of("state-key", StateType.LINE_ITEM_STATE).transitions(singleton(State.referenceOfId(""))).build();
final StateReferenceResolver stateReferenceResolver = new StateReferenceResolver(stateSyncOptions, mockStateService);
// test and assertion
assertThat(stateReferenceResolver.resolveReferences(stateDraft).toCompletableFuture()).failsWithin(1, TimeUnit.SECONDS).withThrowableOfType(ExecutionException.class).withCauseExactlyInstanceOf(ReferenceResolutionException.class).withMessageContaining(format("Failed to resolve 'transition' reference on StateDraft with " + "key:'%s'. Reason: %s", stateDraft.getKey(), BLANK_ID_VALUE_ON_REFERENCE));
}
use of com.commercetools.sync.states.StateSyncOptions in project commercetools-sync-java by commercetools.
the class StateSyncIT method sync_WithUpdatedState_ShouldUpdateState.
@Test
void sync_WithUpdatedState_ShouldUpdateState() {
// preparation
String key = this.key;
final StateDraft stateDraft = StateDraftBuilder.of(key, StateType.REVIEW_STATE).name(ofEnglish("state-name-updated")).description(ofEnglish("state-desc-updated")).roles(Collections.singleton(StateRole.REVIEW_INCLUDED_IN_STATISTICS)).initial(true).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();
// assertion
assertThat(stateSyncStatistics).hasValues(1, 0, 1, 0, 0);
final Optional<State> oldStateAfter = getStateByKey(CTP_TARGET_CLIENT, key);
Assertions.assertThat(oldStateAfter).hasValueSatisfying(state -> {
Assertions.assertThat(state.getType()).isEqualTo(StateType.REVIEW_STATE);
Assertions.assertThat(state.getName()).isEqualTo(ofEnglish("state-name-updated"));
Assertions.assertThat(state.getDescription()).isEqualTo(ofEnglish("state-desc-updated"));
Assertions.assertThat(state.getRoles()).isEqualTo(Collections.singleton(StateRole.REVIEW_INCLUDED_IN_STATISTICS));
Assertions.assertThat(state.isInitial()).isEqualTo(true);
});
deleteStates(CTP_TARGET_CLIENT, Optional.empty());
}
use of com.commercetools.sync.states.StateSyncOptions in project commercetools-sync-java by commercetools.
the class StateSyncIT method sync_WithConcurrentModificationExceptionAndFailedFetch_ShouldFailToReFetchAndUpdate.
@Test
void sync_WithConcurrentModificationExceptionAndFailedFetch_ShouldFailToReFetchAndUpdate() {
// preparation
final SphereClient spyClient = buildClientWithConcurrentModificationUpdateAndFailedFetchOnRetry();
final StateSyncOptions spyOptions = StateSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception.getCause());
}).warningCallback((exception, newResource, oldResource) -> warningCallBackMessages.add(exception.getMessage())).build();
final StateSync stateSync = new StateSync(spyOptions);
final StateDraft stateDraft = StateDraftBuilder.of(key, StateType.REVIEW_STATE).name(ofEnglish("state-name-updated")).description(ofEnglish("state-desc-updated")).roles(Collections.singleton(StateRole.REVIEW_INCLUDED_IN_STATISTICS)).initial(true).build();
final StateSyncStatistics syncStatistics = executeBlocking(stateSync.sync(singletonList(stateDraft)));
// Test and assertion
assertThat(syncStatistics).hasValues(1, 0, 0, 1, 0);
Assertions.assertThat(errorCallBackMessages).hasSize(1);
Assertions.assertThat(errorCallBackExceptions).hasSize(1);
Assertions.assertThat(errorCallBackExceptions.get(0).getCause()).isExactlyInstanceOf(BadGatewayException.class);
Assertions.assertThat(errorCallBackMessages.get(0)).contains(format("Failed to update state with key: '%s'. Reason: Failed to fetch from CTP while retrying " + "after concurrency modification.", stateDraft.getKey()));
}
Aggregations