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);
}
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));
}
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));
}
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);
}
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));
}
Aggregations