package org.openslx.virtualization.configuration.logic; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.StringReader; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import org.apache.commons.io.FileUtils; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.virtualization.configuration.VirtualizationConfiguration; import org.xmlunit.assertj.XmlAssert; public class ConfigurationLogicTestUtils { // @formatter:off public static final List STUB_OS_LIST = Collections.unmodifiableList( Arrays.asList( new OperatingSystem( 1, "Windows 7 (64 Bit)", null, "AMD64", 196608, 256 ), new OperatingSystem( 2, "Windows 8 (32 Bit)", null, "x86", 4096, 32 ), new OperatingSystem( 3, "Windows 8 (64 Bit)", null, "AMD64", 131072, 256 ), new OperatingSystem( 4, "Ubuntu (32 Bit)", null, "x86", 0, 0 ), new OperatingSystem( 5, "Ubuntu (64 Bit)", null, "AMD64", 0, 0 ), new OperatingSystem( 6, "OpenSUSE (32 Bit)", null, "x86", 0, 0 ), new OperatingSystem( 7, "OpenSUSE (64 Bit)", null, "AMD64", 0, 0 ), new OperatingSystem( 8, "Other Linux (32 Bit)", null, "x86", 0, 0 ), new OperatingSystem( 9, "Other Linux (64 Bit)", null, "AMD64", 0, 0 ), new OperatingSystem( 10, "Windows 7 (32 Bit)", null, "x86", 4096, 32 ), new OperatingSystem( 11, "Windows 2000 Professional", null, "x86", 4096, 4 ) ) ); // @formatter:on 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 = "( linesVmx1 = bfrVmx1.lines().collect( Collectors.toList() ); final List linesVmx2 = bfrVmx2.lines().collect( Collectors.toList() ); // check output size first if ( linesVmx1.size() != linesVmx2.size() ) { // create list of items that are expected but missing in the actual output final List missingItems; final String missingItemsDesc; if ( linesVmx1.size() > linesVmx2.size() ) { missingItemsDesc = "The following items are expected but missing in the actual output"; missingItems = new ArrayList( linesVmx1 ); missingItems.removeAll( linesVmx2 ); } else { missingItemsDesc = "The following items are not expected but occuring in the actual output"; missingItems = new ArrayList( linesVmx2 ); missingItems.removeAll( linesVmx1 ); } throw new AssertionError( String.format( "VMX output size is not satisfied: Expected %d lines, but output has %d lines!\n" + "%s:\n" + "%s", linesVmx1.size(), linesVmx2.size(), missingItemsDesc, missingItems ) ); } // check the content of the output line by line assertEquals( linesVmx1, linesVmx2 ); } }