Bladeren bron

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 weken geleden
bovenliggende
commit
b7c4653f95

+ 2
- 2
iot-platform/src/test/java/com/iot/platform/mqtt/MqttChargeStationConsumerTest.java Bestand weergeven

@@ -98,7 +98,7 @@ class MqttChargeStationConsumerTest {
98 98
 
99 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 104
     @Test
@@ -146,6 +146,6 @@ class MqttChargeStationConsumerTest {
146 146
 
147 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 Bestand weergeven

@@ -188,7 +188,7 @@ class MqttFaultConsumerTest {
188 188
 
189 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 194
     @Test
@@ -215,6 +215,6 @@ class MqttFaultConsumerTest {
215 215
 
216 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 Bestand weergeven

@@ -54,7 +54,7 @@ class SysRealtimeServiceTest {
54 54
     @Test
55 55
     @DisplayName("insertTables: 非法表名应抛出异常且不调用 mapper")
56 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 58
             .isInstanceOf(IllegalArgumentException.class);
59 59
         verifyNoInteractions(sysRealtimeMapper);
60 60
     }
@@ -62,8 +62,8 @@ class SysRealtimeServiceTest {
62 62
     @Test
63 63
     @DisplayName("updateTables: 合法表名应调用 mapper")
64 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 69
     @Test

+ 26
- 26
iot-platform/src/test/java/com/iot/platform/service/TDengineServiceTest.java Bestand weergeven

@@ -82,104 +82,104 @@ class TDengineServiceTest {
82 82
     @Test
83 83
     @DisplayName("getValueType: Boolean 返回 BOOL")
84 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 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 92
     @Test
93 93
     @DisplayName("getValueType: Integer 返回 BIGINT")
94 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 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 102
     @Test
103 103
     @DisplayName("getValueType: Long 返回 BIGINT")
104 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 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 111
     @Test
112 112
     @DisplayName("getValueType: Float 返回 DOUBLE")
113 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 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 120
     @Test
121 121
     @DisplayName("getValueType: Double 返回 DOUBLE")
122 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 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 130
     @Test
131 131
     @DisplayName("getValueType: java.util.Date 返回 TIMESTAMP")
132 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 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 139
     @Test
140 140
     @DisplayName("getValueType: java.sql.Timestamp 返回 TIMESTAMP")
141 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 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 148
     @Test
149 149
     @DisplayName("getValueType: java.time.LocalDateTime 返回 TIMESTAMP")
150 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 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 157
     @Test
158 158
     @DisplayName("getValueType: java.time.Instant 返回 TIMESTAMP")
159 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 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 166
     @Test
167 167
     @DisplayName("getValueType: String 返回 VARCHAR")
168 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 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 176
     @Test
177 177
     @DisplayName("getValueType: null 返回 VARCHAR")
178 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 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 185
     @Test

Laden…
Annuleren
Opslaan