Search in sources :

Example 1 with TYPE_NAME_1

use of com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_1 in project commercetools-sync-java by commercetools.

the class TypeSyncIT method sync_WithoutKey_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter.

@Test
void sync_WithoutKey_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter() {
    final TypeDraft newTypeDraft = TypeDraftBuilder.of(null, TYPE_NAME_1, ResourceTypeIdsSetBuilder.of().addCategories().build()).description(TYPE_DESCRIPTION_1).fieldDefinitions(asList(FIELD_DEFINITION_1, FIELD_DEFINITION_2)).build();
    final List<String> errorMessages = new ArrayList<>();
    final List<Throwable> exceptions = new ArrayList<>();
    final TypeSyncOptions typeSyncOptions = TypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorMessages.add(exception.getMessage());
        exceptions.add(exception.getCause());
    }).build();
    final TypeSync typeSync = new TypeSync(typeSyncOptions);
    // test
    final TypeSyncStatistics typeSyncStatistics = typeSync.sync(singletonList(newTypeDraft)).toCompletableFuture().join();
    // assertions
    assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).isEqualTo("TypeDraft with name: LocalizedString(en -> name_1) doesn't have a key. " + "Please make sure all type drafts have keys.");
    assertThat(exceptions).hasSize(1).singleElement().isNull();
    assertThat(typeSyncStatistics).hasValues(1, 0, 0, 1);
}
Also used : TypeDraft(io.sphere.sdk.types.TypeDraft) BeforeEach(org.junit.jupiter.api.BeforeEach) TYPE_DESCRIPTION_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_DESCRIPTION_1) TYPE_DESCRIPTION_2(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_DESCRIPTION_2) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collections.singletonList(java.util.Collections.singletonList) FieldDefinition(io.sphere.sdk.types.FieldDefinition) LocalizedEnumFieldType(io.sphere.sdk.types.LocalizedEnumFieldType) AfterAll(org.junit.jupiter.api.AfterAll) FIELD_DEFINITION_LABEL_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_LABEL_1) Arrays.asList(java.util.Arrays.asList) SphereClient(io.sphere.sdk.client.SphereClient) CompletableFutureUtils.exceptionallyCompletedFuture(io.sphere.sdk.utils.CompletableFutureUtils.exceptionallyCompletedFuture) EnumValue(io.sphere.sdk.models.EnumValue) ITUtils.deleteTypes(com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypes) BadGatewayException(io.sphere.sdk.client.BadGatewayException) TypeSyncStatistics(com.commercetools.sync.types.helpers.TypeSyncStatistics) TypeSync(com.commercetools.sync.types.TypeSync) CompletionException(java.util.concurrent.CompletionException) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) FIELD_DEFINITION_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_1) Test(org.junit.jupiter.api.Test) TYPE_KEY_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_KEY_1) LocalizedString(io.sphere.sdk.models.LocalizedString) FIELD_DEFINITION_3(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_3) List(java.util.List) FIELD_DEFINITION_2(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_2) LocalizedString.ofEnglish(io.sphere.sdk.models.LocalizedString.ofEnglish) TextInputHint(io.sphere.sdk.models.TextInputHint) TYPE_KEY_2(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_KEY_2) TypeITUtils.populateTargetProject(com.commercetools.sync.integration.commons.utils.TypeITUtils.populateTargetProject) Optional(java.util.Optional) Mockito.any(org.mockito.Mockito.any) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) IntStream(java.util.stream.IntStream) TypeSyncOptionsBuilder(com.commercetools.sync.types.TypeSyncOptionsBuilder) TypeUpdateCommand(io.sphere.sdk.types.commands.TypeUpdateCommand) ResourceTypeIdsSetBuilder(io.sphere.sdk.types.ResourceTypeIdsSetBuilder) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) ArrayList(java.util.ArrayList) Assertions.as(org.assertj.core.api.Assertions.as) TypeQuery(io.sphere.sdk.types.queries.TypeQuery) TypeDraftBuilder(io.sphere.sdk.types.TypeDraftBuilder) Nonnull(javax.annotation.Nonnull) StringFieldType(io.sphere.sdk.types.StringFieldType) TYPE_NAME_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_1) FIELD_DEFINITION_NAME_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_NAME_1) TYPE_NAME_2(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_2) TypeCreateCommand(io.sphere.sdk.types.commands.TypeCreateCommand) LocalizedEnumValue(io.sphere.sdk.models.LocalizedEnumValue) Mockito.when(org.mockito.Mockito.when) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) EnumFieldType(io.sphere.sdk.types.EnumFieldType) TypeITUtils.getTypeByKey(com.commercetools.sync.integration.commons.utils.TypeITUtils.getTypeByKey) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) Collections(java.util.Collections) SetFieldType(io.sphere.sdk.types.SetFieldType) Type(io.sphere.sdk.types.Type) ArrayList(java.util.ArrayList) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) LocalizedString(io.sphere.sdk.models.LocalizedString) TypeSyncStatistics(com.commercetools.sync.types.helpers.TypeSyncStatistics) TypeDraft(io.sphere.sdk.types.TypeDraft) TypeSync(com.commercetools.sync.types.TypeSync) Test(org.junit.jupiter.api.Test)

Example 2 with TYPE_NAME_1

use of com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_1 in project commercetools-sync-java by commercetools.

the class TypeServiceImplIT method createType_WithInvalidType_ShouldHaveEmptyOptionalAsAResult.

@Test
void createType_WithInvalidType_ShouldHaveEmptyOptionalAsAResult() {
    // preparation
    final TypeDraft newTypeDraft = TypeDraftBuilder.of("", TYPE_NAME_1, ResourceTypeIdsSetBuilder.of().addCategories().build()).description(TYPE_DESCRIPTION_1).fieldDefinitions(singletonList(FIELD_DEFINITION_1)).build();
    final TypeSyncOptions options = TypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception.getCause());
    }).build();
    final TypeService typeService = new TypeServiceImpl(options);
    // test
    final Optional<Type> result = typeService.createType(newTypeDraft).toCompletableFuture().join();
    // assertion
    assertThat(result).isEmpty();
    assertThat(errorCallBackMessages).containsExactly("Failed to create draft with key: ''. Reason: Draft key is blank!");
}
Also used : TypeDraft(io.sphere.sdk.types.TypeDraft) BeforeEach(org.junit.jupiter.api.BeforeEach) TYPE_DESCRIPTION_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_DESCRIPTION_1) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StringUtils(org.apache.commons.lang3.StringUtils) Collections.singletonList(java.util.Collections.singletonList) AfterAll(org.junit.jupiter.api.AfterAll) Collections.singleton(java.util.Collections.singleton) Locale(java.util.Locale) SphereClient(io.sphere.sdk.client.SphereClient) ChangeKey(io.sphere.sdk.types.commands.updateactions.ChangeKey) BadGatewayException(io.sphere.sdk.client.BadGatewayException) CompletionStageUtil.executeBlocking(com.commercetools.tests.utils.CompletionStageUtil.executeBlocking) Set(java.util.Set) FIELD_DEFINITION_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_1) Test(org.junit.jupiter.api.Test) TYPE_KEY_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_KEY_1) List(java.util.List) LocalizedString.ofEnglish(io.sphere.sdk.models.LocalizedString.ofEnglish) Optional(java.util.Optional) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TypeSyncOptionsBuilder(com.commercetools.sync.types.TypeSyncOptionsBuilder) ResourceTypeIdsSetBuilder(io.sphere.sdk.types.ResourceTypeIdsSetBuilder) Mockito.spy(org.mockito.Mockito.spy) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) DuplicateFieldError(io.sphere.sdk.models.errors.DuplicateFieldError) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Assertions.as(org.assertj.core.api.Assertions.as) TypeService(com.commercetools.sync.services.TypeService) TypeQuery(io.sphere.sdk.types.queries.TypeQuery) TypeDraftBuilder(io.sphere.sdk.types.TypeDraftBuilder) TYPE_NAME_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_1) CategoryITUtils.deleteAllCategories(com.commercetools.sync.integration.commons.utils.CategoryITUtils.deleteAllCategories) CategoryITUtils.createCategoriesCustomType(com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) TypeServiceImpl(com.commercetools.sync.services.impl.TypeServiceImpl) ChangeName(io.sphere.sdk.types.commands.updateactions.ChangeName) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) TypeITUtils.deleteTypes(com.commercetools.sync.integration.commons.utils.TypeITUtils.deleteTypes) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) Collections(java.util.Collections) Type(io.sphere.sdk.types.Type) CategoryITUtils.createCategoriesCustomType(com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType) Type(io.sphere.sdk.types.Type) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) TypeServiceImpl(com.commercetools.sync.services.impl.TypeServiceImpl) TypeDraft(io.sphere.sdk.types.TypeDraft) TypeService(com.commercetools.sync.services.TypeService) Test(org.junit.jupiter.api.Test)

Example 3 with TYPE_NAME_1

use of com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_1 in project commercetools-sync-java by commercetools.

the class TypeServiceImplIT method createType_WithDuplicateKey_ShouldHaveEmptyOptionalAsAResult.

@Test
void createType_WithDuplicateKey_ShouldHaveEmptyOptionalAsAResult() {
    // preparation
    final TypeDraft newTypeDraft = TypeDraftBuilder.of(OLD_TYPE_KEY, TYPE_NAME_1, ResourceTypeIdsSetBuilder.of().addCategories().build()).description(TYPE_DESCRIPTION_1).fieldDefinitions(singletonList(FIELD_DEFINITION_1)).build();
    final TypeSyncOptions options = TypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception.getCause());
    }).build();
    final TypeService typeService = new TypeServiceImpl(options);
    // test
    final Optional<Type> result = typeService.createType(newTypeDraft).toCompletableFuture().join();
    // assertion
    assertThat(result).isEmpty();
    assertThat(errorCallBackMessages).hasSize(1).singleElement(as(STRING)).contains("A duplicate value");
    assertThat(errorCallBackExceptions).hasSize(1).singleElement().matches(exception -> {
        assertThat(exception).isExactlyInstanceOf(ErrorResponseException.class);
        final ErrorResponseException errorResponseException = (ErrorResponseException) exception;
        final List<DuplicateFieldError> fieldErrors = errorResponseException.getErrors().stream().map(sphereError -> {
            assertThat(sphereError.getCode()).isEqualTo(DuplicateFieldError.CODE);
            return sphereError.as(DuplicateFieldError.class);
        }).collect(toList());
        return fieldErrors.size() == 1;
    });
}
Also used : TypeDraft(io.sphere.sdk.types.TypeDraft) BeforeEach(org.junit.jupiter.api.BeforeEach) TYPE_DESCRIPTION_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_DESCRIPTION_1) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StringUtils(org.apache.commons.lang3.StringUtils) Collections.singletonList(java.util.Collections.singletonList) AfterAll(org.junit.jupiter.api.AfterAll) Collections.singleton(java.util.Collections.singleton) Locale(java.util.Locale) SphereClient(io.sphere.sdk.client.SphereClient) ChangeKey(io.sphere.sdk.types.commands.updateactions.ChangeKey) BadGatewayException(io.sphere.sdk.client.BadGatewayException) CompletionStageUtil.executeBlocking(com.commercetools.tests.utils.CompletionStageUtil.executeBlocking) Set(java.util.Set) FIELD_DEFINITION_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_1) Test(org.junit.jupiter.api.Test) TYPE_KEY_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_KEY_1) List(java.util.List) LocalizedString.ofEnglish(io.sphere.sdk.models.LocalizedString.ofEnglish) Optional(java.util.Optional) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TypeSyncOptionsBuilder(com.commercetools.sync.types.TypeSyncOptionsBuilder) ResourceTypeIdsSetBuilder(io.sphere.sdk.types.ResourceTypeIdsSetBuilder) Mockito.spy(org.mockito.Mockito.spy) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) DuplicateFieldError(io.sphere.sdk.models.errors.DuplicateFieldError) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Assertions.as(org.assertj.core.api.Assertions.as) TypeService(com.commercetools.sync.services.TypeService) TypeQuery(io.sphere.sdk.types.queries.TypeQuery) TypeDraftBuilder(io.sphere.sdk.types.TypeDraftBuilder) TYPE_NAME_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_1) CategoryITUtils.deleteAllCategories(com.commercetools.sync.integration.commons.utils.CategoryITUtils.deleteAllCategories) CategoryITUtils.createCategoriesCustomType(com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) TypeServiceImpl(com.commercetools.sync.services.impl.TypeServiceImpl) ChangeName(io.sphere.sdk.types.commands.updateactions.ChangeName) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) TypeITUtils.deleteTypes(com.commercetools.sync.integration.commons.utils.TypeITUtils.deleteTypes) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) Collections(java.util.Collections) Type(io.sphere.sdk.types.Type) CategoryITUtils.createCategoriesCustomType(com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType) Type(io.sphere.sdk.types.Type) DuplicateFieldError(io.sphere.sdk.models.errors.DuplicateFieldError) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) TypeServiceImpl(com.commercetools.sync.services.impl.TypeServiceImpl) TypeDraft(io.sphere.sdk.types.TypeDraft) TypeService(com.commercetools.sync.services.TypeService) Test(org.junit.jupiter.api.Test)

Example 4 with TYPE_NAME_1

use of com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_1 in project commercetools-sync-java by commercetools.

the class TypeServiceImplIT method createType_WithValidType_ShouldCreateTypeAndCacheId.

@Test
void createType_WithValidType_ShouldCreateTypeAndCacheId() {
    final TypeDraft newTypeDraft = TypeDraftBuilder.of(TYPE_KEY_1, TYPE_NAME_1, ResourceTypeIdsSetBuilder.of().addCategories().build()).description(TYPE_DESCRIPTION_1).fieldDefinitions(singletonList(FIELD_DEFINITION_1)).build();
    final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
    final TypeSyncOptions spyOptions = TypeSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception.getCause());
    }).build();
    final TypeService spyTypeService = new TypeServiceImpl(spyOptions);
    // test
    final Optional<Type> createdType = spyTypeService.createType(newTypeDraft).toCompletableFuture().join();
    final Optional<Type> queriedOptional = CTP_TARGET_CLIENT.execute(TypeQuery.of().withPredicates(typeQueryModel -> typeQueryModel.key().is(TYPE_KEY_1))).toCompletableFuture().join().head();
    assertThat(queriedOptional).hasValueSatisfying(queried -> assertThat(createdType).hasValueSatisfying(created -> {
        assertThat(created.getKey()).isEqualTo(queried.getKey());
        assertThat(created.getDescription()).isEqualTo(queried.getDescription());
        assertThat(created.getName()).isEqualTo(queried.getName());
        assertThat(created.getFieldDefinitions()).isEqualTo(queried.getFieldDefinitions());
    }));
    // Assert that the created type is cached
    final Optional<String> typeId = spyTypeService.fetchCachedTypeId(TYPE_KEY_1).toCompletableFuture().join();
    assertThat(typeId).isPresent();
    verify(spyClient, times(0)).execute(any(TypeQuery.class));
}
Also used : TypeDraft(io.sphere.sdk.types.TypeDraft) BeforeEach(org.junit.jupiter.api.BeforeEach) TYPE_DESCRIPTION_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_DESCRIPTION_1) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StringUtils(org.apache.commons.lang3.StringUtils) Collections.singletonList(java.util.Collections.singletonList) AfterAll(org.junit.jupiter.api.AfterAll) Collections.singleton(java.util.Collections.singleton) Locale(java.util.Locale) SphereClient(io.sphere.sdk.client.SphereClient) ChangeKey(io.sphere.sdk.types.commands.updateactions.ChangeKey) BadGatewayException(io.sphere.sdk.client.BadGatewayException) CompletionStageUtil.executeBlocking(com.commercetools.tests.utils.CompletionStageUtil.executeBlocking) Set(java.util.Set) FIELD_DEFINITION_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_1) Test(org.junit.jupiter.api.Test) TYPE_KEY_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_KEY_1) List(java.util.List) LocalizedString.ofEnglish(io.sphere.sdk.models.LocalizedString.ofEnglish) Optional(java.util.Optional) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TypeSyncOptionsBuilder(com.commercetools.sync.types.TypeSyncOptionsBuilder) ResourceTypeIdsSetBuilder(io.sphere.sdk.types.ResourceTypeIdsSetBuilder) Mockito.spy(org.mockito.Mockito.spy) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) DuplicateFieldError(io.sphere.sdk.models.errors.DuplicateFieldError) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Assertions.as(org.assertj.core.api.Assertions.as) TypeService(com.commercetools.sync.services.TypeService) TypeQuery(io.sphere.sdk.types.queries.TypeQuery) TypeDraftBuilder(io.sphere.sdk.types.TypeDraftBuilder) TYPE_NAME_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_1) CategoryITUtils.deleteAllCategories(com.commercetools.sync.integration.commons.utils.CategoryITUtils.deleteAllCategories) CategoryITUtils.createCategoriesCustomType(com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) TypeServiceImpl(com.commercetools.sync.services.impl.TypeServiceImpl) ChangeName(io.sphere.sdk.types.commands.updateactions.ChangeName) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) TypeITUtils.deleteTypes(com.commercetools.sync.integration.commons.utils.TypeITUtils.deleteTypes) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) Collections(java.util.Collections) Type(io.sphere.sdk.types.Type) CategoryITUtils.createCategoriesCustomType(com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType) Type(io.sphere.sdk.types.Type) SphereClient(io.sphere.sdk.client.SphereClient) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) TypeServiceImpl(com.commercetools.sync.services.impl.TypeServiceImpl) TypeQuery(io.sphere.sdk.types.queries.TypeQuery) TypeDraft(io.sphere.sdk.types.TypeDraft) TypeService(com.commercetools.sync.services.TypeService) Test(org.junit.jupiter.api.Test)

Example 5 with TYPE_NAME_1

use of com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_1 in project commercetools-sync-java by commercetools.

the class TypeSyncIT method sync_WithConcurrentModificationException_ShouldRetryToUpdateNewTypeWithSuccess.

@Test
void sync_WithConcurrentModificationException_ShouldRetryToUpdateNewTypeWithSuccess() {
    // Preparation
    final SphereClient spyClient = buildClientWithConcurrentModificationUpdate();
    final TypeDraft typeDraft = TypeDraftBuilder.of(TYPE_KEY_2, TYPE_NAME_2, ResourceTypeIdsSetBuilder.of().addChannels()).build();
    CTP_TARGET_CLIENT.execute(TypeCreateCommand.of(typeDraft)).toCompletableFuture().join();
    final TypeDraft updatedDraft = TypeDraftBuilder.of(typeDraft).name(TYPE_NAME_1).build();
    final TypeSyncOptions typeSyncOptions = TypeSyncOptionsBuilder.of(spyClient).build();
    final TypeSync typeSync = new TypeSync(typeSyncOptions);
    // test
    final TypeSyncStatistics statistics = typeSync.sync(Collections.singletonList(updatedDraft)).toCompletableFuture().join();
    // assertion
    assertThat(statistics).hasValues(1, 0, 1, 0);
    // Assert CTP state.
    final PagedQueryResult<Type> queryResult = CTP_TARGET_CLIENT.execute(TypeQuery.of().plusPredicates(queryModel -> queryModel.key().is(typeDraft.getKey()))).toCompletableFuture().join();
    assertThat(queryResult.head()).hasValueSatisfying(type -> assertThat(type.getName()).isEqualTo(TYPE_NAME_1));
}
Also used : TypeDraft(io.sphere.sdk.types.TypeDraft) BeforeEach(org.junit.jupiter.api.BeforeEach) TYPE_DESCRIPTION_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_DESCRIPTION_1) TYPE_DESCRIPTION_2(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_DESCRIPTION_2) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collections.singletonList(java.util.Collections.singletonList) FieldDefinition(io.sphere.sdk.types.FieldDefinition) LocalizedEnumFieldType(io.sphere.sdk.types.LocalizedEnumFieldType) AfterAll(org.junit.jupiter.api.AfterAll) FIELD_DEFINITION_LABEL_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_LABEL_1) Arrays.asList(java.util.Arrays.asList) SphereClient(io.sphere.sdk.client.SphereClient) CompletableFutureUtils.exceptionallyCompletedFuture(io.sphere.sdk.utils.CompletableFutureUtils.exceptionallyCompletedFuture) EnumValue(io.sphere.sdk.models.EnumValue) ITUtils.deleteTypes(com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypes) BadGatewayException(io.sphere.sdk.client.BadGatewayException) TypeSyncStatistics(com.commercetools.sync.types.helpers.TypeSyncStatistics) TypeSync(com.commercetools.sync.types.TypeSync) CompletionException(java.util.concurrent.CompletionException) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) FIELD_DEFINITION_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_1) Test(org.junit.jupiter.api.Test) TYPE_KEY_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_KEY_1) LocalizedString(io.sphere.sdk.models.LocalizedString) FIELD_DEFINITION_3(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_3) List(java.util.List) FIELD_DEFINITION_2(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_2) LocalizedString.ofEnglish(io.sphere.sdk.models.LocalizedString.ofEnglish) TextInputHint(io.sphere.sdk.models.TextInputHint) TYPE_KEY_2(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_KEY_2) TypeITUtils.populateTargetProject(com.commercetools.sync.integration.commons.utils.TypeITUtils.populateTargetProject) Optional(java.util.Optional) Mockito.any(org.mockito.Mockito.any) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) IntStream(java.util.stream.IntStream) TypeSyncOptionsBuilder(com.commercetools.sync.types.TypeSyncOptionsBuilder) TypeUpdateCommand(io.sphere.sdk.types.commands.TypeUpdateCommand) ResourceTypeIdsSetBuilder(io.sphere.sdk.types.ResourceTypeIdsSetBuilder) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) ArrayList(java.util.ArrayList) Assertions.as(org.assertj.core.api.Assertions.as) TypeQuery(io.sphere.sdk.types.queries.TypeQuery) TypeDraftBuilder(io.sphere.sdk.types.TypeDraftBuilder) Nonnull(javax.annotation.Nonnull) StringFieldType(io.sphere.sdk.types.StringFieldType) TYPE_NAME_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_1) FIELD_DEFINITION_NAME_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_NAME_1) TYPE_NAME_2(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_2) TypeCreateCommand(io.sphere.sdk.types.commands.TypeCreateCommand) LocalizedEnumValue(io.sphere.sdk.models.LocalizedEnumValue) Mockito.when(org.mockito.Mockito.when) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) EnumFieldType(io.sphere.sdk.types.EnumFieldType) TypeITUtils.getTypeByKey(com.commercetools.sync.integration.commons.utils.TypeITUtils.getTypeByKey) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) Collections(java.util.Collections) SetFieldType(io.sphere.sdk.types.SetFieldType) Type(io.sphere.sdk.types.Type) LocalizedEnumFieldType(io.sphere.sdk.types.LocalizedEnumFieldType) StringFieldType(io.sphere.sdk.types.StringFieldType) EnumFieldType(io.sphere.sdk.types.EnumFieldType) SetFieldType(io.sphere.sdk.types.SetFieldType) Type(io.sphere.sdk.types.Type) SphereClient(io.sphere.sdk.client.SphereClient) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) TypeSyncStatistics(com.commercetools.sync.types.helpers.TypeSyncStatistics) TypeDraft(io.sphere.sdk.types.TypeDraft) TypeSync(com.commercetools.sync.types.TypeSync) Test(org.junit.jupiter.api.Test)

Aggregations

CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)5 FIELD_DEFINITION_1 (com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_1)5 TYPE_DESCRIPTION_1 (com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_DESCRIPTION_1)5 TYPE_KEY_1 (com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_KEY_1)5 TYPE_NAME_1 (com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_1)5 TypeSyncOptions (com.commercetools.sync.types.TypeSyncOptions)5 TypeSyncOptionsBuilder (com.commercetools.sync.types.TypeSyncOptionsBuilder)5 BadGatewayException (io.sphere.sdk.client.BadGatewayException)5 ErrorResponseException (io.sphere.sdk.client.ErrorResponseException)5 SphereClient (io.sphere.sdk.client.SphereClient)5 LocalizedString.ofEnglish (io.sphere.sdk.models.LocalizedString.ofEnglish)5 ResourceTypeIdsSetBuilder (io.sphere.sdk.types.ResourceTypeIdsSetBuilder)5 Type (io.sphere.sdk.types.Type)5 TypeDraft (io.sphere.sdk.types.TypeDraft)5 TypeDraftBuilder (io.sphere.sdk.types.TypeDraftBuilder)5 TypeQuery (io.sphere.sdk.types.queries.TypeQuery)5 ArrayList (java.util.ArrayList)5 Collections (java.util.Collections)5 Collections.singletonList (java.util.Collections.singletonList)5 List (java.util.List)5