diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2014-09-20 09:17:18 +0200 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2015-04-14 07:44:29 +0200 |
commit | d6f22a2af48f83d63b5381118d2029797458194e (patch) | |
tree | cb6bef9a98335a7af2aee40b0752d14fcee0916e /src/main/JUTests/conf/SSSyncConfParserTest.java | |
parent | 774194091e9bcee08e48fcdf4127f9afd9d6d644 (diff) | |
download | sssync-d6f22a2af48f83d63b5381118d2029797458194e.tar.gz sssync-d6f22a2af48f83d63b5381118d2029797458194e.tar.bz2 sssync-d6f22a2af48f83d63b5381118d2029797458194e.zip |
Early development stages (before SCM) : WIP_1
Early development stages (before SCM) : WIP_2
Early development stages (before SCM) : WIP_3
Early development stages (before SCM) : WIP_4
Early development stages (before SCM) : WIP_6
Early development stages (before SCM) : WIP_7
Early development stages (before SCM) : WIP_8
Adds documentation folder as an Eclipse project.
Adds README for github.
Decent source tree by tuning Eclise project's location
One forgetten file while movign everything :)
Adding Copyright, licencing (GPL v3), correcting README
Diffstat (limited to 'src/main/JUTests/conf/SSSyncConfParserTest.java')
-rw-r--r-- | src/main/JUTests/conf/SSSyncConfParserTest.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/main/JUTests/conf/SSSyncConfParserTest.java b/src/main/JUTests/conf/SSSyncConfParserTest.java new file mode 100644 index 0000000..100df16 --- /dev/null +++ b/src/main/JUTests/conf/SSSyncConfParserTest.java @@ -0,0 +1,69 @@ +package conf; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.net.URL; + +import org.junit.Before; +import org.junit.Test; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; + +public class SSSyncConfParserTest { + + private File currentFolder; + + @Before + public void setup() { + URL main = SSSyncConfParserTest.class.getResource("SSSyncConfParserTest.class"); + if (!"file".equalsIgnoreCase(main.getProtocol())) + throw new IllegalStateException("This class is not stored in a file"); + currentFolder = new File(main.getPath()).getParentFile(); + } + + @Test + public void loadConfigTest() throws Exception { + + String expectedMain = readEntireFile(new File(currentFolder, "testExpectedMain.yaml")); + String expectedConn = readEntireFile(new File(currentFolder, "testExpectedConn.yaml")); + String mainConfigFile = new File(currentFolder, "testMain.yaml").getAbsolutePath(); + String connConfigFile = new File(currentFolder, "testConn.yaml").getAbsolutePath(); + + // Loading (config => beans) + ConfigRootBean confMain = SSSyncConfParser.loadMainConfig(mainConfigFile); + ConfigConnectionsBean confConn = SSSyncConfParser.loadConnConfig(connConfigFile); + + + System.out.println(confMain); + System.out.println(confConn); + + // Dumping (beans => config) + DumperOptions options = new DumperOptions(); + options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + Yaml yamlDump = new Yaml(options); + String dumpMain = yamlDump.dump(confMain); + String dumpConn = yamlDump.dump(confConn); + + // Checking that everything is kept + assertEquals(expectedMain, dumpMain); + assertEquals(expectedConn, dumpConn); + } + + private static String readEntireFile(File file) throws IOException { + FileReader in = new FileReader(file); + StringBuilder contents = new StringBuilder((int) file.length()); + char[] buffer = new char[4096]; + int read = 0; + do { + contents.append(buffer, 0, read); + read = in.read(buffer); + } while (read >= 0); + in.close(); + + return contents.toString(); + } + +} |