DestroyAsyncEventQueueFunction implements InternalFunction<DestroyAsyncEventQueueFunctionArgs> { @Override public void execute(FunctionContext<DestroyAsyncEventQueueFunctionArgs> context) { DestroyAsyncEventQueueFunctionArgs aeqArgs = context.getArguments(); String aeqId = aeqArgs.getId(); String memberId = context.getMemberName(); try { AsyncEventQueueImpl aeq = (AsyncEventQueueImpl) context.getCache().getAsyncEventQueue(aeqId); if (aeq == null) { if (aeqArgs.isIfExists()) { context.getResultSender() .lastResult(new CliFunctionResult(memberId, true, String.format( "Skipping: " + DestroyAsyncEventQueueCommand.DESTROY_ASYNC_EVENT_QUEUE__AEQ_0_NOT_FOUND, aeqId))); } else { context.getResultSender().lastResult(new CliFunctionResult(memberId, false, String.format( DestroyAsyncEventQueueCommand.DESTROY_ASYNC_EVENT_QUEUE__AEQ_0_NOT_FOUND, aeqId))); } } else { XmlEntity xmlEntity = getAEQXmlEntity("id", aeqId); aeq.stop(); aeq.destroy(); @SuppressWarnings("deprecation") final CliFunctionResult lastResult = new CliFunctionResult(memberId, xmlEntity, String.format( DestroyAsyncEventQueueCommand.DESTROY_ASYNC_EVENT_QUEUE__AEQ_0_DESTROYED, aeqId)); context.getResultSender() .lastResult(lastResult); } } catch (Exception e) { context.getResultSender().lastResult(new CliFunctionResult(memberId, e, e.getMessage())); } }  @Override void execute(FunctionContext<DestroyAsyncEventQueueFunctionArgs> context); @Override String getId();  }
@Test @SuppressWarnings("deprecation") public void execute_nonexistentAeqId_returnsError() { when(cache.getAsyncEventQueue(TEST_AEQ_ID)).thenReturn(null); function.execute(mockContext); verify(resultSender).lastResult(resultCaptor.capture()); CliFunctionResult result = resultCaptor.getValue(); assertThat(result.isSuccessful()).isFalse(); assertThat(result.getMessage()).containsPattern(TEST_AEQ_ID + ".*not found"); }
@Test @SuppressWarnings("deprecation") public void execute_nonexistentAeqIdIfExists_returnsSuccess() { when(cache.getAsyncEventQueue(TEST_AEQ_ID)).thenReturn(null); when(mockArgs.isIfExists()).thenReturn(true); function.execute(mockContext); verify(resultSender).lastResult(resultCaptor.capture()); CliFunctionResult result = resultCaptor.getValue(); assertThat(result.isSuccessful()).isTrue(); assertThat(result.getMessage()).containsPattern("Skipping:.*" + TEST_AEQ_ID + ".*not found"); }