| | |
| | | package com.ruoyi.device.contract; |
| | | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | | import static org.junit.jupiter.api.Assertions.assertNotEquals; |
| | | import static org.junit.jupiter.api.Assertions.assertFalse; |
| | | import static org.junit.jupiter.api.Assertions.assertTrue; |
| | | import static org.junit.jupiter.api.Assertions.assertThrows; |
| | |
| | | } |
| | | |
| | | @Test |
| | | void developmentSimulatorSupportsNewareProfilesAndDynamicObservation() throws Exception |
| | | { |
| | | try (BtsDevelopmentSimulator simulator = new BtsDevelopmentSimulator(0); |
| | | BtsTcpTransport transport = new BtsTcpTransport("127.0.0.1", simulator.port(), |
| | | Duration.ofSeconds(1), Duration.ofSeconds(1)); |
| | | DeviceAdapter adapter = new BtsDeviceAdapter("dev-sim", transport, |
| | | new BtsXmlCodec("dev-sim", ZoneId.of("Asia/Hong_Kong")))) |
| | | { |
| | | int tDevice = simulator.addNewareDevice("127.0.0.8", "CT-4008T-5V6A-S1-F"); |
| | | int tnDevice = simulator.addNewareDevice("127.0.0.9", "CT-4008Tn-5V12A-S1-F"); |
| | | simulator.updateChannel(tDevice, 1, true, DeviceWorkStatus.WORKING); |
| | | |
| | | var discovered = adapter.discoverChannels(); |
| | | var tChannels = discovered.stream().filter(channel -> channel.serverIp().equals("127.0.0.8")).toList(); |
| | | var tnChannels = discovered.stream().filter(channel -> channel.serverIp().equals("127.0.0.9")).toList(); |
| | | |
| | | assertEquals(4, discovered.stream().filter(channel -> channel.serverIp().equals("127.0.0.2")).count()); |
| | | assertEquals(8, tChannels.size()); |
| | | assertEquals(8, tnChannels.size()); |
| | | assertEquals("新威", tChannels.get(0).deviceMetadata().manufacturer()); |
| | | assertEquals("CT-4008T-5V6A-S1-F", tChannels.get(0).deviceMetadata().model()); |
| | | assertEquals("CT-4008Tn-5V12A-S1-F", tnChannels.get(0).deviceMetadata().model()); |
| | | assertEquals(8, simulator.snapshot().devices().stream() |
| | | .filter(device -> device.deviceId() == tDevice || device.deviceId() == tnDevice) |
| | | .mapToInt(device -> device.channels().size()).sum() / 2); |
| | | |
| | | Set<com.ruoyi.device.model.ChannelIdentity> channel = tChannels.stream() |
| | | .map(DetectedChannel::identity).filter(identity -> identity.chlid() == 1) |
| | | .collect(java.util.stream.Collectors.toSet()); |
| | | var first = adapter.inquire(channel).values().iterator().next(); |
| | | var second = adapter.inquire(channel).values().iterator().next(); |
| | | assertEquals(DeviceWorkStatus.WORKING, first.workStatus()); |
| | | assertNotEquals(first.currentA(), second.currentA()); |
| | | assertTrue(first.voltageV().doubleValue() >= 0.0 && first.voltageV().doubleValue() <= 5.0); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | void developmentSimulatorPersistsNewareProfileMetadata() throws Exception |
| | | { |
| | | InMemoryBtsSimulatorStateStore store = new InMemoryBtsSimulatorStateStore(); |
| | | try (BtsDevelopmentSimulator simulator = new BtsDevelopmentSimulator(0, store)) |
| | | { |
| | | simulator.addNewareDevice("127.0.0.8", "CT-4008Tn-5V12A-S1-F"); |
| | | } |
| | | |
| | | try (BtsDevelopmentSimulator restored = new BtsDevelopmentSimulator(0, store); |
| | | BtsTcpTransport transport = new BtsTcpTransport("127.0.0.1", restored.port(), |
| | | Duration.ofSeconds(1), Duration.ofSeconds(1)); |
| | | DeviceAdapter adapter = new BtsDeviceAdapter("dev-sim", transport, |
| | | new BtsXmlCodec("dev-sim", ZoneId.of("Asia/Hong_Kong")))) |
| | | { |
| | | var profileChannels = adapter.discoverChannels().stream() |
| | | .filter(channel -> channel.serverIp().equals("127.0.0.8")).toList(); |
| | | assertEquals(8, profileChannels.size()); |
| | | assertEquals("CT-4008Tn-5V12A-S1-F", profileChannels.get(0).deviceMetadata().model()); |
| | | assertEquals("新威", profileChannels.get(0).deviceMetadata().manufacturer()); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | void developmentSimulatorPublishesOperatorControlledChannelFacts() throws Exception |
| | | { |
| | | try (BtsDevelopmentSimulator simulator = new BtsDevelopmentSimulator(0); |