ListDriversCommand extends GfshCommand { @CliCommand(value = LIST_DRIVERS, help = LIST_DRIVERS__HELP) @CliMetaData() @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, operation = ResourcePermission.Operation.MANAGE) public ResultModel listDrivers( @CliOption(key = MEMBER_NAME, help = MEMBER_NAME__HELP) String memberName) { ResultModel resultModel = new ResultModel(); return createTabularResultDataAndGetResult(resultModel, memberName); }  @CliCommand(value = LIST_DRIVERS, help = LIST_DRIVERS__HELP) @CliMetaData() @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, operation = ResourcePermission.Operation.MANAGE) ResultModel listDrivers(
      @CliOption(key = MEMBER_NAME, help = MEMBER_NAME__HELP) String memberName);  }
@Test public void testListDriverDoesNotThrowException() { when(memberSet.size()).thenReturn(1); List<String> driverNames = new ArrayList<>(); driverNames.add("Driver.Class.One"); driverNames.add("Driver.Class.Two"); driverNames.add("Driver.Class.Three"); result = new CliFunctionResult("Server 1", driverNames, "{Driver.Class.One, Driver.Class.Two, Driver.Class.Three}"); resultList.add(result); ResultModel resultModel = command.listDrivers(null); assertThat(resultModel.toString()).contains("Driver.Class.One").contains("Driver.Class.Two") .contains("Driver.Class.Three"); resultList.clear(); }
@Test public void testListDriverWithMemberNameDoesNotThrowException() { when(memberSet.size()).thenReturn(1); List<String> driverNames = new ArrayList<>(); driverNames.add("Driver.Class.One"); driverNames.add("Driver.Class.Two"); driverNames.add("Driver.Class.Three"); result = new CliFunctionResult("Server 1", driverNames, "{Driver.Class.One, Driver.Class.Two, Driver.Class.Three}"); resultList.add(result); ResultModel resultModel = command.listDrivers("Server 1"); assertThat(resultModel.toString()).contains("Driver.Class.One").contains("Driver.Class.Two") .contains("Driver.Class.Three").contains("Server 1"); resultList.clear(); }
@Test public void testListDriverReturnsErrorWhenNoMembers() { when(memberSet.size()).thenReturn(0); ResultModel resultModel = command.listDrivers(null); assertThat(resultModel.toString()).contains(NO_MEMBERS_FOUND); }
@Test public void testListDriverReturnsWhenFunctionFailsToExecute() { when(memberSet.size()).thenReturn(1); String errorMessage = "Error message"; result = new CliFunctionResult("Server 1", CliFunctionResult.StatusState.ERROR, errorMessage); resultList.add(result); ResultModel resultModel = command.listDrivers(null); assertThat(resultModel.toString()).contains(errorMessage); assertThat(resultModel.getStatus()).isEqualTo(Result.Status.ERROR); }
@Test public void testListDriverWithInvalidMemberNameReportsError() { String badMemberName = "Bad Member Name"; when(memberSet.size()).thenReturn(1); List<String> driverNames = new ArrayList<>(); driverNames.add("Driver.Class.One"); driverNames.add("Driver.Class.Two"); driverNames.add("Driver.Class.Three"); result = new CliFunctionResult("Server 1", driverNames, "{Driver.Class.One, Driver.Class.Two, Driver.Class.Three}"); resultList.add(result); ResultModel resultModel = command.listDrivers(badMemberName); assertThat(resultModel.toString()).contains("No member found with name: " + badMemberName); resultList.clear(); }