Modified tests to always read and write files with UTF-8 encoding

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_spring_cleaning@215 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
index 1ae6466..4dfe106 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
@@ -6,8 +6,8 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
-import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.Reader;
 import java.io.UnsupportedEncodingException;
@@ -48,7 +48,7 @@
 
     public static void runScriptAndCompareWithResult(IHyracksClientConnection hcc, File scriptFile, PrintWriter print,
             File expectedFile, File actualFile) throws Exception {
-        Reader query = new BufferedReader(new FileReader(scriptFile));
+        Reader query = new BufferedReader(new InputStreamReader(new FileInputStream(scriptFile), "UTF-8"));
         AsterixJavaClient asterix = new AsterixJavaClient(hcc, query, print);
         try {
             asterix.compile(true, false, true, true, false, true, false);
@@ -58,8 +58,10 @@
             query.close();
         }
         asterix.execute();
-        BufferedReader readerExpected = new BufferedReader(new FileReader(expectedFile));
-        BufferedReader readerActual = new BufferedReader(new FileReader(actualFile));
+        BufferedReader readerExpected = new BufferedReader(new InputStreamReader(new FileInputStream(expectedFile),
+                "UTF-8"));
+        BufferedReader readerActual = new BufferedReader(
+                new InputStreamReader(new FileInputStream(actualFile), "UTF-8"));
         String lineExpected, lineActual;
         int num = 1;
         try {
@@ -122,8 +124,10 @@
         }
         fos.close();
 
-        BufferedReader readerExpected = new BufferedReader(new FileReader(expectedFile));
-        BufferedReader readerActual = new BufferedReader(new FileReader(actualFile));
+        BufferedReader readerExpected = new BufferedReader(new InputStreamReader(new FileInputStream(expectedFile),
+                "UTF-8"));
+        BufferedReader readerActual = new BufferedReader(
+                new InputStreamReader(new FileInputStream(actualFile), "UTF-8"));
         String lineExpected, lineActual;
         int num = 1;
         try {
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/aqlj/ClientAPITest.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/aqlj/ClientAPITest.java
index fcc4eaf..0301675 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/aqlj/ClientAPITest.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/aqlj/ClientAPITest.java
@@ -2,9 +2,10 @@
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -48,7 +49,7 @@
         ArrayList<String> list = new ArrayList<String>();
         BufferedReader result;
         try {
-            result = new BufferedReader(new FileReader(PATH_BASE + fileName));
+            result = new BufferedReader(new InputStreamReader(new FileInputStream(PATH_BASE + fileName), "UTF-8"));
             while (true) {
                 String line = result.readLine();
                 if (line == null) {
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/dml/DmlTest.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/dml/DmlTest.java
index 3e82ff6..5b88edb 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/dml/DmlTest.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/dml/DmlTest.java
@@ -2,7 +2,8 @@
 
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.Reader;
 
@@ -34,7 +35,8 @@
         outdir.mkdirs();
 
         AsterixHyracksIntegrationUtil.init();
-        Reader loadReader = new BufferedReader(new FileReader(LOAD_FOR_ENLIST_FILE));
+        Reader loadReader = new BufferedReader(
+                new InputStreamReader(new FileInputStream(LOAD_FOR_ENLIST_FILE), "UTF-8"));
         AsterixJavaClient asterixLoad = new AsterixJavaClient(
                 AsterixHyracksIntegrationUtil.getHyracksClientConnection(), loadReader, ERR);
         try {
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/metadata/MetadataTest.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/metadata/MetadataTest.java
index baa91dc..6fec201 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/metadata/MetadataTest.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/metadata/MetadataTest.java
@@ -1,11 +1,8 @@
 package edu.uci.ics.asterix.test.metadata;
 
 import java.io.BufferedReader;
-import java.io.DataInputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
@@ -52,26 +49,6 @@
         return fname.substring(0, dot + 1) + EXTENSION_RESULT;
     }
 
-    public static ArrayList<String> readFile(String fileName) {
-        ArrayList<String> list = new ArrayList<String>();
-        BufferedReader result;
-        try {
-            result = new BufferedReader(new FileReader(PATH_BASE + fileName));
-            while (true) {
-                String line = result.readLine();
-                if (line == null) {
-                    break;
-                } else {
-                    list.add(line);
-                }
-            }
-            result.close();
-        } catch (FileNotFoundException e) {
-        } catch (IOException e) {
-        }
-        return list;
-    }
-
     @BeforeClass
     public static void setUp() throws Exception {
         _oldConfigFileName = System.getProperty(GlobalConfig.CONFIG_FILE_PROPERTY);
@@ -99,11 +76,10 @@
         }
     }
 
-    private static void suiteBuild(File f, Collection<Object[]> testArgs, String path) {
+    private static void suiteBuild(File f, Collection<Object[]> testArgs, String path) throws IOException {
+        BufferedReader br = null;
         try {
-            FileInputStream fstream = new FileInputStream(f);
-            DataInputStream in = new DataInputStream(fstream);
-            BufferedReader br = new BufferedReader(new InputStreamReader(in));
+            br = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
             String strLine;
             File file;
             while ((strLine = br.readLine()) != null) {
@@ -119,14 +95,18 @@
                     testArgs.add(new Object[] { file, expectedFile, actualFile });
                 }
             }
-            in.close();
+
         } catch (IOException e) {
             e.printStackTrace();
+        } finally {
+            if (br != null) {
+                br.close();
+            }
         }
     }
 
     @Parameters
-    public static Collection<Object[]> tests() {
+    public static Collection<Object[]> tests() throws IOException {
         Collection<Object[]> testArgs = new ArrayList<Object[]>();
         suiteBuild(new File(QUERIES_FILE), testArgs, "");
         return testArgs;
@@ -144,7 +124,7 @@
 
     @Test
     public void test() throws Exception {
-        Reader query = new BufferedReader(new FileReader(queryFile));
+        Reader query = new BufferedReader(new InputStreamReader(new FileInputStream(queryFile), "UTF-8"));
         AsterixJavaClient asterix = new AsterixJavaClient(AsterixHyracksIntegrationUtil.getHyracksClientConnection(),
                 query, ERR);
         try {
@@ -160,8 +140,10 @@
         query.close();
 
         if (actualFile.exists()) {
-            BufferedReader readerExpected = new BufferedReader(new FileReader(expectedFile));
-            BufferedReader readerActual = new BufferedReader(new FileReader(actualFile));
+            BufferedReader readerExpected = new BufferedReader(new InputStreamReader(new FileInputStream(expectedFile),
+                    "UTF-8"));
+            BufferedReader readerActual = new BufferedReader(new InputStreamReader(new FileInputStream(actualFile),
+                    "UTF-8"));
             String lineExpected, lineActual;
             int num = 1;
             try {
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/metadata/MetadataTransactionsTest.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/metadata/MetadataTransactionsTest.java
index 6081994..1645a96 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/metadata/MetadataTransactionsTest.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/metadata/MetadataTransactionsTest.java
@@ -3,11 +3,8 @@
 import static org.junit.Assert.fail;
 
 import java.io.BufferedReader;
-import java.io.DataInputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
@@ -55,32 +52,12 @@
         return fname.substring(0, dot + 1) + EXTENSION_RESULT;
     }
 
-    public static ArrayList<String> readFile(String fileName) {
-        ArrayList<String> list = new ArrayList<String>();
-        BufferedReader result;
-        try {
-            result = new BufferedReader(new FileReader(PATH_BASE + fileName));
-            while (true) {
-                String line = result.readLine();
-                if (line == null) {
-                    break;
-                } else {
-                    list.add(line);
-                }
-            }
-            result.close();
-        } catch (FileNotFoundException e) {
-        } catch (IOException e) {
-        }
-        return list;
-    }
-
     private static void executeQueryTuple(Object[] queryTuple, boolean expectFailure, boolean executeQuery) {
         String queryFileName = (String) queryTuple[0];
         String expectedFileName = (String) queryTuple[1];
         String actualFileName = (String) queryTuple[2];
         try {
-            Reader query = new BufferedReader(new FileReader(queryFileName));
+            Reader query = new BufferedReader(new InputStreamReader(new FileInputStream(queryFileName), "UTF-8"));
             AsterixJavaClient asterix = new AsterixJavaClient(
                     AsterixHyracksIntegrationUtil.getHyracksClientConnection(), query, ERR);
             LOGGER.info("Query is: " + queryFileName);
@@ -115,8 +92,10 @@
             File actualFile = new File(actualFileName);
             File expectedFile = new File(expectedFileName);
             if (actualFile.exists()) {
-                BufferedReader readerExpected = new BufferedReader(new FileReader(expectedFile));
-                BufferedReader readerActual = new BufferedReader(new FileReader(actualFile));
+                BufferedReader readerExpected = new BufferedReader(new InputStreamReader(new FileInputStream(
+                        expectedFile), "UTF-8"));
+                BufferedReader readerActual = new BufferedReader(new InputStreamReader(new FileInputStream(actualFile),
+                        "UTF-8"));
                 String lineExpected, lineActual;
                 int num = 1;
                 try {
@@ -204,12 +183,11 @@
     }
 
     private static void prepareQuerySuite(String queryListPath, String queryPath, String expectedPath,
-            String actualPath, Collection<Object[]> output) {
+            String actualPath, Collection<Object[]> output) throws IOException {
+        BufferedReader br = null;
         try {
             File queryListFile = new File(queryListPath);
-            FileInputStream fstream = new FileInputStream(queryListFile);
-            DataInputStream in = new DataInputStream(fstream);
-            BufferedReader br = new BufferedReader(new InputStreamReader(in));
+            br = new BufferedReader(new InputStreamReader(new FileInputStream(queryListFile), "UTF-8"));
             String strLine;
             String queryFileName;
             File queryFile;
@@ -235,14 +213,17 @@
                     output.add(new Object[] { queryFileName, expectedFileName, actualFileName });
                 }
             }
-            in.close();
         } catch (IOException e) {
             e.printStackTrace();
+        } finally {
+            if (br != null) {
+                br.close();
+            }
         }
     }
 
     @Parameters
-    public static Collection<Object[]> tests() {
+    public static Collection<Object[]> tests() throws IOException {
         Collection<Object[]> testArgs = new ArrayList<Object[]>();
         prepareQuerySuite(QUERIES_FILE, TEST_QUERIES_PATH, null, null, testArgs);
         return testArgs;
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/optimizer/OptimizerTest.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/optimizer/OptimizerTest.java
index 4c6e301..7e0ff86 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/optimizer/OptimizerTest.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/optimizer/OptimizerTest.java
@@ -2,7 +2,9 @@
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileReader;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.Reader;
 import java.util.ArrayList;
@@ -120,8 +122,7 @@
             Assume.assumeTrue(!skipped);
 
             LOGGER.severe("RUN TEST: \"" + queryFile.getPath() + "\"");
-
-            Reader query = new BufferedReader(new FileReader(queryFile));
+            Reader query = new BufferedReader(new InputStreamReader(new FileInputStream(queryFile), "UTF-8"));
             PrintWriter plan = new PrintWriter(actualFile);
             AsterixJavaClient asterix = new AsterixJavaClient(
                     AsterixHyracksIntegrationUtil.getHyracksClientConnection(), query, plan);
@@ -135,8 +136,10 @@
             plan.close();
             query.close();
 
-            BufferedReader readerExpected = new BufferedReader(new FileReader(expectedFile));
-            BufferedReader readerActual = new BufferedReader(new FileReader(actualFile));
+            BufferedReader readerExpected = new BufferedReader(new InputStreamReader(new FileInputStream(expectedFile),
+                    "UTF-8"));
+            BufferedReader readerActual = new BufferedReader(new InputStreamReader(new FileInputStream(actualFile),
+                    "UTF-8"));
 
             String lineExpected, lineActual;
             int num = 1;
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/runtime/RuntimeTest.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/runtime/RuntimeTest.java
index 1d39109..aefea0e 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/runtime/RuntimeTest.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/runtime/RuntimeTest.java
@@ -2,9 +2,10 @@
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -51,7 +52,7 @@
         ArrayList<String> list = new ArrayList<String>();
         BufferedReader result;
         try {
-            result = new BufferedReader(new FileReader(PATH_BASE + fileName));
+            result = new BufferedReader(new InputStreamReader(new FileInputStream(PATH_BASE + fileName), "UTF-8"));
             while (true) {
                 String line = result.readLine();
                 if (line == null) {