public static ChangeName of(final LocalizedStrings name, final ProductUpdateScope productUpdateScope) { return new ChangeName(name, productUpdateScope); }
public static ChangeName of(final LocalizedString name) { return of(name, null); }
public static ChangeName of(final LocalizedString name) { return new ChangeName(name); }
public static ChangeName of(final LocalizedString name) { return of(name, null); }
public static ChangeName of(final LocalizedStrings name, final ProductUpdateScope productUpdateScope) { return new ChangeName(name, productUpdateScope); }
public void changeNameWithStaged(final Boolean staged) { withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final LocalizedString newName = LocalizedString.ofEnglish("newName " + RANDOM.nextInt()); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, ChangeName.of(newName, staged))); assertThat(updatedProduct.getMasterData().getStaged().getName()).isEqualTo(newName); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
public static ChangeName of(final LocalizedString name, @Nullable final Boolean staged) { return new ChangeName(name, staged); }
@Test public void changeName() throws Exception { withUpdateableProduct(client(), product -> { final LocalizedString newName = LocalizedString.ofEnglish("newName " + RANDOM.nextInt()); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, ChangeName.of(newName))); assertThat(updatedProduct.getMasterData().getStaged().getName()).isEqualTo(newName); return updatedProduct; }); }
public static ChangeName of(final LocalizedString name, @Nullable final Boolean staged) { return new ChangeName(name, staged); }
@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 updateCommandPlusUpdateActions() { withUpdateableProduct(client(), (Product product) -> { assertThat(product.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0); final Image image = createExternalImage(); final AddExternalImage updateAction1 = AddExternalImage.of(image, MASTER_VARIANT_ID); final ProductUpdateCommand command = ProductUpdateCommand.of(product, updateAction1); assertThat(command.getUpdateActions()).hasSize(1); assertThat(command.getUpdateActions().get(0)).isEqualTo(updateAction1); final LocalizedString localizedName = en("New Name"); final ChangeName updateAction2 = ChangeName.of(localizedName); final ProductUpdateCommand updatedCommand = command.plusUpdateActions(asList(updateAction2)); assertThat(updatedCommand.getUpdateActions()).hasSize(2); assertThat(updatedCommand.getUpdateActions().get(1)).isEqualTo(updateAction2); final Product updatedProduct = client().executeBlocking(updatedCommand); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); assertThat(updatedProduct.getMasterData().getStaged().getName()).isEqualTo(localizedName); return updatedProduct; }); }
@Test public void differentiateBetweenCurrentAndStaged() throws Exception { withUpdateableProduct(client(), product -> { final Product publishedProduct = client().executeBlocking(ProductUpdateCommand.of(product, Publish.of())); final Product mixedDataProduct = client().executeBlocking(ProductUpdateCommand.of(publishedProduct, ChangeName.of(randomSlug()))); final LocalizedString nameInCurrent = mixedDataProduct.getMasterData().getCurrent().getName(); final LocalizedString nameInStaged = mixedDataProduct.getMasterData().getStaged().getName(); final ProductProjectionQuery stagedQuery = ProductProjectionQuery.of(STAGED).withPredicates(m -> m.id().is(product.getId())); assertThat(client().executeBlocking(stagedQuery).head().get().getName()).isEqualTo(nameInStaged); final ProductProjectionQuery currentQuery = ProductProjectionQuery.of(CURRENT).withPredicates(m -> m.id().is(product.getId())); assertThat(client().executeBlocking(currentQuery).head().get().getName()).isEqualTo(nameInCurrent); return mixedDataProduct; }); }
@Test public void queryByHasStagedChanges() throws Exception { withProduct(client(), product -> { final Product updated = client().executeBlocking(ProductUpdateCommand.of(product, ChangeName.of(randomSlug()))); final ProductProjectionQuery query = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.hasStagedChanges().is(true)) .withSort(m -> m.createdAt().sort().desc()); final PagedQueryResult<ProductProjection> pagedQueryResult = client().executeBlocking(query); assertThat(ids(pagedQueryResult)).contains(updated.getId()); }); }