package com.erp.system; 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 java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { "app.seeding.enabled=false", "app.self-ping.fixed-rate-ms=3600000" } ) public class SpringBootResilienceIntegrationTest { @Autowired private TestRestTemplate restTemplate; @Test public void testContextLoadsAndHealthEndpointResponds() { ResponseEntity response = restTemplate.getForEntity("/health", Map.class); assertEquals(HttpStatus.OK, response.getStatusCode()); assertNotNull(response.getBody()); assertTrue(response.getBody().containsKey("status")); assertTrue(response.getBody().containsKey("databases")); } @Test public void testPostgresEndpointReturns503WhenUnreachable() { ResponseEntity response = restTemplate.getForEntity("/api/erp/postgres", Map.class); assertEquals(HttpStatus.SERVICE_UNAVAILABLE, response.getStatusCode()); assertNotNull(response.getBody()); assertEquals(503, response.getBody().get("status")); assertEquals("Service Unavailable", response.getBody().get("error")); assertTrue(response.getBody().get("diagnostic").toString().contains("DNS resolution failure")); } @Test public void testRootEndpointReturns200() { ResponseEntity response = restTemplate.getForEntity("/", Map.class); assertEquals(HttpStatus.OK, response.getStatusCode()); assertNotNull(response.getBody()); assertEquals("ERP System", response.getBody().get("application")); assertEquals("running", response.getBody().get("status")); } @Test public void testPingEndpointReturns200() { ResponseEntity response = restTemplate.getForEntity("/ping", Map.class); assertEquals(HttpStatus.OK, response.getStatusCode()); assertNotNull(response.getBody()); assertEquals("pong", response.getBody().get("message")); } }