public JenaDatabaseClient(DatabaseClient client, boolean periodicFlush) { this.client = client; this.graphManager = client.newGraphManager(); this.graphManager.setDefaultMimetype(RDFMimeTypes.NTRIPLES); this.sparqlQueryManager = client.newSPARQLQueryManager(); if (periodicFlush) { this.writeBuffer = new TriplesWriteBuffer(this); this.deleteBuffer = new TriplesDeleteBuffer(this); this.timer = new Timer(); timer.schedule(writeBuffer, DEFAULT_INITIAL_DELAY, DEFAULT_CACHE_MILLIS); timer.schedule(deleteBuffer, DEFAULT_INITIAL_DELAY + 250, DEFAULT_CACHE_MILLIS); } }
@BeforeClass public static void beforeClass() { Common.connect(); gmgr = Common.client.newGraphManager(); }
public static void writeSPARQLDataFromString(String content, String graphName) throws KeyManagementException, NoSuchAlgorithmException, Exception { // Create Grapgh manager GraphManager sparqlGmgr = writeclient.newGraphManager(); StringHandle handle = new StringHandle(); handle.set(content.toString()); // write the triples in the doc into named graph sparqlGmgr.write(graphName, handle.withMimetype(RDFMimeTypes.TURTLE)); // Wait for index. Need a better way to handle this. try { Thread.sleep(5000); } catch (InterruptedException e) { System.out.print("Exception from writeSPARQLDataFromString " + e.getMessage()); e.printStackTrace(); } }
public static void writeNTriplesFromFile(String filename, String graphName) throws KeyManagementException, NoSuchAlgorithmException, Exception { File file = new File(datasource + filename); FileHandle filehandle = new FileHandle(); GraphManager sparqlGmgr = writeclient.newGraphManager(); filehandle.set(file); sparqlGmgr.write(graphName, filehandle.withMimetype(RDFMimeTypes.TURTLE)); }
@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 } }
GraphManager sparqlGmgr = client.newGraphManager(); if (uri != null) docId = uri + filename;
@AfterClass public static void afterClass() { GraphManager gmgr = Common.client.newGraphManager(); gmgr.delete(graphUri); readPrivilegedClient.release(); writePrivilegedClient.release(); }
@Test public void C_testGetPermissions() throws Exception { GraphManager readPrivilegedGmgr = readPrivilegedClient.newGraphManager(); GraphPermissions permissions = readPrivilegedGmgr.getPermissions(graphUri); assertEquals(6, permissions.size()); assertNotNull(permissions.get("read-privileged")); assertNotNull(permissions.get("write-privileged")); assertEquals(1, permissions.get("read-privileged").size()); assertEquals(1, permissions.get("write-privileged").size()); assertEquals(Capability.READ, permissions.get("read-privileged").iterator().next()); assertEquals(Capability.UPDATE, permissions.get("write-privileged").iterator().next()); }
@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 } }
@Before public void setUp() throws Exception { createUserRolesWithPrevilages("test-eval", "xdbc:eval", "xdbc:eval-in", "xdmp:eval-in", "any-uri", "xdbc:invoke"); createRESTUser("eval-user", "x", "test-eval", "rest-admin", "rest-writer", "rest-reader"); int restPort = getRestServerPort(); adminClient = getDatabaseClientOnDatabase(appServerHostname, restPort, dbName, "rest-admin", "x", getConnType()); writerClient = getDatabaseClientOnDatabase(appServerHostname, restPort, dbName, "rest-writer", "x", getConnType()); readerClient = getDatabaseClientOnDatabase(appServerHostname, restPort, dbName, "rest-reader", "x", getConnType()); gmWriter = writerClient.newGraphManager(); gmReader = readerClient.newGraphManager(); }
@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; } } }
@BeforeClass public static void beforeClass() { Common.connect(); gmgr = Common.client.newGraphManager(); String nTriples = triple1 + "\n" + triple2; gmgr.setDefaultMimetype(RDFMimeTypes.NTRIPLES); gmgr.write(graphUri, new StringHandle(nTriples)); smgr = Common.client.newSPARQLQueryManager(); }
@BeforeClass public static void beforeClass() { Common.connect(); gmgr = Common.client.newGraphManager(); gmgr.mergeGraphs(new StringHandle(TEST_TRIG) .withMimetype("text/trig")); smgr = Common.client.newSPARQLQueryManager(); }
@BeforeClass public static void beforeClass() { Common.connect(); gmgr = Common.client.newGraphManager(); String triple = "<s> <p> <o>."; GraphPermissions perms = gmgr.permission("read-privileged", Capability.READ) .permission("write-privileged", Capability.UPDATE); gmgr.write(graphUri, new StringHandle(triple).withMimetype(RDFMimeTypes.NTRIPLES), perms); }
@Test public void testWriteMergeDelete_Trx() throws Exception { Transaction trx = writerClient.openTransaction(); GraphManager gmWriter = writerClient.newGraphManager(); File file = new File(datasource + "triplexml1.xml"); gmWriter.write("htp://test.sem.graph/mergetrx", new FileHandle(file).withMimetype(RDFMimeTypes.TRIPLEXML), trx); file = new File(datasource + "bug25348.json"); gmWriter.merge("htp://test.sem.graph/mergetrx", new FileHandle(file).withMimetype(RDFMimeTypes.RDFJSON), trx); FileHandle handle = gmWriter.read("htp://test.sem.graph/mergetrx", new FileHandle(), trx); File readFile = handle.get(); String expectedContent = convertFileToString(readFile); try { assertTrue("Did not Merge document or inserted empty doc", expectedContent.contains("Michelle") && expectedContent.contains("Anna's Homepage")); gmWriter.delete("htp://test.sem.graph/mergetrx", trx); trx.commit(); trx = null; StringHandle readContent = gmWriter.read("htp://test.sem.graph/mergetrx", new StringHandle(), trx); assertTrue("Unexpected Content from read, expecting null", readContent == null); } catch (Exception e) { assertTrue("Unexpected Exception Thrown", e.toString().contains("ResourceNotFoundException")); } finally { if (trx != null) trx.commit(); trx = null; } }
@Test public void testWrite_triplexml_FileHandle() throws Exception { Transaction trx = writerClient.openTransaction(); GraphManager gmWriter = writerClient.newGraphManager(); File file = new File(datasource + "relative5.xml"); FileHandle filehandle = new FileHandle(); filehandle.set(file); // Write Graph using transaction gmWriter.write("htp://test.sem.graph/tripxml", filehandle.withMimetype(RDFMimeTypes.TRIPLEXML), trx); // Validate graph written to DB by reading within the same transaction StringHandle handle = gmWriter.read("htp://test.sem.graph/tripxml", new StringHandle().withMimetype(RDFMimeTypes.TRIPLEXML), trx); assertTrue("Did not insert document or inserted empty doc", handle.toString().contains("Anna's Homepage")); // Delete Graph in the same transaction gmWriter.delete("htp://test.sem.graph/tripxml", trx); // Validate Graph is deleted try { gmWriter.read("htp://test.sem.graph/tripxml", new StringHandle(), trx); trx.commit(); trx = null; } catch (ResourceNotFoundException e) { System.out.println(e); } finally { if (trx != null) { trx.rollback(); trx = null; } } }
@Test public void testWriteAs_ReadAs_FileHandle() throws Exception { Transaction trx = writerClient.openTransaction(); GraphManager gmWriter = writerClient.newGraphManager(); File file = new File(datasource + "semantics.ttl"); FileHandle filehandle = new FileHandle();
@AfterClass public static void afterClass() { Common.connect(); gmgr = Common.client.newGraphManager(); gmgr.delete(GraphManager.DEFAULT_GRAPH); gmgr.delete("http://marklogic.com/SPARQLQDefTest/g1"); gmgr.delete("http://marklogic.com/SPARQLQDefTest/g2"); gmgr.delete("http://marklogic.com/SPARQLQDefTest/g4"); gmgr.delete("http://marklogic.com/SPARQLQDefTest/g65"); gmgr.delete("http://marklogic.com/SPARQLQDefTest/o1"); gmgr.delete("http://marklogic.com/SPARQLQDefTest/o2"); gmgr.delete("http://marklogic.com/SPARQLQDefTest/o3"); gmgr.delete("http://marklogic.com/SPARQLQDefTest/o4"); }
GraphManager gmTestPerm = permUser.newGraphManager();
@Test public void testTransactions() { GraphManager graphManagerWriter = Common.client.newGraphManager(); graphManagerWriter.setDefaultMimetype(RDFMimeTypes.NTRIPLES); DatabaseClient readOnlyClient = Common.connectReadOnly();