@Test public void testMergeAs_jsonxml_FileHandle() throws Exception { gmWriter.setDefaultMimetype(RDFMimeTypes.RDFJSON); File file = new File(datasource + "bug25348.json"); FileInputStream fis = new FileInputStream(file); Object graphData = convertInputStreamToString(fis); fis.close(); gmWriter.writeAs("htp://test.sem.graph/jsonMergeAs", graphData); gmWriter.setDefaultMimetype(RDFMimeTypes.TRIPLEXML); File file2 = new File(datasource + "relative5.xml"); Object graphData2 = convertFileToString(file2); gmWriter.mergeAs("htp://test.sem.graph/jsonMergeAs", graphData2); File readFile = gmWriter.readAs("htp://test.sem.graph/jsonMergeAs", File.class); String expectedContent = convertFileToString(readFile); assertTrue("Did not insert document or inserted empty doc", expectedContent.contains("http://example.com/ns/person#firstName") && expectedContent.contains("Anna's Homepage")); }
@Test public void testReadAs_WriteAs() throws Exception { File file = new File(datasource + "semantics.nt"); FileHandle filehandle = new FileHandle(); filehandle.set(file); gmWriter.writeAs("htp://test.sem.graph/ntAs", filehandle.withMimetype(RDFMimeTypes.NTRIPLES)); File read = gmWriter.readAs("htp://test.sem.graph/ntAs", File.class); String expectedContent = convertFileToString(read); assertTrue("writeAs & readAs test did not return expected content", expectedContent.contains("http://www.w3.org/2001/sw/RDFCore/ntriples/")); }
@Test public void B_testWritePermission() throws Exception { // a negative test to ensure a user without update privilege can't write try { GraphManager readPrivilegedGmgr = readPrivilegedClient.newGraphManager(); readPrivilegedGmgr.writeAs(graphUri, new StringHandle("").withMimetype(RDFMimeTypes.NTRIPLES)); fail("User read-privileged should see ForbiddenUserException when trying to write"); } catch (ForbiddenUserException e) { // passed negative test } }
@Test public void testMergeAs_jsonxml_Trx_FileHandle() throws Exception { Transaction trx = writerClient.openTransaction(); GraphManager gmWriter = writerClient.newGraphManager(); gmWriter.setDefaultMimetype(RDFMimeTypes.RDFJSON); File file = new File(datasource + "bug25348.json"); FileInputStream fis = new FileInputStream(file); Object graphData = convertInputStreamToString(fis); fis.close(); gmWriter.writeAs("htp://test.sem.graph/jsonMergeAsTrx", graphData, trx); File file2 = new File(datasource + "relative6.json"); Object graphData2 = convertFileToString(file2); gmWriter.mergeAs("htp://test.sem.graph/jsonMergeAsTrx", graphData2, trx); File readFile = gmWriter.readAs("htp://test.sem.graph/jsonMergeAsTrx", File.class, trx); String expectedContent = convertFileToString(readFile); assertTrue("Did not insert document or inserted empty doc", expectedContent.contains("http://example.com/ns/person#firstName") && expectedContent.contains("Anna's Homepage")); try { trx.commit(); trx = null; } catch (Exception e) { System.out.println(e); } finally { if (trx != null) { trx.rollback(); trx = null; } } }
gmgr.writeAs(localGraphUri, triple1);
filehandle.set(file); gmWriter.writeAs("htp://test.sem.graph/ttlas", filehandle.withMimetype(RDFMimeTypes.TURTLE), trx);
assertEquals(ntriple5 + "\n" + ntriple6 + "\n" + ntriple7, triples5and6and7.get()); gmgr.writeAs(tripleGraphUri, ntriple7); String triples7 = gmgr.readAs(tripleGraphUri, String.class); assertEquals(ntriple7, triples7);