use of com.commercetools.sync.services.StateService 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.services.StateService 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));
}
Aggregations