Skip to content

Commit e2b7291

Browse files
committed
Add Health checks
1 parent da8b003 commit e2b7291

File tree

7 files changed

+113
-1
lines changed

7 files changed

+113
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>com.systelab</groupId>
77
<artifactId>seed</artifactId>
88
<packaging>war</packaging>
9-
<version>2.0</version>
9+
<version>2.1</version>
1010
<name>seed</name>
1111

1212
<properties>

src/main/java/com/systelab/seed/SeedApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.systelab.seed;
22

33
import com.systelab.seed.infrastructure.auth.TokenAuthenticationFilter;
4+
import com.systelab.seed.resource.HealthResource;
45
import com.systelab.seed.resource.PatientResource;
56
import com.systelab.seed.resource.UserResource;
67
import com.systelab.seed.util.security.CORSFilter;
@@ -38,6 +39,7 @@ public Set<Class<?>> getClasses() {
3839

3940
resources.add(PatientResource.class);
4041
resources.add(UserResource.class);
42+
resources.add(HealthResource.class);
4143

4244
resources.add(CORSFilter.class);
4345
resources.add(TokenAuthenticationFilter.class);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.systelab.seed.resource;
2+
3+
import io.swagger.annotations.Api;
4+
import io.swagger.annotations.ApiOperation;
5+
import io.swagger.annotations.ApiResponse;
6+
import io.swagger.annotations.ApiResponses;
7+
8+
import javax.annotation.security.PermitAll;
9+
import javax.ws.rs.GET;
10+
import javax.ws.rs.Path;
11+
import javax.ws.rs.Produces;
12+
import javax.ws.rs.core.MediaType;
13+
import javax.ws.rs.core.Response;
14+
15+
@Api(value = "Health")
16+
17+
@Path("health")
18+
@Produces({MediaType.TEXT_PLAIN})
19+
public class HealthResource {
20+
21+
@ApiOperation(value = "Check Health", notes = "")
22+
@ApiResponses(value = {@ApiResponse(code = 200, message = "Healthy"), @ApiResponse(code = 500, message = "Internal Server Error")})
23+
24+
@GET
25+
@PermitAll
26+
public Response checkHealth() {
27+
try {
28+
return Response.ok().build();
29+
} catch (Exception ex) {
30+
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
31+
}
32+
}
33+
34+
}

src/test/java/com/systelab/seed/bdd/PatientSearchSteps.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import cucumber.api.java.en.Given;
99
import cucumber.api.java.en.Then;
1010
import cucumber.api.java.en.When;
11+
import io.qameta.allure.Feature;
12+
import org.junit.jupiter.api.DisplayName;
1113

1214
import java.util.ArrayList;
1315
import java.util.Date;
@@ -16,6 +18,9 @@
1618
/**
1719
* Class that defines the expected behavior for BDD Test following Gherkin language
1820
*/
21+
22+
@Feature("Cucumber Test Suite")
23+
@DisplayName("Cucumber Test Suite")
1924
public class PatientSearchSteps {
2025

2126
private Hospital hospital = new Hospital();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.systelab.seed.client;
2+
3+
import com.systelab.seed.model.user.User;
4+
import io.qameta.allure.Step;
5+
6+
import java.util.List;
7+
8+
import javax.ws.rs.client.Entity;
9+
import javax.ws.rs.client.WebTarget;
10+
import javax.ws.rs.core.GenericType;
11+
import javax.ws.rs.core.HttpHeaders;
12+
import javax.ws.rs.core.MediaType;
13+
import javax.ws.rs.core.Response;
14+
15+
public class HealthClient extends BaseClient {
16+
17+
public void getHealth() throws RequestException {
18+
WebTarget target = getWebTarget().path("health");
19+
20+
Response response = target.request(MediaType.TEXT_PLAIN).get(Response.class);
21+
22+
if (response.getStatus() != 200) {
23+
throw new RequestException(response.getStatus());
24+
}
25+
}
26+
}

src/test/java/com/systelab/seed/rest/SeedRestTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.systelab.seed.rest;
22

3+
import io.qameta.allure.Feature;
34
import io.restassured.module.jsv.JsonSchemaValidator;
45
import io.restassured.response.Response;
56
import org.junit.jupiter.api.*;
@@ -15,6 +16,9 @@
1516
* Note: See FunctionalTest parent class to understand how to obtain the rest entry endpoint
1617
* Note: Consider to change the method naming to pass Codacy checks
1718
*/
19+
20+
@Feature("Rest Assured Test Suite")
21+
@DisplayName("Rest Assureddocker-compose Test Suite")
1822
public class SeedRestTest extends FunctionalTest {
1923

2024
@Test
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.systelab.seed.unit;
2+
3+
import com.systelab.seed.TestUtil;
4+
import com.systelab.seed.client.HealthClient;
5+
import com.systelab.seed.client.RequestException;
6+
import io.qameta.allure.*;
7+
import org.junit.jupiter.api.BeforeAll;
8+
import org.junit.jupiter.api.DisplayName;
9+
import org.junit.jupiter.api.Tag;
10+
import org.junit.jupiter.api.Test;
11+
12+
13+
@TmsLink("TC0003_HealthManagement_IntegrationTest")
14+
@Feature("Check that the service is healthy by calling a REST endpoint.")
15+
@DisplayName("Health Check Test Suite")
16+
public class HealthClientTest extends BaseClientTest {
17+
18+
public static HealthClient clientForHealth;
19+
20+
@BeforeAll
21+
public static void init() throws RequestException {
22+
clientForHealth = new HealthClient();
23+
}
24+
25+
@DisplayName("Get the Health status")
26+
@Description("Action: Get the Health status and check that is OK.")
27+
@Tag("health")
28+
@Severity(SeverityLevel.BLOCKER)
29+
@Test
30+
public void testHealth() throws RequestException {
31+
32+
Exception caughtException = null;
33+
try {
34+
clientForHealth.getHealth();
35+
} catch (Exception ex) {
36+
caughtException = ex;
37+
}
38+
TestUtil.checkObjectIsNull("Exception", caughtException);
39+
}
40+
41+
}

0 commit comments

Comments
 (0)