test: centralize vehicle identity fixtures

This commit is contained in:
lingniu
2026-07-01 18:32:09 +08:00
parent 4eaaa88e9c
commit e06534d6a5
12 changed files with 95 additions and 150 deletions

View File

@@ -31,6 +31,11 @@
<groupId>com.lingniu.ingest</groupId>
<artifactId>vehicle-identity</artifactId>
</dependency>
<dependency>
<groupId>com.lingniu.ingest</groupId>
<artifactId>vehicle-identity-test-support</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.lingniu.ingest</groupId>
<artifactId>sink-archive</artifactId>

View File

@@ -1,48 +0,0 @@
package com.lingniu.ingest.identity;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public final class InMemoryVehicleIdentityService implements VehicleIdentityResolver, VehicleIdentityRegistry {
private final List<VehicleIdentityBinding> bindings = new CopyOnWriteArrayList<>();
@Override
public VehicleIdentity resolve(VehicleIdentityLookup lookup) {
if (lookup == null) {
return new VehicleIdentity("unknown", false, VehicleIdentitySource.UNKNOWN);
}
if (!lookup.vin().isBlank() && !"unknown".equalsIgnoreCase(lookup.vin())) {
return new VehicleIdentity(lookup.vin(), true, VehicleIdentitySource.EXPLICIT_VIN);
}
for (VehicleIdentityBinding binding : bindings) {
if (binding.protocol() != lookup.protocol()) {
continue;
}
if (!lookup.phone().isBlank() && lookup.phone().equals(binding.phone())) {
return new VehicleIdentity(binding.vin(), true, VehicleIdentitySource.BOUND_PHONE);
}
if (!lookup.deviceId().isBlank() && lookup.deviceId().equals(binding.deviceId())) {
return new VehicleIdentity(binding.vin(), true, VehicleIdentitySource.BOUND_DEVICE_ID);
}
if (!lookup.plate().isBlank() && lookup.plate().equals(binding.plate())) {
return new VehicleIdentity(binding.vin(), true, VehicleIdentitySource.BOUND_PLATE);
}
}
if (!lookup.phone().isBlank()) {
return new VehicleIdentity("unknown", false, VehicleIdentitySource.FALLBACK_PHONE);
}
if (!lookup.deviceId().isBlank()) {
return new VehicleIdentity("unknown", false, VehicleIdentitySource.FALLBACK_DEVICE_ID);
}
if (!lookup.plate().isBlank()) {
return new VehicleIdentity("unknown", false, VehicleIdentitySource.FALLBACK_PLATE);
}
return new VehicleIdentity("unknown", false, VehicleIdentitySource.UNKNOWN);
}
@Override
public void bind(VehicleIdentityBinding binding) {
bindings.add(binding);
}
}

View File

@@ -31,6 +31,11 @@
<groupId>com.lingniu.ingest</groupId>
<artifactId>vehicle-identity</artifactId>
</dependency>
<dependency>
<groupId>com.lingniu.ingest</groupId>
<artifactId>vehicle-identity-test-support</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.lingniu.ingest</groupId>
<artifactId>sink-archive</artifactId>

View File

@@ -1,48 +0,0 @@
package com.lingniu.ingest.identity;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public final class InMemoryVehicleIdentityService implements VehicleIdentityResolver, VehicleIdentityRegistry {
private final List<VehicleIdentityBinding> bindings = new CopyOnWriteArrayList<>();
@Override
public VehicleIdentity resolve(VehicleIdentityLookup lookup) {
if (lookup == null) {
return new VehicleIdentity("unknown", false, VehicleIdentitySource.UNKNOWN);
}
if (!lookup.vin().isBlank() && !"unknown".equalsIgnoreCase(lookup.vin())) {
return new VehicleIdentity(lookup.vin(), true, VehicleIdentitySource.EXPLICIT_VIN);
}
for (VehicleIdentityBinding binding : bindings) {
if (binding.protocol() != lookup.protocol()) {
continue;
}
if (!lookup.phone().isBlank() && lookup.phone().equals(binding.phone())) {
return new VehicleIdentity(binding.vin(), true, VehicleIdentitySource.BOUND_PHONE);
}
if (!lookup.deviceId().isBlank() && lookup.deviceId().equals(binding.deviceId())) {
return new VehicleIdentity(binding.vin(), true, VehicleIdentitySource.BOUND_DEVICE_ID);
}
if (!lookup.plate().isBlank() && lookup.plate().equals(binding.plate())) {
return new VehicleIdentity(binding.vin(), true, VehicleIdentitySource.BOUND_PLATE);
}
}
if (!lookup.phone().isBlank()) {
return new VehicleIdentity("unknown", false, VehicleIdentitySource.FALLBACK_PHONE);
}
if (!lookup.deviceId().isBlank()) {
return new VehicleIdentity("unknown", false, VehicleIdentitySource.FALLBACK_DEVICE_ID);
}
if (!lookup.plate().isBlank()) {
return new VehicleIdentity("unknown", false, VehicleIdentitySource.FALLBACK_PLATE);
}
return new VehicleIdentity("unknown", false, VehicleIdentitySource.UNKNOWN);
}
@Override
public void bind(VehicleIdentityBinding binding) {
bindings.add(binding);
}
}

View File

@@ -32,6 +32,11 @@
<groupId>com.lingniu.ingest</groupId>
<artifactId>vehicle-identity</artifactId>
</dependency>
<dependency>
<groupId>com.lingniu.ingest</groupId>
<artifactId>vehicle-identity-test-support</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>

View File

@@ -1,48 +0,0 @@
package com.lingniu.ingest.identity;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public final class InMemoryVehicleIdentityService implements VehicleIdentityResolver, VehicleIdentityRegistry {
private final List<VehicleIdentityBinding> bindings = new CopyOnWriteArrayList<>();
@Override
public VehicleIdentity resolve(VehicleIdentityLookup lookup) {
if (lookup == null) {
return new VehicleIdentity("unknown", false, VehicleIdentitySource.UNKNOWN);
}
if (!lookup.vin().isBlank() && !"unknown".equalsIgnoreCase(lookup.vin())) {
return new VehicleIdentity(lookup.vin(), true, VehicleIdentitySource.EXPLICIT_VIN);
}
for (VehicleIdentityBinding binding : bindings) {
if (binding.protocol() != lookup.protocol()) {
continue;
}
if (!lookup.phone().isBlank() && lookup.phone().equals(binding.phone())) {
return new VehicleIdentity(binding.vin(), true, VehicleIdentitySource.BOUND_PHONE);
}
if (!lookup.deviceId().isBlank() && lookup.deviceId().equals(binding.deviceId())) {
return new VehicleIdentity(binding.vin(), true, VehicleIdentitySource.BOUND_DEVICE_ID);
}
if (!lookup.plate().isBlank() && lookup.plate().equals(binding.plate())) {
return new VehicleIdentity(binding.vin(), true, VehicleIdentitySource.BOUND_PLATE);
}
}
if (!lookup.phone().isBlank()) {
return new VehicleIdentity("unknown", false, VehicleIdentitySource.FALLBACK_PHONE);
}
if (!lookup.deviceId().isBlank()) {
return new VehicleIdentity("unknown", false, VehicleIdentitySource.FALLBACK_DEVICE_ID);
}
if (!lookup.plate().isBlank()) {
return new VehicleIdentity("unknown", false, VehicleIdentitySource.FALLBACK_PLATE);
}
return new VehicleIdentity("unknown", false, VehicleIdentitySource.UNKNOWN);
}
@Override
public void bind(VehicleIdentityBinding binding) {
bindings.add(binding);
}
}