static ProductProjectionByIdGet ofStaged(final String id) { return of(id, ProductProjectionType.STAGED); }
@Test public void withExpansionPathDslDemo() throws Exception { final ProductProjectionByIdGet fetch = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT) .plusExpansionPaths(ProductProjectionExpansionModel.of().categories()); assertThat(fetch.expansionPaths()) .isEqualTo(asList(ExpansionPath.of("categories[*]"))); final ProductProjectionByIdGet fetch2 = fetch.withExpansionPaths(m -> m.productType()); assertThat(fetch.expansionPaths()).overridingErrorMessage("old object is unchanged") .isEqualTo(asList(ExpansionPath.of("categories[*]"))); assertThat(fetch2.expansionPaths()).isEqualTo(asList(ExpansionPath.of("productType"))); assertThat(fetch2).isNotSameAs(fetch); }
@Test public void plusExpansionPathDemo() throws Exception { final ProductProjectionByIdGet fetch = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT); assertThat(fetch.expansionPaths()).isEmpty(); final ProductProjectionByIdGet fetch2 = fetch.plusExpansionPaths(ProductProjectionExpansionModel.of().categories()); assertThat(fetch.expansionPaths()).overridingErrorMessage("old object is unchanged").isEmpty(); assertThat(fetch2.expansionPaths()).isEqualTo(asList(ExpansionPath.of("categories[*]"))); assertThat(fetch2).isNotSameAs(fetch); }
@Test public void withExpansionPathDemo() throws Exception { final ProductProjectionByIdGet fetch = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT) .withExpansionPaths(ProductProjectionExpansionModel.of().categories()); assertThat(fetch.expansionPaths()) .isEqualTo(asList(ExpansionPath.of("categories[*]"))); final ProductProjectionByIdGet fetch2 = fetch.withExpansionPaths(ProductProjectionExpansionModel.of().productType()); assertThat(fetch.expansionPaths()).overridingErrorMessage("old object is unchanged") .isEqualTo(asList(ExpansionPath.of("categories[*]"))); assertThat(fetch2.expansionPaths()).isEqualTo(asList(ExpansionPath.of("productType"))); assertThat(fetch2).isNotSameAs(fetch); }
@Test public void selectAPriceByCurrencyInProductProjectionByIdGet() { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); withProductOfPrices(prices, product -> { final ProductProjectionByIdGet request = ProductProjectionByIdGet.ofStaged(product) .withPriceSelection(PriceSelection.of(EUR));//price selection config final ProductProjection result = client().executeBlocking(request); final ProductVariant masterVariant = result.getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }
final ProductProjection productProjection = client().executeBlocking(ProductProjectionByIdGet.ofStaged(product)); assertThat(productProjection.getReviewRatingStatistics()).isNotNull(); assertThat(productProjection.getReviewRatingStatistics().getAverageRating()).isEqualTo(100D);
@Test public void expandCategoriesDemo() throws Exception { final ProductProjectionByIdGet fetch1 = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT) .plusExpansionPaths(m -> m.categories()); assertThat(fetch1.expansionPaths()) .isEqualTo(asList(ExpansionPath.of("categories[*]"))); final ProductProjectionByIdGet fetch2 = fetch1.plusExpansionPaths(m -> m.productType()); assertThat(fetch2.expansionPaths()) .isEqualTo(asList(ExpansionPath.of("categories[*]"), ExpansionPath.of("productType"))) .isEqualTo(listOf(fetch1.expansionPaths(), ExpansionPath.of("productType"))); //this is equivalent to final ExpansionPath<ProductProjection> categoryExpand = ProductProjectionExpansionModel.of().categories().expansionPaths().get(0); final ExpansionPath<ProductProjection> productTypeExpand = ProductProjectionExpansionModel.of().productType().expansionPaths().get(0); final ProductProjectionByIdGet fetchB = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT) .withExpansionPaths(asList(categoryExpand, productTypeExpand)); assertThat(fetchB.expansionPaths()) .isEqualTo(asList(ExpansionPath.of("categories[*]"), ExpansionPath.of("productType"))); }
assertThat(review.getCustomer()).isEqualTo(customer.toReference()); final ProductProjection productProjection = client().executeBlocking(ProductProjectionByIdGet.ofStaged(product)); assertThat(productProjection.getReviewRatingStatistics()). as("the state has not the role ReviewIncludedInStatistics, so it is not accounted yet")
static ProductProjectionByIdGet ofStaged(final String id) { return of(id, ProductProjectionType.STAGED); }
static ProductProjectionByIdGet ofStaged(final String id) { return of(id, ProductProjectionType.STAGED); }
static ProductProjectionByIdGet ofCurrent(final String id) { return of(id, ProductProjectionType.CURRENT); }
static ProductProjectionByIdGet ofCurrent(final String id) { return of(id, ProductProjectionType.CURRENT); }
static ProductProjectionByIdGet ofCurrent(final String id) { return of(id, ProductProjectionType.CURRENT); }
static ProductProjectionByIdGet ofCurrent(final ProductIdentifiable product) { return of(product.getId(), ProductProjectionType.CURRENT); }
static ProductProjectionByIdGet ofStaged(final ProductIdentifiable product) { return of(product.getId(), ProductProjectionType.STAGED); }
static ProductProjectionByIdGet ofStaged(final ProductIdentifiable product) { return of(product.getId(), ProductProjectionType.STAGED); }
static ProductProjectionByIdGet ofStaged(final ProductIdentifiable product) { return of(product.getId(), ProductProjectionType.STAGED); }
static ProductProjectionByIdGet of(final ProductIdentifiable product, final ProductProjectionType projectionType) { return of(product.getId(), projectionType); }
static ProductProjectionByIdGet ofCurrent(final ProductIdentifiable product) { return of(product.getId(), ProductProjectionType.CURRENT); }
static ProductProjectionByIdGet of(final ProductIdentifiable product, final ProductProjectionType projectionType) { return of(product.getId(), projectionType); }