feat(wcs): add device capabilities and snapshots
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package com.ruoyi.wcs.domain.equipment;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class DeviceCapabilityTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"ONLINE,AUTO,NORMAL,IDLE,80,true",
|
||||
"OFFLINE,AUTO,NORMAL,IDLE,80,false",
|
||||
"ONLINE,MANUAL,NORMAL,IDLE,80,false",
|
||||
"ONLINE,AUTO,FAULT,IDLE,80,false",
|
||||
"ONLINE,AUTO,NORMAL,BUSY,80,false",
|
||||
"ONLINE,AUTO,NORMAL,IDLE,20,false",
|
||||
"ONLINE,AUTO,NORMAL,IDLE,30,true"
|
||||
})
|
||||
void dispatchabilityUsesOrthogonalStateDimensions(
|
||||
String connection, String mode, String health,
|
||||
String occupation, int battery, boolean expected) {
|
||||
VehicleSnapshot snapshot = snapshot(connection, mode, health,
|
||||
occupation, battery);
|
||||
|
||||
assertEquals(expected, snapshot.isDispatchable(30));
|
||||
}
|
||||
|
||||
@Test
|
||||
void descriptorMatchesOnlyDeclaredCapabilities() {
|
||||
DeviceDescriptor descriptor = descriptor();
|
||||
|
||||
assertTrue(descriptor.supports(DeviceCapability.FOUR_WAY_MOVE));
|
||||
assertTrue(descriptor.supports(DeviceCapability.LOAD_HANDLING));
|
||||
assertFalse(descriptor.supports(DeviceCapability.LIFT_TRANSFER));
|
||||
}
|
||||
|
||||
@Test
|
||||
void descriptorCapabilitySetCannotBeMutated() {
|
||||
DeviceDescriptor descriptor = descriptor();
|
||||
|
||||
assertThrows(UnsupportedOperationException.class,
|
||||
() -> descriptor.getCapabilities().add(DeviceCapability.LIFT_TRANSFER));
|
||||
}
|
||||
|
||||
private static VehicleSnapshot snapshot(String connection, String mode,
|
||||
String health, String occupation,
|
||||
int battery) {
|
||||
return new VehicleSnapshot(descriptor(),
|
||||
VehicleSnapshot.ConnectionState.valueOf(connection),
|
||||
VehicleSnapshot.OperatingMode.valueOf(mode),
|
||||
VehicleSnapshot.HealthState.valueOf(health),
|
||||
VehicleSnapshot.OccupationState.valueOf(occupation),
|
||||
"A", null, battery, null, "F1",
|
||||
Instant.parse("2026-08-04T00:00:00Z"));
|
||||
}
|
||||
|
||||
private static DeviceDescriptor descriptor() {
|
||||
return new DeviceDescriptor("V1", DeviceType.FOUR_WAY_SHUTTLE, "F1",
|
||||
EnumSet.of(DeviceCapability.FOUR_WAY_MOVE,
|
||||
DeviceCapability.LOAD_HANDLING));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user