From c47f6928159cbc1058eebb25c5c4efabcad75e77 Mon Sep 17 00:00:00 2001 From: Sam Mefford Date: Wed, 5 Aug 2015 09:48:29 -0600 Subject: [PATCH 1/9] fix error preventing users from being created; add windows-friendly bootstrap and teardown scripts --- src/test/resources/boot-test-cygwin.sh | 6 ++++++ src/test/resources/bootstrap.xqy | 2 +- src/test/resources/teardown-test-cygwin.sh | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/boot-test-cygwin.sh create mode 100644 src/test/resources/teardown-test-cygwin.sh diff --git a/src/test/resources/boot-test-cygwin.sh b/src/test/resources/boot-test-cygwin.sh new file mode 100644 index 000000000..3da3cf4e4 --- /dev/null +++ b/src/test/resources/boot-test-cygwin.sh @@ -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 diff --git a/src/test/resources/bootstrap.xqy b/src/test/resources/bootstrap.xqy index 7c4831473..2fe65765c 100644 --- a/src/test/resources/bootstrap.xqy +++ b/src/test/resources/bootstrap.xqy @@ -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 ( diff --git a/src/test/resources/teardown-test-cygwin.sh b/src/test/resources/teardown-test-cygwin.sh new file mode 100644 index 000000000..a62bb01a5 --- /dev/null +++ b/src/test/resources/teardown-test-cygwin.sh @@ -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 + From 8f028e708feb5880996ec9438ad89efe1f4bcc52 Mon Sep 17 00:00:00 2001 From: sammefford Date: Thu, 6 Nov 2014 13:19:21 -0700 Subject: [PATCH 2/9] fix #80--intermingled writers were not flushing and therefore behaving inconsitently on different streams in eclipse vs maven (cherry picked from commit 4c0cff98badba1806b7463b9665b940370098a45) --- .../java/com/marklogic/client/alerting/RuleDefinition.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/marklogic/client/alerting/RuleDefinition.java b/src/main/java/com/marklogic/client/alerting/RuleDefinition.java index a3574f3c9..96829f396 100644 --- a/src/main/java/com/marklogic/client/alerting/RuleDefinition.java +++ b/src/main/java/com/marklogic/client/alerting/RuleDefinition.java @@ -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); From 857a8c69ffd402bf5b29ed17cf9ccbafbbc9b0b5 Mon Sep 17 00:00:00 2001 From: sammefford Date: Mon, 21 Apr 2014 12:51:22 -0600 Subject: [PATCH 3/9] fix #101 - (cherry-pick 4f3ee44) use XMLUnit assertXMLEqual to overcome an issue with XML element attribute names out of order (cherry picked from commit 4f3ee4411705aa22939228e2226f6152101ec65a) --- .../test/StructuredQueryBuilderTest.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/marklogic/client/test/StructuredQueryBuilderTest.java b/src/test/java/com/marklogic/client/test/StructuredQueryBuilderTest.java index a8c4a4978..5e22dd38c 100644 --- a/src/test/java/com/marklogic/client/test/StructuredQueryBuilderTest.java +++ b/src/test/java/com/marklogic/client/test/StructuredQueryBuilderTest.java @@ -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; @@ -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; @@ -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 namespaces = new HashMap(); + 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) { @@ -508,7 +539,7 @@ public void testBuilder() throws IOException, SAXException, ParserConfigurationE xml = new StringInputStream(q); parser.parse(xml, handler); - assertEquals( + assertXMLEqual("Geospatial query malformed", " Date: Thu, 12 Jun 2014 14:33:57 -0600 Subject: [PATCH 4/9] fix #100 and #264 - (cherry-pick 43bed84) remove conversion to XML as we no longer have the JSON-XML facade--we now only support reading/writing JSON as JSON (cherry picked from commit 43bed84bddd3fd381522b8bcdaefd65a5d124b6b) --- .../client/test/JSONDocumentTest.java | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/src/test/java/com/marklogic/client/test/JSONDocumentTest.java b/src/test/java/com/marklogic/client/test/JSONDocumentTest.java index 8fcafa834..f826d382e 100644 --- a/src/test/java/com/marklogic/client/test/JSONDocumentTest.java +++ b/src/test/java/com/marklogic/client/test/JSONDocumentTest.java @@ -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; @@ -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; @@ -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 From 2aac19c2bf67e99e712e21f034e5891d8de18736 Mon Sep 17 00:00:00 2001 From: sammefford Date: Tue, 29 Jul 2014 16:03:52 -0700 Subject: [PATCH 5/9] fix #99 - (cherry-pick 253d40a) since REST API was off by one, we were compensating, but we should not anymore (cherry picked from commit 253d40a7db2dcdaca50c8072dd7c6bc6b96fef73) --- src/main/java/com/marklogic/client/impl/BinaryDocumentImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/marklogic/client/impl/BinaryDocumentImpl.java b/src/main/java/com/marklogic/client/impl/BinaryDocumentImpl.java index db711521e..9b8ffdd07 100644 --- a/src/main/java/com/marklogic/client/impl/BinaryDocumentImpl.java +++ b/src/main/java/com/marklogic/client/impl/BinaryDocumentImpl.java @@ -132,7 +132,7 @@ public 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)); From dfa2701fe6c10947b3085bee18fa18dd3f529126 Mon Sep 17 00:00:00 2001 From: Sam Mefford Date: Thu, 7 May 2015 13:54:34 -0600 Subject: [PATCH 6/9] fix #288 - update test to expect the change made to the server-generated binary metadata (cherry picked from commit 97d8f7a3900e0017828a49c4f0717b72cf63cac7) --- .../java/com/marklogic/client/test/BinaryDocumentTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/marklogic/client/test/BinaryDocumentTest.java b/src/test/java/com/marklogic/client/test/BinaryDocumentTest.java index 73373a938..f3c25a7b4 100644 --- a/src/test/java/com/marklogic/client/test/BinaryDocumentTest.java +++ b/src/test/java/com/marklogic/client/test/BinaryDocumentTest.java @@ -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() { @@ -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); } } From d6fc6c3026c1951e62f587857f11b0295b669424 Mon Sep 17 00:00:00 2001 From: Sam Mefford Date: Fri, 6 Nov 2015 11:44:55 -0700 Subject: [PATCH 7/9] fix #176 - deprecate QueryOptionsHandle since it depends on QueryOptions which is already deprecated (cherry picked from commit 338f4e32187e8513d03934438bd921af793e1196) --- .../client/io/QueryOptionsHandle.java | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/marklogic/client/io/QueryOptionsHandle.java b/src/main/java/com/marklogic/client/io/QueryOptionsHandle.java index 0250a71ba..9a30a9027 100644 --- a/src/main/java/com/marklogic/client/io/QueryOptionsHandle.java +++ b/src/main/java/com/marklogic/client/io/QueryOptionsHandle.java @@ -80,27 +80,24 @@ import com.marklogic.client.io.marker.QueryOptionsWriteHandle; /** - * A QueryOptionsHandle is used to configure query configurations. - * - *

Use a QueryOptionsHandle if you want to use Java to configure and manage - * MarkLogic query configurations, for search, value lookups, and facets.

- * - *

Read an options node from MarkLogic with

- * - *
QueryOptionsHandle handle = QueryOptionsManager.readOptions(name, new QueryOptionsHandle());
- * - *

or construct a fresh empty one (which is not a valid configuration without further building)

- * - *
QueryOptionsHandle handle = new QueryOptionsHandle();
- * - *

Build up options to a handle using fluent setter methods

- * - *
handle.withConstraints(...).withTerm(...).withOperators(...)
- * - *

and constructed items from {@link com.marklogic.client.admin.config.QueryOptionsBuilder}.

- * + * @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: + *
{@code
+ *  String opts = new StringBuilder()
+ *      .append("")
+ *      .append(    "true")
+ *      .append("")
+ *      .toString();
+ *  optsMgr.writeOptions("debug", new StringHandle(opts)); }
+ * or + *
{@code
+ *  String opts = "{\"options\":{\"debug\":true}}";
+ *  optsMgr.writeOptions("debug", new StringHandle(opts).withFormat(Format.JSON)); }
*/ -@SuppressWarnings("deprecation") +@Deprecated public final class QueryOptionsHandle extends BaseHandle implements OutputStreamSender, BufferableHandle, From a82df17fd822bf596739de15067ee02a27d40b2b Mon Sep 17 00:00:00 2001 From: Sam Mefford Date: Fri, 6 Nov 2015 15:07:23 -0700 Subject: [PATCH 8/9] fix #266 - missing namespace in document properties --- .../java/com/marklogic/client/io/DocumentMetadataHandle.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/marklogic/client/io/DocumentMetadataHandle.java b/src/main/java/com/marklogic/client/io/DocumentMetadataHandle.java index 62ce84493..c06f95efc 100644 --- a/src/main/java/com/marklogic/client/io/DocumentMetadataHandle.java +++ b/src/main/java/com/marklogic/client/io/DocumentMetadataHandle.java @@ -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; From d70139acba5310865aae2ed51b3308e56e5170a6 Mon Sep 17 00:00:00 2001 From: Ajit George Date: Thu, 28 Jan 2016 11:50:55 -0800 Subject: [PATCH 9/9] updating version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 43f1b6821..12561d8af 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.marklogic java-client-api jar - 2.0-SNAPSHOT + 2.0.6 MarkLogic Java Client API The official MarkLogic Java client API. https://github.com/marklogic/java-client-api