protected String determineImportScriptToUse() { String version = client.newServerEval().xquery("xdmp:version()").evalAs(String.class); String xquery = QconsoleScripts.IMPORT; if (version != null && version.startsWith("8")) { return xquery.replace("qconsole-model:default-database()", "qconsole-model:default-content-source()"); } return xquery; }
@Override public void write(List<? extends String> items) throws Exception { if (logger.isInfoEnabled()) { logger.info("Deleting URIs: " + items); } client.newDocumentManager().delete(items.toArray(new String[] {})); }
public JobManagerImpl(DatabaseClient jobClient) { this.jobClient = jobClient; this.docMgr = jobClient.newJSONDocumentManager(); this.jobDeleteRunner = new JobDeleteResource(jobClient); }
@Override public void release() { for ( DatabaseClient client : clientMap.values() ) { try { // don't release the primaryClient because we didn't create it, it was provided to us if ( primaryClient != client ) client.release(); } catch (Throwable t) { logger.error("Failed to release client for host \"" + client.getHost() + "\"", t); } } }
@Override public QueryBatcher buildQueryBatcher(DatabaseClient databaseClient, DataMovementManager dataMovementManager) { StructuredQueryDefinition query = databaseClient.newQueryManager().newStructuredQueryBuilder().collection(collectionUris); return dataMovementManager.newQueryBatcher(query); } }
@BeforeClass public static void setupTestOptions() throws FileNotFoundException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { Common.connectAdmin(); QueryOptionsManager queryOptionsManager = Common.adminClient.newServerConfigManager().newQueryOptionsManager(); File options = new File("src/test/resources/alerting-options.xml"); queryOptionsManager.writeOptions("alerts", new FileHandle(options)); Common.adminClient.newServerConfigManager().setServerRequestLogging(true); Common.connect(); JSONDocumentManager jsonDocMgr = Common.client.newJSONDocumentManager(); jsonDocMgr.write("/basic1.json", new FileHandle(new File("src/test/resources/basic1.json"))); // write three files for alert tests. XMLDocumentManager docMgr = Common.client.newXMLDocumentManager(); docMgr.write("/alert/first.xml", new FileHandle(new File("src/test/resources/alertFirst.xml"))); docMgr.write("/alert/second.xml", new FileHandle(new File("src/test/resources/alertSecond.xml"))); docMgr.write("/alert/third.xml", new FileHandle(new File("src/test/resources/alertThird.xml"))); }
@Override public void destroy() { if (client != null) { if (logger.isInfoEnabled()) { logger.info("Releasing client with username: " + config.getUsername()); } client.release(); } }
@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\"]" ); }
@BeforeClass public static void beforeClass() { Common.connect(); docMgr = Common.client.newXMLDocumentManager(); queryMgr = Common.client.newQueryManager(); } @AfterClass
private static void deleteEnvironment() { XMLDocumentManager docMgr = Common.client.newXMLDocumentManager(); docMgr.delete("usa.xml", "cuba.xml", "mexico.xml", "p1.xml", "p2.xml","newpolygon.xml"); Common.adminClient.newServerConfigManager().setQueryValidation(false); Common.propertyWait(); }
@AfterClass public static void afterClass() { DeleteQueryDefinition deleteQuery = client.newQueryManager().newDeleteDefinition(); deleteQuery.setCollections(collection); client.newQueryManager().delete(deleteQuery); client.newDocumentManager().delete("doc1.txt"); client.newDocumentManager().delete("doc2.txt"); }
public TestManager(DatabaseClient client, ServiceResponseUnmarshaller unitTestXmlParser) { super(); this.unitTestXmlParser = unitTestXmlParser; client.init("marklogic-unit-test", this); }
@Test public void jsonQbe() { JSONDocumentManager jdm = Common.client.newJSONDocumentManager(); QueryManager qm = Common.client.newQueryManager(); String queryAsString = "{ \"$query\": { \"kind\": \"bird\" } }"; StringHandle handle = new StringHandle(); handle.withFormat(Format.JSON).set(queryAsString); RawQueryByExampleDefinition query = qm.newRawQueryByExampleDefinition(handle); StringHandle report = qm.validate(query, new StringHandle()); System.out.println(report.toString()); SearchHandle results = qm.search(query, new SearchHandle()); assertEquals("6 json results should have matched", results.getTotalResults(), 6); DocumentPage documents = jdm.search(query, 1); assertEquals("6 json documents should have matched", documents.getTotalSize(), 6); documents = jdm.search(query, 1, new JacksonHandle()); assertEquals("6 json documents should have matched", documents.getTotalSize(), 6); documents = jdm.search(query, 1, new SearchHandle()); assertEquals("6 json documents should have matched", documents.getTotalSize(), 6); }
@BeforeClass public static void beforeClass() { libMgr = adminClient.newServerConfigManager().newExtensionLibrariesManager(); Common.connectEval(); septFirst.set(2014, Calendar.SEPTEMBER, 1, 0, 0, 0); septFirst.set(Calendar.MILLISECOND, 0); } @AfterClass
@Override public void write(List<? extends Document> items) throws Exception { XMLDocumentManager docMgr = client.newXMLDocumentManager(); for (Document doc : items) { DOMHandle handle = new DOMHandle(doc); docMgr.write(doc.getDocumentURI(), handle); } }
@Test /** Avoid regression on https://github.com/marklogic/java-client-api/issues/761 */ public void test_issue_761() { DatabaseClient client = Common.newClient("Documents"); try { client.newServerConfigManager().newResourceExtensionsManager() .listServices(new DOMHandle()); } finally { client.release(); } }
@Test public void testRequestLogger() throws KeyManagementException, NoSuchAlgorithmException, IOException { System.out.println("Running testRequestLogger"); String filename = "bbq1.xml"; String uri = "/request-logger/"; File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create transaction Transaction transaction = client.openTransaction(); // create a manager for XML documents XMLDocumentManager docMgr = client.newXMLDocumentManager(); // create an identifier for the document String docId = uri + filename; // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); // create logger RequestLogger logger = client.newLogger(System.out); logger.setContentMax(RequestLogger.ALL_CONTENT); // start logging docMgr.startLogging(logger); // write the document content docMgr.write(docId, handle, transaction); // commit transaction transaction.commit(); // stop logging docMgr.stopLogging(); String expectedContentMax = "9223372036854775807"; assertEquals("Content log is not equal", expectedContentMax, Long.toString(logger.getContentMax())); }
@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 public void testStack20170725() throws IOException { XMLDocumentManager documentManager = Common.client.newXMLDocumentManager(); Transaction transaction = Common.client.openTransaction(); DocumentMetadataHandle metadataHandle = new DocumentMetadataHandle(); documentManager.writeAs("all_well.xml", new FileHandle( new File("../marklogic-client-api-functionaltests/src/test/java/com" + "/marklogic/client/functionaltest/data/all_well.xml"))); InputStreamHandle handle = documentManager.read("all_well.xml", metadataHandle, new InputStreamHandle(), transaction); try { InputStream stream = handle.get(); try { while ( stream.read() > -1 ) {} } finally { stream.close(); } } finally { handle.close(); } // if we ran without throwing any exceptions, then this test passes } }
@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); }