Search in sources :

Example 1 with AttributeMetaData

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

the class BuildProductVariantAttributeUpdateActionsTest method withSameValues_WithNoExistingAttributeInMetaData_ShouldThrowException.

@Test
void withSameValues_WithNoExistingAttributeInMetaData_ShouldThrowException() {
    // Preparation
    final Attribute oldAttribute = Attribute.of("foo", JsonNodeFactory.instance.textNode("foo"));
    final AttributeDraft newAttribute = AttributeDraft.of("foo", JsonNodeFactory.instance.textNode("foo"));
    final Map<String, AttributeMetaData> attributesMetaData = new HashMap<>();
    // Test and assertion
    assertThatThrownBy(() -> buildProductVariantAttributeUpdateAction(1, oldAttribute, newAttribute, attributesMetaData)).hasMessage(format(ATTRIBUTE_NOT_IN_ATTRIBUTE_METADATA, newAttribute.getName())).isExactlyInstanceOf(BuildUpdateActionException.class);
}
Also used : Attribute(io.sphere.sdk.products.attributes.Attribute) SetAttribute(io.sphere.sdk.products.commands.updateactions.SetAttribute) AttributeDraft(io.sphere.sdk.products.attributes.AttributeDraft) AttributeMetaData(com.commercetools.sync.products.AttributeMetaData) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 2 with AttributeMetaData

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

the class BuildProductVariantAttributeUpdateActionsTest method withNullOldAndNonNullNew_ShouldBuildSetAction.

@Test
void withNullOldAndNonNullNew_ShouldBuildSetAction() throws BuildUpdateActionException {
    // Preparation
    final int variantId = 1;
    final Attribute oldAttribute = null;
    final AttributeDraft newAttribute = AttributeDraft.of("foo", JsonNodeFactory.instance.objectNode());
    final Map<String, AttributeMetaData> attributesMetaData = new HashMap<>();
    final AttributeDefinition attributeDefinition = AttributeDefinitionBuilder.of(newAttribute.getName(), ofEnglish("foo"), StringAttributeType.of()).build();
    attributesMetaData.put(newAttribute.getName(), AttributeMetaData.of(attributeDefinition));
    // Test
    final Optional<UpdateAction<Product>> actionOptional = buildProductVariantAttributeUpdateAction(variantId, oldAttribute, newAttribute, attributesMetaData);
    // Assertion
    assertThat(actionOptional).contains(SetAttribute.of(variantId, newAttribute.getName(), newAttribute.getValue(), true));
}
Also used : Attribute(io.sphere.sdk.products.attributes.Attribute) SetAttribute(io.sphere.sdk.products.commands.updateactions.SetAttribute) AttributeDraft(io.sphere.sdk.products.attributes.AttributeDraft) AttributeMetaData(com.commercetools.sync.products.AttributeMetaData) HashMap(java.util.HashMap) ProductVariantAttributeUpdateActionUtils.buildProductVariantAttributeUpdateAction(com.commercetools.sync.products.utils.ProductVariantAttributeUpdateActionUtils.buildProductVariantAttributeUpdateAction) UpdateAction(io.sphere.sdk.commands.UpdateAction) AttributeDefinition(io.sphere.sdk.products.attributes.AttributeDefinition) AttributeConstraint(io.sphere.sdk.products.attributes.AttributeConstraint) Test(org.junit.jupiter.api.Test)

Example 3 with AttributeMetaData

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

the class BuildProductVariantAttributeUpdateActionsTest method withDifferentValues_ShouldBuildSetAction.

@Test
void withDifferentValues_ShouldBuildSetAction() throws BuildUpdateActionException {
    // Preparation
    final Integer variantId = 1;
    final Attribute oldAttribute = Attribute.of("foo", JsonNodeFactory.instance.textNode("bar"));
    final AttributeDraft newAttribute = AttributeDraft.of("foo", JsonNodeFactory.instance.textNode("other-bar"));
    final Map<String, AttributeMetaData> attributesMetaData = new HashMap<>();
    final AttributeDefinition attributeDefinition = AttributeDefinitionBuilder.of(newAttribute.getName(), ofEnglish("foo"), StringAttributeType.of()).build();
    attributesMetaData.put(newAttribute.getName(), AttributeMetaData.of(attributeDefinition));
    // Test
    final Optional<UpdateAction<Product>> actionOptional = buildProductVariantAttributeUpdateAction(variantId, oldAttribute, newAttribute, attributesMetaData);
    // Assertion
    assertThat(actionOptional).contains(SetAttribute.of(variantId, newAttribute.getName(), newAttribute.getValue(), true));
}
Also used : Attribute(io.sphere.sdk.products.attributes.Attribute) SetAttribute(io.sphere.sdk.products.commands.updateactions.SetAttribute) AttributeDraft(io.sphere.sdk.products.attributes.AttributeDraft) AttributeMetaData(com.commercetools.sync.products.AttributeMetaData) HashMap(java.util.HashMap) ProductVariantAttributeUpdateActionUtils.buildProductVariantAttributeUpdateAction(com.commercetools.sync.products.utils.ProductVariantAttributeUpdateActionUtils.buildProductVariantAttributeUpdateAction) UpdateAction(io.sphere.sdk.commands.UpdateAction) AttributeDefinition(io.sphere.sdk.products.attributes.AttributeDefinition) Test(org.junit.jupiter.api.Test)

Example 4 with AttributeMetaData

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

the class BuildProductVariantAttributeUpdateActionsTest method withDifferentValues_WithNoExistingAttributeInMetaData_ShouldThrowException.

@Test
void withDifferentValues_WithNoExistingAttributeInMetaData_ShouldThrowException() {
    // Preparation
    final Attribute oldAttribute = Attribute.of("foo", JsonNodeFactory.instance.textNode("bar"));
    final AttributeDraft newAttribute = AttributeDraft.of("foo", JsonNodeFactory.instance.textNode("other-bar"));
    final Map<String, AttributeMetaData> attributesMetaData = new HashMap<>();
    // Test and assertion
    assertThatThrownBy(() -> buildProductVariantAttributeUpdateAction(1, oldAttribute, newAttribute, attributesMetaData)).hasMessage(format(ATTRIBUTE_NOT_IN_ATTRIBUTE_METADATA, newAttribute.getName())).isExactlyInstanceOf(BuildUpdateActionException.class);
}
Also used : Attribute(io.sphere.sdk.products.attributes.Attribute) SetAttribute(io.sphere.sdk.products.commands.updateactions.SetAttribute) AttributeDraft(io.sphere.sdk.products.attributes.AttributeDraft) AttributeMetaData(com.commercetools.sync.products.AttributeMetaData) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 5 with AttributeMetaData

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

the class BuildProductVariantAttributeUpdateActionsTest method withNullOldAndNonNullNew_WithSameForAllAttribute_ShouldBuildSetAllAction.

@Test
void withNullOldAndNonNullNew_WithSameForAllAttribute_ShouldBuildSetAllAction() throws BuildUpdateActionException {
    // Preparation
    final Attribute oldAttribute = null;
    final AttributeDraft newAttribute = AttributeDraft.of("foo", JsonNodeFactory.instance.objectNode());
    final Map<String, AttributeMetaData> attributesMetaData = new HashMap<>();
    final AttributeDefinition attributeDefinition = AttributeDefinitionBuilder.of(newAttribute.getName(), ofEnglish("foo"), StringAttributeType.of()).attributeConstraint(AttributeConstraint.SAME_FOR_ALL).build();
    attributesMetaData.put(newAttribute.getName(), AttributeMetaData.of(attributeDefinition));
    // Test
    final Optional<UpdateAction<Product>> actionOptional = buildProductVariantAttributeUpdateAction(1, oldAttribute, newAttribute, attributesMetaData);
    // Assertion
    assertThat(actionOptional).contains(SetAttributeInAllVariants.of(newAttribute.getName(), newAttribute.getValue(), true));
}
Also used : Attribute(io.sphere.sdk.products.attributes.Attribute) SetAttribute(io.sphere.sdk.products.commands.updateactions.SetAttribute) AttributeDraft(io.sphere.sdk.products.attributes.AttributeDraft) AttributeMetaData(com.commercetools.sync.products.AttributeMetaData) HashMap(java.util.HashMap) ProductVariantAttributeUpdateActionUtils.buildProductVariantAttributeUpdateAction(com.commercetools.sync.products.utils.ProductVariantAttributeUpdateActionUtils.buildProductVariantAttributeUpdateAction) UpdateAction(io.sphere.sdk.commands.UpdateAction) AttributeDefinition(io.sphere.sdk.products.attributes.AttributeDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

AttributeMetaData (com.commercetools.sync.products.AttributeMetaData)30 HashMap (java.util.HashMap)28 UpdateAction (io.sphere.sdk.commands.UpdateAction)26 Test (org.junit.jupiter.api.Test)26 AttributeDraft (io.sphere.sdk.products.attributes.AttributeDraft)21 SetAttribute (io.sphere.sdk.products.commands.updateactions.SetAttribute)21 Attribute (io.sphere.sdk.products.attributes.Attribute)20 AttributeDefinition (io.sphere.sdk.products.attributes.AttributeDefinition)18 ProductDraft (io.sphere.sdk.products.ProductDraft)8 ProductSyncOptions (com.commercetools.sync.products.ProductSyncOptions)6 ProductProjection (io.sphere.sdk.products.ProductProjection)6 ProductVariantDraft (io.sphere.sdk.products.ProductVariantDraft)6 SyncFilter (com.commercetools.sync.products.SyncFilter)4 ProductVariantAttributeUpdateActionUtils.buildProductVariantAttributeUpdateAction (com.commercetools.sync.products.utils.ProductVariantAttributeUpdateActionUtils.buildProductVariantAttributeUpdateAction)4 LocalizedString (io.sphere.sdk.models.LocalizedString)4 CollectionUtils.emptyIfNull (com.commercetools.sync.commons.utils.CollectionUtils.emptyIfNull)3 ActionGroup (com.commercetools.sync.products.ActionGroup)3 Product (io.sphere.sdk.products.Product)3 ProductVariant (io.sphere.sdk.products.ProductVariant)3 RemoveVariant (io.sphere.sdk.products.commands.updateactions.RemoveVariant)3