public interface ReviewCreateCommand extends DraftBasedCreateCommandDsl<Review,ReviewDraft,ReviewCreateCommand>, MetaModelReferenceExpansionDsl<Review,ReviewCreateCommand,ReviewExpansionModel<Review>>
Review
.
withType(client(), (Type type) -> { withCustomer(client(), (Customer customer) -> { withProduct(client(), (Product product) -> { withState(client(), StateDraft.of("initial-review-state", StateType.REVIEW_STATE), (State state) -> { final CustomFieldsDraft extraFields = CustomFieldsDraft.ofTypeKeyAndObjects(type.getKey(), singletonMap("screenshotUrls", Collections.singleton("https://docs.commercetools.com/assets/img/CT-logo.svg"))); final ReviewDraft reviewDraft = ReviewDraftBuilder.ofTitle("Commercetools rocks") .authorName("John Smith") .text("It is great.") .rating(100) .custom(extraFields) .customer(customer) .key("review1") //only allow one review for a product from one customer .uniquenessValue(product.getId() + "+" + customer.getId()) .locale(Locale.ENGLISH) .state(state) .target(product) .build(); final Review review = client().executeBlocking(ReviewCreateCommand.of(reviewDraft)); assertThat(review.getAuthorName()).isEqualTo("John Smith"); assertThat(review.getCustom().getFieldAsStringSet("screenshotUrls")) .containsExactly("https://docs.commercetools.com/assets/img/CT-logo.svg"); assertThat(review.getCustomer()).isEqualTo(customer.toReference()); assertThat(review.getKey()).isEqualTo("review1"); assertThat(review.getUniquenessValue()).isEqualTo(product.getId() + "+" + customer.getId()); assertThat(review.getLocale()).isEqualTo(Locale.ENGLISH); assertThat(review.getAuthorName()).isEqualTo("John Smith"); assertThat(review.getTitle()).isEqualTo("Commercetools rocks"); assertThat(review.getText()).isEqualTo("It is great."); assertThat(review.getTarget()).isEqualTo(product.toReference()); assertThat(review.getRating()).isEqualTo(100); assertThat(review.getState()).isEqualTo(state.toReference()); 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") .isNull(); //you can observe a message assertEventually(() -> { final PagedQueryResult<ReviewCreatedMessage> pagedQueryResult = client().executeBlocking(MessageQuery.of() .withPredicates(m -> m.resource().is(review)) .forMessageType(ReviewCreatedMessage.MESSAGE_HINT)); final Optional<ReviewCreatedMessage> paymentCreatedMessage = pagedQueryResult.head(); assertThat(paymentCreatedMessage).isPresent(); assertThat(paymentCreatedMessage.get().getReview().getId()).isEqualTo(review.getId()); assertThat(paymentCreatedMessage.get().getResource().getId()).isEqualTo(review.getId()); }); client().executeBlocking(ReviewDeleteCommand.of(review)); }); }); }); });
See the test code.
ReviewDraft
,
Review
Modifier and Type | Method and Description |
---|---|
static ReviewCreateCommand |
of(ReviewDraft draft)
Creates a command object to create a
Review . |
getDraft, withDraft
canDeserialize, deserialize, httpRequestIntent
plusExpansionPaths, withExpansionPaths
plusExpansionPaths, plusExpansionPaths, plusExpansionPaths, plusExpansionPaths, withExpansionPaths, withExpansionPaths, withExpansionPaths, withExpansionPaths
expansionPaths
static ReviewCreateCommand of(ReviewDraft draft)
Review
.draft
- template to create the new object