|
| 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