@Test public void failedWithAmazonServiceException() throws JSONException { InternalServerException internalServerException = new InternalServerException(TestConstants.DUMMY_ERROR_MESSAGE); internalServerException.setErrorCode(TestConstants.ERROR_CODE); internalServerException.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); internalServerException.setRequestId(TestConstants.DUMMY_REQUEST_ID); internalServerException.setServiceName(ComprehendOperationEnum.DetectSentiment.toString()); internalServerException.setErrorMessage(CustomerMessage.INTERNAL_ERROR); test = new SingularOperationCallable(TestConstants.FIELD_NAME, ComprehendOperationEnum.DetectDominantLanguage, TestConstants.LANGUAGE_CODE, TestConstants.CUSTOMER_INGESTION_PAYLOAD_TEXT, mockComprehendClient); when(mockComprehendClient.detectDominantLanguage(any())) .thenThrow(internalServerException); SingularResponse response = test.call(); JSONObject result = response.getComprehendResult(); assertEquals(String.format("%s_Error", TestConstants.FIELD_NAME), response.getFieldNameAndOperation()); assertEquals(TestConstants.ERROR_CODE, result.get(TestConstants.ERROR_CODE_KEY)); assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, result.get(TestConstants.STATUS_CODE_KEY)); assertEquals(TestConstants.DUMMY_REQUEST_ID, result.get(TestConstants.REQUEST_ID_KEY)); assertEquals(CustomerMessage.INTERNAL_ERROR, result.get(TestConstants.ERROR_MESSAGE_KEY)); }
@Override public SingularResponse call() { try { return comprehendOperation.getComprehendOperation() .sendSingularRequest(fieldNameAndOperation, content, languageCode, comprehendClient); } catch (AmazonServiceException e) { ServiceExceptionMessage serviceException = ServiceExceptionMessage.builder() .statusCode(e.getStatusCode()) .errorCode(e.getErrorCode()) .requestId(e.getRequestId()) .errorMessage(e.getErrorMessage()) .build(); return new SingularResponse(String.format("%s_Error", fieldNameAndOperation), new JSONObject(serviceException), null); } catch (AmazonClientException e) { ClientExceptionMessage clientException = ClientExceptionMessage.builder() .errorCode(Constants.CLIENT_EXCEPTION_ERROR_CODE) .errorMessage(e.getMessage()) .build(); return new SingularResponse(String.format("%s_Error", fieldNameAndOperation), new JSONObject(clientException), null); } }
SingularOperationCallable implements Callable<SingularResponse> { @Override public SingularResponse call() { try { return comprehendOperation.getComprehendOperation() .sendSingularRequest(fieldNameAndOperation, content, languageCode, comprehendClient); } catch (AmazonServiceException e) { ServiceExceptionMessage serviceException = ServiceExceptionMessage.builder() .statusCode(e.getStatusCode()) .errorCode(e.getErrorCode()) .requestId(e.getRequestId()) .errorMessage(e.getErrorMessage()) .build(); return new SingularResponse(String.format("%s_Error", fieldNameAndOperation), new JSONObject(serviceException), null); } catch (AmazonClientException e) { ClientExceptionMessage clientException = ClientExceptionMessage.builder() .errorCode(Constants.CLIENT_EXCEPTION_ERROR_CODE) .errorMessage(e.getMessage()) .build(); return new SingularResponse(String.format("%s_Error", fieldNameAndOperation), new JSONObject(clientException), null); } } }
SingularOperationCallable implements Callable<SingularResponse> { @Override public SingularResponse call() { try { return comprehendOperation.getComprehendOperation() .sendSingularRequest(fieldNameAndOperation, content, languageCode, comprehendClient); } catch (AmazonServiceException e) { ServiceExceptionMessage serviceException = ServiceExceptionMessage.builder() .statusCode(e.getStatusCode()) .errorCode(e.getErrorCode()) .requestId(e.getRequestId()) .errorMessage(e.getErrorMessage()) .build(); return new SingularResponse(String.format("%s_Error", fieldNameAndOperation), new JSONObject(serviceException), null); } catch (AmazonClientException e) { ClientExceptionMessage clientException = ClientExceptionMessage.builder() .errorCode(Constants.CLIENT_EXCEPTION_ERROR_CODE) .errorMessage(e.getMessage()) .build(); return new SingularResponse(String.format("%s_Error", fieldNameAndOperation), new JSONObject(clientException), null); } }  }
SingularOperationCallable implements Callable<SingularResponse> { @Override public SingularResponse call() { try { return comprehendOperation.getComprehendOperation() .sendSingularRequest(fieldNameAndOperation, content, languageCode, comprehendClient); } catch (AmazonServiceException e) { ServiceExceptionMessage serviceException = ServiceExceptionMessage.builder() .statusCode(e.getStatusCode()) .errorCode(e.getErrorCode()) .requestId(e.getRequestId()) .errorMessage(e.getErrorMessage()) .build(); return new SingularResponse(String.format("%s_Error", fieldNameAndOperation), new JSONObject(serviceException), null); } catch (AmazonClientException e) { ClientExceptionMessage clientException = ClientExceptionMessage.builder() .errorCode(Constants.CLIENT_EXCEPTION_ERROR_CODE) .errorMessage(e.getMessage()) .build(); return new SingularResponse(String.format("%s_Error", fieldNameAndOperation), new JSONObject(clientException), null); } }  @Override SingularResponse call(); }
SingularOperationCallable implements Callable<SingularResponse> { @Override public SingularResponse call() { try { return comprehendOperation.getComprehendOperation() .sendSingularRequest(fieldNameAndOperation, content, languageCode, comprehendClient); } catch (AmazonServiceException e) { ServiceExceptionMessage serviceException = ServiceExceptionMessage.builder() .statusCode(e.getStatusCode()) .errorCode(e.getErrorCode()) .requestId(e.getRequestId()) .errorMessage(e.getErrorMessage()) .build(); return new SingularResponse(String.format("%s_Error", fieldNameAndOperation), new JSONObject(serviceException), null); } catch (AmazonClientException e) { ClientExceptionMessage clientException = ClientExceptionMessage.builder() .errorCode(Constants.CLIENT_EXCEPTION_ERROR_CODE) .errorMessage(e.getMessage()) .build(); return new SingularResponse(String.format("%s_Error", fieldNameAndOperation), new JSONObject(clientException), null); } }  @Override SingularResponse call();  }