Skip to content
This repository was archived by the owner on Jun 6, 2024. It is now read-only.

Commit 13f2b04

Browse files
committed
Use minimal health endpoint and introduce status endpoint
1 parent 05df877 commit 13f2b04

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>ch.unisg.library.systemlibrarian</groupId>
66
<artifactId>alma-job-runner</artifactId>
7-
<version>1.0.1</version>
7+
<version>1.0.2</version>
88
<packaging>${packaging}</packaging>
99

1010
<parent>

src/main/java/ch/unisg/library/systemlibrarian/health/HealthController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public HealthController(
3030

3131
@Get(value = "/health", produces = MediaType.TEXT_PLAIN)
3232
public HttpResponse<String> health() {
33+
LOG.info("Health endpoint called, health OK");
34+
return HttpResponse.ok("OK");
35+
}
36+
37+
@Get(value = "/status", produces = MediaType.TEXT_PLAIN)
38+
public HttpResponse<String> status() {
3339
final List<String> issues = new ArrayList<>();
3440
if (ResponseStatus.ERROR == almaApiHttpClient.apiHealthCheck().responseStatus()) {
3541
issues.add("Alma API not available");

src/test/java/ch/unisg/library/systemlibrarian/health/HealthControllerTest.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ JobSchedulerService jobSchedulerService() {
3939
}
4040

4141
@Test
42-
void testHealthOk() {
42+
void testHealth(){
43+
HttpResponse<String> exchange = client.toBlocking().exchange(HttpRequest.GET("/health"), String.class);
44+
Assertions.assertEquals(200, exchange.code());
45+
Assertions.assertEquals("OK", exchange.body());
46+
}
47+
48+
@Test
49+
void testStatusOk() {
4350
// mock Alma API, with response healthy
4451
EmbeddedServer almaApiMockServer = ApplicationContext.run(
4552
EmbeddedServer.class,
@@ -52,14 +59,14 @@ void testHealthOk() {
5259
);
5360
// mock non empty joblist
5461
Mockito.when(jobSchedulerService.getScheduledJobs()).thenReturn(Set.of(Mockito.mock(JobConfig.class)));
55-
HttpResponse<String> exchange = client.toBlocking().exchange(HttpRequest.GET("/health"), String.class);
62+
HttpResponse<String> exchange = client.toBlocking().exchange(HttpRequest.GET("/status"), String.class);
5663
Assertions.assertEquals(200, exchange.code());
5764
Assertions.assertEquals("OK", exchange.body());
5865
almaApiMockServer.close();
5966
}
6067

6168
@Test
62-
void testHealthAlmaApiNotAvailable() {
69+
void testStatusAlmaApiNotAvailable() {
6370
// mock Alma API, with unsuccessful response
6471
EmbeddedServer almaApiMockServer = ApplicationContext.run(
6572
EmbeddedServer.class,
@@ -73,7 +80,7 @@ void testHealthAlmaApiNotAvailable() {
7380
// mock non empty joblist
7481
Mockito.when(jobSchedulerService.getScheduledJobs()).thenReturn(Set.of(Mockito.mock(JobConfig.class)));
7582
try {
76-
client.toBlocking().exchange(HttpRequest.GET("/health"), String.class);
83+
client.toBlocking().exchange(HttpRequest.GET("/status"), String.class);
7784
} catch (HttpClientResponseException e) {
7885
Assertions.assertEquals(500, e.getResponse().code());
7986
Assertions.assertEquals("Alma API not available", e.getResponse().body());
@@ -82,7 +89,7 @@ void testHealthAlmaApiNotAvailable() {
8289
}
8390

8491
@Test
85-
void testHealthNoJobs() {
92+
void testStatusNoJobs() {
8693
// mock Alma API, with response healthy
8794
EmbeddedServer almaApiMockServer = ApplicationContext.run(
8895
EmbeddedServer.class,
@@ -96,7 +103,7 @@ void testHealthNoJobs() {
96103
// mock empty joblist
97104
Mockito.when(jobSchedulerService.getScheduledJobs()).thenReturn(Set.of());
98105
try {
99-
client.toBlocking().exchange(HttpRequest.GET("/health"), String.class);
106+
client.toBlocking().exchange(HttpRequest.GET("/status"), String.class);
100107
} catch (HttpClientResponseException e) {
101108
Assertions.assertEquals(500, e.getResponse().code());
102109
Assertions.assertEquals("No jobs registered", e.getResponse().body());

0 commit comments

Comments
 (0)