@Test public void A_testReadPemission() throws Exception { // a negative test to ensure a user without read privilege can't read try { GraphManager writePrivilegedGmgr = writePrivilegedClient.newGraphManager(); writePrivilegedGmgr.readAs(graphUri, String.class); fail("User write-privileged should see ForbiddenUserException when trying to read"); } catch (ResourceNotFoundException e) { // passed negative test } }
@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 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; } } }
File readFile = gmWriter.readAs("htp://test.sem.graph/ttlas", File.class, trx); String expectedContent = convertFileToString(readFile); assertTrue("Did not insert document or inserted empty doc", expectedContent.contains("http://www.w3.org/2004/02/skos/core#Concept")); String readContent = gmWriter.readAs("htp://test.sem.graph/ttlas", String.class, trx); trx.commit(); trx = null;
String triples5and6 = gmgr.readAs(tripleGraphUri, String.class); String expected = ntriple5 + "\n" + ntriple6; assertEquals(expected, triples5and6); String triples7 = gmgr.readAs(tripleGraphUri, String.class); assertEquals(ntriple7, triples7); String triples7and8 = gmgr.readAs(tripleGraphUri, String.class); assertEquals(ntriple7 + "\n" + ntriple8, triples7and8);
@Test public void testQuads() throws Exception { gmgr.setDefaultMimetype(RDFMimeTypes.NQUADS); String quadGraphUri = "GraphsTest.testQuads"; String quad1 = "<http://example.org/s1> <http://example.org/p1> <http://example.org/o1> <" + quadGraphUri + "> ."; String quad2 = "<http://example.org/s2> <http://example.org/p2> <http://example.org/o2> <" + quadGraphUri + "> ."; String quad3 = "<http://example.org/s3> <http://example.org/p2> <http://example.org/o2> <" + quadGraphUri + "> ."; String quad4 = "<http://example.org/s4> <http://example.org/p2> <http://example.org/o2> <" + quadGraphUri + "> ."; gmgr.replaceGraphs(new StringHandle(quad1)); StringHandle quadsHandle = gmgr.read(quadGraphUri, new StringHandle()); assertEquals(quad1, quadsHandle.get()); gmgr.mergeGraphs(new StringHandle(quad2)); StringHandle quads1and2 = gmgr.read(quadGraphUri, new StringHandle()); assertEquals(quad1 + "\n" + quad2, quads1and2.get()); gmgr.replaceGraphsAs(quad3); quadsHandle = gmgr.read(quadGraphUri, new StringHandle()); assertEquals(quad3, quadsHandle.get()); gmgr.mergeGraphsAs(quad4); String quads3and4 = gmgr.readAs(quadGraphUri, String.class); assertEquals(quad3 + "\n" + quad4, quads3and4); gmgr.delete(quadGraphUri); }
assertEquals(quad3 + "\n" + quad4, gmgr.readAs(quadGraphUri, String.class, tx));
tx = null; String mergedGraph = graphManagerWriter.readAs("newGraph", String.class); assertEquals(t1 + "\n" + t2, mergedGraph);