Browse Source

第二版基本完成

Frost 1 year ago
parent
commit
12fdfed60f

+ 46 - 0
src/test/java/wj/service/impl/SaveRecordTest.java

@@ -0,0 +1,46 @@
+package wj.service.impl;
+
+import com.wj.config.PropertiesConfig;
+import com.wj.service.impl.SaveRecord;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class SaveRecordTest {
+
+    @Test
+    public void testSaverecord() throws Exception {
+        try (MockedStatic<PropertiesConfig> mockedPropertiesConfig = Mockito.mockStatic(PropertiesConfig.class)) {
+            // 定义getSqlurl方法的行为,使其返回一个模拟的URL
+            mockedPropertiesConfig.when(PropertiesConfig::getSqlUrl).thenReturn("http://mocked-url.com");
+
+            // 模拟URL和HttpURLConnection
+            URL mockUrl = Mockito.mock(URL.class);
+            HttpURLConnection mockCon = Mockito.mock(HttpURLConnection.class);
+
+            // 配置模拟对象的行为
+            when(mockUrl.openConnection()).thenReturn(mockCon);
+            when(mockCon.getResponseCode()).thenReturn(200);
+
+            // 调用saverecord方法
+            boolean result = SaveRecord.saverecord("http://mocked-url.com", "test-ucid", "test-url");
+
+            // 断言结果为true
+            assertTrue(result);
+
+            // 验证是否调用了正确的方法
+            verify(mockCon).setRequestMethod("POST");
+            verify(mockCon).setDoOutput(true);
+            verify(mockCon).setRequestProperty("Content-Type", "application/json");
+            verify(mockCon).getOutputStream();
+            verify(mockCon).getResponseCode();
+        }
+    }
+}

+ 65 - 0
src/test/java/wj/service/impl/UploadSmallFileTest.java

@@ -0,0 +1,65 @@
+
+package wj.service.impl;
+
+import com.volcengine.tos.TOSV2;
+import com.volcengine.tos.model.object.PutObjectFromFileInput;
+import com.volcengine.tos.model.object.PutObjectFromFileOutput;
+import com.wj.exception.CustomXmlParseException;
+import com.wj.service.impl.SaveRecord;
+import com.wj.service.impl.UploadFile;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.*;
+
+public class UploadSmallFileTest {
+
+    private SaveRecord saveRecord;
+    private TOSV2 tos;
+    private String bucketName = "test-bucket";
+    private String file = "test-file.wav";
+    private String UCID = "test-ucid";
+    private String str = "test-string";
+
+    @BeforeEach
+    public void setUp() {
+        saveRecord = Mockito.mock(SaveRecord.class);
+        tos = Mockito.mock(TOSV2.class);
+    }
+
+    @Test
+    public void testUploadSmallFileSuccess() throws Exception {
+        // 模拟成功上传文件
+        PutObjectFromFileOutput mockOutput = Mockito.mock(PutObjectFromFileOutput.class);
+        when(tos.putObjectFromFile(any(PutObjectFromFileInput.class))).thenReturn(mockOutput);
+        when(mockOutput.getEtag()).thenReturn("test-etag");
+        when(mockOutput.getHashCrc64ecma()).thenReturn("test-crc64");
+
+        // 模拟成功保存记录到数据库
+        when(SaveRecord.saverecord(anyString(), anyString(), anyString())).thenReturn(true);
+
+        // 执行上传文件的方法
+        UploadFile.uploadSmallFile(tos, bucketName, file, UCID, str);
+
+        // 验证是否成功调用了saverecord方法
+        //verify(saveRecord);
+        verify(saveRecord).saverecord(anyString(), eq(UCID), anyString());
+    }
+
+    @Test
+    public void testUploadSmallFileFailure() {
+        // 模拟上传文件失败
+        PutObjectFromFileOutput mockOutput = Mockito.mock(PutObjectFromFileOutput.class);
+        when(tos.putObjectFromFile(any(PutObjectFromFileInput.class))).thenReturn(mockOutput);
+        when(mockOutput.getEtag()).thenReturn(null);
+        when(mockOutput.getHashCrc64ecma()).thenReturn(null);
+
+        // 验证上传失败时是否抛出了CustomXmlParseException异常
+        assertThrows(CustomXmlParseException.class, () -> {
+            UploadFile.uploadSmallFile(tos, bucketName, file, UCID, str);
+        });
+    }
+}

+ 50 - 0
xml_cache.txt

@@ -0,0 +1,50 @@
+D:\Desktop\calls\400001\002\11\14\400001002111405.xml,00001018381676248043,2023-02-13T08:27:46.793+08:00,400001002111405
+D:\Desktop\calls\400001\002\11\14\400001002111400.xml,00001017911676247869,2023-02-13T08:26:26.853+08:00,400001002111400
+D:\Desktop\calls\400001\002\11\14\400001002111404.xml,00001018171676247987,2023-02-13T08:28:50.574+08:00,400001002111404
+D:\Desktop\calls\400001\002\11\14\400001002111403.xml,00001018161676247986,2023-02-13T08:26:50.034+08:00,400001002111403
+D:\Desktop\calls\400001\002\11\14\400001002111407.xml,00001018401676248054,2023-02-13T08:28:30.173+08:00,400001002111407
+D:\Desktop\calls\400001\002\11\14\400001002111406.xml,00001018391676248044,2023-02-13T08:27:58.408+08:00,400001002111406
+D:\Desktop\calls\400001\002\11\14\400001002111401.xml,00001017921676247890,2023-02-13T08:26:10.940+08:00,400001002111401
+D:\Desktop\calls\400001\002\11\14\400001002111408.xml,00001018651676248123,2023-02-13T08:28:51.444+08:00,400001002111408
+D:\Desktop\calls\400001\002\11\14\400001002111402.xml,00001018141676247982,2023-02-13T08:26:35.203+08:00,400001002111402
+D:\Desktop\calls\400001\002\11\14\400001002111409.xml,00001018711676248161,2023-02-13T08:33:44.225+08:00,400001002111409
+D:\Desktop\calls\400001\002\11\14\400001002111415.xml,00001019021676248364,2023-02-13T08:35:55.345+08:00,400001002111415
+D:\Desktop\calls\400001\002\11\14\400001002111412.xml,00001018841676248287,2023-02-13T08:31:43.932+08:00,400001002111412
+D:\Desktop\calls\400001\002\11\14\400001002111413.xml,00001018911676248317,2023-02-13T08:32:48.501+08:00,400001002111413
+D:\Desktop\calls\400001\002\11\14\400001002111411.xml,00001018821676248265,2023-02-13T08:34:21.111+08:00,400001002111411
+D:\Desktop\calls\400001\002\11\14\400001002111410.xml,00001018811676248258,2023-02-13T08:31:50.332+08:00,400001002111410
+D:\Desktop\calls\400001\002\11\14\400001002111414.xml,00001019001676248351,2023-02-13T08:34:57.002+08:00,400001002111414
+D:\Desktop\calls\400001\002\11\14\400001002111416.xml,00001018981676248340,2023-02-13T08:40:33.956+08:00,400001002111416
+D:\Desktop\calls\400001\002\11\14\400001002111417.xml,00001019081676248397,2023-02-13T08:35:20.263+08:00,400001002111417
+D:\Desktop\calls\400001\002\11\14\400001002111418.xml,00001019091676248398,2023-02-13T08:36:01.006+08:00,400001002111418
+D:\Desktop\calls\400001\002\11\14\400001002111419.xml,00001019061676248392,2023-02-13T08:35:01.731+08:00,400001002111419
+D:\Desktop\calls\400001\002\11\14\400001002111420.xml,00001019251676248427,2023-02-13T08:36:06.406+08:00,400001002111420
+D:\Desktop\calls\400001\002\11\14\400001002111421.xml,00001019131676248412,2023-02-13T08:38:51.260+08:00,400001002111421
+D:\Desktop\calls\400001\002\11\14\400001002111422.xml,00001019311676248445,2023-02-13T08:38:56.980+08:00,400001002111422
+D:\Desktop\calls\400001\002\11\14\400001002111424.xml,00001019391676248461,2023-02-13T08:38:51.360+08:00,400001002111424
+D:\Desktop\calls\400001\002\11\14\400001002111425.xml,00001019471676248502,2023-02-13T08:38:30.978+08:00,400001002111425
+D:\Desktop\calls\400001\002\11\14\400001002111423.xml,00001019441676248487,2023-02-13T08:34:54.882+08:00,400001002111423
+D:\Desktop\calls\400001\002\11\14\400001002111426.xml,00001019551676248522,2023-02-13T08:36:52.423+08:00,400001002111426
+D:\Desktop\calls\400001\002\11\14\400001002111427.xml,00001019581676248546,2023-02-13T08:38:39.140+08:00,400001002111427
+D:\Desktop\calls\400001\002\11\14\400001002111428.xml,00001019621676248561,2023-02-13T08:41:05.669+08:00,400001002111428
+D:\Desktop\calls\400001\002\11\14\400001002111429.xml,00001019601676248559,2023-02-13T08:40:07.196+08:00,400001002111429
+D:\Desktop\calls\400001\002\11\14\400001002111430.xml,00001019841676248646,2023-02-13T08:37:49.067+08:00,400001002111430
+D:\Desktop\calls\400001\002\11\14\400001002111431.xml,00001019731676248594,2023-02-13T08:38:45.910+08:00,400001002111431
+D:\Desktop\calls\400001\002\11\14\400001002111432.xml,00001019881676248655,2023-02-13T08:42:00.705+08:00,400001002111432
+D:\Desktop\calls\400001\002\11\14\400001002111434.xml,00001019971676248676,2023-02-13T08:42:18.727+08:00,400001002111434
+D:\Desktop\calls\400001\002\11\14\400001002111433.xml,00001019941676248663,2023-02-13T08:37:59.948+08:00,400001002111433
+D:\Desktop\calls\400001\002\11\14\400001002111435.xml,00001020041676248684,2023-02-13T08:40:38.336+08:00,400001002111435
+D:\Desktop\calls\400001\002\11\14\400001002111436.xml,00001020161676248697,2023-02-13T08:40:10.745+08:00,400001002111436
+D:\Desktop\calls\400001\002\11\14\400001002111437.xml,00001020231676248726,2023-02-13T08:39:25.022+08:00,400001002111437
+D:\Desktop\calls\400001\002\11\14\400001002111438.xml,00001020271676248742,2023-02-13T08:39:11.550+08:00,400001002111438
+D:\Desktop\calls\400001\002\11\14\400001002111439.xml,00001020261676248741,2023-02-13T08:40:19.306+08:00,400001002111439
+D:\Desktop\calls\400001\002\11\14\400001002111440.xml,00001020311676248757,2023-02-13T08:48:43.742+08:00,400001002111440
+D:\Desktop\calls\400001\002\11\14\400001002111441.xml,00001020321676248758,2023-02-13T08:42:51.991+08:00,400001002111441
+D:\Desktop\calls\400001\002\11\14\400001002111442.xml,00001020491676248793,2023-02-13T08:42:26.007+08:00,400001002111442
+D:\Desktop\calls\400001\002\11\14\400001002111443.xml,00001020571676248835,2023-02-13T08:50:05.811+08:00,400001002111443
+D:\Desktop\calls\400001\002\11\14\400001002111444.xml,00001020521676248809,2023-02-13T08:44:15.690+08:00,400001002111444
+D:\Desktop\calls\400001\002\11\14\400001002111445.xml,00001020711676248895,2023-02-13T08:45:09.283+08:00,400001002111445
+D:\Desktop\calls\400001\002\11\14\400001002111446.xml,00001020811676248948,2023-02-13T08:42:29.489+08:00,400001002111446
+D:\Desktop\calls\400001\002\11\14\400001002111447.xml,00001020931676248964,2023-02-13T08:44:21.100+08:00,400001002111447
+D:\Desktop\calls\400001\002\11\14\400001002111448.xml,00001020951676248970,2023-02-13T08:42:58.572+08:00,400001002111448
+D:\Desktop\calls\400001\002\11\14\400001002111449.xml,00001020941676248965,2023-02-13T08:45:19.544+08:00,400001002111449