| | |
| | | import com.battery.device.api.TestDataObservationAdapter.CycleRecord; |
| | | import com.battery.device.api.TestDataObservationAdapter.SampleWatermark; |
| | | import com.battery.device.api.TestDataObservationAdapter.StepRecord; |
| | | import com.battery.device.api.credentials.LocalCredentials; |
| | | import com.battery.device.api.model.AdapterCapabilities; |
| | | import com.battery.device.api.model.ChannelIdentity; |
| | | import com.battery.device.api.model.DetectedChannel; |
| | |
| | | assertEquals(3, latest.cycleNo()); |
| | | assertEquals(12, latest.stepNo()); |
| | | assertEquals("2", latest.stepType()); |
| | | // 工步名称由设备工步类型解释出的方向填写:2 = 放电。类型本身仍保留设备给的数字。 |
| | | assertEquals("放电", latest.stepName()); |
| | | assertEquals("neware:440:7435", latest.sourceRecordId()); |
| | | // 工步类型保留设备给出的数字,不按电流符号猜方向;同一秒的另一行靠工步与序号区分。 |
| | | // 同一秒的另一行靠工步与序号区分。 |
| | | assertEquals(9, rows.get(1).stepNo()); |
| | | } |
| | | |
| | |
| | | |
| | | StepRecord rest = step(steps, 0, 1); |
| | | assertEquals("4", rest.stepType()); |
| | | assertNull(rest.stepName()); |
| | | // 工步名称按设备工步类型解释出的方向:4 = 搁置。 |
| | | assertEquals("搁置", rest.stepName()); |
| | | assertEquals(Instant.parse("2026-09-28T01:00:00Z"), rest.startedAt()); |
| | | assertEquals(Instant.parse("2026-09-28T01:00:38Z"), rest.endedAt()); |
| | | assertEquals(1.3588, rest.endVoltageV(), 1e-9); |
| | |
| | | |
| | | StepRecord charge = step(steps, 0, 4); |
| | | assertEquals("1", charge.stepType()); |
| | | assertEquals("充电", charge.stepName()); |
| | | // 单项容量只在方向已确认时给出:充电工步取充电侧。 |
| | | assertEquals(119277040d / 36000000d, charge.capacityAh(), 1e-9); |
| | | assertEquals(195220576d / 36000000d, charge.energyWh(), 1e-9); |
| | |
| | | |
| | | StepRecord discharge = step(steps, 0, 6); |
| | | assertEquals("2", discharge.stepType()); |
| | | assertEquals("放电", discharge.stepName()); |
| | | assertEquals(68462032d / 36000000d, discharge.capacityAh(), 1e-9); |
| | | assertTrue(discharge.measurements().containsKey("dischargeMedianVoltage")); |
| | | // 四组容量能量都是设备事实:每一组都保留,不只保留方向匹配的那一组。 |
| | |
| | | List<StepRecord> steps = adapter(stepLayerDatabase()).stepRecords(CHANNEL); |
| | | StepRecord unknown = step(steps, 1, 3); |
| | | assertEquals("7", unknown.stepType()); |
| | | // 类型未确认时工步名称留空:不按电流符号也不按名称猜方向。 |
| | | assertNull(unknown.stepName()); |
| | | // 单项容量留空:方向未确认时不给出可归属的单值,但四组明细照原样保留供核对。 |
| | | assertNull(unknown.capacityAh()); |
| | | assertNull(unknown.energyWh()); |
| | |
| | | { |
| | | // 文件、环境变量、启动参数都在时取文件。 |
| | | java.nio.file.Files.writeString(file, key + "=from-file\n"); |
| | | assertEquals("from-file", NewareMysqlAdapterFactory.credential(key, file, |
| | | assertEquals("from-file", LocalCredentials.resolve(key, file, |
| | | Map.of(key, "from-env"), name -> "from-parameter")); |
| | | |
| | | // 没有文件时退到环境变量。 |
| | | java.nio.file.Files.delete(file); |
| | | assertEquals("from-env", NewareMysqlAdapterFactory.credential(key, file, |
| | | assertEquals("from-env", LocalCredentials.resolve(key, file, |
| | | Map.of(key, "from-env"), name -> "from-parameter")); |
| | | |
| | | // 前两者都没有时退到启动参数。 |
| | | assertEquals("from-parameter", NewareMysqlAdapterFactory.credential(key, file, |
| | | assertEquals("from-parameter", LocalCredentials.resolve(key, file, |
| | | Map.of(), name -> "from-parameter")); |
| | | |
| | | // 三者都没有:失败信息里同时出现文件路径与键名。 |
| | | var failure = org.junit.jupiter.api.Assertions.assertThrows( |
| | | com.battery.device.api.DeviceAdapterException.class, |
| | | () -> NewareMysqlAdapterFactory.credential(key, file, Map.of(), name -> null)); |
| | | () -> LocalCredentials.resolve(key, file, Map.of(), name -> null)); |
| | | assertTrue(failure.getMessage().contains(file.toString())); |
| | | assertTrue(failure.getMessage().contains(key)); |
| | | } |
| | |
| | | try |
| | | { |
| | | java.nio.file.Files.writeString(file, key + "=\n"); |
| | | assertEquals("from-env", NewareMysqlAdapterFactory.credential(key, file, Map.of(key, "from-env"), |
| | | assertEquals("from-env", LocalCredentials.resolve(key, file, Map.of(key, "from-env"), |
| | | name -> null)); |
| | | } |
| | | finally |