public final class AddShippingRate extends UpdateActionImpl<ShippingMethod>
See also ShippingMethodUpdateCommand.
withZone(client(), zone -> {
withUpdateableShippingMethod(client(), shippingMethod -> {
final long count = shippingMethod.getZones().stream().filter(z -> z.hasSameIdAs(zone)).count();
assertThat(count).overridingErrorMessage("zone is not used yet").isEqualTo(0);
//addZone
final ShippingMethod shippingMethodWithZone = client().executeBlocking(ShippingMethodUpdateCommand.of(shippingMethod, AddZone.of(zone)));
final ZoneRate zoneRate = shippingMethodWithZone.getZoneRates().stream()
.filter(rate -> rate.getZone().hasSameIdAs(zone))
.findFirst()
.get();
assertThat(zoneRate.getShippingRates()).isEmpty();
//addShippingRate
final ShippingRate shippingRate = ShippingRate.of(MoneyImpl.of(30, USD),null, Collections.EMPTY_LIST);
final ShippingMethod shippingMethodWithShippingRate =
client().executeBlocking(ShippingMethodUpdateCommand.of(shippingMethodWithZone, AddShippingRate.of(shippingRate, zone)));
assertThat(shippingMethodWithShippingRate.getShippingRatesForZone(zone)).isEqualTo(asList(shippingRate));
//check reference expansion
final ShippingMethodByIdGet shippingMethodByIdGet = ShippingMethodByIdGet.of(shippingMethod)
.plusExpansionPaths(m -> m.zoneRates().zone());
final ShippingMethod loadedShippingMethod = client().executeBlocking(shippingMethodByIdGet);
assertThat(loadedShippingMethod.getZoneRates().get(0).getZone().getObj()).isNotNull();
assertThat(loadedShippingMethod.getZones().get(0).getObj())
.overridingErrorMessage("the convenience method also has expanded references").isNotNull();
//removeShippingRate
final ShippingMethod shippingMethodWithoutShippingRate =
client().executeBlocking(ShippingMethodUpdateCommand.of(shippingMethodWithShippingRate, RemoveShippingRate.of(shippingRate, zone)));
assertThat(shippingMethodWithoutShippingRate.getShippingRatesForZone(zone)).isEmpty();
//removeZone
final ShippingMethod shippingMethodWithoutZone =
client().executeBlocking(ShippingMethodUpdateCommand.of(shippingMethodWithoutShippingRate, RemoveZone.of(zone.toResourceIdentifier())));
assertThat(shippingMethodWithoutZone.getZoneRates()).isEqualTo(shippingMethod.getZoneRates());
return shippingMethodWithoutZone;
});
}, CountryCode.EA);
See the test code.
Modifier and Type | Method and Description |
---|---|
ShippingRate |
getShippingRate() |
ResourceIdentifier<Zone> |
getZone() |
static AddShippingRate |
of(ShippingRate shippingRate,
Referenceable<Zone> zone) |
getAction
public ShippingRate getShippingRate()
public ResourceIdentifier<Zone> getZone()
public static AddShippingRate of(ShippingRate shippingRate, Referenceable<Zone> zone)