Selaa lähdekoodia

test: 修复 mqy20260511 合并后的测试编译和运行时失败

- MqttFaultConsumerTest: insertAlertData 9→8参数, updateAlertData 7→6参数
- SysRealtimeServiceTest: insertTables/updateTables 参数数量同步方法签名
- MqttChargeStationConsumerTest: pe_iot 前缀改为 pe_ems
- TDengineServiceTest: 11个 getValueType 测试同步 (String, Object) 新签名
master
humanleft 2 viikkoa sitten
vanhempi
commit
b7c4653f95

+ 2
- 2
iot-platform/src/test/java/com/iot/platform/mqtt/MqttChargeStationConsumerTest.java Näytä tiedosto

98
 
98
 
99
         method.invoke(consumer, dataList, topic);
99
         method.invoke(consumer, dataList, topic);
100
 
100
 
101
-        verify(tdengineService).insertBatch(eq("pe_iot_my"), eq("mySuperTable"), eq("myDb"), anyList());
101
+        verify(tdengineService).insertBatch(eq("pe_ems_my"), eq("mySuperTable"), eq("myDb"), anyList());
102
     }
102
     }
103
 
103
 
104
     @Test
104
     @Test
146
 
146
 
147
         method.invoke(consumer, dataList, topic);
147
         method.invoke(consumer, dataList, topic);
148
 
148
 
149
-        verify(tdengineService).insertBatch(eq("pe_iot_my"), eq("mySuperTable"), eq("myDb"), argThat(list -> list.size() == 1));
149
+        verify(tdengineService).insertBatch(eq("pe_ems_my"), eq("mySuperTable"), eq("myDb"), argThat(list -> list.size() == 1));
150
     }
150
     }
151
 }
151
 }

+ 2
- 2
iot-platform/src/test/java/com/iot/platform/mqtt/MqttFaultConsumerTest.java Näytä tiedosto

188
 
188
 
189
         mqttFaultConsumer.triggerMethod(topic, faultData);
189
         mqttFaultConsumer.triggerMethod(topic, faultData);
190
 
190
 
191
-        verify(sysFaultService).insertAlertData(eq("GJ123456789"), eq("overtemperature"), eq("0"), anyString(), eq("0"), eq("ctrl1"), eq("dev1"), eq(""), anyString());
191
+        verify(sysFaultService).insertAlertData(eq("GJ123456789"), eq("overtemperature"), eq("0"), eq("0"), eq("ctrl1"), eq("dev1"), eq(""), anyString());
192
     }
192
     }
193
 
193
 
194
     @Test
194
     @Test
215
 
215
 
216
         mqttFaultConsumer.triggerMethod(topic, faultData);
216
         mqttFaultConsumer.triggerMethod(topic, faultData);
217
 
217
 
218
-        verify(sysFaultService).updateAlertData(eq("1"), eq("0"), eq("overtemperature recovered"), eq("ctrl1"), eq("dev1"), anyString(), anyString());
218
+        verify(sysFaultService).updateAlertData(eq("1"), eq("0"), eq("overtemperature recovered"), eq("ctrl1"), eq("dev1"), anyString());
219
     }
219
     }
220
 }
220
 }

+ 3
- 3
iot-platform/src/test/java/com/iot/platform/service/SysRealtimeServiceTest.java Näytä tiedosto

54
     @Test
54
     @Test
55
     @DisplayName("insertTables: 非法表名应抛出异常且不调用 mapper")
55
     @DisplayName("insertTables: 非法表名应抛出异常且不调用 mapper")
56
     void inserttables_invalidTableName_throwsWithoutCallingMapper() {
56
     void inserttables_invalidTableName_throwsWithoutCallingMapper() {
57
-        assertThatThrownBy(() -> service.insertTables("bad;name", "2024-01-01", "C1", "D1", "ts", "k", "v"))
57
+        assertThatThrownBy(() -> service.insertTables("bad;name", "2024-01-01", "C1", "D1", "ts", "k"))
58
             .isInstanceOf(IllegalArgumentException.class);
58
             .isInstanceOf(IllegalArgumentException.class);
59
         verifyNoInteractions(sysRealtimeMapper);
59
         verifyNoInteractions(sysRealtimeMapper);
60
     }
60
     }
62
     @Test
62
     @Test
63
     @DisplayName("updateTables: 合法表名应调用 mapper")
63
     @DisplayName("updateTables: 合法表名应调用 mapper")
64
     void updatetables_validTableName_callsMapper() {
64
     void updatetables_validTableName_callsMapper() {
65
-        service.updateTables("dev_001", "2024-01-01", "v1", "ts", "key1", "C1", "D1");
66
-        verify(sysRealtimeMapper).updateTables("dev_001", "2024-01-01", "v1", "ts", "key1", "C1", "D1");
65
+        service.updateTables("dev_001", "v1", "2024-01-01", "ts", "key1", "C1");
66
+        verify(sysRealtimeMapper).updateTables("dev_001", "v1", "2024-01-01", "ts", "key1", "C1");
67
     }
67
     }
68
 
68
 
69
     @Test
69
     @Test

+ 26
- 26
iot-platform/src/test/java/com/iot/platform/service/TDengineServiceTest.java Näytä tiedosto

82
     @Test
82
     @Test
83
     @DisplayName("getValueType: Boolean 返回 BOOL")
83
     @DisplayName("getValueType: Boolean 返回 BOOL")
84
     void getValueType_boolean_returnsBool() throws Exception {
84
     void getValueType_boolean_returnsBool() throws Exception {
85
-        Method method = TdEngineService.class.getDeclaredMethod("getValueType", Object.class);
85
+        Method method = TdEngineService.class.getDeclaredMethod("getValueType", String.class, Object.class);
86
         method.setAccessible(true);
86
         method.setAccessible(true);
87
 
87
 
88
-        assertThat(method.invoke(tdengineService, Boolean.TRUE)).isEqualTo("BOOL");
89
-        assertThat(method.invoke(tdengineService, Boolean.FALSE)).isEqualTo("BOOL");
88
+        assertThat(method.invoke(tdengineService, "test_col", Boolean.TRUE)).isEqualTo("BOOL");
89
+        assertThat(method.invoke(tdengineService, "test_col", Boolean.FALSE)).isEqualTo("BOOL");
90
     }
90
     }
91
 
91
 
92
     @Test
92
     @Test
93
     @DisplayName("getValueType: Integer 返回 BIGINT")
93
     @DisplayName("getValueType: Integer 返回 BIGINT")
94
     void getValueType_integer_returnsBigint() throws Exception {
94
     void getValueType_integer_returnsBigint() throws Exception {
95
-        Method method = TdEngineService.class.getDeclaredMethod("getValueType", Object.class);
95
+        Method method = TdEngineService.class.getDeclaredMethod("getValueType", String.class, Object.class);
96
         method.setAccessible(true);
96
         method.setAccessible(true);
97
 
97
 
98
-        assertThat(method.invoke(tdengineService, 123)).isEqualTo("BIGINT");
99
-        assertThat(method.invoke(tdengineService, Integer.valueOf(456))).isEqualTo("BIGINT");
98
+        assertThat(method.invoke(tdengineService, "test_col", 123)).isEqualTo("BIGINT");
99
+        assertThat(method.invoke(tdengineService, "test_col", Integer.valueOf(456))).isEqualTo("BIGINT");
100
     }
100
     }
101
 
101
 
102
     @Test
102
     @Test
103
     @DisplayName("getValueType: Long 返回 BIGINT")
103
     @DisplayName("getValueType: Long 返回 BIGINT")
104
     void getValueType_long_returnsBigint() throws Exception {
104
     void getValueType_long_returnsBigint() throws Exception {
105
-        Method method = TdEngineService.class.getDeclaredMethod("getValueType", Object.class);
105
+        Method method = TdEngineService.class.getDeclaredMethod("getValueType", String.class, Object.class);
106
         method.setAccessible(true);
106
         method.setAccessible(true);
107
 
107
 
108
-        assertThat(method.invoke(tdengineService, 123L)).isEqualTo("BIGINT");
108
+        assertThat(method.invoke(tdengineService, "test_col", 123L)).isEqualTo("BIGINT");
109
     }
109
     }
110
 
110
 
111
     @Test
111
     @Test
112
     @DisplayName("getValueType: Float 返回 DOUBLE")
112
     @DisplayName("getValueType: Float 返回 DOUBLE")
113
     void getValueType_float_returnsDouble() throws Exception {
113
     void getValueType_float_returnsDouble() throws Exception {
114
-        Method method = TdEngineService.class.getDeclaredMethod("getValueType", Object.class);
114
+        Method method = TdEngineService.class.getDeclaredMethod("getValueType", String.class, Object.class);
115
         method.setAccessible(true);
115
         method.setAccessible(true);
116
 
116
 
117
-        assertThat(method.invoke(tdengineService, 12.34f)).isEqualTo("DOUBLE");
117
+        assertThat(method.invoke(tdengineService, "test_col", 12.34f)).isEqualTo("DOUBLE");
118
     }
118
     }
119
 
119
 
120
     @Test
120
     @Test
121
     @DisplayName("getValueType: Double 返回 DOUBLE")
121
     @DisplayName("getValueType: Double 返回 DOUBLE")
122
     void getValueType_double_returnsDouble() throws Exception {
122
     void getValueType_double_returnsDouble() throws Exception {
123
-        Method method = TdEngineService.class.getDeclaredMethod("getValueType", Object.class);
123
+        Method method = TdEngineService.class.getDeclaredMethod("getValueType", String.class, Object.class);
124
         method.setAccessible(true);
124
         method.setAccessible(true);
125
 
125
 
126
-        assertThat(method.invoke(tdengineService, 56.78)).isEqualTo("DOUBLE");
127
-        assertThat(method.invoke(tdengineService, Double.valueOf(99.99))).isEqualTo("DOUBLE");
126
+        assertThat(method.invoke(tdengineService, "test_col", 56.78)).isEqualTo("DOUBLE");
127
+        assertThat(method.invoke(tdengineService, "test_col", Double.valueOf(99.99))).isEqualTo("DOUBLE");
128
     }
128
     }
129
 
129
 
130
     @Test
130
     @Test
131
     @DisplayName("getValueType: java.util.Date 返回 TIMESTAMP")
131
     @DisplayName("getValueType: java.util.Date 返回 TIMESTAMP")
132
     void getValueType_date_returnsTimestamp() throws Exception {
132
     void getValueType_date_returnsTimestamp() throws Exception {
133
-        Method method = TdEngineService.class.getDeclaredMethod("getValueType", Object.class);
133
+        Method method = TdEngineService.class.getDeclaredMethod("getValueType", String.class, Object.class);
134
         method.setAccessible(true);
134
         method.setAccessible(true);
135
 
135
 
136
-        assertThat(method.invoke(tdengineService, new java.util.Date())).isEqualTo("TIMESTAMP");
136
+        assertThat(method.invoke(tdengineService, "test_col", new java.util.Date())).isEqualTo("TIMESTAMP");
137
     }
137
     }
138
 
138
 
139
     @Test
139
     @Test
140
     @DisplayName("getValueType: java.sql.Timestamp 返回 TIMESTAMP")
140
     @DisplayName("getValueType: java.sql.Timestamp 返回 TIMESTAMP")
141
     void getValueType_timestamp_returnsTimestamp() throws Exception {
141
     void getValueType_timestamp_returnsTimestamp() throws Exception {
142
-        Method method = TdEngineService.class.getDeclaredMethod("getValueType", Object.class);
142
+        Method method = TdEngineService.class.getDeclaredMethod("getValueType", String.class, Object.class);
143
         method.setAccessible(true);
143
         method.setAccessible(true);
144
 
144
 
145
-        assertThat(method.invoke(tdengineService, new java.sql.Timestamp(System.currentTimeMillis()))).isEqualTo("TIMESTAMP");
145
+        assertThat(method.invoke(tdengineService, "test_col", new java.sql.Timestamp(System.currentTimeMillis()))).isEqualTo("TIMESTAMP");
146
     }
146
     }
147
 
147
 
148
     @Test
148
     @Test
149
     @DisplayName("getValueType: java.time.LocalDateTime 返回 TIMESTAMP")
149
     @DisplayName("getValueType: java.time.LocalDateTime 返回 TIMESTAMP")
150
     void getValueType_localDateTime_returnsTimestamp() throws Exception {
150
     void getValueType_localDateTime_returnsTimestamp() throws Exception {
151
-        Method method = TdEngineService.class.getDeclaredMethod("getValueType", Object.class);
151
+        Method method = TdEngineService.class.getDeclaredMethod("getValueType", String.class, Object.class);
152
         method.setAccessible(true);
152
         method.setAccessible(true);
153
 
153
 
154
-        assertThat(method.invoke(tdengineService, java.time.LocalDateTime.now())).isEqualTo("TIMESTAMP");
154
+        assertThat(method.invoke(tdengineService, "test_col", java.time.LocalDateTime.now())).isEqualTo("TIMESTAMP");
155
     }
155
     }
156
 
156
 
157
     @Test
157
     @Test
158
     @DisplayName("getValueType: java.time.Instant 返回 TIMESTAMP")
158
     @DisplayName("getValueType: java.time.Instant 返回 TIMESTAMP")
159
     void getValueType_instant_returnsTimestamp() throws Exception {
159
     void getValueType_instant_returnsTimestamp() throws Exception {
160
-        Method method = TdEngineService.class.getDeclaredMethod("getValueType", Object.class);
160
+        Method method = TdEngineService.class.getDeclaredMethod("getValueType", String.class, Object.class);
161
         method.setAccessible(true);
161
         method.setAccessible(true);
162
 
162
 
163
-        assertThat(method.invoke(tdengineService, java.time.Instant.now())).isEqualTo("TIMESTAMP");
163
+        assertThat(method.invoke(tdengineService, "test_col", java.time.Instant.now())).isEqualTo("TIMESTAMP");
164
     }
164
     }
165
 
165
 
166
     @Test
166
     @Test
167
     @DisplayName("getValueType: String 返回 VARCHAR")
167
     @DisplayName("getValueType: String 返回 VARCHAR")
168
     void getValueType_string_returnsVarchar() throws Exception {
168
     void getValueType_string_returnsVarchar() throws Exception {
169
-        Method method = TdEngineService.class.getDeclaredMethod("getValueType", Object.class);
169
+        Method method = TdEngineService.class.getDeclaredMethod("getValueType", String.class, Object.class);
170
         method.setAccessible(true);
170
         method.setAccessible(true);
171
 
171
 
172
-        assertThat(method.invoke(tdengineService, "test")).isEqualTo("VARCHAR");
173
-        assertThat(method.invoke(tdengineService, "")).isEqualTo("VARCHAR");
172
+        assertThat(method.invoke(tdengineService, "test_col", "test")).isEqualTo("VARCHAR");
173
+        assertThat(method.invoke(tdengineService, "test_col", "")).isEqualTo("VARCHAR");
174
     }
174
     }
175
 
175
 
176
     @Test
176
     @Test
177
     @DisplayName("getValueType: null 返回 VARCHAR")
177
     @DisplayName("getValueType: null 返回 VARCHAR")
178
     void getValueType_null_returnsVarchar() throws Exception {
178
     void getValueType_null_returnsVarchar() throws Exception {
179
-        Method method = TdEngineService.class.getDeclaredMethod("getValueType", Object.class);
179
+        Method method = TdEngineService.class.getDeclaredMethod("getValueType", String.class, Object.class);
180
         method.setAccessible(true);
180
         method.setAccessible(true);
181
 
181
 
182
-        assertThat(method.invoke(tdengineService, (Object) null)).isEqualTo("VARCHAR");
182
+        assertThat(method.invoke(tdengineService, "test_col", (Object) null)).isEqualTo("VARCHAR");
183
     }
183
     }
184
 
184
 
185
     @Test
185
     @Test

Loading…
Peruuta
Tallenna