ExportLogsInterceptor extends AbstractCliAroundInterceptor { @Override public ResultModel preExecution(GfshParseResult parseResult) { if (parseResult.getParamValueAsString("group") != null && parseResult.getParamValueAsString("member") != null) { return ResultModel.createError("Can't specify both group and member."); } String logLevel = parseResult.getParamValueAsString("log-level"); if (StringUtils.isBlank(logLevel) || LogLevel.getLevel(logLevel) == null) { return ResultModel.createError("Invalid log level: " + logLevel); } String start = parseResult.getParamValueAsString("start-time"); String end = parseResult.getParamValueAsString("end-time"); if (start != null && end != null) { LocalDateTime startTime = ExportLogsFunction.parseTime(start); LocalDateTime endTime = ExportLogsFunction.parseTime(end); if (startTime.isAfter(endTime)) { return ResultModel.createError("start-time has to be earlier than end-time."); } } boolean onlyLogs = (boolean) parseResult.getParamValue("logs-only"); boolean onlyStats = (boolean) parseResult.getParamValue("stats-only"); if (onlyLogs && onlyStats) { return ResultModel.createError("logs-only and stats-only can't both be true"); } return ResultModel.createInfo(""); }  @Override ResultModel preExecution(GfshParseResult parseResult); @Override ResultModel postExecution(GfshParseResult parseResult, ResultModel commandResult,
      Path tempFile);  }
@Test public void testGroupAndMember() { when(parseResult.getParamValueAsString("group")).thenReturn("group"); when(parseResult.getParamValueAsString("member")).thenReturn("group"); result = interceptor.preExecution(parseResult); assertThat(result.getInfoSection("info").getContent()) .containsOnly("Can't specify both group and member."); }
@Test public void testStartEnd() { when(parseResult.getParamValueAsString("start-time")).thenReturn("2000/01/01"); when(parseResult.getParamValueAsString("end-time")).thenReturn("2000/01/02"); result = interceptor.preExecution(parseResult); assertThat(result.getInfoSection("info").getContent()).containsOnly(""); when(parseResult.getParamValueAsString("start-time")).thenReturn("2000/01/02"); when(parseResult.getParamValueAsString("end-time")).thenReturn("2000/01/01"); result = interceptor.preExecution(parseResult); assertThat(result.getInfoSection("info").getContent()) .containsOnly("start-time has to be earlier than end-time."); }
@Test public void testInclideStats() { when(parseResult.getParamValue("logs-only")).thenReturn(true); when(parseResult.getParamValue("stats-only")).thenReturn(false); result = interceptor.preExecution(parseResult); assertThat(result.getInfoSection("info").getContent()).containsOnly(""); when(parseResult.getParamValue("logs-only")).thenReturn(true); when(parseResult.getParamValue("stats-only")).thenReturn(true); result = interceptor.preExecution(parseResult); assertThat(result.getInfoSection("info").getContent()) .containsOnly("logs-only and stats-only can't both be true"); }