Package com.powsybl.commons.test
Class AbstractSerDeTest
java.lang.Object
com.powsybl.commons.test.AbstractSerDeTest
- Author:
- Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected <T> T
roundTripTest
(T data, BiConsumer<T, Path> write, Function<Path, T> read, String ref) Roundtrip test on the given data.protected <T> T
roundTripTest
(T data, BiConsumer<T, Path> write, Function<Path, T> read, BiConsumer<InputStream, InputStream> compare, String ref) protected <T> T
roundTripTest
(T data, BiFunction<T, Path, T> transformer, BiConsumer<T, Path> write, Function<Path, T> read, BiConsumer<InputStream, InputStream> compare, String ref) protected <T> T
roundTripXmlTest
(T data, BiFunction<T, Path, T> transformer, BiConsumer<T, Path> write, Function<Path, T> read, String ref) XML roundtrip test on the given data.void
setUp()
void
tearDown()
protected <T> Path
writeTest
(T data, BiConsumer<T, Path> write, BiConsumer<InputStream, InputStream> compare, String ref) Write the given data with given write function, and compare the resulting file to given reference with the comparison method provided.protected <T> Path
writeXmlTest
(T data, BiConsumer<T, Path> write, String ref) Write the given data with given write function, and compare the resulting XML file to given reference.
-
Field Details
-
fileSystem
-
tmpDir
-
-
Constructor Details
-
AbstractSerDeTest
public AbstractSerDeTest()
-
-
Method Details
-
setUp
- Throws:
IOException
-
tearDown
- Throws:
IOException
-
roundTripXmlTest
protected <T> T roundTripXmlTest(T data, BiFunction<T, Path, throws IOExceptionT> transformer, BiConsumer<T, Path> write, Function<Path, T> read, String ref) XML roundtrip test on the given data. The following steps occur:- Transform the given data with the transformer function provided. This might be used to add a roundtrip on other formats prior to the XML roundtrip.
- Write the transformed data to a temporary XML file thanks to the given write function.
- Compare the obtained XML file with the given reference file thanks to
ComparisonUtils.compareXml(java.io.InputStream, java.io.InputStream)
. - Read the same XML file with the given read function.
- Write the data read in the previous step to a new temporary XML file.
- Compare the new obtained XML file with the first obtained XML file byte by byte using
Files.mismatch(java.nio.file.Path, java.nio.file.Path)
. - Return the data read 3 steps above.
- Throws:
IOException
-
roundTripTest
protected <T> T roundTripTest(T data, BiConsumer<T, Path> write, Function<Path, throws IOExceptionT> read, String ref) Roundtrip test on the given data. The following steps occur:- Write the given data to a temporary file thanks to the given write function.
- Compare the obtained file with the given reference file thanks to
ComparisonUtils.compareTxt(java.io.InputStream, java.io.InputStream)
. - Read the same file with the given read function.
- Write the data read in the previous step to a new temporary file.
- Compare the new obtained file with the first obtained file byte by byte using
Files.mismatch(java.nio.file.Path, java.nio.file.Path)
. - Return the data read 3 steps above.
- Throws:
IOException
-
writeXmlTest
Write the given data with given write function, and compare the resulting XML file to given reference.- Returns:
- the path of written file.
- Throws:
IOException
-
writeTest
protected <T> Path writeTest(T data, BiConsumer<T, Path> write, BiConsumer<InputStream, throws IOExceptionInputStream> compare, String ref) Write the given data with given write function, and compare the resulting file to given reference with the comparison method provided.- Returns:
- the path of written XML file.
- Throws:
IOException
-
roundTripTest
protected <T> T roundTripTest(T data, BiConsumer<T, Path> write, Function<Path, throws IOExceptionT> read, BiConsumer<InputStream, InputStream> compare, String ref) - Throws:
IOException
-
roundTripTest
protected <T> T roundTripTest(T data, BiFunction<T, Path, throws IOExceptionT> transformer, BiConsumer<T, Path> write, Function<Path, T> read, BiConsumer<InputStream, InputStream> compare, String ref) - Throws:
IOException
-