fix: avoid jt808 fallback ids as vin
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
lingniu
2026-06-26 11:37:37 +08:00
parent 5e619c3634
commit ec555cd67a
4 changed files with 75 additions and 10 deletions

View File

@@ -197,6 +197,46 @@ class Jt808ChannelHandlerTest {
eventBus.close();
}
@Test
void unboundLocationArchiveUsesUnknownVinInsteadOfPhoneFallback() throws Exception {
RecordingSink sink = new RecordingSink(1);
DisruptorEventBus eventBus = new DisruptorEventBus(1024, "blocking", List.of(sink));
AsyncBatchExecutor batchExecutor = new AsyncBatchExecutor(eventBus::publish);
Dispatcher dispatcher = new Dispatcher(
new HandlerRegistry(),
new InterceptorChain(List.of()),
new HandlerInvoker(),
eventBus,
batchExecutor);
InMemoryVehicleIdentityService identity = new InMemoryVehicleIdentityService();
Jt808ChannelHandler handler = new Jt808ChannelHandler(
new Jt808MessageDecoder(new BodyParserRegistry(List.of(new LocationBodyParser()))),
dispatcher,
new InMemorySessionStore(),
identity,
new Jt808ChannelRegistry(),
new Jt808PendingRequests());
EmbeddedChannel channel = new EmbeddedChannel(handler);
byte[] frame = buildFrame(Jt808MessageId.TERMINAL_LOCATION, "123456789012", 1, buildLocationBody());
channel.writeInbound(frame);
assertThat(sink.await()).isTrue();
assertThat(sink.events).singleElement().satisfies(event -> {
assertThat(event).isInstanceOf(VehicleEvent.RawArchive.class);
VehicleEvent.RawArchive archive = (VehicleEvent.RawArchive) event;
assertThat(archive.vin()).isEqualTo("unknown");
assertThat(archive.metadata())
.containsEntry("vin", "unknown")
.containsEntry("phone", "123456789012")
.containsEntry("identityResolved", "false")
.containsEntry("identitySource", "FALLBACK_PHONE");
});
batchExecutor.close();
eventBus.close();
}
@Test
void malformedFrameIsArchivedAndDispatchedAsPassthrough() throws Exception {
RecordingSink sink = new RecordingSink(2);

View File

@@ -34,10 +34,12 @@ class Jt808EventMapperTest {
assertThat(events).hasSize(1);
assertThat(events.get(0)).isInstanceOf(VehicleEvent.Location.class);
assertThat(events.get(0).source()).isEqualTo(ProtocolId.JT808);
assertThat(events.get(0).vin()).isEqualTo("123456789012");
assertThat(events.get(0).vin()).isEqualTo("unknown");
assertThat(events.get(0).metadata())
.containsEntry("vin", "123456789012")
.containsEntry("identityResolved", "false");
.containsEntry("vin", "unknown")
.containsEntry("phone", "123456789012")
.containsEntry("identityResolved", "false")
.containsEntry("identitySource", "FALLBACK_PHONE");
}
@Test
@@ -197,7 +199,10 @@ class Jt808EventMapperTest {
assertThat(passthrough.passthroughType()).isEqualTo(0x0F01);
assertThat(passthrough.data()).containsExactly(0x11, 0x22, 0x33);
assertThat(passthrough.metadata())
.containsEntry("vin", "123456789012")
.containsEntry("vin", "unknown")
.containsEntry("phone", "123456789012")
.containsEntry("identityResolved", "false")
.containsEntry("identitySource", "FALLBACK_PHONE")
.containsEntry("rawBody", "true");
});
}