summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/openslx/virtualization/disk/DiskImageVmdkTest.java
blob: 5b3cccf8c1f9f168c765a24e192bd83298d4a64a (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package org.openslx.virtualization.disk;

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

import java.io.IOException;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.openslx.virtualization.Version;
import org.openslx.virtualization.disk.DiskImage.ImageFormat;

public class DiskImageVmdkTest
{
	@Test
	@DisplayName( "Test detection of default VMDK disk image" )
	public void testVmdkDiskImage() throws DiskImageException, IOException
	{
		final DiskImage image = DiskImage.newInstance( DiskImageTestResources.getDiskFile( "image-default.vmdk" ) );
		final Version imageVersion = new Version( Short.valueOf( "1" ) );
		final Version imageHwVersion = new Version( Short.valueOf( "18" ) );

		assertEquals( ImageFormat.VMDK.toString(), image.getFormat().toString() );
		assertEquals( true, image.isStandalone() );
		assertEquals( false, image.isSnapshot() );
		assertEquals( false, image.isCompressed() );
		assertEquals( imageVersion, image.getVersion() );
		assertNull( image.getDescription() );

		// test special features of the VMDK disk image format
		final DiskImageVmdk vmdkImage = DiskImageVmdk.class.cast( image );
		assertEquals( imageHwVersion, vmdkImage.getHwVersion() );
	}

	@Test
	@DisplayName( "Test detection of VMDK disk image (type 0: single growable virtual disk)" )
	public void testVmdkDiskImageType0() throws DiskImageException, IOException
	{
		final DiskImage image = DiskImage.newInstance( DiskImageTestResources.getDiskFile( "image_t0.vmdk" ) );
		final Version imageVersion = new Version( Short.valueOf( "1" ) );
		final Version imageHwVersion = new Version( Short.valueOf( "18" ) );

		assertEquals( ImageFormat.VMDK.toString(), image.getFormat().toString() );
		assertEquals( true, image.isStandalone() );
		assertEquals( false, image.isSnapshot() );
		assertEquals( false, image.isCompressed() );
		assertEquals( imageVersion, image.getVersion() );
		assertNull( image.getDescription() );

		// test special features of the VMDK disk image format
		final DiskImageVmdk vmdkImage = DiskImageVmdk.class.cast( image );
		assertEquals( imageHwVersion, vmdkImage.getHwVersion() );
	}

	@Test
	@DisplayName( "Test detection of VMDK disk image (type 1: growable virtual disk split into multiple files)" )
	public void testVmdkDiskImageType1() throws DiskImageException, IOException
	{
		Assertions.assertThrows( DiskImageException.class, () -> {
			DiskImage.newInstance( DiskImageTestResources.getDiskFile( "image_t1.vmdk" ) );
		} );
	}

	@Test
	@DisplayName( "Test detection of VMDK disk image (type 2: preallocated virtual disk)" )
	public void testVmdkDiskImageType2() throws DiskImageException, IOException
	{
		Assertions.assertThrows( DiskImageException.class, () -> {
			DiskImage.newInstance( DiskImageTestResources.getDiskFile( "image_t2.vmdk" ) );
		} );
	}

	@Test
	@DisplayName( "Test detection of VMDK disk image (type 3: preallocated virtual disk split into multiple files)" )
	public void testVmdkDiskImageType3() throws DiskImageException, IOException
	{
		Assertions.assertThrows( DiskImageException.class, () -> {
			DiskImage.newInstance( DiskImageTestResources.getDiskFile( "image_t3.vmdk" ) );
		} );
	}

	@Test
	@DisplayName( "Test detection of VMDK disk image (type 4: preallocated ESX-type virtual disk)" )
	public void testVmdkDiskImageType4() throws DiskImageException, IOException
	{
		Assertions.assertThrows( DiskImageException.class, () -> {
			DiskImage.newInstance( DiskImageTestResources.getDiskFile( "image_t4.vmdk" ) );
		} );
	}

	@Test
	@DisplayName( "Test detection of VMDK disk image (type 5: compressed disk optimized for streaming)" )
	public void testVmdkDiskImageType5() throws DiskImageException, IOException
	{
		final DiskImage image = DiskImage.newInstance( DiskImageTestResources.getDiskFile( "image_t5.vmdk" ) );
		final Version imageVersion = new Version( Short.valueOf( "3" ) );
		final Version imageHwVersion = new Version( Short.valueOf( "18" ) );

		assertEquals( ImageFormat.VMDK.toString(), image.getFormat().toString() );
		assertEquals( true, image.isStandalone() );
		assertEquals( false, image.isSnapshot() );
		assertEquals( true, image.isCompressed() );
		assertEquals( imageVersion, image.getVersion() );
		assertNull( image.getDescription() );

		// test special features of the VMDK disk image format
		final DiskImageVmdk vmdkImage = DiskImageVmdk.class.cast( image );
		assertEquals( imageHwVersion, vmdkImage.getHwVersion() );
	}
}