提交
This commit is contained in:
+71
@@ -0,0 +1,71 @@
|
||||
package com.baiyue.lastleg.delivery;
|
||||
|
||||
import com.baiyue.common.web.LongIdJacksonConfiguration;
|
||||
import com.baiyue.lastleg.delivery.dto.DeliveryRequests;
|
||||
import com.baiyue.lastleg.delivery.dto.DeliveryResponses;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@DisplayName("派送单长整型 ID JSON 契约")
|
||||
class DeliveryLongIdJsonContractTest {
|
||||
|
||||
private static final long DELIVERY_ID = 19_000_000_000_000_001L;
|
||||
private static final long FEE_ID = 19_000_000_000_000_002L;
|
||||
private static final long OPERATION_ID = 19_000_000_000_000_003L;
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
JacksonAutoConfiguration.class, LongIdJacksonConfiguration.class));
|
||||
|
||||
@Test
|
||||
void deliveryResponseIdsShouldBeSerializedAsJsonStrings() {
|
||||
contextRunner.run(context -> {
|
||||
ObjectMapper objectMapper = context.getBean(ObjectMapper.class);
|
||||
DeliveryResponses.DeliveryDetail detail = new DeliveryResponses.DeliveryDetail(
|
||||
deliveryRow(),
|
||||
List.of(),
|
||||
List.of(new DeliveryResponses.DeliveryFeeRow(
|
||||
FEE_ID, "RECEIVABLE", "DELIVERY_FEE", "USD", null, null)),
|
||||
List.of(new DeliveryResponses.DeliveryOperationRow(
|
||||
OPERATION_ID, null, "CREATED", "tester", "success")));
|
||||
|
||||
JsonNode json = objectMapper.readTree(objectMapper.writeValueAsString(detail));
|
||||
|
||||
assertThat(json.at("/order/id").isTextual()).isTrue();
|
||||
assertThat(json.at("/order/id").textValue()).isEqualTo(Long.toString(DELIVERY_ID));
|
||||
assertThat(json.at("/fees/0/id").textValue()).isEqualTo(Long.toString(FEE_ID));
|
||||
assertThat(json.at("/operations/0/id").textValue()).isEqualTo(Long.toString(OPERATION_ID));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void quotedRequestIdShouldBeDeserializedToLong() {
|
||||
contextRunner.run(context -> {
|
||||
ObjectMapper objectMapper = context.getBean(ObjectMapper.class);
|
||||
|
||||
DeliveryRequests.OneClickItem item = objectMapper.readValue(
|
||||
"{\"inventoryPositionId\":\"19000000000000001\",\"packages\":\"2\",\"sku\":\"SKU-1\"}",
|
||||
DeliveryRequests.OneClickItem.class);
|
||||
|
||||
assertThat(item.inventoryPositionId()).isEqualTo(DELIVERY_ID);
|
||||
assertThat(item.packages()).isEqualTo(2L);
|
||||
});
|
||||
}
|
||||
|
||||
private DeliveryResponses.DeliveryRow deliveryRow() {
|
||||
return new DeliveryResponses.DeliveryRow(
|
||||
DELIVERY_ID,
|
||||
null, null, "PS-1", null, null, null, null, "CREATED", null,
|
||||
null, null, null, null, null, null, null, null, null, null, null,
|
||||
0, 0, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
+9
@@ -7,6 +7,8 @@ import com.baiyue.lastleg.delivery.entity.DeliveryOrder;
|
||||
import com.baiyue.lastleg.delivery.entity.OutboundOrder;
|
||||
import com.baiyue.lastleg.delivery.entity.OutboundPalletItem;
|
||||
import com.baiyue.lastleg.delivery.mapper.DeliveryOrderMapper;
|
||||
import com.baiyue.lastleg.delivery.mapper.DeliveryFeeMapper;
|
||||
import com.baiyue.lastleg.delivery.mapper.DeliveryOperationMapper;
|
||||
import com.baiyue.lastleg.delivery.mapper.OutboundOrderMapper;
|
||||
import com.baiyue.lastleg.delivery.mapper.OutboundPalletItemMapper;
|
||||
import com.baiyue.lastleg.dispatch.entity.DispatchItem;
|
||||
@@ -19,6 +21,7 @@ import com.baiyue.lastleg.entity.LastlegOrder;
|
||||
import com.baiyue.lastleg.entity.LastlegOrderStatusHistory;
|
||||
import com.baiyue.lastleg.mapper.LastlegOrderMapper;
|
||||
import com.baiyue.lastleg.mapper.LastlegOrderStatusHistoryMapper;
|
||||
import com.baiyue.lastleg.mapper.LastlegOrderDetailMapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -47,10 +50,13 @@ class DeliveryTransferServiceTest {
|
||||
@Mock OutboundOrderMapper outboundOrders;
|
||||
@Mock OutboundPalletItemMapper outboundPallets;
|
||||
@Mock DeliveryOrderMapper deliveryOrders;
|
||||
@Mock DeliveryFeeMapper deliveryFees;
|
||||
@Mock DeliveryOperationMapper deliveryOperations;
|
||||
@Mock InboundPlanPalletAllocationMapper planAllocations;
|
||||
@Mock InboundPlanLineMapper planLines;
|
||||
@Mock LastlegOrderMapper tailOrders;
|
||||
@Mock LastlegOrderStatusHistoryMapper histories;
|
||||
@Mock LastlegOrderDetailMapper tailOrderDetails;
|
||||
|
||||
private DeliveryTransferService service;
|
||||
|
||||
@@ -62,10 +68,13 @@ class DeliveryTransferServiceTest {
|
||||
ReflectionTestUtils.setField(service, "outboundOrders", outboundOrders);
|
||||
ReflectionTestUtils.setField(service, "outboundPallets", outboundPallets);
|
||||
ReflectionTestUtils.setField(service, "deliveryOrders", deliveryOrders);
|
||||
ReflectionTestUtils.setField(service, "deliveryFees", deliveryFees);
|
||||
ReflectionTestUtils.setField(service, "deliveryOperations", deliveryOperations);
|
||||
ReflectionTestUtils.setField(service, "planAllocations", planAllocations);
|
||||
ReflectionTestUtils.setField(service, "planLines", planLines);
|
||||
ReflectionTestUtils.setField(service, "tailOrders", tailOrders);
|
||||
ReflectionTestUtils.setField(service, "histories", histories);
|
||||
ReflectionTestUtils.setField(service, "tailOrderDetails", tailOrderDetails);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -111,8 +111,8 @@ class LastlegOrderServiceTest {
|
||||
assertEquals("100", fee.getCustomerId());
|
||||
assertEquals("清关费", fee.getFeeItem());
|
||||
assertEquals(new BigDecimal("420.00"), fee.getAmount());
|
||||
verify(fees).insert(any());
|
||||
verify(operations).insert(any());
|
||||
verify(fees).insert(any(com.baiyue.lastleg.entity.LastlegOrderFee.class));
|
||||
verify(operations).insert(any(com.baiyue.lastleg.entity.LastlegOrderOperationLog.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user