Skip to content

Commit

Permalink
Merge f2de5bc into 47f1f2c
Browse files Browse the repository at this point in the history
  • Loading branch information
allanmckenzie committed Mar 23, 2022
2 parents 47f1f2c + f2de5bc commit c89cb43
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to
- Update to event-store 11.0.0-M1
- Bumped the base version of the project to 11.0.0 to match the framework libraries and show java 11 change
- Handled the move to the new Cloudsmith.io maven repository
### Added
- Added support for feature toggling with an integration test showing it working
- Added healthcheck integration test

## [2.0.0] - 2019-08-19
### Added
Expand Down
49 changes: 49 additions & 0 deletions example-context/example-service/example-healthcheck/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>example-service</artifactId>
<groupId>uk.gov.justice.services.example</groupId>
<version>11.0.0-M1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>example-healthcheck</artifactId>

<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>framework-healthcheck</artifactId>
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>healthchecks</artifactId>
<version>${event-store.version}</version>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package uk.gov.justice.services.example.cakeshop.healthcheck;

import static java.util.Collections.singletonList;
import static uk.gov.justice.services.healthcheck.healthchecks.JobStoreHealthcheck.JOB_STORE_HEALTHCHECK_NAME;

import uk.gov.justice.services.healthcheck.api.DefaultIgnoredHealthcheckNamesProvider;
import uk.gov.justice.services.healthcheck.healthchecks.JobStoreHealthcheck;

import java.util.List;

import javax.enterprise.inject.Specializes;

@Specializes
public class CakeShopIgnoredHealthcheckNamesProvider extends DefaultIgnoredHealthcheckNamesProvider {

public CakeShopIgnoredHealthcheckNamesProvider() {}

@Override
public List<String> getNamesOfIgnoredHealthChecks() {
return singletonList(JOB_STORE_HEALTHCHECK_NAME);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- Marker file indicating CDI should be enabled -->

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="
http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="all">
</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package uk.gov.justice.services.example.cakeshop.healthcheck;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static uk.gov.justice.services.healthcheck.healthchecks.JobStoreHealthcheck.JOB_STORE_HEALTHCHECK_NAME;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class CakeShopIgnoredHealthcheckNamesProviderTest {

@InjectMocks
private CakeShopIgnoredHealthcheckNamesProvider ignoredHealthcheckNamesProvider;

@Test
public void shouldGetListOfAllHealthchecksToIgnore() throws Exception {

final List<String> ignoredHealthChecks = ignoredHealthcheckNamesProvider.getNamesOfIgnoredHealthChecks();

assertThat(ignoredHealthChecks.size(), is(1));
assertThat(ignoredHealthChecks.get(0), is(JOB_STORE_HEALTHCHECK_NAME));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package uk.gov.justice.services.example.cakeshop.it;

import static com.jayway.jsonassert.JsonAssert.with;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static uk.gov.justice.services.example.cakeshop.it.params.CakeShopUris.HEALTHCHECK_URI;

import uk.gov.justice.services.example.cakeshop.it.helpers.RestEasyClientFactory;

import javax.ws.rs.client.Client;
import javax.ws.rs.core.Response;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HealthcheckIT {

private static final Logger LOGGER = LoggerFactory.getLogger(HealthcheckIT.class);

private final Client client = new RestEasyClientFactory().createResteasyClient();

@Test
public void shouldSuccessfullyCallHealthcheckServlet() throws Exception {

final String healthcheckUri = HEALTHCHECK_URI;

LOGGER.info("Making request to '" + healthcheckUri + "'");
final Response response = client.target(healthcheckUri)
.request()
.get();

final String healthcheckJson = response.readEntity(String.class);
LOGGER.info(healthcheckJson);

assertThat(response.getStatus(), is(200));
with(healthcheckJson).assertThat("$.allHealthchecksPassed", is(true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class CakeShopUris {
public static final String CAKES_RESOURCE_QUERY_URI = HOST + "/example-query-api/query/api/rest/cakeshop/cakes/";
public static final String OVEN_RESOURCE_CUSTOM_URI = HOST + "/example-custom-api/custom/api/rest/cakeshop/ovens/";
public static final String INDEXES_RESOURCE_QUERY_URI = HOST + "/example-query-api/query/api/rest/cakeshop/index/";
public static final String HEALTHCHECK_URI = HOST + "/example-single/internal/healthchecks/all";


public static final String CAKES_RESOURCE_URI_FORMAT = RECIPES_RESOURCE_URI + "%s/cakes/%s";
Expand Down
15 changes: 15 additions & 0 deletions example-context/example-service/example-single/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@
<artifactId>event-store-management-command-handler-extension</artifactId>
<version>${event-store.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.event-store</groupId>
<artifactId>healthchecks</artifactId>
<version>${event-store.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>framework-healthcheck</artifactId>
<version>${framework.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.justice.services.example</groupId>
<artifactId>example-healthcheck</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Test Dependencies -->
<dependency>
Expand Down
1 change: 1 addition & 0 deletions example-context/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
<module>example-domain</module>
<module>example-persistence</module>
<module>example-service</module>
<module>example-service/example-healthcheck</module>
</modules>
</project>
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
<wildfly.version>20.0.1.Final</wildfly.version>
<wildfly.maven.plugin.version>2.0.2.Final</wildfly.maven.plugin.version>

<framework-libraries.version>11.0.0-M8</framework-libraries.version>
<framework.version>11.0.0-M7</framework.version>
<event-store.version>11.0.0-M9</event-store.version>
<framework-libraries.version>11.0.0-M13</framework-libraries.version>
<framework.version>11.0.0-M10</framework.version>
<event-store.version>11.0.0-M11</event-store.version>
</properties>

<dependencyManagement>
Expand Down

0 comments on commit c89cb43

Please sign in to comment.