yeg
2026-09-05 92f32acd847ea1700590bc669750f23ef499840e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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());
        }
    }
}