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

fix: 测试编译错误修复 - ArticleService.getAdminList 参数补齐 + update 方法参数类型修正

- ArticleServiceTest.java: getAdminList 调用补齐4个 null 参数
- ArticleAdminControllerTest.java: getAdminList mock 补齐参数,update 改用 Map 参数+Result<String>
- AdminArticleControllerTest.java: getAdminList mock 补齐参数,update 改用 Map 参数+Result<String>
- application.yml: datasource 切到本地 MariaDB (root/cfc123)
Xiaogang Liao 4 месяцев назад
Родитель
Сommit
b75d77395c

+ 3 - 3
cfc-backend/src/main/resources/application.yml

@@ -16,9 +16,9 @@ spring:
     name: cfc-backend
     name: cfc-backend
   datasource:
   datasource:
     driver-class-name: com.mysql.cj.jdbc.Driver
     driver-class-name: com.mysql.cj.jdbc.Driver
-    url: jdbc:mysql://192.168.16.251:3306/zxyj?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true&createDatabaseIfNotExist=true
-    username: zxyj
-    password: zxyj@123
+    url: jdbc:mysql://127.0.0.1:3306/zxyj?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true&createDatabaseIfNotExist=true
+    username: root
+    password: cfc123
     hikari:
     hikari:
       maximum-pool-size: 50
       maximum-pool-size: 50
       minimum-idle: 10
       minimum-idle: 10

+ 11 - 6
cfc-backend/src/test/java/com/etotem/cfc/controller/AdminArticleControllerTest.java

@@ -54,7 +54,7 @@ public class AdminArticleControllerTest {
         Page<Article> mockPage = new Page<>(1, 20, 1);
         Page<Article> mockPage = new Page<>(1, 20, 1);
         mockPage.setRecords(records);
         mockPage.setRecords(records);
 
 
-        when(articleService.getAdminList(isNull(), isNull(), isNull(), eq(1), eq(20)))
+        when(articleService.getAdminList(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), eq(1), eq(20)))
             .thenReturn(mockPage);
             .thenReturn(mockPage);
 
 
         Result<Page<Article>> result = controller.list(body);
         Result<Page<Article>> result = controller.list(body);
@@ -71,7 +71,7 @@ public class AdminArticleControllerTest {
         body.put("page", 1);
         body.put("page", 1);
         body.put("size", 10);
         body.put("size", 10);
 
 
-        when(articleService.getAdminList(eq("draft"), eq(2L), eq("测试"), eq(1), eq(10)))
+        when(articleService.getAdminList(eq("draft"), eq(2L), eq("测试"), isNull(), isNull(), isNull(), isNull(), eq(1), eq(10)))
             .thenReturn(new Page<>());
             .thenReturn(new Page<>());
 
 
         Result<Page<Article>> result = controller.list(body);
         Result<Page<Article>> result = controller.list(body);
@@ -82,7 +82,7 @@ public class AdminArticleControllerTest {
     public void adminList_DefaultPagination() {
     public void adminList_DefaultPagination() {
         Map<String, Object> body = new HashMap<>();
         Map<String, Object> body = new HashMap<>();
 
 
-        when(articleService.getAdminList(isNull(), isNull(), isNull(), eq(1), eq(20)))
+        when(articleService.getAdminList(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), eq(1), eq(20)))
             .thenReturn(new Page<>());
             .thenReturn(new Page<>());
 
 
         Result<Page<Article>> result = controller.list(body);
         Result<Page<Article>> result = controller.list(body);
@@ -109,10 +109,15 @@ public class AdminArticleControllerTest {
 
 
     @Test
     @Test
     public void adminUpdate_Success() {
     public void adminUpdate_Success() {
-        Article article = mockArticle(1L, "更新标题", "published");
-        doNothing().when(articleService).update(article);
+Map<String, Object> body = new HashMap<>();
+        body.put("id", 1L);
+        body.put("title", "更新标题");
+        body.put("content", "内容");
+        body.put("status", "published");
+
+        doNothing().when(articleService).update(any(Article.class));
 
 
-        Result<String> result = controller.update(article);
+        Result<String> result = controller.update(body);
         assertEquals(200, result.getCode());
         assertEquals(200, result.getCode());
         assertEquals("更新成功", result.getData());
         assertEquals("更新成功", result.getData());
     }
     }

+ 9 - 5
cfc-backend/src/test/java/com/etotem/cfc/controller/ArticleAdminControllerTest.java

@@ -80,7 +80,7 @@ public class ArticleAdminControllerTest {
         Page<Article> page = new Page<>(1, 20, 2);
         Page<Article> page = new Page<>(1, 20, 2);
         page.setRecords(records);
         page.setRecords(records);
 
 
-        when(articleService.getAdminList(isNull(), isNull(), isNull(), eq(1), eq(20)))
+        when(articleService.getAdminList(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), eq(1), eq(20)))
             .thenReturn(page);
             .thenReturn(page);
 
 
         Result<Page<Article>> result = controller.list(body);
         Result<Page<Article>> result = controller.list(body);
@@ -103,7 +103,7 @@ public class ArticleAdminControllerTest {
         Page<Article> page = new Page<>(1, 10, 1);
         Page<Article> page = new Page<>(1, 10, 1);
         page.setRecords(records);
         page.setRecords(records);
 
 
-        when(articleService.getAdminList(eq("published"), eq(2L), eq("健康"), eq(1), eq(10)))
+        when(articleService.getAdminList(eq("published"), eq(2L), eq("健康"), isNull(), isNull(), isNull(), isNull(), eq(1), eq(10)))
             .thenReturn(page);
             .thenReturn(page);
 
 
         Result<Page<Article>> result = controller.list(body);
         Result<Page<Article>> result = controller.list(body);
@@ -118,7 +118,7 @@ public class ArticleAdminControllerTest {
         Page<Article> page = new Page<>(1, 20, 0);
         Page<Article> page = new Page<>(1, 20, 0);
         page.setRecords(Collections.emptyList());
         page.setRecords(Collections.emptyList());
 
 
-        when(articleService.getAdminList(isNull(), isNull(), isNull(), eq(1), eq(20)))
+        when(articleService.getAdminList(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), eq(1), eq(20)))
             .thenReturn(page);
             .thenReturn(page);
 
 
         Result<Page<Article>> result = controller.list(body);
         Result<Page<Article>> result = controller.list(body);
@@ -146,11 +146,15 @@ public class ArticleAdminControllerTest {
 
 
     @Test
     @Test
     public void update_Success() {
     public void update_Success() {
-        Article article = mockArticle(1L, "更新后的文章", "published", 0);
+        Map<String, Object> body = new HashMap<>();
+        body.put("id", 1L);
+        body.put("title", "更新后的文章");
+        body.put("content", "新内容");
+        body.put("status", "published");
 
 
         doNothing().when(articleService).update(any(Article.class));
         doNothing().when(articleService).update(any(Article.class));
 
 
-        Result<String> result = controller.update(article);
+        Result<String> result = controller.update(body);
         assertEquals(200, result.getCode());
         assertEquals(200, result.getCode());
         assertEquals("更新成功", result.getData());
         assertEquals("更新成功", result.getData());
         verify(articleService).update(any(Article.class));
         verify(articleService).update(any(Article.class));

+ 2 - 2
cfc-backend/src/test/java/com/etotem/cfc/service/ArticleServiceTest.java

@@ -196,7 +196,7 @@ public class ArticleServiceTest {
                 return page;
                 return page;
             });
             });
 
 
-        Page<Article> result = articleService.getAdminList(null, null, null, 1, 20);
+        Page<Article> result = articleService.getAdminList(null, null, null, null, null, null, null, 1, 20);
         assertEquals(1, result.getRecords().size());
         assertEquals(1, result.getRecords().size());
     }
     }
 
 
@@ -210,7 +210,7 @@ public class ArticleServiceTest {
                 return page;
                 return page;
             });
             });
 
 
-        Page<Article> result = articleService.getAdminList("draft", null, null, 1, 20);
+        Page<Article> result = articleService.getAdminList("draft", null, null, null, null, null, null, 1, 20);
         assertEquals(1, result.getRecords().size());
         assertEquals(1, result.getRecords().size());
     }
     }