@@ -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 */
@@ -418,7 +459,7 @@ private ApiCall<String, CoreApiException> getApiCallGlobalErrorTemplate(String r
418459 .httpMethod (Method .GET ))
419460 .responseHandler (responseHandler -> responseHandler
420461 .deserializer (response -> CoreHelper .deserialize (response , String .class ))
421- .nullify404 (false ).globalErrorCase (getGlobalErrorCases () ))
462+ .nullify404 (false ).globalErrorCase (GLOBAL_ERROR_CASES ))
422463 .endpointConfiguration (
423464 param -> param .arraySerializationFormat (ArraySerializationFormat .INDEXED )
424465 .hasBinaryResponse (false ).retryOption (RetryOption .DEFAULT ))
@@ -445,7 +486,7 @@ private ApiCall<String, CoreApiException> getApiCallGlobalErrorTemplateWithHeade
445486 .httpMethod (Method .GET ))
446487 .responseHandler (responseHandler -> responseHandler
447488 .deserializer (response -> CoreHelper .deserialize (response , String .class ))
448- .nullify404 (false ).globalErrorCase (getGlobalErrorCases () ))
489+ .nullify404 (false ).globalErrorCase (GLOBAL_ERROR_CASES ))
449490 .endpointConfiguration (
450491 param -> param .arraySerializationFormat (ArraySerializationFormat .INDEXED )
451492 .hasBinaryResponse (false ).retryOption (RetryOption .DEFAULT ))
@@ -479,49 +520,4 @@ private void prepareStub() throws IOException {
479520 when (context .getResponse ()).thenReturn (response );
480521 when (response .getStatusCode ()).thenReturn (SUCCESS_CODE );
481522 }
482-
483- private Map <String , ErrorCase <CoreApiException >> getGlobalErrorCases () {
484- Map <String , ErrorCase <CoreApiException >> globalErrorCase = new HashMap <>();
485- globalErrorCase .put ("400" , ErrorCase .setTemplate (
486- "Failed to make the request, {$statusCode} {$response.body#/errors/0/code} - "
487- + "{$response.body#/errors/0/detail}" ,
488- (reason , context ) -> new GlobalTestException (reason , context )));
489-
490- globalErrorCase .put ("404" , ErrorCase .setReason ("Not found" ,
491- (reason , context ) -> new CoreApiException (reason , context )));
492-
493- globalErrorCase .put ("401" ,
494- ErrorCase .setTemplate ("Failed to make the request, {$response.header.content-type} "
495- + "{$response.body#/errors/0/code} - {$response.body#/errors/0/detail}" ,
496- (reason , context ) -> new CoreApiException (reason , context )));
497-
498- globalErrorCase .put ("410" ,
499- ErrorCase .setTemplate ("Failed to make the request, {$response.body}" ,
500- (reason , context ) -> new CoreApiException (reason , context )));
501-
502- globalErrorCase .put ("405" ,
503- ErrorCase .setTemplate ("Failed to make the request, {$response.header.accept} "
504- + "{$response.body#/errors/0/code} - {$response.body#/errors/0/detail}" ,
505- (reason , context ) -> new CoreApiException (reason , context )));
506-
507- globalErrorCase .put ("500" ,
508- ErrorCase .setTemplate ("Failed to make the request, http status code: {$statusCode}" ,
509- (reason , context ) -> new CoreApiException (reason , context )));
510-
511- globalErrorCase .put ("4XX" ,
512- ErrorCase .setTemplate (
513- "Failed to make the request, {$response.body#/errors/0/code} -"
514- + " {$response.body#/errors/0/detail}" ,
515- (reason , context ) -> new CoreApiException (reason , context )));
516-
517- globalErrorCase .put (ErrorCase .DEFAULT ,
518- ErrorCase .setReason (
519- "Failed to make the request, {$response.body#/errors/0/code} - "
520- + "{$response.body#/errors/0/detail}" ,
521- (reason , context ) -> new CoreApiException (reason , context )));
522-
523- return globalErrorCase ;
524-
525- }
526-
527523}
0 commit comments