default CategoryQuery byIsRoot() { return withPredicates(m -> m.parent().isNotPresent()); }
@Test public void cart() throws Exception { assertOrderIsFoundWithPredicate(order -> MODEL.cart().is(order.getCart())); }
withUpdateableInventoryEntry(client(), draft, entry -> { final QueryPredicate<InventoryEntry> skuP = InventoryEntryQueryModel.of().sku().is(sku); final QueryPredicate<InventoryEntry> channelP = InventoryEntryQueryModel.of().supplyChannel().is(channel); final QueryPredicate<InventoryEntry> channelPById = InventoryEntryQueryModel.of().supplyChannel().id().is(channel.getId()); final QueryPredicate<InventoryEntry> stockP = InventoryEntryQueryModel.of().quantityOnStock().is(quantityOnStock); final QueryPredicate<InventoryEntry> availableP = InventoryEntryQueryModel.of().availableQuantity().is(quantityOnStock);
public static List<Review> query(final BlockingSphereClient client, final State initialState) { //this ID can be cached final String initialStateId = client.executeBlocking(StateQuery.of().byKey("to-approve")).head().get().getId(); final ReviewQuery reviewQuery = ReviewQuery.of() .withPredicates(m -> m.state().id().is(initialStateId)) .withSort(m -> m.createdAt().sort().asc());//oldest first final List<Review> reviewsToApprove = client.executeBlocking(reviewQuery).getResults(); assertThat(reviewsToApprove).extracting(review -> review.getTitle()).contains("review title"); return reviewsToApprove; } }
default CategoryQuery byIsRoot() { return withPredicates(m -> m.parent().isNotPresent()); }
@Test public void customerGroup() throws Exception { check((model) -> model.customerGroup().is(customer.getCustomerGroup()), false); }
@Test public void fetchRoots_withMapper() throws Exception { final CategoryQuery seedQuery = CategoryQuery.of().withPredicates(m -> m.parent().isNotPresent()); final CompletionStage<List<Category>> rootCategoryStage = QueryExecutionUtils .queryAll(client(), seedQuery, category -> category); final List<Category> rootCategories = SphereClientUtils .blockingWait(rootCategoryStage, Duration.ofMinutes(1)); assertThat(rootCategories.stream().allMatch(cat -> cat.getParent() == null)) .overridingErrorMessage("fetched only root categories") .isTrue(); }
@Test public void fetchRoots() throws Exception { final CategoryQuery seedQuery = CategoryQuery.of().withPredicates(m -> m.parent().isNotPresent()); final CompletionStage<List<Category>> categoriesStage = QueryExecutionUtils.queryAll(client(), seedQuery); final List<Category> rootCategories = SphereClientUtils.blockingWait(categoriesStage, Duration.ofMinutes(1)); assertThat(rootCategories.stream().allMatch(cat -> cat.getParent() == null)) .overridingErrorMessage("fetched only root categories") .isTrue(); }
@Test public void transitionState() throws Exception { withStateByBuilder(client(), builder -> builder.type(StateType.ORDER_STATE), state -> { withOrder(client(), order -> { final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, TransitionState.of(state))); assertThat(updatedOrder.getState()).isEqualTo(state.toReference()); assertEventually(() -> { final PagedQueryResult<OrderStateTransitionMessage> messageQueryResult = client().executeBlocking(MessageQuery.of() .withPredicates(m -> m.resource().is(order)) .forMessageType(OrderStateTransitionMessage.MESSAGE_HINT)); final Optional<OrderStateTransitionMessage> message = messageQueryResult.head(); assertThat(message).isPresent(); assertThat(message.get().getState()).isEqualTo(state.toReference()); //check query model final OrderQuery orderQuery = OrderQuery.of() .withPredicates(m -> m.id().is(order.getId()).and(m.state().is(state))); final Order orderByState = client().executeBlocking(orderQuery) .head().get(); assertThat(orderByState).isEqualTo(updatedOrder); }); return updatedOrder; }); }); }
@Test public void transitionState() { withStateByBuilder(client(), builder -> builder.type(PRODUCT_STATE), state -> { withUpdateableProduct(client(), product -> { assertThat(product.getState()).isNull(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, asList(TransitionState.of(state)))); assertThat(updatedProduct.getState()).isEqualTo(state.toReference()); assertEventually(() -> { final PagedQueryResult<ProductStateTransitionMessage> messageQueryResult = client().executeBlocking(MessageQuery.of() .withPredicates(m -> m.resource().is(product)) .forMessageType(ProductStateTransitionMessage.MESSAGE_HINT)); assertThat(messageQueryResult.getResults()).isNotEmpty(); final ProductStateTransitionMessage message = messageQueryResult.head().get(); assertThat(message.getState()).isEqualTo(state.toReference()); }); //check query model final ProductQuery query = ProductQuery.of() .withPredicates(m -> m.id().is(product.getId()).and(m.state().is(state))); final Product productByState = client().executeBlocking(query) .head().get(); assertThat(productByState).isEqualTo(updatedProduct); return updatedProduct; }); }); }
@Test public void customerGroupIsExpandeable() throws Exception { CustomerFixtures.withCustomerInGroup(client(), (customer, customerGroup) -> { withOrder(client(), customer, order -> { final OrderQuery orderQuery = OrderQuery.of() .withPredicates(m -> m.id().is(order.getId()).and(m.customerGroup().is(customerGroup))) .withExpansionPaths(m -> m.customerGroup()); final Order queriedOrder = client().executeBlocking(orderQuery).head().get(); assertThat(queriedOrder.getCustomerGroup().getObj().getName()) .overridingErrorMessage("customerGroupIsExpandeable") .isEqualTo(customerGroup.getName()); return order; }); }); }
@BeforeClass public static void clean() { client().executeBlocking(StateQuery.of() .withPredicates(m -> m.key().isIn(asList("approved", "to-approve"))) .withSort(m -> m.key().sort().desc())) .getResults() .forEach(state -> { final ReviewQuery reviewQuery = ReviewQuery.of() .withPredicates(m -> m.state().is(state)) .withLimit(500); client().executeBlocking(reviewQuery) .getResults() .forEach(review -> client().executeBlocking(ReviewDeleteCommand.of(review))); client().executeBlocking(StateDeleteCommand.of(state)); }); }
.and(m.customer().is(customer)) .and(m.externalId().is(externalId)) .and(m.interfaceId().is(interfaceId)) .and(m.paymentStatus().interfaceCode().is(paymentStatus.getInterfaceCode())) .and(m.paymentStatus().interfaceText().is(paymentStatus.getInterfaceText())) .and(m.paymentStatus().state().is(paidState)) .and(m.transactions().type().is(transactionType)) .and(m.transactions().id().is(payment.getTransactions().get(0).getId()))
@Test public void shippingMethodQuery() throws Exception { withShippingMethodForGermany(client(), shippingMethod -> { withCart(client(), createCartWithShippingAddress(client()), cart -> { final CartUpdateCommand updateCommand = CartUpdateCommand.of(cart, SetShippingMethod.of(shippingMethod)) .plusExpansionPaths(m -> m.shippingInfo().shippingMethod().taxCategory()) .plusExpansionPaths(m -> m.shippingInfo().taxCategory()); final Cart cartWithShippingMethod = client().executeBlocking(updateCommand); final CartShippingInfo shippingInfo = cartWithShippingMethod.getShippingInfo(); final CartQuery query = CartQuery.of() .plusPredicates(m -> m.id().is(cart.getId())) .plusPredicates(m -> m.shippingInfo().shippingMethodName().is(shippingMethod.getName())) .plusPredicates(m -> m.shippingInfo().price().centAmount().is(MoneyImpl.centAmountOf(shippingInfo.getPrice()))) .plusPredicates(m -> m.shippingInfo().taxRate().name().is(shippingInfo.getTaxRate().getName())) .plusPredicates(m -> m.shippingInfo().taxRate().includedInPrice().is(shippingInfo.getTaxRate().isIncludedInPrice())) .plusPredicates(m -> m.shippingInfo().taxRate().country().is(shippingInfo.getTaxRate().getCountry())) .plusPredicates(m -> m.shippingInfo().shippingMethod().is(shippingMethod)) .plusPredicates(m -> m.shippingInfo().discountedPrice().isNotPresent()); assertThat(client().executeBlocking(query).head().get()).isEqualTo(cartWithShippingMethod); return cartWithShippingMethod; }); }); }