提交
This commit is contained in:
+71
@@ -0,0 +1,71 @@
|
||||
package com.baiyue.lastleg.inboundplan.pda.service;
|
||||
|
||||
import com.baiyue.common.event.EventEnvelope;
|
||||
import com.baiyue.common.event.EventTypes;
|
||||
import com.baiyue.common.event.RegionCode;
|
||||
import com.baiyue.lastleg.entity.LastlegEventOutbox;
|
||||
import com.baiyue.lastleg.entity.LastlegOrder;
|
||||
import com.baiyue.lastleg.inboundplan.entity.InboundPlan;
|
||||
import com.baiyue.lastleg.inboundplan.pda.entity.InboundPdaTask;
|
||||
import com.baiyue.lastleg.mapper.LastlegEventOutboxMapper;
|
||||
import com.baiyue.lastleg.mapper.LastlegOrderMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class InboundUnloadCompletedOutboxServiceTest {
|
||||
@Mock LastlegEventOutboxMapper outbox;
|
||||
@Mock LastlegOrderMapper orders;
|
||||
private final ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules();
|
||||
private InboundUnloadCompletedOutboxService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new InboundUnloadCompletedOutboxService();
|
||||
ReflectionTestUtils.setField(service, "mapper", outbox);
|
||||
ReflectionTestUtils.setField(service, "orders", orders);
|
||||
ReflectionTestUtils.setField(service, "objectMapper", objectMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void writesAValidOverseasToCnEnvelopeUsingTheSourceBookingId() throws Exception {
|
||||
InboundPlan plan = new InboundPlan(); plan.setSourceOrderId(11L); plan.setContainerNo("MSCU1");
|
||||
InboundPdaTask task = new InboundPdaTask(); task.setId(22L); task.setCustomerId("100");
|
||||
task.setUnloadPhotoUploadedAt(LocalDateTime.of(2026, 8, 20, 10, 0)); task.setVersion(3);
|
||||
LastlegOrder order = new LastlegOrder(); order.setSourceContainerBookingId("9001");
|
||||
when(orders.selectById(11L)).thenReturn(order);
|
||||
|
||||
service.publish(plan, task, List.of(101L));
|
||||
|
||||
ArgumentCaptor<LastlegEventOutbox> saved = ArgumentCaptor.forClass(LastlegEventOutbox.class);
|
||||
verify(outbox).insert(saved.capture());
|
||||
EventEnvelope envelope = objectMapper.readValue(saved.getValue().getPayloadJson(), EventEnvelope.class);
|
||||
assertEquals(EventTypes.OVERSEAS_CONTAINER_UNLOADED, envelope.eventType());
|
||||
assertEquals(RegionCode.OVERSEAS, envelope.sourceRegion());
|
||||
assertEquals(RegionCode.CN, envelope.targetRegion());
|
||||
assertEquals("9001", envelope.aggregateId());
|
||||
assertEquals("MSCU1", envelope.payload().path("containerNo").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsPlansWhoseSourceOrderLostTheContainerBookingId() {
|
||||
InboundPlan plan = new InboundPlan(); plan.setSourceOrderId(11L);
|
||||
InboundPdaTask task = new InboundPdaTask(); task.setId(22L); task.setCustomerId("100");
|
||||
when(orders.selectById(11L)).thenReturn(new LastlegOrder());
|
||||
assertThrows(IllegalStateException.class, () -> service.publish(plan, task, List.of(101L)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user