Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
Expand Up @@ -5,7 +5,7 @@

import java.nio.file.Path;

public class ActiveMqContainer extends GenericContainer<ActiveMqContainer> {
public final class ActiveMqContainer extends GenericContainer<ActiveMqContainer> {

public static final int ACTIVEMQ_PORT = 5672;
private static ActiveMqContainer container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.nio.file.Path;

@Slf4j
public class FakeMeshContainer extends GenericContainer<FakeMeshContainer> {
public final class FakeMeshContainer extends GenericContainer<FakeMeshContainer> {

public static final int FAKE_MESH_PORT = 8829;
private static FakeMeshContainer container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.testcontainers.containers.GenericContainer;

@Slf4j
public class MongoDbContainer extends GenericContainer<MongoDbContainer> {
public final class MongoDbContainer extends GenericContainer<MongoDbContainer> {

public static final int MONGODB_PORT = 27017;
public static final String DEFAULT_IMAGE_AND_TAG = "mongo:8.0";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public class TimeToLiveTest {
private NhaisMongoClientConfiguration mongoConfig;

@Test
void when_ApplicationStarts_then_TtlIndexExistsForInboundStateWithValueFromConfiguration() {
void When_ApplicationStarts_Expect_TtlIndexExistsForInboundStateWithValueFromConfiguration() {
var indexOperations = mongoTemplate.indexOps(InboundState.class);
assertThat(timeToLiveIndexExists(indexOperations)).isTrue();
}

@Test
void when_ApplicationStarts_then_TtlIndexExistsForOutboundStateWithValueFromConfiguration() {
void When_ApplicationStarts_Expect_TtlIndexExistsForOutboundStateWithValueFromConfiguration() {
var indexOperations = mongoTemplate.indexOps(OutboundState.class);
assertThat(timeToLiveIndexExists(indexOperations)).isTrue();
}
Expand All @@ -70,7 +70,7 @@ private boolean timeToLiveIndexExists(IndexOperations indexOperations) {

@Test
@Disabled("Long running test that depends on external TTL config, enable when needed")
void when_TimeToLiveHasPassedInInboundState_then_documentRemoved() {
void When_TimeToLiveHasPassedInInboundState_Expect_DocumentRemoved() {
var inboundState = new InboundState()
.setWorkflowId(WorkflowId.RECEP)
.setSender("some_sender")
Expand All @@ -89,7 +89,7 @@ void when_TimeToLiveHasPassedInInboundState_then_documentRemoved() {

@Test
@Disabled("Long running test that depends on external TTL config, enable when needed")
void when_TimeToLiveHasPassedInOutboundState_then_documentRemoved() {
void When_TimeToLiveHasPassedInOutboundState_Expect_DocumentRemoved() {
var inboundState = new OutboundState()
.setWorkflowId(WorkflowId.RECEP)
.setSender("some_sender")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class DeadLetterQueueTest extends IntegrationBaseTest {
private ObjectMapper objectMapper;

@Test
public void whenSendingInvalidMessage_toMeshInboundQueue_thenMessageIsSentToDeadLetterQueue() throws JMSException {
public void When_SendingInvalidMessageToMeshInboundQueue_Expect_MessageIsSentToDeadLetterQueue() throws JMSException {
clearDeadLetterQueue(meshInboundQueueName);
sendToMeshInboundQueue(MESSAGE_CONTENT);

Expand All @@ -48,10 +48,15 @@ public void whenSendingInvalidMessage_toMeshInboundQueue_thenMessageIsSentToDead
}

@Test
public void whenMeshOutboundQueueMessageCannotBeProcessed_thenMessageIsSentToDeadLetterQueue() throws Exception {
public void When_MeshOutboundQueueMessageCannotBeProcessed_Expect_MessageIsSentToDeadLetterQueue() throws Exception {
String conversationId = Long.toString(System.currentTimeMillis());
when(conversationIdService.getCurrentConversationId()).thenReturn(conversationId);
OutboundMeshMessage meshMessage = OutboundMeshMessage.create("XX11", WorkflowId.REGISTRATION, MESSAGE_CONTENT, "2020-01-01T00:00:00Z", "asdf");
OutboundMeshMessage meshMessage = OutboundMeshMessage.create(
"XX11",
WorkflowId.REGISTRATION, MESSAGE_CONTENT,
"2020-01-01T00:00:00Z",
"asdf"
);
doThrow(RuntimeException.class).when(meshClient).authenticate();

clearDeadLetterQueue(meshOutboundQueueName);
Expand All @@ -62,5 +67,4 @@ public void whenMeshOutboundQueueMessageCannotBeProcessed_thenMessageIsSentToDea
assertThat(message.getStringProperty(JmsHeaders.CONVERSATION_ID)).isEqualTo(conversationId);
assertThat(parseTextMessage(message)).isEqualTo(objectMapper.writeValueAsString(meshMessage));
}

}
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 @@ -62,10 +65,10 @@ public class InboundMeshQueueMultiTransactionTest extends IntegrationBaseTest {
private static final String TRANSACTION_5_OPERATION_ID = OperationId.buildOperationId(RECIPIENT, TN_5);
private static final String TRANSACTION_6_OPERATION_ID = OperationId.buildOperationId(RECIPIENT, TN_6);
private static final Instant INTERCHANGE_TRANSLATION_TIMESTAMP = ZonedDateTime
.of(2020, 1, 25, 12, 35, 0, 0, TimestampService.UKZone)
.of(2020, 1, 25, 12, 35, 0, 0, TimestampService.UK_ZONE)
.toInstant();

private static final Instant GENERATED_TIMESTAMP = ZonedDateTime.of(2020, 6, 10, 14, 38, 0, 0, TimestampService.UKZone)
private static final Instant GENERATED_TIMESTAMP = ZonedDateTime.of(2020, 6, 10, 14, 38, 0, 0, TimestampService.UK_ZONE)
.toInstant();
private static final String ISO_GENERATED_TIMESTAMP = new TimestampService().formatInISO(GENERATED_TIMESTAMP);

Expand Down Expand Up @@ -100,7 +103,9 @@ void setUp() {
}

@Test
void whenMeshInboundQueueRegistrationMessageIsReceived_thenMessageIsHandled(SoftAssertions softly) throws IOException, JMSException {
void When_MeshInboundQueueRegistrationMessageIsReceived_Expect_MessageIsHandled(SoftAssertions softly)
throws IOException, JMSException {

var meshMessage = new MeshMessage()
.setWorkflowId(WorkflowId.REGISTRATION)
.setContent(new String(Files.readAllBytes(interchange.getFile().toPath())));
Expand Down Expand Up @@ -148,10 +153,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,11 +177,11 @@ 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");
if(previousConversationId == null) {
if (previousConversationId == null) {
previousConversationId = conversationId;
}
softly.assertThat(conversationId).isEqualTo(previousConversationId);
Expand All @@ -185,8 +190,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
Expand Up @@ -6,7 +6,6 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.core.io.Resource;
import org.springframework.test.annotation.DirtiesContext;
import uk.nhs.digital.nhsconnect.nhais.IntegrationBaseTest;
Expand Down Expand Up @@ -41,7 +40,7 @@ public class InboundMeshQueueRecepTest extends IntegrationBaseTest {
private static final String SENDER = "FHS1";
private static final String RECIPIENT = "GP05";
private static final Instant TRANSLATION_TIMESTAMP = ZonedDateTime
.of(2020, 6, 20, 14, 0, 0, 0, TimestampService.UKZone)
.of(2020, 6, 20, 14, 0, 0, 0, TimestampService.UK_ZONE)
.toInstant();
// Mongo only supports millis precision
private static final Instant PROCESSED_TIMESTAMP = Instant.now().truncatedTo(ChronoUnit.MILLIS);
Expand All @@ -65,7 +64,7 @@ void setUp() {
}

@Test
void whenMeshInboundQueueRecepMessageIsReceived_thenRecepHandled(SoftAssertions softly) throws IOException {
void When_MeshInboundQueueRecepMessageIsReceived_Expect_RecepHandled(SoftAssertions softly) throws IOException {
createOutboundStateRecords();

sendToMeshInboundQueue(new MeshMessage()
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 @@ -39,9 +42,9 @@ public class InboundMeshQueueRegistrationTest extends IntegrationBaseTest {
private static final ReferenceTransactionType.Inbound TRANSACTION_TYPE = ReferenceTransactionType.Inbound.APPROVAL;
private static final String OPERATION_ID = OperationId.buildOperationId(RECIPIENT, TN);
private static final Instant TRANSLATION_TIMESTAMP = ZonedDateTime
.of(2020, 1, 25, 12, 35, 0, 0, TimestampService.UKZone)
.of(2020, 1, 25, 12, 35, 0, 0, TimestampService.UK_ZONE)
.toInstant();
private static final Instant GENERATED_TIMESTAMP = ZonedDateTime.of(2020, 6, 10, 14, 38, 00, 0, TimestampService.UKZone)
private static final Instant GENERATED_TIMESTAMP = ZonedDateTime.of(2020, 6, 10, 14, 38, 00, 0, TimestampService.UK_ZONE)
.toInstant();
private static final String ISO_GENERATED_TIMESTAMP = new TimestampService().formatInISO(GENERATED_TIMESTAMP);

Expand All @@ -63,7 +66,9 @@ void setUp() {
}

@Test
void whenMeshInboundQueueRegistrationMessageIsReceived_thenMessageIsHandled(SoftAssertions softly) throws IOException, JMSException {
void When_MeshInboundQueueRegistrationMessageIsReceived_Expect_MessageIsHandled(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 +91,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
Expand Up @@ -26,7 +26,7 @@ public class InboundStateRepositoryTest {
private InboundStateRepository inboundStateRepository;

@Test
void whenDuplicateInterchangeInboundStateInserted_thenThrowsException() {
void When_DuplicateInterchangeInboundStateInserted_Expect_ThrowsException() {
var inboundState = new InboundState()
.setWorkflowId(WorkflowId.REGISTRATION)
.setSender("some_sender")
Expand All @@ -44,7 +44,7 @@ void whenDuplicateInterchangeInboundStateInserted_thenThrowsException() {
}

@Test
void whenDuplicateRecepInboundStateInserted_thenThrowsException() {
void When_DuplicateRecepInboundStateInserted_Expect_ThrowsException() {
var inboundState = new InboundState()
.setWorkflowId(WorkflowId.RECEP)
.setSender("some_sender")
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,19 @@ 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 All @@ -126,19 +132,25 @@ private void assertOutboundRecepMessage(String recep) {
List<String> messageIds = waitFor(() -> {
List<String> inboxMessageIds = nhaisMeshClient.getInboxMessageIds();
return inboxMessageIds.isEmpty() ? null : inboxMessageIds;
} );
});
var meshMessage = nhaisMeshClient.getEdifactMessage(messageIds.get(0));

Interchange expectedRecep = edifactParser.parse(recep);
Interchange actualRecep = edifactParser.parse(meshMessage.getContent());

assertThat(meshMessage.getWorkflowId()).isEqualTo(WorkflowId.RECEP);
assertThat(actualRecep.getInterchangeHeader().getRecipient()).isEqualTo(expectedRecep.getInterchangeHeader().getRecipient());
assertThat(actualRecep.getInterchangeHeader().getSender()).isEqualTo(expectedRecep.getInterchangeHeader().getSender());
assertThat(actualRecep.getInterchangeHeader().getSequenceNumber()).isEqualTo(expectedRecep.getInterchangeHeader().getSequenceNumber());
assertThat(meshMessage.getWorkflowId())
.isEqualTo(WorkflowId.RECEP);
assertThat(actualRecep.getInterchangeHeader().getRecipient())
.isEqualTo(expectedRecep.getInterchangeHeader().getRecipient());
assertThat(actualRecep.getInterchangeHeader().getSender())
.isEqualTo(expectedRecep.getInterchangeHeader().getSender());
assertThat(actualRecep.getInterchangeHeader().getSequenceNumber())
.isEqualTo(expectedRecep.getInterchangeHeader().getSequenceNumber());
assertThat(filterTimestampedSegments(actualRecep)).containsExactlyElementsOf(filterTimestampedSegments(expectedRecep));
assertThat(actualRecep.getInterchangeTrailer().getNumberOfMessages()).isEqualTo(expectedRecep.getInterchangeTrailer().getNumberOfMessages());
assertThat(actualRecep.getInterchangeTrailer().getSequenceNumber()).isEqualTo(expectedRecep.getInterchangeTrailer().getSequenceNumber());
assertThat(actualRecep.getInterchangeTrailer().getNumberOfMessages())
.isEqualTo(expectedRecep.getInterchangeTrailer().getNumberOfMessages());
assertThat(actualRecep.getInterchangeTrailer().getSequenceNumber())
.isEqualTo(expectedRecep.getInterchangeTrailer().getSequenceNumber());
}

private List<String> filterTimestampedSegments(Interchange recep) {
Expand Down
Loading
Loading