Просмотр исходного кода

feat(zhaozhaonews): 新增测试模块 - test(MinIO文件上传测试/应用入口)

WanJL 3 недель назад
Родитель
Сommit
1c4728d5a6

+ 54 - 0
zhaozhaonews/zhaozhaonews-test/pom.xml

@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.zhaozhaonews</groupId>
+        <artifactId>zhaozhaonews</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>zhaozhaonews-test</artifactId>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+    <dependencies>
+        <!--引入我们自己封装的文件上传的starter-->
+        <dependency>
+            <groupId>com.zhaozhaonews</groupId>
+            <artifactId>zhaozhaonews-file-starter</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+        <!-- 引入依赖模块 -->
+        <dependency>
+            <groupId>com.zhaozhaonews</groupId>
+            <artifactId>zhaozhaonews-model</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.zhaozhaonews</groupId>
+            <artifactId>zhaozhaonews-common</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.zhaozhaonews</groupId>
+            <artifactId>zhaozhaonews-feign-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.zhaozhaonews</groupId>
+            <artifactId>zhaozhaonews-util</artifactId>
+        </dependency>
+        <!-- Spring boot starter -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>

+ 19 - 0
zhaozhaonews/zhaozhaonews-test/src/main/java/com/zhaozhaonews/TestApplication.java

@@ -0,0 +1,19 @@
+package com.zhaozhaonews;
+
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * @author WanJl
+ * @version 1.0
+ * @title TestApplication
+ * @description
+ * @create 2026/4/26
+ */
+@SpringBootApplication
+public class TestApplication {
+    public static void main(String[] args) {
+        SpringApplication.run(TestApplication.class, args);
+    }
+}

+ 19 - 0
zhaozhaonews/zhaozhaonews-test/src/main/resources/application.yaml

@@ -0,0 +1,19 @@
+spring:
+  datasource:
+    driver-class-name: com.mysql.jdbc.Driver
+    url: jdbc:mysql://192.168.200.129:3306/zhaozhaonews_article?useUnicode=true&characterEncoding=UTF-8&serverTimeZone=UTC
+    username: root
+    password: 123456
+mybatis-plus:
+  mapper-locations: classpath*:mapper*/*Mapper.xml # 设置Mapper接口对应的文件位置
+  type-aliases-package: com.zhaozhaonews.model.article.entity #别名
+  global-config:
+    datacenter-id: 1 #数据中心id
+    workerId: 1 #机器id
+
+minio:
+  access-key: admin
+  secret-key: 123456789
+  bucket: zhaozhaonews
+  endpoint: http://192.168.200.129:9000
+  read-path: http://192.168.200.129:9000

+ 39 - 0
zhaozhaonews/zhaozhaonews-test/src/test/java/com/zhaozhaonews/minio/UploadFileTest.java

@@ -0,0 +1,39 @@
+package com.zhaozhaonews.minio;
+
+
+import com.zhaozhaonews.TestApplication;
+import com.zhaozhaonews.file.service.FileStorageService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+
+/**
+ * @author WanJl
+ * @version 1.0
+ * @title UploadFileTest
+ * @description
+ * @create 2026/4/26
+ */
+@SpringBootTest(classes = TestApplication.class)
+@RunWith(SpringRunner.class)
+public class UploadFileTest {
+
+    @Resource
+    private FileStorageService fileStorageService;
+
+    @Test
+    public void uploadFileTest(){
+        try {
+            FileInputStream inputStream=new FileInputStream("E:/infinity-6988633.jpg");
+            String filePath = fileStorageService.uploadImgFile("", "infinity-6988633.jpg", inputStream);
+            System.out.println(filePath);
+        } catch (FileNotFoundException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}