Search in sources :

Example 16 with StateService

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();
}
Also used : StateDraft(io.sphere.sdk.states.StateDraft) StateService(com.commercetools.sync.services.StateService) StateSyncOptions(com.commercetools.sync.states.StateSyncOptions) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 17 with StateService

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));
}
Also used : StateDraft(io.sphere.sdk.states.StateDraft) StateService(com.commercetools.sync.services.StateService) ReferenceResolutionException(com.commercetools.sync.commons.exceptions.ReferenceResolutionException) StateSyncOptions(com.commercetools.sync.states.StateSyncOptions) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

StateService (com.commercetools.sync.services.StateService)17 StateDraft (io.sphere.sdk.states.StateDraft)16 Test (org.junit.jupiter.api.Test)16 StateSyncOptions (com.commercetools.sync.states.StateSyncOptions)11 State (io.sphere.sdk.states.State)11 HashSet (java.util.HashSet)11 SphereClient (io.sphere.sdk.client.SphereClient)9 StateDraftBuilder (io.sphere.sdk.states.StateDraftBuilder)9 StateType (io.sphere.sdk.states.StateType)9 Collections.singleton (java.util.Collections.singleton)9 List (java.util.List)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)9 Mockito.when (org.mockito.Mockito.when)9 StateServiceImpl (com.commercetools.sync.services.impl.StateServiceImpl)8 StateQuery (io.sphere.sdk.states.queries.StateQuery)8 ArrayList (java.util.ArrayList)8 Collections.singletonList (java.util.Collections.singletonList)8 Optional (java.util.Optional)8 Assertions.as (org.assertj.core.api.Assertions.as)8