diff --git a/CHANGELOG.md b/CHANGELOG.md index 10fa292e..b9682dcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/example-context/example-service/example-healthcheck/pom.xml b/example-context/example-service/example-healthcheck/pom.xml new file mode 100644 index 00000000..01bbbcdc --- /dev/null +++ b/example-context/example-service/example-healthcheck/pom.xml @@ -0,0 +1,49 @@ + + + + example-service + uk.gov.justice.services.example + 11.0.0-M1-SNAPSHOT + + 4.0.0 + + example-healthcheck + + + + javax + javaee-api + provided + + + uk.gov.justice.services + framework-healthcheck + ${framework.version} + + + uk.gov.justice.event-store + healthchecks + ${event-store.version} + + + + + junit + junit + test + + + org.mockito + mockito-core + test + + + org.hamcrest + hamcrest-library + test + + + + \ No newline at end of file diff --git a/example-context/example-service/example-healthcheck/src/main/java/uk/gov/justice/services/example/cakeshop/healthcheck/CakeShopIgnoredHealthcheckNamesProvider.java b/example-context/example-service/example-healthcheck/src/main/java/uk/gov/justice/services/example/cakeshop/healthcheck/CakeShopIgnoredHealthcheckNamesProvider.java new file mode 100644 index 00000000..e1100cf3 --- /dev/null +++ b/example-context/example-service/example-healthcheck/src/main/java/uk/gov/justice/services/example/cakeshop/healthcheck/CakeShopIgnoredHealthcheckNamesProvider.java @@ -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 getNamesOfIgnoredHealthChecks() { + return singletonList(JOB_STORE_HEALTHCHECK_NAME); + } +} diff --git a/example-context/example-service/example-healthcheck/src/main/resources/META-INF/beans.xml b/example-context/example-service/example-healthcheck/src/main/resources/META-INF/beans.xml new file mode 100644 index 00000000..a0aaf442 --- /dev/null +++ b/example-context/example-service/example-healthcheck/src/main/resources/META-INF/beans.xml @@ -0,0 +1,8 @@ + + + + diff --git a/example-context/example-service/example-healthcheck/src/test/java/uk/gov/justice/services/example/cakeshop/healthcheck/CakeShopIgnoredHealthcheckNamesProviderTest.java b/example-context/example-service/example-healthcheck/src/test/java/uk/gov/justice/services/example/cakeshop/healthcheck/CakeShopIgnoredHealthcheckNamesProviderTest.java new file mode 100644 index 00000000..027ad836 --- /dev/null +++ b/example-context/example-service/example-healthcheck/src/test/java/uk/gov/justice/services/example/cakeshop/healthcheck/CakeShopIgnoredHealthcheckNamesProviderTest.java @@ -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 ignoredHealthChecks = ignoredHealthcheckNamesProvider.getNamesOfIgnoredHealthChecks(); + + assertThat(ignoredHealthChecks.size(), is(1)); + assertThat(ignoredHealthChecks.get(0), is(JOB_STORE_HEALTHCHECK_NAME)); + } +} \ No newline at end of file diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/HealthcheckIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/HealthcheckIT.java new file mode 100644 index 00000000..96124adc --- /dev/null +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/HealthcheckIT.java @@ -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)); + } +} diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/params/CakeShopUris.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/params/CakeShopUris.java index 2cc1d7d9..89aacca3 100644 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/params/CakeShopUris.java +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/params/CakeShopUris.java @@ -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"; diff --git a/example-context/example-service/example-single/pom.xml b/example-context/example-service/example-single/pom.xml index ebfebf86..1f603dde 100644 --- a/example-context/example-service/example-single/pom.xml +++ b/example-context/example-service/example-single/pom.xml @@ -91,6 +91,21 @@ event-store-management-command-handler-extension ${event-store.version} + + uk.gov.justice.event-store + healthchecks + ${event-store.version} + + + uk.gov.justice.services + framework-healthcheck + ${framework.version} + + + uk.gov.justice.services.example + example-healthcheck + ${project.version} + diff --git a/example-context/pom.xml b/example-context/pom.xml index 92ee35b1..b9481958 100644 --- a/example-context/pom.xml +++ b/example-context/pom.xml @@ -17,5 +17,6 @@ example-domain example-persistence example-service + example-service/example-healthcheck diff --git a/pom.xml b/pom.xml index f0ac6bc3..ba4e6cf8 100644 --- a/pom.xml +++ b/pom.xml @@ -34,9 +34,9 @@ 20.0.1.Final 2.0.2.Final - 11.0.0-M8 - 11.0.0-M7 - 11.0.0-M9 + 11.0.0-M13 + 11.0.0-M10 + 11.0.0-M11