1010import org .mockito .junit .jupiter .MockitoExtension ;
1111import org .springframework .beans .factory .annotation .Autowired ;
1212import org .springframework .boot .test .context .SpringBootTest ;
13+ import org .springframework .boot .test .mock .mockito .MockBean ;
1314import org .springframework .http .HttpStatus ;
1415import org .springframework .test .annotation .DirtiesContext ;
1516import org .springframework .test .context .junit .jupiter .SpringExtension ;
17+ import uk .nhs .adaptors .gp2gp .common .task .TaskDispatcher ;
1618import uk .nhs .adaptors .gp2gp .ehr .model .EhrExtractStatus ;
19+ import uk .nhs .adaptors .gp2gp .gpc .GetGpcStructuredTaskDefinition ;
1720import uk .nhs .adaptors .gp2gp .testcontainers .ActiveMQExtension ;
1821import uk .nhs .adaptors .gp2gp .testcontainers .MongoDBExtension ;
1922
2528
2629import static org .assertj .core .api .Assertions .assertThat ;
2730import static org .hl7 .fhir .dstu3 .model .OperationOutcome .IssueType ;
31+ import static org .mockito .Mockito .times ;
32+ import static org .mockito .Mockito .verify ;
2833import static uk .nhs .adaptors .gp2gp .ehr .EhrStatusConstants .INCUMBENT_NACK_CODE ;
2934import 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
0 commit comments