use of com.neovisionaries.i18n.CountryCode.DE in project commercetools-sync-java by commercetools.
the class ProductSyncWithPricesIT method withMixedCasesOfPriceMatches_ShouldBuildActions.
@Test
void withMixedCasesOfPriceMatches_ShouldBuildActions() {
// Preparation
createExistingProductWithPrices();
final ProductDraft newProductDraft = createProductDraftWithNewPrices();
final ObjectNode lTextWithEnDe = JsonNodeFactory.instance.objectNode().put("de", "rot").put("en", "red");
final PriceDraft de222EurCust1Ofid = PriceDraftBuilder.of(DRAFT_DE_222_EUR_CUST1).customerGroup(cust1).build();
final PriceDraft de333UsdCust1Ofid = PriceDraftBuilder.of(DRAFT_DE_333_USD_CUST1).customerGroup(cust1).build();
final PriceDraft us666Usd0102Cust2OfId = PriceDraftBuilder.of(DRAFT_US_666_USD_CUST2_01_02).customerGroup(cust2).build();
final CustomFieldsDraft customType1WithEnDeOfId = CustomFieldsDraft.ofTypeIdAndJson(customType1.getId(), createCustomFieldsJsonMap(LOCALISED_STRING_CUSTOM_FIELD_NAME, lTextWithEnDe));
final PriceDraft withChannel1CustomType1WithEnDeOfId = getPriceDraft(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getId(), customType1WithEnDeOfId);
final PriceDraft withChannel2CustomType1WithEnDeOfId = getPriceDraft(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel2.getId(), customType1WithEnDeOfId);
// 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(5);
assertThat(updateActionsFromSync).filteredOn(action -> action instanceof ChangePrice).hasSize(3);
assertThat(updateActionsFromSync).filteredOn(action -> action instanceof SetProductPriceCustomType).hasSize(1);
assertThat(updateActionsFromSync).filteredOn(action -> action instanceof SetProductPriceCustomField).hasSize(1);
assertThat(updateActionsFromSync).filteredOn(action -> action instanceof AddPrice).hasSize(9).containsExactlyInAnyOrder(AddPrice.ofVariantId(masterVariantId, de222EurCust1Ofid, true), AddPrice.ofVariantId(masterVariantId, DRAFT_DE_111_EUR_01_02, true), AddPrice.ofVariantId(masterVariantId, DRAFT_DE_111_EUR_03_04, true), AddPrice.ofVariantId(masterVariantId, de333UsdCust1Ofid, true), AddPrice.ofVariantId(masterVariantId, DRAFT_UK_999_GBP, true), AddPrice.ofVariantId(masterVariantId, us666Usd0102Cust2OfId, true), AddPrice.ofVariantId(masterVariantId, DRAFT_FR_888_EUR_01_03, true), AddPrice.ofVariantId(masterVariantId, DRAFT_FR_999_EUR_03_06, true), AddPrice.ofVariantId(masterVariantId, DRAFT_NE_777_EUR_05_07, true));
final ProductProjection productProjection = CTP_TARGET_CLIENT.execute(ProductProjectionByKeyGet.of(newProductDraft.getKey(), ProductProjectionType.STAGED)).toCompletableFuture().join();
assertThat(productProjection).isNotNull();
final List<PriceDraft> newPricesWithReferenceIds = asList(DRAFT_DE_111_EUR, de222EurCust1Ofid, DRAFT_DE_111_EUR_01_02, DRAFT_DE_111_EUR_03_04, withChannel1CustomType1WithEnDeOfId, withChannel2CustomType1WithEnDeOfId, de333UsdCust1Ofid, DRAFT_DE_22_USD, DRAFT_UK_111_GBP_01_02, DRAFT_UK_999_GBP, us666Usd0102Cust2OfId, DRAFT_FR_888_EUR_01_03, DRAFT_FR_999_EUR_03_06, DRAFT_NE_777_EUR_01_04, DRAFT_NE_777_EUR_05_07);
assertPricesAreEqual(productProjection.getMasterVariant().getPrices(), newPricesWithReferenceIds);
}
use of com.neovisionaries.i18n.CountryCode.DE in project commercetools-sync-java by commercetools.
the class ProductSyncWithPricesIT method sync_WithNonEmptySetNewCustomFields_ShouldCorrectlyUpdateCustomFields.
@Test
void sync_WithNonEmptySetNewCustomFields_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 ArrayNode nonEmptyNewSet = JsonNodeFactory.instance.arrayNode();
nonEmptyNewSet.add("bar");
final Map<String, JsonNode> newCustomFieldsJsonMap = createCustomFieldsJsonMap(EMPTY_SET_CUSTOM_FIELD_NAME, nonEmptyNewSet);
newCustomFieldsJsonMap.put(NULL_SET_CUSTOM_FIELD_NAME, nonEmptyNewSet);
newCustomFieldsJsonMap.put(NON_EMPTY_SEY_CUSTOM_FIELD_NAME, nonEmptyNewSet);
newCustomFieldsJsonMap.put(NULL_NODE_SET_CUSTOM_FIELD_NAME, nonEmptyNewSet);
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(4);
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)).containsOnly("bar");
assertThat(price.getCustom().getFieldAsStringSet(NULL_SET_CUSTOM_FIELD_NAME)).containsOnly("bar");
assertThat(price.getCustom().getFieldAsStringSet(NULL_NODE_SET_CUSTOM_FIELD_NAME)).containsOnly("bar");
assertThat(price.getCustom().getFieldAsStringSet(NON_EMPTY_SEY_CUSTOM_FIELD_NAME)).containsOnly("bar");
}
}
Aggregations