Skip to content

Commit

Permalink
#325: Remove publish and revert product services.
Browse files Browse the repository at this point in the history
  • Loading branch information
heshamMassoud committed Nov 24, 2018
1 parent 1169172 commit 40395f6
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 157 deletions.
Expand Up @@ -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<Product> 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<Product> fetchedProductOptional = productService.fetchProduct(product.getKey())
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -159,16 +157,4 @@ public CompletionStage<Product> updateProduct(@Nonnull final Product product,
@Nonnull final List<UpdateAction<Product>> updateActions) {
return updateResource(product, ProductUpdateCommand::of, updateActions);
}

@Nonnull
@Override
public CompletionStage<Product> publishProduct(@Nonnull final Product product) {
return syncOptions.getCtpClient().execute(ProductUpdateCommand.of(product, Publish.of()));
}

@Nonnull
@Override
public CompletionStage<Product> revertProduct(@Nonnull final Product product) {
return syncOptions.getCtpClient().execute(ProductUpdateCommand.of(product, RevertStagedChanges.of()));
}
}
Expand Up @@ -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;
Expand Down Expand Up @@ -139,26 +137,4 @@ public void buildProductKeysQueryPredicate_WithSomeBlankProductKeys_ShouldBuildC
final QueryPredicate<Product> 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())));
}
}

0 comments on commit 40395f6

Please sign in to comment.