@Test public void failedWithAmazonClientException() throws JSONException { AmazonClientException clientException = new AmazonClientException(TestConstants.DUMMY_ERROR_MESSAGE); List<BatchFieldLocator> fieldLocatorList = Collections.singletonList( new BatchFieldLocator(String.format("%s_%s", TestConstants.FIELD_NAME, ComprehendOperationEnum.DetectSentiment), 1)); test = new BatchOperationCallable( ComprehendOperationEnum.DetectSentiment, TestConstants.LANGUAGE_CODE, mockComprehendClient, fieldLocatorList, TestConstants.CONTENT_LIST); when(mockComprehendClient.batchDetectSentiment(any(BatchDetectSentimentRequest.class))) .thenThrow(clientException); BatchResponse<?> response = test.call(); List<BatchFieldLocator> locatorList = response.getLocatorList(); List<JSONObject> resultList = response.getBatchResultList(); assertEquals(1, locatorList.get(0).getContentRowNum()); assertEquals(String.format("%s_%s_%s", TestConstants.FIELD_NAME, ComprehendOperationEnum.DetectSentiment, "Error"), locatorList.get(0).getFieldNameAndOperation()); assertEquals(Constants.CLIENT_EXCEPTION_ERROR_CODE, resultList.get(0).get(TestConstants.ERROR_CODE_KEY)); assertEquals(TestConstants.DUMMY_ERROR_MESSAGE, resultList.get(0).get(TestConstants.ERROR_MESSAGE_KEY)); }
@Override public BatchResponse call() { try { return comprehendOperation.getComprehendOperation() .sendBatchRequest(fieldLocatorList, contentList, languageCode, comprehendClient); } catch (AmazonServiceException e) { return new BatchResponse<>(fieldLocatorList, Collections.emptyList(), getBatchItemErrors(e.getErrorCode(), e.getErrorMessage()), null); } catch (AmazonClientException e) { return new BatchResponse<>(fieldLocatorList, Collections.emptyList(), getBatchItemErrors(Constants.CLIENT_EXCEPTION_ERROR_CODE, e.getMessage()), null); } }
BatchOperationCallable implements Callable<BatchResponse> { @Override public BatchResponse call() { try { return comprehendOperation.getComprehendOperation() .sendBatchRequest(fieldLocatorList, contentList, languageCode, comprehendClient); } catch (AmazonServiceException e) { return new BatchResponse<>(fieldLocatorList, Collections.emptyList(), getBatchItemErrors(e.getErrorCode(), e.getErrorMessage()), null); } catch (AmazonClientException e) { return new BatchResponse<>(fieldLocatorList, Collections.emptyList(), getBatchItemErrors(Constants.CLIENT_EXCEPTION_ERROR_CODE, e.getMessage()), null); } } }
BatchOperationCallable implements Callable<BatchResponse> { @Override public BatchResponse call() { try { return comprehendOperation.getComprehendOperation() .sendBatchRequest(fieldLocatorList, contentList, languageCode, comprehendClient); } catch (AmazonServiceException e) { return new BatchResponse<>(fieldLocatorList, Collections.emptyList(), getBatchItemErrors(e.getErrorCode(), e.getErrorMessage()), null); } catch (AmazonClientException e) { return new BatchResponse<>(fieldLocatorList, Collections.emptyList(), getBatchItemErrors(Constants.CLIENT_EXCEPTION_ERROR_CODE, e.getMessage()), null); } }  }
BatchOperationCallable implements Callable<BatchResponse> { @Override public BatchResponse call() { try { return comprehendOperation.getComprehendOperation() .sendBatchRequest(fieldLocatorList, contentList, languageCode, comprehendClient); } catch (AmazonServiceException e) { return new BatchResponse<>(fieldLocatorList, Collections.emptyList(), getBatchItemErrors(e.getErrorCode(), e.getErrorMessage()), null); } catch (AmazonClientException e) { return new BatchResponse<>(fieldLocatorList, Collections.emptyList(), getBatchItemErrors(Constants.CLIENT_EXCEPTION_ERROR_CODE, e.getMessage()), null); } }  @Override BatchResponse call(); }
BatchOperationCallable implements Callable<BatchResponse> { @Override public BatchResponse call() { try { return comprehendOperation.getComprehendOperation() .sendBatchRequest(fieldLocatorList, contentList, languageCode, comprehendClient); } catch (AmazonServiceException e) { return new BatchResponse<>(fieldLocatorList, Collections.emptyList(), getBatchItemErrors(e.getErrorCode(), e.getErrorMessage()), null); } catch (AmazonClientException e) { return new BatchResponse<>(fieldLocatorList, Collections.emptyList(), getBatchItemErrors(Constants.CLIENT_EXCEPTION_ERROR_CODE, e.getMessage()), null); } }  @Override BatchResponse call();  }