use of org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method testValidateNotRemovingUsedNetworkByVmsWhenUsedByVms.
@Test
public void testValidateNotRemovingUsedNetworkByVmsWhenUsedByVms() {
String nameOfNetworkA = "networkA";
Network networkA = createNetworkWithName(nameOfNetworkA);
NetworkAttachment networkAttachmentA = createNetworkAttachment(networkA);
VdsNetworkInterface nicA = createNic("nicA");
networkAttachmentA.setNicId(nicA.getId());
final HostSetupNetworksValidator underTest = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addRemovedNetworkAttachments(networkAttachmentA).build()).addExistingInterfaces(Collections.singletonList(nicA)).addExistingAttachments(Collections.singletonList(networkAttachmentA)).addNetworks(Collections.singletonList(networkA)).build();
List<String> vmNames = Arrays.asList("vmName1", "vmName2");
when(findActiveVmsUsingNetwork.findNamesOfActiveVmsUsingNetworks(any(), anyCollection())).thenReturn(vmNames);
final List<String> removedNetworkNames = Collections.singletonList(nameOfNetworkA);
assertThat(underTest.validateNotRemovingUsedNetworkByVms(nameOfNetworkA), failsWith(EngineMessage.NETWORK_CANNOT_DETACH_NETWORK_USED_BY_VMS, Stream.concat(ReplacementUtils.replaceWith(VAR_NETWORK_NAME, removedNetworkNames, SEPARATOR).stream(), ReplacementUtils.replaceWith(VAR_VM_NAMES, vmNames, SEPARATOR).stream()).collect(Collectors.toList())));
verify(findActiveVmsUsingNetwork).findNamesOfActiveVmsUsingNetworks(eq(host.getId()), collectionArgumentCaptor.capture());
assertThat(collectionArgumentCaptor.getValue(), contains(nameOfNetworkA));
}
Aggregations