summaryrefslogtreecommitdiffstats
path: root/core/modules/qemu/runvirt-plugin-qemu/src/test/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericFileSystemDevicesTest.java
blob: 7605f778f3a8dc8502765acdf9eee2596b740a6c (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
64
65
66
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.FileSystem;
import org.openslx.libvirt.domain.device.FileSystem.AccessMode;
import org.openslx.libvirt.domain.device.FileSystem.Type;
import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs;
import org.openslx.virtualization.configuration.transformation.TransformationException;

public class TransformationGenericFileSystemDevicesTest
{
	@Test
	@DisplayName( "Test transformation of VM file system devices configuration with specified input data" )
	public void testTransformationGenericFileSystemDevices() throws TransformationException
	{
		final TransformationGenericFileSystemDevices transformation = new TransformationGenericFileSystemDevices();
		final Domain config = TransformationTestUtils.getDefaultDomain();
		final CommandLineArgs args = TransformationTestUtils.getDefaultCmdLnArgs();

		final ArrayList<FileSystem> devicesBeforeTransformation = config.getFileSystemDevices();
		assertEquals( 0, devicesBeforeTransformation.size() );

		transformation.transform( config, args );

		final ArrayList<FileSystem> devicesAfterTransformation = config.getFileSystemDevices();
		assertEquals( 2, devicesAfterTransformation.size() );
		final FileSystem fs1AfterTransformation = devicesAfterTransformation.get( 0 );
		final FileSystem fs2AfterTransformation = devicesAfterTransformation.get( 1 );
		assertEquals( Type.MOUNT, fs1AfterTransformation.getType() );
		assertEquals( AccessMode.MAPPED, fs1AfterTransformation.getAccessMode() );
		assertEquals( TransformationTestUtils.DEFAULT_VM_FSSRC0, fs1AfterTransformation.getSource() );
		assertEquals( TransformationTestUtils.DEFAULT_VM_FSTGT0, fs1AfterTransformation.getTarget() );
		assertEquals( Type.MOUNT, fs2AfterTransformation.getType() );
		assertEquals( AccessMode.MAPPED, fs2AfterTransformation.getAccessMode() );
		assertEquals( TransformationTestUtils.DEFAULT_VM_FSSRC1, fs2AfterTransformation.getSource() );
		assertEquals( TransformationTestUtils.DEFAULT_VM_FSTGT1, fs2AfterTransformation.getTarget() );

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

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

		final ArrayList<FileSystem> devicesBeforeTransformation = config.getFileSystemDevices();
		assertEquals( 0, devicesBeforeTransformation.size() );

		transformation.transform( config, args );

		final ArrayList<FileSystem> devicesAfterTransformation = config.getFileSystemDevices();
		assertEquals( 0, devicesAfterTransformation.size() );

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