Skip to content

Commit

Permalink
Merge pull request #4 from everymeals/chore/project-setting
Browse files Browse the repository at this point in the history
[chore/project-setting] #1, #2 설정 테스트를 위한 Health-Check API 개발
  • Loading branch information
dldmsql committed Jul 9, 2023
2 parents eca6c77 + a6392e0 commit c3a6f49
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ sonar {
property 'sonar.sources', 'src'
property 'sonar.language', 'java'
property 'sonar.sourceEncoding', 'UTF-8'
property "sonar.exclusions", "**/*Application*.java"
property("sonar.test.inclusions", "**/*Test.kt")
property "sonar.exclusions", "**/test/**, **/*Application*.java"
property "sonar.java.coveragePlugin", "jacoco"
property 'sonar.coverage.jacoco.xmlReportPaths', 'build/reports/jacoco/test/jacocoTestReport.xml'
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/everymeal/server/infra/HealthCheckController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package everymeal.server.infra;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@GetMapping
public String healthCheck() {
return "Server is Up!";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package everymeal.server.infra;

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 everymeal.server.infra.HealthCheckController;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.web.servlet.MockMvc;

@WebMvcTest(HealthCheckController.class)
class HealthCheckControllerTest {

@Autowired
MockMvc mvc;

@Test
@DisplayName("health-check")
void healthCheck() throws Exception {
//given
String hello = "Server is Up!";
//when

//then
mvc.perform(get("/health-check"))
.andExpect(status().isOk())
.andExpect(content().string(hello));
}
}

0 comments on commit c3a6f49

Please sign in to comment.