Skip to content

Commit

Permalink
Generate health check code
Browse files Browse the repository at this point in the history
  • Loading branch information
cheolwon1994 committed Nov 5, 2023
1 parent cdcdfb4 commit 9dee918
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.catcher.batch.resource;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
@RequestMapping("/health")
public class HealthCheckController {

@GetMapping
public ResponseEntity<String> healthCheck(){
return ResponseEntity.ok("ok");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.catcher.batch.resource;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@WebMvcTest(
value = HealthCheckController.class,
excludeAutoConfiguration = {SecurityAutoConfiguration.class}
)
class HealthCheckControllerTest {

@Autowired
private MockMvc mockMvc;

@DisplayName("Health check 검사가 성공적으로 반환된다")
@Test
void health_check_and_receive_ok() throws Exception {
//given

//when
ResultActions resultActions = mockMvc.perform(
MockMvcRequestBuilders
.get("/health")
.contentType(MediaType.APPLICATION_JSON)
);

//Then
resultActions.andExpect(status().isOk());
}
}

0 comments on commit 9dee918

Please sign in to comment.