use of com.commercetools.sync.services.impl.ShoppingListServiceImpl in project commercetools-sync-java by commercetools.
the class ShoppingListServiceImplIT method setup.
/**
* Deletes shopping list and products from the target CTP projects, then it populates the project
* with test data.
*/
@BeforeEach
void setup() {
deleteShoppingListTestData(CTP_TARGET_CLIENT);
errorCallBackMessages = new ArrayList<>();
errorCallBackExceptions = new ArrayList<>();
shoppingList = createShoppingList(CTP_TARGET_CLIENT, "name", "key");
final ShoppingListSyncOptions options = ShoppingListSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, actions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception);
}).build();
shoppingListService = new ShoppingListServiceImpl(options);
}
use of com.commercetools.sync.services.impl.ShoppingListServiceImpl in project commercetools-sync-java by commercetools.
the class ShoppingListServiceImplIT method createShoppingList_WithValidShoppingList_ShouldCreateShoppingList.
@Test
void createShoppingList_WithValidShoppingList_ShouldCreateShoppingList() {
// preparation
ProductType productType = createProductType(PRODUCT_TYPE_RESOURCE_PATH, CTP_TARGET_CLIENT);
final ProductDraft productDraft = ProductDraftBuilder.of(ResourceIdentifier.ofKey(productType.getKey()), LocalizedString.ofEnglish("newProduct"), LocalizedString.ofEnglish("foo"), ProductVariantDraftBuilder.of().key("foo-new").sku("sku-new").build()).key("newProduct").build();
executeBlocking(CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(productDraft)));
LineItemDraft lineItemDraft = LineItemDraftBuilder.ofSku("sku-new", Long.valueOf(1)).build();
TextLineItemDraft textLineItemDraft = TextLineItemDraftBuilder.of(LocalizedString.ofEnglish("text"), 1L).build();
final ShoppingListDraftDsl newShoppingListDraft = ShoppingListDraftBuilder.of(LocalizedString.ofEnglish("new_name")).key("new_key").plusLineItems(lineItemDraft).plusTextLineItems(textLineItemDraft).build();
final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
final ShoppingListSyncOptions options = ShoppingListSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, actions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception);
}).build();
ShoppingListService spyShoppingListService = new ShoppingListServiceImpl(options);
// test
final Optional<ShoppingList> createdShoppingList = spyShoppingListService.createShoppingList(newShoppingListDraft).toCompletableFuture().join();
final Optional<ShoppingList> queriedOptional = CTP_TARGET_CLIENT.execute(ShoppingListQuery.of().withPredicates(shoppingListQueryModel -> shoppingListQueryModel.key().is("new_key"))).toCompletableFuture().join().head();
assertThat(queriedOptional).hasValueSatisfying(queried -> assertThat(createdShoppingList).hasValueSatisfying(created -> {
assertThat(created.getKey()).isEqualTo(queried.getKey());
assertThat(created.getName()).isEqualTo(queried.getName());
assertThat(created.getLineItems()).hasSize(1);
assertThat(created.getTextLineItems()).hasSize(1);
}));
}
use of com.commercetools.sync.services.impl.ShoppingListServiceImpl in project commercetools-sync-java by commercetools.
the class ShoppingListServiceImplIT method cacheKeysToIds_WithCachedKeys_ShouldReturnCachedKeysWithoutRequest.
@Test
void cacheKeysToIds_WithCachedKeys_ShouldReturnCachedKeysWithoutRequest() {
final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
final ShoppingListSyncOptions shoppingListSyncOptions = ShoppingListSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception.getCause());
}).build();
final ShoppingListService shoppingListService = new ShoppingListServiceImpl(shoppingListSyncOptions);
Map<String, String> cache = shoppingListService.cacheKeysToIds(singleton(shoppingList.getKey())).toCompletableFuture().join();
assertThat(cache).hasSize(1);
cache = shoppingListService.cacheKeysToIds(singleton(shoppingList.getKey())).toCompletableFuture().join();
assertThat(cache).hasSize(1);
verify(spyClient, times(1)).execute(any());
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
}
Aggregations