Spring / springboot-app 2 /src /test /java /com /example /demo /DemoApplicationTests.java
AI-RESEARCHER-2024's picture
Upload 9 files
26f6e80 verified
package com.example.demo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.hamcrest.Matchers.*;
@SpringBootTest
@AutoConfigureMockMvc
class DemoApplicationTests {
@Autowired
private MockMvc mockMvc;
@Test
void contextLoads() {
}
@Test
void testHomeEndpoint() throws Exception {
mockMvc.perform(get("/api/"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.message").value("Welcome to Spring Boot on Hugging Face!"))
.andExpect(jsonPath("$.status").value("running"));
}
@Test
void testGreetingEndpoint() throws Exception {
mockMvc.perform(get("/api/greeting").param("name", "Test"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.greeting").value("Hello, Test!"));
}
@Test
void testHealthEndpoint() throws Exception {
mockMvc.perform(get("/api/health"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.status").value("UP"));
}
}