use of com.neovisionaries.i18n.CountryCode.DE in project commercetools-sync-java by commercetools.
the class ProductSyncWithPricesIT method sync_WithNullNewCustomFields_ShouldCorrectlyUpdateCustomFields.
@Test
void sync_WithNullNewCustomFields_ShouldCorrectlyUpdateCustomFields() {
// preparation
final ArrayNode emptySet = JsonNodeFactory.instance.arrayNode();
final Map<String, JsonNode> customFieldsJsonMap = createCustomFieldsJsonMap(EMPTY_SET_CUSTOM_FIELD_NAME, emptySet);
final ArrayNode nonEmptySet = JsonNodeFactory.instance.arrayNode();
nonEmptySet.add("foo");
customFieldsJsonMap.put(NON_EMPTY_SEY_CUSTOM_FIELD_NAME, nonEmptySet);
final CustomFieldsDraft customType1WithSet = CustomFieldsDraft.ofTypeIdAndJson(customType1.getId(), customFieldsJsonMap);
final PriceDraft withChannel1CustomType1WithSet = getPriceDraft(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getId(), customType1WithSet);
final ProductDraft existingProductDraft = ProductDraftBuilder.of(productType.toReference(), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, singletonList(withChannel1CustomType1WithSet))).key("bar").build();
product = executeBlocking(CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(existingProductDraft)));
final CustomFieldsDraft customType1WithEmptySet = CustomFieldsDraft.ofTypeKeyAndJson(customType1.getKey(), new HashMap<>());
final PriceDraft withChannel1CustomType1WithNullSet = getPriceDraftWithKeys(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getKey(), customType1WithEmptySet);
final ProductDraft newProductDraft = ProductDraftBuilder.of(referenceOfId(productType.getKey()), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, singletonList(withChannel1CustomType1WithNullSet))).key("bar").build();
// test
final ProductSyncStatistics syncStatistics = executeBlocking(productSync.sync(singletonList(newProductDraft)));
// assertion
assertThat(syncStatistics).hasValues(1, 0, 1, 0, 0);
assertThat(updateActionsFromSync).filteredOn(action -> action instanceof SetProductPriceCustomField).hasSize(2);
final ProductProjection productProjection = CTP_TARGET_CLIENT.execute(ProductProjectionByKeyGet.of(newProductDraft.getKey(), ProductProjectionType.STAGED)).toCompletableFuture().join();
assertThat(productProjection).isNotNull();
final List<Price> prices = productProjection.getMasterVariant().getPrices();
for (Price price : prices) {
assertThat(price.getCustom().getFieldAsStringSet(EMPTY_SET_CUSTOM_FIELD_NAME)).isNull();
assertThat(price.getCustom().getFieldAsStringSet(NULL_SET_CUSTOM_FIELD_NAME)).isNull();
assertThat(price.getCustom().getFieldAsStringSet(NULL_NODE_SET_CUSTOM_FIELD_NAME)).isNull();
assertThat(price.getCustom().getFieldAsStringSet(NON_EMPTY_SEY_CUSTOM_FIELD_NAME)).isNull();
}
}
use of com.neovisionaries.i18n.CountryCode.DE in project commercetools-sync-java by commercetools.
the class ProductSyncWithPricesIT method sync_WithEmptySetNewCustomFields_ShouldCorrectlyUpdateCustomFields.
@Test
void sync_WithEmptySetNewCustomFields_ShouldCorrectlyUpdateCustomFields() {
// preparation
final ArrayNode emptySet = JsonNodeFactory.instance.arrayNode();
final Map<String, JsonNode> customFieldsJsonMap = createCustomFieldsJsonMap(EMPTY_SET_CUSTOM_FIELD_NAME, emptySet);
final ArrayNode nonEmptySet = JsonNodeFactory.instance.arrayNode();
nonEmptySet.add("foo");
customFieldsJsonMap.put(NON_EMPTY_SEY_CUSTOM_FIELD_NAME, nonEmptySet);
final CustomFieldsDraft customType1WithSet = CustomFieldsDraft.ofTypeIdAndJson(customType1.getId(), customFieldsJsonMap);
final PriceDraft withChannel1CustomType1WithSet = getPriceDraft(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getId(), customType1WithSet);
final ProductDraft existingProductDraft = ProductDraftBuilder.of(productType.toReference(), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, singletonList(withChannel1CustomType1WithSet))).key("bar").build();
product = executeBlocking(CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(existingProductDraft)));
final Map<String, JsonNode> newCustomFieldsJsonMap = createCustomFieldsJsonMap(EMPTY_SET_CUSTOM_FIELD_NAME, emptySet);
newCustomFieldsJsonMap.put(NULL_SET_CUSTOM_FIELD_NAME, emptySet);
newCustomFieldsJsonMap.put(NON_EMPTY_SEY_CUSTOM_FIELD_NAME, emptySet);
newCustomFieldsJsonMap.put(NULL_NODE_SET_CUSTOM_FIELD_NAME, emptySet);
final CustomFieldsDraft customType1WithEmptySet = CustomFieldsDraft.ofTypeKeyAndJson(customType1.getKey(), newCustomFieldsJsonMap);
final PriceDraft withChannel1CustomType1WithNullSet = getPriceDraftWithKeys(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getKey(), customType1WithEmptySet);
final ProductDraft newProductDraft = ProductDraftBuilder.of(referenceOfId(productType.getKey()), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, singletonList(withChannel1CustomType1WithNullSet))).key("bar").build();
// test
final ProductSyncStatistics syncStatistics = executeBlocking(productSync.sync(singletonList(newProductDraft)));
// assertion
assertThat(syncStatistics).hasValues(1, 0, 1, 0, 0);
assertThat(updateActionsFromSync).filteredOn(action -> action instanceof SetProductPriceCustomField).hasSize(3);
final ProductProjection productProjection = CTP_TARGET_CLIENT.execute(ProductProjectionByKeyGet.of(newProductDraft.getKey(), ProductProjectionType.STAGED)).toCompletableFuture().join();
assertThat(productProjection).isNotNull();
final List<Price> prices = productProjection.getMasterVariant().getPrices();
for (Price price : prices) {
assertThat(price.getCustom().getFieldAsStringSet(EMPTY_SET_CUSTOM_FIELD_NAME)).isEmpty();
assertThat(price.getCustom().getFieldAsStringSet(NULL_SET_CUSTOM_FIELD_NAME)).isEmpty();
assertThat(price.getCustom().getFieldAsStringSet(NULL_NODE_SET_CUSTOM_FIELD_NAME)).isEmpty();
assertThat(price.getCustom().getFieldAsStringSet(NON_EMPTY_SEY_CUSTOM_FIELD_NAME)).isEmpty();
}
}
use of com.neovisionaries.i18n.CountryCode.DE in project commercetools-sync-java by commercetools.
the class ProductSyncWithPricesIT method sync_WithNullJsonNodeNewCustomFields_ShouldCorrectlyUpdateCustomFields.
@Test
void sync_WithNullJsonNodeNewCustomFields_ShouldCorrectlyUpdateCustomFields() {
// preparation
final ArrayNode emptySet = JsonNodeFactory.instance.arrayNode();
final Map<String, JsonNode> customFieldsJsonMap = createCustomFieldsJsonMap(EMPTY_SET_CUSTOM_FIELD_NAME, emptySet);
final ArrayNode nonEmptySet = JsonNodeFactory.instance.arrayNode();
nonEmptySet.add("foo");
customFieldsJsonMap.put(NON_EMPTY_SEY_CUSTOM_FIELD_NAME, nonEmptySet);
final CustomFieldsDraft customType1WithSet = CustomFieldsDraft.ofTypeIdAndJson(customType1.getId(), customFieldsJsonMap);
final PriceDraft withChannel1CustomType1WithSet = getPriceDraft(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getId(), customType1WithSet);
final ProductDraft existingProductDraft = ProductDraftBuilder.of(productType.toReference(), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, singletonList(withChannel1CustomType1WithSet))).key("bar").build();
product = executeBlocking(CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(existingProductDraft)));
final NullNode nullJsonNode = JsonNodeFactory.instance.nullNode();
final Map<String, JsonNode> newCustomFieldsJsonMap = createCustomFieldsJsonMap(EMPTY_SET_CUSTOM_FIELD_NAME, nullJsonNode);
newCustomFieldsJsonMap.put(NULL_SET_CUSTOM_FIELD_NAME, nullJsonNode);
newCustomFieldsJsonMap.put(NULL_NODE_SET_CUSTOM_FIELD_NAME, nullJsonNode);
newCustomFieldsJsonMap.put(NON_EMPTY_SEY_CUSTOM_FIELD_NAME, nullJsonNode);
final CustomFieldsDraft customType1WithEmptySet = CustomFieldsDraft.ofTypeKeyAndJson(customType1.getKey(), newCustomFieldsJsonMap);
final PriceDraft withChannel1CustomType1WithNullSet = getPriceDraftWithKeys(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getKey(), customType1WithEmptySet);
final ProductDraft newProductDraft = ProductDraftBuilder.of(referenceOfId(productType.getKey()), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, singletonList(withChannel1CustomType1WithNullSet))).key("bar").build();
// test
final ProductSyncStatistics syncStatistics = executeBlocking(productSync.sync(singletonList(newProductDraft)));
// assertion
assertThat(syncStatistics).hasValues(1, 0, 1, 0, 0);
assertThat(updateActionsFromSync).filteredOn(action -> action instanceof SetProductPriceCustomField).hasSize(2);
final ProductProjection productProjection = CTP_TARGET_CLIENT.execute(ProductProjectionByKeyGet.of(newProductDraft.getKey(), ProductProjectionType.STAGED)).toCompletableFuture().join();
assertThat(productProjection).isNotNull();
final List<Price> prices = productProjection.getMasterVariant().getPrices();
for (Price price : prices) {
assertThat(price.getCustom().getFieldAsStringSet(EMPTY_SET_CUSTOM_FIELD_NAME)).isNull();
assertThat(price.getCustom().getFieldAsStringSet(NULL_SET_CUSTOM_FIELD_NAME)).isNull();
assertThat(price.getCustom().getFieldAsStringSet(NULL_NODE_SET_CUSTOM_FIELD_NAME)).isNull();
assertThat(price.getCustom().getFieldAsStringSet(NON_EMPTY_SEY_CUSTOM_FIELD_NAME)).isNull();
}
}
use of com.neovisionaries.i18n.CountryCode.DE in project commercetools-jvm-sdk by commercetools.
the class OrderUpdateCommandIntegrationTest method setBillingAddress.
@Test
public void setBillingAddress() {
withOrder(client(), order -> {
assertThat(order.getBillingAddress()).isNull();
final Address newAddress = Address.of(DE).withStreetNumber("5");
final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, SetBillingAddress.of(newAddress)));
assertThat(updatedOrder.getBillingAddress().getStreetNumber()).isEqualTo("5");
// there is also a message
final Query<OrderBillingAddressSetMessage> messageQuery = MessageQuery.of().withPredicates(m -> m.resource().is(order)).forMessageType(OrderBillingAddressSetMessage.MESSAGE_HINT);
assertEventually(() -> {
final Optional<OrderBillingAddressSetMessage> billingAddressSetMessageOptional = client().executeBlocking(messageQuery).head();
assertThat(billingAddressSetMessageOptional).isPresent();
final OrderBillingAddressSetMessage orderBillingAddressSetMessage = billingAddressSetMessageOptional.get();
assertThat(orderBillingAddressSetMessage.getAddress()).isEqualTo(newAddress);
});
return updatedOrder;
});
}
use of com.neovisionaries.i18n.CountryCode.DE in project commercetools-sync-java by commercetools.
the class ProductSyncWithPricesIT method sync_withSomeChangedMatchingPrices_ShouldAddAndRemovePrices.
@Test
void sync_withSomeChangedMatchingPrices_ShouldAddAndRemovePrices() {
// Preparation
final List<PriceDraft> oldPrices = asList(DRAFT_DE_111_EUR, DRAFT_UK_111_GBP, DRAFT_DE_111_EUR_03_04, DRAFT_DE_111_EUR_01_02);
final PriceDraft price1WithCustomerGroupWithKey = getPriceDraftWithKeys(BigDecimal.valueOf(222), EUR, DE, "cust1", null, null, null, null);
final PriceDraft price2WithCustomerGroupWithKey = getPriceDraftWithKeys(BigDecimal.valueOf(333), USD, DE, "cust1", null, null, null, null);
final PriceDraft price1WithCustomerGroupReferenceWithCust1Id = PriceDraftBuilder.of(getPriceDraft(BigDecimal.valueOf(222), EUR, DE, cust1.getId(), null, null, null, null)).customerGroup(cust1).build();
final PriceDraft price2WithCustomerGroupReferenceWithCust1Id = PriceDraftBuilder.of(getPriceDraft(BigDecimal.valueOf(333), USD, DE, cust1.getId(), null, null, null, null)).customerGroup(cust1).build();
final List<PriceDraft> newPrices = asList(DRAFT_DE_111_EUR, DRAFT_UK_111_GBP, price1WithCustomerGroupWithKey, price2WithCustomerGroupWithKey);
final ProductDraft existingProductDraft = ProductDraftBuilder.of(productType.toReference(), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, oldPrices)).key("bar").build();
product = executeBlocking(CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(existingProductDraft)));
final ProductDraft newProductDraft = ProductDraftBuilder.of(referenceOfId(productType.getKey()), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, newPrices)).key("bar").build();
// test
final ProductSyncStatistics syncStatistics = executeBlocking(productSync.sync(singletonList(newProductDraft)));
// assertion
assertThat(syncStatistics).hasValues(1, 0, 1, 0, 0);
final Integer masterVariantId = product.getMasterData().getStaged().getMasterVariant().getId();
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
assertThat(updateActionsFromSync).filteredOn(action -> action instanceof RemovePrice).hasSize(2);
assertThat(updateActionsFromSync).filteredOn(action -> action instanceof AddPrice).hasSize(2).containsExactlyInAnyOrder(AddPrice.ofVariantId(masterVariantId, price1WithCustomerGroupReferenceWithCust1Id, true), AddPrice.ofVariantId(masterVariantId, price2WithCustomerGroupReferenceWithCust1Id, true));
final ProductProjection productProjection = CTP_TARGET_CLIENT.execute(ProductProjectionByKeyGet.of(newProductDraft.getKey(), ProductProjectionType.STAGED)).toCompletableFuture().join();
assertThat(productProjection).isNotNull();
final List<PriceDraft> newPricesWithIds = asList(DRAFT_DE_111_EUR, DRAFT_UK_111_GBP, price1WithCustomerGroupReferenceWithCust1Id, price2WithCustomerGroupReferenceWithCust1Id);
assertPricesAreEqual(productProjection.getMasterVariant().getPrices(), newPricesWithIds);
}
Aggregations