From aa666bd8472d0ee64e5d1cbac3ee95609a2fd361 Mon Sep 17 00:00:00 2001 From: dongHyo Date: Fri, 6 May 2022 13:49:06 +0900 Subject: [PATCH] =?UTF-8?q?test:=20health=20check=20test=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/health/L7checkControllerTest.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 server/src/test/java/com/ticketing/server/global/health/L7checkControllerTest.java diff --git a/server/src/test/java/com/ticketing/server/global/health/L7checkControllerTest.java b/server/src/test/java/com/ticketing/server/global/health/L7checkControllerTest.java new file mode 100644 index 0000000..3a1ccf4 --- /dev/null +++ b/server/src/test/java/com/ticketing/server/global/health/L7checkControllerTest.java @@ -0,0 +1,51 @@ +package com.ticketing.server.global.health; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.concurrent.TimeUnit; +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.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class L7checkControllerTest { + + private static final String L7CHECK = "/l7check"; + private static final String HEALTH = "/actuator/health"; + + @Autowired + TestRestTemplate restTemplate; + + @Test + void downAndUp() throws InterruptedException { + // before + expectUrlStatus(L7CHECK, HttpStatus.OK); + expectUrlStatus(HEALTH, HttpStatus.OK); + + // down + restTemplate.delete(L7CHECK); + + // then down + TimeUnit.MILLISECONDS.sleep(1000); + expectUrlStatus(L7CHECK, HttpStatus.SERVICE_UNAVAILABLE); + expectUrlStatus(HEALTH, HttpStatus.SERVICE_UNAVAILABLE); + + // up + restTemplate.postForEntity(L7CHECK, null, Object.class); + + // then up + TimeUnit.MILLISECONDS.sleep(1000); + expectUrlStatus(L7CHECK, HttpStatus.OK); + expectUrlStatus(HEALTH, HttpStatus.OK); + } + + private void expectUrlStatus(String url, HttpStatus status) { + ResponseEntity res = restTemplate.getForEntity(url, Object.class); + assertThat(res.getStatusCode()).isEqualTo(status); + } + +} \ No newline at end of file