@Test public void containsDraftGetter() { final CategoryDraft categoryDraft = CategoryDraftBuilder.of(randomSlug(), randomSlug()).build(); final CategoryCreateCommand categoryCreateCommand = CategoryCreateCommand.of(categoryDraft); assertThat(categoryCreateCommand.getDraft()).isEqualTo(categoryDraft); } }
public static void withProduct(final BlockingSphereClient client, final UnaryOperator<ProductDraftBuilder> builderMapper, final Consumer<Product> productConsumer) { withAttributesProductType(client, productType -> { final ProductDraftBuilder builder = ProductDraftBuilder.of(productType, randomSlug(), randomSlug(), ProductVariantDraftBuilder.of().build()); final ProductDraftBuilder updatedBuilder = builderMapper.apply(builder); final Product product = client.executeBlocking(ProductCreateCommand.of(updatedBuilder.build())); productConsumer.accept(product); client.executeBlocking(ProductDeleteCommand.of(product)); }); }
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); }); }
private void withProductOfPrices(final List<PriceDraft> priceDrafts, final Consumer<Product> productConsumer) { final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of() .prices(priceDrafts) .build(); final ProductDraft productDraft = ProductDraftBuilder.of(productType, randomSlug(), randomSlug(), masterVariant) .publish(true) .build(); withProduct(client(), () -> productDraft, productConsumer); } }
public static void withSuggestProduct(final BlockingSphereClient client, final Consumer<Product> consumer) { withEmptyProductType(client, randomKey(), productType -> { final SearchKeywords searchKeywords = SearchKeywords.of( Locale.ENGLISH, asList(SearchKeyword.of("Multi tool"), SearchKeyword.of("Swiss Army Knife", WhiteSpaceSuggestTokenizer.of())), Locale.GERMAN, singletonList(SearchKeyword.of("Schweizer Messer", CustomSuggestTokenizer.of(asList("schweizer messer", "offiziersmesser", "sackmesser")))) ); final ProductDraftBuilder productDraftBuilder = ProductDraftBuilder.of(productType, randomSlug(), randomSlug(), ProductVariantDraftBuilder.of().build()) .searchKeywords(searchKeywords); withProduct(client, productDraftBuilder, consumer); }); }
@Test public void setDescription() throws Exception { withPersistentDiscountCode(client(), discountCode -> { final LocalizedString newDescription = randomSlug(); final DiscountCode updatedDiscountCode = client().executeBlocking(DiscountCodeUpdateCommand.of(discountCode, SetDescription.of(newDescription))); assertThat(updatedDiscountCode.getDescription()).isEqualTo(newDescription); }); }
@Test public void setSlug() throws Exception { withUpdateableShoppingList(client(), shoppingList -> { final LocalizedString newSlug = randomSlug(); final ShoppingList updatedShoppingList = client().executeBlocking( ShoppingListUpdateCommand.of(shoppingList, SetSlug.of(newSlug))); assertThat(updatedShoppingList.getSlug()).isEqualTo(newSlug); return updatedShoppingList; }); }
private void withProductOfPrices(final List<PriceDraft> priceDrafts, final Consumer<Product> productConsumer) { final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of() .prices(priceDrafts) .build(); final ProductDraft productDraft = ProductDraftBuilder.of(productType, randomSlug(), randomSlug(), masterVariant) .key(randomKey()) .build(); ProductFixtures.withProduct(client(), () -> productDraft, productConsumer); } }
@Test public void setName() throws Exception { withPersistentDiscountCode(client(), discountCode -> { final LocalizedString newName = randomSlug(); final DiscountCode updatedDiscountCode = client().executeBlocking(DiscountCodeUpdateCommand.of(discountCode, SetName.of(newName))); assertThat(updatedDiscountCode.getName()).isEqualTo(newName); }); }
@Test public void setDescription() { withUpdateableType(client(), type -> { final LocalizedString newDescription = randomSlug(); final Type updatedType = client().executeBlocking(TypeUpdateCommand.of(type, SetDescription.of(newDescription))); assertThat(updatedType.getDescription()).isEqualTo(newDescription); return updatedType; }); }
@Test public void referenceExpansion() throws Exception { final CategoryDraft parentDraft = CategoryDraftBuilder.of(randomSlug(), randomSlug()).build(); final Category parent = client().executeBlocking(CategoryCreateCommand.of(parentDraft)); final CategoryDraft categoryDraft = CategoryDraftBuilder.of(randomSlug(), randomSlug()).parent(parent).build(); final CategoryCreateCommand createCommand = CategoryCreateCommand.of(categoryDraft).withExpansionPaths(m -> m.parent()); final Category category = client().executeBlocking(createCommand); assertThat(category.getParent()).is(expanded()); client().executeBlocking(CategoryDeleteCommand.of(parent)); }
private AttributeDefinitionDraft attributeDefinition(final String attributeName) { AttributeDefinition attributeDefinition = AttributeDefinitionBuilder.of(attributeName, randomSlug(), StringAttributeType.of()).build(); return AttributeDefinitionDraftBuilder.of(attributeDefinition).build(); } }
public static void withAttributesProductType(final BlockingSphereClient client, final Consumer<ProductType> user) { withProductType(client, () -> { final AttributeDefinition stringAttribute = AttributeDefinitionBuilder .of("stringfield", randomSlug(), StringAttributeType.of()) .build(); return ProductTypeDraft.of(randomKey(), randomKey(), "desc", Collections.singletonList(stringAttribute)); }, user); }
@Test public void changeLabel() { withUpdateableType(client(), type -> { final LocalizedString newLabel = randomSlug(); final String name = type.getFieldDefinitions().get(0).getName(); final Type updatedType = client().executeBlocking(TypeUpdateCommand.of(type, ChangeFieldDefinitionLabel.of(name, newLabel))); assertThat(updatedType.getFieldDefinitionByName(name).getLabel()).isEqualTo(newLabel); return updatedType; }); }
@Test public void updateByKey() { withUpdateableType(client(), (Type type) -> { final LocalizedString newName = randomSlug(); final String key = type.getKey(); final Long version = type.getVersion(); final Type updatedType = client().executeBlocking(TypeUpdateCommand.ofKey(key, version, ChangeName.of(newName))); assertThat(updatedType.getName()).isEqualTo(newName); return updatedType; }); }
@Test public void execution() throws Exception { final CategoryDraft draft = CategoryDraftBuilder.of(randomSlug(), randomSlug()).build(); final Category category = client().executeBlocking(CategoryCreateCommand.of(draft)); client().executeBlocking(CategoryDeleteCommand.of(category)); assertThat(client().executeBlocking(CategoryQuery.of().byId(category.getId())).head()).isEmpty(); }
@Test public void changeName() throws Exception { withPersistentCartDiscount(client(), cartDiscount -> { final LocalizedString newName = randomSlug(); assertThat(cartDiscount.getName()).isNotEqualTo(newName); final CartDiscount updatedDiscount = client().executeBlocking(CartDiscountUpdateCommand.of(cartDiscount, ChangeName.of(newName))); assertThat(updatedDiscount.getName()).isEqualTo(newName); //clean up test, cart discount is reused by name client().executeBlocking(CartDiscountUpdateCommand.of(updatedDiscount, ChangeName.of(cartDiscount.getName()))); }); }
@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(); } }
@Test public void queryByHasStagedChanges() throws Exception { withProduct(client(), product -> { final Product updated = client().executeBlocking(ProductUpdateCommand.of(product, ChangeName.of(randomSlug()))); final ProductProjectionQuery query = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.hasStagedChanges().is(true)) .withSort(m -> m.createdAt().sort().desc()); final PagedQueryResult<ProductProjection> pagedQueryResult = client().executeBlocking(query); assertThat(ids(pagedQueryResult)).contains(updated.getId()); }); }
@Test public void productReferenceAttribute() throws Exception { withEmptyProductType(client(), "productReferenceAttribute-testcase", productType -> { final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of().build(); final ProductDraft productDraft = ProductDraftBuilder.of(productType, LABEL, SphereTestUtils.randomSlug(), masterVariant).build(); final Product product = client().executeBlocking(ProductCreateCommand.of(productDraft)); testSingleAndSet(AttributeAccess.ofProductReference(), AttributeAccess.ofProductReferenceSet(), asSet(product.toReference().filled(null)), ReferenceAttributeType.ofProduct(), AttributeDefinitionBuilder.of("productReference", LABEL, ReferenceAttributeType.ofProduct()).build()); }); }