NetworkHelperImpl implements NetworkHelper { @Override public boolean sendCommandsToRouter(final VirtualRouter router, final Commands cmds) throws AgentUnavailableException, ResourceUnavailableException { if (!checkRouterVersion(router)) { s_logger.debug("Router requires upgrade. Unable to send command to router:" + router.getId() + ", router template version : " + router.getTemplateVersion() + ", minimal required version : " + NetworkOrchestrationService.MinVRVersion.valueIn(router.getDataCenterId())); throw new ResourceUnavailableException("Unable to send command. Router requires upgrade", VirtualRouter.class, router.getId()); } Answer[] answers = null; try { answers = _agentMgr.send(router.getHostId(), cmds); } catch (final OperationTimedoutException e) { s_logger.warn("Timed Out", e); throw new AgentUnavailableException("Unable to send commands to virtual router ", router.getHostId(), e); } if (answers == null || answers.length != cmds.size()) { return false; } boolean result = true; for (final Answer answer : answers) { if (!answer.getResult()) { result = false; break; } } return result; }  @Override boolean sendCommandsToRouter(final VirtualRouter router, final Commands cmds); @Override void handleSingleWorkingRedundantRouter(final List<? extends VirtualRouter> connectedRouters, final List<? extends VirtualRouter> disconnectedRouters,
                                                   final String reason); @Override NicTO getNicTO(final VirtualRouter router, final Long networkId, final String broadcastUri); @Override VirtualRouter destroyRouter(final long routerId, final Account caller, final Long callerUserId); @Override boolean checkRouterVersion(final VirtualRouter router); @Override List<DomainRouterVO> startRouters(final RouterDeploymentDefinition routerDeploymentDefinition); @Override DomainRouterVO startVirtualRouter(final DomainRouterVO router, final User user, final Account caller, final Map<Param, Object> params); @Override DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploymentDefinition, final boolean startRouter); @Override LinkedHashMap<Network, List<? extends NicProfile>> configureDefaultNics(final RouterDeploymentDefinition routerDeploymentDefinition); @Override LinkedHashMap<Network, List<? extends NicProfile>> configureGuestNic(final RouterDeploymentDefinition routerDeploymentDefinition); @Override void reallocateRouterNetworks(final RouterDeploymentDefinition routerDeploymentDefinition, final VirtualRouter router, final VMTemplateVO template, final HypervisorType hType); static void setSystemAccount(final Account systemAccount); static void setVMInstanceName(final String vmInstanceName);  }
@Test public void testSendCommandsToRouter() throws AgentUnavailableException, OperationTimedoutException, ResourceUnavailableException { NetworkHelperImpl nwHelperUT = spy(this.nwHelper); VirtualRouter vr = mock(VirtualRouter.class); when(vr.getHostId()).thenReturn(HOST_ID); doReturn(true).when(nwHelperUT).checkRouterVersion(vr); Commands commands = mock(Commands.class); when(commands.size()).thenReturn(3); Answer answer1 = mock(Answer.class); Answer answer2 = mock(Answer.class); Answer answer3 = mock(Answer.class); Answer[] answers = {answer1, answer2, answer3}; when(answer1.getResult()).thenReturn(true); when(answer2.getResult()).thenReturn(false); when(answer3.getResult()).thenReturn(false); when(this.agentManager.send(HOST_ID, commands)).thenReturn(answers); final boolean result = nwHelperUT.sendCommandsToRouter(vr, commands); verify(this.agentManager, times(1)).send(HOST_ID, commands); verify(answer1, times(1)).getResult(); verify(answer2, times(1)).getResult(); verify(answer3, times(0)).getResult(); assertFalse(result); }