public static void withUpdateableState(final BlockingSphereClient client, final Function<State, State> f) { final State state = createStateByKey(client, randomKey()); final State updatedState = f.apply(state); client.executeBlocking(StateDeleteCommand.of(updatedState)); }
@Test public void firstNumberIsOne() throws Exception { final String key = randomKey();//this could be something like "orderNumber" final CustomObjectBigIntegerNumberGeneratorConfig config = CustomObjectBigIntegerNumberGeneratorConfigBuilder.of(client(), key) .build(); final BigIntegerNumberGenerator generator = CustomObjectBigIntegerNumberGenerator.of(config); final BigInteger firstNumber = generator.getNextNumber().toCompletableFuture().join(); assertThat(firstNumber).isEqualTo(BigInteger.ONE); }
private static AssetDraft getAssetDraft2() { final AssetSource assetSource1 = AssetSourceBuilder.ofUri("http://dev.commercetools.com/assets/img/CT-logo.svg") .key(randomKey()) .contentType("image/svg+xml") .build(); final LocalizedString name = LocalizedString.ofEnglish("commercetools logo"); return AssetDraftBuilder.of(singletonList(assetSource1), name) .tags("desktop-sized", "svg-format", "commercetools", "awesome") .key(randomKey()) .build(); } }
public static void withCustomerGroup(final BlockingSphereClient client, final UnaryOperator<CustomerGroup> consumer) { final String name = randomString(); final String key = randomKey(); final CustomerGroupDraft customerGroupDraft = CustomerGroupDraft.of(name,key); final CustomerGroup customerGroup = client.executeBlocking(CustomerGroupCreateCommand.of(customerGroupDraft)); final CustomerGroup updatedCustomerGroup = consumer.apply(customerGroup); final Optional<CustomerGroup> customerGroupOptional = Optional.ofNullable(client.executeBlocking(CustomerGroupByIdGet.of(updatedCustomerGroup.getId()))); customerGroupOptional.ifPresent(group -> client.executeBlocking(CustomerGroupDeleteCommand.of(updatedCustomerGroup))); }
@Test public void setAuthorName() { withUpdateableReview(client(), (Review review) -> { final String authorName = randomKey(); final Review updatedReview = client().executeBlocking(ReviewUpdateCommand.of(review, SetAuthorName.of(authorName))); assertThat(updatedReview.getAuthorName()).isEqualTo(authorName); return updatedReview; }); }
@Test public void setText() { withUpdateableReview(client(), (Review review) -> { final String text = randomKey(); final Review updatedReview = client().executeBlocking(ReviewUpdateCommand.of(review, SetText.of(text))); assertThat(updatedReview.getText()).isEqualTo(text); return updatedReview; }); }
@Test public void changeKey() throws Exception { withUpdateableState(client(), state -> { final String newKey = randomKey(); final StateUpdateCommand command = StateUpdateCommand.of(state, ChangeKey.of(newKey)); final State updatedState = client().executeBlocking(command); assertThat(updatedState.getKey()).isEqualTo(newKey); return updatedState; }); }
@Test public void setKey() throws Exception { final String key = randomKey(); withProduct(client(), (Product product) -> { final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, SetKey.of(key))); assertThat(updatedProduct.getKey()).isEqualTo(key); }); }
@Test public void setKey() throws Exception { withUpdateableProductType(client(), productType -> { final String newKey = randomKey(); final ProductType updatedProductType = client().executeBlocking(ProductTypeUpdateCommand.of(productType, SetKey.of(newKey))); assertThat(updatedProductType.getKey()).isEqualTo(newKey); return updatedProductType; }); }
@Test public void setKey() { withCustomer(client(), customer -> { String newKey = randomKey(); assertThat(customer.getKey()).isNotEqualTo(newKey); final Customer updatedCustomer = client().executeBlocking(CustomerUpdateCommand.of(customer, SetKey.of(newKey))); assertThat(updatedCustomer.getKey()).isEqualTo(newKey); }); }
@Test public void execution() throws Exception { final Set<CountryCode> euAndSwissCountries = asSet(AT, BE, CH);//not complete, but you get the idea final String key = randomKey(); final Set<Location> locations = euAndSwissCountries.stream().map(country -> Location.of(country)).collect(toSet()); final ZoneDraft draft = ZoneDraftBuilder.of("zone1",locations ).description("EU and Swiss").key(key).build(); final ZoneCreateCommand createCommand = ZoneCreateCommand.of(draft); final Zone zone = client().executeBlocking(createCommand); assertThat(zone.getKey()).isEqualTo(key); //end example parsing here client().executeBlocking(ZoneDeleteCommand.ofKey(zone.getKey(),zone.getVersion())); }
public void setProductVariantKeyByVariantIdWithStaged(final Boolean staged) { final String key = randomKey(); withProduct(client(), (Product product) -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Integer variantId = product.getMasterData().getStaged().getMasterVariant().getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetProductVariantKey.ofKeyAndVariantId(key, variantId, staged)); final Product updatedProduct = client().executeBlocking(cmd); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getKey()).isEqualTo(key); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); }); }
@Test public void changeNameByKeyUpdate() throws Exception { withUpdateableProductType(client(), productType -> { final String name = randomKey(); final ProductType updatedProductType = client().executeBlocking(ProductTypeUpdateCommand.ofKey(productType.getKey(), productType.getVersion(), ChangeName.of(name))); assertThat(updatedProductType.getName()).isEqualTo(name); return updatedProductType; }); }
public static ReviewDraftBuilder createReviewDraftBuilder() { return ReviewDraftBuilder.ofTitle(REVIEW_TITLE) .authorName(AUTHOR_NAME) .text(REVIEW_TEXT) .rating(100) .locale(Locale.ENGLISH) .key(randomKey()); }
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 ProductType productReferenceProductType(final BlockingSphereClient client) { final AttributeDefinition productReferenceDefinition = AttributeDefinitionBuilder .of("productreference", en("suggested product"), ReferenceAttributeType.ofProduct()) .required(true) .build(); final ProductTypeDraft productTypeDraft = ProductTypeDraft.of(randomKey(), productReferenceProductTypeName, "has an attribute which is reference to a product", asList(productReferenceDefinition)); final Optional<ProductType> productTypeOptional = client.executeBlocking(ProductTypeQuery.of().byName(productReferenceProductTypeName)).head(); return productTypeOptional.orElseGet(() -> client.executeBlocking(ProductTypeCreateCommand.of(productTypeDraft))); }
private ProductTypeDraft createBanana(Referenceable<ProductType> nutrientType) { return ProductTypeDraft.of(randomKey(), "Banana", "Banana", asList( AttributeDefinitionBuilder.of(Banana.bananaColor.getName(), en(Banana.bananaColor.getName()), StringAttributeType.of()).build(), AttributeDefinitionBuilder.of(Banana.nutrients.getName(), en(Banana.nutrients.getName()), SetAttributeType.of(NestedAttributeType.of(nutrientType))).searchable(false).build())); } }
@Test public void referenceExpansionForDeletionByKey() throws Exception { final String key = randomKey(); final Category parent = client().executeBlocking(CategoryCreateCommand.of(CategoryDraftBuilder.of(randomLocalizedString(), randomSlug()).build())); final Category category = client().executeBlocking(CategoryCreateCommand.of(CategoryDraftBuilder.of(randomLocalizedString(), randomSlug()).key(key).parent(parent).build())); final CategoryDeleteCommand deleteCommand = CategoryDeleteCommand.ofKey(key, category.getVersion()).plusExpansionPaths(m -> m.parent()); final Category deletedCategory = client().executeBlocking(deleteCommand); assertThat(deletedCategory.getParent().getObj()).isNotNull().isEqualTo(parent); client().executeBlocking(CategoryDeleteCommand.of(parent)); } }
@Test public void deleteByKey() { final ResourceTypeIdsSetBuilder idsSetBuilder = ResourceTypeIdsSetBuilder.of().addCustomers(); final TypeDraft draft = TypeDraftBuilder.of(randomKey(), randomSlug(), idsSetBuilder) .build(); final Type type = client().executeBlocking(TypeCreateCommand.of(draft)); final String key = type.getKey(); final Long version = type.getVersion(); client().executeBlocking(TypeDeleteCommand.ofKey(key, version)); assertThat(client().executeBlocking(TypeByIdGet.of(type))).isNull(); } }
private ProductTypeDraft createNutrient(final Referenceable<ProductType> nutrientInformationType) { return ProductTypeDraft.of(randomKey(), "Nutrient", "Nutrient", asList( AttributeDefinitionBuilder.of(Nutrient.servingSizeUOM.getName(), en(Nutrient.servingSizeUOM.getName()), StringAttributeType.of()).build(), AttributeDefinitionBuilder.of(Nutrient.servingSize.getName(), en(Nutrient.servingSize.getName()), NumberAttributeType.of()).build(), AttributeDefinitionBuilder.of(Nutrient.nutrientInformation.getName(), en(Nutrient.nutrientInformation.getName()), SetAttributeType.of(NestedAttributeType.of(nutrientInformationType))).searchable(false).build())); }