GatewaySenderDestroyFunction implements InternalFunction<GatewaySenderDestroyFunctionArgs> { @Override @SuppressWarnings("deprecation") public void execute(FunctionContext<GatewaySenderDestroyFunctionArgs> context) { ResultSender<Object> resultSender = context.getResultSender(); Cache cache = context.getCache(); String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember()); GatewaySenderDestroyFunctionArgs gatewaySenderDestroyFunctionArgs = context.getArguments(); String senderId = gatewaySenderDestroyFunctionArgs.getId(); boolean ifExists = gatewaySenderDestroyFunctionArgs.isIfExists(); GatewaySender gatewaySender = cache.getGatewaySender(senderId); if (gatewaySender == null) { String message = "Gateway sender " + senderId + " not found."; if (ifExists) { resultSender .lastResult(new CliFunctionResult(memberNameOrId, true, "Skipping: " + message)); } else { resultSender.lastResult(new CliFunctionResult(memberNameOrId, false, message)); } return; } try { gatewaySender.stop(); gatewaySender.destroy(); XmlEntity xmlEntity = new XmlEntity(CacheXml.GATEWAY_SENDER, "id", senderId); resultSender.lastResult(new CliFunctionResult(memberNameOrId, xmlEntity, String.format("GatewaySender \"%s\" destroyed on \"%s\"", senderId, memberNameOrId))); } catch (Exception e) { resultSender.lastResult(new CliFunctionResult(memberNameOrId, e, "")); } }  @Override @SuppressWarnings("deprecation") void execute(FunctionContext<GatewaySenderDestroyFunctionArgs> context); @Override String getId(); @Immutable
  static final GatewaySenderDestroyFunction INSTANCE; }
@Test @SuppressWarnings("deprecation") public void gateWaySenderNotFound_ifExists_false() { when(cache.getGatewaySender(any())).thenReturn(null); when(args.isIfExists()).thenReturn(false); function.execute(context); verify(resultSender).lastResult(resultCaptor.capture()); CliFunctionResult result = resultCaptor.getValue(); assertThat(result.isSuccessful()).isFalse(); assertThat(result.getThrowable()).isNull(); assertThat(result.getMessage()).isEqualTo("Gateway sender id not found."); }
@Test @SuppressWarnings("deprecation") public void gateWaySenderNotFound_ifExists_true() { when(cache.getGatewaySender(any())).thenReturn(null); when(args.isIfExists()).thenReturn(true); function.execute(context); verify(resultSender).lastResult(resultCaptor.capture()); CliFunctionResult result = resultCaptor.getValue(); assertThat(result.isSuccessful()).isTrue(); assertThat(result.getThrowable()).isNull(); assertThat(result.getMessage()).isEqualTo("Skipping: Gateway sender id not found."); }