Spaces:
No application file
No application file
| 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.*; | |
| class DemoApplicationTests { | |
| private MockMvc mockMvc; | |
| void contextLoads() { | |
| } | |
| 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")); | |
| } | |
| void testGreetingEndpoint() throws Exception { | |
| mockMvc.perform(get("/api/greeting").param("name", "Test")) | |
| .andExpect(status().isOk()) | |
| .andExpect(jsonPath("$.greeting").value("Hello, Test!")); | |
| } | |
| void testHealthEndpoint() throws Exception { | |
| mockMvc.perform(get("/api/health")) | |
| .andExpect(status().isOk()) | |
| .andExpect(jsonPath("$.status").value("UP")); | |
| } | |
| } | |