Skip to content

Commit d065fd8

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

File tree

5 files changed

+396
-0
lines changed

5 files changed

+396
-0
lines changed

src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/entities/AsylumCaseFieldDefinition.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2857,6 +2857,12 @@ public enum AsylumCaseFieldDefinition {
28572857

28582858
APPELLANT_DETAINED_DATE("appellantDetainedDate",
28592859
new TypeReference<String>(){}),
2860+
2861+
HAS_BEEN_DECIDED("hasBeenDecided",
2862+
new TypeReference<YesOrNo>(){}),
2863+
2864+
HAS_BEEN_FTPA_DECIDED("hasBeenFtpaDecided",
2865+
new TypeReference<YesOrNo>(){}),
28602866
;
28612867

28622868
private final String value;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package uk.gov.hmcts.reform.iacaseapi.domain.handlers.presubmit;
2+
3+
import static java.util.Objects.requireNonNull;
4+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.HAS_BEEN_DECIDED;
5+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event.FORCE_DECIDED_STATE;
6+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event.SEND_DECISION_AND_REASONS;
7+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage.ABOUT_TO_SUBMIT;
8+
9+
import org.springframework.stereotype.Component;
10+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase;
11+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event;
12+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.Callback;
13+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackResponse;
14+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage;
15+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.YesOrNo;
16+
import uk.gov.hmcts.reform.iacaseapi.domain.handlers.PreSubmitCallbackHandler;
17+
18+
@Component
19+
public class DecidedFlagHandler implements PreSubmitCallbackHandler<AsylumCase> {
20+
21+
public boolean canHandle(
22+
PreSubmitCallbackStage callbackStage,
23+
Callback<AsylumCase> callback) {
24+
requireNonNull(callbackStage, "callbackStage must not be null");
25+
requireNonNull(callback, "callback must not be null");
26+
27+
Event event = callback.getEvent();
28+
return callbackStage.equals(ABOUT_TO_SUBMIT) &&
29+
event.equals(SEND_DECISION_AND_REASONS) ||
30+
event.equals(FORCE_DECIDED_STATE);
31+
}
32+
33+
public PreSubmitCallbackResponse<AsylumCase> handle(PreSubmitCallbackStage callbackStage, Callback<AsylumCase> callback) {
34+
if (!canHandle(callbackStage, callback)) {
35+
throw new IllegalStateException("Cannot handle callback");
36+
}
37+
38+
AsylumCase asylumCase =
39+
callback
40+
.getCaseDetails()
41+
.getCaseData();
42+
43+
asylumCase.write(HAS_BEEN_DECIDED, YesOrNo.YES);
44+
45+
return new PreSubmitCallbackResponse<>(asylumCase);
46+
}
47+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package uk.gov.hmcts.reform.iacaseapi.domain.handlers.presubmit;
2+
3+
import static java.util.Objects.requireNonNull;
4+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.HAS_BEEN_DECIDED;
5+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.HAS_BEEN_FTPA_DECIDED;
6+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event.FORCE_FTPA_DECIDED_STATE;
7+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event.LEADERSHIP_JUDGE_FTPA_DECISION;
8+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event.RESIDENT_JUDGE_FTPA_DECISION;
9+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage.ABOUT_TO_SUBMIT;
10+
11+
import org.springframework.stereotype.Component;
12+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase;
13+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event;
14+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.Callback;
15+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackResponse;
16+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage;
17+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.YesOrNo;
18+
import uk.gov.hmcts.reform.iacaseapi.domain.handlers.PreSubmitCallbackHandler;
19+
20+
@Component
21+
public class FtpaDecidedFlagHandler implements PreSubmitCallbackHandler<AsylumCase> {
22+
23+
public boolean canHandle(
24+
PreSubmitCallbackStage callbackStage,
25+
Callback<AsylumCase> callback) {
26+
requireNonNull(callbackStage, "callbackStage must not be null");
27+
requireNonNull(callback, "callback must not be null");
28+
29+
Event event = callback.getEvent();
30+
return callbackStage.equals(ABOUT_TO_SUBMIT) &&
31+
event.equals(LEADERSHIP_JUDGE_FTPA_DECISION) ||
32+
event.equals(RESIDENT_JUDGE_FTPA_DECISION) ||
33+
event.equals(FORCE_FTPA_DECIDED_STATE);
34+
}
35+
36+
public PreSubmitCallbackResponse<AsylumCase> handle(PreSubmitCallbackStage callbackStage, Callback<AsylumCase> callback) {
37+
if (!canHandle(callbackStage, callback)) {
38+
throw new IllegalStateException("Cannot handle callback");
39+
}
40+
41+
AsylumCase asylumCase =
42+
callback
43+
.getCaseDetails()
44+
.getCaseData();
45+
46+
asylumCase.write(HAS_BEEN_DECIDED, YesOrNo.YES);
47+
asylumCase.write(HAS_BEEN_FTPA_DECIDED, YesOrNo.YES);
48+
49+
return new PreSubmitCallbackResponse<>(asylumCase);
50+
}
51+
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
package uk.gov.hmcts.reform.iacaseapi.domain.handlers.presubmit;
2+
3+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
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.verify;
10+
import static org.mockito.Mockito.when;
11+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.HAS_BEEN_DECIDED;
12+
13+
import org.junit.jupiter.api.BeforeEach;
14+
import org.junit.jupiter.api.Test;
15+
import org.junit.jupiter.api.extension.ExtendWith;
16+
import org.mockito.Mock;
17+
import org.mockito.junit.jupiter.MockitoExtension;
18+
import org.mockito.junit.jupiter.MockitoSettings;
19+
import org.mockito.quality.Strictness;
20+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase;
21+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.CaseDetails;
22+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event;
23+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.Callback;
24+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackResponse;
25+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage;
26+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.YesOrNo;
27+
28+
@MockitoSettings(strictness = Strictness.LENIENT)
29+
@ExtendWith(MockitoExtension.class)
30+
@SuppressWarnings("unchecked")
31+
class DecidedFlagHandlerTest {
32+
33+
@Mock
34+
private Callback<AsylumCase> callback;
35+
@Mock
36+
private CaseDetails<AsylumCase> caseDetails;
37+
@Mock
38+
private AsylumCase asylumCase;
39+
40+
private DecidedFlagHandler decidedFlagHandler;
41+
42+
@BeforeEach
43+
public void setUp() {
44+
decidedFlagHandler = new DecidedFlagHandler();
45+
}
46+
47+
@Test
48+
void should_set_has_been_decided_flag_for_send_decision_and_reasons() {
49+
50+
when(callback.getCaseDetails()).thenReturn(caseDetails);
51+
when(callback.getEvent()).thenReturn(Event.SEND_DECISION_AND_REASONS);
52+
when(caseDetails.getCaseData()).thenReturn(asylumCase);
53+
54+
PreSubmitCallbackResponse<AsylumCase> returnedCallbackResponse =
55+
decidedFlagHandler.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback);
56+
57+
assertNotNull(returnedCallbackResponse);
58+
assertEquals(asylumCase, returnedCallbackResponse.getData());
59+
verify(asylumCase).write(HAS_BEEN_DECIDED, YesOrNo.YES);
60+
}
61+
62+
@Test
63+
void should_set_has_been_decided_flag_for_force_decided_state() {
64+
65+
when(callback.getCaseDetails()).thenReturn(caseDetails);
66+
when(callback.getEvent()).thenReturn(Event.FORCE_DECIDED_STATE);
67+
when(caseDetails.getCaseData()).thenReturn(asylumCase);
68+
69+
PreSubmitCallbackResponse<AsylumCase> returnedCallbackResponse =
70+
decidedFlagHandler.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback);
71+
72+
assertNotNull(returnedCallbackResponse);
73+
assertEquals(asylumCase, returnedCallbackResponse.getData());
74+
verify(asylumCase).write(HAS_BEEN_DECIDED, YesOrNo.YES);
75+
}
76+
77+
@Test
78+
void handling_should_throw_if_cannot_actually_handle() {
79+
80+
when(callback.getEvent()).thenReturn(Event.SEND_DECISION_AND_REASONS);
81+
assertThatThrownBy(
82+
() -> decidedFlagHandler.handle(PreSubmitCallbackStage.ABOUT_TO_START, callback))
83+
.hasMessage("Cannot handle callback")
84+
.isExactlyInstanceOf(IllegalStateException.class);
85+
86+
when(callback.getEvent()).thenReturn(Event.SUBMIT_APPEAL);
87+
assertThatThrownBy(
88+
() -> decidedFlagHandler.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback))
89+
.hasMessage("Cannot handle callback")
90+
.isExactlyInstanceOf(IllegalStateException.class);
91+
}
92+
93+
@Test
94+
void it_can_handle_callback() {
95+
96+
for (Event event : Event.values()) {
97+
98+
when(callback.getEvent()).thenReturn(event);
99+
100+
for (PreSubmitCallbackStage callbackStage : PreSubmitCallbackStage.values()) {
101+
102+
boolean canHandle = decidedFlagHandler.canHandle(callbackStage, callback);
103+
104+
if ((event == Event.SEND_DECISION_AND_REASONS && callbackStage == PreSubmitCallbackStage.ABOUT_TO_SUBMIT)
105+
|| event == Event.FORCE_DECIDED_STATE) {
106+
107+
assertTrue(canHandle, "Expected to handle event: " + event + " and stage: " + callbackStage);
108+
} else {
109+
assertFalse(canHandle, "Expected not to handle event: " + event + " and stage: " + callbackStage);
110+
}
111+
}
112+
113+
reset(callback);
114+
}
115+
}
116+
117+
@Test
118+
void should_not_allow_null_arguments() {
119+
120+
assertThatThrownBy(() -> decidedFlagHandler.canHandle(null, callback))
121+
.hasMessage("callbackStage must not be null")
122+
.isExactlyInstanceOf(NullPointerException.class);
123+
124+
assertThatThrownBy(() -> decidedFlagHandler.canHandle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, null))
125+
.hasMessage("callback must not be null")
126+
.isExactlyInstanceOf(NullPointerException.class);
127+
128+
assertThatThrownBy(() -> decidedFlagHandler.handle(null, callback))
129+
.hasMessage("callbackStage must not be null")
130+
.isExactlyInstanceOf(NullPointerException.class);
131+
132+
assertThatThrownBy(() -> decidedFlagHandler.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, null))
133+
.hasMessage("callback must not be null")
134+
.isExactlyInstanceOf(NullPointerException.class);
135+
}
136+
}

0 commit comments

Comments
 (0)