Tabnine Logo
SphereTestUtils
Code IndexAdd Tabnine to your IDE (free)

How to use
SphereTestUtils
in
io.sphere.sdk.test

Best Java code snippets using io.sphere.sdk.test.SphereTestUtils (Showing top 20 results out of 315)

origin: commercetools/commercetools-jvm-sdk

public static void withUpdateableShoppingList(final BlockingSphereClient client, final Function<ShoppingList, ShoppingList> f){
  final ShoppingListDraft draft = newShoppingListDraftBuilder()
      .name(en(randomString()))
      .description(en(randomString()))
      .key(randomKey())
      .slug(randomSlug()).build();
  final ShoppingList shoppingList = client.executeBlocking(ShoppingListCreateCommand.of(draft));
  final ShoppingList possiblyUpdatedShoppingList = f.apply(shoppingList);
  client.executeBlocking(ShoppingListDeleteCommand.of(possiblyUpdatedShoppingList));
}
origin: io.sphere.sdk.jvm/sphere-test-lib

  public static void assertEventually(final Runnable block) {
    final Duration maxWaitTime = Duration.ofSeconds(30);
    final Duration waitBeforeRetry = Duration.ofMillis(100);
    assertEventually(maxWaitTime, waitBeforeRetry, block);
  }
}
origin: io.sphere.sdk.jvm/sphere-test-lib

public static final ZonedDateTime tomorrowZonedDateTime() {
  return now().plus(1, ChronoUnit.DAYS);
}
origin: commercetools/commercetools-jvm-sdk

private static FieldDefinition localizedEnumFieldDefinition() {
  final List<LocalizedEnumValue> localizedEnumValues = asList("1", "2").stream()
      .map(s -> LocalizedEnumValue.of("key" + s, en("label " + s)))
      .collect(toList());
  return fieldDefinition(LocalizedEnumFieldType.of(localizedEnumValues), LOCALIZED_ENUM_FIELD_NAME);
}
origin: commercetools/commercetools-jvm-sdk

public static ShoppingListDraftDsl newShoppingListDraftWithTextLineItems() {
  final List<TextLineItemDraft> textLineItemDrafts = asList(
      TextLineItemDraftBuilder.of(en(randomString()), 1L).build(),
      TextLineItemDraftBuilder.of(en(randomString()), 2L).build(),
      TextLineItemDraftBuilder.of(en(randomString()), 3L).build());
  final ShoppingListDraftDsl shoppingListDraft = newShoppingListDraftBuilder().textLineItems(textLineItemDrafts).build();
  return shoppingListDraft;
}
public static ShoppingListDraftDsl newShoppingListDraftWithLineItems(final Product product) {
origin: commercetools/commercetools-jvm-sdk

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)));
}
origin: commercetools/commercetools-jvm-sdk

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));
}
origin: io.sphere.sdk.jvm/test-lib

public static MetaAttributes randomMetaAttributes() {
  final String metaTitle = "meta title" + randomString();
  final String metaDescription = "meta description" + randomString();
  final String metaKeywords = "meta keywords," + randomString();
  return MetaAttributes.metaAttributesOf(ENGLISH, metaTitle, metaDescription, metaKeywords);
}
origin: commercetools/commercetools-jvm-sdk

@BeforeClass
public static void createBookProductType() throws Exception {
  final AttributeDefinition isbn = AttributeDefinitionBuilder
      .of(ISBN_ATTR_NAME, en("ISBN"), StringAttributeType.of())
      .build();
  final ProductTypeDraft productTypeDraft = ProductTypeDraft.of(randomKey(), BOOK_PRODUCT_TYPE_NAME, "books", asList(isbn));
  final ProductType productType = client().executeBlocking(ProductTypeCreateCommand.of(productTypeDraft));
}
origin: commercetools/commercetools-jvm-sdk

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)));
}
origin: commercetools/commercetools-jvm-sdk

final Reference<TaxCategory> taxCategoryRef = taxCategory.toReference();
final Reference<ShippingMethod> shippingMethodRef = shippingMethod.toReference();
final ZonedDateTime createdAt = SphereTestUtils.now().minusSeconds(4);
final ParcelMeasurements parcelMeasurements = ParcelMeasurements.of(2, 3, 1, 3);
final LineItemLike lineItem = new LineItemLike() {
final TrackingData trackingData = TrackingData.of().withTrackingId("tracking id")
    .withCarrier("carrier").withProvider("provider").withProviderTransaction("prov transaction").withIsReturn(true);
final Parcel parcel = Parcel.of(createdAt, randomUUID(),asList(), parcelMeasurements, trackingData);
final List<Delivery> deliveries = asList(Delivery.of(deliveryId, createdAt, asList(deliveryItem), asList(parcel)));
final ShippingInfoImportDraft shippingInfo = ShippingInfoImportDraftBuilder.of(randomString(), price, shippingRate, taxRate, taxCategoryRef, shippingMethodRef,ShippingMethodState.DOES_NOT_MATCH_CART, deliveries).build();
testOrderAspect(
    builder -> builder.shippingInfo(shippingInfo),
origin: io.sphere.sdk.jvm/sphere-test-lib

public static String randomSortOrder() {
  final int append = 5;//hack to not have a trailing 0 which is not accepted in sphere
  return  "0." + randomInt() + append;
}
origin: commercetools/commercetools-jvm-sdk

  @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));
  }
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void setDescription() throws Exception {
  withUpdateableShoppingList(client(), shoppingList -> {
    final LocalizedString newDescription = en(randomString());
    final ShoppingList updatedShoppingList = client().executeBlocking(
        ShoppingListUpdateCommand.of(shoppingList, SetDescription.of(newDescription)));
    assertThat(updatedShoppingList.getDescription()).isEqualTo(newDescription);
    return updatedShoppingList;
  });
}
origin: commercetools/commercetools-jvm-sdk

  @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();
  }
}
origin: commercetools/commercetools-jvm-sdk

public static void withUpdateableShippingMethod(final BlockingSphereClient client, final UnaryOperator<ShippingMethodDraftBuilder> builderMapper, final Function<ShippingMethod, ShippingMethod> f) {
  withTaxCategory(client, taxCategory -> {
    final ShippingMethodDraftBuilder builder = ShippingMethodDraftBuilder.of(randomString(), "test shipping method", taxCategory.toReference(), asList(), false);
    final ShippingMethodDraft draft = builderMapper.apply(builder).build();
    final ShippingMethod shippingMethod = client.executeBlocking(ShippingMethodCreateCommand.of(draft));
    final ShippingMethod possiblyUpdatedShippingMethod = f.apply(shippingMethod);
    client.executeBlocking(ShippingMethodDeleteCommand.of(possiblyUpdatedShippingMethod));
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void execution() throws Exception {
  final ZonedDateTime validFrom = SphereTestUtils.now();
  final ZonedDateTime validUntil = validFrom.plusSeconds(8000);
  final LocalizedString name = en("discount name");
  final LocalizedString description = en("discount descriptions");
  final String predicate = "totalPrice > \"800.00 EUR\"";
  final AbsoluteCartDiscountValue value = CartDiscountValue.ofAbsolute(MoneyImpl.of(10, EUR));
origin: commercetools/commercetools-jvm-sdk

  private static void testProductIds(final SortExpression<ProductProjection> sortExpr,
                    final Consumer<List<String>> test) {
    final ProductProjectionSearch search = ProductProjectionSearch.ofStaged().withSort(sortExpr);
    final List<ProductProjection> results = executeSearch(search).getResults();
    assertEventually(() -> {
      test.accept(toIds(results));
    });
  }
}
origin: commercetools/commercetools-jvm-sdk

private static void withFilledImportedOrderDraftBuilder(final BlockingSphereClient client, final Consumer<OrderImportDraftBuilder> operator) {
  withTransientTaxCategory(client, taxCategory -> {
    final MonetaryAmount lineItemPrice = MoneyImpl.ofCents(randomInt(), EUR);
    final CustomLineItemImportDraft customLineItemImportDraft = CustomLineItemImportDraftBuilder.of(randomSlug(), 1, lineItemPrice, taxCategory).build();
    final OrderImportDraftBuilder builder = OrderImportDraftBuilder.ofCustomLineItems(lineItemPrice, OrderState.OPEN, singletonList(customLineItemImportDraft));
    operator.accept(builder);
  });
}
origin: commercetools/commercetools-jvm-sdk

  public static CustomLineItemDraft createCustomLineItemDraft(final TaxCategory taxCategory) {
    final MonetaryAmount money = MoneyImpl.of(new BigDecimal("23.50"), EUR);
    return CustomLineItemDraft.of(en("thing"), "thing-slug", money, taxCategory, 5L, null);
  }
}
io.sphere.sdk.testSphereTestUtils

Most used methods

  • randomKey
  • randomString
  • assertEventually
  • now
  • randomInt
  • en
  • jsonNodeFromResource
  • stringFromResource
  • asList
  • consumerToFunction
  • draftFromJsonResource
  • englishSlugOf
  • draftFromJsonResource,
  • englishSlugOf,
  • firstOf,
  • oneOf,
  • randomEmail,
  • randomLocalizedString,
  • randomLong,
  • randomMetaAttributes,
  • randomSlug,
  • randomSortOrder

Popular in Java

  • Running tasks concurrently on multiple threads
  • onCreateOptionsMenu (Activity)
  • setRequestProperty (URLConnection)
  • addToBackStack (FragmentTransaction)
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now