Skip to content

Commit

Permalink
Merge branch '2.0.6' into 2.0-master
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeajit committed Jan 28, 2016
2 parents 8dab28b + d70139a commit 01874eb
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 45 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.marklogic</groupId>
<artifactId>java-client-api</artifactId>
<packaging>jar</packaging>
<version>2.0.5</version>
<version>2.0.6</version>
<name>MarkLogic Java Client API</name>
<description>The official MarkLogic Java client API.</description>
<url>https://github.com/marklogic/java-client-api</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,15 @@ public void write(OutputStream out) throws IOException {
"description", RequestConstants.RESTAPI_NS);
serializer.writeCharacters(getDescription());
serializer.writeEndElement();
serializer.flush();

// logger.debug("Send: " + new String(queryPayload));
XMLEventWriter eventWriter = factory.createXMLEventWriter(out);
for (XMLEvent event : this.queryPayload) {
eventWriter.add(event);
}
eventWriter.flush();
out.flush();

writeMetadataElement(serializer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public <T extends BinaryReadHandle> T read(DocumentDescriptor desc, DocumentMeta

RequestParameters extraParams = new RequestParameters();
if (length > 0)
extraParams.put("range", "bytes="+start+"-"+(start + length));
extraParams.put("range", "bytes="+start+"-"+(start + length - 1));
else
extraParams.put("range", "bytes="+String.valueOf(start));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ private void receiveQualityImpl(Document document) {
private void sendMetadataImpl(OutputStream out) {
try {
XMLOutputFactory factory = XMLOutputFactory.newInstance();
factory.setProperty("javax.xml.stream.isRepairingNamespaces", true);

valueSerializer = null;

Expand Down
37 changes: 17 additions & 20 deletions src/main/java/com/marklogic/client/io/QueryOptionsHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,24 @@
import com.marklogic.client.io.marker.QueryOptionsWriteHandle;

/**
* A QueryOptionsHandle is used to configure query configurations.
*
* <p>Use a QueryOptionsHandle if you want to use Java to configure and manage
* MarkLogic query configurations, for search, value lookups, and facets.</p>
*
* <p>Read an options node from MarkLogic with</p>
*
* <pre>QueryOptionsHandle handle = QueryOptionsManager.readOptions(name, new QueryOptionsHandle());</pre>
*
* <p>or construct a fresh empty one (which is not a valid configuration without further building)</p>
*
* <pre>QueryOptionsHandle handle = new QueryOptionsHandle();</pre>
*
* <p>Build up options to a handle using fluent setter methods</p>
*
* <pre>handle.withConstraints(...).withTerm(...).withOperators(...)</pre>
*
* <p>and constructed items from {@link com.marklogic.client.admin.config.QueryOptionsBuilder}.</p>
*
* @deprecated Use a JSON or XML
* {@link com.marklogic.client.io.marker.StructureWriteHandle write handle} or
* {@link com.marklogic.client.io.marker.StructureReadHandle read handle}
* implementation instead of this class to write or read
* query options. For instance:
* <pre>{@code
* String opts = new StringBuilder()
* .append("<options xmlns=\"http://marklogic.com/appservices/search\">")
* .append( "<debug>true</debug>")
* .append("</options>")
* .toString();
* optsMgr.writeOptions("debug", new StringHandle(opts)); }</pre>
* or
* <pre>{@code
* String opts = "{\"options\":{\"debug\":true}}";
* optsMgr.writeOptions("debug", new StringHandle(opts).withFormat(Format.JSON)); }</pre>
*/
@SuppressWarnings("deprecation")
@Deprecated
public final class QueryOptionsHandle
extends BaseHandle<InputStream, OutputStreamSender>
implements OutputStreamSender, BufferableHandle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class BinaryDocumentTest {
@BeforeClass
public static void beforeClass() {
Common.connect();
//System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "debug");
}
@AfterClass
public static void afterClass() {
Expand Down Expand Up @@ -80,7 +81,7 @@ public void testReadWrite() throws IOException, XpathException {
docMgr.setMetadataCategories(Metadata.PROPERTIES);
Document metadataDocument = docMgr.readMetadata(docId, new DOMHandle()).get();
assertXpathEvaluatesTo("image/png","string(/*[local-name()='metadata']/*[local-name()='properties']/*[local-name()='content-type'])", metadataDocument);
assertXpathEvaluatesTo("none","string(/*[local-name()='metadata']/*[local-name()='properties']/*[local-name()='filter-capabilities'])", metadataDocument);
assertXpathEvaluatesTo("text HD-HTML","string(/*[local-name()='metadata']/*[local-name()='properties']/*[local-name()='filter-capabilities'])", metadataDocument);
assertXpathEvaluatesTo("815","string(/*[local-name()='metadata']/*[local-name()='properties']/*[local-name()='size'])", metadataDocument);
}
}
20 changes: 0 additions & 20 deletions src/test/java/com/marklogic/client/test/JSONDocumentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import java.io.IOException;
import java.io.Reader;

import javax.xml.XMLConstants;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
Expand All @@ -40,7 +38,6 @@
import com.marklogic.client.document.DocumentPatchBuilder;
import com.marklogic.client.document.DocumentPatchBuilder.Position;
import com.marklogic.client.document.JSONDocumentManager;
import com.marklogic.client.document.XMLDocumentManager;
import com.marklogic.client.io.BytesHandle;
import com.marklogic.client.io.DOMHandle;
import com.marklogic.client.io.FileHandle;
Expand Down Expand Up @@ -91,23 +88,6 @@ public void testReadWrite() throws IOException {
File file = docMgr.read(docId, new FileHandle()).get();
readNode = mapper.readTree(file);
assertTrue("JSON document mismatch with file", sourceNode.equals(readNode));

docMgr.write(docId,
new StringHandle().with(GenericDocumentTest.metadata).withFormat(Format.XML),
new StringHandle().with(content));
docText = docMgr.read(docId, new StringHandle()).get();
assertNotNull("Read null string for JSON content",docText);
readNode = mapper.readTree(docText);
assertTrue("Failed to read JSON document as String", sourceNode.equals(readNode));

String lang = "fr-CA";
docMgr.setLanguage(lang);
docMgr.write(docId, new StringHandle().with(content));

XMLDocumentManager xmlMgr = Common.client.newXMLDocumentManager();
Document document = xmlMgr.read(docId, new DOMHandle()).get();
assertEquals("Failed to set language attribute on JSON", lang,
document.getDocumentElement().getAttributeNS(XMLConstants.XML_NS_URI, "lang"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@
*/
package com.marklogic.client.test;

import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import static org.junit.Assert.assertEquals;

import org.custommonkey.xmlunit.XpathEngine;
import org.custommonkey.xmlunit.SimpleNamespaceContext;
import org.custommonkey.xmlunit.XMLUnit;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;

import javax.xml.XMLConstants;
import javax.xml.parsers.ParserConfigurationException;
Expand All @@ -30,6 +36,7 @@
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

import org.junit.BeforeClass;
import org.junit.Test;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
Expand All @@ -42,6 +49,30 @@
import com.marklogic.client.util.EditableNamespaceContext;

public class StructuredQueryBuilderTest {
static private XpathEngine xpather;

@BeforeClass
public static void beforeClass() {
XMLUnit.setIgnoreAttributeOrder(true);
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setNormalize(true);
XMLUnit.setNormalizeWhitespace(true);
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);

HashMap<String,String> namespaces = new HashMap<String, String>();
namespaces.put("rapi", "http://marklogic.com/rest-api");
namespaces.put("prop", "http://marklogic.com/xdmp/property");
namespaces.put("xs", "http://www.w3.org/2001/XMLSchema");
namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
namespaces.put("search", "http://marklogic.com/appservices/search");


SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(namespaces);

xpather = XMLUnit.newXpathEngine();
xpather.setNamespaceContext(namespaceContext);
}

// remove dependency on org.apache.tools.ant.filters.StringInputStream
static class StringInputStream extends ByteArrayInputStream {
StringInputStream(String input) {
Expand Down Expand Up @@ -508,7 +539,7 @@ public void testBuilder() throws IOException, SAXException, ParserConfigurationE
xml = new StringInputStream(q);
parser.parse(xml, handler);

assertEquals(
assertXMLEqual("Geospatial query malformed",
"<query xmlns=\"http://marklogic.com/appservices/search\" "
+ "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" "
+ "xmlns:search=\"http://marklogic.com/appservices/search\" "
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/boot-test-cygwin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

DEFAULT_M2=$USERPROFILE/.m2/repository
M2_REPO=${1:-$DEFAULT_M2}

java -cp "target/test-classes;target/classes;$M2_REPO/org/apache/httpcomponents/httpclient/4.1.1/httpclient-4.1.1.jar;$M2_REPO/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1.jar;$M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar;$M2_REPO/org/slf4j/slf4j-api/1.7.4/slf4j-api-1.7.4.jar" com.marklogic.client.test.util.TestServerBootstrapper
2 changes: 1 addition & 1 deletion src/test/resources/bootstrap.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ declare function bootstrap:post(
if (exists($user-id)) then ()
else if ($user eq "valid")
then bootstrap:security-config('sec:create-user("valid", "valid unprivileged user", "x", (), (), (), ())')
else bootstrap:security-config('sec:create-user($user, $user||" user", "x", ($user), (), (), () )'),
else bootstrap:security-config('sec:create-user("'||$user||'", "'||$user||' user", "x", ("'||$user||'"), (), (), () )'),

let $dbid := xdmp:database("java-unittest")
return (
Expand Down
7 changes: 7 additions & 0 deletions src/test/resources/teardown-test-cygwin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

DEFAULT_M2=$USERPROFILE/.m2/repository
M2_REPO=${1:-$DEFAULT_M2}

java -cp "target/test-classes;target/classes;$M2_REPO/org/apache/httpcomponents/httpclient/4.1.1/httpclient-4.1.1.jar;$M2_REPO/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1.jar;$M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar;$M2_REPO/org/slf4j/slf4j-api/1.7.4/slf4j-api-1.7.4.jar" com.marklogic.client.test.util.TestServerBootstrapper teardown

0 comments on commit 01874eb

Please sign in to comment.