String xqueryModuleAsString = libsMgr.read(Path, new StringHandle()).get(); assertTrue("module read and read back", xqueryModuleAsString.contains("let $x := (1,2,3,4,5)")); String xqueryModuleAsStringNew = libsMgr.read(Path, new StringHandle()).get(); System.out.println("Path returned by Descriptor " + descriptor.getPath() + "Document returned by Descriptor" + xqueryModuleAsStringNew); libsMgr.delete(descriptor.getPath()); xqueryModuleAsString = libsMgr.read(Path, new StringHandle()).get(); } catch (ResourceNotFoundException e) { System.out.println("Reading deleted file Failed");
String xqueryModuleAsString = libsMgr.read(Path, new StringHandle()).get(); assertTrue("module read and read back", xqueryModuleAsString.contains("let $x := (1,2,3,4,5)")); try { xqueryModuleAsString = libsMgr.read(Path, new StringHandle()).get(); } catch (ResourceNotFoundException e) { System.out.println("Reading deleted file Failed");
@Test public void testXQueryModuleCRUDBinaryFile() throws KeyManagementException, NoSuchAlgorithmException, IOException { DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // get a manager ExtensionLibrariesManager libsMgr = client.newServerConfigManager().newExtensionLibrariesManager(); String Path = "/ext/my/path/to/my/module.xqy"; // write XQuery file to the modules database libsMgr.write(Path, new FileHandle(new File("src/test/java/com/marklogic/client/functionaltest/data/binary.jpg")).withFormat(Format.BINARY)); // read it back File f = new File("src/test/java/com/marklogic/client/functionaltest/data/binary.jpg"); assertEquals(f.length(), libsMgr.read(Path, new StringHandle()).getByteLength()); // get the list of descriptors ExtensionLibraryDescriptor[] descriptors = libsMgr.list(); assertEquals("number of modules installed", descriptors.length, 1); for (ExtensionLibraryDescriptor descriptor : descriptors) { assertEquals(descriptor.getPath(), Path); } // delete it libsMgr.delete(Path); try { // read deleted module libsMgr.read(Path, new StringHandle()).get(); } catch (ResourceNotFoundException e) { // pass; } }
String xqueryModuleAsString = libsMgr.read(firstPath, new StringHandle()).get(); assertTrue("module read and read back", xqueryModuleAsString.startsWith("xquery version \"1.0-ml\";")); String xqueryModuleAsString1 = libsMgr.read(secondPath, new StringHandle()).get(); assertTrue("module read and read back", xqueryModuleAsString1.startsWith("xquery version \"1.0-ml\";")); xqueryModuleAsString = libsMgr.read(firstPath, new StringHandle()).get(); xqueryModuleAsString = libsMgr.read(secondPath, new StringHandle()).get(); } catch (ResourceNotFoundException e) {
String xqueryModuleAsString = libsMgr.read(Path, new StringHandle()).get(); assertTrue("module read and read back", xqueryModuleAsString.startsWith("xquery version \"1.0-ml\";")); String xqueryModuleAsDuplicateString = libsMgr.read(Path, new StringHandle()).get(); assertTrue("module read and read back", xqueryModuleAsDuplicateString.startsWith("xquery version \"1.0-ml\";")); xqueryModuleAsString = libsMgr.read(Path, new StringHandle()).get(); } catch (ResourceNotFoundException e) {
libsMgr.read(libraryPath, new StringHandle()); fail("Call to read with an invalid path should have failed"); }catch(Exception e){
@Test public void testXQueryModuleCRUDTextFile() throws KeyManagementException, NoSuchAlgorithmException, IOException { DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // get a manager ExtensionLibrariesManager libsMgr = client.newServerConfigManager().newExtensionLibrariesManager(); String Path = "/ext/my/path/to/my/module.xqy"; // write XQuery file to the modules database libsMgr.write(Path, new FileHandle(new File("src/test/java/com/marklogic/client/functionaltest/data/readme.txt")).withFormat(Format.TEXT)); // read it back String xqueryModuleAsString = libsMgr.read(Path, new StringHandle()).get(); assertTrue("module read and read back", xqueryModuleAsString.startsWith("Copyright 2017 MarkLogic Corporation")); // get the list of descriptors ExtensionLibraryDescriptor[] descriptors = libsMgr.list(); assertEquals("number of modules installed", descriptors.length, 1); for (ExtensionLibraryDescriptor descriptor : descriptors) { assertEquals(descriptor.getPath(), Path); } // delete it libsMgr.delete(Path); try { // read deleted module xqueryModuleAsString = libsMgr.read(Path, new StringHandle()).get(); } catch (ResourceNotFoundException e) { // pass; } }
@Test public void testXQueryModuleCRUDXmlFile() throws KeyManagementException, NoSuchAlgorithmException, IOException { DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // get a manager ExtensionLibrariesManager libsMgr = client.newServerConfigManager().newExtensionLibrariesManager(); String Path = "/ext/my/path/to/my/module.xqy"; FileHandle f = new FileHandle(new File("src/test/java/com/marklogic/client/functionaltest/data/all_well.xml")).withFormat(Format.XML); // write XQuery file to the modules database libsMgr.write(Path, f); // read it back assertEquals(209745, libsMgr.read(Path, new StringHandle()).getByteLength()); // get the list of descriptors ExtensionLibraryDescriptor[] descriptors = libsMgr.list(); assertEquals("number of modules installed", descriptors.length, 1); for (ExtensionLibraryDescriptor descriptor : descriptors) { assertEquals(descriptor.getPath(), Path); } // delete it libsMgr.delete(Path); try { // read deleted module libsMgr.read(Path, new StringHandle()).get(); } catch (ResourceNotFoundException e) { // pass; } }