use of com.commercetools.sync.products.AttributeMetaData in project commercetools-sync-java by commercetools.
the class BuildProductVariantAttributesUpdateActionsTest method withNullNewAttributes_ShouldBuildUnSetAttributeActions.
@Test
void withNullNewAttributes_ShouldBuildUnSetAttributeActions() {
// Preparation
final String productKey = "foo";
final String variantKey = "foo";
when(oldProduct.getKey()).thenReturn(productKey);
when(newProductVariant.getAttributes()).thenReturn(null);
when(newProductVariant.getKey()).thenReturn(variantKey);
final List<Attribute> oldAttributes = asList(BOOLEAN_ATTRIBUTE_TRUE, TEXT_ATTRIBUTE_BAR);
when(oldProductVariant.getAttributes()).thenReturn(oldAttributes);
when(oldProductVariant.getKey()).thenReturn(variantKey);
final HashMap<String, AttributeMetaData> attributesMetaData = new HashMap<>();
final AttributeDefinition booleanAttributeDefinition = AttributeDefinitionBuilder.of(BOOLEAN_ATTRIBUTE_TRUE.getName(), ofEnglish("label"), BooleanAttributeType.of()).build();
final AttributeDefinition textAttributeDefinition = AttributeDefinitionBuilder.of(TEXT_ATTRIBUTE_BAR.getName(), ofEnglish("label"), StringAttributeType.of()).build();
attributesMetaData.put(BOOLEAN_ATTRIBUTE_TRUE.getName(), AttributeMetaData.of(booleanAttributeDefinition));
attributesMetaData.put(TEXT_ATTRIBUTE_BAR.getName(), AttributeMetaData.of(textAttributeDefinition));
// Test
final List<UpdateAction<Product>> updateActions = buildProductVariantAttributesUpdateActions(oldProduct, newProductDraft, oldProductVariant, newProductVariant, attributesMetaData, syncOptions);
// Assertion
assertThat(updateActions).containsExactly(SetAttribute.ofUnsetAttribute(oldProductVariant.getId(), BOOLEAN_ATTRIBUTE_TRUE.getName(), true), SetAttribute.ofUnsetAttribute(oldProductVariant.getId(), TEXT_ATTRIBUTE_BAR.getName(), true));
}
use of com.commercetools.sync.products.AttributeMetaData in project commercetools-sync-java by commercetools.
the class BuildProductVariantAttributesUpdateActionsTest method withSomeNonChangedMatchingAttributesAndNoNewAttributes_ShouldBuildUnSetAttributeActions.
@Test
void withSomeNonChangedMatchingAttributesAndNoNewAttributes_ShouldBuildUnSetAttributeActions() {
// Preparation
final String productKey = "foo";
final String variantKey = "foo";
when(oldProduct.getKey()).thenReturn(productKey);
final List<AttributeDraft> newAttributes = singletonList(AttributeDraftBuilder.of(BOOLEAN_ATTRIBUTE_TRUE).build());
when(newProductVariant.getAttributes()).thenReturn(newAttributes);
when(newProductVariant.getKey()).thenReturn(variantKey);
final List<Attribute> oldAttributes = asList(BOOLEAN_ATTRIBUTE_TRUE, TEXT_ATTRIBUTE_BAR);
when(oldProductVariant.getAttributes()).thenReturn(oldAttributes);
when(oldProductVariant.getKey()).thenReturn(variantKey);
final HashMap<String, AttributeMetaData> attributesMetaData = new HashMap<>();
final AttributeDefinition booleanAttributeDefinition = AttributeDefinitionBuilder.of(BOOLEAN_ATTRIBUTE_TRUE.getName(), ofEnglish("label"), BooleanAttributeType.of()).build();
final AttributeDefinition textAttributeDefinition = AttributeDefinitionBuilder.of(TEXT_ATTRIBUTE_BAR.getName(), ofEnglish("label"), StringAttributeType.of()).build();
attributesMetaData.put(BOOLEAN_ATTRIBUTE_TRUE.getName(), AttributeMetaData.of(booleanAttributeDefinition));
attributesMetaData.put(TEXT_ATTRIBUTE_BAR.getName(), AttributeMetaData.of(textAttributeDefinition));
// Test
final List<UpdateAction<Product>> updateActions = buildProductVariantAttributesUpdateActions(oldProduct, newProductDraft, oldProductVariant, newProductVariant, attributesMetaData, syncOptions);
// Assertion
assertThat(updateActions).containsExactly(SetAttribute.ofUnsetAttribute(oldProductVariant.getId(), TEXT_ATTRIBUTE_BAR.getName(), true));
}
use of com.commercetools.sync.products.AttributeMetaData in project commercetools-sync-java by commercetools.
the class BuildProductVariantAttributesUpdateActionsTest method withAllChangedMatchingAttributes_ShouldBuildSetActions.
@Test
void withAllChangedMatchingAttributes_ShouldBuildSetActions() {
// Preparation
final String productKey = "foo";
final String variantKey = "foo";
when(oldProduct.getKey()).thenReturn(productKey);
final List<AttributeDraft> newAttributes = asList(AttributeDraftBuilder.of(BOOLEAN_ATTRIBUTE_TRUE).build(), AttributeDraftBuilder.of(TEXT_ATTRIBUTE_FOO).build());
when(newProductVariant.getAttributes()).thenReturn(newAttributes);
when(newProductVariant.getKey()).thenReturn(variantKey);
final List<Attribute> oldAttributes = asList(BOOLEAN_ATTRIBUTE_FALSE, TEXT_ATTRIBUTE_BAR);
when(oldProductVariant.getAttributes()).thenReturn(oldAttributes);
when(oldProductVariant.getKey()).thenReturn(variantKey);
final HashMap<String, AttributeMetaData> attributesMetaData = new HashMap<>();
final AttributeDefinition booleanAttributeDefinition = AttributeDefinitionBuilder.of(BOOLEAN_ATTRIBUTE_TRUE.getName(), ofEnglish("label"), BooleanAttributeType.of()).build();
final AttributeDefinition textAttributeDefinition = AttributeDefinitionBuilder.of(TEXT_ATTRIBUTE_BAR.getName(), ofEnglish("label"), StringAttributeType.of()).build();
attributesMetaData.put(BOOLEAN_ATTRIBUTE_TRUE.getName(), AttributeMetaData.of(booleanAttributeDefinition));
attributesMetaData.put(TEXT_ATTRIBUTE_BAR.getName(), AttributeMetaData.of(textAttributeDefinition));
// Test
final List<UpdateAction<Product>> updateActions = buildProductVariantAttributesUpdateActions(oldProduct, newProductDraft, oldProductVariant, newProductVariant, attributesMetaData, syncOptions);
// Assertion
assertThat(updateActions).containsExactlyInAnyOrder(SetAttribute.of(oldProductVariant.getId(), AttributeDraftBuilder.of(TEXT_ATTRIBUTE_FOO).build(), true), SetAttribute.of(oldProductVariant.getId(), AttributeDraftBuilder.of(BOOLEAN_ATTRIBUTE_TRUE).build(), true));
}
use of com.commercetools.sync.products.AttributeMetaData in project commercetools-sync-java by commercetools.
the class BuildProductVariantAttributesUpdateActionsTest method withSomeChangedMatchingAttributes_ShouldBuildSetActions.
@Test
void withSomeChangedMatchingAttributes_ShouldBuildSetActions() {
// Preparation
final String productKey = "foo";
final String variantKey = "foo";
when(oldProduct.getKey()).thenReturn(productKey);
final List<AttributeDraft> newAttributes = asList(AttributeDraftBuilder.of(BOOLEAN_ATTRIBUTE_TRUE).build(), AttributeDraftBuilder.of(TEXT_ATTRIBUTE_FOO).build());
when(newProductVariant.getAttributes()).thenReturn(newAttributes);
when(newProductVariant.getKey()).thenReturn(variantKey);
final List<Attribute> oldAttributes = asList(BOOLEAN_ATTRIBUTE_TRUE, TEXT_ATTRIBUTE_BAR);
when(oldProductVariant.getAttributes()).thenReturn(oldAttributes);
when(oldProductVariant.getKey()).thenReturn(variantKey);
final HashMap<String, AttributeMetaData> attributesMetaData = new HashMap<>();
final AttributeDefinition booleanAttributeDefinition = AttributeDefinitionBuilder.of(BOOLEAN_ATTRIBUTE_TRUE.getName(), ofEnglish("label"), BooleanAttributeType.of()).build();
final AttributeDefinition textAttributeDefinition = AttributeDefinitionBuilder.of(TEXT_ATTRIBUTE_BAR.getName(), ofEnglish("label"), StringAttributeType.of()).build();
attributesMetaData.put(BOOLEAN_ATTRIBUTE_TRUE.getName(), AttributeMetaData.of(booleanAttributeDefinition));
attributesMetaData.put(TEXT_ATTRIBUTE_BAR.getName(), AttributeMetaData.of(textAttributeDefinition));
// Test
final List<UpdateAction<Product>> updateActions = buildProductVariantAttributesUpdateActions(oldProduct, newProductDraft, oldProductVariant, newProductVariant, attributesMetaData, syncOptions);
// Assertion
assertThat(updateActions).containsExactly(SetAttribute.of(oldProductVariant.getId(), AttributeDraftBuilder.of(TEXT_ATTRIBUTE_FOO).build(), true));
}
use of com.commercetools.sync.products.AttributeMetaData in project commercetools-sync-java by commercetools.
the class BuildProductVariantAttributesUpdateActionsTest method withNoMatchingAttributes_ShouldBuildUnsetAndSetActionsInCorrectOrder.
@Test
void withNoMatchingAttributes_ShouldBuildUnsetAndSetActionsInCorrectOrder() {
// Preparation
final String productKey = "foo";
final String variantKey = "foo";
when(oldProduct.getKey()).thenReturn(productKey);
final List<AttributeDraft> newAttributes = singletonList(AttributeDraftBuilder.of(BOOLEAN_ATTRIBUTE_TRUE).build());
when(newProductVariant.getAttributes()).thenReturn(newAttributes);
when(newProductVariant.getKey()).thenReturn(variantKey);
final List<Attribute> oldAttributes = singletonList(TEXT_ATTRIBUTE_BAR);
when(oldProductVariant.getAttributes()).thenReturn(oldAttributes);
when(oldProductVariant.getKey()).thenReturn(variantKey);
final HashMap<String, AttributeMetaData> attributesMetaData = new HashMap<>();
final AttributeDefinition booleanAttributeDefinition = AttributeDefinitionBuilder.of(BOOLEAN_ATTRIBUTE_TRUE.getName(), ofEnglish("label"), BooleanAttributeType.of()).build();
final AttributeDefinition textAttributeDefinition = AttributeDefinitionBuilder.of(TEXT_ATTRIBUTE_BAR.getName(), ofEnglish("label"), StringAttributeType.of()).build();
attributesMetaData.put(BOOLEAN_ATTRIBUTE_TRUE.getName(), AttributeMetaData.of(booleanAttributeDefinition));
attributesMetaData.put(TEXT_ATTRIBUTE_BAR.getName(), AttributeMetaData.of(textAttributeDefinition));
// Test
final List<UpdateAction<Product>> updateActions = buildProductVariantAttributesUpdateActions(oldProduct, newProductDraft, oldProductVariant, newProductVariant, attributesMetaData, syncOptions);
// Assertion
assertThat(updateActions).containsExactly(SetAttribute.ofUnsetAttribute(oldProductVariant.getId(), TEXT_ATTRIBUTE_BAR.getName(), true), SetAttribute.of(oldProductVariant.getId(), AttributeDraftBuilder.of(BOOLEAN_ATTRIBUTE_TRUE).build(), true));
}
Aggregations