DocWriter(DatabaseClient client, String id, String doc) throws KeyManagementException, NoSuchAlgorithmException, Exception { this.id = id; if (isResendable) this.resendableDoc = doc; else this.onetimeDoc = new ByteArrayInputStream(doc.getBytes("UTF-8")); docMgr = client.newTextDocumentManager(); }
@Test public void testNewTextDocument() { TextDocumentManager doc = Common.client.newTextDocumentManager(); assertNotNull("Client could not create text document", doc); }
@Test public void test_issue_623() { String uniqueDir = "BulkReadWriteTest_" + new Random().nextInt(10000) + "/"; List<String> uris = new ArrayList<>(); uris.add(uniqueDir + "test_with_ampersand.txt?a=b&c=d"); uris.add(uniqueDir + "test+with+plus.txt"); uris.add(uniqueDir + "test/with/forwardslash.txt"); uris.add(uniqueDir + "test.with.dot.txt"); uris.add(uniqueDir + "test_with!every@thing#else$*()-_[]:',~.txt"); uris.add(uniqueDir + "test_with;.txt"); test_issue_623_body( Common.client.newTextDocumentManager(), uris, "$0" ); test_issue_623_body( Common.client.newBinaryDocumentManager(), uris, "$0" ); test_issue_623_body( Common.client.newXMLDocumentManager(), uris, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xml>$0</xml>" ); test_issue_623_body( Common.client.newJSONDocumentManager(), uris, "[\"$0\"]" ); }
@SuppressWarnings("deprecation") @Test public void testUserPortal() throws Exception { final String query1 = "fn:count(fn:doc())"; InetAddress addr = java.net.InetAddress.getLocalHost(); System.out.println("Hostname is : " + addr.getHostName()); DatabaseClient client = DatabaseClientFactory.newClient(localHostname, port, new CertificateAuthContext(temp + "portal.p12", "abc")); int count = client.newServerEval().xquery(query1).eval().next().getNumber().intValue(); System.out.println(count); TextDocumentManager docMgr = client.newTextDocumentManager(); String docId = "/example/texet.txt"; StringHandle handle = new StringHandle(); handle.set("A simple text document"); docMgr.write(docId, handle); System.out.println(client.newServerEval().xquery(query1)); System.out.println("Doc written"); Assert.assertEquals(count + 1, client.newServerEval().xquery(query1).eval().next().getNumber().intValue()); client.release(); }
@Test public void testWriteTextDoc() { System.out.println("Running testWriteTextDoc method"); String docId = "/foo/test/myFoo.txt"; TextDocumentManager docMgr = client.newTextDocumentManager(); docMgr.write(docId, new StringHandle().with("This is so foo")); assertEquals("Text document write difference", "This is so foo", docMgr.read(docId, new StringHandle()).get()); }
@Test public void testWriteTextDoc() { System.out.println("Running testWriteTextDoc method"); String docId = "/foo/test/myFoo.txt"; TextDocumentManager docMgr = client.newTextDocumentManager(); docMgr.write(docId, new StringHandle().with("This is so foo")); assertEquals("Text document write difference", "This is so foo", docMgr.read(docId, new StringHandle()).get()); }
public void loadTxtDocuments() { int count = 1; TextDocumentManager docMgr = client.newTextDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); for (int i = 0; i < 101; i++) { writeset.add(DIRECTORY + "Textfoo" + i + ".txt", new StringHandle().with("bar can be foo" + i)); if (count % BATCH_SIZE == 0) { docMgr.write(writeset); writeset = docMgr.newWriteSet(); } count++; } if (count % BATCH_SIZE > 0) { docMgr.write(writeset); } }
public void loadTxtDocuments() { int count = 1; TextDocumentManager docMgr = client.newTextDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); for (int i = 0; i < 101; i++) { writeset.add(DIRECTORY + "Textfoo" + i + ".txt", new StringHandle().with("bar can be foo" + i)); if (count % BATCH_SIZE == 0) { docMgr.write(writeset); writeset = docMgr.newWriteSet(); } count++; } if (count % BATCH_SIZE > 0) { docMgr.write(writeset); } }
@Test public void testBulkSearchSQDwithNoResults() throws KeyManagementException, NoSuchAlgorithmException, Exception { loadTxtDocuments(); TextDocumentManager docMgr = client.newTextDocumentManager(); QueryManager queryMgr = client.newQueryManager(); StringQueryDefinition qd = queryMgr.newStringDefinition(); qd.setCriteria("zzzz"); SearchHandle results = new SearchHandle(); DocumentPage page = docMgr.search(qd, 1, results); assertFalse("Should return no results", page.hasNext()); }
@Test(expected = UnsupportedOperationException.class) public void testBulkSearchSQDwithWrongResponseFormat() throws KeyManagementException, NoSuchAlgorithmException, Exception { loadTxtDocuments(); TextDocumentManager docMgr = client.newTextDocumentManager(); QueryManager queryMgr = client.newQueryManager(); StringQueryDefinition qd = queryMgr.newStringDefinition(); qd.setCriteria("bar"); docMgr.setNonDocumentFormat(Format.JSON); SearchHandle results = new SearchHandle(); DocumentPage page = docMgr.search(qd, 1, results); MatchDocumentSummary[] summaries = results.getMatchResults(); for (MatchDocumentSummary summary : summaries) { MatchLocation[] locations = summary.getMatchLocations(); for (MatchLocation location : locations) { System.out.println(location.getAllSnippetText()); // do something with the snippet text } } }
@Test public void testExists() { String docId = "/test/testExists1.txt"; TextDocumentManager docMgr = Common.client.newTextDocumentManager(); // guarantee that a previous run didn't leave the document docMgr.delete(docId); assertTrue("Non-existent document appears to exist", docMgr.exists(docId)==null); docMgr.write(docId,new StringHandle().with("A simple text document")); assertTrue("Existent document doesn't appear to exist", docMgr.exists(docId)!=null); docMgr.delete(docId); }
@Test public void testDelete() { String docId = "/test/testDelete1.txt"; TextDocumentManager docMgr = Common.client.newTextDocumentManager(); docMgr.write(docId, new StringHandle().with("A simple text document")); String text = docMgr.read(docId, new StringHandle()).get(); assertTrue("Could not create document for deletion", text != null && text.length() > 0); docMgr.delete(docId); text = null; boolean hadException = false; try { text = docMgr.read(docId, new StringHandle()).get(); } catch (Exception ex) { hadException = true; } assertTrue("Could not delete document", text == null && hadException); }
@Test public void testWriteTextDoc() { SecurityContext secContext = new DatabaseClientFactory.DigestAuthContext("admin", "admin"); DatabaseClient client = DatabaseClientFactory.newClient(appServerHostname, 8015, secContext, getConnType()); String docId = "/foo/test/myFoo.txt"; TextDocumentManager docMgr = client.newTextDocumentManager(); docMgr.write(docId, new StringHandle().with("This is so foo")); assertEquals("Text document write difference", "This is so foo", docMgr.read(docId, new StringHandle()).get()); }
@Test public void testReadWrite() throws IOException { String docId = "/test/testWrite1.txt"; String text = "A simple text document"; TextDocumentManager docMgr = Common.client.newTextDocumentManager(); docMgr.write(docId, new StringHandle().with(text)); assertEquals("Text document write difference",text,docMgr.read(docId, new StringHandle()).get()); BytesHandle bytesHandle = new BytesHandle(); docMgr.read(docId, bytesHandle); assertEquals("Text document mismatch reading bytes", bytesHandle.get().length,text.length()); InputStreamHandle inputStreamHandle = new InputStreamHandle(); docMgr.read(docId, inputStreamHandle); byte[] b = Common.streamToBytes(inputStreamHandle.get()); assertEquals("Text document mismatch reading input stream",new String(b),text); Reader reader = docMgr.read(docId, new ReaderHandle()).get(); String s = Common.readerToString(reader); assertEquals("Text document mismatch with reader",s,text); File file = docMgr.read(docId, new FileHandle()).get(); assertEquals("Text document mismatch with file",text.length(),file.length()); }
@Test public void testCommit() throws XpathException { String docId1 = "/test/testExists1.txt"; String docId2 = "/test/testExists2.txt"; TextDocumentManager docMgr = Common.client.newTextDocumentManager(); docMgr.write(docId1,new StringHandle().with("A simple text document")); String transactionName = "java-client-" + seed.nextLong(); Transaction transaction = Common.client.openTransaction(transactionName); StringHandle docHandle = docMgr.read(docId1, new StringHandle(), transaction); docMgr.write(docId2, docHandle, transaction); docMgr.delete(docId1, transaction); Document status = transaction.readStatus(new DOMHandle()).get(); assertXpathExists("//*[local-name() = 'transaction-name' and "+ "string(.) = '"+transactionName+"']", status); transaction.commit(); assertTrue("Document 1 exists", docMgr.exists(docId1)==null); assertTrue("Document 2 doesn't exist", docMgr.exists(docId2)!=null); docMgr.delete(docId2); }
@Test public void testRollback() { String docId1 = "/test/testExists1.txt"; String docId2 = "/test/testExists2.txt"; TextDocumentManager docMgr = Common.client.newTextDocumentManager(); docMgr.write(docId1,new StringHandle().with("A simple text document")); Transaction transaction = Common.client.openTransaction(); StringHandle docHandle = docMgr.read(docId1, new StringHandle(), transaction); docMgr.write(docId2, docHandle, transaction); docMgr.delete(docId1, transaction); transaction.rollback(); assertTrue("Document 1 doesn't exist", docMgr.exists(docId1)!=null); assertTrue("Document 2 exists", docMgr.exists(docId2)==null); docMgr.delete(docId1); }
@Test public void testBulkSearchSQDwithResponseFormatandStringHandle() throws KeyManagementException, NoSuchAlgorithmException, Exception { loadTxtDocuments(); loadJSONDocuments(); TextDocumentManager docMgr = client.newTextDocumentManager(); QueryManager queryMgr = client.newQueryManager(); StringQueryDefinition qd = queryMgr.newStringDefinition(); qd.setCriteria("bar"); docMgr.setNonDocumentFormat(Format.JSON); docMgr.setSearchView(QueryView.METADATA); docMgr.setMetadataCategories(Metadata.PERMISSIONS); StringHandle results = new StringHandle().withFormat(Format.JSON); DocumentPage page = docMgr.search(qd, 1, results); DocumentMetadataHandle mh = new DocumentMetadataHandle(); while (page.hasNext()) { DocumentRecord rec = page.next(); validateRecord(rec, Format.TEXT); docMgr.readMetadata(rec.getUri(), mh); assertTrue("Records has permissions? ", mh.getPermissions().containsKey("flexrep-eval")); assertTrue("Record has collections ?", mh.getCollections().isEmpty()); } assertFalse("Search handle contains", results.get().isEmpty()); }
@Test public void testWriteMultipleTextDocWithDefaultMetadata() { String docId[] = { "/foo/test/myFoo1.txt", "/foo/test/myFoo2.txt", "/foo/test/myFoo3.txt" }; TextDocumentManager docMgr = client.newTextDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); // put metadata DocumentMetadataHandle mh = setMetadata(); writeset.addDefault(mh); writeset.add(docId[0], new StringHandle().with("This is so foo1")); writeset.add(docId[1], new StringHandle().with("This is so foo2")); writeset.add(docId[2], new StringHandle().with("This is so foo3")); docMgr.write(writeset); DocumentPage page = docMgr.read(docId); while (page.hasNext()) { DocumentRecord rec = page.next(); docMgr.readMetadata(rec.getUri(), mh); validateMetadata(mh); } validateMetadata(mh); }
@Test public void testWriteMultipleTextDoc() { String docId[] = { "/foo/test/myFoo1.txt", "/foo/test/myFoo2.txt", "/foo/test/myFoo3.txt" }; TextDocumentManager docMgr = client.newTextDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); writeset.add(docId[0], new StringHandle().with("This is so foo1")); writeset.add(docId[1], new StringHandle().with("This is so foo2")); writeset.add(docId[2], new StringHandle().with("This is so foo3")); docMgr.write(writeset); assertEquals("Text document write difference", "This is so foo1", docMgr.read(docId[0], new StringHandle()).get()); assertEquals("Text document write difference", "This is so foo2", docMgr.read(docId[1], new StringHandle()).get()); assertEquals("Text document write difference", "This is so foo3", docMgr.read(docId[2], new StringHandle()).get()); // Bulk delete on TextDocumentManager docMgr.delete(docId[0], docId[1], docId[2]); }
@Test public void testE_TextLoad() { String docId[] = {"/foo/test/myFoo1.txt","/foo/test/myFoo2.txt","/foo/test/myFoo3.txt"}; TextDocumentManager docMgr = Common.client.newTextDocumentManager(); DocumentWriteSet writeset =docMgr.newWriteSet(); writeset.add(docId[0], new StringHandle().with("This is so foo1")); writeset.add(docId[1], new StringHandle().with("This is so foo2")); writeset.add(docId[2], new StringHandle().with("This is so foo3")); docMgr.write(writeset); assertEquals("Text document write difference", "This is so foo1", docMgr.read(docId[0], new StringHandle()).get()); assertEquals("Text document write difference", "This is so foo2", docMgr.read(docId[1], new StringHandle()).get()); assertEquals("Text document write difference", "This is so foo3", docMgr.read(docId[2], new StringHandle()).get()); docMgr.delete(docId[0]); docMgr.delete(docId[1]); docMgr.delete(docId[2]); }