-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Gepardec/mega#686] add tests for liveness util
- Loading branch information
Showing
2 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/test/java/com/gepardec/mega/application/utils/LivenessUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.gepardec.mega.application.utils; | ||
|
||
import com.gepardec.mega.application.health.LivenessUtil; | ||
import com.gepardec.mega.personio.PersonioHealthClient; | ||
import com.gepardec.mega.zep.rest.client.ZepHealthRestClient; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.mockito.InjectMock; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.core.Response; | ||
import org.eclipse.microprofile.health.HealthCheckResponse; | ||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.junit.jupiter.api.Test; | ||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.mockito.Mockito.when; | ||
|
||
@QuarkusTest | ||
public class LivenessUtilTest { | ||
@Inject | ||
LivenessUtil livenessUtil; | ||
|
||
@InjectMock | ||
@RestClient | ||
PersonioHealthClient personioHealthClient; | ||
|
||
@InjectMock | ||
@RestClient | ||
ZepHealthRestClient zepHealthRestClient; | ||
|
||
|
||
@Test | ||
void getResponseForPersonio_whenPersonioIsUp_returnHealthCheckResponseWithStatusUp() { | ||
when(personioHealthClient.health()).thenReturn(getOkResponse()); | ||
HealthCheckResponse actual = livenessUtil.getResponseForPersonio(); | ||
|
||
assertThat(actual.getName()).isEqualTo("Personio Liveness"); | ||
assertThat(actual.getStatus()).isEqualTo(HealthCheckResponse.Status.UP); | ||
} | ||
|
||
@Test | ||
void getResponseForPersonio_whenPersonioIsDown_returnHealthCheckResponseWithStatusDown() { | ||
when(personioHealthClient.health()).thenReturn(getErrorResponse()); | ||
HealthCheckResponse actual = livenessUtil.getResponseForPersonio(); | ||
|
||
assertThat(actual.getName()).isEqualTo("Personio Liveness"); | ||
assertThat(actual.getStatus()).isEqualTo(HealthCheckResponse.Status.DOWN); | ||
} | ||
|
||
@Test | ||
void getResponseForZep_whenZepIsUp_returnHealthCheckResponseWithStatusUp() { | ||
when(zepHealthRestClient.health()).thenReturn(getOkResponse()); | ||
HealthCheckResponse actual = livenessUtil.getResponseForZep(); | ||
|
||
assertThat(actual.getName()).isEqualTo("Zep Liveness"); | ||
assertThat(actual.getStatus()).isEqualTo(HealthCheckResponse.Status.UP); | ||
} | ||
|
||
@Test | ||
void getResponseForZep_whenZepIsDown_returnHealthCheckResponseWithStatusDown() { | ||
when(zepHealthRestClient.health()).thenReturn(getErrorResponse()); | ||
HealthCheckResponse actual = livenessUtil.getResponseForZep(); | ||
|
||
assertThat(actual.getName()).isEqualTo("Zep Liveness"); | ||
assertThat(actual.getStatus()).isEqualTo(HealthCheckResponse.Status.DOWN); | ||
} | ||
|
||
private Response getOkResponse() { | ||
return Response.ok().build(); | ||
} | ||
|
||
private Response getErrorResponse() { | ||
return Response.serverError().build(); | ||
} | ||
} |