Skip to content

Commit 00b604d

Browse files
committed
add test for default metadata
1 parent b0c4235 commit 00b604d

File tree

2 files changed

+76
-12
lines changed

2 files changed

+76
-12
lines changed

src/main/java/com/marklogic/client/impl/DocumentWriteSetImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,25 @@ public DocumentWriteSet addDefault(DocumentMetadataWriteHandle metadataHandle) {
3333
}
3434

3535
public DocumentWriteSet add(String docId, AbstractWriteHandle contentHandle) {
36-
add(new DocumentWriteOperationImpl(OperationType.METADATA_DEFAULT,
36+
add(new DocumentWriteOperationImpl(OperationType.DOCUMENT_WRITE,
3737
docId, null, contentHandle));
3838
return this;
3939
}
4040

4141
public DocumentWriteSet add(String docId, DocumentMetadataWriteHandle metadataHandle, AbstractWriteHandle contentHandle) {
42-
add(new DocumentWriteOperationImpl(OperationType.METADATA_DEFAULT,
42+
add(new DocumentWriteOperationImpl(OperationType.DOCUMENT_WRITE,
4343
docId, metadataHandle, contentHandle));
4444
return this;
4545
}
4646

4747
public DocumentWriteSet add(DocumentDescriptor desc, AbstractWriteHandle contentHandle) {
48-
add(new DocumentWriteOperationImpl(OperationType.METADATA_DEFAULT,
48+
add(new DocumentWriteOperationImpl(OperationType.DOCUMENT_WRITE,
4949
desc.getUri(), null, contentHandle));
5050
return this;
5151
}
5252

5353
public DocumentWriteSet add(DocumentDescriptor desc, DocumentMetadataWriteHandle metadataHandle, AbstractWriteHandle contentHandle) {
54-
add(new DocumentWriteOperationImpl(OperationType.METADATA_DEFAULT,
54+
add(new DocumentWriteOperationImpl(OperationType.DOCUMENT_WRITE,
5555
desc.getUri(), metadataHandle, contentHandle));
5656
return this;
5757
}

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

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import java.util.HashMap;
2121
import java.util.Map;
22+
import java.util.Set;
2223
import java.util.logging.FileHandler;
2324
import java.util.logging.Handler;
2425
import java.util.logging.Logger;
@@ -71,7 +72,6 @@ public static void beforeClass() throws JAXBException {
7172
Common.connect();
7273
context = JAXBContext.newInstance(City.class);
7374
//System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "debug");
74-
//System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug");
7575
}
7676
@AfterClass
7777
public static void afterClass() {
@@ -107,7 +107,7 @@ public void finishBatch() {
107107
}
108108

109109
public void setNumRecords(int numWritten) {
110-
assertEquals("Number of records not expected", numWritten, RECORDS_EXPECTED);
110+
assertEquals("Number of records not expected", RECORDS_EXPECTED, numWritten);
111111
}
112112
}
113113

@@ -150,12 +150,12 @@ static void loadCities(CityWriter cityWriter) throws Exception {
150150

151151

152152
@Test
153-
public void testBulkLoad() throws IOException, Exception {
153+
public void testA_BulkLoad() throws IOException, Exception {
154154
loadCities(new BulkCityWriter());
155155
}
156156

157157
@Test
158-
public void testBulkRead() {
158+
public void testB_BulkRead() {
159159
XMLDocumentManager docMgr = Common.client.newXMLDocumentManager();
160160

161161
DocumentPage page = docMgr.read(DIRECTORY + "1016670.xml", DIRECTORY + "108410.xml", DIRECTORY + "1205733.xml");
@@ -169,7 +169,7 @@ public void testBulkRead() {
169169
}
170170

171171
@Test
172-
public void testBulkSearch() {
172+
public void testC_BulkSearch() {
173173
XMLDocumentManager docMgr = Common.client.newXMLDocumentManager();
174174

175175
SearchHandle searchHandle = new SearchHandle();
@@ -188,7 +188,7 @@ public void testBulkSearch() {
188188

189189
//public void testMixedLoad() {
190190
@Test
191-
public void testJsonLoad() {
191+
public void testD_JsonLoad() {
192192
JSONDocumentManager docMgr = Common.client.newJSONDocumentManager();
193193

194194
StringHandle doc1 =
@@ -244,8 +244,8 @@ public static void validateChittagong(City chittagong) {
244244
}
245245

246246
@Test
247-
public void testTextLoad() {
248-
String docId[] = {"/foo/test/myFoo1.xml","/foo/test/myFoo2.xml","/foo/test/myFoo3.xml"};
247+
public void testE_TextLoad() {
248+
String docId[] = {"/foo/test/myFoo1.txt","/foo/test/myFoo2.txt","/foo/test/myFoo3.txt"};
249249
TextDocumentManager docMgr = Common.client.newTextDocumentManager();
250250
DocumentWriteSet writeset =docMgr.newWriteSet();
251251

@@ -263,6 +263,70 @@ public void testTextLoad() {
263263
docMgr.delete(docId[2]);
264264
}
265265

266+
@Test
267+
public void testF_DefaultMetadata() {
268+
// Synthesize input content
269+
StringHandle doc1 = new StringHandle(
270+
"{\"number\": 1}").withFormat(Format.JSON);
271+
StringHandle doc2 = new StringHandle(
272+
"{\"number\": 2}").withFormat(Format.JSON);
273+
StringHandle doc3 = new StringHandle(
274+
"{\"number\": 3}").withFormat(Format.JSON);
275+
StringHandle doc4 = new StringHandle(
276+
"{\"number\": 4}").withFormat(Format.JSON);
277+
StringHandle doc5 = new StringHandle(
278+
"{\"number\": 5}").withFormat(Format.JSON);
279+
280+
// Synthesize input metadata
281+
DocumentMetadataHandle defaultMetadata1 =
282+
new DocumentMetadataHandle().withQuality(1);
283+
DocumentMetadataHandle defaultMetadata2 =
284+
new DocumentMetadataHandle().withQuality(2);
285+
DocumentMetadataHandle docSpecificMetadata =
286+
new DocumentMetadataHandle().withCollections("myCollection");
287+
288+
// Create and build up the batch
289+
JSONDocumentManager jdm = Common.client.newJSONDocumentManager();
290+
DocumentWriteSet batch = jdm.newWriteSet();
291+
292+
// use system default metadata
293+
batch.add("doc1.json", doc1); // system default metadata
294+
295+
// using batch default metadata
296+
batch.addDefault(defaultMetadata1);
297+
batch.add("doc2.json", doc2); // batch default metadata
298+
batch.add("doc3.json", docSpecificMetadata, doc3);
299+
batch.add("doc4.json", doc4); // batch default metadata
300+
301+
// replace batch default metadata with new metadata
302+
batch.addDefault(defaultMetadata2);
303+
batch.add("doc5.json", doc5); // batch default
304+
305+
// Execute the write operation
306+
jdm.write(batch);
307+
308+
// Check the results
309+
assertEquals("Doc1 should have the system default quality of 0", 0,
310+
jdm.readMetadata("doc1.json", new DocumentMetadataHandle()).getQuality());
311+
assertEquals("Doc2 should use the first batch default metadata, with quality 1", defaultMetadata1.getQuality(),
312+
jdm.readMetadata("doc2.json", new DocumentMetadataHandle()).getQuality());
313+
314+
DocumentMetadataHandle doc3Metadata =
315+
jdm.readMetadata("doc3.json", new DocumentMetadataHandle());
316+
assertEquals("Doc3 should have the system default document quality (0) because quality " +
317+
"was not included in the document-specific metadata.", 0, doc3Metadata.getQuality());
318+
Set collections = doc3Metadata.getCollections();
319+
assertEquals("Doc3 should be in exactly one collection from the document-specific metadata.", 1, collections.size());
320+
assertEquals("Doc3 should be in the collection \"myCollection\", from the document-specific metadata.",
321+
"myCollection", collections.iterator().next());
322+
323+
//
324+
assertEquals("Doc4 should also use the 1st batch default metadata, with quality 1", defaultMetadata1.getQuality(),
325+
jdm.readMetadata("doc4.json", new DocumentMetadataHandle()).getQuality());
326+
assertEquals("Doc5 should use the 2nd batch default metadata, with quality 2", defaultMetadata2.getQuality(),
327+
jdm.readMetadata("doc5.json", new DocumentMetadataHandle()).getQuality());
328+
}
329+
266330

267331
private static void addCountry(String line, Map<String, Country> countries) {
268332
// skip comment lines

0 commit comments

Comments
 (0)