yeg
2026-09-05 f522c9ffa487e3710d691e8b98df8c4f0cfafd43
ruoyi-admin/src/test/java/com/battery/business/web/device/BtsDevelopmentSimulatorControllerTest.java
@@ -30,6 +30,62 @@
class BtsDevelopmentSimulatorControllerTest
{
    @Test
    void invalidChannelConfigurationDoesNotReplaceSavedValues() throws Exception
    {
        try (var simulator = new BtsDevelopmentSimulator(0)) {
            var mvc = org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup(controller(simulator)).build();
            var before = simulator.snapshot().devices().get(0).channels().get(0).configuration();
            String valid = com.alibaba.fastjson2.JSON.toJSONString(before);
            for (String property : List.of("stepNo", "cycleNo", "currentA", "steps")) {
                var invalid = com.alibaba.fastjson2.JSON.parseObject(valid);
                invalid.put(property, switch (property) {
                    case "stepNo" -> 2;
                    case "cycleNo" -> 0;
                    case "steps" -> List.of();
                    default -> null;
                });
                mvc.perform(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put(
                        "/dev/bts-simulator/devices/1/channels/1/configuration")
                        .contentType("application/json").content(invalid.toJSONString()))
                        .andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status().isBadRequest());
                assertEquals(before, simulator.snapshot().devices().get(0).channels().get(0).configuration());
            }
        }
    }
    @Test
    void channelConfigurationChangesMeasurementsAndPlanOnlyForSelectedChannel() throws Exception
    {
        try (var simulator = new BtsDevelopmentSimulator(0)) {
            var mvc = org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup(controller(simulator)).build();
            mvc.perform(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put(
                    "/dev/bts-simulator/devices/1/channels/1/configuration")
                    .contentType("application/json").content("""
                    {"currentA":-2.5,"voltageV":4.125,"capacityAh":8.2,"energyWh":33.8,
                     "cycleNo":2,"stepNo":2,"plannedCycleCount":3,"totalTimeSeconds":120,"relativeTimeSeconds":30,
                     "steps":[{"name":"充电","stepType":"cc","durationSeconds":60,"voltageV":4.2},
                              {"name":"放电","stepType":"dc","durationSeconds":90,"voltageV":3.0}]}
                    """))
                    .andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status().isOk());
            var identity = simulator.discoverChannels().get(0).identity();
            var actual = simulator.latestCabinet(identity);
            assertEquals(-2.5, actual.currentA());
            assertEquals(4.125, actual.voltageV());
            assertEquals(8.2, actual.capacityAh());
            assertEquals(33.8, actual.energyWh());
            assertEquals(2, actual.cycleNo());
            assertEquals(2, actual.stepNo());
            assertEquals("dc", actual.stepType());
            assertEquals("放电", actual.stepName());
            assertEquals(2, simulator.testPlan(identity).rows().size());
            assertEquals(3, simulator.testPlan(identity).plannedCycleCount());
            var other = simulator.discoverChannels().get(1).identity();
            assertEquals(1, simulator.testPlan(other).rows().size());
            assertEquals(1, simulator.latestCabinet(other).stepNo());
        }
    }
    @Test
    void restChangesSoftwareAndCollectorChannelFactsAndRetiresPlayback() throws Exception
    {
        try (BtsDevelopmentSimulator simulator = new BtsDevelopmentSimulator(0))