DeregisterDriverCommand extends GfshCommand { @CliCommand(value = DEREGISTER_DRIVER, help = DEREGISTER_DRIVER__HELP) @CliMetaData(relatedTopic = CliStrings.DEFAULT_TOPIC_GEODE) @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, operation = ResourcePermission.Operation.MANAGE) public ResultModel deregisterDriver( @CliOption(key = DRIVER_CLASS_NAME, help = DRIVER_CLASS_NAME_HELP, mandatory = true) String driverClassName) { try { ConfigurationPersistenceService ccService = getConfigurationPersistenceService(); if (ccService == null) { return ResultModel.createError("Cluster configuration service must be enabled."); } CacheConfig cacheConfig = ccService.getCacheConfig(null); if (cacheConfig != null) { for (JndiBindingsType.JndiBinding dataSource : cacheConfig.getJndiBindings()) { if (driverClassName.equals(dataSource.getJdbcDriverClass())) { return ResultModel .createError("Driver is currently in use by " + dataSource.getJndiName()); } } } Set<DistributedMember> targetMembers = findMembers(null, null); if (targetMembers.size() > 0) { Object[] arguments = new Object[] {driverClassName}; List<CliFunctionResult> deregisterDriverResults = executeAndGetFunctionResult( new DeregisterDriverFunction(), arguments, targetMembers); return ResultModel.createMemberStatusResult(deregisterDriverResults, EXPERIMENTAL, null, false, true); } else { return ResultModel.createInfo(EXPERIMENTAL + "\n" + NO_MEMBERS_FOUND); } } catch (Exception ex) { return ResultModel.createError( "Failed to deregister driver \"" + driverClassName + "\": " + ex.getMessage()); } }  @CliCommand(value = DEREGISTER_DRIVER, help = DEREGISTER_DRIVER__HELP) @CliMetaData(relatedTopic = CliStrings.DEFAULT_TOPIC_GEODE) @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, operation = ResourcePermission.Operation.MANAGE) ResultModel deregisterDriver(
      @CliOption(key = DRIVER_CLASS_NAME, help = DRIVER_CLASS_NAME_HELP,
          mandatory = true) String driverClassName);  }
@Test public void testDeregisterDriverDoesNotThrowException() { when(memberSet.size()).thenReturn(1); result = new CliFunctionResult("Server1", CliFunctionResult.StatusState.OK, DRIVER_CLASS_NAME + " was successfully deregistered."); resultList.add(result); ResultModel resultModel = command.deregisterDriver(DRIVER_CLASS_NAME); assertThat(resultModel.toString()) .contains(DRIVER_CLASS_NAME + " was successfully deregistered."); assertThat(resultModel.getStatus()).isEqualTo(Result.Status.OK); resultList.clear(); }
@Test public void testDeregisterDriverWithNoClusterConfigurationServerFails() { doReturn(null).when(command).getConfigurationPersistenceService(); ResultModel result = command.deregisterDriver(DRIVER_CLASS_NAME); assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); assertThat(result.toString()).contains("Cluster configuration service must be enabled."); }
@Test public void testDeregisterDriverFailsWhenDriverIsInUse() { this.dataSource.setJdbcDriverClass(DRIVER_CLASS_NAME); ResultModel result = command.deregisterDriver(DRIVER_CLASS_NAME); assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); assertThat(result.toString()).contains("Driver is currently in use by " + DATA_SOURCE_NAME); }
@Test public void testDeregisterDriverReturnsErrorWhenNoMembers() { when(memberSet.size()).thenReturn(0); ResultModel resultModel = command.deregisterDriver(DRIVER_CLASS_NAME); assertThat(resultModel.toString()).contains(NO_MEMBERS_FOUND); }
@Test public void testDeregisterDriverReturnsWhenFunctionFailsToExecute() { when(memberSet.size()).thenReturn(1); String errorMessage = "Error message"; result = new CliFunctionResult("Server1", CliFunctionResult.StatusState.ERROR, errorMessage); resultList.add(result); ResultModel resultModel = command.deregisterDriver(DRIVER_CLASS_NAME); assertThat(resultModel.toString()).contains(errorMessage); assertThat(resultModel.getStatus()).isEqualTo(Result.Status.ERROR); }
@Test public void testDeregisterDriverReturnsWhenExceptionIsThrown() { String exceptionString = "Test Exception"; doThrow(new NullPointerException(exceptionString)).when(command).findMembers(any(), any()); ResultModel resultModel = command.deregisterDriver(DRIVER_CLASS_NAME); assertThat(resultModel.getStatus()).isEqualTo(Result.Status.ERROR); assertThat(resultModel.toString()).contains( "Failed to deregister driver \\\"" + DRIVER_CLASS_NAME + "\\\": " + exceptionString); }