DestroyJndiBindingCommand extends SingleGfshCommand { @Override public boolean updateConfigForGroup(String group, CacheConfig config, Object element) { remove(config.getJndiBindings(), (String) element); return true; }  @CliCommand(value = DESTROY_JNDIBINDING, help = DESTROY_JNDIBINDING__HELP) @CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_REGION) @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, operation = ResourcePermission.Operation.MANAGE) ResultModel destroyJDNIBinding(
      @CliOption(key = JNDI_NAME, mandatory = true, help = JNDI_NAME__HELP) String jndiName,
      @CliOption(key = CliStrings.IFEXISTS, help = IFEXISTS_HELP, specifiedDefaultValue = "true",
          unspecifiedDefaultValue = "false") boolean ifExists); @Override boolean updateConfigForGroup(String group, CacheConfig config, Object element);  }
@Test public void whenNoMembersFoundAndClusterConfigRunningThenUpdateClusterConfig() { List<JndiBindingsType.JndiBinding> bindings = new ArrayList<>(); JndiBindingsType.JndiBinding jndiBinding = new JndiBindingsType.JndiBinding(); jndiBinding.setJndiName("name"); bindings.add(jndiBinding); doReturn(bindings).when(cacheConfig).getJndiBindings(); gfsh.executeAndAssertThat(command, COMMAND + " --name=name").statusIsSuccess() .containsOutput("No members found.") .containsOutput("Cluster configuration for group 'cluster' is updated"); verify(ccService).updateCacheConfig(any(), any()); verify(command).updateConfigForGroup(eq("cluster"), eq(cacheConfig), any()); }
@Test @SuppressWarnings("deprecation") public void whenMembersFoundAndClusterConfigRunningThenUpdateClusterConfigAndInvokeFunction() { List<JndiBindingsType.JndiBinding> bindings = new ArrayList<>(); JndiBindingsType.JndiBinding jndiBinding = new JndiBindingsType.JndiBinding(); jndiBinding.setJndiName("name"); bindings.add(jndiBinding); doReturn(bindings).when(cacheConfig).getJndiBindings(); Set<DistributedMember> members = new HashSet<>(); members.add(mock(DistributedMember.class)); CliFunctionResult result = new CliFunctionResult("server1", true, "Jndi binding \"name\" destroyed on \"server1\""); List<CliFunctionResult> results = new ArrayList<>(); results.add(result); doReturn(members).when(command).findMembers(any(), any()); doReturn(results).when(command).executeAndGetFunctionResult(any(), any(), any()); gfsh.executeAndAssertThat(command, COMMAND + " --name=name").statusIsSuccess() .tableHasColumnOnlyWithValues("Member", "server1") .tableHasColumnOnlyWithValues("Status", "OK") .tableHasColumnOnlyWithValues("Message", "Jndi binding \"name\" destroyed on \"server1\""); assertThat(cacheConfig.getJndiBindings().isEmpty()).isTrue(); verify(command).updateConfigForGroup(eq("cluster"), eq(cacheConfig), any()); ArgumentCaptor<DestroyJndiBindingFunction> function = ArgumentCaptor.forClass(DestroyJndiBindingFunction.class); ArgumentCaptor<Object[]> arguments = ArgumentCaptor.forClass(Object[].class); @SuppressWarnings("unchecked") ArgumentCaptor<Set<DistributedMember>> targetMembers = ArgumentCaptor.forClass(Set.class); verify(command, times(1)).executeAndGetFunctionResult(function.capture(), arguments.capture(), targetMembers.capture()); String jndiName = (String) arguments.getValue()[0]; boolean destroyingDataSource = (boolean) arguments.getValue()[1]; assertThat(function.getValue()).isInstanceOf(DestroyJndiBindingFunction.class); assertThat(jndiName).isEqualTo("name"); assertThat(destroyingDataSource).isEqualTo(false); assertThat(targetMembers.getValue()).isEqualTo(members); }