From fb421e48ee173dad8f84e4c4c50bca107621ac95 Mon Sep 17 00:00:00 2001 From: ReaJason Date: Mon, 30 Dec 2024 23:20:16 +0800 Subject: [PATCH] fix: boot run failed --- boot/build.gradle | 6 ++- .../ConfigControllerIntegrationTest.java | 37 +++++++++++++++++++ .../boot/controller/ConfigControllerTest.java | 21 ----------- 3 files changed, 41 insertions(+), 23 deletions(-) create mode 100644 boot/src/test/java/com/reajason/javaweb/boot/controller/ConfigControllerIntegrationTest.java delete mode 100644 boot/src/test/java/com/reajason/javaweb/boot/controller/ConfigControllerTest.java diff --git a/boot/build.gradle b/boot/build.gradle index 5ee38eb4..410da5d4 100644 --- a/boot/build.gradle +++ b/boot/build.gradle @@ -51,8 +51,10 @@ dependencies { } implementation 'org.apache.bcel:bcel:5.2' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' - implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.springframework.boot:spring-boot-starter-tomcat' + implementation('org.springframework.boot:spring-boot-starter-web') { + exclude group:'org.springframework.boot', module:'spring-boot-starter-tomcat' + } + implementation 'org.springframework.boot:spring-boot-starter-undertow' implementation 'com.google.code.gson:gson:2.11.0' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' diff --git a/boot/src/test/java/com/reajason/javaweb/boot/controller/ConfigControllerIntegrationTest.java b/boot/src/test/java/com/reajason/javaweb/boot/controller/ConfigControllerIntegrationTest.java new file mode 100644 index 00000000..69d371f9 --- /dev/null +++ b/boot/src/test/java/com/reajason/javaweb/boot/controller/ConfigControllerIntegrationTest.java @@ -0,0 +1,37 @@ +package com.reajason.javaweb.boot.controller; + +import com.reajason.javaweb.boot.entity.Config; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * @author ReaJason + * @since 2024/12/13 + */ + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class ConfigControllerIntegrationTest { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + public void testConfigEndpoint() { + ResponseEntity response = restTemplate.getForEntity("/config", Config.class); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + + Config config = response.getBody(); + assertNotNull(config); + assertNotNull(config.getServers()); + assertNotNull(config.getCore()); + assertNotNull(config.getPackers()); + } +} \ No newline at end of file diff --git a/boot/src/test/java/com/reajason/javaweb/boot/controller/ConfigControllerTest.java b/boot/src/test/java/com/reajason/javaweb/boot/controller/ConfigControllerTest.java deleted file mode 100644 index de818e5b..00000000 --- a/boot/src/test/java/com/reajason/javaweb/boot/controller/ConfigControllerTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.reajason.javaweb.boot.controller; - -import org.junit.jupiter.api.Test; -import org.springframework.http.ResponseEntity; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -/** - * @author ReaJason - * @since 2024/12/13 - */ -class ConfigControllerTest { - @Test - void getConfig() { - ConfigController configController = new ConfigController(); - ResponseEntity config = configController.config(); - Object body = config.getBody(); - assertNotNull(body); - System.out.println(body); - } -} \ No newline at end of file