Search in sources :

Example 11 with StateSyncStatistics

use of com.commercetools.sync.states.helpers.StateSyncStatistics in project commercetools-sync-java by commercetools.

the class StateSyncTest method sync_WithErrorFetchingExistingKeys_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter.

@Test
void sync_WithErrorFetchingExistingKeys_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter() {
    // preparation
    final StateDraft stateDraft = StateDraftBuilder.of("state-1", StateType.LINE_ITEM_STATE).build();
    final List<String> errorMessages = new ArrayList<>();
    final List<Throwable> exceptions = new ArrayList<>();
    final SphereClient mockClient = mock(SphereClient.class);
    when(mockClient.execute(any(StateQuery.class))).thenReturn(supplyAsync(() -> {
        throw new SphereException();
    }));
    final StateSyncOptions syncOptions = StateSyncOptionsBuilder.of(mockClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorMessages.add(exception.getMessage());
        exceptions.add(exception.getCause());
    }).build();
    final StateService stateService = spy(new StateServiceImpl(syncOptions));
    final Map<String, String> keyToIds = new HashMap<>();
    keyToIds.put(stateDraft.getKey(), UUID.randomUUID().toString());
    when(stateService.cacheKeysToIds(anySet())).thenReturn(completedFuture(keyToIds));
    final StateSync stateSync = new StateSync(syncOptions, stateService);
    // test
    final StateSyncStatistics stateSyncStatistics = stateSync.sync(singletonList(stateDraft)).toCompletableFuture().join();
    // assertions
    assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).contains("Failed to fetch existing states");
    assertThat(exceptions).hasSize(1).singleElement(as(THROWABLE)).isExactlyInstanceOf(CompletionException.class).hasCauseExactlyInstanceOf(SphereException.class);
    assertThat(stateSyncStatistics).hasValues(1, 0, 0, 1);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) StateSyncStatistics(com.commercetools.sync.states.helpers.StateSyncStatistics) StateQuery(io.sphere.sdk.states.queries.StateQuery) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Collections.singleton(java.util.Collections.singleton) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Arrays.asList(java.util.Arrays.asList) Assertions.as(org.assertj.core.api.Assertions.as) CompletableFuture.supplyAsync(java.util.concurrent.CompletableFuture.supplyAsync) Map(java.util.Map) THROWABLE(org.assertj.core.api.InstanceOfAssertFactories.THROWABLE) SphereClient(io.sphere.sdk.client.SphereClient) SphereException(io.sphere.sdk.models.SphereException) StateType(io.sphere.sdk.states.StateType) StateDraftBuilder(io.sphere.sdk.states.StateDraftBuilder) Collections.emptyMap(java.util.Collections.emptyMap) Collections.emptySet(java.util.Collections.emptySet) CompletionException(java.util.concurrent.CompletionException) Mockito.when(org.mockito.Mockito.when) StateService(com.commercetools.sync.services.StateService) UUID(java.util.UUID) StateServiceImpl(com.commercetools.sync.services.impl.StateServiceImpl) State(io.sphere.sdk.states.State) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) LocalizedString(io.sphere.sdk.models.LocalizedString) Mockito.never(org.mockito.Mockito.never) List(java.util.List) Optional(java.util.Optional) StateDraft(io.sphere.sdk.states.StateDraft) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) Mockito.mock(org.mockito.Mockito.mock) HashMap(java.util.HashMap) StateService(com.commercetools.sync.services.StateService) StateSyncStatistics(com.commercetools.sync.states.helpers.StateSyncStatistics) ArrayList(java.util.ArrayList) LocalizedString(io.sphere.sdk.models.LocalizedString) StateQuery(io.sphere.sdk.states.queries.StateQuery) SphereException(io.sphere.sdk.models.SphereException) StateServiceImpl(com.commercetools.sync.services.impl.StateServiceImpl) StateDraft(io.sphere.sdk.states.StateDraft) SphereClient(io.sphere.sdk.client.SphereClient) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.jupiter.api.Test)

Example 12 with StateSyncStatistics

use of com.commercetools.sync.states.helpers.StateSyncStatistics in project commercetools-sync-java by commercetools.

the class StateSyncIT method sync_WithExceptionOnResolvingTransition_ShouldUpdateTransitions.

@Test
void sync_WithExceptionOnResolvingTransition_ShouldUpdateTransitions() {
    final StateDraft stateCDraft = createStateDraft(keyC);
    final State stateC = createStateInSource(stateCDraft);
    final StateDraft stateBDraft = createStateDraft(keyB, stateC);
    final State stateB = createStateInSource(stateBDraft);
    final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
    when(spyClient.execute(any())).thenCallRealMethod().thenReturn(exceptionallyCompletedFuture(new BadGatewayException()));
    final StateSyncOptions stateSyncOptions = StateSyncOptionsBuilder.of(spyClient).batchSize(3).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(stateSyncOptions);
    final List<StateDraft> stateDrafts = StateTransformUtils.toStateDrafts(CTP_SOURCE_CLIENT, referenceIdToKeyCache, Arrays.asList(stateB, stateC)).join();
    // test
    final StateSyncStatistics stateSyncStatistics = stateSync.sync(stateDrafts).toCompletableFuture().join();
    assertThat(stateSyncStatistics).hasValues(2, 0, 0, 2, 0);
    Assertions.assertThat(errorCallBackExceptions).isNotEmpty();
    Assertions.assertThat(errorCallBackMessages).isNotEmpty();
    Assertions.assertThat(errorCallBackMessages.get(0)).contains("Failed to fetch existing states with keys");
    Assertions.assertThat(warningCallBackMessages).isEmpty();
}
Also used : CustomObjectQuery(io.sphere.sdk.customobjects.queries.CustomObjectQuery) BeforeEach(org.junit.jupiter.api.BeforeEach) StateSyncStatistics(com.commercetools.sync.states.helpers.StateSyncStatistics) Arrays(java.util.Arrays) Reference(io.sphere.sdk.models.Reference) CTP_SOURCE_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Collections.singletonList(java.util.Collections.singletonList) AfterAll(org.junit.jupiter.api.AfterAll) ReferenceIdToKeyCache(com.commercetools.sync.commons.utils.ReferenceIdToKeyCache) StateTransformUtils(com.commercetools.sync.states.utils.StateTransformUtils) StateCreateCommand(io.sphere.sdk.states.commands.StateCreateCommand) Arrays.asList(java.util.Arrays.asList) StateITUtils.getStateByKey(com.commercetools.sync.integration.commons.utils.StateITUtils.getStateByKey) SphereClient(io.sphere.sdk.client.SphereClient) CompletableFutureUtils.exceptionallyCompletedFuture(io.sphere.sdk.utils.CompletableFutureUtils.exceptionallyCompletedFuture) StateType(io.sphere.sdk.states.StateType) Assertions(org.assertj.core.api.Assertions) UnresolvedReferencesServiceImpl(com.commercetools.sync.services.impl.UnresolvedReferencesServiceImpl) BadGatewayException(io.sphere.sdk.client.BadGatewayException) ThreadLocalRandom.current(java.util.concurrent.ThreadLocalRandom.current) CompletionStageUtil.executeBlocking(com.commercetools.tests.utils.CompletionStageUtil.executeBlocking) ResourceKeyIdGraphQlRequest(com.commercetools.sync.commons.helpers.ResourceKeyIdGraphQlRequest) StateUpdateCommand(io.sphere.sdk.states.commands.StateUpdateCommand) Set(java.util.Set) StateServiceImpl(com.commercetools.sync.services.impl.StateServiceImpl) State(io.sphere.sdk.states.State) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) StateITUtils.deleteStatesFromTargetAndSource(com.commercetools.sync.integration.commons.utils.StateITUtils.deleteStatesFromTargetAndSource) Test(org.junit.jupiter.api.Test) LocalizedString(io.sphere.sdk.models.LocalizedString) List(java.util.List) CUSTOM_OBJECT_TRANSITION_CONTAINER_KEY(com.commercetools.sync.services.impl.UnresolvedReferencesServiceImpl.CUSTOM_OBJECT_TRANSITION_CONTAINER_KEY) LocalizedString.ofEnglish(io.sphere.sdk.models.LocalizedString.ofEnglish) CompletionStage(java.util.concurrent.CompletionStage) SphereInternalUtils.asSet(io.sphere.sdk.utils.SphereInternalUtils.asSet) Optional(java.util.Optional) StateDraft(io.sphere.sdk.states.StateDraft) StateITUtils.deleteStates(com.commercetools.sync.integration.commons.utils.StateITUtils.deleteStates) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) StateQuery(io.sphere.sdk.states.queries.StateQuery) BadRequestException(io.sphere.sdk.client.BadRequestException) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) Mockito.spy(org.mockito.Mockito.spy) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) State.referenceOfId(io.sphere.sdk.states.State.referenceOfId) StateReferenceResolver(com.commercetools.sync.states.helpers.StateReferenceResolver) UnresolvedReferencesService(com.commercetools.sync.services.UnresolvedReferencesService) StateRole(io.sphere.sdk.states.StateRole) Nonnull(javax.annotation.Nonnull) StateDraftBuilder(io.sphere.sdk.states.StateDraftBuilder) StateQueryBuilder(io.sphere.sdk.states.queries.StateQueryBuilder) StateSyncOptionsBuilder(com.commercetools.sync.states.StateSyncOptionsBuilder) CaffeineReferenceIdToKeyCacheImpl(com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl) StateSync(com.commercetools.sync.states.StateSync) Mockito.when(org.mockito.Mockito.when) StateSyncOptions(com.commercetools.sync.states.StateSyncOptions) CtpQueryUtils(com.commercetools.sync.commons.utils.CtpQueryUtils) WaitingToBeResolvedTransitions(com.commercetools.sync.commons.models.WaitingToBeResolvedTransitions) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) Collections(java.util.Collections) StateSync(com.commercetools.sync.states.StateSync) StateDraft(io.sphere.sdk.states.StateDraft) State(io.sphere.sdk.states.State) StateSyncStatistics(com.commercetools.sync.states.helpers.StateSyncStatistics) SphereClient(io.sphere.sdk.client.SphereClient) BadGatewayException(io.sphere.sdk.client.BadGatewayException) StateSyncOptions(com.commercetools.sync.states.StateSyncOptions) Test(org.junit.jupiter.api.Test)

Example 13 with StateSyncStatistics

use of com.commercetools.sync.states.helpers.StateSyncStatistics in project commercetools-sync-java by commercetools.

the class StateSyncIT method sync_withNewStateWithNewRole_shouldAddRole.

@Test
void sync_withNewStateWithNewRole_shouldAddRole() {
    final StateDraft stateDraft = StateDraftBuilder.of(keyA, StateType.REVIEW_STATE).roles(asSet(StateRole.REVIEW_INCLUDED_IN_STATISTICS)).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().size()).isEqualTo(1);
    }).toCompletableFuture().join();
}
Also used : CustomObjectQuery(io.sphere.sdk.customobjects.queries.CustomObjectQuery) BeforeEach(org.junit.jupiter.api.BeforeEach) StateSyncStatistics(com.commercetools.sync.states.helpers.StateSyncStatistics) Arrays(java.util.Arrays) Reference(io.sphere.sdk.models.Reference) CTP_SOURCE_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Collections.singletonList(java.util.Collections.singletonList) AfterAll(org.junit.jupiter.api.AfterAll) ReferenceIdToKeyCache(com.commercetools.sync.commons.utils.ReferenceIdToKeyCache) StateTransformUtils(com.commercetools.sync.states.utils.StateTransformUtils) StateCreateCommand(io.sphere.sdk.states.commands.StateCreateCommand) Arrays.asList(java.util.Arrays.asList) StateITUtils.getStateByKey(com.commercetools.sync.integration.commons.utils.StateITUtils.getStateByKey) SphereClient(io.sphere.sdk.client.SphereClient) CompletableFutureUtils.exceptionallyCompletedFuture(io.sphere.sdk.utils.CompletableFutureUtils.exceptionallyCompletedFuture) StateType(io.sphere.sdk.states.StateType) Assertions(org.assertj.core.api.Assertions) UnresolvedReferencesServiceImpl(com.commercetools.sync.services.impl.UnresolvedReferencesServiceImpl) BadGatewayException(io.sphere.sdk.client.BadGatewayException) ThreadLocalRandom.current(java.util.concurrent.ThreadLocalRandom.current) CompletionStageUtil.executeBlocking(com.commercetools.tests.utils.CompletionStageUtil.executeBlocking) ResourceKeyIdGraphQlRequest(com.commercetools.sync.commons.helpers.ResourceKeyIdGraphQlRequest) StateUpdateCommand(io.sphere.sdk.states.commands.StateUpdateCommand) Set(java.util.Set) StateServiceImpl(com.commercetools.sync.services.impl.StateServiceImpl) State(io.sphere.sdk.states.State) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) StateITUtils.deleteStatesFromTargetAndSource(com.commercetools.sync.integration.commons.utils.StateITUtils.deleteStatesFromTargetAndSource) Test(org.junit.jupiter.api.Test) LocalizedString(io.sphere.sdk.models.LocalizedString) List(java.util.List) CUSTOM_OBJECT_TRANSITION_CONTAINER_KEY(com.commercetools.sync.services.impl.UnresolvedReferencesServiceImpl.CUSTOM_OBJECT_TRANSITION_CONTAINER_KEY) LocalizedString.ofEnglish(io.sphere.sdk.models.LocalizedString.ofEnglish) CompletionStage(java.util.concurrent.CompletionStage) SphereInternalUtils.asSet(io.sphere.sdk.utils.SphereInternalUtils.asSet) Optional(java.util.Optional) StateDraft(io.sphere.sdk.states.StateDraft) StateITUtils.deleteStates(com.commercetools.sync.integration.commons.utils.StateITUtils.deleteStates) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) StateQuery(io.sphere.sdk.states.queries.StateQuery) BadRequestException(io.sphere.sdk.client.BadRequestException) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) Mockito.spy(org.mockito.Mockito.spy) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) State.referenceOfId(io.sphere.sdk.states.State.referenceOfId) StateReferenceResolver(com.commercetools.sync.states.helpers.StateReferenceResolver) UnresolvedReferencesService(com.commercetools.sync.services.UnresolvedReferencesService) StateRole(io.sphere.sdk.states.StateRole) Nonnull(javax.annotation.Nonnull) StateDraftBuilder(io.sphere.sdk.states.StateDraftBuilder) StateQueryBuilder(io.sphere.sdk.states.queries.StateQueryBuilder) StateSyncOptionsBuilder(com.commercetools.sync.states.StateSyncOptionsBuilder) CaffeineReferenceIdToKeyCacheImpl(com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl) StateSync(com.commercetools.sync.states.StateSync) Mockito.when(org.mockito.Mockito.when) StateSyncOptions(com.commercetools.sync.states.StateSyncOptions) CtpQueryUtils(com.commercetools.sync.commons.utils.CtpQueryUtils) WaitingToBeResolvedTransitions(com.commercetools.sync.commons.models.WaitingToBeResolvedTransitions) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) Collections(java.util.Collections) StateSync(com.commercetools.sync.states.StateSync) StateDraft(io.sphere.sdk.states.StateDraft) StateSyncStatistics(com.commercetools.sync.states.helpers.StateSyncStatistics) StateSyncOptions(com.commercetools.sync.states.StateSyncOptions) Test(org.junit.jupiter.api.Test)

Example 14 with StateSyncStatistics

use of com.commercetools.sync.states.helpers.StateSyncStatistics in project commercetools-sync-java by commercetools.

the class StateSyncTest method sync_WithInvalidDrafts_ShouldCompleteWithoutAnyProcessing.

@Test
void sync_WithInvalidDrafts_ShouldCompleteWithoutAnyProcessing() {
    // preparation
    final SphereClient ctpClient = mock(SphereClient.class);
    final List<String> errors = new ArrayList<>();
    final StateSyncOptions stateSyncOptions = StateSyncOptionsBuilder.of(ctpClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errors.add(exception.getMessage());
    }).build();
    final StateService stateService = mock(StateService.class);
    final StateSync stateSync = new StateSync(stateSyncOptions, stateService);
    final StateDraft stateDraftWithoutKey = StateDraftBuilder.of(null, StateType.LINE_ITEM_STATE).name(LocalizedString.ofEnglish("state-name")).build();
    // test
    final StateSyncStatistics statistics = stateSync.sync(asList(stateDraftWithoutKey, null)).toCompletableFuture().join();
    // assertion
    verifyNoMoreInteractions(ctpClient);
    verifyNoMoreInteractions(stateService);
    assertThat(errors).hasSize(2);
    assertThat(errors).containsExactly("StateDraft with name: LocalizedString(en -> state-name) doesn't have a key. " + "Please make sure all state drafts have keys.", "StateDraft is null.");
    assertThat(statistics).hasValues(2, 0, 0, 2, 0);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) StateSyncStatistics(com.commercetools.sync.states.helpers.StateSyncStatistics) StateQuery(io.sphere.sdk.states.queries.StateQuery) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Collections.singleton(java.util.Collections.singleton) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Arrays.asList(java.util.Arrays.asList) Assertions.as(org.assertj.core.api.Assertions.as) CompletableFuture.supplyAsync(java.util.concurrent.CompletableFuture.supplyAsync) Map(java.util.Map) THROWABLE(org.assertj.core.api.InstanceOfAssertFactories.THROWABLE) SphereClient(io.sphere.sdk.client.SphereClient) SphereException(io.sphere.sdk.models.SphereException) StateType(io.sphere.sdk.states.StateType) StateDraftBuilder(io.sphere.sdk.states.StateDraftBuilder) Collections.emptyMap(java.util.Collections.emptyMap) Collections.emptySet(java.util.Collections.emptySet) CompletionException(java.util.concurrent.CompletionException) Mockito.when(org.mockito.Mockito.when) StateService(com.commercetools.sync.services.StateService) UUID(java.util.UUID) StateServiceImpl(com.commercetools.sync.services.impl.StateServiceImpl) State(io.sphere.sdk.states.State) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) LocalizedString(io.sphere.sdk.models.LocalizedString) Mockito.never(org.mockito.Mockito.never) List(java.util.List) Optional(java.util.Optional) StateDraft(io.sphere.sdk.states.StateDraft) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) Mockito.mock(org.mockito.Mockito.mock) StateDraft(io.sphere.sdk.states.StateDraft) StateService(com.commercetools.sync.services.StateService) StateSyncStatistics(com.commercetools.sync.states.helpers.StateSyncStatistics) SphereClient(io.sphere.sdk.client.SphereClient) ArrayList(java.util.ArrayList) LocalizedString(io.sphere.sdk.models.LocalizedString) Test(org.junit.jupiter.api.Test)

Example 15 with StateSyncStatistics

use of com.commercetools.sync.states.helpers.StateSyncStatistics 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());
}
Also used : StateSync(com.commercetools.sync.states.StateSync) StateDraft(io.sphere.sdk.states.StateDraft) StateSyncStatistics(com.commercetools.sync.states.helpers.StateSyncStatistics) State(io.sphere.sdk.states.State) LocalizedString(io.sphere.sdk.models.LocalizedString) StateSyncOptions(com.commercetools.sync.states.StateSyncOptions) Test(org.junit.jupiter.api.Test)

Aggregations

StateSyncStatistics (com.commercetools.sync.states.helpers.StateSyncStatistics)29 Test (org.junit.jupiter.api.Test)29 StateDraft (io.sphere.sdk.states.StateDraft)28 StateSync (com.commercetools.sync.states.StateSync)26 StateSyncOptions (com.commercetools.sync.states.StateSyncOptions)26 State (io.sphere.sdk.states.State)25 LocalizedString (io.sphere.sdk.models.LocalizedString)24 SphereClient (io.sphere.sdk.client.SphereClient)23 ArrayList (java.util.ArrayList)23 AssertionsForStatistics.assertThat (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat)22 StateServiceImpl (com.commercetools.sync.services.impl.StateServiceImpl)22 StateDraftBuilder (io.sphere.sdk.states.StateDraftBuilder)22 StateType (io.sphere.sdk.states.StateType)22 StateQuery (io.sphere.sdk.states.queries.StateQuery)22 Arrays.asList (java.util.Arrays.asList)22 Collections.singletonList (java.util.Collections.singletonList)22 List (java.util.List)22 Optional (java.util.Optional)22 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)22 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)22