RegisterDriverCommand extends GfshCommand { @CliCommand(value = REGISTER_DRIVER, help = REGISTER_DRIVER__HELP) @CliMetaData(relatedTopic = CliStrings.DEFAULT_TOPIC_GEODE) @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, operation = ResourcePermission.Operation.MANAGE) public ResultModel registerDriver( @CliOption(key = DRIVER_CLASS_NAME, help = DRIVER_CLASS_NAME_HELP, mandatory = true) String driverClassName) { try { Set<DistributedMember> targetMembers = findMembers(null, null); if (targetMembers.size() > 0) { Object[] arguments = new Object[] {driverClassName}; List<CliFunctionResult> registerDriverResults = executeAndGetFunctionResult( new RegisterDriverFunction(), arguments, targetMembers); return ResultModel.createMemberStatusResult(registerDriverResults, EXPERIMENTAL, null, false, true); } else { return ResultModel.createInfo(EXPERIMENTAL + "\n" + NO_MEMBERS_FOUND); } } catch (Exception ex) { return ResultModel .createError("Failed to register driver \"" + driverClassName + "\": " + ex.getMessage()); } }  @CliCommand(value = REGISTER_DRIVER, help = REGISTER_DRIVER__HELP) @CliMetaData(relatedTopic = CliStrings.DEFAULT_TOPIC_GEODE) @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, operation = ResourcePermission.Operation.MANAGE) ResultModel registerDriver(
      @CliOption(key = DRIVER_CLASS_NAME, help = DRIVER_CLASS_NAME_HELP,
          mandatory = true) String driverClassName);  }
@Test public void testRegisterDriverDoesNotThrowException() { when(memberSet.size()).thenReturn(1); result = new CliFunctionResult("Server1", CliFunctionResult.StatusState.OK, DRIVER_CLASS_NAME + " was successfully registered."); resultList.add(result); ResultModel resultModel = command.registerDriver(DRIVER_CLASS_NAME); assertThat(resultModel.toString()) .contains(DRIVER_CLASS_NAME + " was successfully registered."); assertThat(resultModel.getStatus()).isEqualTo(Result.Status.OK); resultList.clear(); }
@Test public void testRegisterDriverReturnsErrorWhenNoMembers() { when(memberSet.size()).thenReturn(0); ResultModel resultModel = command.registerDriver(DRIVER_CLASS_NAME); assertThat(resultModel.toString()).contains(NO_MEMBERS_FOUND); }
@Test public void testRegisterDriverReturnsWhenFunctionFailsToExecute() { when(memberSet.size()).thenReturn(1); String errorMessage = "Error message"; result = new CliFunctionResult("Server1", CliFunctionResult.StatusState.ERROR, errorMessage); resultList.add(result); ResultModel resultModel = command.registerDriver(DRIVER_CLASS_NAME); assertThat(resultModel.toString()).contains(errorMessage); assertThat(resultModel.getStatus()).isEqualTo(Result.Status.ERROR); }
@Test public void testRegisterDriverReturnsWhenExceptionIsThrown() { String exceptionString = "Test Exception"; doThrow(new NullPointerException(exceptionString)).when(command).findMembers(any(), any()); ResultModel resultModel = command.registerDriver(DRIVER_CLASS_NAME); assertThat(resultModel.getStatus()).isEqualTo(Result.Status.ERROR); assertThat(resultModel.toString()).contains( "Failed to register driver \\\"" + DRIVER_CLASS_NAME + "\\\": " + exceptionString); }