use of com.commercetools.sync.commons.models.WaitingToBeResolvedProducts in project commercetools-sync-java by commercetools.
the class UnresolvedReferencesServiceImplIT method saveFetchAndDelete_WithKeyWithSpecialCharacter_shouldWorkCorrectly.
@Test
void saveFetchAndDelete_WithKeyWithSpecialCharacter_shouldWorkCorrectly() {
// preparation
final ProductDraft productDraft = SphereJsonUtils.readObjectFromResource(PRODUCT_KEY_SPECIAL_CHARS_RESOURCE_PATH, ProductDraft.class);
final WaitingToBeResolvedProducts productDraftWithUnresolvedRefs = new WaitingToBeResolvedProducts(productDraft, asSet("foo", "bar"));
// test
final Optional<WaitingToBeResolvedProducts> result = unresolvedReferencesService.save(productDraftWithUnresolvedRefs, CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class).toCompletableFuture().join();
// assertions
assertThat(result).hasValueSatisfying(waitingToBeResolved -> assertThat(waitingToBeResolved.getProductDraft()).isEqualTo(productDraft));
// test
final CustomObjectByKeyGet<WaitingToBeResolvedProducts> customObjectByKeyGet = CustomObjectByKeyGet.of(CUSTOM_OBJECT_CONTAINER_KEY, sha1Hex(productDraft.getKey()), WaitingToBeResolvedProducts.class);
final CustomObject<WaitingToBeResolvedProducts> createdCustomObject = CTP_TARGET_CLIENT.execute(customObjectByKeyGet).toCompletableFuture().join();
// assertions
assertThat(createdCustomObject.getKey()).isEqualTo(sha1Hex(productDraft.getKey()));
// test
final Set<WaitingToBeResolvedProducts> waitingDrafts = unresolvedReferencesService.fetch(singleton(productDraft.getKey()), CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class).toCompletableFuture().join();
// assertions
assertThat(waitingDrafts).containsExactly(productDraftWithUnresolvedRefs);
// test
final Optional<WaitingToBeResolvedProducts> deletionResult = unresolvedReferencesService.delete(productDraft.getKey(), CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class).toCompletableFuture().join();
// assertions
assertThat(deletionResult).hasValueSatisfying(waitingToBeResolved -> assertThat(waitingToBeResolved.getProductDraft()).isEqualTo(productDraft));
assertThat(errorCallBackMessages).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
assertThat(errorCallBackExceptions).isEmpty();
}
use of com.commercetools.sync.commons.models.WaitingToBeResolvedProducts in project commercetools-sync-java by commercetools.
the class UnresolvedReferencesServiceImplTest method delete_OnSuccess_ShouldMakeRequestWithSha1HashedKey.
@SuppressWarnings("unchecked")
@Test
void delete_OnSuccess_ShouldMakeRequestWithSha1HashedKey() {
// preparation
final CustomObject customObjectMock = mock(CustomObject.class);
final ProductDraft productDraftMock = mock(ProductDraft.class);
when(productDraftMock.getKey()).thenReturn("product-draft-key");
final WaitingToBeResolvedProducts waitingDraft = new WaitingToBeResolvedProducts(productDraftMock, singleton("test-ref"));
when(customObjectMock.getValue()).thenReturn(waitingDraft);
when(productSyncOptions.getCtpClient().execute(any(CustomObjectDeleteCommand.class))).thenReturn(completedFuture(customObjectMock));
final ArgumentCaptor<CustomObjectDeleteCommand<WaitingToBeResolved>> requestArgumentCaptor = ArgumentCaptor.forClass(CustomObjectDeleteCommand.class);
// test
final Optional<WaitingToBeResolvedProducts> toBeResolvedOptional = service.delete("product-draft-key", CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class).toCompletableFuture().join();
// assertions
verify(productSyncOptions.getCtpClient()).execute(requestArgumentCaptor.capture());
assertThat(toBeResolvedOptional).contains(waitingDraft);
final CustomObjectDeleteCommand<WaitingToBeResolved> value = requestArgumentCaptor.getValue();
assertThat(value.httpRequestIntent().getPath()).contains(sha1Hex(productDraftMock.getKey()));
}
use of com.commercetools.sync.commons.models.WaitingToBeResolvedProducts in project commercetools-sync-java by commercetools.
the class UnresolvedReferencesServiceImplTest method save_OnSuccess_ShouldSaveMock.
@Test
void save_OnSuccess_ShouldSaveMock() {
// preparation
final CustomObject customObjectMock = mock(CustomObject.class);
final ProductDraft productDraftMock = mock(ProductDraft.class);
when(productDraftMock.getKey()).thenReturn("product-draft-key");
final WaitingToBeResolvedProducts waitingToBeResolved = new WaitingToBeResolvedProducts(productDraftMock, singleton("test-ref"));
when(customObjectMock.getValue()).thenReturn(waitingToBeResolved);
when(productSyncOptions.getCtpClient().execute(any())).thenReturn(completedFuture(customObjectMock));
// test
final Optional<WaitingToBeResolvedProducts> result = service.save(waitingToBeResolved, CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class).toCompletableFuture().join();
// assertions
assertThat(result).contains(waitingToBeResolved);
}
use of com.commercetools.sync.commons.models.WaitingToBeResolvedProducts in project commercetools-sync-java by commercetools.
the class UnresolvedReferencesServiceImplTest method save_OnSuccess_ShouldSaveMockWithSha1HashedKey.
@SuppressWarnings("unchecked")
@Test
void save_OnSuccess_ShouldSaveMockWithSha1HashedKey() {
// preparation
final CustomObject customObjectMock = mock(CustomObject.class);
final ProductDraft productDraftMock = mock(ProductDraft.class);
when(productDraftMock.getKey()).thenReturn("product-draft-key");
final WaitingToBeResolvedProducts waitingToBeResolved = new WaitingToBeResolvedProducts(productDraftMock, singleton("test-ref"));
when(customObjectMock.getValue()).thenReturn(waitingToBeResolved);
when(productSyncOptions.getCtpClient().execute(any())).thenReturn(completedFuture(customObjectMock));
final ArgumentCaptor<CustomObjectUpsertCommand<WaitingToBeResolved>> requestArgumentCaptor = ArgumentCaptor.forClass(CustomObjectUpsertCommand.class);
// test
final Optional<WaitingToBeResolvedProducts> result = service.save(waitingToBeResolved, CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class).toCompletableFuture().join();
// assertions
verify(productSyncOptions.getCtpClient()).execute(requestArgumentCaptor.capture());
assertThat(result).contains(waitingToBeResolved);
assertThat(requestArgumentCaptor.getValue().getDraft().getKey()).isEqualTo(sha1Hex(productDraftMock.getKey()));
}
use of com.commercetools.sync.commons.models.WaitingToBeResolvedProducts in project commercetools-sync-java by commercetools.
the class ProductSyncWithReferencedProductsIT method sync_withProductReferenceSetContainingANonExistingReference_shouldFailCreatingTheProduct.
@Test
void sync_withProductReferenceSetContainingANonExistingReference_shouldFailCreatingTheProduct() {
// preparation
final AttributeDraft productReferenceAttribute = AttributeDraft.of("product-reference", Reference.of(Product.referenceTypeId(), product.getKey()));
final HashSet<Reference<Product>> references = new HashSet<>();
references.add(Reference.of(Product.referenceTypeId(), "nonExistingKey"));
references.add(Reference.of(Product.referenceTypeId(), product2.getKey()));
final AttributeDraft productReferenceSetAttribute = AttributeDraft.of("product-reference-set", references);
final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of().sku("sku").key("new-product-master-variant").attributes(productReferenceAttribute, productReferenceSetAttribute).build();
final ProductDraft productDraftWithProductReference = ProductDraftBuilder.of(productType, ofEnglish("productName"), ofEnglish("productSlug"), masterVariant).key("new-product").build();
// test
final ProductSync productSync = new ProductSync(syncOptions);
final ProductSyncStatistics syncStatistics = productSync.sync(singletonList(productDraftWithProductReference)).toCompletableFuture().join();
// assertion
assertThat(syncStatistics).hasValues(1, 0, 0, 0, 1);
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
assertThat(actions).isEmpty();
final UnresolvedReferencesServiceImpl<WaitingToBeResolvedProducts> unresolvedReferencesService = new UnresolvedReferencesServiceImpl<>(syncOptions);
final Set<WaitingToBeResolvedProducts> waitingToBeResolvedDrafts = unresolvedReferencesService.fetch(asSet(productDraftWithProductReference.getKey()), CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class).toCompletableFuture().join();
assertThat(waitingToBeResolvedDrafts).singleElement().matches(waitingToBeResolvedDraft -> {
assertThat(waitingToBeResolvedDraft.getProductDraft().getKey()).isEqualTo(productDraftWithProductReference.getKey());
assertThat(waitingToBeResolvedDraft.getMissingReferencedProductKeys()).containsExactly("nonExistingKey");
return true;
});
}
Aggregations