@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; } }
@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; } }