public static void withUpdateableShoppingList(final BlockingSphereClient client, final Function<ShoppingList, ShoppingList> f){ final ShoppingListDraft draft = newShoppingListDraftBuilder() .name(en(randomString())) .description(en(randomString())) .key(randomKey()) .slug(randomSlug()).build(); final ShoppingList shoppingList = client.executeBlocking(ShoppingListCreateCommand.of(draft)); final ShoppingList possiblyUpdatedShoppingList = f.apply(shoppingList); client.executeBlocking(ShoppingListDeleteCommand.of(possiblyUpdatedShoppingList)); }
public static void assertEventually(final Runnable block) { final Duration maxWaitTime = Duration.ofSeconds(30); final Duration waitBeforeRetry = Duration.ofMillis(100); assertEventually(maxWaitTime, waitBeforeRetry, block); } }
public static final ZonedDateTime tomorrowZonedDateTime() { return now().plus(1, ChronoUnit.DAYS); }
private static FieldDefinition localizedEnumFieldDefinition() { final List<LocalizedEnumValue> localizedEnumValues = asList("1", "2").stream() .map(s -> LocalizedEnumValue.of("key" + s, en("label " + s))) .collect(toList()); return fieldDefinition(LocalizedEnumFieldType.of(localizedEnumValues), LOCALIZED_ENUM_FIELD_NAME); }
public static ShoppingListDraftDsl newShoppingListDraftWithTextLineItems() { final List<TextLineItemDraft> textLineItemDrafts = asList( TextLineItemDraftBuilder.of(en(randomString()), 1L).build(), TextLineItemDraftBuilder.of(en(randomString()), 2L).build(), TextLineItemDraftBuilder.of(en(randomString()), 3L).build()); final ShoppingListDraftDsl shoppingListDraft = newShoppingListDraftBuilder().textLineItems(textLineItemDrafts).build(); return shoppingListDraft; } public static ShoppingListDraftDsl newShoppingListDraftWithLineItems(final Product product) {
public static void withCustomerGroup(final BlockingSphereClient client, final UnaryOperator<CustomerGroup> consumer) { final String name = randomString(); final String key = randomKey(); final CustomerGroupDraft customerGroupDraft = CustomerGroupDraft.of(name,key); final CustomerGroup customerGroup = client.executeBlocking(CustomerGroupCreateCommand.of(customerGroupDraft)); final CustomerGroup updatedCustomerGroup = consumer.apply(customerGroup); final Optional<CustomerGroup> customerGroupOptional = Optional.ofNullable(client.executeBlocking(CustomerGroupByIdGet.of(updatedCustomerGroup.getId()))); customerGroupOptional.ifPresent(group -> client.executeBlocking(CustomerGroupDeleteCommand.of(updatedCustomerGroup))); }
public static void withUpdateableState(final BlockingSphereClient client, final Function<State, State> f) { final State state = createStateByKey(client, randomKey()); final State updatedState = f.apply(state); client.executeBlocking(StateDeleteCommand.of(updatedState)); }
public static MetaAttributes randomMetaAttributes() { final String metaTitle = "meta title" + randomString(); final String metaDescription = "meta description" + randomString(); final String metaKeywords = "meta keywords," + randomString(); return MetaAttributes.metaAttributesOf(ENGLISH, metaTitle, metaDescription, metaKeywords); }
@BeforeClass public static void createBookProductType() throws Exception { final AttributeDefinition isbn = AttributeDefinitionBuilder .of(ISBN_ATTR_NAME, en("ISBN"), StringAttributeType.of()) .build(); final ProductTypeDraft productTypeDraft = ProductTypeDraft.of(randomKey(), BOOK_PRODUCT_TYPE_NAME, "books", asList(isbn)); final ProductType productType = client().executeBlocking(ProductTypeCreateCommand.of(productTypeDraft)); }
public static ProductType productReferenceProductType(final BlockingSphereClient client) { final AttributeDefinition productReferenceDefinition = AttributeDefinitionBuilder .of("productreference", en("suggested product"), ReferenceAttributeType.ofProduct()) .required(true) .build(); final ProductTypeDraft productTypeDraft = ProductTypeDraft.of(randomKey(), productReferenceProductTypeName, "has an attribute which is reference to a product", asList(productReferenceDefinition)); final Optional<ProductType> productTypeOptional = client.executeBlocking(ProductTypeQuery.of().byName(productReferenceProductTypeName)).head(); return productTypeOptional.orElseGet(() -> client.executeBlocking(ProductTypeCreateCommand.of(productTypeDraft))); }
final Reference<TaxCategory> taxCategoryRef = taxCategory.toReference(); final Reference<ShippingMethod> shippingMethodRef = shippingMethod.toReference(); final ZonedDateTime createdAt = SphereTestUtils.now().minusSeconds(4); final ParcelMeasurements parcelMeasurements = ParcelMeasurements.of(2, 3, 1, 3); final LineItemLike lineItem = new LineItemLike() { final TrackingData trackingData = TrackingData.of().withTrackingId("tracking id") .withCarrier("carrier").withProvider("provider").withProviderTransaction("prov transaction").withIsReturn(true); final Parcel parcel = Parcel.of(createdAt, randomUUID(),asList(), parcelMeasurements, trackingData); final List<Delivery> deliveries = asList(Delivery.of(deliveryId, createdAt, asList(deliveryItem), asList(parcel))); final ShippingInfoImportDraft shippingInfo = ShippingInfoImportDraftBuilder.of(randomString(), price, shippingRate, taxRate, taxCategoryRef, shippingMethodRef,ShippingMethodState.DOES_NOT_MATCH_CART, deliveries).build(); testOrderAspect( builder -> builder.shippingInfo(shippingInfo),
public static String randomSortOrder() { final int append = 5;//hack to not have a trailing 0 which is not accepted in sphere return "0." + randomInt() + append; }
@Test public void referenceExpansionForDeletionByKey() throws Exception { final String key = randomKey(); final Category parent = client().executeBlocking(CategoryCreateCommand.of(CategoryDraftBuilder.of(randomLocalizedString(), randomSlug()).build())); final Category category = client().executeBlocking(CategoryCreateCommand.of(CategoryDraftBuilder.of(randomLocalizedString(), randomSlug()).key(key).parent(parent).build())); final CategoryDeleteCommand deleteCommand = CategoryDeleteCommand.ofKey(key, category.getVersion()).plusExpansionPaths(m -> m.parent()); final Category deletedCategory = client().executeBlocking(deleteCommand); assertThat(deletedCategory.getParent().getObj()).isNotNull().isEqualTo(parent); client().executeBlocking(CategoryDeleteCommand.of(parent)); } }
@Test public void setDescription() throws Exception { withUpdateableShoppingList(client(), shoppingList -> { final LocalizedString newDescription = en(randomString()); final ShoppingList updatedShoppingList = client().executeBlocking( ShoppingListUpdateCommand.of(shoppingList, SetDescription.of(newDescription))); assertThat(updatedShoppingList.getDescription()).isEqualTo(newDescription); return updatedShoppingList; }); }
@Test public void deleteByKey() { final ResourceTypeIdsSetBuilder idsSetBuilder = ResourceTypeIdsSetBuilder.of().addCustomers(); final TypeDraft draft = TypeDraftBuilder.of(randomKey(), randomSlug(), idsSetBuilder) .build(); final Type type = client().executeBlocking(TypeCreateCommand.of(draft)); final String key = type.getKey(); final Long version = type.getVersion(); client().executeBlocking(TypeDeleteCommand.ofKey(key, version)); assertThat(client().executeBlocking(TypeByIdGet.of(type))).isNull(); } }
public static void withUpdateableShippingMethod(final BlockingSphereClient client, final UnaryOperator<ShippingMethodDraftBuilder> builderMapper, final Function<ShippingMethod, ShippingMethod> f) { withTaxCategory(client, taxCategory -> { final ShippingMethodDraftBuilder builder = ShippingMethodDraftBuilder.of(randomString(), "test shipping method", taxCategory.toReference(), asList(), false); final ShippingMethodDraft draft = builderMapper.apply(builder).build(); final ShippingMethod shippingMethod = client.executeBlocking(ShippingMethodCreateCommand.of(draft)); final ShippingMethod possiblyUpdatedShippingMethod = f.apply(shippingMethod); client.executeBlocking(ShippingMethodDeleteCommand.of(possiblyUpdatedShippingMethod)); }); }
@Test public void execution() throws Exception { final ZonedDateTime validFrom = SphereTestUtils.now(); final ZonedDateTime validUntil = validFrom.plusSeconds(8000); final LocalizedString name = en("discount name"); final LocalizedString description = en("discount descriptions"); final String predicate = "totalPrice > \"800.00 EUR\""; final AbsoluteCartDiscountValue value = CartDiscountValue.ofAbsolute(MoneyImpl.of(10, EUR));
private static void testProductIds(final SortExpression<ProductProjection> sortExpr, final Consumer<List<String>> test) { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged().withSort(sortExpr); final List<ProductProjection> results = executeSearch(search).getResults(); assertEventually(() -> { test.accept(toIds(results)); }); } }
private static void withFilledImportedOrderDraftBuilder(final BlockingSphereClient client, final Consumer<OrderImportDraftBuilder> operator) { withTransientTaxCategory(client, taxCategory -> { final MonetaryAmount lineItemPrice = MoneyImpl.ofCents(randomInt(), EUR); final CustomLineItemImportDraft customLineItemImportDraft = CustomLineItemImportDraftBuilder.of(randomSlug(), 1, lineItemPrice, taxCategory).build(); final OrderImportDraftBuilder builder = OrderImportDraftBuilder.ofCustomLineItems(lineItemPrice, OrderState.OPEN, singletonList(customLineItemImportDraft)); operator.accept(builder); }); }
public static CustomLineItemDraft createCustomLineItemDraft(final TaxCategory taxCategory) { final MonetaryAmount money = MoneyImpl.of(new BigDecimal("23.50"), EUR); return CustomLineItemDraft.of(en("thing"), "thing-slug", money, taxCategory, 5L, null); } }