Search in sources :

Example 26 with ProductSync

use of com.commercetools.sync.products.ProductSync in project commercetools-sync-java by commercetools.

the class ProductSyncWithReferencedProductsInAnyOrderIT method sync_withMultipleHierarchyProductReferenceAsAttribute_shouldCreateProductReferencingExistingProduct.

@Test
void sync_withMultipleHierarchyProductReferenceAsAttribute_shouldCreateProductReferencingExistingProduct() {
    // preparation
    final String parentKey = "product-parent";
    final String parentKey1 = "product-parent-1";
    final String parentKey2 = "product-parent-2";
    final String parentKey3 = "product-parent-3";
    final String parentKey4 = "product-parent-4";
    final String productAttributeReferenceName = "product-reference";
    final String productAttributeReferenceSetName = "product-reference-set";
    final AttributeDraft productReferenceAttribute = AttributeDraft.of(productAttributeReferenceName, Reference.of(Product.referenceTypeId(), parentKey));
    final ArrayNode refSet = JsonNodeFactory.instance.arrayNode();
    final ObjectNode parentKey1RefObject = createReferenceObject(parentKey1, Product.referenceTypeId());
    final ObjectNode parentKey2RefObject = createReferenceObject(parentKey2, Product.referenceTypeId());
    final ObjectNode parentKey3RefObject = createReferenceObject(parentKey3, Product.referenceTypeId());
    final ObjectNode parentKey4RefObject = createReferenceObject(parentKey4, Product.referenceTypeId());
    refSet.add(parentKey1RefObject);
    refSet.add(parentKey2RefObject);
    refSet.add(parentKey3RefObject);
    refSet.add(parentKey4RefObject);
    final AttributeDraft productReferenceSetAttribute = AttributeDraft.of(productAttributeReferenceSetName, refSet);
    final ProductDraft childDraft = ProductDraftBuilder.of(productType, ofEnglish("foo"), ofEnglish("foo-slug"), emptyList()).key("foo").masterVariant(ProductVariantDraftBuilder.of().key("foo").sku("foo").attributes(productReferenceAttribute, productReferenceSetAttribute).build()).build();
    final ProductDraft childDraft1 = ProductDraftBuilder.of(productType, ofEnglish("childDraft1"), ofEnglish("childDraft1"), ProductVariantDraftBuilder.of().key("childDraft1").sku("childDraft1").attributes(productReferenceAttribute).build()).key("childDraft1").build();
    final ProductDraft parentDraft = ProductDraftBuilder.of(productType, ofEnglish(parentKey), ofEnglish(parentKey), ProductVariantDraftBuilder.of().sku(parentKey).key(parentKey).build()).key(parentKey).build();
    final ProductDraft parentDraft1 = ProductDraftBuilder.of(productType, ofEnglish(parentKey1), ofEnglish(parentKey1), ProductVariantDraftBuilder.of().key(parentKey1).sku(parentKey1).build()).key(parentKey1).build();
    final ProductDraft parentDraft2 = ProductDraftBuilder.of(productType, ofEnglish(parentKey2), ofEnglish(parentKey2), ProductVariantDraftBuilder.of().key(parentKey2).sku(parentKey2).attributes(AttributeDraft.of(productAttributeReferenceName, parentKey1RefObject)).build()).key(parentKey2).build();
    final ProductDraft parentDraft3 = ProductDraftBuilder.of(productType, ofEnglish(parentKey3), ofEnglish(parentKey3), ProductVariantDraftBuilder.of().key(parentKey3).sku(parentKey3).attributes(AttributeDraft.of(productAttributeReferenceName, parentKey2RefObject)).build()).key(parentKey3).build();
    final ProductDraft parentDraft4 = ProductDraftBuilder.of(productType, ofEnglish(parentKey4), ofEnglish(parentKey4), ProductVariantDraftBuilder.of().key(parentKey4).sku(parentKey4).attributes(AttributeDraft.of(productAttributeReferenceName, parentKey3RefObject)).build()).key(parentKey4).build();
    // test
    final ProductSync productSync = new ProductSync(syncOptions);
    final ProductSyncStatistics syncStatistics = productSync.sync(asList(childDraft, parentDraft, parentDraft4, childDraft1, parentDraft3, parentDraft2, parentDraft1)).toCompletableFuture().join();
    // assertion
    final Product syncedChild1 = CTP_TARGET_CLIENT.execute(ProductByKeyGet.of(childDraft1.getKey())).toCompletableFuture().join();
    final Product syncedParent = CTP_TARGET_CLIENT.execute(ProductByKeyGet.of(parentDraft.getKey())).toCompletableFuture().join();
    final Product syncedParent1 = CTP_TARGET_CLIENT.execute(ProductByKeyGet.of(parentDraft1.getKey())).toCompletableFuture().join();
    final Product syncedParent2 = CTP_TARGET_CLIENT.execute(ProductByKeyGet.of(parentDraft2.getKey())).toCompletableFuture().join();
    final Product syncedParent3 = CTP_TARGET_CLIENT.execute(ProductByKeyGet.of(parentDraft3.getKey())).toCompletableFuture().join();
    final Product syncedParent4 = CTP_TARGET_CLIENT.execute(ProductByKeyGet.of(parentDraft4.getKey())).toCompletableFuture().join();
    final ArrayNode expectedAttributeValue = JsonNodeFactory.instance.arrayNode();
    expectedAttributeValue.add(createReferenceObject(syncedParent1.getId(), Product.referenceTypeId()));
    expectedAttributeValue.add(createReferenceObject(syncedParent2.getId(), Product.referenceTypeId()));
    expectedAttributeValue.add(createReferenceObject(syncedParent3.getId(), Product.referenceTypeId()));
    expectedAttributeValue.add(createReferenceObject(syncedParent4.getId(), Product.referenceTypeId()));
    assertThat(syncStatistics).hasValues(7, 6, 1, 0, 0);
    assertThat(errorCallBackExceptions).isEmpty();
    assertThat(errorCallBackMessages).isEmpty();
    assertThat(warningCallBackMessages).isEmpty();
    final Product existingProduct = CTP_TARGET_CLIENT.execute(ProductByKeyGet.of(childDraft.getKey())).toCompletableFuture().join();
    final Optional<Attribute> existingProductReferenceSetAttribute = existingProduct.getMasterData().getStaged().getMasterVariant().findAttribute(productReferenceSetAttribute.getName());
    assertThat(existingProductReferenceSetAttribute).hasValueSatisfying(attribute -> {
        assertThat(attribute.getValueAsJsonNode().get(0).get(REFERENCE_TYPE_ID_FIELD).asText()).isEqualTo(Product.referenceTypeId());
        assertThat(attribute.getValueAsJsonNode().get(0).get(REFERENCE_ID_FIELD).asText()).isEqualTo(syncedParent1.getId());
        assertThat(attribute.getValueAsJsonNode().get(1).get(REFERENCE_TYPE_ID_FIELD).asText()).isEqualTo(Product.referenceTypeId());
        assertThat(attribute.getValueAsJsonNode().get(1).get(REFERENCE_ID_FIELD).asText()).isEqualTo(syncedParent2.getId());
        assertThat(attribute.getValueAsJsonNode().get(2).get(REFERENCE_TYPE_ID_FIELD).asText()).isEqualTo(Product.referenceTypeId());
        assertThat(attribute.getValueAsJsonNode().get(2).get(REFERENCE_ID_FIELD).asText()).isEqualTo(syncedParent3.getId());
        assertThat(attribute.getValueAsJsonNode().get(3).get(REFERENCE_TYPE_ID_FIELD).asText()).isEqualTo(Product.referenceTypeId());
        assertThat(attribute.getValueAsJsonNode().get(3).get(REFERENCE_ID_FIELD).asText()).isEqualTo(syncedParent4.getId());
    });
    final Optional<Attribute> existingProductReferenceAttribute = existingProduct.getMasterData().getStaged().getMasterVariant().findAttribute(productReferenceAttribute.getName());
    assertThat(existingProductReferenceAttribute).hasValueSatisfying(attribute -> {
        assertThat(attribute.getValueAsJsonNode().get(REFERENCE_TYPE_ID_FIELD).asText()).isEqualTo(Product.referenceTypeId());
        assertThat(attribute.getValueAsJsonNode().get(REFERENCE_ID_FIELD).asText()).isEqualTo(syncedParent.getId());
    });
    final Optional<Attribute> syncedProduct4Attribute = syncedParent4.getMasterData().getStaged().getMasterVariant().findAttribute(productReferenceAttribute.getName());
    assertThat(syncedProduct4Attribute).hasValueSatisfying(attribute -> {
        assertThat(attribute.getValueAsJsonNode().get(REFERENCE_TYPE_ID_FIELD).asText()).isEqualTo(Product.referenceTypeId());
        assertThat(attribute.getValueAsJsonNode().get(REFERENCE_ID_FIELD).asText()).isEqualTo(syncedParent3.getId());
    });
    final Optional<Attribute> syncedProduct3Attribute = syncedParent3.getMasterData().getStaged().getMasterVariant().findAttribute(productReferenceAttribute.getName());
    assertThat(syncedProduct3Attribute).hasValueSatisfying(attribute -> {
        assertThat(attribute.getValueAsJsonNode().get(REFERENCE_TYPE_ID_FIELD).asText()).isEqualTo(Product.referenceTypeId());
        assertThat(attribute.getValueAsJsonNode().get(REFERENCE_ID_FIELD).asText()).isEqualTo(syncedParent2.getId());
    });
    final Optional<Attribute> syncedProduct2Attribute = syncedParent2.getMasterData().getStaged().getMasterVariant().findAttribute(productReferenceAttribute.getName());
    assertThat(syncedProduct2Attribute).hasValueSatisfying(attribute -> {
        assertThat(attribute.getValueAsJsonNode().get(REFERENCE_TYPE_ID_FIELD).asText()).isEqualTo(Product.referenceTypeId());
        assertThat(attribute.getValueAsJsonNode().get(REFERENCE_ID_FIELD).asText()).isEqualTo(syncedParent1.getId());
    });
    final Optional<Attribute> syncedChild1Attribute = syncedChild1.getMasterData().getStaged().getMasterVariant().findAttribute(productReferenceAttribute.getName());
    assertThat(syncedChild1Attribute).hasValueSatisfying(attribute -> {
        assertThat(attribute.getValueAsJsonNode().get(REFERENCE_TYPE_ID_FIELD).asText()).isEqualTo(Product.referenceTypeId());
        assertThat(attribute.getValueAsJsonNode().get(REFERENCE_ID_FIELD).asText()).isEqualTo(syncedParent.getId());
    });
    assertNoWaitingDrafts(CTP_TARGET_CLIENT);
}
Also used : ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProductDraft(io.sphere.sdk.products.ProductDraft) AttributeDraft(io.sphere.sdk.products.attributes.AttributeDraft) Attribute(io.sphere.sdk.products.attributes.Attribute) Product(io.sphere.sdk.products.Product) ProductSync(com.commercetools.sync.products.ProductSync) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Test(org.junit.jupiter.api.Test)

Example 27 with ProductSync

use of com.commercetools.sync.products.ProductSync in project commercetools-sync-java by commercetools.

the class ProductSyncWithReferencedProductsInAnyOrderIT method sync_withMultipleChildDraftsSuppliedBeforeParent_shouldSyncCorrectly.

@Test
void sync_withMultipleChildDraftsSuppliedBeforeParent_shouldSyncCorrectly() {
    // preparation
    final String productReferenceAttributeName = "product-reference";
    final String parentProductKey = "parent-product-key";
    final AttributeDraft productReferenceAttribute = AttributeDraft.of(productReferenceAttributeName, Reference.of(Product.referenceTypeId(), parentProductKey));
    final ProductDraft childDraft1 = ProductDraftBuilder.of(productType, ofEnglish("foo"), ofEnglish("foo-slug"), ProductVariantDraftBuilder.of().key("foo").sku("foo").attributes(productReferenceAttribute).build()).key(product.getKey()).build();
    final ProductDraft childDraft2 = ProductDraftBuilder.of(productType, ofEnglish("foo-2"), ofEnglish("foo-slug-2"), ProductVariantDraftBuilder.of().key("foo-2").sku("foo-2").attributes(productReferenceAttribute).build()).key("foo-2").build();
    final ProductDraft parentDraft = ProductDraftBuilder.of(productType, ofEnglish("bar"), ofEnglish("bar-slug"), ProductVariantDraftBuilder.of().sku("bar").key("bar").build()).key(parentProductKey).build();
    // test
    final ProductSync productSync = new ProductSync(syncOptions);
    final ProductSyncStatistics syncStatistics = productSync.sync(asList(childDraft1, childDraft2, parentDraft)).toCompletableFuture().join();
    final Product syncedParent = CTP_TARGET_CLIENT.execute(ProductByKeyGet.of(parentDraft.getKey())).toCompletableFuture().join();
    // assertion
    assertThat(syncedParent).isNotNull();
    assertThat(syncedParent.getKey()).isEqualTo(parentProductKey);
    assertThat(syncStatistics).hasValues(3, 2, 1, 0, 0);
    assertThat(errorCallBackExceptions).isEmpty();
    assertThat(errorCallBackMessages).isEmpty();
    assertThat(warningCallBackMessages).isEmpty();
    assertThat(actions).containsExactly(SetAttributeInAllVariants.of(productReferenceAttributeName, createReferenceObject(syncedParent.getId(), Product.referenceTypeId()), true));
    final Product syncedChild1 = CTP_TARGET_CLIENT.execute(ProductByKeyGet.of(childDraft1.getKey())).toCompletableFuture().join();
    final Product syncedChild2 = CTP_TARGET_CLIENT.execute(ProductByKeyGet.of(childDraft2.getKey())).toCompletableFuture().join();
    final Optional<Attribute> syncedProductReferenceAttribute1 = syncedChild1.getMasterData().getStaged().getMasterVariant().findAttribute(productReferenceAttribute.getName());
    final Optional<Attribute> createdProductReferenceAttribute2 = syncedChild2.getMasterData().getStaged().getMasterVariant().findAttribute(productReferenceAttribute.getName());
    assertThat(syncedProductReferenceAttribute1).hasValueSatisfying(attribute -> {
        assertThat(attribute.getValueAsJsonNode().get(REFERENCE_TYPE_ID_FIELD).asText()).isEqualTo(Product.referenceTypeId());
        assertThat(attribute.getValueAsJsonNode().get(REFERENCE_ID_FIELD).asText()).isEqualTo(syncedParent.getId());
    });
    assertThat(createdProductReferenceAttribute2).hasValueSatisfying(attribute -> {
        assertThat(attribute.getValueAsJsonNode().get(REFERENCE_TYPE_ID_FIELD).asText()).isEqualTo(Product.referenceTypeId());
        assertThat(attribute.getValueAsJsonNode().get(REFERENCE_ID_FIELD).asText()).isEqualTo(syncedParent.getId());
    });
    assertNoWaitingDrafts(CTP_TARGET_CLIENT);
}
Also used : ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) ProductDraft(io.sphere.sdk.products.ProductDraft) AttributeDraft(io.sphere.sdk.products.attributes.AttributeDraft) Attribute(io.sphere.sdk.products.attributes.Attribute) Product(io.sphere.sdk.products.Product) ProductSync(com.commercetools.sync.products.ProductSync) Test(org.junit.jupiter.api.Test)

Example 28 with ProductSync

use of com.commercetools.sync.products.ProductSync in project commercetools-sync-java by commercetools.

the class ProductSyncWithNestedReferencedProductTypesIT method sync_withSameNestedProductTypeReferenceAsAttribute_shouldNotSyncAnythingNew.

@Test
void sync_withSameNestedProductTypeReferenceAsAttribute_shouldNotSyncAnythingNew() {
    // preparation
    final ObjectNode nestedAttributeValue = createNestedAttributeValueReferences("productType-reference", createReferenceObject(testProductType1.getId(), ProductType.referenceTypeId()));
    final AttributeDraft productTypeReferenceAttribute = AttributeDraft.of("nestedAttribute", createArrayNode(nestedAttributeValue));
    final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of().sku("sku").key("new-product-master-variant").attributes(productTypeReferenceAttribute).build();
    final ProductDraft productDraftWithProductTypeReference = ProductDraftBuilder.of(testProductType1, ofEnglish("productName"), ofEnglish("productSlug"), masterVariant).key("new-product").build();
    CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(productDraftWithProductTypeReference)).toCompletableFuture().join();
    final ObjectNode newNestedAttributeValue = createNestedAttributeValueReferences("productType-reference", createReferenceObject(testProductType1.getKey(), ProductType.referenceTypeId()));
    final AttributeDraft newProductReferenceAttribute = AttributeDraft.of("nestedAttribute", createArrayNode(newNestedAttributeValue));
    final ProductVariantDraft newMasterVariant = ProductVariantDraftBuilder.of().sku("sku").key("new-product-master-variant").attributes(newProductReferenceAttribute).build();
    final ProductDraft newProductDraftWithProductReference = ProductDraftBuilder.of(testProductType1, ofEnglish("productName"), ofEnglish("productSlug"), newMasterVariant).key("new-product").build();
    // test
    final ProductSync productSync = new ProductSync(syncOptions);
    final ProductSyncStatistics syncStatistics = productSync.sync(singletonList(newProductDraftWithProductReference)).toCompletableFuture().join();
    // assertion
    assertThat(syncStatistics).hasValues(1, 0, 0, 0, 0);
    assertThat(errorCallBackExceptions).isEmpty();
    assertThat(errorCallBackMessages).isEmpty();
    assertThat(warningCallBackMessages).isEmpty();
    assertThat(actions).isEmpty();
    final Product createdProduct = CTP_TARGET_CLIENT.execute(ProductByKeyGet.of(productDraftWithProductTypeReference.getKey())).toCompletableFuture().join();
    final Optional<Attribute> createdProductTypeReferenceAttribute = createdProduct.getMasterData().getStaged().getMasterVariant().findAttribute(productTypeReferenceAttribute.getName());
    assertThat(createdProductTypeReferenceAttribute).hasValueSatisfying(attribute -> {
        final JsonNode nestedAttributeNameField = attribute.getValueAsJsonNode().get(0).get(ATTRIBUTE_NAME_FIELD);
        final JsonNode nestedAttributeValueField = attribute.getValueAsJsonNode().get(0).get(ATTRIBUTE_VALUE_FIELD);
        assertThat(nestedAttributeNameField.asText()).isEqualTo("productType-reference");
        assertThat(nestedAttributeValueField.get(REFERENCE_TYPE_ID_FIELD).asText()).isEqualTo(ProductType.referenceTypeId());
        assertThat(nestedAttributeValueField.get(REFERENCE_ID_FIELD).asText()).isEqualTo(testProductType1.getId());
    });
}
Also used : ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProductDraft(io.sphere.sdk.products.ProductDraft) AttributeDraft(io.sphere.sdk.products.attributes.AttributeDraft) Attribute(io.sphere.sdk.products.attributes.Attribute) SetAttribute(io.sphere.sdk.products.commands.updateactions.SetAttribute) ProductVariantDraft(io.sphere.sdk.products.ProductVariantDraft) Product(io.sphere.sdk.products.Product) ProductSync(com.commercetools.sync.products.ProductSync) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test)

Example 29 with ProductSync

use of com.commercetools.sync.products.ProductSync in project commercetools-sync-java by commercetools.

the class ProductSyncWithNestedReferencedProductTypesIT method sync_withNestedProductTypeReferenceAsAttribute_shouldCreateProductReferencingExistingProductType.

@Test
void sync_withNestedProductTypeReferenceAsAttribute_shouldCreateProductReferencingExistingProductType() {
    // preparation
    final ObjectNode nestedAttributeValue = createNestedAttributeValueReferences("productType-reference", createReferenceObject(testProductType1.getKey(), ProductType.referenceTypeId()));
    final AttributeDraft productTypeReferenceAttribute = AttributeDraft.of("nestedAttribute", createArrayNode(nestedAttributeValue));
    final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of().sku("sku").key("new-product-master-variant").attributes(productTypeReferenceAttribute).build();
    final ProductDraft productDraftWithProductTypeReference = ProductDraftBuilder.of(testProductType1, ofEnglish("productName"), ofEnglish("productSlug"), masterVariant).key("new-product").build();
    // test
    final ProductSync productSync = new ProductSync(syncOptions);
    final ProductSyncStatistics syncStatistics = productSync.sync(singletonList(productDraftWithProductTypeReference)).toCompletableFuture().join();
    // assertion
    assertThat(syncStatistics).hasValues(1, 1, 0, 0, 0);
    assertThat(errorCallBackExceptions).isEmpty();
    assertThat(errorCallBackMessages).isEmpty();
    assertThat(warningCallBackMessages).isEmpty();
    assertThat(actions).isEmpty();
    final Product createdProduct = CTP_TARGET_CLIENT.execute(ProductByKeyGet.of(productDraftWithProductTypeReference.getKey())).toCompletableFuture().join();
    final Optional<Attribute> createdProductTypeReferenceAttribute = createdProduct.getMasterData().getStaged().getMasterVariant().findAttribute(productTypeReferenceAttribute.getName());
    assertThat(createdProductTypeReferenceAttribute).hasValueSatisfying(attribute -> {
        final JsonNode nestedAttributeNameField = attribute.getValueAsJsonNode().get(0).get(ATTRIBUTE_NAME_FIELD);
        final JsonNode nestedAttributeReferenceValueField = attribute.getValueAsJsonNode().get(0).get(ATTRIBUTE_VALUE_FIELD);
        assertThat(nestedAttributeNameField.asText()).isEqualTo("productType-reference");
        assertThat(nestedAttributeReferenceValueField.get(REFERENCE_TYPE_ID_FIELD).asText()).isEqualTo(ProductType.referenceTypeId());
        assertThat(nestedAttributeReferenceValueField.get(REFERENCE_ID_FIELD).asText()).isEqualTo(testProductType1.getId());
    });
}
Also used : ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProductDraft(io.sphere.sdk.products.ProductDraft) AttributeDraft(io.sphere.sdk.products.attributes.AttributeDraft) Attribute(io.sphere.sdk.products.attributes.Attribute) SetAttribute(io.sphere.sdk.products.commands.updateactions.SetAttribute) ProductVariantDraft(io.sphere.sdk.products.ProductVariantDraft) Product(io.sphere.sdk.products.Product) ProductSync(com.commercetools.sync.products.ProductSync) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test)

Example 30 with ProductSync

use of com.commercetools.sync.products.ProductSync in project commercetools-sync-java by commercetools.

the class ProductSyncWithNestedReferencedProductTypesIT method sync_withSetOfNestedProductReferenceSetAsAttribute_shouldCreateProductReferencingExistingProductType.

@Test
void sync_withSetOfNestedProductReferenceSetAsAttribute_shouldCreateProductReferencingExistingProductType() {
    // preparation
    final ArrayNode nestedAttributeValue = createArrayNode(createNestedAttributeValueSetOfReferences("productType-reference-set", createReferenceObject(testProductType1.getKey(), ProductType.referenceTypeId()), createReferenceObject(testProductType2.getKey(), ProductType.referenceTypeId())));
    final AttributeDraft productTypeReferenceAttribute = AttributeDraft.of("setOfNestedAttribute", createArrayNode(nestedAttributeValue));
    final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of().sku("sku").key("new-product-master-variant").attributes(productTypeReferenceAttribute).build();
    final ProductDraft productDraftWithProductTypeReference = ProductDraftBuilder.of(testProductType1, ofEnglish("productName"), ofEnglish("productSlug"), masterVariant).key("new-product").build();
    // test
    final ProductSync productSync = new ProductSync(syncOptions);
    final ProductSyncStatistics syncStatistics = productSync.sync(singletonList(productDraftWithProductTypeReference)).toCompletableFuture().join();
    // assertion
    assertThat(syncStatistics).hasValues(1, 1, 0, 0, 0);
    assertThat(errorCallBackExceptions).isEmpty();
    assertThat(errorCallBackMessages).isEmpty();
    assertThat(warningCallBackMessages).isEmpty();
    assertThat(actions).isEmpty();
    final Product createdProduct = CTP_TARGET_CLIENT.execute(ProductByKeyGet.of(productDraftWithProductTypeReference.getKey())).toCompletableFuture().join();
    final Optional<Attribute> createdProductTypeReferenceAttribute = createdProduct.getMasterData().getStaged().getMasterVariant().findAttribute(productTypeReferenceAttribute.getName());
    assertThat(createdProductTypeReferenceAttribute).hasValueSatisfying(attribute -> {
        final JsonNode setOfNestedAttributeNameField = attribute.getValueAsJsonNode().get(0).get(0).get(ATTRIBUTE_NAME_FIELD);
        final JsonNode setOfNestedAttributeValueField = attribute.getValueAsJsonNode().get(0).get(0).get(ATTRIBUTE_VALUE_FIELD);
        assertThat(setOfNestedAttributeNameField.asText()).isEqualTo("productType-reference-set");
        assertThat(setOfNestedAttributeValueField).isInstanceOf(ArrayNode.class);
        final ArrayNode referenceSet = (ArrayNode) setOfNestedAttributeValueField;
        assertThat(referenceSet).hasSize(2).anySatisfy(reference -> {
            assertThat(reference.get(REFERENCE_TYPE_ID_FIELD).asText()).isEqualTo(ProductType.referenceTypeId());
            assertThat(reference.get(REFERENCE_ID_FIELD).asText()).isEqualTo(testProductType1.getId());
        }).anySatisfy(reference -> {
            assertThat(reference.get(REFERENCE_TYPE_ID_FIELD).asText()).isEqualTo(ProductType.referenceTypeId());
            assertThat(reference.get(REFERENCE_ID_FIELD).asText()).isEqualTo(testProductType2.getId());
        });
    });
}
Also used : ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) BeforeEach(org.junit.jupiter.api.BeforeEach) ProductVariantDraft(io.sphere.sdk.products.ProductVariantDraft) PRODUCT_TYPE_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_TYPE_RESOURCE_PATH) SyncException(com.commercetools.sync.commons.exceptions.SyncException) ProductSyncWithNestedReferencedProductsIT.createNestedAttributeValueSetOfReferences(com.commercetools.sync.integration.externalsource.products.ProductSyncWithNestedReferencedProductsIT.createNestedAttributeValueSetOfReferences) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UpdateAction(io.sphere.sdk.commands.UpdateAction) AddAttributeDefinition(io.sphere.sdk.producttypes.commands.updateactions.AddAttributeDefinition) Collections.singletonList(java.util.Collections.singletonList) ProductITUtils.deleteProductSyncTestData(com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteProductSyncTestData) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) Arrays.asList(java.util.Arrays.asList) TriConsumer(com.commercetools.sync.commons.utils.TriConsumer) JsonNode(com.fasterxml.jackson.databind.JsonNode) ProductDraft(io.sphere.sdk.products.ProductDraft) ProductProjection(io.sphere.sdk.products.ProductProjection) ProductTypeITUtils.createProductType(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.createProductType) ProductTypeUpdateCommand(io.sphere.sdk.producttypes.commands.ProductTypeUpdateCommand) Product(io.sphere.sdk.products.Product) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Test(org.junit.jupiter.api.Test) List(java.util.List) LocalizedString.ofEnglish(io.sphere.sdk.models.LocalizedString.ofEnglish) ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) ProductSyncOptionsBuilder(com.commercetools.sync.products.ProductSyncOptionsBuilder) ProductSyncMockUtils.createReferenceObject(com.commercetools.sync.products.ProductSyncMockUtils.createReferenceObject) Optional(java.util.Optional) REFERENCE_TYPE_ID_FIELD(com.commercetools.sync.commons.utils.ResourceIdentifierUtils.REFERENCE_TYPE_ID_FIELD) ProductCreateCommand(io.sphere.sdk.products.commands.ProductCreateCommand) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ProductSyncOptions(com.commercetools.sync.products.ProductSyncOptions) AttributeDefinitionDraft(io.sphere.sdk.products.attributes.AttributeDefinitionDraft) ProductByKeyGet(io.sphere.sdk.products.queries.ProductByKeyGet) ProductType(io.sphere.sdk.producttypes.ProductType) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) ProductITUtils.deleteAllProducts(com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteAllProducts) ProductSyncWithNestedReferencedProductsIT.createArrayNode(com.commercetools.sync.integration.externalsource.products.ProductSyncWithNestedReferencedProductsIT.createArrayNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) Attribute(io.sphere.sdk.products.attributes.Attribute) Assertions.as(org.assertj.core.api.Assertions.as) ProductSync(com.commercetools.sync.products.ProductSync) ProductDraftBuilder(io.sphere.sdk.products.ProductDraftBuilder) SetAttribute(io.sphere.sdk.products.commands.updateactions.SetAttribute) Nonnull(javax.annotation.Nonnull) SetAttributeType(io.sphere.sdk.products.attributes.SetAttributeType) AttributeDefinitionDraftBuilder(io.sphere.sdk.products.attributes.AttributeDefinitionDraftBuilder) PRODUCT_TYPE_WITH_REFERENCES_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_TYPE_WITH_REFERENCES_RESOURCE_PATH) REFERENCE_ID_FIELD(com.commercetools.sync.commons.utils.ResourceIdentifierUtils.REFERENCE_ID_FIELD) ProductSyncWithNestedReferencedProductsIT.createNestedAttributeValueReferences(com.commercetools.sync.integration.externalsource.products.ProductSyncWithNestedReferencedProductsIT.createNestedAttributeValueReferences) NestedAttributeType(io.sphere.sdk.products.attributes.NestedAttributeType) AttributeDraft(io.sphere.sdk.products.attributes.AttributeDraft) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) ProductVariantDraftBuilder(io.sphere.sdk.products.ProductVariantDraftBuilder) ProductDraft(io.sphere.sdk.products.ProductDraft) AttributeDraft(io.sphere.sdk.products.attributes.AttributeDraft) Attribute(io.sphere.sdk.products.attributes.Attribute) SetAttribute(io.sphere.sdk.products.commands.updateactions.SetAttribute) ProductVariantDraft(io.sphere.sdk.products.ProductVariantDraft) Product(io.sphere.sdk.products.Product) ProductSync(com.commercetools.sync.products.ProductSync) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ProductSyncWithNestedReferencedProductsIT.createArrayNode(com.commercetools.sync.integration.externalsource.products.ProductSyncWithNestedReferencedProductsIT.createArrayNode) Test(org.junit.jupiter.api.Test)

Aggregations

ProductSync (com.commercetools.sync.products.ProductSync)89 ProductDraft (io.sphere.sdk.products.ProductDraft)85 ProductSyncStatistics (com.commercetools.sync.products.helpers.ProductSyncStatistics)84 Test (org.junit.jupiter.api.Test)83 AttributeDraft (io.sphere.sdk.products.attributes.AttributeDraft)66 ProductVariantDraft (io.sphere.sdk.products.ProductVariantDraft)64 Product (io.sphere.sdk.products.Product)56 Attribute (io.sphere.sdk.products.attributes.Attribute)41 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)35 ProductSyncOptions (com.commercetools.sync.products.ProductSyncOptions)33 SetAttribute (io.sphere.sdk.products.commands.updateactions.SetAttribute)33 BeforeEach (org.junit.jupiter.api.BeforeEach)33 ArrayList (java.util.ArrayList)32 ProductProjection (io.sphere.sdk.products.ProductProjection)30 ProductSyncOptionsBuilder (com.commercetools.sync.products.ProductSyncOptionsBuilder)29 List (java.util.List)29 ProductITUtils.deleteProductSyncTestData (com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteProductSyncTestData)28 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)28 ProductDraftBuilder (io.sphere.sdk.products.ProductDraftBuilder)28 ProductVariantDraftBuilder (io.sphere.sdk.products.ProductVariantDraftBuilder)28