This repository was archived by the owner on Oct 2, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +39
-2
lines changed
main/java/uk/gov/hmcts/reform/bulkscanccdeventhandler/handler
test/java/uk/gov/hmcts/reform/bulkscanccdeventhandler/handler Expand file tree Collapse file tree 4 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ plugins {
1010}
1111
1212group ' uk.gov.hmcts.reform'
13- version ' 0.1 .0'
13+ version ' 0.2 .0'
1414
1515sourceCompatibility = 1.8
1616
Original file line number Diff line number Diff line change 22
33import uk .gov .hmcts .reform .bulkscanccdeventhandler .ccd .CcdClient ;
44import uk .gov .hmcts .reform .bulkscanccdeventhandler .handler .exceptions .InvalidTransformationResultTypeException ;
5+ import uk .gov .hmcts .reform .bulkscanccdeventhandler .handler .exceptions .TransformationException ;
56import uk .gov .hmcts .reform .bulkscanccdeventhandler .handler .model .CaseCreationRequest ;
67import uk .gov .hmcts .reform .bulkscanccdeventhandler .handler .model .CaseCreationResult ;
78import uk .gov .hmcts .reform .bulkscanccdeventhandler .handler .validation .CaseCreationRequestValidator ;
@@ -36,8 +37,19 @@ public ExceptionRecordEventHandler(
3637 public CaseCreationResult handle (CaseCreationRequest req ) {
3738 validator .validate (req );
3839
40+ final TransformationResult result ;
41+ try {
42+ result = transformer .transform (req .exceptionRecord );
43+ } catch (Exception exc ) {
44+ throw new TransformationException (
45+ "Provided transformer threw an exception when transforming exception record to a case. "
46+ + "See cause for details." ,
47+ exc
48+ );
49+ }
50+
3951 return handleTransformationResult (
40- transformer . transform ( req . exceptionRecord ) ,
52+ result ,
4153 okRes -> {
4254 if (okRes .warnings .isEmpty () || req .ignoreWarnings ) {
4355 // TODO: handle exceptions
Original file line number Diff line number Diff line change 1+ package uk .gov .hmcts .reform .bulkscanccdeventhandler .handler .exceptions ;
2+
3+ public class TransformationException extends RuntimeException {
4+ public TransformationException (String message , Throwable cause ) {
5+ super (message , cause );
6+ }
7+ }
Original file line number Diff line number Diff line change 66import org .mockito .Mock ;
77import org .mockito .junit .jupiter .MockitoExtension ;
88import uk .gov .hmcts .reform .bulkscanccdeventhandler .ccd .CcdClient ;
9+ import uk .gov .hmcts .reform .bulkscanccdeventhandler .handler .exceptions .TransformationException ;
910import uk .gov .hmcts .reform .bulkscanccdeventhandler .handler .model .CaseCreationRequest ;
1011import uk .gov .hmcts .reform .bulkscanccdeventhandler .handler .model .CaseCreationResult ;
1112import uk .gov .hmcts .reform .bulkscanccdeventhandler .handler .validation .CaseCreationRequestValidator ;
1516
1617import static java .util .Arrays .asList ;
1718import static org .assertj .core .api .Assertions .assertThat ;
19+ import static org .assertj .core .api .Assertions .catchThrowable ;
1820import static org .mockito .ArgumentMatchers .any ;
1921import static org .mockito .BDDMockito .given ;
2022import static org .mockito .Mockito .never ;
@@ -134,4 +136,20 @@ public void should_validate_request() {
134136 // then
135137 verify (validator ).validate (req );
136138 }
139+
140+ @ Test
141+ void should_throw_custom_exception_when_provided_transformer_fails () {
142+ // given
143+ CaseCreationRequest req = SampleCaseCreationRequest .caseCreationRequest ();
144+ RuntimeException cause = new RuntimeException ();
145+ given (transformer .transform (req .exceptionRecord )).willThrow (cause );
146+
147+ // when
148+ Throwable exc = catchThrowable (() -> handler .handle (req ));
149+
150+ //then
151+ assertThat (exc )
152+ .isInstanceOf (TransformationException .class )
153+ .hasCause (cause );
154+ }
137155}
You can’t perform that action at this time.
0 commit comments