From 20649ad4e35c7438573226479dcb65e65f1d3599 Mon Sep 17 00:00:00 2001 From: lojzatran Date: Wed, 12 Feb 2025 14:32:38 +0100 Subject: [PATCH 1/6] #1201 add test for syncing 2 products with same slug --- .../products/ProductSyncIT.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/integration-test/java/com/commercetools/sync/integration/externalsource/products/ProductSyncIT.java b/src/integration-test/java/com/commercetools/sync/integration/externalsource/products/ProductSyncIT.java index 8580d3381..2223dbdd6 100644 --- a/src/integration-test/java/com/commercetools/sync/integration/externalsource/products/ProductSyncIT.java +++ b/src/integration-test/java/com/commercetools/sync/integration/externalsource/products/ProductSyncIT.java @@ -78,6 +78,7 @@ import java.util.Locale; import java.util.Optional; import java.util.Set; +import java.util.UUID; import javax.annotation.Nonnull; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -955,6 +956,66 @@ void sync_withANullDraftInBatch_ShouldNotSyncItAndTriggerErrorCallBack() { assertThat(warningCallBackMessages).isEmpty(); } + @Test + void test_Generic_NPE_error_without_details_on_product_import() { + // preparation + final List updateActions = new ArrayList<>(); + final TriConsumer, Optional> + warningCallBack = + (exception, newResource, oldResource) -> + warningCallBackMessages.add(exception.getMessage()); + + final ProductSyncOptions customOptions = + ProductSyncOptionsBuilder.of(TestClientUtils.CTP_TARGET_CLIENT) + .errorCallback( + (exception, oldResource, newResource, actions) -> + collectErrors(exception.getMessage(), exception.getCause())) + .warningCallback(warningCallBack) + .beforeUpdateCallback( + (actions, draft, old) -> { + updateActions.addAll(actions); + return actions; + }) + .build(); + + final ProductDraft productDraft = + createProductDraftBuilder( + PRODUCT_KEY_1_RESOURCE_PATH, + ProductTypeResourceIdentifierBuilder.of().key(productType.getKey()).build()) + .slug(LocalizedString.of(Locale.ENGLISH, "slug")) + .categories(emptyList()) + .taxCategory((TaxCategoryResourceIdentifier) null) + .state((StateResourceIdentifier) null) + .build(); + + final ProductDraft productDraft2 = + createProductDraftBuilder( + PRODUCT_KEY_1_RESOURCE_PATH, + ProductTypeResourceIdentifierBuilder.of().key(productType.getKey()).build()) + .key(UUID.randomUUID().toString()) + .slug(LocalizedString.of(Locale.ENGLISH, "slug")) + .categories(emptyList()) + .taxCategory((TaxCategoryResourceIdentifier) null) + .state((StateResourceIdentifier) null) + .build(); + + // test + final ProductSync productSync = new ProductSync(customOptions); + productSync + .sync(singletonList(productDraft)) + .toCompletableFuture() + .join(); + final ProductSyncStatistics syncStatistics = + productSync + .sync(singletonList(productDraft2)) + .toCompletableFuture() + .join(); + + assertThat(syncStatistics).hasValues(2, 0, 1, 1, 0); + assertThat(this.errorCallBackExceptions.get(0).getCause().getMessage()).contains("A duplicate value '\\\"slug\\\"' exists for field"); + assertThat(this.errorCallBackMessages.get(0)).contains("A duplicate value '\\\"slug\\\"' exists for field"); + } + @Test void sync_withProductContainingAttributeChanges_shouldSyncProductCorrectly() { // preparation From eb49e9fc03278c1c7817d3376c4b6265e0bb7391 Mon Sep 17 00:00:00 2001 From: lojzatran Date: Wed, 12 Feb 2025 17:48:46 +0100 Subject: [PATCH 2/6] #1201 reformat code --- .../products/ProductSyncIT.java | 76 +++++++++---------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/src/integration-test/java/com/commercetools/sync/integration/externalsource/products/ProductSyncIT.java b/src/integration-test/java/com/commercetools/sync/integration/externalsource/products/ProductSyncIT.java index 2223dbdd6..ed8c33868 100644 --- a/src/integration-test/java/com/commercetools/sync/integration/externalsource/products/ProductSyncIT.java +++ b/src/integration-test/java/com/commercetools/sync/integration/externalsource/products/ProductSyncIT.java @@ -961,59 +961,55 @@ void test_Generic_NPE_error_without_details_on_product_import() { // preparation final List updateActions = new ArrayList<>(); final TriConsumer, Optional> - warningCallBack = + warningCallBack = (exception, newResource, oldResource) -> - warningCallBackMessages.add(exception.getMessage()); + warningCallBackMessages.add(exception.getMessage()); final ProductSyncOptions customOptions = - ProductSyncOptionsBuilder.of(TestClientUtils.CTP_TARGET_CLIENT) - .errorCallback( - (exception, oldResource, newResource, actions) -> - collectErrors(exception.getMessage(), exception.getCause())) - .warningCallback(warningCallBack) - .beforeUpdateCallback( - (actions, draft, old) -> { - updateActions.addAll(actions); - return actions; - }) - .build(); + ProductSyncOptionsBuilder.of(TestClientUtils.CTP_TARGET_CLIENT) + .errorCallback( + (exception, oldResource, newResource, actions) -> + collectErrors(exception.getMessage(), exception.getCause())) + .warningCallback(warningCallBack) + .beforeUpdateCallback( + (actions, draft, old) -> { + updateActions.addAll(actions); + return actions; + }) + .build(); final ProductDraft productDraft = - createProductDraftBuilder( - PRODUCT_KEY_1_RESOURCE_PATH, - ProductTypeResourceIdentifierBuilder.of().key(productType.getKey()).build()) - .slug(LocalizedString.of(Locale.ENGLISH, "slug")) - .categories(emptyList()) - .taxCategory((TaxCategoryResourceIdentifier) null) - .state((StateResourceIdentifier) null) - .build(); + createProductDraftBuilder( + PRODUCT_KEY_1_RESOURCE_PATH, + ProductTypeResourceIdentifierBuilder.of().key(productType.getKey()).build()) + .slug(LocalizedString.of(Locale.ENGLISH, "slug")) + .categories(emptyList()) + .taxCategory((TaxCategoryResourceIdentifier) null) + .state((StateResourceIdentifier) null) + .build(); final ProductDraft productDraft2 = - createProductDraftBuilder( - PRODUCT_KEY_1_RESOURCE_PATH, - ProductTypeResourceIdentifierBuilder.of().key(productType.getKey()).build()) - .key(UUID.randomUUID().toString()) - .slug(LocalizedString.of(Locale.ENGLISH, "slug")) - .categories(emptyList()) - .taxCategory((TaxCategoryResourceIdentifier) null) - .state((StateResourceIdentifier) null) - .build(); + createProductDraftBuilder( + PRODUCT_KEY_1_RESOURCE_PATH, + ProductTypeResourceIdentifierBuilder.of().key(productType.getKey()).build()) + .key(UUID.randomUUID().toString()) + .slug(LocalizedString.of(Locale.ENGLISH, "slug")) + .categories(emptyList()) + .taxCategory((TaxCategoryResourceIdentifier) null) + .state((StateResourceIdentifier) null) + .build(); // test final ProductSync productSync = new ProductSync(customOptions); - productSync - .sync(singletonList(productDraft)) - .toCompletableFuture() - .join(); + productSync.sync(singletonList(productDraft)).toCompletableFuture().join(); final ProductSyncStatistics syncStatistics = - productSync - .sync(singletonList(productDraft2)) - .toCompletableFuture() - .join(); + productSync.sync(singletonList(productDraft2)).toCompletableFuture().join(); assertThat(syncStatistics).hasValues(2, 0, 1, 1, 0); - assertThat(this.errorCallBackExceptions.get(0).getCause().getMessage()).contains("A duplicate value '\\\"slug\\\"' exists for field"); - assertThat(this.errorCallBackMessages.get(0)).contains("A duplicate value '\\\"slug\\\"' exists for field"); + assertThat(this.errorCallBackExceptions.get(0).getCause().getMessage()) + .contains("A duplicate value '\\\"slug\\\"' exists for field"); + assertThat(this.errorCallBackMessages.get(0)) + .contains("A duplicate value '\\\"slug\\\"' exists for field"); } @Test From 3beddbf482b3c53a64099e6095fd3bb9d4087e30 Mon Sep 17 00:00:00 2001 From: lojzatran Date: Wed, 12 Feb 2025 22:19:46 +0100 Subject: [PATCH 3/6] #1201 update mkdocs plugin --- build.gradle | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 1841ed475..7fbb62cbc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,7 @@ plugins { - id 'org.ajoberstar.git-publish' version '4.2.2' id 'com.adarshr.test-logger' version '4.0.0' - id 'org.ajoberstar.grgit' version '5.2.2' id "com.github.ben-manes.versions" version '0.51.0' - id 'ru.vyarus.mkdocs' version '3.0.0' + id 'ru.vyarus.mkdocs' version '4.0.1' id "com.github.spotbugs" version "6.0.9" id 'com.diffplug.spotless' version '6.25.0' id 'io.github.gradle-nexus.publish-plugin' version '2.0.0' From 3ce774aaab73dddf7199d606b858d544c1fa9661 Mon Sep 17 00:00:00 2001 From: lojzatran Date: Wed, 12 Feb 2025 22:29:26 +0100 Subject: [PATCH 4/6] #1201 update mkdocs plugin --- gradle-scripts/mkdocs.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle-scripts/mkdocs.gradle b/gradle-scripts/mkdocs.gradle index fad615241..b01085e85 100644 --- a/gradle-scripts/mkdocs.gradle +++ b/gradle-scripts/mkdocs.gradle @@ -1,6 +1,6 @@ mkdocs { // mkdocs sources - sourcesDir = '.' // default is 'docs' in the root directory. + sourcesDir = 'src/docs' // default is 'doc' in the root directory. // strict build (fail on build errors) strict = true // target build directory (publication root) From 03cbf49363742392f3a7255950ba517c4fb649da Mon Sep 17 00:00:00 2001 From: lojzatran Date: Wed, 12 Feb 2025 22:34:48 +0100 Subject: [PATCH 5/6] #1201 update mkdocs plugin --- gradle-scripts/mkdocs.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle-scripts/mkdocs.gradle b/gradle-scripts/mkdocs.gradle index b01085e85..97edc04b6 100644 --- a/gradle-scripts/mkdocs.gradle +++ b/gradle-scripts/mkdocs.gradle @@ -1,6 +1,6 @@ mkdocs { // mkdocs sources - sourcesDir = 'src/docs' // default is 'doc' in the root directory. + sourcesDir = 'docs' // default is 'doc' in the root directory. // strict build (fail on build errors) strict = true // target build directory (publication root) From dab4a2d77499243eb32c0acae10fdc500897d36c Mon Sep 17 00:00:00 2001 From: lojzatran Date: Thu, 13 Feb 2025 12:12:06 +0100 Subject: [PATCH 6/6] Update mkdocs plugin ordering --- build.gradle | 6 +++--- gradle-scripts/mkdocs.gradle | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 7fbb62cbc..3182e5d3f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ plugins { id 'com.adarshr.test-logger' version '4.0.0' id "com.github.ben-manes.versions" version '0.51.0' - id 'ru.vyarus.mkdocs' version '4.0.1' + id 'ru.vyarus.mkdocs' version '4.0.1' apply false id "com.github.spotbugs" version "6.0.9" id 'com.diffplug.spotless' version '6.25.0' id 'io.github.gradle-nexus.publish-plugin' version '2.0.0' @@ -34,11 +34,11 @@ apply from: "$rootDir/gradle-scripts/jacoco.gradle" apply from: "$rootDir/gradle-scripts/spotbugs.gradle" apply from: "$rootDir/gradle-scripts/maven-publish.gradle" apply from: "$rootDir/gradle-scripts/nexus-publish.gradle" -apply from: "$rootDir/gradle-scripts/javadocs-publish.gradle" apply from: "$rootDir/gradle-scripts/set-library-version.gradle" -apply from: "$rootDir/gradle-scripts/execution-order.gradle" apply from: "$rootDir/gradle-scripts/mkdocs.gradle" +apply from: "$rootDir/gradle-scripts/javadocs-publish.gradle" apply from: "$rootDir/gradle-scripts/spotless.gradle" +apply from: "$rootDir/gradle-scripts/execution-order.gradle" dependencies { implementation "com.commercetools.sdk:commercetools-http-client:${commercetoolsJavaSdkV2Version}" diff --git a/gradle-scripts/mkdocs.gradle b/gradle-scripts/mkdocs.gradle index 97edc04b6..d25e5e3b1 100644 --- a/gradle-scripts/mkdocs.gradle +++ b/gradle-scripts/mkdocs.gradle @@ -1,6 +1,8 @@ +apply plugin: 'ru.vyarus.mkdocs' + mkdocs { // mkdocs sources - sourcesDir = 'docs' // default is 'doc' in the root directory. + sourcesDir = "." // default is 'doc' in the root directory. // strict build (fail on build errors) strict = true // target build directory (publication root)