fix: return A0404 for missing PDA pallets

This commit is contained in:
2026-09-04 14:07:18 +08:00
parent f6247ce232
commit 3399ae7488
13 changed files with 205 additions and 7 deletions
@@ -0,0 +1,40 @@
package com.baiyue.lastleg.palletops.gateway;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.RestClient;
import org.springframework.web.server.ResponseStatusException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
class HttpPalletPhysicalGatewayTest {
private HttpPalletPhysicalGateway gateway;
private MockRestServiceServer server;
@BeforeEach
void setUp() {
RestClient.Builder builder = RestClient.builder();
server = MockRestServiceServer.bindTo(builder).build();
gateway = new HttpPalletPhysicalGateway();
ReflectionTestUtils.setField(gateway, "client", builder.baseUrl("http://warehouse").build());
ReflectionTestUtils.setField(gateway, "internalToken", "test-token");
}
@Test
void resolveMapsBusinessNotFoundEnvelopeToStableNotFound() {
server.expect(requestTo("http://warehouse/internal/v1/warehouse-pallets/resolve/MISSING"))
.andRespond(withSuccess("""
{"code":"A0404","message":"Not found","data":null}
""", MediaType.APPLICATION_JSON));
assertThatThrownBy(() -> gateway.resolve("MISSING"))
.isInstanceOf(ResponseStatusException.class)
.hasMessageContaining("404");
server.verify();
}
}
@@ -63,6 +63,16 @@ class PdaPalletOperationServiceTest {
verifyNoInteractions(mapper);
}
@Test void resolveReportsMissingOnSitePalletAsNotFound() {
when(physical.resolve("MISSING")).thenReturn(null);
ResponseStatusException failure = assertThrows(ResponseStatusException.class, () -> service.resolve(identity(),
new PalletOperationRequests.Scan("MISSING")));
assertEquals(404, failure.getStatusCode().value());
verifyNoInteractions(mapper);
}
@Test void localConcurrencyFailureCompensatesEveryAppliedPhysicalTransitionInReverseSafeForm() {
var source = pallet(10L, "SOURCE", 88L, 1);
var target = pallet(20L, "TARGET", 88L, 2);