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); } }
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 void predicateTestCase(final QueryPredicate<Category> predicate, final Consumer<List<Category>> assertions) { withCategory(client(), CategoryDraftBuilder.of(en("x1"), en("x1")).description(null), c1 -> { withCategory(client(), CategoryDraftBuilder.of(en("x2").plus(Locale.CHINESE, "xx"), en("x2")).description(en("desc 2")), c2 -> { withCategory(client(), CategoryDraftBuilder.of(en("x10"), en("x10")), c10 -> { final Query<Category> query = CategoryQuery.of().withPredicates(predicate).withSort(CategoryQueryModel.of().createdAt().sort().desc()); final List<Category> results = client().executeBlocking(query).getResults(); assertions.accept(results); }); }); }); } }
public static DiscountCodeDraftBuilder discountCodeDraftBuilder(BlockingSphereClient client, String code) { final CartDiscount cartDiscount = defaultCartDiscount(client); return DiscountCodeDraftBuilder.of(code, cartDiscount) .name(en("sample discount code")) .description(en("sample discount code descr.")) .isActive(true) .maxApplications(5L) .maxApplicationsPerCustomer(1L); }
private static FieldDefinition relatedCategoriesFieldDefinition() { final LocalizedString relatedCategoriesLabel = en("categories to suggest products similar to the current category"); //referenceTypeId is required to refere to categories final String referenceTypeId = Category.referenceTypeId(); final SetFieldType setType = SetFieldType.of(ReferenceFieldType.of(referenceTypeId)); return FieldDefinition .of(setType, "relatedCategories", relatedCategoriesLabel, false); } }
private static FieldDefinition stateFieldDefinition() { final List<EnumValue> values = asList( EnumValue.of("published", "the category is publicly visible"), EnumValue.of("draft", "the category should not be displayed in the frontend") ); final boolean required = false; final LocalizedString label = en("state of the category concerning to show it publicly"); final String fieldName = "state"; return FieldDefinition .of(EnumFieldType.of(values), fieldName, label, required); }
@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; }); }
public static Product referenceableProduct(final BlockingSphereClient client) { final ProductType productType = ProductTypeFixtures.defaultProductType(client); final ProductVariantDraft variantDraft = ProductVariantDraftBuilder.of().price(PRICE).build(); final String slugEn = "referenceable-product-2"; final ProductDraft productDraft = ProductDraftBuilder.of(productType, en("referenceable product"), en(slugEn), variantDraft).build(); return client.executeBlocking(ProductQuery.of().bySlug(ProductProjectionType.STAGED, ENGLISH, slugEn)).head() .orElseGet(() -> client.executeBlocking(ProductCreateCommand.of(productDraft))); }
@Test public void changeName() throws Exception { withUpdateableShoppingList(client(), shoppingList -> { final String newName = randomString(); final ShoppingList updatedShoppingList = client().executeBlocking( ShoppingListUpdateCommand.of(shoppingList, ChangeName.of(en(newName)))); assertThat(updatedShoppingList.getName().get(Locale.ENGLISH)).isEqualTo(newName); return updatedShoppingList; }); }
@BeforeClass public static void createProducts() { ProductFixtures.deleteProductsAndProductTypes(client()); productType = ProductTypeFixtures.createProductType(client(), "QueryAllProductsDemo"); final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of().build(); final Stream<Product> productStream = Stream.generate(() -> { final ProductDraft productDraft = ProductDraftBuilder.of(productType, en("QueryAllDemoProduct"), randomSlug(), masterVariant).build(); return client().executeBlocking(ProductCreateCommand.of(productDraft)); }); createdProducts = productStream.limit(19).sorted(BY_ID_COMPARATOR).collect(toList()); }
public static void withPersistentCategory(final BlockingSphereClient client, final Consumer<Category> user) { final String externalId = "persistent-category-id"; final Optional<Category> fetchedCategory = client.executeBlocking(CategoryQuery.of().byExternalId(externalId)).head(); final Category category = fetchedCategory.orElseGet(() -> { final LocalizedString name = en("name persistent-category-id"); final CategoryDraftBuilder catSupplier = CategoryDraftBuilder.of(name, name.slugified()).externalId(externalId); return client.executeBlocking(CategoryCreateCommand.of(catSupplier.build())); }); user.accept(category); }
private ProductTypeDraft createNutrient(final Referenceable<ProductType> nutrientInformationType) { return ProductTypeDraft.of(randomKey(), "Nutrient", "Nutrient", asList( AttributeDefinitionBuilder.of(Nutrient.servingSizeUOM.getName(), en(Nutrient.servingSizeUOM.getName()), StringAttributeType.of()).build(), AttributeDefinitionBuilder.of(Nutrient.servingSize.getName(), en(Nutrient.servingSize.getName()), NumberAttributeType.of()).build(), AttributeDefinitionBuilder.of(Nutrient.nutrientInformation.getName(), en(Nutrient.nutrientInformation.getName()), SetAttributeType.of(NestedAttributeType.of(nutrientInformationType))).searchable(false).build())); }
private ProductTypeDraft createBanana(Referenceable<ProductType> nutrientType) { return ProductTypeDraft.of(randomKey(), "Banana", "Banana", asList( AttributeDefinitionBuilder.of(Banana.bananaColor.getName(), en(Banana.bananaColor.getName()), StringAttributeType.of()).build(), AttributeDefinitionBuilder.of(Banana.nutrients.getName(), en(Banana.nutrients.getName()), SetAttributeType.of(NestedAttributeType.of(nutrientType))).searchable(false).build())); } }
@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 ShoppingListDraftDsl newShoppingListDraftWithTextLineItem(final Long quantity) { final List<TextLineItemDraft> textLineItemDrafts = asList( TextLineItemDraftBuilder.of(en(randomString()), quantity).build()); final ShoppingListDraftDsl shoppingListDraft = newShoppingListDraftBuilder().textLineItems(textLineItemDrafts).build(); return shoppingListDraft; }
@Test public void addLocalizedEnumValue() { withUpdateableType(client(), type -> { final String name = TypeFixtures.LOCALIZED_ENUM_FIELD_NAME; final LocalizedEnumValue newLocalizedEnumValue = LocalizedEnumValue.of("key-new", en("label new")); final Type updatedType = client().executeBlocking(TypeUpdateCommand.of(type, AddLocalizedEnumValue.of(name, newLocalizedEnumValue))); assertThat(updatedType.getFieldDefinitionByName(name).getType()) .isInstanceOf(LocalizedEnumFieldType.class) .matches(fieldType -> ((LocalizedEnumFieldType) fieldType).getValues().contains(newLocalizedEnumValue), "contains the new enum value"); return updatedType; }); }
@Test public void queryByMetaAttributes() throws Exception { withProduct(client(), product -> { final MetaAttributes metaAttributes = randomMetaAttributes(); final Product productWithMetaAttributes = client().executeBlocking(ProductUpdateCommand.of(product, MetaAttributesUpdateActions.of(metaAttributes))); checkOneResult(productWithMetaAttributes, model().metaDescription().lang(ENGLISH).is(en(metaAttributes.getMetaDescription()))); checkOneResult(productWithMetaAttributes, model().metaTitle().lang(ENGLISH).is(en(metaAttributes.getMetaTitle()))); checkOneResult(productWithMetaAttributes, model().metaKeywords().lang(ENGLISH).is(en(metaAttributes.getMetaKeywords()))); }); }
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))); }
public static TypeDraftBuilder createTypeDraftBuilder() { final String typeKey = randomKey(); return TypeDraftBuilder.of(typeKey, en(TYPE_NAME), TYPE_IDS) .description(en("description")) .fieldDefinitions(asList(stringfieldDefinition(), enumFieldDefinition(), localizedEnumFieldDefinition(), catRefDefinition(), booleanDefinition(), LocalizedStringDefinition(), intDefinition(), doubleDefinition(), bigDecimalDefinition(), moneyDefinition(), dateDefinition(), dateTimeDefinition(), timeDefinition(), stringSetDefinition())); }
public static void withProductWithProductReference(final BlockingSphereClient client, final BiConsumer<Product, Product> consumer) { withProduct(client, referencedProduct -> { final ProductType productType = productReferenceProductType(client); final ProductVariantDraft productVariantDraft = ProductVariantDraftBuilder.of().attributes(AttributeDraft.of("productreference", referencedProduct.toReference())).build(); final ProductDraft productDraft = ProductDraftBuilder.of(productType, en("product reference name 1"), randomSlug(), productVariantDraft).build(); final Product product = client.executeBlocking(ProductCreateCommand.of(productDraft)); consumer.accept(product, referencedProduct); client.executeBlocking(ProductDeleteCommand.of(product)); }); }