|
4 | 4 | import static org.junit.Assert.assertNotNull; |
5 | 5 | import static org.junit.Assert.assertTrue; |
6 | 6 |
|
7 | | -import java.io.File; |
8 | 7 | import java.util.Calendar; |
9 | 8 |
|
10 | 9 | import org.junit.After; |
|
13 | 12 | import org.junit.BeforeClass; |
14 | 13 | import org.junit.Test; |
15 | 14 |
|
16 | | -import com.fasterxml.jackson.core.JsonFactory; |
17 | 15 | import com.marklogic.client.DatabaseClient; |
18 | 16 | import com.marklogic.client.DatabaseClientFactory; |
19 | 17 | import com.marklogic.client.DatabaseClientFactory.Authentication; |
@@ -154,61 +152,52 @@ public void validateDefaultMetadata(DocumentMetadataHandle mh){ |
154 | 152 |
|
155 | 153 | /* |
156 | 154 | * 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 | + * |
158 | 156 | */ |
159 | 157 | @Test |
160 | 158 | public void testWriteMultipleJSONFiles() throws Exception { |
161 | 159 |
|
162 | | - String docId[] = {"/apple.json","/microsoft.json","/hp.json"}; |
| 160 | + String docId = "/"; |
163 | 161 |
|
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"; |
174 | 166 |
|
175 | 167 | JSONDocumentManager docMgr = client.newJSONDocumentManager(); |
176 | 168 | docMgr.setMetadataCategories(Metadata.ALL); |
177 | | - DocumentWriteSet writeset = docMgr.newWriteSet(); |
178 | 169 | // put meta-data |
179 | 170 | DocumentMetadataHandle mh = setMetadata(); |
180 | | - DocumentMetadataHandle mhRead = new DocumentMetadataHandle(); |
181 | | - |
182 | | - JsonFactory f = new JsonFactory(); |
183 | 171 |
|
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"); |
200 | 176 |
|
201 | 177 | //Read it back into JacksonDatabindHandle Product |
202 | 178 | JacksonDatabindHandle<Product> handleRead = new JacksonDatabindHandle<Product>(Product.class); |
203 | 179 |
|
204 | | - // Do we iterate individually ? |
205 | | - docMgr.read(docId[0], handleRead); |
| 180 | + // Read into JacksonDatabindHandle |
| 181 | + docMgr.read(docId+jsonFilename1, handleRead); |
206 | 182 | 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(); |
207 | 189 |
|
208 | 190 | 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")); |
211 | 197 |
|
| 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")); |
212 | 201 | } |
213 | 202 |
|
214 | 203 | @Test |
|
0 commit comments