From 40395f6fecf70d63e3281163871102a85ce36e5f Mon Sep 17 00:00:00 2001 From: Hesham Massoud Date: Sat, 24 Nov 2018 23:54:18 +0100 Subject: [PATCH] #325: Remove publish and revert product services. --- .../services/impl/ProductServiceImplIT.java | 119 ------------------ .../services/impl/ProductServiceImpl.java | 14 --- .../services/impl/ProductServiceTest.java | 24 ---- 3 files changed, 157 deletions(-) diff --git a/src/integration-test/java/com/commercetools/sync/integration/services/impl/ProductServiceImplIT.java b/src/integration-test/java/com/commercetools/sync/integration/services/impl/ProductServiceImplIT.java index a8488c8593..add8514aa6 100644 --- a/src/integration-test/java/com/commercetools/sync/integration/services/impl/ProductServiceImplIT.java +++ b/src/integration-test/java/com/commercetools/sync/integration/services/impl/ProductServiceImplIT.java @@ -806,125 +806,6 @@ public void updateProduct_WithMoreThan500ImageAdditions_ShouldHaveAllNewImages() assertThat(currentMasterVariantImages).containsAll(addedImages); } - @Test - @SuppressWarnings("ConstantConditions") - public void publishProduct_ThatIsAlreadyPublished_ShouldThrowException() { - productService.publishProduct(product) - .exceptionally(exception -> { - assertThat(exception).isExactlyInstanceOf(ErrorResponseException.class); - assertThat(exception.getMessage()).containsIgnoringCase("Product is published and has no " - + "staged changes"); - assertThat(errorCallBackExceptions).isEmpty(); - assertThat(errorCallBackMessages).isEmpty(); - return null; - }).toCompletableFuture().join(); - } - - @Test - @SuppressWarnings("ConstantConditions") - public void publishProduct_ThatHasStagedChanges_ShouldPublishStagedChanges() { - final String newProductName = "This is my new name!"; - final ChangeName changeNameUpdateAction = ChangeName - .of(LocalizedString.of(Locale.GERMAN, newProductName)); - - final Product updatedProduct = productService - .updateProduct(product, Collections.singletonList(changeNameUpdateAction)).toCompletableFuture().join(); - - assertThat(updatedProduct.getMasterData().isPublished()).isTrue(); - assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); - assertThat(updatedProduct.getMasterData().getCurrent().getName()) - .isNotEqualTo(updatedProduct.getMasterData().getStaged().getName()); - - final Product publishedProduct = productService.publishProduct(updatedProduct).toCompletableFuture().join(); - - assertThat(errorCallBackExceptions).isEmpty(); - assertThat(errorCallBackMessages).isEmpty(); - assertThat(publishedProduct).isNotNull(); - assertThat(publishedProduct.getMasterData().getCurrent().getName()) - .isEqualTo(publishedProduct.getMasterData().getStaged().getName()); - assertThat(publishedProduct.getMasterData().isPublished()).isTrue(); - assertThat(publishedProduct.getMasterData().hasStagedChanges()).isFalse(); - } - - @Test - @SuppressWarnings("ConstantConditions") - public void publishProduct_ThatIsUnPublished_ShouldPublishProductCorrectly() { - final String newKey = "newKey"; - final ProductDraft productDraft = createProductDraftBuilder(PRODUCT_KEY_2_RESOURCE_PATH, - productType.toReference()) - .key(newKey) - .categories(emptyList()) - .categoryOrderHints(null) - .taxCategory(null) - .state(null) - .slug(LocalizedString.of(Locale.ENGLISH, "newSlug")) - .masterVariant(ProductVariantDraftBuilder.of().build()) - .publish(false) - .build(); - - final Optional newProductOptional = - productService.createProduct(productDraft).toCompletableFuture().join(); - - assertThat(newProductOptional).isPresent(); - final Product newProduct = newProductOptional.get(); - assertThat(newProduct.getMasterData().isPublished()).isFalse(); - assertThat(newProduct.getMasterData().getCurrent()).isNull(); - - final Product publishedProduct = productService.publishProduct(newProduct) - .toCompletableFuture().join(); - - assertThat(errorCallBackExceptions).isEmpty(); - assertThat(errorCallBackMessages).isEmpty(); - assertThat(publishedProduct).isNotNull(); - assertThat(publishedProduct.getMasterData().getCurrent()).isNotNull(); - assertThat(publishedProduct.getMasterData().getCurrent().getName()) - .isEqualTo(productDraft.getName()); - assertThat(publishedProduct.getMasterData().getCurrent().getSlug()) - .isEqualTo(productDraft.getSlug()); - assertThat(publishedProduct.getKey()).isEqualTo(productDraft.getKey()); - assertThat(publishedProduct.getMasterData().isPublished()).isTrue(); - } - - @Test - @SuppressWarnings("ConstantConditions") - public void revertProduct_ThatHasNoStagedChanges_ShouldThrowException() { - productService.revertProduct(product) - .exceptionally(exception -> { - assertThat(exception).isExactlyInstanceOf(ErrorResponseException.class); - assertThat(exception.getMessage()).containsIgnoringCase("No staged changes present in " - + "catalog master"); - assertThat(errorCallBackExceptions).isEmpty(); - assertThat(errorCallBackMessages).isEmpty(); - return null; - }).toCompletableFuture().join(); - } - - @Test - @SuppressWarnings("ConstantConditions") - public void revertProduct_ThatHasStagedChanges_ShouldRevertStagedChanges() { - final String newProductName = "This is my new name!"; - final ChangeName changeNameUpdateAction = ChangeName - .of(LocalizedString.of(Locale.GERMAN, newProductName)); - - final Product updatedProduct = productService - .updateProduct(product, Collections.singletonList(changeNameUpdateAction)).toCompletableFuture().join(); - - assertThat(updatedProduct.getMasterData().isPublished()).isTrue(); - assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); - assertThat(updatedProduct.getMasterData().getCurrent().getName()) - .isNotEqualTo(updatedProduct.getMasterData().getStaged().getName()); - - final Product revertedProduct = productService.revertProduct(updatedProduct).toCompletableFuture().join(); - - assertThat(errorCallBackExceptions).isEmpty(); - assertThat(errorCallBackMessages).isEmpty(); - assertThat(revertedProduct).isNotNull(); - assertThat(revertedProduct.getMasterData().getCurrent().getName()) - .isEqualTo(revertedProduct.getMasterData().getStaged().getName()); - assertThat(revertedProduct.getMasterData().isPublished()).isTrue(); - assertThat(revertedProduct.getMasterData().hasStagedChanges()).isFalse(); - } - @Test public void fetchProduct_WithExistingKey_ShouldReturnProduct() { final Optional fetchedProductOptional = productService.fetchProduct(product.getKey()) diff --git a/src/main/java/com/commercetools/sync/services/impl/ProductServiceImpl.java b/src/main/java/com/commercetools/sync/services/impl/ProductServiceImpl.java index 42d66c579a..159202dd81 100644 --- a/src/main/java/com/commercetools/sync/services/impl/ProductServiceImpl.java +++ b/src/main/java/com/commercetools/sync/services/impl/ProductServiceImpl.java @@ -8,8 +8,6 @@ import io.sphere.sdk.products.ProductDraft; import io.sphere.sdk.products.commands.ProductCreateCommand; import io.sphere.sdk.products.commands.ProductUpdateCommand; -import io.sphere.sdk.products.commands.updateactions.Publish; -import io.sphere.sdk.products.commands.updateactions.RevertStagedChanges; import io.sphere.sdk.products.queries.ProductQuery; import io.sphere.sdk.queries.QueryPredicate; import org.apache.commons.lang3.StringUtils; @@ -159,16 +157,4 @@ public CompletionStage updateProduct(@Nonnull final Product product, @Nonnull final List> updateActions) { return updateResource(product, ProductUpdateCommand::of, updateActions); } - - @Nonnull - @Override - public CompletionStage publishProduct(@Nonnull final Product product) { - return syncOptions.getCtpClient().execute(ProductUpdateCommand.of(product, Publish.of())); - } - - @Nonnull - @Override - public CompletionStage revertProduct(@Nonnull final Product product) { - return syncOptions.getCtpClient().execute(ProductUpdateCommand.of(product, RevertStagedChanges.of())); - } } diff --git a/src/test/java/com/commercetools/sync/services/impl/ProductServiceTest.java b/src/test/java/com/commercetools/sync/services/impl/ProductServiceTest.java index c4bcde371c..9fbe159ccb 100644 --- a/src/test/java/com/commercetools/sync/services/impl/ProductServiceTest.java +++ b/src/test/java/com/commercetools/sync/services/impl/ProductServiceTest.java @@ -11,8 +11,6 @@ import io.sphere.sdk.products.commands.ProductCreateCommand; import io.sphere.sdk.products.commands.ProductUpdateCommand; import io.sphere.sdk.products.commands.updateactions.ChangeName; -import io.sphere.sdk.products.commands.updateactions.Publish; -import io.sphere.sdk.products.commands.updateactions.RevertStagedChanges; import io.sphere.sdk.queries.QueryPredicate; import io.sphere.sdk.utils.CompletableFutureUtils; import org.junit.Before; @@ -139,26 +137,4 @@ public void buildProductKeysQueryPredicate_WithSomeBlankProductKeys_ShouldBuildC final QueryPredicate queryPredicate = service.buildProductKeysQueryPredicate(productKeys); assertThat(queryPredicate.toSphereQuery()).isEqualTo("key in (\"key1\", \"key2\")"); } - - @Test - public void publishProduct_WithMockCtpResponse_ShouldReturnMock() { - final Product mock = mock(Product.class); - when(productSyncOptions.getCtpClient().execute(any())).thenReturn(completedFuture(mock)); - - final Product product = service.publishProduct(mock).toCompletableFuture().join(); - - assertThat(product).isSameAs(mock); - verify(productSyncOptions.getCtpClient()).execute(eq(ProductUpdateCommand.of(mock, Publish.of()))); - } - - @Test - public void revertProduct_WithMockCtpResponse_ShouldReturnMock() { - final Product mock = mock(Product.class); - when(productSyncOptions.getCtpClient().execute(any())).thenReturn(completedFuture(mock)); - - final Product product = service.revertProduct(mock).toCompletableFuture().join(); - - assertThat(product).isSameAs(mock); - verify(productSyncOptions.getCtpClient()).execute(eq(ProductUpdateCommand.of(mock, RevertStagedChanges.of()))); - } } \ No newline at end of file