1. John Marsden
  2. JSONStat

Commits

John Marsden  committed 7a14f73

Output the results to a json file.

  • Participants
  • Parent commits 512bf64
  • Branches default

Comments (0)

Files changed (2)

File src/main/java/cc/plural/json/JSONTestRunner.java

View file
  • Ignore whitespace
     public static void main(String[] args) {
         // Library Classes
         Class[] libraryClasses = new Class[]{
-                /*GSONLibrary.class, JSONDotOrgLibrary.class, JSONSimpleLibrary.class,*/
+                GSONLibrary.class, JSONDotOrgLibrary.class, JSONSimpleLibrary.class,
                 JSONSmartLibrary.class, JSONiJLibrary.class,  JacksonLibrary.class};
         JSONLibrarySet<JSONLibrary> jsonLibrarySet = new JSONLibrarySet<JSONLibrary>();
         try {
         // Set up all tests into the suite
         JSONTestSuite<JSONTestSet<JSONTest>> jsonTestSuite = new JSONTestSuite<JSONTestSet<JSONTest>>();
         jsonTestSuite.add(new StrictRFC4627ParsingJSONTestSet<JSONTest>());
-        //jsonTestSuite.add(new StrictRFC4627WhiteSpaceParsingJSONTestSet<JSONTest>());
-        //jsonTestSuite.add(new StrictRFC4627ErrorConditions<JSONTest>());
-        //jsonTestSuite.add(new StrictRFDC4627RealExamples<JSONTest>());
+        jsonTestSuite.add(new StrictRFC4627WhiteSpaceParsingJSONTestSet<JSONTest>());
+        jsonTestSuite.add(new StrictRFC4627ErrorConditions<JSONTest>());
+        jsonTestSuite.add(new StrictRFDC4627RealExamples<JSONTest>());
         jsonTestSuite.primeAllTestSets();
 
         List<JSONTestSuiteResult<JSONTestSetResult<JSONTestResult>>> testResultsList = new ArrayList<JSONTestSuiteResult<JSONTestSetResult<JSONTestResult>>>();
         //consoleDumpOutput.setTestResultsList(testResultsList);
         //consoleDumpOutput.generateOutput();
 
-        JSONOutput jsonOutput = new JSONOutput(new File("temp.txt"), jsonTestSuite);
+        JSONOutput jsonOutput = new JSONOutput(new File("results.json"), jsonTestSuite);
         jsonOutput.setJsonLibrarySet(jsonLibrarySet);
         jsonOutput.setTestResultsList(testResultsList);
         jsonOutput.generateOutput();

File src/main/java/cc/plural/json/output/JSONOutput.java

View file
  • Ignore whitespace
  * See the License for the specific language governing permissions and
  * limitations under the License.
  **/
-
 package cc.plural.json.output;
 
 import cc.plural.json.JSONLibrary;
 import cc.plural.json.JSONTestSetResult;
 import cc.plural.json.JSONTestSuite;
 import cc.plural.json.JSONTestSuiteResult;
+import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileWriter;
 import java.util.List;
 import jsonij.json.JSON;
 import jsonij.json.JSONMarshaler;
-import jsonij.json.Value;
 
 /**
  *
     File outputFile;
     JSONLibrarySet<JSONLibrary> jsonLibrarySet;
     JSONTestSuite<JSONTestSet<JSONTest>> jsonTestSuite;
-
     List<JSONTestSuiteResult<JSONTestSetResult<JSONTestResult>>> testResultsList;
 
     public JSONOutput(File outputFile, JSONTestSuite<JSONTestSet<JSONTest>> jsonTestSuite) {
     }
 
     public void generateOutput() {
-        if(outputFile == null || jsonLibrarySet == null || testResultsList == null) {
+        if (outputFile == null || jsonLibrarySet == null || testResultsList == null) {
             // TODO: throw an exception
             return;
         }
 
         JSON results = JSONMarshaler.marshalObject(testResultsList);
         System.out.println(results.toJSON());
-        
+
+        try {
+            // Create file
+            FileWriter fstream = new FileWriter(outputFile);
+            BufferedWriter out = new BufferedWriter(fstream);
+            out.write(results.toJSON());
+            //Close the output stream
+            out.close();
+        } catch (Exception e) {//Catch exception if any
+            System.err.println("Error: " + e.getMessage());
+        }
     }
+
 }