JsonNode resourceExtensions = resourceExtensionsManager.listServices(new JacksonHandle()).get(); resourceExtensions.findValuesAsText("name").forEach( x -> {
@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 /** Avoid regression on https://github.com/marklogic/java-client-api/issues/172 */ public void test_172() { ResourceExtensionsManager extensionMgr = Common.adminClient.newServerConfigManager().newResourceExtensionsManager(); Common.adminClient.release(); // since we released the existing connection, clear it out Common.adminClient = null; String expectedMessage = "You cannot use this connected object anymore--connection has already been released"; try { extensionMgr.writeServices(ResourceExtensionsTest.RESOURCE_NAME, null, null); } catch (IllegalStateException e) { assertEquals("Wrong error", expectedMessage, e.getMessage()); } try { extensionMgr.readServices(ResourceExtensionsTest.RESOURCE_NAME, new StringHandle()); } catch (IllegalStateException e) { assertEquals("Wrong error", expectedMessage, e.getMessage()); } try { extensionMgr.listServices(new DOMHandle()); } catch (IllegalStateException e) { assertEquals("Wrong error", expectedMessage, e.getMessage()); } try { extensionMgr.deleteServices(ResourceExtensionsTest.RESOURCE_NAME); } catch (IllegalStateException e) { assertEquals("Wrong error", expectedMessage, e.getMessage()); } }
@Test public void test1GetAllResourceServices() throws KeyManagementException, NoSuchAlgorithmException, Exception { JacksonHandle jh = new JacksonHandle(); resourceMgr.listServices(jh); assertEquals("Format on Handle", "JSON", jh.getFormat().name()); assertEquals("Mime Type on Handle", "application/json", jh.getMimetype()); String expectedList = "{\"resources\":{\"resource\":[{\"name\":\"simpleJSResourceModule\", \"source-format\":\"javascript\", \"description\":\"Testing resource extension for java script\", \"version\":\"1.0\", \"title\":\"BasicJSTest\", \"methods\":{\"method\":[{\"method-name\":\"get\", \"parameter\":[{\"parameter-name\":\"my-uri\", \"parameter-type\":\"xs:string?\"}]}, {\"method-name\":\"post\"}, {\"method-name\":\"put\"}, {\"method-name\":\"delete\"}]}, \"resource-source\":\"/v1/resources/simpleJSResourceModule\"}]}}"; JSONAssert.assertEquals(expectedList, jh.get().toString(), false); TestJSExtension tjs = new TestJSExtension(client); String expectedResponse = "{\"response\":[200, \"OK\"]}"; JSONAssert.assertEquals(expectedResponse, tjs.putJSON("helloJS.json"), false); String expAftrPut = "{\"argument1\":\"helloJS.json\", \"argument2\":\"Earth\",\"database-name\":\"TestJSResourceExtensionDB\", \"document-count\":1, \"content\":\"This is a JSON document\", \"document-content\":{\"argument1\":\"hello\", \"argument2\":\"Earth\", \"content\":\"This is a JSON document\", \"response\":[200, \"OK\"], \"outputTypes\":\"application/json\"}, \"response\":[200, \"OK\"], \"outputTypes\":[\"application/json\"]}"; JSONAssert.assertEquals(expAftrPut, tjs.getJSON("helloJS.json"), false); JSONAssert.assertEquals(expectedResponse, tjs.postJSON("helloJS.json"), false); String expAftrPost = "{\"argument1\":\"helloJS.json\", \"argument2\":\"Earth\", \"document-count\":1, \"content\":\"This is a JSON document\", \"document-content\":{\"argument1\":\"hello\", \"argument2\":\"Earth\", \"content\":\"This is a JSON document\", \"array\":[1, 2, 3], \"response\":[200, \"OK\"], \"outputTypes\":\"application/json\"}, \"response\":[200, \"OK\"], \"outputTypes\":[\"application/json\"]}"; JSONAssert.assertEquals(expAftrPost, tjs.getJSON("helloJS.json"), false); String expected = "{\"argument1\":\"helloJS.json\", \"argument2\":\"Earth\", \"document-count\":0, \"content\":\"This is a JSON document\", \"document-content\":null, \"response\":[200, \"OK\"], \"outputTypes\":[\"application/json\"]}"; JSONAssert.assertEquals(expectedResponse, tjs.deleteJSON("helloJS.json"), false); JSONAssert.assertEquals(expected, tjs.getJSON("helloJS.json"), false); }
@Test public void testResourceServiceExtension() throws XpathException, SAXException, IOException { ResourceExtensionsManager extensionMgr = Common.adminClient.newServerConfigManager().newResourceExtensionsManager(); StringHandle handle = new StringHandle(); ExtensionMetadata metadata = makeMetadata(); MethodParameters[] params = makeParameters(); handle.set(resourceServices); extensionMgr.writeServices(RESOURCE_NAME, handle, metadata, params); extensionMgr.readServices(RESOURCE_NAME, handle); assertEquals("Failed to retrieve resource services", resourceServices, handle.get()); String result = extensionMgr.listServices(new StringHandle().withFormat(Format.XML), true).get(); assertNotNull("Failed to retrieve resource services list", result); assertTrue("List without resource", xpather.getMatchingNodes( "/rapi:resources/rapi:resource/rapi:name[string(.) = 'testresource']", XMLUnit.buildControlDocument(result) ).getLength() == 1); extensionMgr.deleteServices(RESOURCE_NAME); result = extensionMgr.readServices(RESOURCE_NAME, handle).get(); assertTrue("Failed to delete resource services", result == null); } }