Skip to content

#1201 add test for syncing 2 products with same slug #1202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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' 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'
Expand Down Expand Up @@ -36,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}"
Expand Down
4 changes: 3 additions & 1 deletion gradle-scripts/mkdocs.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
apply plugin: 'ru.vyarus.mkdocs'

mkdocs {
// mkdocs sources
sourcesDir = '.' // default is 'docs' 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -955,6 +956,62 @@ void sync_withANullDraftInBatch_ShouldNotSyncItAndTriggerErrorCallBack() {
assertThat(warningCallBackMessages).isEmpty();
}

@Test
void test_Generic_NPE_error_without_details_on_product_import() {
// preparation
final List<ProductUpdateAction> updateActions = new ArrayList<>();
final TriConsumer<SyncException, Optional<ProductDraft>, Optional<ProductProjection>>
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
Expand Down
Loading