use of com.commercetools.sync.commons.models.WaitingToBeResolvedProducts in project commercetools-sync-java by commercetools.
the class UnresolvedReferencesServiceImplTest method delete_OnSuccess_ShouldRemoveTheResourceObject.
@SuppressWarnings("unchecked")
@Test
void delete_OnSuccess_ShouldRemoveTheResourceObject() {
// 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));
// test
final Optional<WaitingToBeResolvedProducts> toBeResolvedOptional = service.delete("product-draft-key", CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class).toCompletableFuture().join();
// assertions
assertThat(toBeResolvedOptional).contains(waitingDraft);
}
use of com.commercetools.sync.commons.models.WaitingToBeResolvedProducts in project commercetools-sync-java by commercetools.
the class UnresolvedReferencesServiceImplTest method fetch_OnSuccess_ShouldRequestHashedKeys.
@SuppressWarnings("unchecked")
@Test
void fetch_OnSuccess_ShouldRequestHashedKeys() {
// 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);
final PagedQueryResult result = getMockPagedQueryResult(singletonList(customObjectMock));
when(productSyncOptions.getCtpClient().execute(any(CustomObjectQuery.class))).thenReturn(completedFuture(result));
final ArgumentCaptor<CustomObjectQuery<WaitingToBeResolved>> requestArgumentCaptor = ArgumentCaptor.forClass(CustomObjectQuery.class);
// test
final Set<String> setOfSpecialCharKeys = asSet("Get a $100 Visa® Reward Card because you’re ordering TV", "product$", "Visa®", "Visa©");
final Set<WaitingToBeResolvedProducts> toBeResolvedOptional = service.fetch(setOfSpecialCharKeys, CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class).toCompletableFuture().join();
// assertions
verify(productSyncOptions.getCtpClient()).execute(requestArgumentCaptor.capture());
assertThat(toBeResolvedOptional).containsOnly(waitingToBeResolved);
setOfSpecialCharKeys.forEach(key -> assertThat(requestArgumentCaptor.getValue().httpRequestIntent().getPath()).contains(sha1Hex(key)));
}
use of com.commercetools.sync.commons.models.WaitingToBeResolvedProducts in project commercetools-sync-java by commercetools.
the class UnresolvedReferencesServiceImplTest method save_WithUnsuccessfulMockCtpResponse_ShouldNotSaveMock.
@Test
void save_WithUnsuccessfulMockCtpResponse_ShouldNotSaveMock() {
// preparation
final String productKey = "product-draft-key";
final ProductDraft productDraftMock = mock(ProductDraft.class);
when(productDraftMock.getKey()).thenReturn(productKey);
final WaitingToBeResolvedProducts waitingToBeResolved = new WaitingToBeResolvedProducts(productDraftMock, singleton("test-ref"));
when(productSyncOptions.getCtpClient().execute(any())).thenReturn(CompletableFutureUtils.failed(new BadRequestException("bad request")));
// test
final Optional<WaitingToBeResolvedProducts> result = service.save(waitingToBeResolved, CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class).toCompletableFuture().join();
// assertions
assertThat(result).isEmpty();
assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).contains(format("Failed to save CustomObject with key: '%s' (hash of product key: '%s').", sha1Hex(productKey), productKey));
assertThat(errorExceptions).hasSize(1).singleElement(as(THROWABLE)).isExactlyInstanceOf(SyncException.class).hasCauseExactlyInstanceOf(BadRequestException.class);
}
use of com.commercetools.sync.commons.models.WaitingToBeResolvedProducts in project commercetools-sync-java by commercetools.
the class UnresolvedReferencesServiceImplTest method delete_WithUnsuccessfulMockCtpResponse_ShouldReturnProperException.
@Test
void delete_WithUnsuccessfulMockCtpResponse_ShouldReturnProperException() {
// preparation
final ProductDraft productDraftMock = mock(ProductDraft.class);
final String key = "product-draft-key";
when(productDraftMock.getKey()).thenReturn(key);
when(productSyncOptions.getCtpClient().execute(any())).thenReturn(CompletableFutureUtils.failed(new BadRequestException("bad request")));
// test
final Optional<WaitingToBeResolvedProducts> toBeResolvedOptional = service.delete("product-draft-key", CUSTOM_OBJECT_PRODUCT_CONTAINER_KEY, WaitingToBeResolvedProducts.class).toCompletableFuture().join();
// assertions
assertThat(toBeResolvedOptional).isEmpty();
assertThat(errorMessages).hasSize(1);
assertThat(errorExceptions).hasSize(1);
assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).contains(format("Failed to delete CustomObject with key: '%s' (hash of product key: '%s')", sha1Hex(key), key));
assertThat(errorExceptions).hasSize(1).singleElement(as(THROWABLE)).isExactlyInstanceOf(SyncException.class).hasCauseExactlyInstanceOf(BadRequestException.class);
}
Aggregations