@@ -48,6 +48,47 @@ public class EndToEndTest extends MockCoreConfig {
4848 private static final int INTERNAL_SERVER_ERROR = 500 ;
4949 private static final int GONE_CLIENT = 410 ;
5050
51+ /**
52+ * Map of Global Error Cases
53+ */
54+ private static final Map <String , ErrorCase <CoreApiException >> GLOBAL_ERROR_CASES =
55+ new HashMap <String , ErrorCase <CoreApiException >>() {
56+ private static final long serialVersionUID = 1L ;
57+ {
58+ put ("400" , ErrorCase .setTemplate (
59+ "Failed to make the request, {$statusCode} {$response.body#/errors/0/code} - "
60+ + "{$response.body#/errors/0/detail}" ,
61+ (reason , context ) -> new GlobalTestException (reason , context )));
62+ put ("404" , ErrorCase .setReason ("Not found" ,
63+ (reason , context ) -> new CoreApiException (reason , context )));
64+ put ("401" ,
65+ ErrorCase .setTemplate ("Failed to make the request, "
66+ + "{$response.header.content-type} {$response.body#/errors/0/code}"
67+ + " - {$response.body#/errors/0/detail}" ,
68+ (reason , context ) -> new CoreApiException (reason , context )));
69+ put ("410" ,
70+ ErrorCase .setTemplate ("Failed to make the request, {$response.body}" ,
71+ (reason , context ) -> new CoreApiException (reason , context )));
72+ put ("405" ,
73+ ErrorCase .setTemplate ("Failed to make the request, {$response.header.accept} "
74+ + "{$response.body#/errors/0/code} - {$response.body#/errors/0/detail}" ,
75+ (reason , context ) -> new CoreApiException (reason , context )));
76+ put ("500" ,
77+ ErrorCase .setTemplate ("Failed to make the request, http status code:"
78+ + " {$statusCode}" ,
79+ (reason , context ) -> new CoreApiException (reason , context )));
80+ put ("4XX" ,
81+ ErrorCase .setTemplate (
82+ "Failed to make the request, {$response.body#/errors/0/code}"
83+ + " - {$response.body#/errors/0/detail}" ,
84+ (reason , context ) -> new CoreApiException (reason , context )));
85+ put (ErrorCase .DEFAULT ,
86+ ErrorCase .setReason (
87+ "Failed to make the request, {$response.body#/errors/0/code}"
88+ + " - {$response.body#/errors/0/detail}" ,
89+ (reason , context ) -> new CoreApiException (reason , context )));
90+ }};
91+
5192 /**
5293 * Initializes mocks annotated with Mock.
5394 */
@@ -415,7 +456,7 @@ private ApiCall<String, CoreApiException> getApiCallGlobalErrorTemplate(String r
415456 .authenticationKey ("global" ).httpMethod (Method .GET ))
416457 .responseHandler (responseHandler -> responseHandler
417458 .deserializer (response -> CoreHelper .deserialize (response , String .class ))
418- .nullify404 (false ).globalErrorCase (getGlobalErrorCases () ))
459+ .nullify404 (false ).globalErrorCase (GLOBAL_ERROR_CASES ))
419460 .endpointConfiguration (
420461 param -> param .arraySerializationFormat (ArraySerializationFormat .INDEXED )
421462 .hasBinaryResponse (false ).retryOption (RetryOption .DEFAULT ))
@@ -441,7 +482,7 @@ private ApiCall<String, CoreApiException> getApiCallGlobalErrorTemplateWithHeade
441482 .authenticationKey ("global" ).httpMethod (Method .GET ))
442483 .responseHandler (responseHandler -> responseHandler
443484 .deserializer (response -> CoreHelper .deserialize (response , String .class ))
444- .nullify404 (false ).globalErrorCase (getGlobalErrorCases () ))
485+ .nullify404 (false ).globalErrorCase (GLOBAL_ERROR_CASES ))
445486 .endpointConfiguration (
446487 param -> param .arraySerializationFormat (ArraySerializationFormat .INDEXED )
447488 .hasBinaryResponse (false ).retryOption (RetryOption .DEFAULT ))
@@ -475,49 +516,4 @@ private void prepareStub() throws IOException {
475516 when (context .getResponse ()).thenReturn (response );
476517 when (response .getStatusCode ()).thenReturn (SUCCESS_CODE );
477518 }
478-
479- private Map <String , ErrorCase <CoreApiException >> getGlobalErrorCases () {
480- Map <String , ErrorCase <CoreApiException >> globalErrorCase = new HashMap <>();
481- globalErrorCase .put ("400" , ErrorCase .setTemplate (
482- "Failed to make the request, {$statusCode} {$response.body#/errors/0/code} - "
483- + "{$response.body#/errors/0/detail}" ,
484- (reason , context ) -> new GlobalTestException (reason , context )));
485-
486- globalErrorCase .put ("404" , ErrorCase .setReason ("Not found" ,
487- (reason , context ) -> new CoreApiException (reason , context )));
488-
489- globalErrorCase .put ("401" ,
490- ErrorCase .setTemplate ("Failed to make the request, {$response.header.content-type} "
491- + "{$response.body#/errors/0/code} - {$response.body#/errors/0/detail}" ,
492- (reason , context ) -> new CoreApiException (reason , context )));
493-
494- globalErrorCase .put ("410" ,
495- ErrorCase .setTemplate ("Failed to make the request, {$response.body}" ,
496- (reason , context ) -> new CoreApiException (reason , context )));
497-
498- globalErrorCase .put ("405" ,
499- ErrorCase .setTemplate ("Failed to make the request, {$response.header.accept} "
500- + "{$response.body#/errors/0/code} - {$response.body#/errors/0/detail}" ,
501- (reason , context ) -> new CoreApiException (reason , context )));
502-
503- globalErrorCase .put ("500" ,
504- ErrorCase .setTemplate ("Failed to make the request, http status code: {$statusCode}" ,
505- (reason , context ) -> new CoreApiException (reason , context )));
506-
507- globalErrorCase .put ("4XX" ,
508- ErrorCase .setTemplate (
509- "Failed to make the request, {$response.body#/errors/0/code} -"
510- + " {$response.body#/errors/0/detail}" ,
511- (reason , context ) -> new CoreApiException (reason , context )));
512-
513- globalErrorCase .put (ErrorCase .DEFAULT ,
514- ErrorCase .setReason (
515- "Failed to make the request, {$response.body#/errors/0/code} - "
516- + "{$response.body#/errors/0/detail}" ,
517- (reason , context ) -> new CoreApiException (reason , context )));
518-
519- return globalErrorCase ;
520-
521- }
522-
523519}
0 commit comments