diff --git a/example-context/example-service/example-it/pom.xml b/example-context/example-service/example-it/pom.xml index cdd81a6f..216affb7 100644 --- a/example-context/example-service/example-it/pom.xml +++ b/example-context/example-service/example-it/pom.xml @@ -116,194 +116,79 @@ test - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uk.gov.justice.services - jmx - test + org.wildfly + wildfly-client-all + ${wildfly.version} + + + org.jboss + jboss-ejb-client + + + org.jboss + jboss-remote-naming + + + org.jboss.logging + jboss-logging + + + org.jboss.marshalling + jboss-marshalling-river + + + org.jboss.remoting + jboss-remoting + + + org.jboss.sasl + jboss-sasl + + + org.jboss.spec.javax.ejb + jboss-ejb-api_3.2_spec + + + org.jboss.spec.javax.transaction + jboss-transaction-api_1.2_spec + + + org.jboss.xnio + xnio-api + + + org.jboss.xnio + xnio-nio + + + io.netty + netty-all + + + org.jgroups + jgroups + + + org.apache.activemq + artemis-core-client + + + org.apache.activemq + artemis-commons + + + org.apache.activemq + artemis-hqclient-protocol + + uk.gov.justice.services - test-utils-wildfly - ${framework.version} + jmx test - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopConcurrencyIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopConcurrencyIT.java index 9cb499d0..bbff2491 100644 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopConcurrencyIT.java +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopConcurrencyIT.java @@ -29,7 +29,6 @@ import javax.ws.rs.client.Client; -@Ignore public class CakeShopConcurrencyIT { private static final CakeShopRepositoryManager CAKE_SHOP_REPOSITORY_MANAGER = new CakeShopRepositoryManager(); diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopCrossOriginResourceSharingIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopCrossOriginResourceSharingIT.java index b36b938a..830012c8 100644 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopCrossOriginResourceSharingIT.java +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopCrossOriginResourceSharingIT.java @@ -16,7 +16,6 @@ import javax.ws.rs.client.Client; import javax.ws.rs.core.Response; -@Ignore public class CakeShopCrossOriginResourceSharingIT { private static final CakeShopRepositoryManager CAKE_SHOP_REPOSITORY_MANAGER = new CakeShopRepositoryManager(); diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopEventBufferingIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopEventBufferingIT.java index 14f907c8..a19cb563 100644 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopEventBufferingIT.java +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopEventBufferingIT.java @@ -20,7 +20,6 @@ import javax.ws.rs.client.Client; -@Ignore public class CakeShopEventBufferingIT { private static final CakeShopRepositoryManager CAKE_SHOP_REPOSITORY_MANAGER = new CakeShopRepositoryManager(); diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopFailuresIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopFailuresIT.java index 0c6bf431..16f62ee8 100644 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopFailuresIT.java +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopFailuresIT.java @@ -34,7 +34,6 @@ import org.apache.http.message.BasicNameValuePair; -@Ignore public class CakeShopFailuresIT { private static final CakeShopRepositoryManager CAKE_SHOP_REPOSITORY_MANAGER = new CakeShopRepositoryManager(); diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopFileServiceIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopFileServiceIT.java index e57afbb8..68044e32 100644 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopFileServiceIT.java +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopFileServiceIT.java @@ -42,7 +42,6 @@ import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.impl.client.HttpClients; -@Ignore public class CakeShopFileServiceIT { private static final CakeShopRepositoryManager CAKE_SHOP_REPOSITORY_MANAGER = new CakeShopRepositoryManager(); diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopFilteringIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopFilteringIT.java index 084f0285..dad4e49a 100644 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopFilteringIT.java +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopFilteringIT.java @@ -24,7 +24,6 @@ import org.apache.http.message.BasicNameValuePair; -@Ignore public class CakeShopFilteringIT { private static final CakeShopRepositoryManager CAKE_SHOP_REPOSITORY_MANAGER = new CakeShopRepositoryManager(); diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopIT.java index 03cfd1d2..7659f13f 100644 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopIT.java +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopIT.java @@ -38,7 +38,6 @@ import org.apache.http.message.BasicNameValuePair; -@Ignore public class CakeShopIT { private static final CakeShopRepositoryManager CAKE_SHOP_REPOSITORY_MANAGER = new CakeShopRepositoryManager(); diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopManyUpdatesIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopManyUpdatesIT.java index 2f3db476..94d46cde 100644 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopManyUpdatesIT.java +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopManyUpdatesIT.java @@ -22,7 +22,6 @@ import javax.jms.Session; import javax.ws.rs.client.Client; -@Ignore public class CakeShopManyUpdatesIT { private static final CakeShopRepositoryManager CAKE_SHOP_REPOSITORY_MANAGER = new CakeShopRepositoryManager(); diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopReplayEventsIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopReplayEventsIT.java index 7ef50cb4..59df4473 100644 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopReplayEventsIT.java +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopReplayEventsIT.java @@ -3,20 +3,14 @@ import static com.jayway.jsonassert.JsonAssert.with; import static java.util.Optional.empty; import static java.util.Optional.of; -import static java.util.Optional.ofNullable; import static java.util.UUID.fromString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import static uk.gov.justice.services.example.cakeshop.it.params.CakeShopMediaTypes.CONTEXT_NAME; -import org.junit.*; import uk.gov.justice.services.event.buffer.core.repository.subscription.Subscription; -import uk.gov.justice.services.example.cakeshop.it.helpers.ApiResponse; import uk.gov.justice.services.example.cakeshop.it.helpers.CakeShopRepositoryManager; -import uk.gov.justice.services.example.cakeshop.it.helpers.CommandFactory; -import uk.gov.justice.services.example.cakeshop.it.helpers.EventFactory; -import uk.gov.justice.services.example.cakeshop.it.helpers.EventFinder; import uk.gov.justice.services.example.cakeshop.it.helpers.Querier; import uk.gov.justice.services.example.cakeshop.it.helpers.RestEasyClientFactory; import uk.gov.justice.services.test.utils.core.messaging.Poller; @@ -25,7 +19,11 @@ import javax.ws.rs.client.Client; -@Ignore +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + public class CakeShopReplayEventsIT { private static final CakeShopRepositoryManager CAKE_SHOP_REPOSITORY_MANAGER = new CakeShopRepositoryManager(); diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopTimeStampIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopTimeStampIT.java index d65df5f3..05683b2e 100644 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopTimeStampIT.java +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/CakeShopTimeStampIT.java @@ -31,7 +31,6 @@ import javax.ws.rs.client.Client; import javax.ws.rs.core.Response; -@Ignore public class CakeShopTimeStampIT { private static final CakeShopRepositoryManager CAKE_SHOP_REPOSITORY_MANAGER = new CakeShopRepositoryManager(); diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/JmxMBeanIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/JmxMBeanIT.java index e0dbcda9..a4f6a496 100644 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/JmxMBeanIT.java +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/JmxMBeanIT.java @@ -1,43 +1,65 @@ package uk.gov.justice.services.example.cakeshop.it; -import uk.gov.justice.services.example.cakeshop.it.helpers.JMXBeanHelper; +import uk.gov.justice.services.example.cakeshop.it.helpers.MBeanHelper; import uk.gov.justice.services.jmx.Shuttering; +import uk.gov.justice.services.jmx.ShutteringMBean; +import java.io.IOException; + +import javax.management.InstanceNotFoundException; +import javax.management.IntrospectionException; import javax.management.MBeanServerConnection; +import javax.management.MalformedObjectNameException; import javax.management.ObjectName; +import javax.management.ReflectionException; import javax.management.remote.JMXConnector; +import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class JmxMBeanIT { - private static final Logger LOGGER = LoggerFactory.getLogger(JmxMBeanIT.class.getName()); + private static final String SHUTTERING_DOMAIN = "shuttering"; + private static final String SHUTTERING = "Shuttering"; - private JMXBeanHelper jmxBeanHelper; + private MBeanHelper mBeanHelper; + private JMXConnector jmxConnector; + private ShutteringMBean shutteringMBean; @Before - public void before() throws Exception { - jmxBeanHelper = new JMXBeanHelper(); + public void before() throws IOException { + mBeanHelper = new MBeanHelper(); + jmxConnector = mBeanHelper.getJMXConnector(); + } + + @After + public void cleanup() { + //invoke unshuttering - Always ensure unshutter is invoked as we cannot guarantee order of execution for other Cakeshop IT's + shutteringMBean.doUnshutteringRequested(); } @Test public void shouldInvokeShuttering() throws Exception { + shutteringMBean = getMbeanProxy(SHUTTERING_DOMAIN); + shutteringMBean.doShutteringRequested(); + } - JMXConnector jmxConnector = jmxBeanHelper.getJMXConnector(); - MBeanServerConnection connection = jmxConnector.getMBeanServerConnection(); + @Test + public void shouldInvokeUnShuttering() throws Exception { + shutteringMBean = getMbeanProxy(SHUTTERING_DOMAIN); + shutteringMBean.doUnshutteringRequested(); + } - final ObjectName objectName = new ObjectName("shuttering", "type", Shuttering.class.getSimpleName()); + private ShutteringMBean getMbeanProxy(final String domain) throws IOException, MalformedObjectNameException, IntrospectionException, InstanceNotFoundException, ReflectionException { + final MBeanServerConnection connection = jmxConnector.getMBeanServerConnection(); - jmxBeanHelper.getMbeanDomains(connection); + final ObjectName objectName = new ObjectName(domain, "type", SHUTTERING); - jmxBeanHelper.getMbeanOperations(objectName, connection); + mBeanHelper.getMbeanDomains(connection); - jmxBeanHelper.getMbeanProxy(objectName, connection).doShutteringRequested(); + mBeanHelper.getMbeanOperations(objectName, connection); - //Close JMX connector - jmxConnector.close(); + return mBeanHelper.getMbeanProxy(connection, objectName, ShutteringMBean.class); } } \ 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/ShutteringIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/ShutteringIT.java new file mode 100644 index 00000000..a4d2eb93 --- /dev/null +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/ShutteringIT.java @@ -0,0 +1,158 @@ +package uk.gov.justice.services.example.cakeshop.it; + +import static com.jayway.awaitility.Awaitility.await; +import static com.jayway.jsonassert.JsonAssert.with; +import static java.lang.String.format; +import static java.util.UUID.randomUUID; +import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.OK; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsCollectionContaining.hasItem; +import static org.slf4j.LoggerFactory.getLogger; +import static uk.gov.justice.services.test.utils.core.matchers.HttpStatusCodeMatcher.isStatus; + +import uk.gov.justice.services.example.cakeshop.it.helpers.ApiResponse; +import uk.gov.justice.services.example.cakeshop.it.helpers.CakeShopRepositoryManager; +import uk.gov.justice.services.example.cakeshop.it.helpers.CommandSender; +import uk.gov.justice.services.example.cakeshop.it.helpers.EventFactory; +import uk.gov.justice.services.example.cakeshop.it.helpers.MBeanHelper; +import uk.gov.justice.services.example.cakeshop.it.helpers.Querier; +import uk.gov.justice.services.example.cakeshop.it.helpers.RestEasyClientFactory; +import uk.gov.justice.services.jmx.Shuttering; +import uk.gov.justice.services.jmx.ShutteringMBean; + +import java.io.IOException; + +import javax.management.InstanceNotFoundException; +import javax.management.IntrospectionException; +import javax.management.MBeanServerConnection; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.ReflectionException; +import javax.management.remote.JMXConnector; +import javax.ws.rs.client.Client; +import javax.ws.rs.core.Response; + +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; + +public class ShutteringIT { + + private static final CakeShopRepositoryManager CAKE_SHOP_REPOSITORY_MANAGER = new CakeShopRepositoryManager(); + + private static final Logger logger = getLogger(ShutteringIT.class); + private static final String MARBLE_CAKE = "Marble cake"; + private static final String CARROT_CAKE = "Carrot cake"; + + private final EventFactory eventFactory = new EventFactory(); + + private Client client; + private Querier querier; + private CommandSender commandSender; + + private MBeanHelper mBeanHelper; + + @BeforeClass + public static void beforeClass() throws Exception { + CAKE_SHOP_REPOSITORY_MANAGER.initialise(); + } + + @Before + public void before() { + client = new RestEasyClientFactory().createResteasyClient(); + querier = new Querier(client); + commandSender = new CommandSender(client, eventFactory); + mBeanHelper = new MBeanHelper(); + } + + @After + public void cleanup() throws MalformedObjectNameException, IntrospectionException, ReflectionException, InstanceNotFoundException, IOException { + client.close(); + + //invoke unshuttering - Always ensure unshutter is invoked as we cannot guarantee order of execution for other Cakeeshop IT's + invokeShuttering(false); + } + + @Test + public void shouldNotReturnRecipesAfterShuttering() throws MalformedObjectNameException, IntrospectionException, ReflectionException, InstanceNotFoundException, IOException { + //invoke shuttering + invokeShuttering(true); + + //add 2 recipes + final String recipeId = addRecipe(MARBLE_CAKE); + final String recipeId2 = addRecipe(CARROT_CAKE); + + //check recipes have not been added due to shuttering + verifyRecipeAdded(recipeId, recipeId2, null, null, false, NOT_FOUND); + } + + @Test + public void shouldQueryForRecipesAfterUnShuttering() throws MalformedObjectNameException, IntrospectionException, ReflectionException, InstanceNotFoundException, IOException { + //invoke shuttering + invokeShuttering(true); + + //add more recipes + final String recipeId = addRecipe(MARBLE_CAKE); + final String recipeId2 = addRecipe(CARROT_CAKE); + + //check recipes have not been added due to shuttering + verifyRecipeAdded(recipeId, recipeId2, null, null, false, NOT_FOUND); + + //invoke unshuttering + invokeShuttering(false); + + ////check new recipes have been added successfully after unshuttering + verifyRecipeAdded(recipeId, recipeId2, MARBLE_CAKE, CARROT_CAKE,true, OK); + } + + private void verifyRecipeAdded(final String recipeId, + final String recipeId2, + final String recipeName, + final String recipeName2, + final boolean checkRecipeName, + final Response.Status status) { + await().until(() -> { + if(checkRecipeName){ + final ApiResponse response = querier.recipesQueryResult(); + assertThat(response.httpCode(), isStatus(status)); + logger.info(format("Response: %s", response.httpCode())); + + with(response.body()) + .assertThat("$.recipes[?(@.id=='" + recipeId + "')].name", hasItem(recipeName)) + .assertThat("$.recipes[?(@.id=='" + recipeId2 + "')].name", hasItem(recipeName2)); + } + else{ + final ApiResponse response = querier.queryForRecipe(recipeId); + logger.info(format("Response: %s", response.httpCode())); + assertThat(response.httpCode(), isStatus(status)); + } + }); + } + + private void invokeShuttering(final boolean isShutteringRequired) throws IOException, MalformedObjectNameException, IntrospectionException, InstanceNotFoundException, ReflectionException { + try(JMXConnector jmxConnector = mBeanHelper.getJMXConnector()){ + + final MBeanServerConnection connection = jmxConnector.getMBeanServerConnection(); + + final ObjectName objectName = new ObjectName("shuttering", "type", Shuttering.class.getSimpleName()); + + mBeanHelper.getMbeanOperations(objectName, connection); + + if(isShutteringRequired){ + mBeanHelper.getMbeanProxy(connection, objectName, ShutteringMBean.class).doShutteringRequested(); + } + else{ + mBeanHelper.getMbeanProxy(connection, objectName, ShutteringMBean.class).doUnshutteringRequested(); + } + } + } + + private String addRecipe(final String cakeName) { + final String recipeId = randomUUID().toString(); + commandSender.addRecipe(recipeId, cakeName); + return recipeId; + } +} diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/SnapshotCakeShopIT.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/SnapshotCakeShopIT.java index f88083b6..7a68ef09 100644 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/SnapshotCakeShopIT.java +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/SnapshotCakeShopIT.java @@ -23,7 +23,6 @@ import javax.ws.rs.client.Client; -@Ignore public class SnapshotCakeShopIT { private static final CakeShopRepositoryManager CAKE_SHOP_REPOSITORY_MANAGER = new CakeShopRepositoryManager(); diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/helpers/JMXBeanHelper.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/helpers/JMXBeanHelper.java deleted file mode 100644 index 5f730ca9..00000000 --- a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/helpers/JMXBeanHelper.java +++ /dev/null @@ -1,61 +0,0 @@ -package uk.gov.justice.services.example.cakeshop.it.helpers; - -import uk.gov.justice.services.jmx.ShutteringMBean; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; - -import javax.management.InstanceNotFoundException; -import javax.management.IntrospectionException; -import javax.management.JMX; -import javax.management.MBeanInfo; -import javax.management.MBeanOperationInfo; -import javax.management.MBeanServerConnection; -import javax.management.ObjectName; -import javax.management.ReflectionException; -import javax.management.remote.JMXConnector; -import javax.management.remote.JMXConnectorFactory; -import javax.management.remote.JMXServiceURL; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class JMXBeanHelper { - - private static final Logger LOGGER = LoggerFactory.getLogger(JMXBeanHelper.class.getName()); - - private static final String HOST = "localhost"; - private static final String RANDOM_MANAGEMENT_PORT = "random.management.port"; - - public ShutteringMBean getMbeanProxy(ObjectName objectName, final MBeanServerConnection connection) { - return JMX.newMBeanProxy(connection, objectName, ShutteringMBean.class, true); - } - - public void getMbeanDomains(final MBeanServerConnection connection) throws IOException { - String [] domains = connection.getDomains(); - List mbeanDomains = Arrays.asList(domains); - - LOGGER.info("MBean Domains: "); - mbeanDomains.forEach(mbeanDomain -> LOGGER.info(mbeanDomain)); - } - - public void getMbeanOperations(ObjectName objectName, final MBeanServerConnection connection) throws IOException, IntrospectionException, InstanceNotFoundException, ReflectionException { - final MBeanInfo mBeanInfo = connection.getMBeanInfo(objectName); - MBeanOperationInfo[] operations = mBeanInfo.getOperations(); - List mbeanOperations = Arrays.asList(operations); - - LOGGER.info("MBean Operations: "); - mbeanOperations.forEach(mBeanOperationInfo -> LOGGER.info(mBeanOperationInfo.getName())); - } - - public JMXConnector getJMXConnector() throws IOException { - int managementPort = Integer.valueOf(System.getProperty(RANDOM_MANAGEMENT_PORT)); - - String urlString = - System.getProperty("jmx.service.url","service:jmx:remote+http://" + HOST + ":" + managementPort); - JMXServiceURL serviceURL = new JMXServiceURL(urlString); - - return JMXConnectorFactory.connect(serviceURL, null); - } -} diff --git a/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/helpers/MBeanHelper.java b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/helpers/MBeanHelper.java new file mode 100644 index 00000000..620fcebb --- /dev/null +++ b/example-context/example-service/example-it/src/test/java/uk/gov/justice/services/example/cakeshop/it/helpers/MBeanHelper.java @@ -0,0 +1,63 @@ +package uk.gov.justice.services.example.cakeshop.it.helpers; + +import static java.lang.Integer.valueOf; +import static java.lang.System.getProperty; +import static java.util.Arrays.asList; +import static javax.management.JMX.newMBeanProxy; +import static javax.management.remote.JMXConnectorFactory.connect; +import static org.slf4j.LoggerFactory.getLogger; +import static uk.gov.justice.services.test.utils.common.host.TestHostProvider.getHost; + +import java.io.IOException; +import java.util.List; + +import javax.management.InstanceNotFoundException; +import javax.management.IntrospectionException; +import javax.management.MBeanInfo; +import javax.management.MBeanOperationInfo; +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; +import javax.management.ReflectionException; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXServiceURL; + +import org.slf4j.Logger; + +public class MBeanHelper { + + private static final Logger logger = getLogger(MBeanHelper.class.getName()); + + private static final String HOST = getHost(); + private static final String RANDOM_MANAGEMENT_PORT = "random.management.port"; + + public T getMbeanProxy(final MBeanServerConnection connection, final ObjectName objectName, final Class interfaceName) { + return newMBeanProxy(connection, objectName, interfaceName, true); + } + + public void getMbeanDomains(final MBeanServerConnection connection) throws IOException { + final String [] domains = connection.getDomains(); + final List mbeanDomains = asList(domains); + + logger.info("MBean Domains: "); + mbeanDomains.forEach(mbeanDomain -> logger.info(mbeanDomain)); + } + + public void getMbeanOperations(final ObjectName objectName, final MBeanServerConnection connection) throws IOException, IntrospectionException, InstanceNotFoundException, ReflectionException { + final MBeanInfo mBeanInfo = connection.getMBeanInfo(objectName); + final MBeanOperationInfo[] operations = mBeanInfo.getOperations(); + final List mbeanOperations = asList(operations); + + logger.info("MBean Operations: "); + mbeanOperations.forEach(mBeanOperationInfo -> logger.info(mBeanOperationInfo.getName())); + } + + public JMXConnector getJMXConnector() throws IOException { + final int managementPort = valueOf(getProperty(RANDOM_MANAGEMENT_PORT)); + + final String urlString = + getProperty("jmx.service.url","service:jmx:remote+http://" + HOST + ":" + managementPort); + final JMXServiceURL serviceURL = new JMXServiceURL(urlString); + + return connect(serviceURL, null); + } +} diff --git a/example-context/example-service/example-single/pom.xml b/example-context/example-service/example-single/pom.xml index 688bf1e0..59081b8e 100644 --- a/example-context/example-service/example-single/pom.xml +++ b/example-context/example-service/example-single/pom.xml @@ -78,13 +78,6 @@ pom test - - uk.gov.justice.services - test-utils-wildfly - ${framework.version} - pom - test - diff --git a/pom.xml b/pom.xml index 26ca0fdd..9b9925df 100644 --- a/pom.xml +++ b/pom.xml @@ -31,12 +31,12 @@ cake-shop 1.29.0 - 6.0.0-SNAPSHOT + 6.0.0-M10 1.2.0 - 2.0.0-SNAPSHOT - 2.0.0-SNAPSHOT + 2.0.0-M10 + 2.0.0-M8 1.17.4 - 4.0.0-SNAPSHOT + 4.0.0-M5 2.6.2 1.6.0 2.2.0.Final