fix: verify mysql identity and jt808 field aliases
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -48,5 +48,10 @@
|
||||
<artifactId>spring-boot-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.lingniu.ingest.identity;
|
||||
|
||||
import com.lingniu.ingest.api.ProtocolId;
|
||||
import org.h2.jdbcx.JdbcDataSource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class MySqlVehicleIdentityServiceJdbcTest {
|
||||
|
||||
@Test
|
||||
void registrationVinWriteBackIsQueryableThroughRealJdbc() throws Exception {
|
||||
JdbcDataSource dataSource = new JdbcDataSource();
|
||||
dataSource.setURL("jdbc:h2:mem:" + UUID.randomUUID()
|
||||
+ ";MODE=MySQL;DATABASE_TO_UPPER=false;DB_CLOSE_DELAY=-1");
|
||||
|
||||
try (MySqlVehicleIdentityService service =
|
||||
new MySqlVehicleIdentityService(dataSource, "vehicle_identity_binding")) {
|
||||
service.register(new VehicleRegistrationBinding(
|
||||
ProtocolId.JT808,
|
||||
"unknown",
|
||||
"13079961001",
|
||||
"dev61001",
|
||||
"粤B61001",
|
||||
44,
|
||||
4401,
|
||||
"maker-a",
|
||||
"type-a",
|
||||
1));
|
||||
|
||||
try (Connection connection = dataSource.getConnection();
|
||||
Statement statement = connection.createStatement()) {
|
||||
ResultSet registered = statement.executeQuery("""
|
||||
SELECT vin, device_id, plate, province, city, maker, device_type, plate_color
|
||||
FROM vehicle_identity_binding_registration
|
||||
WHERE protocol = 'JT808' AND phone = '13079961001'
|
||||
""");
|
||||
assertThat(registered.next()).isTrue();
|
||||
assertThat(registered.getString("vin")).isEqualTo("unknown");
|
||||
assertThat(registered.getString("device_id")).isEqualTo("DEV61001");
|
||||
assertThat(registered.getString("plate")).isEqualTo("粤B61001");
|
||||
assertThat(registered.getInt("province")).isEqualTo(44);
|
||||
assertThat(registered.getInt("city")).isEqualTo(4401);
|
||||
assertThat(registered.getString("maker")).isEqualTo("MAKER-A");
|
||||
assertThat(registered.getString("device_type")).isEqualTo("TYPE-A");
|
||||
assertThat(registered.getInt("plate_color")).isEqualTo(1);
|
||||
|
||||
statement.executeUpdate("""
|
||||
UPDATE vehicle_identity_binding_registration
|
||||
SET vin = 'LNVIN00000061001'
|
||||
WHERE protocol = 'JT808' AND phone = '13079961001'
|
||||
""");
|
||||
}
|
||||
|
||||
service.refresh();
|
||||
|
||||
assertThat(service.resolve(new VehicleIdentityLookup(
|
||||
ProtocolId.JT808, "", "13079961001", "", "")).vin())
|
||||
.isEqualTo("LNVIN00000061001");
|
||||
assertThat(service.resolve(new VehicleIdentityLookup(
|
||||
ProtocolId.JT808, "", "", "dev61001", "")).vin())
|
||||
.isEqualTo("LNVIN00000061001");
|
||||
assertThat(service.resolve(new VehicleIdentityLookup(
|
||||
ProtocolId.JT808, "", "", "", "粤B61001")).vin())
|
||||
.isEqualTo("LNVIN00000061001");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user