Fix some tests and add jsonld to Live Service Demo. Project: http://git-wip-us.apache.org/repos/asf/any23/repo Commit: http://git-wip-us.apache.org/repos/asf/any23/commit/b4e50050 Tree: http://git-wip-us.apache.org/repos/asf/any23/tree/b4e50050 Diff: http://git-wip-us.apache.org/repos/asf/any23/diff/b4e50050
Branch: refs/heads/master Commit: b4e50050c885487465af184e7073f3a879db2453 Parents: ff4ad70 Author: dev <[email protected]> Authored: Mon May 7 01:05:39 2018 -0500 Committer: dev <[email protected]> Committed: Mon May 7 01:05:39 2018 -0500 ---------------------------------------------------------------------- .../org/apache/any23/writer/JSONWriter.java | 5 +- .../org/apache/any23/writer/JSONWriterTest.java | 50 ++++++++++---------- service/src/main/resources/form.html | 3 ++ .../org/apache/any23/servlet/ServletTest.java | 15 +++--- 4 files changed, 42 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/any23/blob/b4e50050/core/src/main/java/org/apache/any23/writer/JSONWriter.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/any23/writer/JSONWriter.java b/core/src/main/java/org/apache/any23/writer/JSONWriter.java index d274871..70e2700 100644 --- a/core/src/main/java/org/apache/any23/writer/JSONWriter.java +++ b/core/src/main/java/org/apache/any23/writer/JSONWriter.java @@ -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 { http://git-wip-us.apache.org/repos/asf/any23/blob/b4e50050/core/src/test/java/org/apache/any23/writer/JSONWriterTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/any23/writer/JSONWriterTest.java b/core/src/test/java/org/apache/any23/writer/JSONWriterTest.java index 93d0558..f6cdfeb 100644 --- a/core/src/test/java/org/apache/any23/writer/JSONWriterTest.java +++ b/core/src/test/java/org/apache/any23/writer/JSONWriterTest.java @@ -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()); } http://git-wip-us.apache.org/repos/asf/any23/blob/b4e50050/service/src/main/resources/form.html ---------------------------------------------------------------------- diff --git a/service/src/main/resources/form.html b/service/src/main/resources/form.html index a5cf937..7cac3e4 100644 --- a/service/src/main/resources/form.html +++ b/service/src/main/resources/form.html @@ -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> http://git-wip-us.apache.org/repos/asf/any23/blob/b4e50050/service/src/test/java/org/apache/any23/servlet/ServletTest.java ---------------------------------------------------------------------- diff --git a/service/src/test/java/org/apache/any23/servlet/ServletTest.java b/service/src/test/java/org/apache/any23/servlet/ServletTest.java index 1f7044f..3d14f98 100644 --- a/service/src/test/java/org/apache/any23/servlet/ServletTest.java +++ b/service/src/test/java/org/apache/any23/servlet/ServletTest.java @@ -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()); }
