Skip to content

Commit 7d09c87

Browse files
committed
DIAC-1587 wip
1 parent 67a458d commit 7d09c87

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package uk.gov.hmcts.reform.iacaseapi.domain.handlers.postsubmit;
2+
3+
import static java.util.Objects.requireNonNull;
4+
5+
import org.springframework.stereotype.Component;
6+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase;
7+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event;
8+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.Callback;
9+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PostSubmitCallbackResponse;
10+
import uk.gov.hmcts.reform.iacaseapi.domain.handlers.PostSubmitCallbackHandler;
11+
12+
@Component
13+
public class ForceFtpaDecidedStateConfirmation implements PostSubmitCallbackHandler<AsylumCase> {
14+
15+
public boolean canHandle(
16+
Callback<AsylumCase> callback
17+
) {
18+
requireNonNull(callback, "callback must not be null");
19+
20+
return callback.getEvent() == Event.FORCE_FTPA_DECIDED_STATE;
21+
}
22+
23+
public PostSubmitCallbackResponse handle(
24+
Callback<AsylumCase> callback
25+
) {
26+
if (!canHandle(callback)) {
27+
throw new IllegalStateException("Cannot handle callback");
28+
}
29+
30+
PostSubmitCallbackResponse postSubmitResponse =
31+
new PostSubmitCallbackResponse();
32+
33+
postSubmitResponse.setConfirmationHeader("# The appeal has been moved to the FTPA decided state");
34+
postSubmitResponse.setConfirmationBody(
35+
"#### What happens next\n\n"
36+
+ "The appeal can now be progressed from the FTPA decided state."
37+
);
38+
39+
return postSubmitResponse;
40+
}
41+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package uk.gov.hmcts.reform.iacaseapi.domain.handlers.postsubmit;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
5+
import static org.junit.jupiter.api.Assertions.assertFalse;
6+
import static org.junit.jupiter.api.Assertions.assertNotNull;
7+
import static org.junit.jupiter.api.Assertions.assertTrue;
8+
import static org.mockito.Mockito.reset;
9+
import static org.mockito.Mockito.when;
10+
11+
import org.junit.jupiter.api.BeforeEach;
12+
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.api.extension.ExtendWith;
14+
import org.mockito.Mock;
15+
import org.mockito.junit.jupiter.MockitoExtension;
16+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase;
17+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event;
18+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.Callback;
19+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PostSubmitCallbackResponse;
20+
21+
@ExtendWith(MockitoExtension.class)
22+
@SuppressWarnings("unchecked")
23+
class ForceFtpaDecidedStateConfirmationTest {
24+
25+
@Mock
26+
private Callback<AsylumCase> callback;
27+
28+
private ForceFtpaDecidedStateConfirmation forceFtpaDecidedStateConfirmation;
29+
30+
@BeforeEach
31+
public void setUp() {
32+
forceFtpaDecidedStateConfirmation = new ForceFtpaDecidedStateConfirmation();
33+
}
34+
35+
@Test
36+
void should_return_confirmation() {
37+
38+
when(callback.getEvent()).thenReturn(Event.FORCE_FTPA_DECIDED_STATE);
39+
40+
PostSubmitCallbackResponse callbackResponse =
41+
forceFtpaDecidedStateConfirmation.handle(callback);
42+
43+
assertNotNull(callbackResponse);
44+
assertTrue(callbackResponse.getConfirmationHeader().isPresent());
45+
assertTrue(callbackResponse.getConfirmationBody().isPresent());
46+
47+
assertThat(
48+
callbackResponse.getConfirmationHeader().get())
49+
.contains("# The appeal has been moved to the FTPA decided state");
50+
51+
assertThat(
52+
callbackResponse.getConfirmationBody().get())
53+
.contains("#### What happens next");
54+
55+
assertThat(
56+
callbackResponse.getConfirmationBody().get())
57+
.contains("The appeal can now be progressed from the FTPA decided state.");
58+
}
59+
60+
@Test
61+
void handling_should_throw_if_cannot_actually_handle() {
62+
63+
assertThatThrownBy(() -> forceFtpaDecidedStateConfirmation.handle(callback))
64+
.hasMessage("Cannot handle callback")
65+
.isExactlyInstanceOf(IllegalStateException.class);
66+
}
67+
68+
@Test
69+
void it_can_handle_callback() {
70+
71+
for (Event event : Event.values()) {
72+
73+
when(callback.getEvent()).thenReturn(event);
74+
75+
boolean canHandle = forceFtpaDecidedStateConfirmation.canHandle(callback);
76+
77+
if (event == Event.FORCE_FTPA_DECIDED_STATE) {
78+
79+
assertTrue(canHandle);
80+
} else {
81+
assertFalse(canHandle);
82+
}
83+
84+
reset(callback);
85+
}
86+
}
87+
88+
@Test
89+
void should_not_allow_null_arguments() {
90+
91+
assertThatThrownBy(() -> forceFtpaDecidedStateConfirmation.canHandle(null))
92+
.hasMessage("callback must not be null")
93+
.isExactlyInstanceOf(NullPointerException.class);
94+
95+
assertThatThrownBy(() -> forceFtpaDecidedStateConfirmation.handle(null))
96+
.hasMessage("callback must not be null")
97+
.isExactlyInstanceOf(NullPointerException.class);
98+
}
99+
}

0 commit comments

Comments
 (0)