Skip to content

Commit 8b42391

Browse files
committed
adding a test for GpcStructureTask scheduler
1 parent 49dd7e8 commit 8b42391

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

service/src/intTest/java/uk/nhs/adaptors/gp2gp/ehr/EhrResendControllerTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
import org.mockito.junit.jupiter.MockitoExtension;
1111
import org.springframework.beans.factory.annotation.Autowired;
1212
import org.springframework.boot.test.context.SpringBootTest;
13+
import org.springframework.boot.test.mock.mockito.MockBean;
1314
import org.springframework.http.HttpStatus;
1415
import org.springframework.test.annotation.DirtiesContext;
1516
import org.springframework.test.context.junit.jupiter.SpringExtension;
17+
import uk.nhs.adaptors.gp2gp.common.task.TaskDispatcher;
1618
import uk.nhs.adaptors.gp2gp.ehr.model.EhrExtractStatus;
19+
import uk.nhs.adaptors.gp2gp.gpc.GetGpcStructuredTaskDefinition;
1720
import uk.nhs.adaptors.gp2gp.testcontainers.ActiveMQExtension;
1821
import uk.nhs.adaptors.gp2gp.testcontainers.MongoDBExtension;
1922

@@ -25,6 +28,8 @@
2528

2629
import static org.assertj.core.api.Assertions.assertThat;
2730
import static org.hl7.fhir.dstu3.model.OperationOutcome.IssueType;
31+
import static org.mockito.Mockito.times;
32+
import static org.mockito.Mockito.verify;
2833
import static uk.nhs.adaptors.gp2gp.ehr.EhrStatusConstants.INCUMBENT_NACK_CODE;
2934
import static uk.nhs.adaptors.gp2gp.ehr.EhrStatusConstants.INCUMBENT_NACK_DISPLAY;
3035

@@ -44,6 +49,9 @@ public class EhrResendControllerTest {
4449
@Autowired
4550
private EhrResendController ehrResendController;
4651

52+
@MockBean
53+
private TaskDispatcher taskDispatcher;
54+
4755
@Test
4856
public void When_AnEhrExtractHasFailed_Expect_RespondsWith202() {
4957

@@ -71,6 +79,34 @@ public void When_AnEhrExtractHasFailed_Expect_RespondsWith202() {
7179
assertThat(response.getBody()).isNull();
7280
}
7381

82+
@Test
83+
public void When_AnEhrExtractHasFailed_Expect_GetGpcStructuredTaskScheduled() {
84+
85+
String ehrMessageRef = generateRandomUppercaseUUID();
86+
var ehrExtractStatus = new EhrExtractStatus();
87+
88+
ehrExtractStatus.setConversationId(CONVERSATION_ID);
89+
ehrExtractStatus.setEhrReceivedAcknowledgement(EhrExtractStatus.EhrReceivedAcknowledgement.builder()
90+
.conversationClosed(FIVE_DAYS_AGO)
91+
.errors(List.of(
92+
EhrExtractStatus.EhrReceivedAcknowledgement.ErrorDetails.builder()
93+
.code(INCUMBENT_NACK_CODE)
94+
.display(INCUMBENT_NACK_DISPLAY)
95+
.build()))
96+
.messageRef(ehrMessageRef)
97+
.received(FIVE_DAYS_AGO)
98+
.rootId(generateRandomUppercaseUUID())
99+
.build());
100+
101+
ehrExtractStatusRepository.save(ehrExtractStatus);
102+
103+
ehrResendController.scheduleEhrExtractResend(CONVERSATION_ID);
104+
105+
var taskDefinition = GetGpcStructuredTaskDefinition.builder().build();
106+
verify(taskDispatcher, times(1)).createTask(taskDefinition);
107+
108+
}
109+
74110
@Test
75111
public void When_AnEhrExtractDoesNotExist_Expect_RespondsWith404() {
76112

service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/EhrResendController.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
import org.springframework.web.bind.annotation.PostMapping;
1414
import org.springframework.web.bind.annotation.RequestMapping;
1515
import org.springframework.web.bind.annotation.RestController;
16+
import uk.nhs.adaptors.gp2gp.common.task.TaskDispatcher;
1617
import uk.nhs.adaptors.gp2gp.ehr.model.EhrExtractStatus;
18+
import uk.nhs.adaptors.gp2gp.gpc.GetGpcStructuredTaskDefinition;
1719

1820
import java.util.Collections;
1921
import java.util.List;
@@ -27,6 +29,7 @@ public class EhrResendController {
2729
private static final String OPERATION_OUTCOME_URL = "https://fhir.nhs.uk/STU3/StructureDefinition/GPConnect-OperationOutcome-1";
2830

2931
private EhrExtractStatusRepository ehrExtractStatusRepository;
32+
private TaskDispatcher taskDispatcher;
3033

3134
@PostMapping("/{conversationId}")
3235
public ResponseEntity<OperationOutcome> scheduleEhrExtractResend(@PathVariable String conversationId) {
@@ -48,10 +51,13 @@ public ResponseEntity<OperationOutcome> scheduleEhrExtractResend(@PathVariable S
4851
return new ResponseEntity<>(operationOutcome, HttpStatus.NOT_FOUND);
4952
}
5053

51-
return new ResponseEntity<>(HttpStatus.ACCEPTED);
54+
var taskDefinition = GetGpcStructuredTaskDefinition.builder().build();
55+
taskDispatcher.createTask(taskDefinition);
5256

57+
return new ResponseEntity<>(HttpStatus.ACCEPTED);
5358
}
5459

60+
5561
public static OperationOutcome createOperationOutcome(
5662
OperationOutcome.IssueType type, OperationOutcome.IssueSeverity severity, CodeableConcept details, String diagnostics) {
5763
var operationOutcome = new OperationOutcome();

0 commit comments

Comments
 (0)