Skip to content

Commit c0c7837

Browse files
committed
Fixing bug where a 'naked' properties fragment cannot be written
The check on content being null was overly restrictive, as v1/documents allows for null content. This may cause some other DMSDK test to fail, in which case that test will be modified as null content is allowable here.
1 parent 3c9e926 commit c0c7837

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/impl/WriteBatcherImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ public WriteBatcher addAs(String uri, Object content) {
207207

208208
@Override
209209
public WriteBatcher add(DocumentWriteOperation writeOperation) {
210-
if ( writeOperation.getUri() == null ) throw new IllegalArgumentException("uri must not be null");
211-
if ( writeOperation.getContent() == null ) throw new IllegalArgumentException("contentHandle must not be null");
210+
if (writeOperation.getUri() == null) throw new IllegalArgumentException("uri must not be null");
211+
// Prior to 6.6.1 and higher, threw an exception here if the content was null. But that was not necessary - the
212+
// v1/documents endpoint supports writing a 'naked' properties fragment with no content.
212213
initialize();
213214
requireNotStopped();
214215
queue.add(writeOperation);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.marklogic.client.test.datamovement;
2+
3+
import com.marklogic.client.DatabaseClient;
4+
import com.marklogic.client.datamovement.DataMovementManager;
5+
import com.marklogic.client.datamovement.WriteBatcher;
6+
import com.marklogic.client.io.DocumentMetadataHandle;
7+
import com.marklogic.client.test.Common;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
10+
11+
import javax.xml.namespace.QName;
12+
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
import static org.junit.jupiter.api.Assertions.assertTrue;
15+
16+
public class WriteNakedPropertiesTest {
17+
18+
@BeforeEach
19+
void setup() {
20+
Common.newRestAdminClient().newXMLDocumentManager().delete("/naked.xml");
21+
}
22+
23+
@Test
24+
void test() {
25+
DatabaseClient client = Common.newClient();
26+
DataMovementManager dmm = client.newDataMovementManager();
27+
WriteBatcher writeBatcher = dmm.newWriteBatcher();
28+
dmm.startJob(writeBatcher);
29+
30+
DocumentMetadataHandle metadata = new DocumentMetadataHandle();
31+
metadata.getProperties().put(new QName("org:example", "hello"), "world");
32+
writeBatcher.add("/naked.xml", metadata, null);
33+
writeBatcher.flushAndWait();
34+
dmm.stopJob(writeBatcher);
35+
36+
DatabaseClient evalClient = Common.newEvalClient();
37+
String properties = evalClient.newServerEval()
38+
.xquery("xdmp:document-properties('/naked.xml')").evalAs(String.class);
39+
assertTrue(properties.contains("world"), "Should be able to read the 'naked' properties fragment, " +
40+
"which verifies that it was written correctly, even with the content handle being null.");
41+
42+
String output = evalClient.newServerEval().xquery("fn:doc-available('/naked.xml')").evalAs(String.class);
43+
assertEquals("false", output, "No document exists, only a properties fragment.");
44+
}
45+
}

0 commit comments

Comments
 (0)