LogCommand implements CommandHasRequest<LogRequest, CommandResponse> { @Override public void execute(LogRequest request, CommandResponse response) throws Exception { switch (request.getLevel()) { case LogRequest.LEVEL_DEBUG: log.debug(request.getStatement()); break; case LogRequest.LEVEL_INFO: log.info(request.getStatement()); break; case LogRequest.LEVEL_WARN: log.warn(request.getStatement()); break; case LogRequest.LEVEL_ERROR: log.error(request.getStatement()); break; default: throw new IllegalArgumentException("Unknown log level " + request.getLevel()); } }  @Override LogRequest getEmptyCommandRequest(); @Override CommandResponse getEmptyCommandResponse(); @Override void execute(LogRequest request, CommandResponse response);  }
@Test public void testLog() throws Exception { LogRequest request = new LogRequest(); request.setLevel(LogRequest.LEVEL_INFO); request.setStatement("Test log command"); CommandResponse response = dispatcher.execute(LogRequest.COMMAND, request, null, "en"); if (response.isError()) { response.getErrors().get(0).printStackTrace(); } Assert.assertFalse(response.isError()); request.setLevel(LogRequest.LEVEL_DEBUG); request.setStatement("Test debug log command"); response = dispatcher.execute(LogRequest.COMMAND, request, null, "en"); if (response.isError()) { response.getErrors().get(0).printStackTrace(); } Assert.assertFalse(response.isError()); request.setLevel(LogRequest.LEVEL_WARN); request.setStatement("Test warn log command"); response = dispatcher.execute(LogRequest.COMMAND, request, null, "en"); if (response.isError()) { response.getErrors().get(0).printStackTrace(); } Assert.assertFalse(response.isError()); request.setLevel(LogRequest.LEVEL_ERROR); request.setStatement("Test error log command"); response = dispatcher.execute(LogRequest.COMMAND, request, null, "en"); if (response.isError()) { response.getErrors().get(0).printStackTrace(); } Assert.assertFalse(response.isError()); }