summaryrefslogtreecommitdiffstats
path: root/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericInterfaceDevicesTest.java
blob: e4632784ccd2f8912aeb23b75d5d18cdf6917e33 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.openslx.runvirt.plugin.qemu.configuration;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.ArrayList;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.openslx.libvirt.domain.Domain;
import org.openslx.libvirt.domain.device.Interface;
import org.openslx.libvirt.domain.device.Interface.Model;
import org.openslx.libvirt.domain.device.Interface.Type;
import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs;
import org.openslx.virtualization.configuration.VirtualizationConfigurationQemu;
import org.openslx.virtualization.configuration.transformation.TransformationException;

public class TransformationGenericInterfaceDevicesTest
{
	@Test
	@DisplayName( "Test transformation of VM network interface devices configuration with specified input data" )
	public void testTransformationGenericInterfaceDevices() throws TransformationException
	{
		final TransformationGenericInterfaceDevices transformation = new TransformationGenericInterfaceDevices();
		final Domain config = TransformationTestUtils.getDefaultDomain();
		final CommandLineArgs args = TransformationTestUtils.getDefaultCmdLnArgs();

		final ArrayList<Interface> devicesBeforeTransformation = config.getInterfaceDevices();
		assertEquals( 1, devicesBeforeTransformation.size() );

		transformation.transform( config, args );

		final ArrayList<Interface> devicesAfterTransformation = config.getInterfaceDevices();
		assertEquals( 1, devicesAfterTransformation.size() );
		final Interface interfaceAfterTransformation = devicesAfterTransformation.get( 0 );
		assertEquals( Type.BRIDGE, interfaceAfterTransformation.getType() );
		assertEquals( Model.VIRTIO, interfaceAfterTransformation.getModel() );
		assertEquals( TransformationTestUtils.DEFAULT_VM_MAC0, interfaceAfterTransformation.getMacAddress() );
		assertEquals( VirtualizationConfigurationQemu.NETWORK_BRIDGE_NAT_DEFAULT,
				interfaceAfterTransformation.getSource() );

		assertDoesNotThrow( () -> config.validateXml() );
	}

	@Test
	@DisplayName( "Test transformation of VM network interface devices configuration with unspecified input data" )
	public void testTransformationGenericInterfaceDevicesNoData() throws TransformationException
	{
		final TransformationGenericInterfaceDevices transformation = new TransformationGenericInterfaceDevices();
		final Domain config = TransformationTestUtils.getDefaultDomain();
		final CommandLineArgs args = TransformationTestUtils.getEmptyCmdLnArgs();

		final ArrayList<Interface> devicesBeforeTransformation = config.getInterfaceDevices();
		assertEquals( 1, devicesBeforeTransformation.size() );

		transformation.transform( config, args );

		final ArrayList<Interface> devicesAfterTransformation = config.getInterfaceDevices();
		assertEquals( 0, devicesAfterTransformation.size() );

		assertDoesNotThrow( () -> config.validateXml() );
	}
}