@Test public void investigateHostStatusFailure() { Mockito.when(_hostDao.findById(Mockito.anyLong())).thenReturn(hostVO); // Set the list of investigators, CheckOnAgentInvestigator suffices for now // Also no need to mock isAgentAlive() as actual implementation returns null Investigator investigator = Mockito.mock(CheckOnAgentInvestigator.class); List<Investigator> investigators = new ArrayList<Investigator>(); investigators.add(investigator); highAvailabilityManager.setInvestigators(investigators); assertNull(highAvailabilityManager.investigate(1l)); }
@Test public void investigateHostStatusSuccess() { Mockito.when(_hostDao.findById(Mockito.anyLong())).thenReturn(hostVO); // Set the list of investigators, CheckOnAgentInvestigator suffices for now Investigator investigator = Mockito.mock(CheckOnAgentInvestigator.class); List<Investigator> investigators = new ArrayList<Investigator>(); investigators.add(investigator); highAvailabilityManager.setInvestigators(investigators); // Mock isAgentAlive to return host status as Down Mockito.when(investigator.isAgentAlive(hostVO)).thenReturn(Status.Down); assertTrue(highAvailabilityManager.investigate(1l) == Status.Down); }
@Test public void scheduleRestartForVmsOnHost() { Mockito.when(hostVO.getType()).thenReturn(Host.Type.Routing); Mockito.when(hostVO.getHypervisorType()).thenReturn(HypervisorType.KVM); Mockito.when(_instanceDao.listByHostId(42l)) .thenReturn(Arrays.asList(Mockito.mock(VMInstanceVO.class))); Mockito.when(_podDao.findById(Mockito.anyLong())).thenReturn(Mockito.mock(HostPodVO.class)); Mockito.when(_dcDao.findById(Mockito.anyLong())).thenReturn(Mockito.mock(DataCenterVO.class)); highAvailabilityManager.scheduleRestartForVmsOnHost(hostVO, true); }