Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up Shuttering IT #23

Merged
merged 1 commit into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to

## [Unreleased]

### Changed
- Update Shuttering Integration Test

## [2.0.0-M2] - 2019-04-08

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static com.jayway.awaitility.Awaitility.await;
import static com.jayway.jsonassert.JsonAssert.with;
import static java.lang.String.format;
import static java.util.Optional.empty;
import static java.util.Optional.of;
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;
Expand All @@ -22,6 +24,7 @@
import uk.gov.justice.services.jmx.ShutteringMBean;

import java.io.IOException;
import java.util.Optional;

import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
Expand All @@ -31,7 +34,6 @@
import javax.management.ReflectionException;
import javax.management.remote.JMXConnector;
import javax.ws.rs.client.Client;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.junit.After;
Expand Down Expand Up @@ -115,32 +117,41 @@ private void verifyRecipeAdded(final String recipeId,
final String recipeName2,
final boolean checkRecipeName,
final Status status) {
final Optional<String> recId = of(recipeId);
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));
}
if(checkRecipeName) {
final ApiResponse response = verifyResponse(empty(), status);

verifyResponseBody(recipeId, recipeId2, recipeName, recipeName2, response);
} else {
verifyResponse(recId, status);
}
});
}

private void verifyResponseBody(final String recipeId, final String recipeId2, final String recipeName, final String recipeName2, final ApiResponse response) {
with(response.body())
.assertThat("$.recipes[?(@.id=='" + recipeId + "')].name", hasItem(recipeName))
.assertThat("$.recipes[?(@.id=='" + recipeId2 + "')].name", hasItem(recipeName2));
}

private ApiResponse verifyResponse(final Optional<String> recipeId, final Status status) {
final ApiResponse response = recipeId.isPresent() ? querier.queryForRecipe(recipeId.get()):
querier.recipesQueryResult();

logger.info(format("Response: %s", response.httpCode()));
assertThat(response.httpCode(), isStatus(status));

return response;
}

private void invokeShuttering(final boolean isShutteringRequired) throws IOException, MalformedObjectNameException, IntrospectionException, InstanceNotFoundException, ReflectionException {
try(JMXConnector jmxConnector = mBeanHelper.getJMXConnector()){
try(final 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 {
Expand Down