public Reference<T> filled(final T obj) { return filled(Optional.ofNullable(obj)); }
public Reference<T> filled(final T obj) { return filled(Optional.ofNullable(obj)); }
private SetCustomerGroup(final Optional<Reference<CustomerGroup>> customerGroup) { super("setCustomerGroup"); this.customerGroup = customerGroup.map(e -> e.filled(Optional.empty())); }
private SetCustomerGroup(final Referenceable<CustomerGroup> customerGroup) { super("setCustomerGroup"); this.customerGroup = Optional.ofNullable(customerGroup) .map(x -> x.toReference().filled(null)) .orElse(null); }
private SetCustomerGroup(final Referenceable<CustomerGroup> customerGroup) { super("setCustomerGroup"); this.customerGroup = Optional.ofNullable(customerGroup) .map(x -> x.toReference().filled(null)) .orElse(null); }
public static <T> Reference<T> of(final String typeId, final String id, T obj) { return Reference.<T>of(typeId, id).filled(obj); }
private ChangeParent(final Referenceable<Category> parent) { super("changeParent"); this.parent = parent.toReference().filled(null); }
private SetCustomerGroup(final Referenceable<CustomerGroup> customerGroup) { super("setCustomerGroup"); this.customerGroup = Optional.ofNullable(customerGroup) .map(x -> x.toReference().filled(null)) .orElse(null); }
private ChangeParent(final Referenceable<Category> parent) { super("changeParent"); this.parent = parent.toReference().filled(Optional.empty()); }
private ChangeParent(final Referenceable<Category> parent) { super("changeParent"); this.parent = parent.toReference().filled(Optional.empty()); }
public static <T> Reference<T> of(final String typeId, final String id, T obj) { return Reference.<T>of(typeId, id).filled(obj); }
@Override public JsonNode serialize(final T t) { return mapper().valueToTree(t.toReference().filled(null)); } }
@Override public JsonNode serialize(final T t) { return mapper().valueToTree(t.toReference().filled(Optional.empty())); } }
@Override public JsonNode serialize(final T t) { return mapper().valueToTree(t.toReference().filled(Optional.empty())); } }
@Override public JsonNode serialize(final T t) { return mapper().valueToTree(t.toReference().filled(null)); } }
@Override public JsonNode serialize(final T t) { return mapper().valueToTree(t.toReference().filled(null)); } }
private Reference<TestEntity> newFilledReference() { return newEmptyReference().filled(new TestEntity("value")); }
@Test public void implementEquals() throws Exception { assertThat(newFilledReference()).isEqualTo(newFilledReference()); assertThat(newEmptyReference()).isEqualTo(newEmptyReference()); assertThat(newFilledReference()).isEqualTo(newEmptyReference()); assertThat(newFilledReference()).isEqualTo(newEmptyReference().filled(new TestEntity("other value"))); assertThat(Reference.<String>of(typeId, "Foo", "x")).isNotEqualTo(newEmptyReference()); assertThat(Reference.<String>ofResourceTypeIdAndIdAndObj(typeId, "Foo", "x")).isNotEqualTo(newEmptyReference()); }
@Test public void attributeShouldKeepExpansions() throws Exception { final AttributeAccess<Reference<Product>> access = AttributeAccess.ofProductReference(); final NamedAttributeAccess<Reference<Product>> namedAccess = access.ofName("foo"); assertThat(EXPANDED_PRODUCT_REFERENCE.getObj()).overridingErrorMessage("product reference is expanded").isNotNull(); final Attribute attribute = Attribute.of(namedAccess, EXPANDED_PRODUCT_REFERENCE); assertThat(attribute.getValue(access).getObj()).isNotNull(); final String jsonFilledRef = SphereJsonUtils.toJsonString(EXPANDED_PRODUCT_REFERENCE); final String jsonEmptyRef = SphereJsonUtils.toJsonString(EXPANDED_PRODUCT_REFERENCE.filled(null)); assertThat(jsonFilledRef) .overridingErrorMessage("references are not expanded if serialized") .doesNotContain(EXPANDED_PRODUCT_REFERENCE.getObj().getMasterData().getStaged().getName().get(Locale.ENGLISH)) .isEqualTo(jsonEmptyRef); }
@Test public void productReferenceAttribute() throws Exception { withEmptyProductType(client(), "productReferenceAttribute-testcase", productType -> { final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of().build(); final ProductDraft productDraft = ProductDraftBuilder.of(productType, LABEL, SphereTestUtils.randomSlug(), masterVariant).build(); final Product product = client().executeBlocking(ProductCreateCommand.of(productDraft)); testSingleAndSet(AttributeAccess.ofProductReference(), AttributeAccess.ofProductReferenceSet(), asSet(product.toReference().filled(null)), ReferenceAttributeType.ofProduct(), AttributeDefinitionBuilder.of("productReference", LABEL, ReferenceAttributeType.ofProduct()).build()); }); }