Skip to content

Commit 20649ad

Browse files
committed
#1201 add test for syncing 2 products with same slug
1 parent 14e6380 commit 20649ad

File tree

1 file changed

+61
-0
lines changed
  • src/integration-test/java/com/commercetools/sync/integration/externalsource/products

1 file changed

+61
-0
lines changed

src/integration-test/java/com/commercetools/sync/integration/externalsource/products/ProductSyncIT.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import java.util.Locale;
7979
import java.util.Optional;
8080
import java.util.Set;
81+
import java.util.UUID;
8182
import javax.annotation.Nonnull;
8283
import org.junit.jupiter.api.AfterAll;
8384
import org.junit.jupiter.api.BeforeAll;
@@ -955,6 +956,66 @@ void sync_withANullDraftInBatch_ShouldNotSyncItAndTriggerErrorCallBack() {
955956
assertThat(warningCallBackMessages).isEmpty();
956957
}
957958

959+
@Test
960+
void test_Generic_NPE_error_without_details_on_product_import() {
961+
// preparation
962+
final List<ProductUpdateAction> updateActions = new ArrayList<>();
963+
final TriConsumer<SyncException, Optional<ProductDraft>, Optional<ProductProjection>>
964+
warningCallBack =
965+
(exception, newResource, oldResource) ->
966+
warningCallBackMessages.add(exception.getMessage());
967+
968+
final ProductSyncOptions customOptions =
969+
ProductSyncOptionsBuilder.of(TestClientUtils.CTP_TARGET_CLIENT)
970+
.errorCallback(
971+
(exception, oldResource, newResource, actions) ->
972+
collectErrors(exception.getMessage(), exception.getCause()))
973+
.warningCallback(warningCallBack)
974+
.beforeUpdateCallback(
975+
(actions, draft, old) -> {
976+
updateActions.addAll(actions);
977+
return actions;
978+
})
979+
.build();
980+
981+
final ProductDraft productDraft =
982+
createProductDraftBuilder(
983+
PRODUCT_KEY_1_RESOURCE_PATH,
984+
ProductTypeResourceIdentifierBuilder.of().key(productType.getKey()).build())
985+
.slug(LocalizedString.of(Locale.ENGLISH, "slug"))
986+
.categories(emptyList())
987+
.taxCategory((TaxCategoryResourceIdentifier) null)
988+
.state((StateResourceIdentifier) null)
989+
.build();
990+
991+
final ProductDraft productDraft2 =
992+
createProductDraftBuilder(
993+
PRODUCT_KEY_1_RESOURCE_PATH,
994+
ProductTypeResourceIdentifierBuilder.of().key(productType.getKey()).build())
995+
.key(UUID.randomUUID().toString())
996+
.slug(LocalizedString.of(Locale.ENGLISH, "slug"))
997+
.categories(emptyList())
998+
.taxCategory((TaxCategoryResourceIdentifier) null)
999+
.state((StateResourceIdentifier) null)
1000+
.build();
1001+
1002+
// test
1003+
final ProductSync productSync = new ProductSync(customOptions);
1004+
productSync
1005+
.sync(singletonList(productDraft))
1006+
.toCompletableFuture()
1007+
.join();
1008+
final ProductSyncStatistics syncStatistics =
1009+
productSync
1010+
.sync(singletonList(productDraft2))
1011+
.toCompletableFuture()
1012+
.join();
1013+
1014+
assertThat(syncStatistics).hasValues(2, 0, 1, 1, 0);
1015+
assertThat(this.errorCallBackExceptions.get(0).getCause().getMessage()).contains("A duplicate value '\\\"slug\\\"' exists for field");
1016+
assertThat(this.errorCallBackMessages.get(0)).contains("A duplicate value '\\\"slug\\\"' exists for field");
1017+
}
1018+
9581019
@Test
9591020
void sync_withProductContainingAttributeChanges_shouldSyncProductCorrectly() {
9601021
// preparation

0 commit comments

Comments
 (0)