|
78 | 78 | import java.util.Locale; |
79 | 79 | import java.util.Optional; |
80 | 80 | import java.util.Set; |
| 81 | +import java.util.UUID; |
81 | 82 | import javax.annotation.Nonnull; |
82 | 83 | import org.junit.jupiter.api.AfterAll; |
83 | 84 | import org.junit.jupiter.api.BeforeAll; |
@@ -955,6 +956,66 @@ void sync_withANullDraftInBatch_ShouldNotSyncItAndTriggerErrorCallBack() { |
955 | 956 | assertThat(warningCallBackMessages).isEmpty(); |
956 | 957 | } |
957 | 958 |
|
| 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 | + |
958 | 1019 | @Test |
959 | 1020 | void sync_withProductContainingAttributeChanges_shouldSyncProductCorrectly() { |
960 | 1021 | // preparation |
|
0 commit comments