diff --git a/src/main/java/OTO/comum/seguranca/SecurityConfig.java b/src/main/java/OTO/comum/seguranca/SecurityConfig.java index db44481..572f02d 100644 --- a/src/main/java/OTO/comum/seguranca/SecurityConfig.java +++ b/src/main/java/OTO/comum/seguranca/SecurityConfig.java @@ -44,6 +44,7 @@ public class SecurityConfig { "/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html", + "/health", "/error" }; diff --git a/src/main/java/OTO/comum/web/HealthController.java b/src/main/java/OTO/comum/web/HealthController.java new file mode 100644 index 0000000..4c7528b --- /dev/null +++ b/src/main/java/OTO/comum/web/HealthController.java @@ -0,0 +1,14 @@ +package OTO.comum.web; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +/** verificação de saúde usada pela hospedagem (Render) para saber se a aplicação subiu. Sem login. */ +@RestController +public class HealthController { + + @GetMapping("/health") + public String health() { + return "ok"; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f5476f7..2bf9bcf 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,8 @@ spring.application.name=OTOProject +# --- porta (o Render define PORT; localmente fica 8080) +server.port=${PORT:8080} + # --- banco de dados (PostgreSQL) spring.config.import=optional:file:.env[.properties] spring.datasource.url=jdbc:postgresql://${DB_HOST:localhost}:${DB_PORT:5433}/${POSTGRES_DB} diff --git a/src/test/java/OTO/comum/web/HealthControllerTest.java b/src/test/java/OTO/comum/web/HealthControllerTest.java new file mode 100644 index 0000000..b0a78ab --- /dev/null +++ b/src/test/java/OTO/comum/web/HealthControllerTest.java @@ -0,0 +1,28 @@ +package OTO.comum.web; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.web.servlet.MockMvc; + +import OTO.SegurancaDeTeste; + +@WebMvcTest(HealthController.class) +@Import(SegurancaDeTeste.class) +class HealthControllerTest { + + @Autowired + private MockMvc mvc; + + @Test + void respondeSemLogin() throws Exception { + mvc.perform(get("/health")) + .andExpect(status().isOk()) + .andExpect(content().string("ok")); + } +}