diff options
3 files changed, 20 insertions, 7 deletions
diff --git a/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClientTest.java b/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClientTest.java index 2271e9c..57df203 100644 --- a/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClientTest.java +++ b/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClientTest.java @@ -71,7 +71,7 @@ public class ConfigurationLogicDozModServerToStatelessClientTest final String transformedConfig = config.getConfigurationAsString(); final String expectedTransformedConfig = ConfigurationLogicTestUtils.readFileToString( expectedConfig ); - ConfigurationLogicTestUtils.assertXmlVirtualBoxEqual( expectedTransformedConfig, transformedConfig ); + ConfigurationLogicTestUtils.assertXmlEqual( expectedTransformedConfig, transformedConfig ); // do not validate the VirtualBox configuration afterwards, since the inserted // place holders do not match valid primitive values from the XML schema diff --git a/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicTestUtils.java b/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicTestUtils.java index 466a1d6..d085960 100644 --- a/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicTestUtils.java +++ b/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicTestUtils.java @@ -38,7 +38,8 @@ public class ConfigurationLogicTestUtils new OperatingSystem( 11, "Windows 2000 Professional", null, "x86", 4096, 4 ) ) ); // @formatter:on - private static final String REGEX_SOURCE_FILE_PATHS = "(<source.*file=\")(.*)(\".*>)"; + private static final String REGEX_UUID = "<(Machine|HardDisk|Image)(.*)[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"; + private static final String REGEX_SOURCE_FILE_PATHS = "(<source.*file=\")([^\"]*)"; public static VirtualizationConfiguration newVirtualizationConfigurationInstance( File configFile ) { @@ -81,7 +82,16 @@ public class ConfigurationLogicTestUtils final Matcher matcherSourceFilePathsContent = patternSourceFilePaths.matcher( content ); // replace all source file paths with the empty String - return matcherSourceFilePathsContent.replaceAll( "$1$3" ); + return matcherSourceFilePathsContent.replaceAll( "$1" ); + } + + private static String removeUuid( String content ) + { + final Pattern patternUuid = Pattern.compile( ConfigurationLogicTestUtils.REGEX_UUID ); + final Matcher matcherUuidContent = patternUuid.matcher( content ); + + // replace all UUIDs with the empty String + return matcherUuidContent.replaceAll( "<$1$200000000-0000-0000-0000-000000000000" ); } public static void assertXmlLibvirtEqual( String expectedXml, String actualXml ) throws AssertionError @@ -95,7 +105,10 @@ public class ConfigurationLogicTestUtils public static void assertXmlVirtualBoxEqual( String expectedXml, String actualXml ) throws AssertionError { - ConfigurationLogicTestUtils.assertXmlEqual( expectedXml, actualXml ); + // replace all UUIDs with the zero UUID in the generated XML as it's random + final String actualXmlFiltered = ConfigurationLogicTestUtils.removeUuid( actualXml ); + + ConfigurationLogicTestUtils.assertXmlEqual( expectedXml, actualXmlFiltered ); } public static void assertVmxVmwareEqual( String expectedVmx, String actualVmx ) throws AssertionError diff --git a/src/test/resources/virtualbox/xml/virtualbox_default-ubuntu_transform-editable.vbox b/src/test/resources/virtualbox/xml/virtualbox_default-ubuntu_transform-editable.vbox index 572f389..63a790b 100644 --- a/src/test/resources/virtualbox/xml/virtualbox_default-ubuntu_transform-editable.vbox +++ b/src/test/resources/virtualbox/xml/virtualbox_default-ubuntu_transform-editable.vbox @@ -1,8 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?><VirtualBox xmlns="http://www.virtualbox.org/" version="1.16-linux"> - <Machine xmlns="http://www.virtualbox.org/" OSType="Ubuntu_64" lastStateChange="2021-04-28T09:11:13Z" name="Test" snapshotFolder="[dummy]" uuid="{f6f806e9-21e3-4238-9e4a-48057a4ab885}"> + <Machine xmlns="http://www.virtualbox.org/" OSType="Ubuntu_64" lastStateChange="2021-04-28T09:11:13Z" name="Test" snapshotFolder="[dummy]" uuid="{00000000-0000-0000-0000-000000000000}"> <MediaRegistry> <HardDisks> - <HardDisk format="VDI" location="image-default.vmdk" type="Normal" uuid="{8eb78aa6-39bf-4eeb-8afc-02af8297d230}"/> + <HardDisk format="VDI" location="image-default.vmdk" type="Normal" uuid="{00000000-0000-0000-0000-000000000000}"/> </HardDisks> </MediaRegistry> <Hardware uuid="{b36f101a-a45d-41cb-8bd4-3908e75e081b}"> @@ -36,7 +36,7 @@ <StorageController Bootable="true" PortCount="2" name="IDE" type="PIIX4" useHostIOCache="true"/> <StorageController Bootable="true" IDE0MasterEmulationPort="0" IDE0SlaveEmulationPort="1" IDE1MasterEmulationPort="2" IDE1SlaveEmulationPort="3" PortCount="1" name="SATA" type="AHCI" useHostIOCache="false"> <AttachedDevice device="0" hotpluggable="false" port="0" type="HardDisk"> - <Image uuid="{8eb78aa6-39bf-4eeb-8afc-02af8297d230}"/> + <Image uuid="{00000000-0000-0000-0000-000000000000}"/> </AttachedDevice> </StorageController> <StorageController Bootable="false" PortCount="1" name="Floppy" type="I82078" useHostIOCache="true"> |