Commits

John Marsden  committed c63939e

Upload New Output Source

  • Participants
  • Parent commits d3dea85

Comments (0)

Files changed (9)

         <dependency>
             <groupId>cc.plural</groupId>
             <artifactId>jsonij</artifactId>
-            <version>0.2.6</version>
+            <version>0.2.7-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.json</groupId>

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

     protected String description;
     protected String input;
     protected String output;
-    
+
     public JSONTest() {
         description = null;
     }
-    
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getInput() {
+        return input;
+    }
+
+    public void setInput(String input) {
+        this.input = input;
+    }
+
+    public String getOutput() {
+        return output;
+    }
+
+    public void setOutput(String output) {
+        this.output = output;
+    }
+
     public JSONTestResult createRestResult() {
         return new JSONTestResult(this);
     }
-    
+
     public abstract void evaluate(JSONLibrary jsonPackage, JSONTestResult jsonResult) throws JSONTestException;
-    
+
     public abstract boolean testPassed(JSONTestResult jsonResult);
 
     @Override
         output.append(description).append(" (").append(JSONStatUtils.addEscapesToString(input)).append(')');
         return output.toString();
     }
-    
-    
 }

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

  **/
 package cc.plural.json;
 
-import java.math.BigDecimal;
+import jsonij.json.annotation.JSONIgnore;
 
 /**
  *
 public class JSONTestResult {
 
     public enum RESULT {
+
         PASS("Pass"),
         FAIL("Fail"),
         ERROR("Exception"),
         HANG("Hang");
         private final String name;
-        RESULT(String name) { this.name = name; }
-        public String getName() { return name; }
+
+        RESULT(String name) {
+            this.name = name;
+        }
+
+        public String getName() {
+            return name;
+        }
     }
-    
     protected String description;
-
     protected String input;
-
     protected JSONLibrary jsonPackage;
-
     protected JSONTestSet testSet;
-    
     protected JSONTest test;
-
     protected String output;
-    
     protected Exception exception;
-    
     protected RESULT result;
-    
     protected long executionTimeAverage;
 
     public JSONTestResult(JSONTest test) {
     public void setTest(JSONTest test) {
         this.test = test;
     }
-
+    @JSONIgnore
     public JSONTestSet getTestSet() {
         return testSet;
     }
-
+    
+    @JSONIgnore
     public void setTestSet(JSONTestSet testSet) {
         this.testSet = testSet;
     }
 
+    public Exception getException() {
+        return exception;
+    }
+
+    public void setException(Exception exception) {
+        this.exception = exception;
+    }
+
+    public RESULT getResult() {
+        return result;
+    }
+
+    public void setResult(RESULT result) {
+        this.result = result;
+    }
+
+    public String getInput() {
+        return input;
+    }
+
+    public void setInput(String input) {
+        this.input = input;
+    }
+
     public long getExecutionTimeAverage() {
         return executionTimeAverage;
     }
 
     @Override
     public String toString() {
-        return "" + jsonPackage.getName() + " [" + description + "| input='" + JSONStatUtils.addEscapesToString(input) + "' output='" + JSONStatUtils.addEscapesToString(output) + "' result='" + result.getName() + "'" + ((result==RESULT.ERROR) ? " error='" + exception.getCause().toString() + "'" : "") + "] in " + (double)executionTimeAverage/1000000D + "ms (avg. over 100 runs)";
+        return "" + jsonPackage.getName() + " [" + description + "| input='" + JSONStatUtils.addEscapesToString(input) + "' output='" + JSONStatUtils.addEscapesToString(output) + "' result='" + result.getName() + "'" + ((result == RESULT.ERROR) ? " error='" + exception.getCause().toString() + "'" : "") + "] in " + (double) executionTimeAverage / 1000000D + "ms (avg. over 100 runs)";
     }
 }

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

  **/
 package cc.plural.json;
 
-import cc.plural.json.JSONTestResult.RESULT;
 import cc.plural.json.library.GSONLibrary;
 import cc.plural.json.library.JSONDotOrgLibrary;
 import cc.plural.json.library.JSONSimpleLibrary;
 import cc.plural.json.library.JSONSmartLibrary;
 import cc.plural.json.library.JSONiJLibrary;
 import cc.plural.json.library.JacksonLibrary;
+import cc.plural.json.output.ConsoleDumpOutput;
+import cc.plural.json.output.JSONOutput;
 import cc.plural.json.test.StrictRFC4627ErrorConditions;
 import cc.plural.json.test.StrictRFC4627ParsingJSONTestSet;
 import cc.plural.json.test.StrictRFC4627WhiteSpaceParsingJSONTestSet;
 import cc.plural.json.test.StrictRFDC4627RealExamples;
-import java.text.DecimalFormat;
+import java.io.File;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
     public static void main(String[] args) {
         // Library Classes
-        Class[] libraryClasses = new Class[]{GSONLibrary.class, JSONDotOrgLibrary.class, JSONSimpleLibrary.class,
+        Class[] libraryClasses = new 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>>>();
             testResultsList.add(jsonTestSuite.runTestSuite(librarySetIterator.next()));
         }
 
+        //ConsoleDumpOutput consoleDumpOutput = new ConsoleDumpOutput(jsonTestSuite);
+        //consoleDumpOutput.setJsonLibrarySet(jsonLibrarySet);
+        //consoleDumpOutput.setTestResultsList(testResultsList);
+        //consoleDumpOutput.generateOutput();
+
+        JSONOutput jsonOutput = new JSONOutput(new File("temp.txt"), jsonTestSuite);
+        jsonOutput.setJsonLibrarySet(jsonLibrarySet);
+        jsonOutput.setTestResultsList(testResultsList);
+        jsonOutput.generateOutput();
+
         
-        System.out.println(testResultsList.toString());
-        System.out.println();
-        System.out.println();
-        
-        StringBuilder output = new StringBuilder();
-        output.append('\t');
-        output.append('\t');
-        output.append('\t');
-        for (int k = 0; k < jsonLibrarySet.size(); k++) {
-            JSONLibrary jsonLibrary = jsonLibrarySet.get(k);
-            output.append(jsonLibrary.getName()).append('(').append(jsonLibrary.getVersion()).append(')');
-            output.append('\t');
-        }
-        output.append("\r\n");
-
-        DecimalFormat decimalFormat = new DecimalFormat("##.#####");
-
-        for (int i = 0; i < jsonTestSuite.getTestSetCount(); i++) {
-            JSONTestSet<JSONTest> testSet = jsonTestSuite.get(i);
-            for (int j = 0; j < testSet.testCount(); j++) {
-                JSONTest test = testSet.get(j);
-                output.append(testSet.getName()).append('\t');
-                output.append(test.description).append('\t');
-                output.append(JSONStatUtils.addEscapesToString(test.input)).append('\t');
-                for (int k = 0; k < jsonLibrarySet.size(); k++) {
-                    JSONLibrary jsonLibrary = jsonLibrarySet.get(k);
-                    // Get the test Result
-                    JSONTestSuiteResult<JSONTestSetResult<JSONTestResult>> currentSuite = testResultsList.get(k);
-                    JSONTestSetResult<JSONTestResult> currentTest = currentSuite.get(i);
-                    JSONTestResult result = currentTest.get(j);
-
-                    output.append(((result.result == RESULT.ERROR || result.result == RESULT.FAIL) ? result.result.getName() : decimalFormat.format(result.executionTimeAverage/1000000D))).append('\t');
-                }
-                output.append("\r\n");
-            }
-        }
-
-        System.out.println(output);
     }
 }

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

 
 import java.util.ArrayList;
 import java.util.Iterator;
+import jsonij.json.annotation.JSONIgnore;
 
 /**
  *
         this.testSet = testSet;
     }
 
+    @JSONIgnore
     public JSONTestSet getTestSet() {
         return testSet;
     }
 
+    @JSONIgnore
     public void setTestSet(JSONTestSet testSet) {
         this.testSet = testSet;
     }
 
+    @JSONIgnore
     public JSONLibrary getTestLibrary() {
         return testLibrary;
     }
 
+    @JSONIgnore
     public void setTestLibrary(JSONLibrary testLibrary) {
         this.testLibrary = testLibrary;
     }

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

 
 import java.util.ArrayList;
 import java.util.Iterator;
+import jsonij.json.annotation.JSONIgnore;
 
 /**
  *
         this.testLibrary = testLibrary;
     }
 
+    @JSONIgnore
     public JSONTestSuite getTestSuite() {
         return testSuite;
     }
-
+    
+    @JSONIgnore
     public void setTestSuite(JSONTestSuite testSuite) {
         this.testSuite = testSuite;
     }
 
+    @JSONIgnore
     public JSONLibrary getTestLibrary() {
         return testLibrary;
     }
 
+    @JSONIgnore
     public void setTestLibrary(JSONLibrary testLibrary) {
         this.testLibrary = testLibrary;
     }

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

+/**
+ * Copyright (C) 2010-2011 J.W.Marsden
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 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.JSONLibrarySet;
+import cc.plural.json.JSONStatUtils;
+import cc.plural.json.JSONTest;
+import cc.plural.json.JSONTestResult;
+import cc.plural.json.JSONTestResult.RESULT;
+import cc.plural.json.JSONTestSet;
+import cc.plural.json.JSONTestSetResult;
+import cc.plural.json.JSONTestSuite;
+import cc.plural.json.JSONTestSuiteResult;
+import java.io.File;
+import java.text.DecimalFormat;
+import java.util.List;
+
+/**
+ *
+ * @author jmarsden
+ */
+public class ConsoleDumpOutput {
+
+    JSONLibrarySet<JSONLibrary> jsonLibrarySet;
+    JSONTestSuite<JSONTestSet<JSONTest>> jsonTestSuite;
+
+    List<JSONTestSuiteResult<JSONTestSetResult<JSONTestResult>>> testResultsList;
+
+    public ConsoleDumpOutput(JSONTestSuite<JSONTestSet<JSONTest>> jsonTestSuite) {
+        this.jsonTestSuite = jsonTestSuite;
+    }
+
+    public JSONLibrarySet<JSONLibrary> getJsonLibrarySet() {
+        return jsonLibrarySet;
+    }
+
+    public void setJsonLibrarySet(JSONLibrarySet<JSONLibrary> jsonLibrarySet) {
+        this.jsonLibrarySet = jsonLibrarySet;
+    }
+
+    public List<JSONTestSuiteResult<JSONTestSetResult<JSONTestResult>>> getTestResultsList() {
+        return testResultsList;
+    }
+
+    public void setTestResultsList(List<JSONTestSuiteResult<JSONTestSetResult<JSONTestResult>>> testResultsList) {
+        this.testResultsList = testResultsList;
+    }
+
+    public void generateOutput() {
+        if(jsonLibrarySet == null || testResultsList == null) {
+            // TODO: throw an exception
+            return;
+        }
+
+        System.out.println(testResultsList.toString());
+        System.out.println();
+        System.out.println();
+
+        StringBuilder output = new StringBuilder();
+        output.append('\t');
+        output.append('\t');
+        output.append('\t');
+        for (int k = 0; k < jsonLibrarySet.size(); k++) {
+            JSONLibrary jsonLibrary = jsonLibrarySet.get(k);
+            output.append(jsonLibrary.getName()).append('(').append(jsonLibrary.getVersion()).append(')');
+            output.append('\t');
+        }
+        output.append("\r\n");
+
+        DecimalFormat decimalFormat = new DecimalFormat("##.#####");
+
+        for (int i = 0; i < jsonTestSuite.getTestSetCount(); i++) {
+            JSONTestSet<JSONTest> testSet = jsonTestSuite.get(i);
+            for (int j = 0; j < testSet.testCount(); j++) {
+                JSONTest test = testSet.get(j);
+                output.append(testSet.getName()).append('\t');
+                output.append(test.getDescription()).append('\t');
+                output.append(JSONStatUtils.addEscapesToString(test.getInput())).append('\t');
+                for (int k = 0; k < jsonLibrarySet.size(); k++) {
+                    JSONLibrary jsonLibrary = jsonLibrarySet.get(k);
+                    // Get the test Result
+                    JSONTestSuiteResult<JSONTestSetResult<JSONTestResult>> currentSuite = testResultsList.get(k);
+                    JSONTestSetResult<JSONTestResult> currentTest = currentSuite.get(i);
+                    JSONTestResult result = currentTest.get(j);
+
+                    output.append(((result.getResult() == RESULT.ERROR || result.getResult() == RESULT.FAIL) ? result.getResult().getName() : decimalFormat.format(result.getExecutionTimeAverage()/1000000D))).append('\t');
+                }
+                output.append("\r\n");
+            }
+        }
+
+        System.out.println(output);
+
+    }
+}

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

+/**
+ * Copyright (C) 2010-2011 J.W.Marsden
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 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.JSONLibrarySet;
+import cc.plural.json.JSONTest;
+import cc.plural.json.JSONTestResult;
+import cc.plural.json.JSONTestSet;
+import cc.plural.json.JSONTestSetResult;
+import cc.plural.json.JSONTestSuite;
+import cc.plural.json.JSONTestSuiteResult;
+import java.io.File;
+import java.util.List;
+import jsonij.json.JSON;
+import jsonij.json.JSONMarshaler;
+import jsonij.json.Value;
+
+/**
+ *
+ * @author jmarsden
+ */
+public class JSONOutput {
+
+    File outputFile;
+    JSONLibrarySet<JSONLibrary> jsonLibrarySet;
+    JSONTestSuite<JSONTestSet<JSONTest>> jsonTestSuite;
+
+    List<JSONTestSuiteResult<JSONTestSetResult<JSONTestResult>>> testResultsList;
+
+    public JSONOutput(File outputFile, JSONTestSuite<JSONTestSet<JSONTest>> jsonTestSuite) {
+        this.outputFile = outputFile;
+        this.jsonTestSuite = jsonTestSuite;
+    }
+
+    public JSONLibrarySet<JSONLibrary> getJsonLibrarySet() {
+        return jsonLibrarySet;
+    }
+
+    public void setJsonLibrarySet(JSONLibrarySet<JSONLibrary> jsonLibrarySet) {
+        this.jsonLibrarySet = jsonLibrarySet;
+    }
+
+    public File getOutputFile() {
+        return outputFile;
+    }
+
+    public void setOutputFile(File outputFile) {
+        this.outputFile = outputFile;
+    }
+
+    public List<JSONTestSuiteResult<JSONTestSetResult<JSONTestResult>>> getTestResultsList() {
+        return testResultsList;
+    }
+
+    public void setTestResultsList(List<JSONTestSuiteResult<JSONTestSetResult<JSONTestResult>>> testResultsList) {
+        this.testResultsList = testResultsList;
+    }
+
+    public void generateOutput() {
+        if(outputFile == null || jsonLibrarySet == null || testResultsList == null) {
+            // TODO: throw an exception
+            return;
+        }
+
+        JSON libraryInfo = JSONMarshaler.marshalObject(jsonLibrarySet);
+        System.out.println(libraryInfo.toJSON());
+
+        JSON results = JSONMarshaler.marshalObject(testResultsList);
+        System.out.println(results.toJSON());
+        
+    }
+}

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

+/**
+ * Copyright (C) 2010-2011 J.W.Marsden
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 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.JSONLibrarySet;
+import cc.plural.json.JSONStatUtils;
+import cc.plural.json.JSONTest;
+import cc.plural.json.JSONTestResult;
+import cc.plural.json.JSONTestResult.RESULT;
+import cc.plural.json.JSONTestSet;
+import cc.plural.json.JSONTestSetResult;
+import cc.plural.json.JSONTestSuite;
+import cc.plural.json.JSONTestSuiteResult;
+import java.io.File;
+import java.text.DecimalFormat;
+import java.util.List;
+
+/**
+ *
+ * @author jmarsden
+ */
+public class JavascriptObjectOutput {
+
+    File outputFile;
+    JSONLibrarySet<JSONLibrary> jsonLibrarySet;
+    JSONTestSuite<JSONTestSet<JSONTest>> jsonTestSuite;
+
+    List<JSONTestSuiteResult<JSONTestSetResult<JSONTestResult>>> testResultsList;
+
+    public JavascriptObjectOutput(File outputFile, JSONTestSuite<JSONTestSet<JSONTest>> jsonTestSuite) {
+        this.outputFile = outputFile;
+        this.jsonTestSuite = jsonTestSuite;
+    }
+
+    public JSONLibrarySet<JSONLibrary> getJsonLibrarySet() {
+        return jsonLibrarySet;
+    }
+
+    public void setJsonLibrarySet(JSONLibrarySet<JSONLibrary> jsonLibrarySet) {
+        this.jsonLibrarySet = jsonLibrarySet;
+    }
+
+    public File getOutputFile() {
+        return outputFile;
+    }
+
+    public void setOutputFile(File outputFile) {
+        this.outputFile = outputFile;
+    }
+
+    public List<JSONTestSuiteResult<JSONTestSetResult<JSONTestResult>>> getTestResultsList() {
+        return testResultsList;
+    }
+
+    public void setTestResultsList(List<JSONTestSuiteResult<JSONTestSetResult<JSONTestResult>>> testResultsList) {
+        this.testResultsList = testResultsList;
+    }
+
+    public void generateOutput() {
+        if(outputFile == null || jsonLibrarySet == null || testResultsList == null) {
+            // TODO: throw an exception
+            return;
+        }
+
+        StringBuilder packageInformationBuilder = new StringBuilder();
+
+        for (int k = 0; k < jsonLibrarySet.size(); k++) {
+            packageInformationBuilder.append('{');
+            JSONLibrary jsonLibrary = jsonLibrarySet.get(k);
+            packageInformationBuilder.append("'name':'").append(jsonLibrary.getName()).append('\'');
+
+            packageInformationBuilder.append('}');
+        }
+
+        /*
+        output.append("\r\n");
+
+        DecimalFormat decimalFormat = new DecimalFormat("##.#####");
+
+        for (int i = 0; i < jsonTestSuite.getTestSetCount(); i++) {
+            JSONTestSet<JSONTest> testSet = jsonTestSuite.get(i);
+            for (int j = 0; j < testSet.testCount(); j++) {
+                JSONTest test = testSet.get(j);
+                output.append(testSet.getName()).append('\t');
+                output.append(test.getDescription()).append('\t');
+                output.append(JSONStatUtils.addEscapesToString(test.getInput())).append('\t');
+                for (int k = 0; k < jsonLibrarySet.size(); k++) {
+                    JSONLibrary jsonLibrary = jsonLibrarySet.get(k);
+                    // Get the test Result
+                    JSONTestSuiteResult<JSONTestSetResult<JSONTestResult>> currentSuite = testResultsList.get(k);
+                    JSONTestSetResult<JSONTestResult> currentTest = currentSuite.get(i);
+                    JSONTestResult result = currentTest.get(j);
+
+                    output.append(((result.getResult() == RESULT.ERROR || result.getResult() == RESULT.FAIL) ? result.getResult().getName() : decimalFormat.format(result.getExecutionTimeAverage()/1000000D))).append('\t');
+                }
+                output.append("\r\n");
+            }
+        }
+
+        System.out.println(output);
+*/
+    }
+}