Skip to content

Commit cf5733c

Browse files
Ajit GeorgeAjit George
authored andcommitted
Fixed TestBulkReadWriteWithJacksonDataBind.java regression
1 parent a3fb117 commit cf5733c

File tree

1 file changed

+27
-38
lines changed

1 file changed

+27
-38
lines changed

test-complete/src/test/java/com/marklogic/javaclient/TestBulkReadWriteWithJacksonDataBind.java

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import static org.junit.Assert.assertNotNull;
55
import static org.junit.Assert.assertTrue;
66

7-
import java.io.File;
87
import java.util.Calendar;
98

109
import org.junit.After;
@@ -13,7 +12,6 @@
1312
import org.junit.BeforeClass;
1413
import org.junit.Test;
1514

16-
import com.fasterxml.jackson.core.JsonFactory;
1715
import com.marklogic.client.DatabaseClient;
1816
import com.marklogic.client.DatabaseClientFactory;
1917
import com.marklogic.client.DatabaseClientFactory.Authentication;
@@ -154,61 +152,52 @@ public void validateDefaultMetadata(DocumentMetadataHandle mh){
154152

155153
/*
156154
* This method is place holder to test JacksonDatabindHandle handling file writing / reading (Streams)
157-
* Need to be completed once JacksonDatabindHandle has the necessary support.
155+
*
158156
*/
159157
@Test
160158
public void testWriteMultipleJSONFiles() throws Exception {
161159

162-
String docId[] = {"/apple.json","/microsoft.json","/hp.json"};
160+
String docId = "/";
163161

164-
// Work yet to be done
165-
// Each of these files can contain multiple products. Need to Read these files and then the JSON content.
166-
167-
String jsonFilename1 = "AppleProducts.json";
168-
String jsonFilename2 = "MicrosoftProducts.json";
169-
String jsonFilename3 = "HpProducts.json";
170-
171-
File jsonFile1 = new File("src/test/java/com/marklogic/javaclient/data/" + jsonFilename1);
172-
File jsonFile2 = new File("src/test/java/com/marklogic/javaclient/data/" + jsonFilename2);
173-
File jsonFile3 = new File("src/test/java/com/marklogic/javaclient/data/" + jsonFilename3);
162+
//These files need to be in src/test/java/com/marklogic/javaclient/data/ folder.
163+
String jsonFilename1 = "product-apple.json";
164+
String jsonFilename2 = "product-microsoft.json";
165+
String jsonFilename3 = "product-hp.json";
174166

175167
JSONDocumentManager docMgr = client.newJSONDocumentManager();
176168
docMgr.setMetadataCategories(Metadata.ALL);
177-
DocumentWriteSet writeset = docMgr.newWriteSet();
178169
// put meta-data
179170
DocumentMetadataHandle mh = setMetadata();
180-
DocumentMetadataHandle mhRead = new DocumentMetadataHandle();
181-
182-
JsonFactory f = new JsonFactory();
183171

184-
JacksonDatabindHandle<File> handle1 = new JacksonDatabindHandle<File>(File.class);
185-
JacksonDatabindHandle<File> handle2 = new JacksonDatabindHandle<File>(File.class);
186-
JacksonDatabindHandle<File> handle3 = new JacksonDatabindHandle<File>(File.class);
187-
188-
// Add meta-data
189-
writeset.addDefault(mh);
190-
191-
handle1.set(jsonFile1);
192-
handle2.set(jsonFile2);
193-
handle3.set(jsonFile3);
194-
195-
writeset.add(docId[0], handle1);
196-
writeset.add(docId[1], handle2);
197-
writeset.add(docId[2], handle3);
198-
199-
docMgr.write(writeset);
172+
//Read from file system 3 files and write them into the database.
173+
writeDocumentUsingOutputStreamHandle(client, jsonFilename1, docId, mh, "JSON");
174+
writeDocumentUsingOutputStreamHandle(client, jsonFilename2, docId, mh, "JSON");
175+
writeDocumentUsingOutputStreamHandle(client, jsonFilename3, docId, mh, "JSON");
200176

201177
//Read it back into JacksonDatabindHandle Product
202178
JacksonDatabindHandle<Product> handleRead = new JacksonDatabindHandle<Product>(Product.class);
203179

204-
// Do we iterate individually ?
205-
docMgr.read(docId[0], handleRead);
180+
// Read into JacksonDatabindHandle
181+
docMgr.read(docId+jsonFilename1, handleRead);
206182
Product product1 = (Product) handleRead.get();
183+
184+
docMgr.read(docId+jsonFilename2, handleRead);
185+
Product product2 = (Product) handleRead.get();
186+
187+
docMgr.read(docId+jsonFilename3, handleRead);
188+
Product product3 = (Product) handleRead.get();
207189

208190
assertTrue("Did not return a iPhone 6", product1.getName().equalsIgnoreCase("iPhone 6"));
209-
assertTrue("Did not return a Mobile Phone", product1.getIndustry().equalsIgnoreCase("Mobile Phone"));
210-
assertTrue("Did not return a Mobile Phone", product1.getDescription().equalsIgnoreCase("New iPhone 6"));
191+
assertTrue("Did not return a Mobile Phone", product1.getIndustry().equalsIgnoreCase("Mobile Hardware"));
192+
assertTrue("Did not return a Mobile Phone", product1.getDescription().equalsIgnoreCase("Bending Iphone"));
193+
194+
assertTrue("Did not return a iPhone 6", product2.getName().equalsIgnoreCase("Windows 10"));
195+
assertTrue("Did not return a Mobile Phone", product2.getIndustry().equalsIgnoreCase("Software"));
196+
assertTrue("Did not return a Mobile Phone", product2.getDescription().equalsIgnoreCase("OS Server"));
211197

198+
assertTrue("Did not return a iPhone 6", product3.getName().equalsIgnoreCase("Elite Book"));
199+
assertTrue("Did not return a Mobile Phone", product3.getIndustry().equalsIgnoreCase("PC Hardware"));
200+
assertTrue("Did not return a Mobile Phone", product3.getDescription().equalsIgnoreCase("Very cool laptop"));
212201
}
213202

214203
@Test

0 commit comments

Comments
 (0)