Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
plugins {
id 'java'
id 'idea'
id 'org.springframework.boot' version '2.1.8.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
}
group 'com.octo.skool13'
sourceCompatibility = 11
repositories {
mavenCentral()
}
dependencies {
// Web
implementation 'org.springframework.boot:spring-boot-starter-web'
// Tests
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'junit:junit:4.12'
}
@RestController
public class HealthcheckApi {
private final SayImAlive sayImAlive;
public HealthcheckApi(SayImAlive sayImAlive) {
this.sayImAlive = sayImAlive;
}
@RequestMapping(value = "/healthcheck")
public Boolean healthcheck() {
return sayImAlive.execute();
}
}
package com.octo.skool13.infra;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class HealthcheckApiTest {
@Autowired
private MockMvc mvc;
@Test
public void isAlive() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/healthcheck"))
.andExpect(status().isOk())
.andExpect(content().string("true"));
}
}
package com.octo.skool13;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ManageoApplication {
public static void main(String[] args) {
SpringApplication.run(ManageoApplication.class, args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment