Tabnine Logo
EnumValue.of
Code IndexAdd Tabnine to your IDE (free)

How to use
of
method
in
io.sphere.sdk.models.EnumValue

Best Java code snippets using io.sphere.sdk.models.EnumValue.of (Showing top 17 results out of 315)

origin: com.commercetools.sunrise.payment/payone-adapter

  public static List<EnumValue> getValuesAsListOfEnumValue() {
    return EnumSet.allOf(CreditCardNetwork.class)
            .stream()
            .map(p -> EnumValue.of(p.name(), p.getLabel()))
            .collect(Collectors.toList());
  }
}
origin: commercetools/commercetools-jvm-sdk

private static FieldDefinition enumFieldDefinition() {
  final List<EnumValue> enumValues = asList(EnumValue.of("key1", "label1"), EnumValue.of("key2", "label2"));
  return fieldDefinition(EnumFieldType.of(enumValues), ENUM_FIELD_NAME);
}
origin: commercetools/commercetools-jvm-sdk

private static FieldDefinition stateFieldDefinition() {
  final List<EnumValue> values = asList(
      EnumValue.of("published", "the category is publicly visible"),
      EnumValue.of("draft", "the category should not be displayed in the frontend")
  );
  final boolean required = false;
  final LocalizedString label = en("state of the category concerning to show it publicly");
  final String fieldName = "state";
  return FieldDefinition
      .of(EnumFieldType.of(values), fieldName, label, required);
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void queryByName() throws Exception {
  withTShirtProductType(type -> {
    final ProductType productType = client().executeBlocking(ProductTypeQuery.of().byName("t-shirt")).head().get();
    final Optional<AttributeDefinition> sizeAttribute = productType.findAttribute("size");
    final List<EnumValue> possibleSizeValues = sizeAttribute.
        map(attrib -> ((EnumAttributeType) attrib.getAttributeType()).getValues()).
        orElse(Collections.<EnumValue>emptyList());
    final List<EnumValue> expected =
        asList(EnumValue.of("S", "S"), EnumValue.of("M", "M"), EnumValue.of("X", "X"));
    assertThat(possibleSizeValues).isEqualTo(expected);
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void changePlainEnumValueLabel() throws Exception {
  final String attributeName = randomKey();
  final AttributeDefinition attributeDefinition = AttributeDefinitionBuilder.of(attributeName, randomSlug(),
      EnumAttributeType.of(
          EnumValue.of("key1", "label 1"),
          EnumValue.of("key2", "label 2")
      )).build();
  final String key = randomKey();
  final ProductTypeDraft productTypeDraft = ProductTypeDraft.of(key, key, key, singletonList(attributeDefinition));
  withUpdateableProductType(client(), () -> productTypeDraft, productType -> {
    final ProductType updatedProductType = client().executeBlocking(ProductTypeUpdateCommand.of(productType, ChangePlainEnumValueLabel.of(attributeName, EnumValue.of("key2", "label 2 (updated)"))));
    final EnumAttributeType updatedAttributeType = (EnumAttributeType) updatedProductType.getAttribute(attributeName).getAttributeType();
    assertThat(updatedAttributeType.getValues())
        .containsExactly(EnumValue.of("key1", "label 1"), EnumValue.of("key2", "label 2 (updated)"));
    return updatedProductType;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void execution() throws Exception {
  //size attribute stuff
  final EnumValue S = EnumValue.of("S", "S");
  final EnumValue M = EnumValue.of("M", "M");
  final EnumValue X = EnumValue.of("X", "X");
  final List<EnumValue> values = asList(S, M, X);
  final LocalizedString sizeAttributeLabel = LocalizedString.of(ENGLISH, "size").plus(GERMAN, "Größe");
  final AttributeDefinition sizeAttributeDefinition =
      AttributeDefinitionBuilder.of("size", sizeAttributeLabel, EnumAttributeType.of(values))
      .required(true)
      .attributeConstraint(AttributeConstraint.COMBINATION_UNIQUE)
      .inputTip(LocalizedString.ofEnglish("size as enum"))
      .build();
  final String name = getName();
  final ProductTypeDraft productTypeDraft =
      ProductTypeDraft.of(randomKey(), name, "a 'T' shaped cloth", asList(sizeAttributeDefinition));
  final ProductType productType = client().executeBlocking(ProductTypeCreateCommand.of(productTypeDraft));
  assertThat(productType.getName()).isEqualTo(name);
  assertThat(productType.getDescription()).isEqualTo("a 'T' shaped cloth");
  assertThat(productType.getAttributes()).contains(sizeAttributeDefinition);
  assertThat(productType.getAttributes()).hasSize(1);
  assertThat(productType.getAttributes().get(0).getInputTip())
      .isEqualTo(LocalizedString.ofEnglish("size as enum"));
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void readAttributeWithoutProductTypeWithName() throws Exception {
  final ProductVariant masterVariant = createProduct().getMasterData().getStaged().getMasterVariant();
  final Optional<EnumValue> attributeOption =
      masterVariant.findAttribute(SIZE_ATTR_NAME, AttributeAccess.ofEnumValue());
  assertThat(attributeOption).contains(EnumValue.of("S", "S"));
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void addEnumValue() {
  withUpdateableType(client(), type -> {
    final String name = TypeFixtures.ENUM_FIELD_NAME;
    final EnumValue newEnumValue = EnumValue.of("key-new", "label new");
    final Type updatedType = client().executeBlocking(TypeUpdateCommand.of(type, AddEnumValue.of(name, newEnumValue)));
    assertThat(updatedType.getFieldDefinitionByName(name).getType())
        .isInstanceOf(EnumFieldType.class)
        .matches(fieldType -> ((EnumFieldType) fieldType).getValues().contains(newEnumValue), "contains the new enum value");
    return updatedType;
  });
}
origin: commercetools/commercetools-jvm-sdk

public void setAttributeWithObjectsWithStaged(final Boolean staged) {
  withProduct(client(), (Product product) -> {
    assertThat(product.getMasterData().hasStagedChanges()).isFalse();
    final String sku = product.getMasterData().getStaged().getMasterVariant().getSku();
    final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, asList(
        SetAttribute.ofSku(sku, "size", "M", staged),
        SetAttribute.ofVariantId(MASTER_VARIANT_ID, "color", "red", staged)
    )));
    final ProductVariant masterVariant = updatedProduct.getMasterData().getStaged().getMasterVariant();
    assertThat(masterVariant.getAttribute("size").getValueAsEnumValue()).isEqualTo(EnumValue.of("M", "M"));
    assertThat(masterVariant.getAttribute("color").getValueAsLocalizedEnumValue().getKey()).isEqualTo("red");
    assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged);
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void readAttributeWithoutProductTypeWithNamedAccess() throws Exception {
  final NamedAttributeAccess<EnumValue> size = AttributeAccess.ofEnumValue().ofName(SIZE_ATTR_NAME);
  final ProductVariant masterVariant = createProduct().getMasterData().getStaged().getMasterVariant();
  final Optional<EnumValue> attributeOption = masterVariant.findAttribute(size);
  assertThat(attributeOption).contains(EnumValue.of("S", "S"));
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void setAttributeWithObjects() {
  withProduct(client(), (Product product) -> {
    assertThat(product.getMasterData().hasStagedChanges()).isFalse();
    final String sku = product.getMasterData().getStaged().getMasterVariant().getSku();
    final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, asList(
        SetAttribute.ofSku(sku, "size", "M"),
        SetAttribute.ofVariantId(MASTER_VARIANT_ID, "color", "red")
    )));
    final ProductVariant masterVariant = updatedProduct.getMasterData().getStaged().getMasterVariant();
    assertThat(masterVariant.getAttribute("size").getValueAsEnumValue()).isEqualTo(EnumValue.of("M", "M"));
    assertThat(masterVariant.getAttribute("color").getValueAsLocalizedEnumValue().getKey()).isEqualTo("red");
    assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue();
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void addEnumValue() throws Exception {
  withUpdateableProductType(client(), productType -> {
    final String attributeName = "size";
    assertThat(productType.findAttribute(attributeName)).isPresent();
    final EnumValue value = EnumValue.of("XXXL", "XXXL");
    final ProductType updatedProductType = client().executeBlocking(ProductTypeUpdateCommand.of(productType,
        AddEnumValue.of(attributeName, value)));
    assertThat(updatedProductType.getAttribute(attributeName).getAttributeType())
        .isInstanceOf(EnumAttributeType.class)
        .matches(type -> ((EnumAttributeType) type).getValues().contains(value));
    return updatedProductType;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void readAttributeWithoutProductTypeWithJson() throws Exception {
  final ProductVariant masterVariant = createProduct().getMasterData().getStaged().getMasterVariant();
  final Attribute attr = masterVariant.getAttribute(SIZE_ATTR_NAME);
  final JsonNode expectedJsonNode = SphereJsonUtils.toJsonNode(EnumValue.of("S", "S"));
  assertThat(attr.getValue(AttributeAccess.ofJsonNode())).isEqualTo(expectedJsonNode);
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void updateAttributes() throws Exception {
  final Product product = createProduct();
  final int masterVariantId = 1;
  final Function<AttributeDraft, SetAttribute> draft = attrDraft ->
      SetAttribute.of(masterVariantId, attrDraft);
  final List<SetAttribute> updateActions = asList(
      draft.apply(AttributeDraft.of(COLOR_ATTR_NAME, "red")),//don't forget: enum like => use only keys
      draft.apply(AttributeDraft.of(SIZE_ATTR_NAME, "M")),
      draft.apply(AttributeDraft.of(LAUNDRY_SYMBOLS_ATTR_NAME, asSet("cold"))),
      draft.apply(AttributeDraft.of(RRP_ATTR_NAME, MoneyImpl.of(20, EUR)))
  );
  final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, updateActions));
  final ProductVariant masterVariant = updatedProduct.getMasterData().getStaged().getMasterVariant();
  assertThat(masterVariant.findAttribute(COLOR_ATTR_NAME, AttributeAccess.ofLocalizedEnumValue()))
      .contains(LocalizedEnumValue.of("red", LocalizedString.of(ENGLISH, "red").plus(GERMAN, "rot")));
  assertThat(masterVariant.findAttribute(SIZE_ATTR_NAME, AttributeAccess.ofEnumValue()))
      .contains(EnumValue.of("M", "M"));
  final LocalizedEnumValue cold = LocalizedEnumValue.of("cold",
      LocalizedString.of(ENGLISH, "Wash at or below 30°C ").plus(GERMAN, "30°C"));
  assertThat(masterVariant.findAttribute(LAUNDRY_SYMBOLS_ATTR_NAME, AttributeAccess.ofLocalizedEnumValueSet()))
      .contains(asSet(cold));
  assertThat(masterVariant.findAttribute(RRP_ATTR_NAME, AttributeAccess.ofMoney()))
      .contains(MoneyImpl.of(20, EUR));
}
origin: commercetools/commercetools-jvm-sdk

    .contains(LocalizedEnumValue.of("green", LocalizedString.of(ENGLISH, "green").plus(GERMAN, "grün")));
assertThat(masterVariant.findAttribute(SIZE_ATTR_NAME, AttributeAccess.ofEnumValue()))
    .contains(EnumValue.of("S", "S"));
final LocalizedEnumValue cold = LocalizedEnumValue.of("cold",
    LocalizedString.of(ENGLISH, "Wash at or below 30°C ").plus(GERMAN, "30°C"));
origin: commercetools/commercetools-jvm-sdk

    .plusAttribute(size, EnumValue.of("S", "S"))
assertThat(masterVariant.findAttribute(color))
    .contains(LocalizedEnumValue.of("green", LocalizedString.of(ENGLISH, "green").plus(GERMAN, "grün")));
assertThat(masterVariant.findAttribute(size)).contains(EnumValue.of("S", "S"));
assertThat(masterVariant.findAttribute(laundrySymbols)).contains(asSet(cold, tumbleDrying));
assertThat(masterVariant.findAttribute(matchingProducts)).contains(asSet(productReference));
origin: commercetools/commercetools-jvm-sdk

    .build();
final EnumValue s = EnumValue.of("S", "S");
final EnumValue m = EnumValue.of("M", "M");
final EnumValue x = EnumValue.of("X", "X");
final AttributeDefinition size = AttributeDefinitionBuilder
    .of(SIZE_ATTR_NAME, en("size"), EnumAttributeType.of(s, m, x))
io.sphere.sdk.modelsEnumValueof

Popular methods of EnumValue

  • getLabel
  • getKey
  • typeReference

Popular in Java

  • Updating database using SQL prepared statement
  • scheduleAtFixedRate (Timer)
  • startActivity (Activity)
  • onCreateOptionsMenu (Activity)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
  • 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