package com.battery.device.simulator; import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; import com.battery.device.api.model.ChannelIdentity; import com.battery.device.api.model.DeviceConnectionStatus; import com.battery.device.api.model.DeviceWorkStatus; class SimulatorObservationAdapterContractTest { @Test void persistenceRejectsForeignIdentitiesAndOfflineCachedFacts() throws Exception { try (BtsDevelopmentSimulator simulator = new BtsDevelopmentSimulator(0)) { ChannelIdentity channel = simulator.discoverChannels().get(0).identity(); simulator.updateChannel(channel.devid(), channel.chlid(), true, DeviceWorkStatus.WORKING); simulator.advanceBts(java.time.Instant.now()); assertNotNull(simulator.latestCabinet(channel)); for (ChannelIdentity foreign : java.util.List.of( new ChannelIdentity("another-adapter", channel.devtype(), channel.devid(), channel.subdevid(), channel.chlid()), new ChannelIdentity(channel.adapterCode(), 999, channel.devid(), channel.subdevid(), channel.chlid()), new ChannelIdentity(channel.adapterCode(), channel.devtype(), channel.devid(), 999, channel.chlid()))) { assertNull(simulator.latestCabinet(foreign)); assertNull(simulator.testPlan(foreign)); assertTrue(simulator.stepRecords(foreign).isEmpty()); assertTrue(simulator.cycleRecords(foreign).isEmpty()); } simulator.updateChannel(channel.devid(), channel.chlid(), false, DeviceWorkStatus.WORKING); assertNull(simulator.latestCabinet(channel)); assertTrue(simulator.stepRecords(channel).isEmpty()); assertTrue(simulator.cycleRecords(channel).isEmpty()); } } @Test void simulatorCanBeUsedDirectlyThroughTheVendorNeutralContract() throws Exception { try (BtsDevelopmentSimulator simulator = new BtsDevelopmentSimulator(0)) { ChannelIdentity channel = simulator.discoverChannels().get(0).identity(); simulator.updateChannel(channel.devid(), channel.chlid(), true, DeviceWorkStatus.WORKING); var observation = simulator.observe(java.util.Set.of(channel)).get(channel); assertEquals("dev-sim", simulator.adapterCode()); assertEquals(DeviceConnectionStatus.ONLINE, observation.connectionStatus()); assertEquals(DeviceWorkStatus.WORKING, observation.workStatus()); } } }