Skip to content

Commit c137912

Browse files
committed
testing #783 - making sure we can stream when also receiving metadata
1 parent ad9c091 commit c137912

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import static org.junit.Assert.assertTrue;
2020

2121
import java.io.IOException;
22+
import java.io.InputStream;
23+
import java.io.File;
2224
import java.util.ArrayList;
2325

2426
import javax.xml.parsers.DocumentBuilderFactory;
@@ -34,13 +36,16 @@
3436
import org.w3c.dom.NodeList;
3537
import org.xml.sax.SAXException;
3638

39+
import com.marklogic.client.Transaction;
3740
import com.marklogic.client.document.DocumentManager.Metadata;
3841
import com.marklogic.client.document.XMLDocumentManager;
3942
import com.marklogic.client.io.DocumentMetadataHandle;
4043
import com.marklogic.client.io.DocumentMetadataHandle.Capability;
4144
import com.marklogic.client.io.DocumentMetadataHandle.DocumentCollections;
4245
import com.marklogic.client.io.DocumentMetadataHandle.DocumentPermissions;
4346
import com.marklogic.client.io.DocumentMetadataHandle.DocumentProperties;
47+
import com.marklogic.client.io.FileHandle;
48+
import com.marklogic.client.io.InputStreamHandle;
4449
import com.marklogic.client.io.StringHandle;
4550

4651
public class DocumentMetadataHandleTest {
@@ -165,4 +170,26 @@ public void testReadWriteMetadata() throws SAXException, IOException, XpathExcep
165170
assertEquals("Wrong quality", 3, metaReadHandle.getQuality());
166171
}
167172
}
173+
174+
// testing https://github.com/marklogic/java-client-api/issues/783
175+
@Test
176+
public void testStack20170725() throws IOException {
177+
XMLDocumentManager documentManager = Common.client.newXMLDocumentManager();
178+
Transaction transaction = Common.client.openTransaction();
179+
DocumentMetadataHandle metadataHandle = new DocumentMetadataHandle();
180+
documentManager.writeAs("all_well.xml", new FileHandle(
181+
new File("test-complete/src/test/java/com/marklogic/client/functionaltest/data/all_well.xml")));
182+
InputStreamHandle handle = documentManager.read("all_well.xml", metadataHandle, new InputStreamHandle(), transaction);
183+
try {
184+
InputStream stream = handle.get();
185+
try {
186+
while ( stream.read() > -1 ) {}
187+
} finally {
188+
stream.close();
189+
}
190+
} finally {
191+
handle.close();
192+
}
193+
// if we ran without throwing any exceptions, then this test passes
194+
}
168195
}

0 commit comments

Comments
 (0)