ElasticsearchErrorMessage extends ErrorMessage { @Override protected String fetchDetails() { StringBuilder details = new StringBuilder(); if (exception instanceof SearchPhaseExecutionException) { details.append( fetchSearchPhaseExecutionExceptionDetails((SearchPhaseExecutionException) exception)); } else { details.append(((ElasticsearchException) exception).getDetailedMessage()); } details.append( "\nFor more details, please send request for Json format to see the raw response from " + "elasticsearch engine."); return details.toString(); } ElasticsearchErrorMessage(ElasticsearchException exception, int status);   }
@Test public void fetchDetailsWithElasticsearchException() { when(elasticsearchException.getDetailedMessage()).thenReturn("detail error"); ElasticsearchErrorMessage errorMessage = new ElasticsearchErrorMessage(elasticsearchException, SERVICE_UNAVAILABLE.getStatus()); assertEquals("detail error\n" + "For more details, please send request for " + "Json format to see the raw response from elasticsearch engine.", errorMessage.fetchDetails()); }
@Test public void fetchDetailsWithSearchPhaseExecutionException() { when(searchPhaseExecutionException.shardFailures()) .thenReturn(new ShardSearchFailure[] {shardSearchFailure}); when(shardSearchFailure.shardId()).thenReturn(1); when(shardSearchFailure.getCause()).thenReturn(new IllegalStateException("illegal state")); ElasticsearchErrorMessage errorMessage = new ElasticsearchErrorMessage(searchPhaseExecutionException, SERVICE_UNAVAILABLE.getStatus()); assertEquals("Shard[1]: java.lang.IllegalStateException: illegal state\n" + "\n" + "For more details, please send request for Json format to see the " + "raw response from elasticsearch engine.", errorMessage.fetchDetails()); }