@Test public void execute_processingFailed_AbbyySdkException() throws Exception { final String expecterErr = "This is the reason"; R request = mockAbbyyRequest(); AbbyyResponse responseMock = mockAbbyyResponse(); when(responseMock.getTaskStatus()) .thenReturn(AbbyyResponse.TaskStatus.QUEUED) .thenReturn(AbbyyResponse.TaskStatus.PROCESSING_FAILED); when(responseMock.getErrorMessage()).thenReturn(expecterErr); when(this.abbyyApiMock.request(eq(request))).thenReturn(responseMock); when(this.abbyyApiMock.getTaskStatus(eq(request), anyString())).thenReturn(responseMock); try { this.sut.execute(request); fail(); } catch (AbbyySdkException ex) { assertTrue(ex.getMessage().contains(expecterErr)); } }
public Map<String, String> execute(@NotNull R request) throws Exception { Map<String, String> results = ResultUtils.createNewEmptyMap(); try { ValidationException validationEx = this.requestValidator.validate(request); if (validationEx != null) { throw validationEx; } AbbyyResponse response = this.abbyyApi.request(request); if (response.getTaskStatus() == AbbyyResponse.TaskStatus.NOT_ENOUGH_CREDITS) { throw new AbbyySdkException(String.format(ExceptionMsgs.NOT_ENOUGH_CREDITS, response.getCredits())); } results.put(OutputNames.TASK_ID, response.getTaskId()); results.put(OutputNames.CREDITS, String.valueOf(response.getCredits())); response = waitTaskToFinish(request, response.getTaskId(), response.getEstimatedProcessingTime()); switch (response.getTaskStatus()) { case COMPLETED: handleTaskCompleted(request, response, results); break; case PROCESSING_FAILED: throw new ServerSideException(String.format(ExceptionMsgs.TASK_PROCESSING_FAILED, response.getErrorMessage())); case DELETED: throw new AbbyySdkException(ExceptionMsgs.TASK_DELETED); case NOT_ENOUGH_CREDITS: throw new AbbyySdkException(ExceptionMsgs.NOT_ENOUGH_CREDITS); default: throw new ClientSideException(ExceptionMsgs.UNEXPECTED_STATUS); } return results; } catch (AbbyySdkException ex) { if (ex.getResultsMap() == null) { ex.setResultsMap(results); } throw ex; } catch (Exception ex) { throw new ClientSideException(ex, results); } finally { results.put(OutputNames.STATUS_CODE, StringUtils.defaultString(this.abbyyApi.getLastStatusCode())); results.put(OutputNames.TIMED_OUT, String.valueOf(this.timedOut)); } }
AbbyyService { public Map<String, String> execute(@NotNull R request) throws Exception { Map<String, String> results = ResultUtils.createNewEmptyMap(); try { ValidationException validationEx = this.requestValidator.validate(request); if (validationEx != null) { throw validationEx; } AbbyyResponse response = this.abbyyApi.request(request); if (response.getTaskStatus() == AbbyyResponse.TaskStatus.NOT_ENOUGH_CREDITS) { throw new AbbyySdkException(String.format(ExceptionMsgs.NOT_ENOUGH_CREDITS, response.getCredits())); } results.put(OutputNames.TASK_ID, response.getTaskId()); results.put(OutputNames.CREDITS, String.valueOf(response.getCredits())); response = waitTaskToFinish(request, response.getTaskId(), response.getEstimatedProcessingTime()); switch (response.getTaskStatus()) { case COMPLETED: handleTaskCompleted(request, response, results); break; case PROCESSING_FAILED: throw new ServerSideException(String.format(ExceptionMsgs.TASK_PROCESSING_FAILED, response.getErrorMessage())); case DELETED: throw new AbbyySdkException(ExceptionMsgs.TASK_DELETED); case NOT_ENOUGH_CREDITS: throw new AbbyySdkException(ExceptionMsgs.NOT_ENOUGH_CREDITS); default: throw new ClientSideException(ExceptionMsgs.UNEXPECTED_STATUS); } return results; } catch (AbbyySdkException ex) { if (ex.getResultsMap() == null) { ex.setResultsMap(results); } throw ex; } catch (Exception ex) { throw new ClientSideException(ex, results); } finally { results.put(OutputNames.STATUS_CODE, StringUtils.defaultString(this.abbyyApi.getLastStatusCode())); results.put(OutputNames.TIMED_OUT, String.valueOf(this.timedOut)); } } }
AbbyyService { public Map<String, String> execute(@NotNull R request) throws Exception { Map<String, String> results = ResultUtils.createNewEmptyMap(); try { ValidationException validationEx = this.requestValidator.validate(request); if (validationEx != null) { throw validationEx; } AbbyyResponse response = this.abbyyApi.request(request); if (response.getTaskStatus() == AbbyyResponse.TaskStatus.NOT_ENOUGH_CREDITS) { throw new AbbyySdkException(String.format(ExceptionMsgs.NOT_ENOUGH_CREDITS, response.getCredits())); } results.put(OutputNames.TASK_ID, response.getTaskId()); results.put(OutputNames.CREDITS, String.valueOf(response.getCredits())); response = waitTaskToFinish(request, response.getTaskId(), response.getEstimatedProcessingTime()); switch (response.getTaskStatus()) { case COMPLETED: handleTaskCompleted(request, response, results); break; case PROCESSING_FAILED: throw new ServerSideException(String.format(ExceptionMsgs.TASK_PROCESSING_FAILED, response.getErrorMessage())); case DELETED: throw new AbbyySdkException(ExceptionMsgs.TASK_DELETED); case NOT_ENOUGH_CREDITS: throw new AbbyySdkException(ExceptionMsgs.NOT_ENOUGH_CREDITS); default: throw new ClientSideException(ExceptionMsgs.UNEXPECTED_STATUS); } return results; } catch (AbbyySdkException ex) { if (ex.getResultsMap() == null) { ex.setResultsMap(results); } throw ex; } catch (Exception ex) { throw new ClientSideException(ex, results); } finally { results.put(OutputNames.STATUS_CODE, StringUtils.defaultString(this.abbyyApi.getLastStatusCode())); results.put(OutputNames.TIMED_OUT, String.valueOf(this.timedOut)); } } AbbyyService(@NotNull AbbyyInputValidator<R> requestValidator, @NotNull AbbyyApi abbyyApi); }
AbbyyService { public Map<String, String> execute(@NotNull R request) throws Exception { Map<String, String> results = ResultUtils.createNewEmptyMap(); try { ValidationException validationEx = this.requestValidator.validate(request); if (validationEx != null) { throw validationEx; } AbbyyResponse response = this.abbyyApi.request(request); if (response.getTaskStatus() == AbbyyResponse.TaskStatus.NOT_ENOUGH_CREDITS) { throw new AbbyySdkException(String.format(ExceptionMsgs.NOT_ENOUGH_CREDITS, response.getCredits())); } results.put(OutputNames.TASK_ID, response.getTaskId()); results.put(OutputNames.CREDITS, String.valueOf(response.getCredits())); response = waitTaskToFinish(request, response.getTaskId(), response.getEstimatedProcessingTime()); switch (response.getTaskStatus()) { case COMPLETED: handleTaskCompleted(request, response, results); break; case PROCESSING_FAILED: throw new ServerSideException(String.format(ExceptionMsgs.TASK_PROCESSING_FAILED, response.getErrorMessage())); case DELETED: throw new AbbyySdkException(ExceptionMsgs.TASK_DELETED); case NOT_ENOUGH_CREDITS: throw new AbbyySdkException(ExceptionMsgs.NOT_ENOUGH_CREDITS); default: throw new ClientSideException(ExceptionMsgs.UNEXPECTED_STATUS); } return results; } catch (AbbyySdkException ex) { if (ex.getResultsMap() == null) { ex.setResultsMap(results); } throw ex; } catch (Exception ex) { throw new ClientSideException(ex, results); } finally { results.put(OutputNames.STATUS_CODE, StringUtils.defaultString(this.abbyyApi.getLastStatusCode())); results.put(OutputNames.TIMED_OUT, String.valueOf(this.timedOut)); } } AbbyyService(@NotNull AbbyyInputValidator<R> requestValidator, @NotNull AbbyyApi abbyyApi); Map<String, String> execute(@NotNull R request); }
AbbyyService { public Map<String, String> execute(@NotNull R request) throws Exception { Map<String, String> results = ResultUtils.createNewEmptyMap(); try { ValidationException validationEx = this.requestValidator.validate(request); if (validationEx != null) { throw validationEx; } AbbyyResponse response = this.abbyyApi.request(request); if (response.getTaskStatus() == AbbyyResponse.TaskStatus.NOT_ENOUGH_CREDITS) { throw new AbbyySdkException(String.format(ExceptionMsgs.NOT_ENOUGH_CREDITS, response.getCredits())); } results.put(OutputNames.TASK_ID, response.getTaskId()); results.put(OutputNames.CREDITS, String.valueOf(response.getCredits())); response = waitTaskToFinish(request, response.getTaskId(), response.getEstimatedProcessingTime()); switch (response.getTaskStatus()) { case COMPLETED: handleTaskCompleted(request, response, results); break; case PROCESSING_FAILED: throw new ServerSideException(String.format(ExceptionMsgs.TASK_PROCESSING_FAILED, response.getErrorMessage())); case DELETED: throw new AbbyySdkException(ExceptionMsgs.TASK_DELETED); case NOT_ENOUGH_CREDITS: throw new AbbyySdkException(ExceptionMsgs.NOT_ENOUGH_CREDITS); default: throw new ClientSideException(ExceptionMsgs.UNEXPECTED_STATUS); } return results; } catch (AbbyySdkException ex) { if (ex.getResultsMap() == null) { ex.setResultsMap(results); } throw ex; } catch (Exception ex) { throw new ClientSideException(ex, results); } finally { results.put(OutputNames.STATUS_CODE, StringUtils.defaultString(this.abbyyApi.getLastStatusCode())); results.put(OutputNames.TIMED_OUT, String.valueOf(this.timedOut)); } } AbbyyService(@NotNull AbbyyInputValidator<R> requestValidator, @NotNull AbbyyApi abbyyApi); Map<String, String> execute(@NotNull R request);  }