Fix some tests and add jsonld to Live Service Demo.
authordev <julio.caguanob@gmail.com>
Mon, 7 May 2018 06:05:39 +0000 (01:05 -0500)
committerdev <julio.caguanob@gmail.com>
Mon, 7 May 2018 06:05:39 +0000 (01:05 -0500)
core/src/main/java/org/apache/any23/writer/JSONWriter.java
core/src/test/java/org/apache/any23/writer/JSONWriterTest.java
service/src/main/resources/form.html
service/src/test/java/org/apache/any23/servlet/ServletTest.java

index d274871..70e2700 100644 (file)
@@ -176,7 +176,10 @@ public class JSONWriter implements FormatWriter {
     }
 
     private void printValue(String type, String value) throws IOException {
-        ps.writeString(value);
+        ps.writeStartObject();
+        ps.writeStringField("type", type);
+        ps.writeStringField("value", value);
+        ps.writeEndObject();
     }
 
     private void printValue(String value) throws IOException {
index 93d0558..f6cdfeb 100644 (file)
@@ -37,30 +37,32 @@ public class JSONWriterTest {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         writeContent(new JSONWriter(baos));
 
-        final String expected
-                = "{ "
-                + "\"quads\" : "
-                + "["
-                + "["
-                + "{ \"type\" : \"bnode\", \"value\" : \"bn1\"}, "
-                + "\"http://pred/1\", "
-                + "{ \"type\" : \"uri\", \"value\" : \"http://value/1\"}, "
-                + "\"http://graph/1\""
-                + "], "
-                + "["
-                + "{ \"type\" : \"uri\", \"value\" : \"http://sub/2\"}, "
-                + "\"http://pred/2\", "
-                + "{\"type\" : \"literal\", \"value\" : \"language literal\", \"lang\" : \"en\", \"datatype\" : \"http://www.w3.org/1999/02/22-rdf-syntax-ns#langString\"}, "
-                + "\"http://graph/2\""
-                + "], "
-                + "["
-                + "{ \"type\" : \"uri\", \"value\" : \"http://sub/3\"}, "
-                + "\"http://pred/3\", "
-                + "{\"type\" : \"literal\", \"value\" : \"123\", \"lang\" : null, \"datatype\" : \"http://datatype\"}, "
-                + "null"
-                + "]"
-                + "]"
-                + "}";
+        final String expected 
+            = "{\n"
+            + "  \"quads\" : [ [ {\n"
+            + "    \"type\" : \"bnode\",\n"
+            + "    \"value\" : \"bn1\"\n"
+            + "  }, \"http://pred/1\", {\n"
+            + "    \"type\" : \"uri\",\n"
+            + "    \"value\" : \"http://value/1\"\n"
+            + "  }, \"http://graph/1\" ], [ {\n"
+            + "    \"type\" : \"uri\",\n"
+            + "    \"value\" : \"http://sub/2\"\n"
+            + "  }, \"http://pred/2\", {\n"
+            + "    \"type\" : \"literal\",\n"
+            + "    \"value\" : \"language literal\",\n"
+            + "    \"lang\" : \"en\",\n"
+            + "    \"datatype\" : \"http://www.w3.org/1999/02/22-rdf-syntax-ns#langString\"\n"
+            + "  }, \"http://graph/2\" ], [ {\n"
+            + "    \"type\" : \"uri\",\n"
+            + "    \"value\" : \"http://sub/3\"\n"
+            + "  }, \"http://pred/3\", {\n"
+            + "    \"type\" : \"literal\",\n"
+            + "    \"value\" : \"123\",\n"
+            + "    \"lang\" : null,\n"
+            + "    \"datatype\" : \"http://datatype\"\n"
+            + "  }, null ] ]\n"
+            + "}";
         Assert.assertEquals(expected, baos.toString());
     }
 
index a5cf937..7cac3e4 100644 (file)
@@ -76,6 +76,7 @@ function showModal( id )
             <option value="nquads">nquads</option>
             <option value="trix">trix</option>
             <option value="json">json</option>
+            <option value="jsonld">json-ld</option>
           </select>/<input type="text" size="50" name="uri" value="http://twitter.com/cygri" />
         </div>
       </div>
@@ -154,6 +155,7 @@ function showModal( id )
             <option value="nquads">nquads</option>
             <option value="trix">trix</option>
             <option value="json">json</option>
+            <option value="jsonld">json-ld</option>
           </select>
         </div>
       </div>
@@ -317,6 +319,7 @@ Content-Length: 174
       <li><code>rdfxml</code>, <code>rdf</code>, <code>xml</code> for
         <a href="http://www.w3.org/TR/rdf-syntax-grammar/" target="_blank">RDF/XML</a></li>
       <li><code>json</code> for <a href="http://json.org/" target="_blank">JSON</a></li>
+      <li><code>jsonld</code> for <a href="https://json-ld.org/" target="_blank">JSON-LD</a></li>
     </ul>
 
     <h3>Error reporting</h3>
index 1f7044f..3d14f98 100644 (file)
@@ -399,12 +399,15 @@ public class ServletTest {
         HttpTester response = doPostRequest("/json", body, "application/n-quads");
         Assert.assertEquals(200, response.getStatus());
         final String EXPECTED_JSON
-                = "["
-                + "{ \"type\" : \"uri\", \"value\" : \"http://sub/1\"}, "
-                + "\"http://pred/1\", "
-                + "{\"type\" : \"literal\", \"value\" : \"123\", \"lang\" : null, \"datatype\" : \"http://datatype\"}, "
-                + "\"http://graph/1\""
-                + "]";
+            = "[ {\n"
+            + "    \"type\" : \"uri\",\n"
+            + "    \"value\" : \"http://sub/1\"\n"
+            + "  }, \"http://pred/1\", {\n"
+            + "    \"type\" : \"literal\",\n"
+            + "    \"value\" : \"123\",\n"
+            + "    \"lang\" : null,\n"
+            + "    \"datatype\" : \"http://datatype\"\n"
+            + "  }, \"http://graph/1\" ]";
         assertContains(EXPECTED_JSON, response.getContent());
     }