Skip to content

Commit

Permalink
Merge pull request #2188 from commercetools/support-14178
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude authored Nov 11, 2021
2 parents 9cf379e + f9993e3 commit 9c77fad
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@
</ul>
-->
-->
<h3 class=released-version id="v2_5_0">2.5.0 (01.12.2021)</h3>
<ul>
<li class=fixed-in-release>Fixed serialization issue with duplicate type property in ShippingRateTier model</li>
</ul>
<h3 class=released-version id="v2_4_0">2.4.0 (01.11.2021)</h3>
<ul>
<li class=change-in-release> Add deprecation announcement</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.sphere.sdk.shippingmethods;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import javax.annotation.Nullable;
import javax.money.MonetaryAmount;
Expand All @@ -19,6 +18,7 @@
@JsonSubTypes.Type(value = CartClassificationImpl.class, name = "CartClassification"),
@JsonSubTypes.Type(value = CartScoreImpl.class, name = "CartScore")
})
@JsonIgnoreProperties(value = {"type"})
public interface ShippingRatePriceTier{

String getType();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package io.sphere.sdk.orders;

import io.sphere.sdk.carts.Cart;
import io.sphere.sdk.json.SphereJsonUtils;
import io.sphere.sdk.shippingmethods.*;
import io.sphere.sdk.utils.MoneyImpl;
import org.assertj.core.api.Assertions;
import org.junit.Test;

Expand All @@ -17,5 +18,39 @@ public void deserializeRefusedGifts(){
assertThat(order.getRefusedGifts().get(0).getId()).isEqualTo("<my-order-discount-id>");
}

@Test
public void serializeCartClassification() {
final ShippingRatePriceTier tier = CartClassificationBuilder.of("small", MoneyImpl.ofCents(100, "EUR")).build();
final String s = SphereJsonUtils.toPrettyJsonString(tier);

Assertions.assertThat(s).containsOnlyOnce("CartClassification");
final ShippingRatePriceTier shippingRatePriceTier = SphereJsonUtils.readObject(s, ShippingRatePriceTier.class);
Assertions.assertThat(shippingRatePriceTier).isInstanceOf(CartClassification.class);
final String t = SphereJsonUtils.toJsonString(shippingRatePriceTier);
Assertions.assertThat(t).containsOnlyOnce("CartClassification");
}

@Test
public void serializeCartScore() {
final ShippingRatePriceTier tier = CartScoreBuilder.of(100L, MoneyImpl.ofCents(100, "EUR")).build();
final String s = SphereJsonUtils.toPrettyJsonString(tier);

Assertions.assertThat(s).containsOnlyOnce("CartScore");
final ShippingRatePriceTier shippingRatePriceTier = SphereJsonUtils.readObject(s, ShippingRatePriceTier.class);
Assertions.assertThat(shippingRatePriceTier).isInstanceOf(CartScore.class);
final String t = SphereJsonUtils.toJsonString(shippingRatePriceTier);
Assertions.assertThat(t).containsOnlyOnce("CartScore");
}

@Test
public void serializeCartValue() {
final ShippingRatePriceTier tier = CartValueBuilder.of(100L, MoneyImpl.ofCents(100, "EUR")).build();
final String s = SphereJsonUtils.toPrettyJsonString(tier);

Assertions.assertThat(s).containsOnlyOnce("CartValue");
final ShippingRatePriceTier shippingRatePriceTier = SphereJsonUtils.readObject(s, ShippingRatePriceTier.class);
Assertions.assertThat(shippingRatePriceTier).isInstanceOf(CartValue.class);
final String t = SphereJsonUtils.toJsonString(shippingRatePriceTier);
Assertions.assertThat(t).containsOnlyOnce("CartValue");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void syncInfo() throws Exception {
order -> client().executeBlocking(OrderUpdateCommand.of(order, UpdateSyncInfo.of(channel).withExternalId(externalId))),
order -> MODEL.syncInfo().channel().is(channel).and(MODEL.syncInfo().externalId().is(externalId)).and(MODEL.syncInfo().isNotEmpty()));
}

@Test
public void queryOrderInStore() {
withStateByBuilder(client(), builder -> builder.type(StateType.ORDER_STATE), state -> {
Expand All @@ -149,11 +149,11 @@ public void queryOrderInStore() {
assertThat(order).isNotNull();
assertThat(order.getStore()).isNotNull();
assertThat(order.getStore().getKey()).isEqualTo(store.getKey());

final OrderInStoreQuery query = OrderInStoreQuery.of(store.getKey()).withPredicates(m -> m.id().is(order.getId()));
final PagedQueryResult<Order> result = client().executeBlocking(query);
assertThat(result.getResults()).isNotEmpty();

client().executeBlocking(OrderDeleteCommand.of(order));
client().executeBlocking(CartDeleteCommand.of(order.getCart().getObj()));
});
Expand Down Expand Up @@ -198,4 +198,4 @@ private void assertOrderIsFoundWithPredicate(final Function<Order, QueryPredicat
private void assertOrderIsNotFoundWithPredicate(final Function<Order, QueryPredicate<Order>> p) {
assertOrderIsFound(order -> OrderQuery.of().withPredicates(p.apply(order)), false);
}
}
}

0 comments on commit 9c77fad

Please sign in to comment.