test: /actuator/health endpoint
This commit is contained in:
parent
a7c0713d31
commit
2b9b668a2f
9 changed files with 126 additions and 4 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -37,3 +37,5 @@ out/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
*.tar
|
*.tar
|
||||||
|
.direnv/
|
||||||
|
.envrc
|
||||||
2
Makefile
2
Makefile
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
# --- Variables ---
|
# --- Variables ---
|
||||||
IMAGE_NAME := ilp-coursework
|
IMAGE_NAME := ilp-coursework
|
||||||
IMAGE_TAG := 0.1
|
IMAGE_TAG := 0.2
|
||||||
FULL_IMAGE_NAME := ${IMAGE_NAME}:${IMAGE_TAG}
|
FULL_IMAGE_NAME := ${IMAGE_NAME}:${IMAGE_TAG}
|
||||||
CONTAINER_NAME := ilp-coursework-app
|
CONTAINER_NAME := ilp-coursework-app
|
||||||
SUBMISSION_FILE := ilp_submission_image.tar
|
SUBMISSION_FILE := ilp_submission_image.tar
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,9 @@
|
||||||
in {
|
in {
|
||||||
default = pkgs.mkShell {
|
default = pkgs.mkShell {
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
|
vscode-langservers-extracted
|
||||||
jdt-language-server
|
jdt-language-server
|
||||||
|
jless
|
||||||
jdk21
|
jdk21
|
||||||
gradle
|
gradle
|
||||||
httpie
|
httpie
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
package io.github.js0ny.ilp_coursework.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import io.github.js0ny.ilp_coursework.service.DroneInfoService;
|
||||||
|
import io.github.js0ny.ilp_coursework.data.DroneDto;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1")
|
||||||
|
public class DroneController {
|
||||||
|
private final DroneInfoService droneService;
|
||||||
|
private final String baseUrl;
|
||||||
|
private final RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
public DroneController(DroneInfoService droneService) {
|
||||||
|
this.droneService = droneService;
|
||||||
|
String baseUrl = System.getenv("ILP_ENDPOINT");
|
||||||
|
if (baseUrl == null || baseUrl.isBlank()) {
|
||||||
|
this.baseUrl = "https://ilp-rest-2025-bvh6e9hschfagrgy.ukwest-01.azurewebsites.net/";
|
||||||
|
} else {
|
||||||
|
if (!baseUrl.endsWith("/")) {
|
||||||
|
baseUrl += "/";
|
||||||
|
}
|
||||||
|
this.baseUrl = baseUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/dronesWithCooling/{state}")
|
||||||
|
|
||||||
|
public int[] getDronesWithCoolingAbility(@PathVariable boolean state) {
|
||||||
|
|
||||||
|
String droneUrl = baseUrl + "drones";
|
||||||
|
|
||||||
|
DroneDto[] drones = restTemplate.getForObject(droneUrl, DroneDto[].class);
|
||||||
|
|
||||||
|
if (drones == null) {
|
||||||
|
return new int[]{};
|
||||||
|
}
|
||||||
|
|
||||||
|
return Arrays.stream(drones).
|
||||||
|
filter(drone -> drone.capability().cooling() == state).
|
||||||
|
mapToInt(drone -> Integer.parseInt(String.valueOf(drone.id()))).
|
||||||
|
toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("queryAvailableDrones")
|
||||||
|
public int queryAvailableDrones() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package io.github.js0ny.ilp_coursework.data;
|
||||||
|
|
||||||
|
public record DroneCapabilityDto(
|
||||||
|
boolean cooling,
|
||||||
|
boolean heating,
|
||||||
|
float capacity,
|
||||||
|
int maxMoves,
|
||||||
|
float costPerMove,
|
||||||
|
float costInitial,
|
||||||
|
float costFinal) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package io.github.js0ny.ilp_coursework.data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the data transfer object for a drone, gained from the endpoints
|
||||||
|
*/
|
||||||
|
public record DroneDto(
|
||||||
|
String name,
|
||||||
|
int id,
|
||||||
|
DroneCapabilityDto capability) {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package io.github.js0ny.ilp_coursework.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DroneInfoService {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
package io.github.js0ny.ilp_coursework.service;
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
package io.github.js0ny.ilp_coursework;
|
||||||
|
|
||||||
|
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.AutoConfigureMockMvc;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@AutoConfigureMockMvc
|
||||||
|
public class ActuatorHealthTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("GET /actuator/health -> 200 OK")
|
||||||
|
void getActuator_shouldReturn200AndON() throws Exception {
|
||||||
|
String endpoint = "/actuator/health";
|
||||||
|
String expected = """
|
||||||
|
{
|
||||||
|
"status": "UP"
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
var mock = mockMvc.perform(get(endpoint));
|
||||||
|
mock.andDo(print());
|
||||||
|
mock.andExpect(status().isOk());
|
||||||
|
mock.andExpect(content().json(expected));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue