### Question:
ListIiopListeners implements AdminCommand { @Override public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); final Target targetUtil = services.getService(Target.class ) ; final Config config = targetUtil.getConfig(target) ; final IiopService iiopService = config.getExtensionByType(IiopService.class); try { List<IiopListener> listenerList = iiopService.getIiopListener(); for (IiopListener listener : listenerList) { final ActionReport.MessagePart part = report.getTopMessagePart() .addChild(); part.setMessage(listener.getId()); } report.setActionExitCode(ActionReport.ExitCode.SUCCESS); } catch (Exception e) { report.setMessage(localStrings.getLocalString("list.iiop.listener" + ".fail", "List IIOP listeners failed.")); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); } }  @Override void execute(AdminCommandContext context);  }### Answer:
@Test public void testExecuteSuccessListOriginal() { ListIiopListeners listCommand = services.getService(ListIiopListeners.class); cr.getCommandInvocation("list-iiop-listeners", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand); List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren(); assertEquals(origNum, list.size()); CreateIiopListenerTest.checkActionReport(context.getActionReport()); }
@Test public void testExecuteSuccessValidTargetOperand() { ListIiopListeners listCommand = services.getService(ListIiopListeners.class); parameters.set("DEFAULT", "server"); cr.getCommandInvocation("list-iiop-listeners", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand); List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren(); assertEquals(origNum, list.size()); CreateIiopListenerTest.checkActionReport(context.getActionReport()); }
@Test public void testExecuteSuccessListListener() { parameters.set("listeneraddress", "localhost"); parameters.set("iiopport", "4440"); parameters.set("listener_id", "listener"); CreateIiopListener createCommand = services.getService(CreateIiopListener.class); cr.getCommandInvocation("create-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand); CreateIiopListenerTest.checkActionReport(context.getActionReport()); parameters = new ParameterMap(); ListIiopListeners listCommand = services.getService(ListIiopListeners.class); cr.getCommandInvocation("list-iiop-listeners", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand); List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren(); assertEquals(origNum + 1, list.size()); List<String> listStr = new ArrayList<String>(); for (MessagePart mp : list) { listStr.add(mp.getMessage()); } assertTrue(listStr.contains("listener")); CreateIiopListenerTest.checkActionReport(context.getActionReport()); parameters = new ParameterMap(); parameters.set("listener_id", "listener"); DeleteIiopListener deleteCommand = services.getService(DeleteIiopListener.class); cr.getCommandInvocation("delete-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand); CreateIiopListenerTest.checkActionReport(context.getActionReport()); }
@Test public void testExecuteSuccessListNoListener() { parameters = new ParameterMap(); ListIiopListeners listCommand = services.getService(ListIiopListeners.class); cr.getCommandInvocation("list-iiop-listeners", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand); CreateIiopListenerTest.checkActionReport(context.getActionReport()); List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren(); assertEquals(origNum, list.size()); List<String> listStr = new ArrayList<String>(); for (MessagePart mp : list) { listStr.add(mp.getMessage()); } assertFalse(listStr.contains("listener")); }