public final class ReviewCreatedMessage extends GenericMessageImpl<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.
ReviewCreateCommand
Modifier and Type | Field and Description |
---|---|
static MessageDerivateHint<ReviewCreatedMessage> |
MESSAGE_HINT |
static String |
MESSAGE_TYPE |
resource, resourceUserProvidedIdentifiers, resourceVersion, sequenceNumber, type
Modifier and Type | Method and Description |
---|---|
Review |
getReview()
Gets the review object at creation time.
|
as, equals, getPayload, getResource, getResourceUserProvidedIdentifiers, getResourceVersion, getSequenceNumber, getType, hashCode, toReference
getCreatedAt, getId, getLastModifiedAt, getVersion
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
referenceOfId, referenceTypeId, typeReference
getCreatedAt, getId, getLastModifiedAt, getVersion
hasSameIdAs, toResourceIdentifier
public static final String MESSAGE_TYPE
public static final MessageDerivateHint<ReviewCreatedMessage> MESSAGE_HINT
public Review getReview()
Message.getResource()
.