static ProductTypeDeleteCommand ofKey(final String key, final Long version) { final Versioned<ProductType> versioned = Versioned.of("key=" + key, version);//hack for simple reuse return of(versioned); } }
public static DeleteCommand<ProductType> of(final Versioned<ProductType> versioned) { return new ProductTypeDeleteCommand(versioned); } }
@Test public void executionByKey() throws Exception { final ProductType productType = client().executeBlocking(ProductTypeCreateCommand.of(getDraft())); client().executeBlocking(ProductTypeDeleteCommand.ofKey(productType.getKey(), productType.getVersion())); final Query<ProductType> query = ProductTypeQuery.of() .withPredicates(m -> m.id().is(productType.getId())); assertThat(client().executeBlocking(query).head()).isEmpty(); }
/** Creates a command object to delete a {@link ProductType} by its key. @param key the key of the ProductType to delete, see {@link ProductType#getKey()} @param version `the current version of the ProductType, see {@link ProductType#getVersion()} @return delete command */ static ProductTypeDeleteCommand ofKey(final String key, final Long version) { final Versioned<ProductType> versioned = Versioned.of("key=" + urlEncode(key), version);//hack for simple reuse return of(versioned); }
public static void destroy(final BlockingSphereClient client, final Data data) { final List<CompletionStage<Product>> productDeletions = data.getAllProducts().stream() .map(product -> client.execute(ProductDeleteCommand.of(product))) .collect(toList()); productDeletions.forEach(stage -> SphereClientUtils.blockingWait(stage, 2, TimeUnit.SECONDS)); client.executeBlocking(ProductTypeDeleteCommand.of(data.getProductType())); }
public static void deleteProductType(final BlockingSphereClient client, final ProductType productType) { try { client.executeBlocking(ProductTypeDeleteCommand.of(productType)); } catch (Exception e) { getLogger("test.fixtures").debug(() -> "no product type to delete"); } }
public static void removeProductTypeByKey(final BlockingSphereClient client, final String productTypeKey) { final ProductType productType = client.executeBlocking(ProductTypeByKeyGet.of(productTypeKey)); if (productType != null) { client.executeBlocking(ProductTypeDeleteCommand.of(productType)); } } }
@After public void tearDown() throws Exception { if (product != null) { client().executeBlocking(ProductDeleteCommand.of(product)); } if (productType != null) { client().executeBlocking(ProductTypeDeleteCommand.of(productType)); } }
@Before @After public void setUp() throws Exception { client().executeBlocking(ProductTypeQuery.of().byName(getName())).getResults().forEach(pt -> client().executeBlocking(ProductTypeDeleteCommand.of(pt))); }
private static void withProductInCategory(final BlockingSphereClient client, final Referenceable<Category> category, final Consumer<Product> user) { final ProductType productType = client.executeBlocking(ProductTypeCreateCommand.of(ProductTypeDraft.of(randomKey(), CategoryDocumentationIntegrationTest.class.getSimpleName(), "", asList()))); final LocalizedString name = LocalizedString.of(ENGLISH, "foo"); final Product product = client.executeBlocking(ProductCreateCommand.of(ProductDraftBuilder.of(productType, name, name.slugifiedUnique(), ProductVariantDraftBuilder.of().build()).categories(asSet(category.toReference())).build())); user.accept(product); client.executeBlocking(ProductDeleteCommand.of(product)); client.executeBlocking(ProductTypeDeleteCommand.of(productType)); }
public static void withUpdateableProductType(final BlockingSphereClient client, final Supplier<ProductTypeDraft> creator, final UnaryOperator<ProductType> user) { final SphereInternalLogger logger = SphereInternalLogger.getLogger("product-types.fixtures"); final ProductTypeDraft productTypeDraft = creator.get(); final String name = productTypeDraft.getName(); final PagedQueryResult<ProductType> queryResult = client.executeBlocking(ProductTypeQuery.of().byName(name)); queryResult.getResults().forEach(productType -> { final PagedQueryResult<Product> pagedQueryResult = client.executeBlocking(ProductQuery.of().byProductType(productType)); delete(client, pagedQueryResult.getResults()); client.executeBlocking(ProductTypeDeleteCommand.of(productType)); }); final ProductType productType = client.executeBlocking(ProductTypeCreateCommand.of(productTypeDraft)); logger.debug(() -> "created product type " + productType.getName() + " " + productType.getId()); final ProductType updated = user.apply(productType); logger.debug(() -> "attempt to delete product type " + productType.getName() + " " + productType.getId()); try { client.executeBlocking(ProductTypeDeleteCommand.of(updated)); } catch (final Exception e) { final PagedQueryResult<Product> pagedQueryResult = client.executeBlocking(ProductQuery.of().byProductType(productType)); delete(client, pagedQueryResult.getResults()); client.executeBlocking(ProductTypeDeleteCommand.of(productType)); } }
@AfterClass @BeforeClass public static void deleteProductsAndProductType() { final List<ProductType> productTypes = client().executeBlocking(ProductTypeQuery.of().byName(PRODUCT_TYPE_NAME)).getResults(); if (!productTypes.isEmpty()) { final ProductQuery productQuery = ProductQuery.of() .withPredicates(m -> m.productType().isIn(productTypes)) .withLimit(500L); client().executeBlocking(productQuery).getResults().forEach(p -> client().executeBlocking(ProductDeleteCommand.of(p))); productTypes.forEach(p -> client().executeBlocking(ProductTypeDeleteCommand.of(p))); } }
@Test public void execution() throws Exception { final ProductType productType = client().executeBlocking(ProductTypeCreateCommand.of(getDraft())); client().executeBlocking(ProductTypeDeleteCommand.of(productType)); final Query<ProductType> query = ProductTypeQuery.of() .withPredicates(m -> m.id().is(productType.getId())); assertThat(client().executeBlocking(query).head()).isEmpty(); }