瀏覽代碼

update file-service test-case

reghao 5 天之前
父節點
當前提交
ed28ca17df

+ 0 - 75
file/file-service/src/test/java/ChatTest.java

@@ -1,28 +1,9 @@
-import cn.reghao.jutil.jdk.converter.DateTimeConverter;
-import cn.reghao.jutil.jdk.serializer.JsonConverter;
-import cn.reghao.jutil.jdk.string.SnowFlake;
 import cn.reghao.tnb.file.app.FileApplication;
-import cn.reghao.tnb.file.app.zchat.db.mapper.ChatDialogueMapper;
-import cn.reghao.tnb.file.app.zchat.db.mapper.ChatMessageMapper;
-import cn.reghao.tnb.file.app.zchat.db.mapper.ChatTransferMapper;
-import cn.reghao.tnb.file.app.zchat.model.constant.ChatMsgType;
-import cn.reghao.tnb.file.app.zchat.model.po.ChatDialogue;
-import cn.reghao.tnb.file.app.zchat.model.po.ChatMessage;
-import cn.reghao.tnb.file.app.zchat.model.po.ChatTransfer;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.ActiveProfiles;
 
-import java.io.File;
-import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * @author reghao
  * @date 2026-06-08 13:29:28
@@ -33,61 +14,5 @@ import java.util.List;
 public class ChatTest {
     @Test
     public void chatTest() {
-        List<ChatMessage> list = new ArrayList<>();
-        JsonArray jsonArray = JsonConverter.jsonFileToObject(new File("/home/reghao/Downloads/chat.json"), JsonArray.class);
-        for (JsonElement jsonElement : jsonArray) {
-            try {
-                JsonObject jsonObject = jsonElement.getAsJsonObject();
-                long senderId = jsonObject.get("senderId").getAsLong();
-                String content = jsonObject.get("content").getAsString();
-                String createAt = jsonObject.get("createAt").getAsString();
-                LocalDateTime createAt1 = DateTimeConverter.localDateTime2(createAt);
-
-                long messageId = snowFlake.nextId();
-                ChatMessage chatMessage = new ChatMessage(messageId, chatId, senderId);
-                chatMessage.setMsgType(ChatMsgType.text.getCode());
-                chatMessage.setContent(content);
-                chatMessage.setCreateAt(createAt1);
-                chatMessage.setSenderId(senderId);
-                list.add(chatMessage);
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-
-        //chatMessageTest();
-        chatMessageMapper.saveAll(list);
-    }
-
-    @Autowired
-    ChatMessageMapper chatMessageMapper;
-    @Autowired
-    ChatTransferMapper chatTransferMapper;
-
-    SnowFlake snowFlake = new SnowFlake(1L, 1L);
-    long chatId = 65422888961L;
-    int chatType = 1;
-    private void chatMessageTest() {
-        long senderId = 10001L;
-
-        long messageId = snowFlake.nextId();
-        ChatMessage chatMessage = new ChatMessage(messageId, chatId, senderId);
-        chatMessage.setContent("");
-        chatMessage.setMsgType(ChatMsgType.chatTransfer.getCode());
-        ChatTransfer chatTransfer = new ChatTransfer(messageId, 1.02);
-
-        chatMessageMapper.save(chatMessage);
-        chatTransferMapper.save(chatTransfer);
-    }
-
-    @Autowired
-    ChatDialogueMapper chatDialogueMapper;
-    private void chatDialogueTest() {
-        long senderId = 10001L;
-        long receiverId = 10002L;
-
-        ChatDialogue chatDialogue1 = new ChatDialogue(chatId, chatType, senderId, receiverId);
-        ChatDialogue chatDialogue2 = new ChatDialogue(chatId, chatType, receiverId, senderId);
-        chatDialogueMapper.saveAll(List.of(chatDialogue1, chatDialogue2));
     }
 }

+ 0 - 22
file/file-service/src/test/java/DiskTest.java

@@ -1,19 +1,9 @@
-import cn.reghao.tnb.common.auth.LoginUser;
-import cn.reghao.tnb.common.auth.UserContext;
 import cn.reghao.tnb.file.app.FileApplication;
-import cn.reghao.tnb.file.app.zdisk.db.mapper.DiskAlbumMapper;
-import cn.reghao.tnb.file.app.zdisk.db.mapper.DiskFileMapper;
-import cn.reghao.tnb.file.app.zdisk.model.vo.FolderTree;
-import cn.reghao.tnb.file.app.zdisk.service.DiskFolderService;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.ActiveProfiles;
 
-import java.util.Collections;
-import java.util.List;
-
 /**
  * @author reghao
  * @date 2025-09-03 19:12:34
@@ -22,19 +12,7 @@ import java.util.List;
 @ActiveProfiles("dev")
 @SpringBootTest(classes = FileApplication.class)
 public class DiskTest {
-    @Autowired
-    DiskAlbumMapper diskAlbumMapper;
-    @Autowired
-    DiskFileMapper diskFileMapper;
-
-    @Autowired
-    DiskFolderService diskFolderService;
     @Test
     public void diskTest() {
-        LoginUser loginUser = new LoginUser(10001L, "loginId", Collections.emptySet());
-        UserContext context = new UserContext(loginUser);
-
-        List<FolderTree> list = diskFolderService.getFolderTree();
-        System.out.println();
     }
 }

+ 0 - 273
file/file-service/src/test/java/DiskUnitTest.java

@@ -1,273 +0,0 @@
-import cn.reghao.jutil.jdk.converter.DateTimeConverter;
-import cn.reghao.jutil.jdk.serializer.JsonConverter;
-import cn.reghao.jutil.jdk.string.SnowFlake;
-import cn.reghao.oss.api.dto.ObjectInfo;
-import cn.reghao.oss.api.dto.ServerInfo;
-import cn.reghao.oss.api.dto.rest.UploadFileRet;
-import cn.reghao.oss.sdk.OssClient;
-import cn.reghao.tnb.file.app.FileApplication;
-import cn.reghao.tnb.file.app.zchat.db.mapper.ChatFileMapper;
-import cn.reghao.tnb.file.app.zchat.db.mapper.ChatMessageMapper;
-import cn.reghao.tnb.file.app.zchat.model.constant.ChatMsgType;
-import cn.reghao.tnb.file.app.zchat.model.po.ChatMessage;
-import cn.reghao.tnb.file.app.zchat.model.po.ChatCall;
-import cn.reghao.tnb.file.app.zchat.model.po.ChatFile;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonPrimitive;
-import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.ActiveProfiles;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.*;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.time.LocalDateTime;
-import java.util.*;
-
-@Slf4j
-@ActiveProfiles("dev")
-@SpringBootTest(classes = FileApplication.class)
-public class DiskUnitTest {
-    @Autowired
-    ChatMessageMapper chatMessageMapper;
-    @Autowired
-    ChatFileMapper chatFileMapper;
-
-    void walkDir(Path path) throws IOException {
-        Files.walkFileTree(path, new SimpleFileVisitor<>() {
-            @Override
-            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
-                File file1 = file.toFile();
-                process(file1);
-                return FileVisitResult.CONTINUE;
-            }
-        });
-    }
-
-    private void process(File file) {
-    }
-
-    @Test
-    public void fileWalk() throws Exception {
-        String baseDir = "/disk/1";
-        //Path path = Paths.get(baseDir);
-        //walkDir(path);
-
-        /*String filePath = "/home/reghao/Downloads/v2-cb256.jpg";
-        UploadFileRet uploadFileRet = uploadFile(new File(filePath));
-        String objectId = uploadFileRet.getUploadId();
-        String signedUrl = getOssClient().getSignedUrl(objectId, ObjectAction.access.getName(), null);
-        System.out.println(signedUrl);*/
-
-        parseTelegram();
-    }
-
-    String baseDir = "/home/reghao/Downloads/0/tg/tg_json";
-    private void parseTelegram() {
-        List<ChatMessage> chatMessageList = new ArrayList<>();
-        List<ChatFile> chatFileList = new ArrayList<>();
-        List<ChatCall> chatCallList = new ArrayList<>();
-
-        String path = baseDir + "/result.json";
-        File jsonFile = new File(path);
-        JsonObject jsonObject = JsonConverter.jsonFileToObject(jsonFile, JsonObject.class);
-        JsonArray jsonArray = jsonObject.get("chats").getAsJsonObject().get("list").getAsJsonArray();
-        JsonObject chat = jsonArray.get(0).getAsJsonObject();
-        JsonArray messages = chat.get("messages").getAsJsonArray();
-        for (JsonElement jsonElement : messages) {
-            JsonObject jsonObject1 = jsonElement.getAsJsonObject();
-            try {
-                long id = jsonObject1.get("id").getAsLong();
-                String date = jsonObject1.get("date").getAsString();
-                LocalDateTime createAt = DateTimeConverter.localDateTime2(date.replace("T", " "));
-                String type = jsonObject1.get("type").getAsString();
-                if ("service".equals(type)) {
-                    long senderId = jsonObject1.get("actor_id").getAsLong();
-                    long messageId = snowFlake.nextId();
-                    ChatMessage chatMessage = new ChatMessage(messageId, chatId, senderId, createAt);
-                    chatMessage.setMsgType(ChatMsgType.audioCall.getCode());
-
-                    String callType = "audio";
-                    double duration = 0.0D;
-                    String discardReason = jsonObject1.get("discard_reason").getAsString();
-                    if ("hangup".equals(discardReason)) {
-                        duration = jsonObject1.get("duration_seconds").getAsDouble();
-                    }
-
-                    ChatCall chatCall = new ChatCall(messageId, callType, duration, discardReason);
-                    chatCallList.add(chatCall);
-                    chatMessageList.add(chatMessage);
-                    continue;
-                }
-                String from = jsonObject1.get("from").getAsString();
-                long fromId = jsonObject1.get("from_id").getAsLong();
-
-                long senderId = userMap.get(fromId);
-                long messageId = snowFlake.nextId();
-                ChatMessage chatMessage = new ChatMessage(messageId, chatId, senderId, createAt);
-
-                JsonElement jsonElement1 = jsonObject1.get("text");
-                if (jsonElement1 instanceof JsonPrimitive) {
-                    String text = jsonObject1.get("text").getAsString();
-                    chatMessage.setMsgType(ChatMsgType.text.getCode());
-                    chatMessage.setContent(text);
-                } else if (jsonElement1 instanceof JsonArray) {
-                    String text1 = "";
-                    for (JsonElement jsonElement2 : jsonElement1.getAsJsonArray()) {
-                        if (jsonElement2 instanceof JsonPrimitive) {
-                            text1 = jsonElement2.getAsString();
-                        } else if (jsonElement2 instanceof JsonObject) {
-                            try {
-                                JsonObject jsonObject2 = jsonElement2.getAsJsonObject();
-                                String type1 = jsonObject2.get("type").getAsString();
-                                String link1 = jsonObject2.get("text").getAsString();
-                                if (type1.equals("link")) {
-                                    chatMessage.setMsgType(ChatMsgType.chatLink.getCode());
-                                    chatMessage.setContent(text1);
-                                    chatMessage.setUrl(link1);
-                                } else if (type1.equals("email")) {
-                                    chatMessage.setMsgType(ChatMsgType.chatLink.getCode());
-                                    chatMessage.setContent(text1);
-                                    chatMessage.setUrl(link1);
-                                } else {
-                                    System.out.printf("unknown type1: %s\n", type1);
-                                }
-                            } catch (Exception e) {
-                                System.out.println(e.getMessage());
-                            }
-                        }
-                    }
-                } else {
-                    System.out.printf("text field is unknown type: %s\n", jsonObject1.get("text"));
-                }
-
-                String mediaType = "NoMedia";
-                if (jsonObject1.get("media_type") != null) {
-                    mediaType = jsonObject1.get("media_type").getAsString();
-                }
-
-                if (!mediaType.equals("NoMedia")) {
-                    String filePath = jsonObject1.get("file").getAsString();
-                    File file = new File(baseDir + "/" + filePath);
-                    if (!file.exists()) {
-                        System.out.printf("file message %s not exist, continue next loop\n", filePath);
-                        continue;
-                    }
-
-                    if ("voice_message".equals(mediaType)) {
-                        chatMessage.setMsgType(ChatMsgType.audio.getCode());
-
-                        UploadFileRet uploadFileRet = uploadFile(file);
-                        String objectId = uploadFileRet.getUploadId();
-                        ObjectInfo objectInfo = getOssClient().getObjectInfo(objectId);
-                        ChatFile chatFile = new ChatFile(chatMessage.getMessageId(), objectInfo);
-                        chatFileList.add(chatFile);
-                    } else if ("video_message".equals(mediaType)) {
-                        chatMessage.setMsgType(ChatMsgType.video.getCode());
-
-                        UploadFileRet uploadFileRet = uploadFile(file);
-                        String objectId = uploadFileRet.getUploadId();
-                        ObjectInfo objectInfo = getOssClient().getObjectInfo(objectId);
-                        ChatFile chatFile = new ChatFile(chatMessage.getMessageId(), objectInfo);
-                        chatFileList.add(chatFile);
-                    } else if ("video_file".equals(mediaType)) {
-                        chatMessage.setMsgType(ChatMsgType.video.getCode());
-
-                        UploadFileRet uploadFileRet = uploadFile(file);
-                        String objectId = uploadFileRet.getUploadId();
-                        ObjectInfo objectInfo = getOssClient().getObjectInfo(objectId);
-                        ChatFile chatFile = new ChatFile(chatMessage.getMessageId(), objectInfo);
-                        chatFileList.add(chatFile);
-                    } else if ("animation".equals(mediaType)) {
-                        if (filePath.endsWith("gif.mp4")) {
-                            String filePath1 = filePath.replace(".mp4", "");
-                            File file1 = new File(baseDir + "/" + filePath1);
-                            if (!file1.exists()) {
-                                System.out.printf("file message %s not exist, continue next loop\n", filePath1);
-                                continue;
-                            }
-                        }
-
-                        chatMessage.setMsgType(ChatMsgType.image.getCode());
-
-                        UploadFileRet uploadFileRet = uploadFile(file);
-                        String objectId = uploadFileRet.getUploadId();
-                        ObjectInfo objectInfo = getOssClient().getObjectInfo(objectId);
-                        ChatFile chatFile = new ChatFile(chatMessage.getMessageId(), objectInfo);
-                        chatFileList.add(chatFile);
-                    } else if ("sticker".equals(mediaType)) {
-                        if (filePath.endsWith(".tgs")) {
-                            String filePath1 = filePath + "_thumb.jpg";
-                            File file1 = new File(baseDir + "/" + filePath1);
-                            if (!file1.exists()) {
-                                System.out.printf("file message %s not exist, continue next loop\n", filePath1);
-                                continue;
-                            }
-                        }
-
-                        chatMessage.setMsgType(ChatMsgType.image.getCode());
-
-                        UploadFileRet uploadFileRet = uploadFile(file);
-                        String objectId = uploadFileRet.getUploadId();
-                        ObjectInfo objectInfo = getOssClient().getObjectInfo(objectId);
-                        ChatFile chatFile = new ChatFile(chatMessage.getMessageId(), objectInfo);
-                        chatFileList.add(chatFile);
-                    }
-                }
-
-                if (jsonObject1.get("photo") != null) {
-                    String photoPath = jsonObject1.get("photo").getAsString();
-                    File photoFile = new File(baseDir + "/" + photoPath);
-                    if (!photoFile.exists()) {
-                        System.out.printf("file message %s not exist, continue next loop\n", photoPath);
-                    }
-
-                    chatMessage.setMsgType(ChatMsgType.image.getCode());
-
-                    UploadFileRet uploadFileRet = uploadFile(photoFile);
-                    String objectId = uploadFileRet.getUploadId();
-                    ObjectInfo objectInfo = getOssClient().getObjectInfo(objectId);
-                    ChatFile chatFile = new ChatFile(chatMessage.getMessageId(), objectInfo);
-                    chatFileList.add(chatFile);
-                }
-                //System.out.printf("%s - %s[%s]\n", date, fromId, from);
-                chatMessageList.add(chatMessage);
-            } catch (Exception e) {
-                System.out.println(e.getMessage());
-            }
-        }
-
-        System.out.println();
-        /*chatFileMapper.saveAll(chatFileList);
-        chatMessageMapper.saveAll(chatMessageList);*/
-    }
-
-    long chatId = 10002L;
-    SnowFlake snowFlake = new SnowFlake(1L, 1L);
-    Map<Long, Long> userMap = Map.of(
-            10001L, 10001L,
-            10002L, 10002L
-            );
-
-    private UploadFileRet uploadFile(File file) throws Exception {
-        OssClient ossClient = getOssClient();
-        int channelCode = 109;
-        ServerInfo serverInfo = ossClient.getServerInfo(channelCode);
-
-        UploadFileRet uploadFileRet = ossClient.putObject(serverInfo, file);
-        return uploadFileRet;
-    }
-
-    private OssClient getOssClient() {
-        String endpoint = "https://ossconsole.reghao.cn";
-        String ak = "PmvonhHI";
-        String sk = "28aQEK7wJ6U5m7E1u7";
-        OssClient ossClient = new OssClient(endpoint, ak, sk);
-        return ossClient;
-    }
-}

+ 0 - 142
file/file-service/src/test/java/FileTest.java

@@ -1,142 +0,0 @@
-import cn.reghao.tnb.file.api.dto.CamPhoto;
-import cn.reghao.tnb.file.app.FileApplication;
-import cn.reghao.tnb.file.app.service.EarthService;
-import cn.reghao.tnb.file.app.util.JarFileResources;
-import cn.reghao.tnb.file.app.util.PhotoExif;
-import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.test.context.ActiveProfiles;
-
-import java.io.*;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.FileVisitResult;
-import java.nio.file.FileVisitor;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author reghao
- * @date 2024-04-17 07:18:59
- */
-@Slf4j
-//@ActiveProfiles("dev")
-//@SpringBootTest(classes = FileApplication.class)
-public class FileTest {
-    void walkDir(Path path) throws IOException {
-        Files.walkFileTree(path, new FileVisitor<Path>() {
-            @Override
-            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
-                return FileVisitResult.CONTINUE;
-            }
-
-            @Override
-            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
-                File file1 = file.toFile();
-                process(file1);
-                return FileVisitResult.CONTINUE;
-            }
-
-            @Override
-            public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
-                return FileVisitResult.CONTINUE;
-            }
-
-            @Override
-            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
-                return FileVisitResult.CONTINUE;
-            }
-        });
-    }
-
-    List<CamPhoto> camPhotoList = new ArrayList<>();
-    private void process(File file) {
-        CamPhoto camPhoto = PhotoExif.getCamPhoto(file.getAbsolutePath());
-        /*if (camPhoto != null && camPhoto.getLatitude() != null) {
-            camPhotoList.add(camPhoto);
-        }*/
-
-        if (camPhoto != null && camPhoto.getShotAt() != null) {
-            camPhotoList.add(camPhoto);
-        }
-    }
-
-    String kmlFile = "/home/reghao/Downloads/my_places.kml";
-    //@Autowired
-    //EarthService earthService;
-    @Test
-    public void photoTest() throws Exception {
-        String baseDir = "/media/veracrypt1/pv/2";
-        walkDir(Path.of(baseDir));
-        //earthService.getEarthKml(kmlFile, camPhotoList);
-        System.out.println();
-    }
-
-    // print input stream
-    private static void printInputStream(InputStream is) {
-        try (InputStreamReader streamReader = new InputStreamReader(is, StandardCharsets.UTF_8);
-             BufferedReader reader = new BufferedReader(streamReader)) {
-            String line;
-            while ((line = reader.readLine()) != null) {
-                System.out.println(line);
-            }
-        } catch (IOException e) {
-            log.error("{}", e.getMessage());
-        }
-    }
-
-    @Test
-    public void getFileFromJar() throws IOException, URISyntaxException {
-        ClassLoader classLoader = this.getClass().getClassLoader();
-        ClassLoader classLoader1 = Thread.currentThread().getContextClassLoader();
-        ClassLoader classLoader2 = FileTest.class.getClassLoader();
-
-        String resourcePath = "templates/index.html";
-        URL resource = classLoader.getResource(resourcePath);
-        File file = new File(resource.toURI());
-        InputStream inputStream = classLoader.getResourceAsStream(resourcePath);
-
-        URL resource1 = classLoader1.getResource(resourcePath);
-        URL resource2 = classLoader2.getResource(resourcePath);
-
-        InputStream resourceAsStream = new ClassPathResource(resourcePath).getInputStream();
-
-
-        /*URL resource = Thread.currentThread().getContextClassLoader().getResource(avatarResource);
-        String avatarPath = resource.getPath();
-        System.out.println(avatarPath);
-        File file = new File(avatarPath);
-        byte[] imageBytes = Files.readAllBytes(file.toPath());*/
-
-        JarFileResources app = new JarFileResources();
-        // Sample 3 - read all files from a resources folder (jar version)
-        try {
-            // get paths from src/main/resources/json
-            List<Path> result = app.getPathsFromResourceJar("json");
-            for (Path path : result) {
-                System.out.println("Path : " + path);
-
-                String filePathInJar = path.toString();
-                // Windows will returns /json/file1.json, cut the first /
-                // the correct path should be json/file1.json
-                if (filePathInJar.startsWith("/")) {
-                    filePathInJar = filePathInJar.substring(1, filePathInJar.length());
-                }
-
-                System.out.println("filePathInJar : " + filePathInJar);
-                // read a file from resource folder
-                InputStream is = app.getFileFromResourceAsStream(filePathInJar);
-                printInputStream(is);
-            }
-        } catch (URISyntaxException | IOException e) {
-            e.printStackTrace();
-        }
-    }
-}