erp-test-suite / src /test /java /com /erp /system /SpringBootResilienceIntegrationTest.java
cronjob-python's picture
Deploy bc3ca8b2da9e8965989188ae78089a0cf381833f
dc510b0 verified
Raw History Blame Contribute Delete
2.54 kB
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<Map> 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<Map> 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<Map> 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<Map> response = restTemplate.getForEntity("/ping", Map.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertNotNull(response.getBody());
assertEquals("pong", response.getBody().get("message"));
}
}