public final class RemoveZone 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 |
---|---|
ResourceIdentifier<Zone> |
getZone() |
static RemoveZone |
of(ResourceIdentifier<Zone> zone) |
static RemoveZone |
ofReferencable(Referenceable<Zone> zone)
Deprecated.
|
getAction
public ResourceIdentifier<Zone> getZone()
@Deprecated public static RemoveZone ofReferencable(Referenceable<Zone> zone)
of(ResourceIdentifier)
public static RemoveZone of(ResourceIdentifier<Zone> zone)