初始化
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package com.example.training;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.example.training.controller.HealthController;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(HealthController.class)
|
||||
@ActiveProfiles("test")
|
||||
class TrainingApplicationTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Test
|
||||
void healthEndpointReturnsUp() throws Exception {
|
||||
mockMvc.perform(get("/api/health"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.status").value("UP"))
|
||||
.andExpect(jsonPath("$.service").value("training-backend"));
|
||||
}
|
||||
}
|
||||
20
backend/src/test/resources/application-test.yml
Normal file
20
backend/src/test/resources/application-test.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
spring:
|
||||
config:
|
||||
activate:
|
||||
on-profile: test
|
||||
datasource:
|
||||
url: jdbc:h2:mem:training-test;MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
|
||||
username: sa
|
||||
password:
|
||||
driver-class-name: org.h2.Driver
|
||||
sql:
|
||||
init:
|
||||
mode: never
|
||||
|
||||
server:
|
||||
port: 0
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.example.training: INFO
|
||||
org.springframework: WARN
|
||||
Reference in New Issue
Block a user