Search in sources :

Example 1 with PRODUCT_TYPE_NAME_1

use of com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_NAME_1 in project commercetools-sync-java by commercetools.

the class ProductTypeServiceImplIT method createProductType_WithDuplicateKey_ShouldHaveEmptyOptionalAsAResult.

@Test
void createProductType_WithDuplicateKey_ShouldHaveEmptyOptionalAsAResult() {
    // preparation
    final ProductTypeDraft newProductTypeDraft = ProductTypeDraft.ofAttributeDefinitionDrafts(OLD_PRODUCT_TYPE_KEY, PRODUCT_TYPE_NAME_1, PRODUCT_TYPE_DESCRIPTION_1, singletonList(ATTRIBUTE_DEFINITION_DRAFT_1));
    final ProductTypeSyncOptions options = ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception.getCause());
    }).build();
    final ProductTypeService service = new ProductTypeServiceImpl(options);
    // test
    final Optional<ProductType> result = service.createProductType(newProductTypeDraft).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 : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProductType(io.sphere.sdk.producttypes.ProductType) Mockito.spy(org.mockito.Mockito.spy) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) DuplicateFieldError(io.sphere.sdk.models.errors.DuplicateFieldError) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) ProductTypeSyncOptionsBuilder(com.commercetools.sync.producttypes.ProductTypeSyncOptionsBuilder) HashSet(java.util.HashSet) AfterAll(org.junit.jupiter.api.AfterAll) Collections.singleton(java.util.Collections.singleton) Assertions.as(org.assertj.core.api.Assertions.as) Locale(java.util.Locale) ProductTypeService(com.commercetools.sync.services.ProductTypeService) Map(java.util.Map) SphereClient(io.sphere.sdk.client.SphereClient) PRODUCT_TYPE_KEY_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_KEY_1) ProductTypeITUtils.createProductType(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.createProductType) BadGatewayException(io.sphere.sdk.client.BadGatewayException) ProductTypeQuery(io.sphere.sdk.producttypes.queries.ProductTypeQuery) PRODUCT_TYPE_NAME_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_NAME_1) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) SetKey(io.sphere.sdk.producttypes.commands.updateactions.SetKey) Mockito.when(org.mockito.Mockito.when) AttributeMetaData(com.commercetools.sync.products.AttributeMetaData) ChangeName(io.sphere.sdk.producttypes.commands.updateactions.ChangeName) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ProductTypeServiceImpl(com.commercetools.sync.services.impl.ProductTypeServiceImpl) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) ProductTypeITUtils.deleteProductTypes(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.deleteProductTypes) Optional(java.util.Optional) PRODUCT_TYPE_DESCRIPTION_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_DESCRIPTION_1) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) Collections(java.util.Collections) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ATTRIBUTE_DEFINITION_DRAFT_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.ATTRIBUTE_DEFINITION_DRAFT_1) ProductTypeService(com.commercetools.sync.services.ProductTypeService) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) ProductType(io.sphere.sdk.producttypes.ProductType) ProductTypeITUtils.createProductType(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.createProductType) DuplicateFieldError(io.sphere.sdk.models.errors.DuplicateFieldError) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) ProductTypeServiceImpl(com.commercetools.sync.services.impl.ProductTypeServiceImpl) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) Test(org.junit.jupiter.api.Test)

Example 2 with PRODUCT_TYPE_NAME_1

use of com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_NAME_1 in project commercetools-sync-java by commercetools.

the class ProductTypeServiceImplIT method createProductType_WithValidProductType_ShouldCreateProductTypeAndCacheId.

@Test
void createProductType_WithValidProductType_ShouldCreateProductTypeAndCacheId() {
    // preparation
    final ProductTypeDraft newProductTypeDraft = ProductTypeDraft.ofAttributeDefinitionDrafts(PRODUCT_TYPE_KEY_1, PRODUCT_TYPE_NAME_1, PRODUCT_TYPE_DESCRIPTION_1, singletonList(ATTRIBUTE_DEFINITION_DRAFT_1));
    final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
    final ProductTypeSyncOptions spyOptions = ProductTypeSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception.getCause());
    }).build();
    final ProductTypeService spyProductTypeService = new ProductTypeServiceImpl(spyOptions);
    // test
    final Optional<ProductType> createdOptional = spyProductTypeService.createProductType(newProductTypeDraft).toCompletableFuture().join();
    // assertion
    final Optional<ProductType> queriedOptional = CTP_TARGET_CLIENT.execute(ProductTypeQuery.of().withPredicates(productTypeQueryModel -> productTypeQueryModel.key().is(PRODUCT_TYPE_KEY_1))).toCompletableFuture().join().head();
    assertThat(queriedOptional).hasValueSatisfying(queried -> assertThat(createdOptional).hasValueSatisfying(created -> {
        assertThat(created.getKey()).isEqualTo(queried.getKey());
        assertThat(created.getDescription()).isEqualTo(queried.getDescription());
        assertThat(created.getName()).isEqualTo(queried.getName());
        assertThat(created.getAttributes()).isEqualTo(queried.getAttributes());
    }));
    // Assert that the created product type is cached
    final Optional<String> productTypeId = spyProductTypeService.fetchCachedProductTypeId(PRODUCT_TYPE_KEY_1).toCompletableFuture().join();
    assertThat(productTypeId).isPresent();
    verify(spyClient, times(0)).execute(any(ProductTypeQuery.class));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProductType(io.sphere.sdk.producttypes.ProductType) Mockito.spy(org.mockito.Mockito.spy) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) DuplicateFieldError(io.sphere.sdk.models.errors.DuplicateFieldError) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) ProductTypeSyncOptionsBuilder(com.commercetools.sync.producttypes.ProductTypeSyncOptionsBuilder) HashSet(java.util.HashSet) AfterAll(org.junit.jupiter.api.AfterAll) Collections.singleton(java.util.Collections.singleton) Assertions.as(org.assertj.core.api.Assertions.as) Locale(java.util.Locale) ProductTypeService(com.commercetools.sync.services.ProductTypeService) Map(java.util.Map) SphereClient(io.sphere.sdk.client.SphereClient) PRODUCT_TYPE_KEY_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_KEY_1) ProductTypeITUtils.createProductType(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.createProductType) BadGatewayException(io.sphere.sdk.client.BadGatewayException) ProductTypeQuery(io.sphere.sdk.producttypes.queries.ProductTypeQuery) PRODUCT_TYPE_NAME_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_NAME_1) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) SetKey(io.sphere.sdk.producttypes.commands.updateactions.SetKey) Mockito.when(org.mockito.Mockito.when) AttributeMetaData(com.commercetools.sync.products.AttributeMetaData) ChangeName(io.sphere.sdk.producttypes.commands.updateactions.ChangeName) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ProductTypeServiceImpl(com.commercetools.sync.services.impl.ProductTypeServiceImpl) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) ProductTypeITUtils.deleteProductTypes(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.deleteProductTypes) Optional(java.util.Optional) PRODUCT_TYPE_DESCRIPTION_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_DESCRIPTION_1) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) Collections(java.util.Collections) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ATTRIBUTE_DEFINITION_DRAFT_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.ATTRIBUTE_DEFINITION_DRAFT_1) ProductTypeService(com.commercetools.sync.services.ProductTypeService) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) ProductTypeQuery(io.sphere.sdk.producttypes.queries.ProductTypeQuery) SphereClient(io.sphere.sdk.client.SphereClient) ProductType(io.sphere.sdk.producttypes.ProductType) ProductTypeITUtils.createProductType(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.createProductType) ProductTypeServiceImpl(com.commercetools.sync.services.impl.ProductTypeServiceImpl) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) Test(org.junit.jupiter.api.Test)

Example 3 with PRODUCT_TYPE_NAME_1

use of com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_NAME_1 in project commercetools-sync-java by commercetools.

the class ProductTypeServiceImplIT method createProductType_WithInvalidProductType_ShouldHaveEmptyOptionalAsAResult.

@Test
void createProductType_WithInvalidProductType_ShouldHaveEmptyOptionalAsAResult() {
    // preparation
    final ProductTypeDraft newProductTypeDraft = ProductTypeDraft.ofAttributeDefinitionDrafts("", PRODUCT_TYPE_NAME_1, PRODUCT_TYPE_DESCRIPTION_1, singletonList(ATTRIBUTE_DEFINITION_DRAFT_1));
    final ProductTypeSyncOptions options = ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception.getCause());
    }).build();
    final ProductTypeService service = new ProductTypeServiceImpl(options);
    // test
    final Optional<ProductType> result = service.createProductType(newProductTypeDraft).toCompletableFuture().join();
    // assertion
    assertThat(result).isEmpty();
    assertThat(errorCallBackMessages).containsExactly("Failed to create draft with key: ''. Reason: Draft key is blank!");
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProductType(io.sphere.sdk.producttypes.ProductType) Mockito.spy(org.mockito.Mockito.spy) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) DuplicateFieldError(io.sphere.sdk.models.errors.DuplicateFieldError) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) ProductTypeSyncOptionsBuilder(com.commercetools.sync.producttypes.ProductTypeSyncOptionsBuilder) HashSet(java.util.HashSet) AfterAll(org.junit.jupiter.api.AfterAll) Collections.singleton(java.util.Collections.singleton) Assertions.as(org.assertj.core.api.Assertions.as) Locale(java.util.Locale) ProductTypeService(com.commercetools.sync.services.ProductTypeService) Map(java.util.Map) SphereClient(io.sphere.sdk.client.SphereClient) PRODUCT_TYPE_KEY_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_KEY_1) ProductTypeITUtils.createProductType(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.createProductType) BadGatewayException(io.sphere.sdk.client.BadGatewayException) ProductTypeQuery(io.sphere.sdk.producttypes.queries.ProductTypeQuery) PRODUCT_TYPE_NAME_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_NAME_1) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) SetKey(io.sphere.sdk.producttypes.commands.updateactions.SetKey) Mockito.when(org.mockito.Mockito.when) AttributeMetaData(com.commercetools.sync.products.AttributeMetaData) ChangeName(io.sphere.sdk.producttypes.commands.updateactions.ChangeName) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ProductTypeServiceImpl(com.commercetools.sync.services.impl.ProductTypeServiceImpl) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) ProductTypeITUtils.deleteProductTypes(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.deleteProductTypes) Optional(java.util.Optional) PRODUCT_TYPE_DESCRIPTION_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_DESCRIPTION_1) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) Collections(java.util.Collections) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ATTRIBUTE_DEFINITION_DRAFT_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.ATTRIBUTE_DEFINITION_DRAFT_1) ProductTypeService(com.commercetools.sync.services.ProductTypeService) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) ProductType(io.sphere.sdk.producttypes.ProductType) ProductTypeITUtils.createProductType(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.createProductType) ProductTypeServiceImpl(com.commercetools.sync.services.impl.ProductTypeServiceImpl) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) Test(org.junit.jupiter.api.Test)

Example 4 with PRODUCT_TYPE_NAME_1

use of com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_NAME_1 in project commercetools-sync-java by commercetools.

the class ProductTypeSyncIT method sync_WithoutKey_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter.

@Test
void sync_WithoutKey_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter() {
    // Draft without key throws an error
    final ProductTypeDraft newProductTypeDraft = ProductTypeDraft.ofAttributeDefinitionDrafts(null, PRODUCT_TYPE_NAME_1, PRODUCT_TYPE_DESCRIPTION_1, asList(ATTRIBUTE_DEFINITION_DRAFT_1, ATTRIBUTE_DEFINITION_DRAFT_1));
    final List<String> errorMessages = new ArrayList<>();
    final List<Throwable> exceptions = new ArrayList<>();
    final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorMessages.add(exception.getMessage());
        exceptions.add(exception);
    }).build();
    final ProductTypeSync productTypeSync = new ProductTypeSync(syncOptions);
    // test
    final ProductTypeSyncStatistics productTypeSyncStatistics = productTypeSync.sync(singletonList(newProductTypeDraft)).toCompletableFuture().join();
    final String expectedErrorMessage = format("ProductTypeDraft with name: %s doesn't have a key. " + "Please make sure all productType drafts have keys.", newProductTypeDraft.getName());
    // assertions
    assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).isEqualTo(expectedErrorMessage);
    assertThat(exceptions).hasSize(1).singleElement().matches(throwable -> {
        assertThat(throwable).isInstanceOf(SyncException.class);
        assertThat(throwable.getMessage()).isEqualTo(expectedErrorMessage);
        return true;
    });
    assertThat(productTypeSyncStatistics).hasValues(1, 0, 0, 1, 0);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) SyncException(com.commercetools.sync.commons.exceptions.SyncException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UpdateAction(io.sphere.sdk.commands.UpdateAction) LocalizedEnumAttributeType(io.sphere.sdk.products.attributes.LocalizedEnumAttributeType) ProductTypeCreateCommand(io.sphere.sdk.producttypes.commands.ProductTypeCreateCommand) Collections.singletonList(java.util.Collections.singletonList) AfterAll(org.junit.jupiter.api.AfterAll) StringAttributeType(io.sphere.sdk.products.attributes.StringAttributeType) 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) MoneyAttributeType(io.sphere.sdk.products.attributes.MoneyAttributeType) ProductTypeITUtils.getProductTypeByKey(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.getProductTypeByKey) ProductTypeITUtils.assertAttributesAreEqual(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.assertAttributesAreEqual) BadGatewayException(io.sphere.sdk.client.BadGatewayException) ProductTypeQuery(io.sphere.sdk.producttypes.queries.ProductTypeQuery) ProductTypeUpdateCommand(io.sphere.sdk.producttypes.commands.ProductTypeUpdateCommand) PRODUCT_TYPE_NAME_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_NAME_1) ProductTypeDraftBuilder(io.sphere.sdk.producttypes.ProductTypeDraftBuilder) PRODUCT_TYPE_NAME_2(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_NAME_2) Collections.emptyList(java.util.Collections.emptyList) CompletionException(java.util.concurrent.CompletionException) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Test(org.junit.jupiter.api.Test) List(java.util.List) LocalizedString.ofEnglish(io.sphere.sdk.models.LocalizedString.ofEnglish) TextInputHint(io.sphere.sdk.models.TextInputHint) AttributeConstraint(io.sphere.sdk.products.attributes.AttributeConstraint) Optional(java.util.Optional) ProductTypeSync(com.commercetools.sync.producttypes.ProductTypeSync) AttributeDefinitionDraftDsl(io.sphere.sdk.products.attributes.AttributeDefinitionDraftDsl) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) AttributeDefinitionDraft(io.sphere.sdk.products.attributes.AttributeDefinitionDraft) ProductTypeITUtils.populateTargetProject(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.populateTargetProject) ProductTypeSyncStatistics(com.commercetools.sync.producttypes.helpers.ProductTypeSyncStatistics) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) ProductType(io.sphere.sdk.producttypes.ProductType) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) ProductTypeSyncOptionsBuilder(com.commercetools.sync.producttypes.ProductTypeSyncOptionsBuilder) Assertions.as(org.assertj.core.api.Assertions.as) PRODUCT_TYPE_KEY_2(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_KEY_2) PRODUCT_TYPE_KEY_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_KEY_1) Nonnull(javax.annotation.Nonnull) SetAttributeType(io.sphere.sdk.products.attributes.SetAttributeType) AttributeDefinitionDraftBuilder(io.sphere.sdk.products.attributes.AttributeDefinitionDraftBuilder) ChangeAttributeOrderByName(io.sphere.sdk.producttypes.commands.updateactions.ChangeAttributeOrderByName) EnumAttributeType(io.sphere.sdk.products.attributes.EnumAttributeType) LocalizedEnumValue(io.sphere.sdk.models.LocalizedEnumValue) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) Mockito.when(org.mockito.Mockito.when) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) ATTRIBUTE_DEFINITION_DRAFT_3(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.ATTRIBUTE_DEFINITION_DRAFT_3) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) ProductTypeITUtils.deleteProductTypes(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.deleteProductTypes) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) PRODUCT_TYPE_DESCRIPTION_2(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_DESCRIPTION_2) PRODUCT_TYPE_DESCRIPTION_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_DESCRIPTION_1) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) ATTRIBUTE_DEFINITION_DRAFT_2(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.ATTRIBUTE_DEFINITION_DRAFT_2) ATTRIBUTE_DEFINITION_DRAFT_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.ATTRIBUTE_DEFINITION_DRAFT_1) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) ProductTypeSync(com.commercetools.sync.producttypes.ProductTypeSync) ArrayList(java.util.ArrayList) ProductTypeSyncStatistics(com.commercetools.sync.producttypes.helpers.ProductTypeSyncStatistics) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) Test(org.junit.jupiter.api.Test)

Example 5 with PRODUCT_TYPE_NAME_1

use of com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_NAME_1 in project commercetools-sync-java by commercetools.

the class ProductTypeSyncIT method sync_WithUpdatedProductType_ChangingAttributeOrder_ShouldUpdateProductTypeChangingAttributeOrder.

@Test
void sync_WithUpdatedProductType_ChangingAttributeOrder_ShouldUpdateProductTypeChangingAttributeOrder() {
    // Changing order from ATTRIBUTE_DEFINITION_DRAFT_1, ATTRIBUTE_DEFINITION_DRAFT_2 to
    // ATTRIBUTE_DEFINITION_DRAFT_2, ATTRIBUTE_DEFINITION_DRAFT_1
    final ProductTypeDraft newProductTypeDraft = ProductTypeDraft.ofAttributeDefinitionDrafts(PRODUCT_TYPE_KEY_1, PRODUCT_TYPE_NAME_1, PRODUCT_TYPE_DESCRIPTION_1, asList(ATTRIBUTE_DEFINITION_DRAFT_2, ATTRIBUTE_DEFINITION_DRAFT_1));
    final ArrayList<UpdateAction<ProductType>> builtUpdateActions = new ArrayList<>();
    final ProductTypeSyncOptions productTypeSyncOptions = ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).beforeUpdateCallback((actions, draft, oldProductType) -> {
        builtUpdateActions.addAll(actions);
        return actions;
    }).build();
    final ProductTypeSync productTypeSync = new ProductTypeSync(productTypeSyncOptions);
    final ProductTypeSyncStatistics productTypeSyncStatistics = productTypeSync.sync(singletonList(newProductTypeDraft)).toCompletableFuture().join();
    assertThat(productTypeSyncStatistics).hasValues(1, 0, 1, 0, 0);
    final Optional<ProductType> oldProductTypeAfter = getProductTypeByKey(CTP_TARGET_CLIENT, PRODUCT_TYPE_KEY_1);
    assertThat(oldProductTypeAfter).hasValueSatisfying(productType -> assertAttributesAreEqual(productType.getAttributes(), asList(ATTRIBUTE_DEFINITION_DRAFT_2, ATTRIBUTE_DEFINITION_DRAFT_1)));
    assertThat(builtUpdateActions).containsExactly(ChangeAttributeOrderByName.of(asList(ATTRIBUTE_DEFINITION_DRAFT_2.getName(), ATTRIBUTE_DEFINITION_DRAFT_1.getName())));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) SyncException(com.commercetools.sync.commons.exceptions.SyncException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UpdateAction(io.sphere.sdk.commands.UpdateAction) LocalizedEnumAttributeType(io.sphere.sdk.products.attributes.LocalizedEnumAttributeType) ProductTypeCreateCommand(io.sphere.sdk.producttypes.commands.ProductTypeCreateCommand) Collections.singletonList(java.util.Collections.singletonList) AfterAll(org.junit.jupiter.api.AfterAll) StringAttributeType(io.sphere.sdk.products.attributes.StringAttributeType) 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) MoneyAttributeType(io.sphere.sdk.products.attributes.MoneyAttributeType) ProductTypeITUtils.getProductTypeByKey(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.getProductTypeByKey) ProductTypeITUtils.assertAttributesAreEqual(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.assertAttributesAreEqual) BadGatewayException(io.sphere.sdk.client.BadGatewayException) ProductTypeQuery(io.sphere.sdk.producttypes.queries.ProductTypeQuery) ProductTypeUpdateCommand(io.sphere.sdk.producttypes.commands.ProductTypeUpdateCommand) PRODUCT_TYPE_NAME_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_NAME_1) ProductTypeDraftBuilder(io.sphere.sdk.producttypes.ProductTypeDraftBuilder) PRODUCT_TYPE_NAME_2(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_NAME_2) Collections.emptyList(java.util.Collections.emptyList) CompletionException(java.util.concurrent.CompletionException) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Test(org.junit.jupiter.api.Test) List(java.util.List) LocalizedString.ofEnglish(io.sphere.sdk.models.LocalizedString.ofEnglish) TextInputHint(io.sphere.sdk.models.TextInputHint) AttributeConstraint(io.sphere.sdk.products.attributes.AttributeConstraint) Optional(java.util.Optional) ProductTypeSync(com.commercetools.sync.producttypes.ProductTypeSync) AttributeDefinitionDraftDsl(io.sphere.sdk.products.attributes.AttributeDefinitionDraftDsl) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) AttributeDefinitionDraft(io.sphere.sdk.products.attributes.AttributeDefinitionDraft) ProductTypeITUtils.populateTargetProject(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.populateTargetProject) ProductTypeSyncStatistics(com.commercetools.sync.producttypes.helpers.ProductTypeSyncStatistics) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) ProductType(io.sphere.sdk.producttypes.ProductType) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) ProductTypeSyncOptionsBuilder(com.commercetools.sync.producttypes.ProductTypeSyncOptionsBuilder) Assertions.as(org.assertj.core.api.Assertions.as) PRODUCT_TYPE_KEY_2(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_KEY_2) PRODUCT_TYPE_KEY_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_KEY_1) Nonnull(javax.annotation.Nonnull) SetAttributeType(io.sphere.sdk.products.attributes.SetAttributeType) AttributeDefinitionDraftBuilder(io.sphere.sdk.products.attributes.AttributeDefinitionDraftBuilder) ChangeAttributeOrderByName(io.sphere.sdk.producttypes.commands.updateactions.ChangeAttributeOrderByName) EnumAttributeType(io.sphere.sdk.products.attributes.EnumAttributeType) LocalizedEnumValue(io.sphere.sdk.models.LocalizedEnumValue) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) Mockito.when(org.mockito.Mockito.when) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) ATTRIBUTE_DEFINITION_DRAFT_3(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.ATTRIBUTE_DEFINITION_DRAFT_3) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) ProductTypeITUtils.deleteProductTypes(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.deleteProductTypes) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) PRODUCT_TYPE_DESCRIPTION_2(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_DESCRIPTION_2) PRODUCT_TYPE_DESCRIPTION_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_DESCRIPTION_1) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) ATTRIBUTE_DEFINITION_DRAFT_2(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.ATTRIBUTE_DEFINITION_DRAFT_2) ATTRIBUTE_DEFINITION_DRAFT_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.ATTRIBUTE_DEFINITION_DRAFT_1) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) UpdateAction(io.sphere.sdk.commands.UpdateAction) ProductTypeSync(com.commercetools.sync.producttypes.ProductTypeSync) ArrayList(java.util.ArrayList) ProductTypeSyncStatistics(com.commercetools.sync.producttypes.helpers.ProductTypeSyncStatistics) ProductType(io.sphere.sdk.producttypes.ProductType) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) Test(org.junit.jupiter.api.Test)

Aggregations

ATTRIBUTE_DEFINITION_DRAFT_1 (com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.ATTRIBUTE_DEFINITION_DRAFT_1)8 PRODUCT_TYPE_DESCRIPTION_1 (com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_DESCRIPTION_1)8 PRODUCT_TYPE_KEY_1 (com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_KEY_1)8 PRODUCT_TYPE_NAME_1 (com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_NAME_1)8 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)8 ProductTypeSyncOptions (com.commercetools.sync.producttypes.ProductTypeSyncOptions)8 ProductTypeSyncOptionsBuilder (com.commercetools.sync.producttypes.ProductTypeSyncOptionsBuilder)8 BadGatewayException (io.sphere.sdk.client.BadGatewayException)8 SphereClient (io.sphere.sdk.client.SphereClient)8 ProductType (io.sphere.sdk.producttypes.ProductType)8 ProductTypeDraft (io.sphere.sdk.producttypes.ProductTypeDraft)8 ProductTypeQuery (io.sphere.sdk.producttypes.queries.ProductTypeQuery)8 ArrayList (java.util.ArrayList)8 Collections.singletonList (java.util.Collections.singletonList)8 List (java.util.List)8 Optional (java.util.Optional)8 Assertions.as (org.assertj.core.api.Assertions.as)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 AfterAll (org.junit.jupiter.api.AfterAll)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8