Skip to content
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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ dependencies {
implementation 'org.apache.httpcomponents:httpclient:4.5.12'
implementation 'com.heroku.sdk:env-keystore:1.1.11'

implementation 'ca.uhn.hapi.fhir:hapi-fhir-base:4.2.0'
implementation 'ca.uhn.hapi.fhir:hapi-fhir-structures-r4:4.2.0'
implementation 'ca.uhn.hapi.fhir:hapi-fhir-base:8.0.0'
implementation 'ca.uhn.hapi.fhir:hapi-fhir-structures-r4:8.0.0'
implementation 'ca.uhn.hapi.fhir:hapi-fhir-validation-resources-r4:8.0.0'
implementation 'com.google.guava:guava:33.4.8-jre'
implementation 'org.apache.qpid:qpid-jms-client:2.7.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package uk.nhs.digital.nhsconnect.nhais.inbound;

import org.assertj.core.api.SoftAssertions;
import org.json.JSONException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.io.Resource;
Expand Down Expand Up @@ -100,7 +103,7 @@ void setUp() {
}

@Test
void whenMeshInboundQueueRegistrationMessageIsReceived_thenMessageIsHandled(SoftAssertions softly) throws IOException, JMSException {
void whenMeshInboundQueueRegistrationMessageIsReceived_thenMessageIsHandled(SoftAssertions softly) throws IOException, JMSException, JSONException {
var meshMessage = new MeshMessage()
.setWorkflowId(WorkflowId.REGISTRATION)
.setContent(new String(Files.readAllBytes(interchange.getFile().toPath())));
Expand Down Expand Up @@ -148,10 +151,10 @@ private void assertOutboundRecepMessage(SoftAssertions softly) throws IOExceptio
softly.assertThat(meshMessage.getMessageSentTimestamp()).isNull();
}

private void assertGpSystemInboundQueueMessages(SoftAssertions softly) throws JMSException, IOException {
private void assertGpSystemInboundQueueMessages(SoftAssertions softly) throws JMSException, IOException, JSONException {
var gpSystemInboundQueueMessages = IntStream.range(0, 6)
.mapToObj(x -> getGpSystemInboundQueueMessage())
.collect(Collectors.toList());
.toList();

assertGpSystemInboundQueueMessages(
softly, gpSystemInboundQueueMessages.get(0), MESSAGE_1_TRANSACTION_TYPE, TRANSACTION_1_OPERATION_ID, fhirTN1);
Expand All @@ -172,7 +175,7 @@ private void assertGpSystemInboundQueueMessages(
Message message,
ReferenceTransactionType.TransactionType expectedTransactionType,
String expectedOperationId,
Resource expectedFhir) throws JMSException, IOException {
Resource expectedFhir) throws JMSException, IOException, JSONException {

// all transactions come from the same interchange and use the same conversation id
String conversationId = message.getStringProperty("ConversationId");
Expand All @@ -185,8 +188,12 @@ private void assertGpSystemInboundQueueMessages(
.isEqualTo(expectedOperationId);
softly.assertThat(message.getStringProperty("TransactionType"))
.isEqualTo(expectedTransactionType.name().toLowerCase());
softly.assertThat(parseTextMessage(message))
.isEqualTo(new String(Files.readAllBytes(expectedFhir.getFile().toPath())));

JSONAssert.assertEquals(
parseTextMessage(message),
new String(Files.readAllBytes(expectedFhir.getFile().toPath())),
JSONCompareMode.STRICT
);
}

private void assertInboundStates(SoftAssertions softly, List<InboundState> inboundStates) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package uk.nhs.digital.nhsconnect.nhais.inbound;

import org.assertj.core.api.SoftAssertions;
import org.json.JSONException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.io.Resource;
Expand Down Expand Up @@ -63,7 +66,7 @@ void setUp() {
}

@Test
void whenMeshInboundQueueRegistrationMessageIsReceived_thenMessageIsHandled(SoftAssertions softly) throws IOException, JMSException {
void whenMeshInboundQueueRegistrationMessageIsReceived_thenMessageIsHandled(SoftAssertions softly) throws IOException, JMSException, JSONException {
var meshMessage = new MeshMessage()
.setWorkflowId(WorkflowId.REGISTRATION)
.setContent(new String(Files.readAllBytes(interchange.getFile().toPath())))
Expand All @@ -86,14 +89,15 @@ private void assertOutboundRecepMessage(SoftAssertions softly) throws IOExceptio
softly.assertThat(meshMessage.getMessageSentTimestamp()).isNull();
}

private void assertGpSystemInboundQueueMessage(SoftAssertions softly) throws JMSException, IOException {
private void assertGpSystemInboundQueueMessage(SoftAssertions softly) throws JMSException, IOException, JSONException {
var message = getGpSystemInboundQueueMessage();
var content = parseTextMessage(message);
var expectedContent = new String(Files.readAllBytes(fhir.getFile().toPath()));

softly.assertThat(message.getStringProperty("OperationId")).isEqualTo(OPERATION_ID);
softly.assertThat(message.getStringProperty("TransactionType")).isEqualTo(TRANSACTION_TYPE.name().toLowerCase());
softly.assertThat(content).isEqualTo(expectedContent);

JSONAssert.assertEquals(expectedContent, content, JSONCompareMode.STRICT);
}

private void assertInboundState(SoftAssertions softly) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package uk.nhs.digital.nhsconnect.nhais.inbound;

import org.json.JSONException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import uk.nhs.digital.nhsconnect.nhais.IntegrationBaseTest;
Expand All @@ -20,6 +23,7 @@

import jakarta.jms.JMSException;
import jakarta.jms.Message;

import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -99,17 +103,17 @@ private void verifyThatCloseQuarterNotificationIsNotPresentOnGpSystemInboundQueu
assertThat(gpSystemInboundQueueMessage).isNull();
}

private void verifyThatNonCloseQuarterNotificationMessageIsTranslated(TestData testData, Message gpSystemInboundQueueMessage) throws JMSException {
private void verifyThatNonCloseQuarterNotificationMessageIsTranslated(TestData testData, Message gpSystemInboundQueueMessage) throws JMSException, JSONException {
assertThat(gpSystemInboundQueueMessage).isNotNull();
// assert transaction type in JMS header is correct
assertMessageHeaders(gpSystemInboundQueueMessage, "fp69_prior_notification");
// assert output body is correct
assertMessageBody(gpSystemInboundQueueMessage, testData.getJson());
}

private void assertMessageBody(Message gpSystemInboundQueueMessage, String expectedBody) throws JMSException {
private void assertMessageBody(Message gpSystemInboundQueueMessage, String expectedBody) throws JMSException, JSONException {
var body = parseTextMessage(gpSystemInboundQueueMessage);
assertThat(body).isEqualTo(expectedBody);
JSONAssert.assertEquals(expectedBody, body, JSONCompareMode.STRICT);
}

private void assertMessageHeaders(Message gpSystemInboundQueueMessage, String expectedTransactionType) throws JMSException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
@DirtiesContext
public class DeductionIntegrationTest {
public static final String URL = "/fhir/Patient/$nhais.deduction";
private static final String ATTRIBUTE_VALUE_MUST_NOT_BE_EMPTY =
"Invalid attribute value \"\": Attribute value must not be empty (\"\")";
private static final String INVALID_VALUE_STRING_PARAMETER =
"Unable to parse JSON resource as a Parameters: HAPI-1821: [element=\"valueString\"] ";
private static final String INVALID_VALUE_PARAMETER =
"Unable to parse JSON resource as a Parameters: HAPI-1821: [element=\"value\"] ";

@Autowired
private MockMvc mockMvc;
Expand Down Expand Up @@ -91,7 +97,8 @@ void whenEmptyNhsNumber_thenRespond400() throws Exception {
.andExpect(status().isBadRequest())
.andReturn();
OperationOutcome operationOutcome = (OperationOutcome) fhirParser.parse(result.getResponse().getContentAsString());
assertThat(operationOutcome.getIssueFirstRep().getDetails().getText()).contains("Unable to parse JSON resource as a Parameters: Invalid attribute value \"\": Attribute values must not be empty (\"\")");
assertThat(operationOutcome.getIssueFirstRep().getDetails().getText())
.contains(INVALID_VALUE_PARAMETER + ATTRIBUTE_VALUE_MUST_NOT_BE_EMPTY);
}

@Test
Expand Down Expand Up @@ -131,7 +138,8 @@ void whenEmptyDateOfDeduction_thenRespond400() throws Exception {
.andExpect(status().isBadRequest())
.andReturn();
OperationOutcome operationOutcome = (OperationOutcome) fhirParser.parse(result.getResponse().getContentAsString());
assertThat(operationOutcome.getIssueFirstRep().getDetails().getText()).contains("Unable to parse JSON resource as a Parameters: Invalid attribute value \"\": Attribute values must not be empty (\"\")");
assertThat(operationOutcome.getIssueFirstRep().getDetails().getText())
.contains(INVALID_VALUE_STRING_PARAMETER + ATTRIBUTE_VALUE_MUST_NOT_BE_EMPTY);
}

@Test
Expand Down Expand Up @@ -171,7 +179,8 @@ void whenEmptyReasonForDeduction_thenRespond400() throws Exception {
.andExpect(status().isBadRequest())
.andReturn();
OperationOutcome operationOutcome = (OperationOutcome) fhirParser.parse(result.getResponse().getContentAsString());
assertThat(operationOutcome.getIssueFirstRep().getDetails().getText()).contains("Unable to parse JSON resource as a Parameters: Invalid attribute value \"\": Attribute values must not be empty (\"\")");
assertThat(operationOutcome.getIssueFirstRep().getDetails().getText())
.contains(INVALID_VALUE_STRING_PARAMETER + ATTRIBUTE_VALUE_MUST_NOT_BE_EMPTY);
}

@Test
Expand All @@ -194,4 +203,4 @@ void whenNullReasonForDeduction_thenRespond400() throws Exception {
assertThat(operationOutcome.getIssueFirstRep().getDetails().getText()).contains(ParameterNames.DEDUCTION_REASON_CODE);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
@AutoConfigureMockMvc
@Slf4j
public class FhirControllerIntegrationTest {
private static final String INVALID_VALUE_STRING_PARAMETER =
"Unable to parse JSON resource as a Parameters: HAPI-1821: [element=\"valueString\"] ";
private static final String INVALID_VALUE_PARAMETER =
"Unable to parse JSON resource as a Parameters: HAPI-1821: [element=\"value\"] ";
private static final String ATTRIBUTE_VALUE_MUST_NOT_BE_EMPTY =
"Invalid attribute value \"\": Attribute value must not be empty (\"\")";

@Autowired
private MockMvc mockMvc;
Expand Down Expand Up @@ -80,7 +86,7 @@ void whenDeductionNoDestinationHaCipher_thenRerturns400() throws Exception {
.andReturn();
OperationOutcome operationOutcome = (OperationOutcome) fhirParser.parse(result.getResponse().getContentAsString());
assertThat(operationOutcome.getIssueFirstRep().getDetails().getText())
.contains("Invalid attribute value \"\": Attribute values must not be empty");
.contains(INVALID_VALUE_PARAMETER + ATTRIBUTE_VALUE_MUST_NOT_BE_EMPTY);
}

@Test
Expand All @@ -91,7 +97,7 @@ void whenRemovalNoDestinationHaCipher_thenRerturns400() throws Exception {
.andReturn();
OperationOutcome operationOutcome = (OperationOutcome) fhirParser.parse(result.getResponse().getContentAsString());
assertThat(operationOutcome.getIssueFirstRep().getDetails().getText())
.contains("Invalid attribute value \"\": Attribute values must not be empty");
.contains(INVALID_VALUE_PARAMETER + ATTRIBUTE_VALUE_MUST_NOT_BE_EMPTY);
}


Expand All @@ -103,7 +109,7 @@ void whenDeductionNoGpCode_thenReturns400() throws Exception {
.andReturn();
OperationOutcome operationOutcome = (OperationOutcome) fhirParser.parse(result.getResponse().getContentAsString());
assertThat(operationOutcome.getIssueFirstRep().getDetails().getText())
.contains("Invalid attribute value \"\": Attribute values must not be empty");
.contains(INVALID_VALUE_PARAMETER + ATTRIBUTE_VALUE_MUST_NOT_BE_EMPTY);
}

@Test
Expand All @@ -114,7 +120,7 @@ void whenRemovalNoGpCode_thenReturns400() throws Exception {
.andReturn();
OperationOutcome operationOutcome = (OperationOutcome) fhirParser.parse(result.getResponse().getContentAsString());
assertThat(operationOutcome.getIssueFirstRep().getDetails().getText())
.contains("Invalid attribute value \"\": Attribute values must not be empty");
.contains(INVALID_VALUE_PARAMETER + ATTRIBUTE_VALUE_MUST_NOT_BE_EMPTY);
}

@Test
Expand All @@ -125,7 +131,7 @@ void whenDeductionNpGpTradingPartnerCode_thenReturns400() throws Exception {
.andReturn();
OperationOutcome operationOutcome = (OperationOutcome) fhirParser.parse(result.getResponse().getContentAsString());
assertThat(operationOutcome.getIssueFirstRep().getDetails().getText())
.contains("Invalid attribute value \"\": Attribute values must not be empty");
.contains(INVALID_VALUE_STRING_PARAMETER + ATTRIBUTE_VALUE_MUST_NOT_BE_EMPTY);
}

@Test
Expand All @@ -136,7 +142,7 @@ void whenRemovalNpGpTradingPartnerCode_thenReturns400() throws Exception {
.andReturn();
OperationOutcome operationOutcome = (OperationOutcome) fhirParser.parse(result.getResponse().getContentAsString());
assertThat(operationOutcome.getIssueFirstRep().getDetails().getText())
.contains("Invalid attribute value \"\": Attribute values must not be empty");
.contains(INVALID_VALUE_STRING_PARAMETER + ATTRIBUTE_VALUE_MUST_NOT_BE_EMPTY);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ void whenEmptyNhsNumber_thenRespond400() throws Exception {
.andExpect(status().isBadRequest())
.andReturn();
OperationOutcome operationOutcome = (OperationOutcome) fhirParser.parse(result.getResponse().getContentAsString());
assertThat(operationOutcome.getIssueFirstRep().getDetails().getText()).contains("Unable to parse JSON resource as a Parameters: Invalid attribute value \"\": Attribute values must not be empty (\"\")");
assertThat(operationOutcome.getIssueFirstRep().getDetails().getText())
.contains(
"Unable to parse JSON resource as a Parameters: HAPI-1821: [element=\"value\"] "
+ "Invalid attribute value \"\": Attribute value must not be empty (\"\")"
);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uk.nhs.digital.nhsconnect.nhais.model.fhir;

import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.Parameters;
Expand All @@ -14,7 +13,6 @@

import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;

@RequiredArgsConstructor
public class ParametersExtension {
Expand Down Expand Up @@ -79,19 +77,15 @@ public static Optional<String> extractOptionalValue(Parameters parameters, Strin
}

public Optional<String> extractOptionalValue(String name) {
return Optional.ofNullable(parameters.getParameter(name))
return parameters.getParameter()
.stream()
.filter(p -> p.getName().equals(name))
.findFirst()
.map(Parameters.ParametersParameterComponent::getValue)
.map(StringType.class::cast)
.map(StringType::getValueAsString);
}

@SneakyThrows
public String extractValueOrThrow(String name, Supplier<? extends Throwable> exception) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method was unused so it was removed rather than updated

return Optional.ofNullable(parameters.getParameter(name))
.map(StringType.class::cast)
.map(StringType::getValueAsString)
.orElseThrow(exception);
}

public int size() {
return parameters.getParameter().size();
}
Expand Down