protected void runAddAndVerify( VmNic iface, boolean reserveExistingMac, VerificationMode addMacVerification, int osId, Version version) { OsRepository osRepository = mock(OsRepository.class); when(vmInterfaceManager.getOsRepository()).thenReturn(osRepository); when(osRepository.hasNicHotplugSupport(any(Integer.class), any(Version.class))) .thenReturn(true); vmInterfaceManager.add( iface, NoOpCompensationContext.getInstance(), reserveExistingMac, osId, version); if (reserveExistingMac) { verify(macPoolManagerStrategy, times(1)).forceAddMac((iface.getMacAddress())); } else { verifyZeroInteractions(macPoolManagerStrategy); } verifyAddDelegatedCorrectly(iface, addMacVerification); }
/** * Verify that {@link VmInterfaceManager#removeAll} delegated correctly to {@link * MacPoolManagerStrategy} & Daos. * * @param iface The interface to check for. */ protected void verifyRemoveAllDelegatedCorrectly(VmNic iface) { verify(macPoolManagerStrategy, times(1)).freeMac(iface.getMacAddress()); verify(vmNicDao).remove(iface.getId()); verify(vmNetworkStatisticsDao).remove(iface.getId()); }
/** * Verify that {@link VmInterfaceManager#add} delegated correctly to {@link * MacPoolManagerStrategy} & Daos. * * @param iface The interface to check for. * @param addMacVerification Mode to check (times(1), never(), etc) for {@link * MacPoolManagerStrategy#addMac(String)}. */ protected void verifyAddDelegatedCorrectly(VmNic iface, VerificationMode addMacVerification) { verify(macPoolManagerStrategy, addMacVerification).forceAddMac(iface.getMacAddress()); verify(vmNicDao).save(iface); verify(vmNetworkStatisticsDao).save(iface.getStatistics()); }