Skip to content

Commit 01874eb

Browse files
Ajit GeorgeAjit George
Ajit George
authored and
Ajit George
committed
Merge branch '2.0.6' into 2.0-master
2 parents 8dab28b + d70139a commit 01874eb

11 files changed

+71
-45
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.marklogic</groupId>
55
<artifactId>java-client-api</artifactId>
66
<packaging>jar</packaging>
7-
<version>2.0.5</version>
7+
<version>2.0.6</version>
88
<name>MarkLogic Java Client API</name>
99
<description>The official MarkLogic Java client API.</description>
1010
<url>https://github.com/marklogic/java-client-api</url>

src/main/java/com/marklogic/client/alerting/RuleDefinition.java

+3
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,15 @@ public void write(OutputStream out) throws IOException {
262262
"description", RequestConstants.RESTAPI_NS);
263263
serializer.writeCharacters(getDescription());
264264
serializer.writeEndElement();
265+
serializer.flush();
265266

266267
// logger.debug("Send: " + new String(queryPayload));
267268
XMLEventWriter eventWriter = factory.createXMLEventWriter(out);
268269
for (XMLEvent event : this.queryPayload) {
269270
eventWriter.add(event);
270271
}
272+
eventWriter.flush();
273+
out.flush();
271274

272275
writeMetadataElement(serializer);
273276

src/main/java/com/marklogic/client/impl/BinaryDocumentImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public <T extends BinaryReadHandle> T read(DocumentDescriptor desc, DocumentMeta
132132

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

src/main/java/com/marklogic/client/io/DocumentMetadataHandle.java

+1
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ private void receiveQualityImpl(Document document) {
659659
private void sendMetadataImpl(OutputStream out) {
660660
try {
661661
XMLOutputFactory factory = XMLOutputFactory.newInstance();
662+
factory.setProperty("javax.xml.stream.isRepairingNamespaces", true);
662663

663664
valueSerializer = null;
664665

src/main/java/com/marklogic/client/io/QueryOptionsHandle.java

+17-20
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,24 @@
8080
import com.marklogic.client.io.marker.QueryOptionsWriteHandle;
8181

8282
/**
83-
* A QueryOptionsHandle is used to configure query configurations.
84-
*
85-
* <p>Use a QueryOptionsHandle if you want to use Java to configure and manage
86-
* MarkLogic query configurations, for search, value lookups, and facets.</p>
87-
*
88-
* <p>Read an options node from MarkLogic with</p>
89-
*
90-
* <pre>QueryOptionsHandle handle = QueryOptionsManager.readOptions(name, new QueryOptionsHandle());</pre>
91-
*
92-
* <p>or construct a fresh empty one (which is not a valid configuration without further building)</p>
93-
*
94-
* <pre>QueryOptionsHandle handle = new QueryOptionsHandle();</pre>
95-
*
96-
* <p>Build up options to a handle using fluent setter methods</p>
97-
*
98-
* <pre>handle.withConstraints(...).withTerm(...).withOperators(...)</pre>
99-
*
100-
* <p>and constructed items from {@link com.marklogic.client.admin.config.QueryOptionsBuilder}.</p>
101-
*
83+
* @deprecated Use a JSON or XML
84+
* {@link com.marklogic.client.io.marker.StructureWriteHandle write handle} or
85+
* {@link com.marklogic.client.io.marker.StructureReadHandle read handle}
86+
* implementation instead of this class to write or read
87+
* query options. For instance:
88+
* <pre>{@code
89+
* String opts = new StringBuilder()
90+
* .append("<options xmlns=\"http://marklogic.com/appservices/search\">")
91+
* .append( "<debug>true</debug>")
92+
* .append("</options>")
93+
* .toString();
94+
* optsMgr.writeOptions("debug", new StringHandle(opts)); }</pre>
95+
* or
96+
* <pre>{@code
97+
* String opts = "{\"options\":{\"debug\":true}}";
98+
* optsMgr.writeOptions("debug", new StringHandle(opts).withFormat(Format.JSON)); }</pre>
10299
*/
103-
@SuppressWarnings("deprecation")
100+
@Deprecated
104101
public final class QueryOptionsHandle
105102
extends BaseHandle<InputStream, OutputStreamSender>
106103
implements OutputStreamSender, BufferableHandle,

src/test/java/com/marklogic/client/test/BinaryDocumentTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class BinaryDocumentTest {
4141
@BeforeClass
4242
public static void beforeClass() {
4343
Common.connect();
44+
//System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "debug");
4445
}
4546
@AfterClass
4647
public static void afterClass() {
@@ -80,7 +81,7 @@ public void testReadWrite() throws IOException, XpathException {
8081
docMgr.setMetadataCategories(Metadata.PROPERTIES);
8182
Document metadataDocument = docMgr.readMetadata(docId, new DOMHandle()).get();
8283
assertXpathEvaluatesTo("image/png","string(/*[local-name()='metadata']/*[local-name()='properties']/*[local-name()='content-type'])", metadataDocument);
83-
assertXpathEvaluatesTo("none","string(/*[local-name()='metadata']/*[local-name()='properties']/*[local-name()='filter-capabilities'])", metadataDocument);
84+
assertXpathEvaluatesTo("text HD-HTML","string(/*[local-name()='metadata']/*[local-name()='properties']/*[local-name()='filter-capabilities'])", metadataDocument);
8485
assertXpathEvaluatesTo("815","string(/*[local-name()='metadata']/*[local-name()='properties']/*[local-name()='size'])", metadataDocument);
8586
}
8687
}

src/test/java/com/marklogic/client/test/JSONDocumentTest.java

-20
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import java.io.IOException;
2424
import java.io.Reader;
2525

26-
import javax.xml.XMLConstants;
27-
2826
import com.fasterxml.jackson.databind.JsonNode;
2927
import com.fasterxml.jackson.databind.ObjectMapper;
3028
import com.fasterxml.jackson.databind.node.ArrayNode;
@@ -40,7 +38,6 @@
4038
import com.marklogic.client.document.DocumentPatchBuilder;
4139
import com.marklogic.client.document.DocumentPatchBuilder.Position;
4240
import com.marklogic.client.document.JSONDocumentManager;
43-
import com.marklogic.client.document.XMLDocumentManager;
4441
import com.marklogic.client.io.BytesHandle;
4542
import com.marklogic.client.io.DOMHandle;
4643
import com.marklogic.client.io.FileHandle;
@@ -91,23 +88,6 @@ public void testReadWrite() throws IOException {
9188
File file = docMgr.read(docId, new FileHandle()).get();
9289
readNode = mapper.readTree(file);
9390
assertTrue("JSON document mismatch with file", sourceNode.equals(readNode));
94-
95-
docMgr.write(docId,
96-
new StringHandle().with(GenericDocumentTest.metadata).withFormat(Format.XML),
97-
new StringHandle().with(content));
98-
docText = docMgr.read(docId, new StringHandle()).get();
99-
assertNotNull("Read null string for JSON content",docText);
100-
readNode = mapper.readTree(docText);
101-
assertTrue("Failed to read JSON document as String", sourceNode.equals(readNode));
102-
103-
String lang = "fr-CA";
104-
docMgr.setLanguage(lang);
105-
docMgr.write(docId, new StringHandle().with(content));
106-
107-
XMLDocumentManager xmlMgr = Common.client.newXMLDocumentManager();
108-
Document document = xmlMgr.read(docId, new DOMHandle()).get();
109-
assertEquals("Failed to set language attribute on JSON", lang,
110-
document.getDocumentElement().getAttributeNS(XMLConstants.XML_NS_URI, "lang"));
11191
}
11292

11393
@Test

src/test/java/com/marklogic/client/test/StructuredQueryBuilderTest.java

+32-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@
1515
*/
1616
package com.marklogic.client.test;
1717

18+
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
1819
import static org.junit.Assert.assertEquals;
1920

21+
import org.custommonkey.xmlunit.XpathEngine;
22+
import org.custommonkey.xmlunit.SimpleNamespaceContext;
23+
import org.custommonkey.xmlunit.XMLUnit;
24+
2025
import java.io.ByteArrayInputStream;
2126
import java.io.FileInputStream;
2227
import java.io.IOException;
2328
import java.io.InputStream;
29+
import java.util.HashMap;
2430

2531
import javax.xml.XMLConstants;
2632
import javax.xml.parsers.ParserConfigurationException;
@@ -30,6 +36,7 @@
3036
import javax.xml.validation.Schema;
3137
import javax.xml.validation.SchemaFactory;
3238

39+
import org.junit.BeforeClass;
3340
import org.junit.Test;
3441
import org.xml.sax.SAXException;
3542
import org.xml.sax.SAXParseException;
@@ -42,6 +49,30 @@
4249
import com.marklogic.client.util.EditableNamespaceContext;
4350

4451
public class StructuredQueryBuilderTest {
52+
static private XpathEngine xpather;
53+
54+
@BeforeClass
55+
public static void beforeClass() {
56+
XMLUnit.setIgnoreAttributeOrder(true);
57+
XMLUnit.setIgnoreWhitespace(true);
58+
XMLUnit.setNormalize(true);
59+
XMLUnit.setNormalizeWhitespace(true);
60+
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
61+
62+
HashMap<String,String> namespaces = new HashMap<String, String>();
63+
namespaces.put("rapi", "http://marklogic.com/rest-api");
64+
namespaces.put("prop", "http://marklogic.com/xdmp/property");
65+
namespaces.put("xs", "http://www.w3.org/2001/XMLSchema");
66+
namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
67+
namespaces.put("search", "http://marklogic.com/appservices/search");
68+
69+
70+
SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(namespaces);
71+
72+
xpather = XMLUnit.newXpathEngine();
73+
xpather.setNamespaceContext(namespaceContext);
74+
}
75+
4576
// remove dependency on org.apache.tools.ant.filters.StringInputStream
4677
static class StringInputStream extends ByteArrayInputStream {
4778
StringInputStream(String input) {
@@ -508,7 +539,7 @@ public void testBuilder() throws IOException, SAXException, ParserConfigurationE
508539
xml = new StringInputStream(q);
509540
parser.parse(xml, handler);
510541

511-
assertEquals(
542+
assertXMLEqual("Geospatial query malformed",
512543
"<query xmlns=\"http://marklogic.com/appservices/search\" "
513544
+ "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" "
514545
+ "xmlns:search=\"http://marklogic.com/appservices/search\" "
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
DEFAULT_M2=$USERPROFILE/.m2/repository
4+
M2_REPO=${1:-$DEFAULT_M2}
5+
6+
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

src/test/resources/bootstrap.xqy

+1-1
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ declare function bootstrap:post(
756756
if (exists($user-id)) then ()
757757
else if ($user eq "valid")
758758
then bootstrap:security-config('sec:create-user("valid", "valid unprivileged user", "x", (), (), (), ())')
759-
else bootstrap:security-config('sec:create-user($user, $user||" user", "x", ($user), (), (), () )'),
759+
else bootstrap:security-config('sec:create-user("'||$user||'", "'||$user||' user", "x", ("'||$user||'"), (), (), () )'),
760760

761761
let $dbid := xdmp:database("java-unittest")
762762
return (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
DEFAULT_M2=$USERPROFILE/.m2/repository
4+
M2_REPO=${1:-$DEFAULT_M2}
5+
6+
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
7+

0 commit comments

Comments
 (0)