Browse Source

单元测试用例与文件

chendayu 2 years ago
parent
commit
e8ef357da0

+ 0 - 38
PAS/src/test/java/cn/cslg/pas/domain/FileSource.java

@@ -1,38 +0,0 @@
-package cn.cslg.pas.domain;
-
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.experimental.Accessors;
-
-/**
- * @author 沈永艺
- * @date 2022-8-12
- * @description 数据权限类 数据库对应实体
- */
-
-@Data
-@Accessors(chain = true)
-
-public class FileSource  {
-    /**
-     * 数据字典名字
-     */
-    private String patentNo;
-
-    /**
-     * 数据字典描述
-     */
-    private String pic;
-
-    /**
-     * 数据字典数据库
-     */
-    private String type;
-
-    /**
-     * 数据字典表格
-     */
-    private String url;
-
-
-}

+ 0 - 35
PAS/src/test/java/cn/cslg/pas/mapper/AssoProductPatentMapperTests.java

@@ -1,35 +0,0 @@
-package cn.cslg.pas.mapper;
-
-import cn.cslg.pas.domain.asso.AssoProductPatent;
-import cn.cslg.pas.mapper.asso.AssoProductPatentMapper;
-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;
-
-/**
- * @Author chenyu
- * @Date 2023/3/16
- */
-@Slf4j
-@SpringBootTest
-public class AssoProductPatentMapperTests {
-    @Autowired
-    private AssoProductPatentMapper assoProductPatentMapper;
-
-    @Test
-    void insert() {
-        AssoProductPatent assoProductPatent = new AssoProductPatent()
-                .setPatentNo("dsadsa3213SD")
-                .setProductId(2);
-        int rows = assoProductPatentMapper.insert(assoProductPatent);
-        log.info("插入数据完成,返回受影响的行数:{}", rows);
-    }
-
-    @Test
-    void deleteByProductId() {
-        int rows = assoProductPatentMapper.deleteByProductId(2);
-        log.info("根据产品id删除数据完成,返回受影响的行数:{}", rows);
-    }
-
-}

+ 0 - 40
PAS/src/test/java/cn/cslg/pas/service/ProductServiceImplTests.java

@@ -1,40 +0,0 @@
-package cn.cslg.pas.service;
-
-import cn.cslg.pas.common.JsonPage;
-import cn.cslg.pas.common.model.dto.ProductQueryPageDTO;
-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 java.util.List;
-
-/**
- * 产品的Service层接口实现类的测试类
- *
- * @Author chenyu
- * @Date 2023/3/16
- */
-@Slf4j
-@SpringBootTest
-public class ProductServiceImplTests {
-    @Autowired
-    private IProductService productService;
-
-    @Test
-    void query() {
-        ProductQueryPageDTO productQueryPageDTO = new ProductQueryPageDTO()
-                //.setProductName("手")
-                //.setCompanyName("世博")
-                //.setProductCategoryId(16)
-                .setPatentNo("CN202674151U");
-        JsonPage jsonPage = productService.query(productQueryPageDTO);
-        List<Object> list = jsonPage.getList();
-        log.info("根据专利号查询产品完成,数据信息为:");
-        for (Object o : list) {
-            log.info("{}", o);
-        }
-    }
-
-
-}

+ 113 - 0
PAS/src/test/java/cn/cslg/pas/service/TextExcelTests.java

@@ -0,0 +1,113 @@
+package cn.cslg.pas.service;
+
+import cn.cslg.pas.common.utils.ReadExcelUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+/**
+ * 检测文件合法性方法单元测试
+ *
+ * @Author chenyu
+ * @Date 2023/8/22
+ */
+@Slf4j
+@SpringBootTest
+public class TextExcelTests {
+    private String filePath;
+
+    /**
+     * 测试用例1:上传的文件丢失或不存在
+     */
+    @Test
+    void addNotFoundFileTask() {
+        filePath = "文件丢失或不存在路径";
+
+        try {
+            ReadExcelUtils.textExcel(filePath);
+
+        } catch (Exception e) {
+            Assertions.assertEquals("文件上传失败,服务器忙请稍后再试!", e.getMessage(), "测试用例1不通过");
+        }
+    }
+
+    /**
+     * 测试用例2:上传非Excel文件
+     */
+    @Test
+    void addNotExcelTask() {
+        filePath = ".\\单元测试用例专用文件\\FTO风险排查报告用户操作手册.pptx";
+
+        try {
+            ReadExcelUtils.textExcel(filePath);
+
+        } catch (Exception e) {
+            Assertions.assertEquals("文件格式错误,请上传Excel文件!", e.getMessage(), "测试用例2不通过");
+        }
+    }
+
+    /**
+     * 测试用例3:上传Excel文件,单元格行数 <= 1
+     */
+    @Test
+    void addRowLessThan1ExcelTask() {
+        filePath = ".\\单元测试用例专用文件\\1件CN专利 - 单元格行数不大于1.XLSX";
+
+        try {
+            ReadExcelUtils.textExcel(filePath);
+
+        } catch (Exception e) {
+            Assertions.assertEquals("文件内容格式不正确,请检查总行数是否有专利内容", e.getMessage(), "测试用例3不通过");
+        }
+    }
+
+    /**
+     * 测试用例4:上传Excel文件,抬头没有申请号
+     */
+    @Test
+    void addFalseTitleExcelTask() {
+        filePath = ".\\单元测试用例专用文件\\1件CN专利 - 抬头没有申请号.XLSX";
+
+        try {
+            ReadExcelUtils.textExcel(filePath);
+
+        } catch (Exception e) {
+            Assertions.assertEquals("文件内容格式不正确,第一行抬头必须有【公开(公告)号】和【申请号】", e.getMessage(), "测试用例4不通过");
+        }
+
+    }
+
+    /**
+     * 测试用例5:上传Excel文件,抬头没有公开公告号
+     */
+    @Test
+    void addFalseTitleExcelTask2() {
+        filePath = ".\\单元测试用例专用文件\\1件CN专利 - 抬头没有公开公告号.XLSX";
+
+        try {
+            ReadExcelUtils.textExcel(filePath);
+
+        } catch (Exception e) {
+            Assertions.assertEquals("文件内容格式不正确,第一行抬头必须有【公开(公告)号】和【申请号】", e.getMessage(), "测试用例5不通过");
+        }
+
+    }
+
+    /**
+     * 测试用例6:上传Excel文件,格式内容符合标准
+     */
+    @Test
+    void addExcelTask() {
+        filePath = ".\\单元测试用例专用文件\\1件CN专利.XLSX";
+
+        try {
+            ReadExcelUtils.textExcel(filePath);
+
+        } catch (Exception e) {
+            Assertions.assertEquals("文件内容格式不正确,第一行抬头必须有【公开(公告)号】和【申请号】", e.getMessage(), "测试用例5不通过");
+        }
+
+    }
+
+}

BIN
单元测试用例专用文件/1件CN专利 - 单元格行数不大于1.XLSX


BIN
单元测试用例专用文件/1件CN专利 - 抬头没有公开公告号.XLSX


BIN
单元测试用例专用文件/1件CN专利 - 抬头没有申请号.XLSX


BIN
单元测试用例专用文件/1件CN专利.XLSX


BIN
单元测试用例专用文件/FTO风险排查报告用户操作手册.pptx