DefaultRpcExceptionTranslator implements RpcExceptionTranslator { @Override public DataAccessException translate(String task, String rpc, RpcException e) { if (e instanceof DivisionNotFoundException) { return new InvalidDataAccessResourceUsageException(getMessage(task, rpc), e); } else if (e instanceof BadCredentialsException) { return new PermissionDeniedDataAccessException(getMessage(task, rpc), e); } else if (e instanceof ChangeVerifyCodeException) { return new PermissionDeniedDataAccessException(getMessage(task, rpc), e); } else if (e instanceof ServiceTemporarilyDownException) { return new DataAccessResourceFailureException(getMessage(task, rpc), e); } else if (e instanceof VerifyCodeExpiredException) { return new PermissionDeniedDataAccessException(getMessage(task, rpc), e); } else if (e instanceof DivisionMismatchException) { return new InvalidDataAccessApiUsageException(getMessage(task, rpc), e); } else if (e instanceof RpcContextAccessDeniedException) { return new PermissionDeniedDataAccessException(getMessage(task, rpc), e); } else if (e instanceof LockedException) { return new PermissionDeniedDataAccessException(getMessage(task, rpc), e); } else if (e instanceof RpcContextNotFoundException) { return new InvalidDataAccessResourceUsageException(getMessage(task, rpc), e); } else if (e instanceof RpcNotFoundException) { return new InvalidDataAccessResourceUsageException(getMessage(task, rpc), e); } else if (e instanceof ProductionMismatchException) { return new InvalidDataAccessResourceUsageException(getMessage(task, rpc), e); } else if (e instanceof ServerUnavailableException) { return new DataAccessResourceFailureException(getMessage(task, rpc), e); } else if (e instanceof ServerNotFoundException) { return new DataAccessResourceFailureException(getMessage(task, rpc), e); } else if (e instanceof ConnectionClosedException) { return new InvalidDataAccessApiUsageException(getMessage(task, rpc), e); } else if (e instanceof TimeoutWaitingForRpcResponseException) { return new DataAccessResourceFailureException(getMessage(task, rpc), e); } else if (e instanceof TimeoutWaitingForIdleConnectionException) { return new TransientDataAccessResourceException(getMessage(task, rpc), e); } if (CLOSE_TASK.equals(task)) { return new CleanupFailureDataAccessException(getMessage(task, rpc), e); } return new DataRetrievalFailureException(getMessage(task, rpc), e); }  @Override DataAccessException translate(String task, String rpc, RpcException e); static final String CLOSE_TASK; }
@Test public void translateUnknownDivision() { Assert.assertTrue(translator.translate("open", null, new DivisionNotFoundException("foo")) instanceof InvalidDataAccessResourceUsageException); }
@Test public void translateProductionMismatch() { Assert.assertTrue(translator.translate("open", null, new ProductionMismatchException(false, true)) instanceof InvalidDataAccessResourceUsageException); }
@Test public void translateServiceTemporarilyDown() { Assert.assertTrue(translator.translate("open", null, new ServiceTemporarilyDownException()) instanceof DataAccessResourceFailureException); }
@Test public void translateExceptionDuringSend() { Assert.assertTrue(translator.translate("send", null, new RpcException("foo")) instanceof DataRetrievalFailureException); }
@Test public void translateVerifyCodeExpired() { Assert.assertTrue(translator.translate("open", null, new VerifyCodeExpiredException(VerifyCodeExpiredException.VERIFY_CODE_EXPIRED_MESSAGE)) instanceof PermissionDeniedDataAccessException); }
@Test public void translateInvalidCredentials() { Assert.assertTrue(translator.translate("open", null, new BadCredentialsException()) instanceof PermissionDeniedDataAccessException); }
@Test public void translateLockedUserAccouunt() { Assert.assertTrue(translator.translate("open", null, new LockedException("foo")) instanceof PermissionDeniedDataAccessException); }
@Test public void translateServerUnavailable() { Assert.assertTrue(translator.translate("open", null, new ServerUnavailableException(new RpcHost("example.org", 1234))) instanceof DataAccessResourceFailureException); }
@Test public void translateServerNotFound() { Assert.assertTrue(translator.translate("open", null, new ServerNotFoundException(new RpcHost("non.existant.domain.org", 1234))) instanceof DataAccessResourceFailureException); }
@Test public void translateRpcContextAccessDenied() { Assert.assertTrue(translator.translate("send", null, new RpcContextAccessDeniedException("foo")) instanceof PermissionDeniedDataAccessException); }
@Test public void translateDivisionMismatch() { Assert.assertTrue(translator.translate("send", null, new DivisionMismatchException("foo")) instanceof InvalidDataAccessApiUsageException); }
@Test public void translateRpcContextNotFound() { Assert.assertTrue(translator.translate("send", null, new RpcContextNotFoundException("foo")) instanceof InvalidDataAccessResourceUsageException); }
@Test public void translateRpcNotFound() { Assert.assertTrue(translator.translate("send", null, new RpcNotFoundException("foo")) instanceof InvalidDataAccessResourceUsageException); }
@Test public void translateConnectionClosed() { Assert.assertTrue(translator.translate("send", null, new ConnectionClosedException("foo")) instanceof InvalidDataAccessApiUsageException); }
@Test public void translateExceptionDuringClose() { Assert.assertTrue(translator.translate("close", null, new RpcException("foo")) instanceof CleanupFailureDataAccessException); }
@Test public void translateTimeoutWaitingForIdleConnection() { Assert.assertTrue(translator.translate("send", null, new TimeoutWaitingForIdleConnectionException()) instanceof TransientDataAccessResourceException); }