|
24 | 24 | import java.io.StringReader; |
25 | 25 |
|
26 | 26 | import javax.xml.bind.JAXBContext; |
| 27 | + |
27 | 28 | import com.marklogic.client.DatabaseClient; |
28 | 29 | import com.marklogic.client.DatabaseClientFactory; |
29 | 30 | import com.marklogic.client.DatabaseClientFactory.Authentication; |
| 31 | +import com.marklogic.client.ResourceNotFoundException; |
30 | 32 | import com.marklogic.client.document.TextDocumentManager; |
31 | 33 | import com.marklogic.client.document.XMLDocumentManager; |
32 | 34 | import com.marklogic.client.document.BinaryDocumentManager; |
|
49 | 51 |
|
50 | 52 |
|
51 | 53 |
|
| 54 | + |
52 | 55 | import javax.xml.transform.dom.DOMSource; |
53 | 56 |
|
54 | 57 | import com.fasterxml.jackson.databind.JsonNode; |
@@ -133,7 +136,11 @@ public void testWriteMultipleTextDoc() |
133 | 136 | assertEquals("Text document write difference", "This is so foo1", docMgr.read(docId[0], new StringHandle()).get()); |
134 | 137 | assertEquals("Text document write difference", "This is so foo2", docMgr.read(docId[1], new StringHandle()).get()); |
135 | 138 | assertEquals("Text document write difference", "This is so foo3", docMgr.read(docId[2], new StringHandle()).get()); |
| 139 | + |
| 140 | + //Bulk delete on TextDocumentManager |
| 141 | + docMgr.delete(docId[0],docId[1],docId[2]); |
136 | 142 | } |
| 143 | + |
137 | 144 | /* |
138 | 145 | * This test uses DOMHandle to load 3 xml documents, writes to database using bulk write set. |
139 | 146 | * Verified by reading individual documents |
@@ -162,6 +169,9 @@ public void testWriteMultipleXMLDoc() throws Exception |
162 | 169 | assertEquals("xml document write difference", "This is so foo2", dh.get().getChildNodes().item(0).getTextContent()); |
163 | 170 | docMgr.read(docId[2], dh); |
164 | 171 | assertEquals("xml document write difference", "This is so foo3", dh.get().getChildNodes().item(0).getTextContent()); |
| 172 | + |
| 173 | + //Bulk delete on XMLDocumentManager |
| 174 | + docMgr.delete(docId[0],docId[1],docId[2]); |
165 | 175 | } |
166 | 176 | /* |
167 | 177 | * This test uses FileHandle to load 3 binary documents with same URI, writes to database using bulk write set. |
@@ -217,6 +227,14 @@ public void testWriteMultipleBinaryDoc() throws Exception |
217 | 227 | System.out.println(file2.getName()+":"+fsize2+" "+readHandle2.get().getName()+":"+readHandle2.get().length()); |
218 | 228 | assertEquals("Size of the File 1"+docId[0],fsize1,readHandle1.get().length()); |
219 | 229 | assertEquals("Size of the File 1"+docId[1],fsize2,readHandle2.get().length()); |
| 230 | + |
| 231 | + //Bulk delete test - Git 284 |
| 232 | + String doc0 = "/1/"+docId[0]; |
| 233 | + String doc1 = "/2/"+docId[0]; |
| 234 | + String doc2 = "/1/"+docId[1]; |
| 235 | + String doc3 = "/2/"+docId[1]; |
| 236 | + |
| 237 | + docMgr.delete(doc0,doc1,doc2,doc3); |
220 | 238 | } |
221 | 239 |
|
222 | 240 | /* |
@@ -285,7 +303,6 @@ public void testWriteMultipleJAXBDocs() throws Exception |
285 | 303 | assertEquals("xml document write difference", "Very cool Ipad", dh.get().getChildNodes().item(0).getChildNodes().item(1).getTextContent()); |
286 | 304 | docMgr.read(docId[2], dh); |
287 | 305 | assertEquals("xml document write difference", "Very cool Ipod", dh.get().getChildNodes().item(0).getChildNodes().item(1).getTextContent()); |
288 | | - |
289 | 306 | } |
290 | 307 | /* |
291 | 308 | * This test uses GenericManager to load all different document types |
@@ -352,6 +369,10 @@ public void testWriteGenericDocMgr() throws Exception |
352 | 369 | assertEquals("Json document write difference", "{\"animal\":\"dog\", \"says\":\"woof\"}", br.readLine() ); |
353 | 370 | br.close(); |
354 | 371 | fis.close(); |
| 372 | + |
| 373 | + //Bulk delete on GenericDocumentManager - Git 284 |
| 374 | + String doc1 = "/generic/"+docId[0]; |
| 375 | + docMgr.delete(doc1,"/generic/foo.xml","/generic/foo1.txt", "/generic/dog.json"); |
355 | 376 | } |
356 | 377 |
|
357 | 378 | @Test |
@@ -395,8 +416,56 @@ public void testWriteMultipleJacksonPoJoDocs() throws Exception |
395 | 416 | docMgr.read(docId[2], jh); |
396 | 417 | exp="{\"name\":\"iPod\",\"industry\":\"Hardware\",\"description\":\"Very cool Ipod\"}"; |
397 | 418 | JSONAssert.assertEquals(exp,jh.get().toString() , false); |
| 419 | + |
| 420 | + //Test bulk delete on JSONDocumentManager |
| 421 | + docMgr.delete(docId[0],docId[1],docId[2]); |
398 | 422 |
|
399 | 423 | } |
| 424 | + |
| 425 | + @Test(expected=ResourceNotFoundException.class) |
| 426 | + public void testJAXBDocsBulkDelete() throws Exception |
| 427 | + { |
| 428 | + String docId[] ={"/jaxb/iphone.xml","/jaxb/ipad.xml","/jaxb/ipod.xml"}; |
| 429 | + Product product1 = new Product(); |
| 430 | + product1.setName("iPhone"); |
| 431 | + product1.setIndustry("Hardware"); |
| 432 | + product1.setDescription("Very cool Iphone"); |
| 433 | + Product product2 = new Product(); |
| 434 | + product2.setName("iPad"); |
| 435 | + product2.setIndustry("Hardware"); |
| 436 | + product2.setDescription("Very cool Ipad"); |
| 437 | + Product product3 = new Product(); |
| 438 | + product3.setName("iPod"); |
| 439 | + product3.setIndustry("Hardware"); |
| 440 | + product3.setDescription("Very cool Ipod"); |
| 441 | + JAXBContext context = JAXBContext.newInstance(Product.class); |
| 442 | + XMLDocumentManager docMgr = client.newXMLDocumentManager(); |
| 443 | + DocumentWriteSet writeset =docMgr.newWriteSet(); |
| 444 | + |
| 445 | + writeset.add(docId[0],new JAXBHandle<Product>(context).with(product1)); |
| 446 | + writeset.add(docId[1],new JAXBHandle<Product>(context).with(product2)); |
| 447 | + writeset.add(docId[2],new JAXBHandle<Product>(context).with(product3)); |
| 448 | + |
| 449 | + docMgr.write(writeset); |
| 450 | + |
| 451 | + DOMHandle dh = new DOMHandle(); |
| 452 | + docMgr.read(docId[0], dh); |
| 453 | + |
| 454 | + assertEquals("xml document write difference", "Very cool Iphone",dh.get().getChildNodes().item(0).getChildNodes().item(1).getTextContent()); |
| 455 | + docMgr.read(docId[1], dh); |
| 456 | + assertEquals("xml document write difference", "Very cool Ipad", dh.get().getChildNodes().item(0).getChildNodes().item(1).getTextContent()); |
| 457 | + docMgr.read(docId[2], dh); |
| 458 | + assertEquals("xml document write difference", "Very cool Ipod", dh.get().getChildNodes().item(0).getChildNodes().item(1).getTextContent()); |
| 459 | + |
| 460 | + //Bulk delete on XMLDocumentManager |
| 461 | + docMgr.delete(docId[0],docId[1],docId[2]); |
| 462 | + |
| 463 | + // Try reading back the deleted document. |
| 464 | + DOMHandle rhDeleted = new DOMHandle(); |
| 465 | + |
| 466 | + //Make sure that bulk delete indeed worked. Should throw ResourceNotFoundException. |
| 467 | + docMgr.read("/generic/"+docId[0],rhDeleted); |
| 468 | + } |
400 | 469 | @AfterClass |
401 | 470 | public static void tearDown() throws Exception |
402 | 471 | { |
|
0 commit comments