@AfterClass public static void afterClass() { libsMgr.delete("/ext/my-lib.xqy"); }
@AfterClass public static void afterClass() { libsMgr.delete("/ext/my-lib.xqy"); }
@AfterClass public static void afterClass() throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { confMgr.newQueryOptionsManager().deleteOptions(optionsName); extensionMgr.deleteTransform(MLCP_TRANSFORM_ADAPTER); extensionMgr.deleteTransform(TransformExtensionsTest.XQUERY_NAME); extensionMgr.deleteTransform(TransformExtensionsTest.XSLT_NAME); libMgr.delete("/ext/RestTransformAdapter.xqy"); libMgr.delete("/ext/memory-operations.xqy"); libMgr.delete("/ext/node-operations.xqy"); }
@Test public void evalAndInvokeXQuery() throws ParserConfigurationException, DatatypeConfigurationException, JsonProcessingException, IOException, SAXException { InputStreamHandle xquery = new InputStreamHandle( this.getClass().getClassLoader().getResourceAsStream("evaltest.xqy")); // first read it locally and run it as ad-hoc eval runAndTestXQuery( Common.evalClient.newServerEval().xquery(xquery) ); // run the same code, this time as a module we'll invoke xquery = new InputStreamHandle( this.getClass().getClassLoader().getResourceAsStream("evaltest.xqy")); xquery.setFormat(Format.TEXT); // libMgr is connected with admin privileges (as rest-admin user) libMgr.write("/ext/test/evaltest.xqy", xquery); // now module is installed, let's invoke it runAndTestXQuery( Common.evalClient.newServerEval().modulePath("/ext/test/evaltest.xqy") ); // clean up module we no longer need libMgr.delete("/ext/test/evaltest.xqy"); }
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()); libsMgr.delete(Path); libsMgr.delete(Path); } catch (Exception e) { System.out.println("Attempt to Delete Non exsting file Failed");
@Test public void testXQueryModuleCRUDXmlFileNegative() throws KeyManagementException, NoSuchAlgorithmException, IOException { DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // get a manager ExtensionLibrariesManager libsMgr = client.newServerConfigManager().newExtensionLibrariesManager(); String Path = "/foo/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 try { libsMgr.write(Path, f); Assert.assertTrue("Exception was not thrown", false); } catch (IllegalArgumentException e) { // Issue 210 logged for meaningful error assertEquals("libraryPath (the modules database path under which you install an asset) must begin with /ext/", e.getMessage()); } // delete it try { libsMgr.delete(Path); Assert.assertTrue("Exception was not thrown", false); } catch (IllegalArgumentException e) { assertEquals("libraryPath (the modules database path under which you install an asset) must begin with /ext/", e.getMessage()); } }
libsMgr.delete(libraryPath); fail("Call to delete with an invalid path should have failed"); }catch(Exception e){
@Test public void testJavascriptMlcpTransformAdapter() throws Exception{ String transformContents = Common.testFileToString("SampleMlcpTransform.sjs"); libMgr.write("/ext/SampleMlcpTransform.sjs", new StringHandle(transformContents).withFormat(Format.TEXT)); ServerTransform transform = new ServerTransform(MLCP_TRANSFORM_ADAPTER) .addParameter("ml.module", "/ext/SampleMlcpTransform.sjs") .addParameter("attr-value", "true"); runTransform(transform); libMgr.delete("/ext/SampleMlcpTransform.sjs"); }
@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 testXQueryMlcpTransformAdapter() throws Exception{ String transformContents = Common.testFileToString("SampleMlcpTransform.xqy"); libMgr.write("/ext/SampleMlcpTransform.xqy", new StringHandle(transformContents).withFormat(Format.TEXT)); ServerTransform transform = new ServerTransform(MLCP_TRANSFORM_ADAPTER) .addParameter("ml.module", "/ext/SampleMlcpTransform.xqy") .addParameter("ml.namespace", "http://marklogic.com/example") .addParameter("attr-value", "true"); runTransform(transform); libMgr.delete("/ext/SampleMlcpTransform.xqy"); }
@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; } }
libsMgr.delete(Path);
@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; } }
@Test public void evalAndInvokeJavascript() throws DatatypeConfigurationException, JsonProcessingException, IOException { String javascript = "var myString;" + "var myArray;" + "var myObject;" + "var myBool;" + "var myInteger;" + "var myDouble;" + "var myDate;" + "var myNull;" + "xdmp.arrayValues([myString, myArray, myObject, myBool, myInteger, myDouble, myDate, myNull])"; // first run it as ad-hoc eval runAndTestJavascript( Common.evalClient.newServerEval().javascript(javascript) ); // run the same code, this time as a module we'll invoke StringHandle javascriptModule = new StringHandle( javascript ); javascriptModule.setFormat(Format.TEXT); // libMgr is connected with admin privileges (as rest-admin user) libMgr.write("/ext/test/evaltest.sjs", javascriptModule); // now module is installed, let's invoke it runAndTestJavascript( Common.evalClient.newServerEval().modulePath("/ext/test/evaltest.sjs") ); // clean up module we no longer need libMgr.delete("/ext/test/evaltest.sjs"); }
libsMgr.delete("/ext/my/path/to/my/module.xqy");