@Override public Set<Reference<Category>> getCategories() { return productData.getCategories(); }
@Override public List<Reference<Category>> getCategories() { return productData.getCategories(); }
@Override public List<Reference<Category>> getCategories() { return productData.getCategories(); }
@Override public Set<Reference<Category>> getCategories() { return productData.getCategories(); }
@Override public Set<Reference<Category>> getCategories() { return productData.getCategories(); }
@Test public void addToCategory() throws Exception { withProductAndUnconnectedCategory(client(), (final Product product, final Category category) -> { assertThat(product.getMasterData().getStaged().getCategories()).isEmpty(); final String orderHint = "0.123"; final Product productWithCategory = client() .executeBlocking(ProductUpdateCommand.of(product, AddToCategory.of(category, orderHint))); final Reference<Category> categoryReference = productWithCategory.getMasterData().getStaged().getCategories().stream().findAny().get(); assertThat(categoryReference.referencesSameResource(category)).isTrue(); assertThat(productWithCategory.getMasterData().getStaged().getCategoryOrderHints().get(category.getId())).isEqualTo(orderHint); final Product productWithoutCategory = client() .executeBlocking(ProductUpdateCommand.of(productWithCategory, RemoveFromCategory.of(category))); assertThat(productWithoutCategory.getMasterData().getStaged().getCategories()).isEmpty(); }); }
@Test public void canExpandItsCategories() throws Exception { withProductInCategory(client(), (product, category) -> { final Query<Product> query = query(product) .withExpansionPaths(ProductExpansionModel.of().masterData().staged().categories()); assertThat(client().executeBlocking(query).head().get().getMasterData().getStaged().getCategories().stream().anyMatch(reference -> reference.getObj() != null)) .isTrue(); }); }
@Test public void execution() throws Exception { withProduct(client(), "getProductProjectionById", product -> { final ProductProjectionType projectionType = STAGED; final String productId = product.getId(); final ProductProjectionByIdGet sphereRequest = ProductProjectionByIdGet.of(productId, projectionType); final ProductProjection productProjection = client().executeBlocking(sphereRequest); final String fetchedProjectionId = productProjection.getId(); assertThat(fetchedProjectionId).isEqualTo(productId); assertThat(productProjection.getCategories()).isEqualTo(product.getMasterData().get(projectionType).getCategories()); }); } }
public void addToCategoryWithStaged(final Boolean staged) { withCategory(client(), category -> { withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().getStaged().getCategories()).isEmpty(); assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final String orderHint = "0.123"; final Product productWithCategory = client() .executeBlocking(ProductUpdateCommand.of(product, AddToCategory.of(category, orderHint, staged))); assertThat(productWithCategory.getMasterData().hasStagedChanges()).isEqualTo(staged); final Product publishedProductWithCategory = client().executeBlocking(ProductUpdateCommand.of(productWithCategory, Publish.of())); final Product productWithoutCategory = client() .executeBlocking(ProductUpdateCommand.of(publishedProductWithCategory, RemoveFromCategory.of(category, staged))); assertThat(productWithoutCategory.getMasterData().hasStagedChanges()).isEqualTo(staged); assertThat(productWithoutCategory.getMasterData().getStaged().getCategories()).isEmpty(); return productWithoutCategory; }); }); }
public void setCategoryOrderHintWithStaged(final Boolean staged) { withCategory(client(), category -> { withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().getStaged().getCategories()).isEmpty(); final String orderHint = "0.123"; final Product productWithCategory = client() .executeBlocking(ProductUpdateCommand.of(product, AddToCategory.of(category, orderHint, false))); assertThat(productWithCategory.getMasterData().hasStagedChanges()).isFalse(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(productWithCategory, SetCategoryOrderHint.of(category.getId(), "0.1234", staged))); final CategoryOrderHints actual = updatedProduct.getMasterData().getStaged().getCategoryOrderHints(); assertThat(actual).isEqualTo(CategoryOrderHints.of(category.getId(), "0.1234")); assertThat(actual.getAsMap()).isEqualTo(Collections.singletonMap(category.getId(), "0.1234")); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return productWithCategory; }); }); }
@Test public void createProductByJsonDraft() throws Exception { final JsonNodeReferenceResolver referenceResolver = new JsonNodeReferenceResolver(); withCategory(client(), category -> { withProductType(client(), randomKey(), productType -> { withTaxCategory(client(), taxCategory -> { withStateByBuilder(client(), stateBuilder -> stateBuilder.initial(true).type(StateType.PRODUCT_STATE), state -> { referenceResolver.addResourceByKey("t-shirt-category", category); referenceResolver.addResourceByKey("t-shirt-product-type", productType); referenceResolver.addResourceByKey("standard-tax", taxCategory); referenceResolver.addResourceByKey("initial-product-state", state); final ProductDraft productDraft = draftFromJsonResource("drafts-tests/product.json", ProductDraft.class, referenceResolver); final Product product = client().executeBlocking(ProductCreateCommand.of(productDraft)); assertThat(product.getProductType()).isEqualTo(productType.toReference()); assertThat(product.getTaxCategory()).isEqualTo(taxCategory.toReference()); assertThat(product.getState()).isEqualTo(state.toReference()); final ProductData productData = product.getMasterData().getStaged(); assertThat(productData.getName()).isEqualTo(LocalizedString.ofEnglish("red shirt")); assertThat(productData.getCategories()).extracting("id").contains(category.getId()); client().executeBlocking(ProductDeleteCommand.of(product)); }); }); }); }); }
@SuppressWarnings("unchecked") @Test public void isInSubtree() { withCategoryAndParentCategory(client(), (Category cat, Category parent) -> { withProduct(client(), builder -> builder.categoriesAsObjectList(singletonList(cat)), product -> { final String parentId = parent.getId(); assertThat(product.getMasterData().getStaged().getCategories()) .contains(cat.toReference()) .doesNotContain(parent.toReference()); assertEventually(() -> { //search for products directly in parent category final ProductProjectionSearch requestForDirectCategories = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.categories().id().is(parentId)); assertThat(client().executeBlocking(requestForDirectCategories).getResults()).isEmpty(); //search for products in parent category or its descendants final ProductProjectionSearch requestForTree = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.categories().id().isInSubtree(parentId)); final List<ProductProjection> results = client().executeBlocking(requestForTree).getResults(); assertThat(results).hasSize(1); }); }); }); } }