use of com.commercetools.sync.products.helpers.PriceCustomActionBuilder in project commercetools-sync-java by commercetools.
the class ProductPriceCustomUpdateActionUtilsTest method buildRemoveCustomTypeAction_WithProductPrice_ShouldBuildChannelUpdateAction.
@Test
void buildRemoveCustomTypeAction_WithProductPrice_ShouldBuildChannelUpdateAction() {
final String priceId = "1";
final UpdateAction<Product> updateAction = new PriceCustomActionBuilder().buildRemoveCustomTypeAction(1, priceId);
assertThat(updateAction).isInstanceOf(SetProductPriceCustomType.class);
assertThat((SetProductPriceCustomType) updateAction).hasValues("setProductPriceCustomType", priceId, true, null, ofId(null));
}
use of com.commercetools.sync.products.helpers.PriceCustomActionBuilder in project commercetools-sync-java by commercetools.
the class CustomUpdateActionUtilsTest method buildSetCustomFieldsUpdateActions_WithNewCustomFields_ShouldBuildUpdateActions.
@Test
void buildSetCustomFieldsUpdateActions_WithNewCustomFields_ShouldBuildUpdateActions() {
final Map<String, JsonNode> oldCustomFields = new HashMap<>();
final Map<String, JsonNode> newCustomFields = new HashMap<>();
newCustomFields.put("invisibleInShop", JsonNodeFactory.instance.booleanNode(true));
newCustomFields.put("backgroundColor", JsonNodeFactory.instance.objectNode().put("de", "rot"));
newCustomFields.put("url", JsonNodeFactory.instance.objectNode().put("domain", "domain.com"));
newCustomFields.put("size", JsonNodeFactory.instance.objectNode().put("cm", 34));
final List<UpdateAction<Product>> updateActions = buildSetCustomFieldsUpdateActions(oldCustomFields, newCustomFields, mock(Price.class), new PriceCustomActionBuilder(), 1, Price::getId);
assertThat(updateActions).hasSize(4);
}
use of com.commercetools.sync.products.helpers.PriceCustomActionBuilder in project commercetools-sync-java by commercetools.
the class CustomUpdateActionUtilsTest method buildNonNullCustomFieldsUpdateActions_WithNullNewCategoryTypeId_ShouldBuildUpdateActions.
@Test
void buildNonNullCustomFieldsUpdateActions_WithNullNewCategoryTypeId_ShouldBuildUpdateActions() throws BuildUpdateActionException {
// Mock old CustomFields
final CustomFields oldCustomFieldsMock = mock(CustomFields.class);
when(oldCustomFieldsMock.getType()).thenReturn(Type.referenceOfId("1"));
// Mock new CustomFieldsDraft
final CustomFieldsDraft newCustomFieldsMock = mock(CustomFieldsDraft.class);
when(newCustomFieldsMock.getType()).thenReturn(Type.referenceOfId(null));
// Mock custom options error callback
final ArrayList<String> errorMessages = new ArrayList<>();
final QuadConsumer<SyncException, Optional<ProductDraft>, Optional<ProductProjection>, List<UpdateAction<Product>>> errorCallback = (exception, newResource, oldResource, updateActions) -> errorMessages.add(exception.getMessage());
// Mock sync options
final ProductSyncOptions productSyncOptions = ProductSyncOptionsBuilder.of(CTP_CLIENT).errorCallback(errorCallback).build();
final Price price = mock(Price.class);
when(price.getId()).thenReturn(UUID.randomUUID().toString());
final List<UpdateAction<Product>> updateActions = buildNonNullCustomFieldsUpdateActions(oldCustomFieldsMock, newCustomFieldsMock, price, new PriceCustomActionBuilder(), 1, Price::getId, priceResource -> Price.resourceTypeId(), Price::getId, productSyncOptions);
assertThat(errorMessages).hasSize(1);
assertThat(errorMessages.get(0)).isEqualTo(format("Failed to build 'setCustomType' update action on the " + "%s with id '%s'. Reason: New Custom Type id is blank (null/empty).", Price.resourceTypeId(), price.getId()));
assertThat(updateActions).isEmpty();
}
use of com.commercetools.sync.products.helpers.PriceCustomActionBuilder in project commercetools-sync-java by commercetools.
the class CustomUpdateActionUtilsTest method buildNonNullCustomFieldsUpdateActions_WithNullOldCategoryTypeId_ShouldBuildUpdateActions.
@Test
void buildNonNullCustomFieldsUpdateActions_WithNullOldCategoryTypeId_ShouldBuildUpdateActions() throws BuildUpdateActionException {
// Mock old CustomFields
final CustomFields oldCustomFieldsMock = mock(CustomFields.class);
when(oldCustomFieldsMock.getType()).thenReturn(Type.referenceOfId(null));
// Mock new CustomFieldsDraft
final CustomFieldsDraft newCustomFieldsMock = mock(CustomFieldsDraft.class);
when(newCustomFieldsMock.getType()).thenReturn(Type.referenceOfId("priceCustomTypeId"));
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 buildTypedSetCustomTypeUpdateAction_WithProductPrice_ShouldBuildProductUpdateAction.
@Test
void buildTypedSetCustomTypeUpdateAction_WithProductPrice_ShouldBuildProductUpdateAction() {
final Price price = mock(Price.class);
when(price.getId()).thenReturn("priceId");
final String newCustomTypeId = UUID.randomUUID().toString();
final UpdateAction<Product> updateAction = buildTypedSetCustomTypeUpdateAction(newCustomTypeId, new HashMap<>(), price, new PriceCustomActionBuilder(), 1, Price::getId, priceResource -> Price.resourceTypeId(), Price::getId, ProductSyncOptionsBuilder.of(mock(SphereClient.class)).build()).orElse(null);
assertThat(updateAction).isInstanceOf(SetProductPriceCustomType.class);
assertThat((SetProductPriceCustomType) updateAction).hasValues("setProductPriceCustomType", price.getId(), true, emptyMap(), ofId(newCustomTypeId));
}
Aggregations