Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package uk.nhs.adaptors.pss.translator.amqp;

import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.test.annotation.DirtiesContext;
import uk.nhs.adaptors.pss.translator.exception.MhsServerErrorException;
import uk.nhs.adaptors.pss.translator.task.SendContinueRequestHandler;
import uk.nhs.adaptors.pss.util.BaseEhrHandler;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import static uk.nhs.adaptors.common.enums.MigrationStatus.EHR_GENERAL_PROCESSING_ERROR;

@SpringBootTest(webEnvironment = RANDOM_PORT)
@AutoConfigureMockMvc
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
public class SendContinueHandlerFailureIT extends BaseEhrHandler {
public static final String JSON_LARGE_MESSAGE_SCENARIO_3_UK_06_JSON = "/json/LargeMessage/Scenario_3/uk06.json";

@TestConfiguration
static class MockedBeansConfig {
@Bean
public SendContinueRequestHandler sendContinueRequestHandler() {
return Mockito.mock(SendContinueRequestHandler.class);
}
}

@Autowired
private SendContinueRequestHandler sendContinueRequestHandler;

@Test
public void When_ReceivingEhrExtract_WithMhsOutboundServerError_Expect_MigrationHasProcessingError() {
doThrow(MhsServerErrorException.class)
.when(sendContinueRequestHandler).prepareAndSendRequest(any());

sendInboundMessageToQueue(JSON_LARGE_MESSAGE_SCENARIO_3_UK_06_JSON);

await().until(() -> hasMigrationStatus(EHR_GENERAL_PROCESSING_ERROR, getConversationId()));

verify(sendContinueRequestHandler, times(1)).prepareAndSendRequest(any());

assertThat(getCurrentMigrationStatus(getConversationId()))
.isEqualTo(EHR_GENERAL_PROCESSING_ERROR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static uk.nhs.adaptors.common.enums.MigrationStatus.CONTINUE_REQUEST_ACCEPTED;
import static uk.nhs.adaptors.common.enums.MigrationStatus.EHR_EXTRACT_REQUEST_ACCEPTED;
import static uk.nhs.adaptors.common.enums.MigrationStatus.EHR_EXTRACT_REQUEST_ERROR;
import static uk.nhs.adaptors.common.enums.MigrationStatus.EHR_GENERAL_PROCESSING_ERROR;
import static uk.nhs.adaptors.common.enums.MigrationStatus.ERROR_LRG_MSG_GENERAL_FAILURE;
import static uk.nhs.adaptors.common.enums.MigrationStatus.REQUEST_RECEIVED;
import static uk.nhs.adaptors.common.enums.QueueMessageType.TRANSFER_REQUEST;
Expand Down Expand Up @@ -67,6 +66,7 @@
@ExtendWith({SpringExtension.class, MockitoExtension.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
@AutoConfigureMockMvc
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
public class ServiceFailureIT extends BaseEhrHandler {

private static final String LOSING_ASID = "LOSING_ASID";
Expand Down Expand Up @@ -141,22 +141,6 @@ public void When_SendingInitialRequest_WithMhsOutboundServerError_Expect_Migrati
.isEqualTo(EHR_EXTRACT_REQUEST_ERROR);
}

@Test
public void When_ReceivingEhrExtract_WithMhsOutboundServerError_Expect_MigrationHasProcessingError() {
doThrow(MhsServerErrorException.class)
.when(sendContinueRequestHandler).prepareAndSendRequest(any());

sendInboundMessageToQueue(JSON_LARGE_MESSAGE_SCENARIO_3_UK_06_JSON);

await().until(() -> hasMigrationStatus(EHR_GENERAL_PROCESSING_ERROR, getConversationId()));

verify(sendContinueRequestHandler, times(1))
.prepareAndSendRequest(any());

assertThat(getCurrentMigrationStatus(getConversationId()))
.isEqualTo(EHR_GENERAL_PROCESSING_ERROR);
}

@Test
public void When_ReceivingCOPC_WithDataFormatExceptionError_Expect_MessageSentToDLQ() {
doThrow(DataFormatException.class)
Expand Down Expand Up @@ -261,12 +245,12 @@ public void When_ReceivingCopc_WithMhsWebClientRequestException_Expect_Migration
await().until(this::hasContinueMessageBeenReceived);

doThrow(WebClientRequestException.class)
.doThrow(WebClientRequestException.class)
.doThrow(WebClientRequestException.class)
.doThrow(WebClientRequestException.class)
.doThrow(WebClientRequestException.class)
.doCallRealMethod()
.when(mhsClientService).send(any());
.doThrow(WebClientRequestException.class)
.doThrow(WebClientRequestException.class)
.doThrow(WebClientRequestException.class)
.doThrow(WebClientRequestException.class)
.doCallRealMethod()
.when(mhsClientService).send(any());

sendInboundMessageToQueue(JSON_LARGE_MESSAGE_SCENARIO_3_COPC_JSON);

Expand All @@ -288,8 +272,8 @@ public void When_ReceivingCopc_WithMhsWebClientResponseException_Expect_Migratio
doThrow(webClientResponseException)
.doThrow(webClientResponseException)
.doThrow(webClientResponseException)
.doCallRealMethod()
.when(mhsClientService).send(any());
.doCallRealMethod()
.when(mhsClientService).send(any());

sendInboundMessageToQueue(JSON_LARGE_MESSAGE_SCENARIO_3_COPC_JSON);

Expand Down Expand Up @@ -381,14 +365,6 @@ private void dlqCleanUp() {
}
}

private boolean hasMigrationStatus(MigrationStatus migrationStatus, String conversationId) {
return migrationStatus.equals(getCurrentMigrationStatus(conversationId));
}

private MigrationStatus getCurrentMigrationStatus(String conversationId) {
return getMigrationStatusLogService().getLatestMigrationStatusLog(conversationId).getMigrationStatus();
}

private void sendRequestToPssQueue(String conversationId, String patientNhsNumber) {

getPatientMigrationRequestDao()
Expand Down Expand Up @@ -424,4 +400,4 @@ private boolean hasContinueMessageBeenReceived() {
var migrationStatusLog = getMigrationStatusLogService().getLatestMigrationStatusLog(getConversationId());
return CONTINUE_REQUEST_ACCEPTED.equals(migrationStatusLog.getMigrationStatus());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage;

@Getter
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
public abstract class BaseEhrHandler {
public static final boolean OVERWRITE_EXPECTED_JSON = false;
private static final String REQUEST_JOURNAL_PATH = "/__admin/requests";
Expand Down Expand Up @@ -195,6 +196,14 @@ protected boolean hasNackBeenSentWithCode(String code) {
.contains("<code code=\\\"" + code + "\\\" codeSystem=\\\"2.16.840.1.113883.2.1.3.2.4.17.101\\\"");
}

protected boolean hasMigrationStatus(MigrationStatus migrationStatus, String conversationId) {
return migrationStatus.equals(getCurrentMigrationStatus(conversationId));
}

protected MigrationStatus getCurrentMigrationStatus(String conversationId) {
return getMigrationStatusLogService().getLatestMigrationStatusLog(conversationId).getMigrationStatus();
}

private List<Request> getMhsRequestsForConversation() {
var requestJournal = restTemplate.getForObject(mhsMockHost + REQUEST_JOURNAL_PATH, RequestJournal.class);

Expand Down
Loading