@Override public long getVersion() { return product.getVersion(); }
@Override public Long getVersion() { return product.getVersion(); }
@Override public Long getVersion() { return product.getVersion(); }
@Override public Long getVersion() { return product.getVersion(); }
@Override public long getVersion() { return product.getVersion(); }
@Test public void lightweigthProductsBySku() { withProduct(client(), product1 -> { withProduct(client(), product2 -> { final List<String> skus = asList(product1, product2).stream() .map(product -> product.getMasterData().getStaged().getMasterVariant().getSku()) .collect(Collectors.toList()); final Set<LightweightProduct> actual = new HashSet<>(client().executeBlocking(LightweightProduct.requestOfSkus(skus))); final Set<LightweightProduct> expected = asList(product1, product2).stream() .map(product -> { final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); return new LightweightProduct(product.getId(), product.getVersion(), singletonList(sku)); }) .collect(Collectors.toSet()); assertThat(actual).isEqualTo(expected); }); }); } }
@Test public void productUpdateByKey() throws Exception { final String key = randomKey(); withUpdateableProduct(client(), builder -> builder.key(key), product -> { final LocalizedString newName = LocalizedString.ofEnglish("newName " + RANDOM.nextInt()); final ProductUpdateCommand cmd = ProductUpdateCommand.ofKey(key, product.getVersion(), ChangeName.of(newName)); final Product updatedProduct = client().executeBlocking(cmd); assertThat(updatedProduct.getMasterData().getStaged().getName()).isEqualTo(newName); assertThat(updatedProduct.getKey()).isEqualTo(key); return updatedProduct; }); }
@Test public void byKey() { ProductTypeFixtures.withEmptyProductType(client(), productType -> { final String key = randomKey(); final ProductDraft productDraft = ProductDraftBuilder.of(productType, randomSlug(), randomSlug(), ProductVariantDraftBuilder.of().build()).key(key).build(); final Product product = client().executeBlocking(ProductCreateCommand.of(productDraft)); final Product deletedProduct = client().executeBlocking(ProductDeleteCommand.ofKey(key, product.getVersion())); assertThat(client().executeBlocking(ProductByKeyGet.of(key))).isNull(); }); } }
@Test public void message() { ProductTypeFixtures.withEmptyProductType(client(), productType -> { final String key = randomKey(); final Image image = createExternalImage(); final ProductDraft productDraft = ProductDraftBuilder.of(productType, randomSlug(), randomSlug(), ProductVariantDraftBuilder.of().images(image).build()).key(key).build(); final Product product = client().executeBlocking(ProductCreateCommand.of(productDraft)); final Product deletedProduct = client().executeBlocking(ProductDeleteCommand.ofKey(key, product.getVersion())); Query<ProductDeletedMessage> messageQuery = MessageQuery.of() .withPredicates(m -> m.resource().is(deletedProduct)) .withSort(m -> m.createdAt().sort().desc()) .withExpansionPaths(m -> m.resource()) .withLimit(1L) .forMessageType(ProductDeletedMessage.MESSAGE_HINT); assertEventually(() -> { final PagedQueryResult<ProductDeletedMessage> queryResult = client().executeBlocking(messageQuery); assertThat(queryResult.head()).isPresent(); final ProductDeletedMessage message = queryResult.head().get(); assertThat(message.getResource().getId()).isEqualTo(product.getId()); assertThat(message.getRemovedImageUrls()).containsExactly(image.getUrl()); }); }); } }