@Override public CompletableFuture<?> request(String method, Object parameter) { Function<Object, CompletableFuture<Object>> handler = methodHandlers.get(method); if (handler != null) { return handler.apply(parameter); } if (delegate instanceof Endpoint) { return ((Endpoint) delegate).request(method, parameter); } String message = "Unsupported request method: " + method; if (isOptionalMethod(method)) { LOG.log(Level.INFO, message); return CompletableFuture.completedFuture(null); } LOG.log(Level.WARNING, message); CompletableFuture<?> exceptionalResult = new CompletableFuture<Object>(); ResponseError error = new ResponseError(ResponseErrorCode.MethodNotFound, message, null); exceptionalResult.completeExceptionally(new ResponseErrorException(error)); return exceptionalResult; }
@Test public void testExecuteCommandNonexistingCommand() { expectedEx.expect(ResponseErrorException.class); expectedEx.expectMessage("No delegateCommandHandler for testcommand.not.existing"); WorkspaceExecuteCommandHandler handler = new WorkspaceExecuteCommandHandler(); ExecuteCommandParams params = new ExecuteCommandParams(); params.setCommand("testcommand.not.existing"); params.setArguments(Arrays.asList("hello", "world")); Object result = handler.executeCommand(params, monitor); }
@Test public void testExecuteCommandThrowsExceptionCommand() { expectedEx.expect(ResponseErrorException.class); expectedEx.expectMessage("Unsupported"); WorkspaceExecuteCommandHandler handler = new WorkspaceExecuteCommandHandler(); ExecuteCommandParams params = new ExecuteCommandParams(); params.setCommand("testcommand.throwexception"); handler.executeCommand(params, monitor); }
@Test public void testExecuteCommandInvalidParameters() { expectedEx.expect(ResponseErrorException.class); expectedEx.expectMessage("The workspace/executeCommand has empty params or command"); WorkspaceExecuteCommandHandler handler = new WorkspaceExecuteCommandHandler(); ExecuteCommandParams params = null; handler.executeCommand(params, monitor); }
public void checkSeverity() { RefactoringIssueAcceptor.Severity _maximumSeverity = this.getMaximumSeverity(); boolean _lessThan = (_maximumSeverity.compareTo(RefactoringIssueAcceptor.Severity.WARNING) < 0); if (_lessThan) { ResponseError _responseError = this.toResponseError(); throw new ResponseErrorException(_responseError); } }
protected IWorkspaceConfig getWorkspaceConfig() { if ((this._workspaceConfig == null)) { final ResponseError error = new ResponseError(ResponseErrorCode.serverNotInitialized, "Workspace has not been initialized yet.", null); throw new ResponseErrorException(error); } return this._workspaceConfig; }