@Override public <C> ContentHandle<C> newHandle(Class<C> type) { @SuppressWarnings("unchecked") ContentHandle<C> handle = isHandled(type) ? (ContentHandle<C>) new StringHandle() : null; return handle; } };
@Override public <C> ContentHandle<C> newHandle(Class<C> type) { @SuppressWarnings("unchecked") ContentHandle<C> handle = isHandled(type) ? (ContentHandle<C>) new StringHandle() : null; return handle; } };
@Override public Iterator<String> listGraphUris() { final String uriString = services.getGraphUris(requestLogger, new StringHandle()).get(); String[] uris = uriString.split("\n"); return Arrays.asList(uris).iterator(); }
@Override public boolean isEnabled() { RequestParameters params = new RequestParameters(); ServiceResultIterator resultItr = this.getServices().get(params); if (resultItr == null || ! resultItr.hasNext()) { return false; } ServiceResult res = resultItr.next(); StringHandle handle = new StringHandle(); String enabled = res.getContent(handle).get(); return Boolean.parseBoolean(enabled); } }
@Override public void enable() { RequestParameters params = new RequestParameters(); params.add("enable", "true"); this.getServices().post(params, new StringHandle("{}").withFormat(Format.JSON)); }
@Test public void testWriteValidAndInvalidDocsAndThrowException() { String directory = "/WriteBatcherTest/testWriteValidAndInvalidDocsAndThrowException/"; DocumentWriteSet writeSet = client.newDocumentManager().newWriteSet(); writeSet.add(directory + uri1, new StringHandle("test")); writeSet.add(directory + uri5, new StringHandle("this is not valid XML").withFormat(Format.XML)); writeSet.add(directory + uri2, new StringHandle("test")); writeSet.add(directory + uri5, new StringHandle("this is not valid XML").withFormat(Format.XML)); writeSet.add(directory + uri3, new StringHandle("test")); testExceptions(writeSet, 3, 2); }
private void patchRecord(String docId, String docContent) { StringHandle patchHandle = new StringHandle(docContent); if (MarkLogicOutputProperties.DocType.JSON == docType) { patchHandle.withFormat(Format.JSON); } else if (MarkLogicOutputProperties.DocType.XML == docType) { patchHandle.withFormat(Format.XML); } else { throw new MarkLogicException(new MarkLogicErrorCode("Cant patch for docType " + docType)); } docMgr.patch(docId, patchHandle); }
/** * @return one TestModule for each test module found in the modules database */ public List<TestModule> list() { RequestParameters params = new RequestParameters(); params.add("func", "list"); String xml = getServices().get(params, new StringHandle()).get(); return unitTestXmlParser.parseTestList(xml); }
public String putJSON(String docUri) { RequestParameters params = new RequestParameters(); params.add("uri", docUri); String input = "{\"argument1\":\"hello\", \"argument2\":\"Earth\", \"content\":\"This is a JSON document\", \"response\":[200, \"OK\"], \"outputTypes\":\"application/json\"}"; StringHandle readHandle = new StringHandle(); // call the service getServices().put(params, new StringHandle(input).withFormat(Format.JSON), readHandle); // iterate over the results return readHandle.get(); }
@Test public void testPostDocumentWithoutFormat() throws SAXException, IOException { StringHandle stringHandle = new StringHandle("<search xmlns=\"http://marklogic.com/appservices/search\"><qtext>true</qtext></search>"); DOMHandle answer = ruleManager.match(stringHandle, new DOMHandle()); Document doc = answer.get(); NodeList nl = doc.getElementsByTagNameNS( "http://marklogic.com/rest-api", "name"); assertEquals(2, nl.getLength()); }
@Test public void testThings_file() throws Exception { gmWriter.setDefaultMimetype(RDFMimeTypes.TRIPLEXML); String tripleGraphUri = "http://test.things.com/file"; File file = new File(datasource + "relative5.xml"); gmWriter.write(tripleGraphUri, new FileHandle(file)); TriplesReadHandle things = gmWriter.things(new StringHandle(), "about"); assertTrue("Things did not return expected Uri's", things.toString().contains("<about> <http://purl.org/dc/elements/1.1/title> \"Anna's Homepage\" .")); gmWriter.delete(tripleGraphUri); }
public void writeXSLTransform(TransformExtensionsManager extensionMgr) throws ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException { extensionMgr.writeXSLTransform( XSLT_NAME, new StringHandle().withFormat(Format.XML).withMimetype("application/xslt+xml").with(xslTransform), makeXSLTMetadata() ); } }
@Test public void testWriteTextDoc() { SecurityContext secContext = new DatabaseClientFactory.DigestAuthContext("admin", "admin"); DatabaseClient client = DatabaseClientFactory.newClient(appServerHostname, 8015, secContext, getConnType()); String docId = "/foo/test/myFoo.txt"; TextDocumentManager docMgr = client.newTextDocumentManager(); docMgr.write(docId, new StringHandle().with("This is so foo")); assertEquals("Text document write difference", "This is so foo", docMgr.read(docId, new StringHandle()).get()); }
@Test public void testWrite_nquads_FileHandle() throws Exception { File file = new File(datasource + "relative2.nq"); FileHandle filehandle = new FileHandle(); filehandle.set(file); gmWriter.write("htp://test.sem.graph/nquads", filehandle.withMimetype("application/n-quads")); StringHandle handle = gmWriter.read("htp://test.sem.graph/nquads", new StringHandle().withMimetype(RDFMimeTypes.NQUADS)); assertTrue("Did not insert document or inserted empty doc", handle.toString().contains("<#electricVehicle2>")); }
@Test public void testWrite_nTriples_FileHandle() throws Exception { File file = new File(datasource + "5triples.nt"); FileHandle filehandle = new FileHandle(); filehandle.set(file); gmWriter.write("htp://test.sem.graph/n", filehandle.withMimetype("application/n-triples")); StringHandle handle = gmWriter.read("htp://test.sem.graph/n", new StringHandle().withMimetype(RDFMimeTypes.NTRIPLES)); assertTrue("Did not insert document or inserted empty doc", handle.toString().contains("<http://jibbering.com/foaf/santa.rdf#bod>")); }
@Test public void testJSON() { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition t = qb.term("leaf3"); // create a handle for the search results StringHandle resultsHandle = new StringHandle().withFormat(Format.JSON); // run the search queryMgr.search(t, resultsHandle); assertEquals("{", resultsHandle.get().substring(0, 1)); // It's JSON, right? }
@Test public void testWriteInvalidXMLAndThrowException() { String directory = "/WriteBatcherTest/testWriteInvalidXMLAndThrowException/"; DocumentWriteSet writeSet = client.newDocumentManager().newWriteSet(); writeSet.add(directory + uri5, new StringHandle("this is not valid XML").withFormat(Format.XML)); testExceptions(writeSet, 0, 1); }
@Test public void testBadQueryAndThrowException() { RawStructuredQueryDefinition query = client.newQueryManager().newRawStructuredQueryDefinition( new StringHandle("<this is not a valid structured query>").withFormat(JSON)); // we'll see one failure per forest List<String> urisIterator = testQueryExceptions(query, 0, moveMgr.readForestConfig().listForests().length); // without any matching uris, there will be no success or failure batches testIteratorExceptions(urisIterator, 0, 0); }
@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 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"); }