use of com.commercetools.sync.products.helpers.PriceCustomActionBuilder in project commercetools-sync-java by commercetools.
the class CustomUpdateActionUtilsTest method buildSetCustomFieldsUpdateActions_WithDifferentCustomFieldValues_ShouldBuildUpdateActions.
@Test
void buildSetCustomFieldsUpdateActions_WithDifferentCustomFieldValues_ShouldBuildUpdateActions() {
final Map<String, JsonNode> oldCustomFields = new HashMap<>();
oldCustomFields.put("invisibleInShop", JsonNodeFactory.instance.booleanNode(false));
oldCustomFields.put("backgroundColor", JsonNodeFactory.instance.objectNode().put("de", "rot").put("en", "red"));
final Map<String, JsonNode> newCustomFields = new HashMap<>();
newCustomFields.put("invisibleInShop", JsonNodeFactory.instance.booleanNode(true));
newCustomFields.put("backgroundColor", JsonNodeFactory.instance.objectNode().put("de", "rot"));
final List<UpdateAction<Product>> updateActions = buildSetCustomFieldsUpdateActions(oldCustomFields, newCustomFields, mock(Price.class), new PriceCustomActionBuilder(), 1, Price::getId);
assertThat(updateActions).isNotNull();
assertThat(updateActions).isNotEmpty();
assertThat(updateActions).hasSize(2);
final UpdateAction<Product> categoryUpdateAction = updateActions.get(0);
assertThat(categoryUpdateAction).isNotNull();
assertThat(categoryUpdateAction).isInstanceOf(SetProductPriceCustomField.class);
}
use of com.commercetools.sync.products.helpers.PriceCustomActionBuilder in project commercetools-sync-java by commercetools.
the class CustomUpdateActionUtilsTest method buildSetCustomFieldsUpdateActions_WithRemovedCustomFields_ShouldBuildUpdateActions.
@Test
void buildSetCustomFieldsUpdateActions_WithRemovedCustomFields_ShouldBuildUpdateActions() {
final Map<String, JsonNode> oldCustomFields = new HashMap<>();
oldCustomFields.put("invisibleInShop", JsonNodeFactory.instance.booleanNode(true));
oldCustomFields.put("backgroundColor", JsonNodeFactory.instance.objectNode().put("de", "rot").put("en", "red"));
final Map<String, JsonNode> newCustomFields = new HashMap<>();
newCustomFields.put("invisibleInShop", JsonNodeFactory.instance.booleanNode(true));
final List<UpdateAction<Product>> updateActions = buildSetCustomFieldsUpdateActions(oldCustomFields, newCustomFields, mock(Price.class), new PriceCustomActionBuilder(), 1, Price::getId);
assertThat(updateActions).hasSize(1).singleElement().matches(action -> {
assertThat(action).isInstanceOf(SetProductPriceCustomField.class);
final SetProductPriceCustomField setProductPriceCustomFieldAction = (SetProductPriceCustomField) action;
assertThat(setProductPriceCustomFieldAction.getName()).isEqualTo("backgroundColor");
assertThat(setProductPriceCustomFieldAction.getValue()).isEqualTo(null);
return true;
});
}
use of com.commercetools.sync.products.helpers.PriceCustomActionBuilder in project commercetools-sync-java by commercetools.
the class CustomUpdateActionUtilsTest method buildNonNullCustomFieldsUpdateActions_WithNullIds_ShouldThrowBuildUpdateActionException.
@Test
void buildNonNullCustomFieldsUpdateActions_WithNullIds_ShouldThrowBuildUpdateActionException() {
final Reference<Type> productPriceTypeReference = Type.referenceOfId(null);
// Mock old CustomFields
final CustomFields oldCustomFieldsMock = mock(CustomFields.class);
when(oldCustomFieldsMock.getType()).thenReturn(productPriceTypeReference);
// Mock new CustomFieldsDraft
final CustomFieldsDraft newCustomFieldsMock = mock(CustomFieldsDraft.class);
when(newCustomFieldsMock.getType()).thenReturn(productPriceTypeReference);
assertThatThrownBy(() -> buildNonNullCustomFieldsUpdateActions(oldCustomFieldsMock, newCustomFieldsMock, mock(Price.class), new PriceCustomActionBuilder(), 1, Price::getId, priceResource -> Price.resourceTypeId(), Price::getId, ProductSyncOptionsBuilder.of(CTP_CLIENT).build())).isInstanceOf(BuildUpdateActionException.class).hasMessageMatching("Custom type ids are not set for both the old and new product-price.");
}
use of com.commercetools.sync.products.helpers.PriceCustomActionBuilder in project commercetools-sync-java by commercetools.
the class CustomUpdateActionUtilsTest method buildNonNullCustomFieldsUpdateActions_WithSameIdsButNullNewCustomFields_ShouldBuildUpdateActions.
@Test
void buildNonNullCustomFieldsUpdateActions_WithSameIdsButNullNewCustomFields_ShouldBuildUpdateActions() throws BuildUpdateActionException {
final Reference<Type> productPriceTypeReference = Type.referenceOfId("productPriceCustomTypeId");
// Mock old CustomFields
final CustomFields oldCustomFieldsMock = mock(CustomFields.class);
final Map<String, JsonNode> oldCustomFieldsJsonMapMock = new HashMap<>();
oldCustomFieldsJsonMapMock.put("invisibleInShop", JsonNodeFactory.instance.booleanNode(true));
when(oldCustomFieldsMock.getType()).thenReturn(productPriceTypeReference);
when(oldCustomFieldsMock.getFieldsJsonMap()).thenReturn(oldCustomFieldsJsonMapMock);
// Mock new CustomFieldsDraft
final CustomFieldsDraft newCustomFieldsMock = mock(CustomFieldsDraft.class);
when(newCustomFieldsMock.getType()).thenReturn(productPriceTypeReference);
when(newCustomFieldsMock.getFields()).thenReturn(null);
final List<UpdateAction<Product>> updateActions = buildNonNullCustomFieldsUpdateActions(oldCustomFieldsMock, newCustomFieldsMock, mock(Price.class), new PriceCustomActionBuilder(), 1, Price::getId, priceResource -> Price.resourceTypeId(), Price::getId, ProductSyncOptionsBuilder.of(CTP_CLIENT).build());
assertThat(updateActions).isNotNull();
assertThat(updateActions).hasSize(1);
assertThat(updateActions.get(0)).isInstanceOf(SetProductPriceCustomType.class);
}
use of com.commercetools.sync.products.helpers.PriceCustomActionBuilder in project commercetools-sync-java by commercetools.
the class ProductPriceCustomUpdateActionUtilsTest method buildSetCustomFieldAction_WithProductPrice_ShouldBuildProductUpdateAction.
@Test
void buildSetCustomFieldAction_WithProductPrice_ShouldBuildProductUpdateAction() {
final String priceId = "1";
final String customFieldName = "name";
final JsonNode customFieldValue = JsonNodeFactory.instance.textNode("foo");
final UpdateAction<Product> updateAction = new PriceCustomActionBuilder().buildSetCustomFieldAction(1, priceId, customFieldName, customFieldValue);
assertThat(updateAction).isInstanceOf(SetProductPriceCustomField.class);
assertThat((SetProductPriceCustomField) updateAction).hasValues("setProductPriceCustomField", true, priceId, customFieldName, customFieldValue);
}
Aggregations