AutonomiccsSystemVmsGuru implements VirtualMachineGuru, InitializingBean { @Override public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException { AutonomiccsSystemVm autonomiccsSystemVm = autonomiccsSystemVmDao.findById(profile.getId()); DataCenter dc = dest.getDataCenter(); List<NicProfile> nics = profile.getNics(); setIpAddressOfEachNic(autonomiccsSystemVm, dc, nics); autonomiccsSystemVmDao.update(profile.getId(), autonomiccsSystemVm); return true; }  @Override void afterPropertiesSet(); @Override boolean finalizeCommandsOnStart(Commands arg0, VirtualMachineProfile arg1); @Override boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context); @Override void finalizeExpunge(VirtualMachine vm); @Override boolean finalizeStart(VirtualMachineProfile arg0, long arg1, Commands arg2, ReservationContext arg3); @Override void finalizeStop(VirtualMachineProfile arg0, Answer arg1); @Override boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context); @Override void prepareStop(VirtualMachineProfile arg0);  }
@Test public void finalizeDeploymentTest() throws ResourceUnavailableException { ReservationContext context = Mockito.mock(ReservationContext.class); Commands cmds = Mockito.mock(Commands.class); DataCenter dc = Mockito.mock(DataCenter.class); VirtualMachineProfileImpl profile = Mockito.mock(VirtualMachineProfileImpl.class); Mockito.when(profile.getNics()).thenReturn(new ArrayList<NicProfile>()); Mockito.when(profile.getId()).thenReturn(0l); AutonomiccsSystemVm autonomiccsSystemVm = Mockito.mock(AutonomiccsSystemVm.class); Mockito.doReturn(autonomiccsSystemVm).when(autonomiccsSystemVmDao).findById(Mockito.anyLong()); DeployDestination dest = Mockito.mock(DeployDestination.class); Mockito.when(dest.getDataCenter()).thenReturn(dc); Mockito.doNothing().when(spy).setIpAddressOfEachNic(Mockito.any(AutonomiccsSystemVm.class), Mockito.any(DataCenter.class), Matchers.anyListOf(NicProfile.class)); Mockito.doReturn(true).when(autonomiccsSystemVmDao).update(Mockito.anyLong(), Mockito.any(AutonomiccsSystemVm.class)); boolean result = spy.finalizeDeployment(cmds, profile, dest, context); Assert.assertEquals(true, result); InOrder inOrder = Mockito.inOrder(autonomiccsSystemVmDao, spy); inOrder.verify(autonomiccsSystemVmDao).findById(Mockito.anyLong()); inOrder.verify(spy).setIpAddressOfEachNic(Mockito.any(AutonomiccsSystemVm.class), Mockito.any(DataCenter.class), Matchers.anyListOf(NicProfile.class)); inOrder.verify(autonomiccsSystemVmDao).update(Mockito.anyLong(), Mockito.any(AutonomiccsSystemVm.class)); }