summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/openslx/libvirt/xml/LibvirtXmlDocumentTest.java
diff options
context:
space:
mode:
authorManuel Bentele2022-02-04 12:19:44 +0100
committerManuel Bentele2022-02-04 12:19:44 +0100
commit255c829b598a7a3151489e7121c56b219e530777 (patch)
tree2bd704054b6b3663b3bd9abbcc4604dace7da176 /src/test/java/org/openslx/libvirt/xml/LibvirtXmlDocumentTest.java
parentFix resource path for virtualizer config tests on Windows platforms (diff)
downloadmaster-sync-shared-255c829b598a7a3151489e7121c56b219e530777.tar.gz
master-sync-shared-255c829b598a7a3151489e7121c56b219e530777.tar.xz
master-sync-shared-255c829b598a7a3151489e7121c56b219e530777.zip
Force Unix line endings for Libvirt XML files (even on Windows platforms)
Diffstat (limited to 'src/test/java/org/openslx/libvirt/xml/LibvirtXmlDocumentTest.java')
-rw-r--r--src/test/java/org/openslx/libvirt/xml/LibvirtXmlDocumentTest.java29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/test/java/org/openslx/libvirt/xml/LibvirtXmlDocumentTest.java b/src/test/java/org/openslx/libvirt/xml/LibvirtXmlDocumentTest.java
index 02c8b19..15d203c 100644
--- a/src/test/java/org/openslx/libvirt/xml/LibvirtXmlDocumentTest.java
+++ b/src/test/java/org/openslx/libvirt/xml/LibvirtXmlDocumentTest.java
@@ -7,9 +7,13 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;
@@ -78,6 +82,22 @@ public class LibvirtXmlDocumentTest
return document;
}
+ private static long countLines( Reader input ) throws IOException
+ {
+ final BufferedReader bfrContent = new BufferedReader( input );
+ return bfrContent.lines().count();
+ }
+
+ public static long countLinesFromString( String input ) throws IOException
+ {
+ return LibvirtXmlDocumentTest.countLines( new StringReader( input ) );
+ }
+
+ public static long countLinesFromFile( File input ) throws IOException
+ {
+ return LibvirtXmlDocumentTest.countLines( new FileReader( input ) );
+ }
+
@Test
@DisplayName( "Read libvirt XML file to String" )
public void testReadXmlFileToString() throws LibvirtXmlSerializationException, IOException
@@ -86,12 +106,11 @@ public class LibvirtXmlDocumentTest
File originalXmlFile = LibvirtXmlTestResources.getLibvirtXmlFile( "qemu-kvm_default-ubuntu-20-04-vm.xml" );
final String readXmlContent = vm.toXml();
- final String originalXmlContent = FileUtils.readFileToString( originalXmlFile, StandardCharsets.UTF_8 );
assertNotNull( readXmlContent );
- final int lengthReadXmlContent = readXmlContent.split( System.lineSeparator() ).length;
- final int lengthOriginalXmlContent = originalXmlContent.split( System.lineSeparator() ).length;
+ final long lengthReadXmlContent = LibvirtXmlDocumentTest.countLinesFromString( readXmlContent );
+ final long lengthOriginalXmlContent = LibvirtXmlDocumentTest.countLinesFromFile( originalXmlFile );
assertEquals( lengthOriginalXmlContent, lengthReadXmlContent );
}
@@ -111,8 +130,8 @@ public class LibvirtXmlDocumentTest
assertNotNull( readXmlContent );
- final int lengthReadXmlContent = readXmlContent.split( System.lineSeparator() ).length;
- final int lengthOriginalXmlContent = originalXmlContent.split( System.lineSeparator() ).length;
+ final long lengthReadXmlContent = LibvirtXmlDocumentTest.countLinesFromString( readXmlContent );
+ final long lengthOriginalXmlContent = LibvirtXmlDocumentTest.countLinesFromString( originalXmlContent );
assertEquals( lengthOriginalXmlContent, lengthReadXmlContent );
}