Skip to content

Commit c969bdc

Browse files
committed
Merge remote-tracking branch 'origin/newRegressionTests' into dev
2 parents a983cd4 + fea7184 commit c969bdc

File tree

8 files changed

+65
-90
lines changed

8 files changed

+65
-90
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

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public class TestBulkWriteWithTransformations extends BasicJavaClientREST{
4040
private static String restServerName = "REST-Java-Client-API-Server";
4141
private static int restPort = 8011;
4242
private DatabaseClient client ;
43+
// Additional port to test for Uber port
44+
private static int uberPort = 8000;
4345

4446
@BeforeClass
4547
public static void setUpBeforeClass() throws Exception {
@@ -58,7 +60,9 @@ public static void tearDownAfterClass() throws Exception {
5860
public void setUp() throws Exception {
5961
// System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "debug");
6062
// create new connection for each test below
61-
client = DatabaseClientFactory.newClient("localhost", restPort, "rest-admin", "x", Authentication.DIGEST);
63+
createUserRolesWithPrevilages("test-eval","xdbc:eval", "xdbc:eval-in","xdmp:eval-in","any-uri","xdbc:invoke");
64+
createRESTUser("eval-user", "x", "test-eval","rest-admin","rest-writer","rest-reader");
65+
client = DatabaseClientFactory.newClient("localhost", uberPort, dbName, "eval-user", "x", Authentication.DIGEST);
6266
}
6367

6468
@After

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

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ public void setInventory(int inventory) {
154154

155155
@BeforeClass
156156
public static void setUpBeforeClass() throws Exception {
157-
// System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire",
158-
// "debug");
159157
System.out.println("In setup");
160158
setupJavaRESTServer(dbName, fNames[0], restServerName, restPort);
161159
}
@@ -212,11 +210,11 @@ public void validateMissingArtifactGetter(SmallArtifactMissingGetter artifact) {
212210
/*
213211
* This method is used when there is a need to validate SmallArtifactMissingSetter.
214212
*/
215-
public void validateMissingArtifactSetter(SmallArtifactMissingSetter artifact) {
213+
public void validateMissingArtifactSetter(SmallArtifactMissingSetter artifact, String name) {
216214
assertNotNull("Artifact object should never be Null", artifact);
217215
assertNotNull("Id should never be Null", artifact.id);
218216
assertEquals("Id of the object is ", -99, artifact.getId());
219-
assertEquals("Name of the object is ", "SmallArtifact",
217+
assertEquals("Name of the object is ", name,
220218
artifact.getName());
221219
assertEquals("Inventory of the object is ", 1000,
222220
artifact.getInventory());
@@ -239,9 +237,6 @@ public void validateMissingArtifactGetSet(SmallArtifactMissGetSet artifact) {
239237
* Purpose : This test is to validate read documents stored with JacksonHandle with valid POJO
240238
* specific URI. Uses SmallArtifactMissingSetter class
241239
* which has @Id only on the setter method.
242-
*
243-
* Current results (10/13/2014) are: read returns a null
244-
*
245240
*/
246241

247242
@Test
@@ -250,7 +245,7 @@ public void testPOJOReadMissingSetter() throws Exception {
250245
String docId[] = { "com.marklogic.javaclient.TestPOJOMissingIdGetSetMethod$SmallArtifactMissingSetter/SmallArtifactMissingSetter.json" };
251246
String json1 = new String(
252247
"{\"com.marklogic.javaclient.TestPOJOMissingIdGetSetMethod$SmallArtifactMissingSetter\":"
253-
+ "{\"name\": \"SmallArtifact\",\"id\": -99, \"inventory\": 1000}}");
248+
+ "{\"name\": \"SmallArtifactMissingSetter\",\"id\": -99, \"inventory\": 1000}}");
254249
JSONDocumentManager docMgr = client.newJSONDocumentManager();
255250
docMgr.setMetadataCategories(Metadata.ALL);
256251
DocumentWriteSet writeset = docMgr.newWriteSet();
@@ -275,21 +270,16 @@ public void testPOJOReadMissingSetter() throws Exception {
275270

276271
PojoRepository<SmallArtifactMissingSetter, String> pojoReposSmallArtifact = client
277272
.newPojoRepository(SmallArtifactMissingSetter.class, String.class);
278-
String artifactName = new String("SmallArtifact");
273+
String artifactName = new String("SmallArtifactMissingSetter");
279274

280275
SmallArtifactMissingSetter artifact1 = pojoReposSmallArtifact.read(artifactName);
281-
validateMissingArtifactSetter(artifact1);
276+
validateMissingArtifactSetter(artifact1, artifactName);
282277
}
283278

284279
/*
285280
* Purpose : This test is to validate read documents stored with JacksonHandle with valid POJO
286281
* specific URI. Uses SmallArtifactMissingGetter class
287-
* which has @Id only on the setter method.
288-
*
289-
* Current results (10/13/2014) are:
290-
* java.lang.IllegalArgumentException: Your getter method, setName, annotated with
291-
* com.marklogic.client.pojo.annotation.Id must not require any arguments.
292-
* Issue 136 might solve this also.
282+
* which has @Id only on the setter method.
293283
*/
294284

295285
@Test
@@ -332,12 +322,7 @@ public void testPOJOReadMissingGetter() throws Exception {
332322
/*
333323
* Purpose : This test is to validate read documents with valid POJO
334324
* specific URI. Uses SmallArtifactMissingGetter class
335-
* which has @Id only on the setter method.
336-
*
337-
* Current results (10/13/2014) are:
338-
* java.lang.IllegalArgumentException: Your getter method, setName, annotated with
339-
* com.marklogic.client.pojo.annotation.Id must not require any arguments.
340-
* Issue 136 might solve this also.
325+
* which has @Id only on the setter method.
341326
*/
342327
@Test
343328
public void testPOJOWriteReadMissingGetter() throws Exception {
@@ -347,7 +332,7 @@ public void testPOJOWriteReadMissingGetter() throws Exception {
347332
String artifactName = new String("SmallArtifact");
348333

349334
SmallArtifactMissingGetter art = new SmallArtifactMissingGetter();
350-
art.setId(0);
335+
art.setId(-99L);
351336
art.setInventory(1000);
352337
art.setName(artifactName);
353338

@@ -361,38 +346,32 @@ public void testPOJOWriteReadMissingGetter() throws Exception {
361346
/*
362347
* Purpose : This test is to validate read documents stored with valid POJO
363348
* specific URI. Uses SmallArtifactMissingSetter class
364-
* which has @Id only on the setter method.
365-
*
366-
* Current results (10/13/2014) are: Works fine
367-
*
349+
* which has @Id only on the setter method.
368350
*/
369351

370352
@Test
371353
public void testPOJOWriteReadMissingSetter() throws Exception {
372354

373355
PojoRepository<SmallArtifactMissingSetter, String> pojoReposSmallArtifact = client
374356
.newPojoRepository(SmallArtifactMissingSetter.class, String.class);
375-
String artifactName = new String("SmallArtifact");
357+
String artifactName = new String("SmallArtifactMissingSetter");
376358

377359
SmallArtifactMissingSetter art = new SmallArtifactMissingSetter();
378-
art.setId(-99);
360+
art.setId(-99L);
379361
art.setInventory(1000);
380362
art.setName(artifactName);
381363

382364
// Load the object into database
383365
pojoReposSmallArtifact.write(art,"com.marklogic.javaclient.TestPOJOMissingIdGetSetMethod$SmallArtifactMissingSetter/SmallArtifactMissingSetter.json");
384366

385367
SmallArtifactMissingSetter artifact1 = pojoReposSmallArtifact.read(artifactName);
386-
validateMissingArtifactSetter(artifact1);
368+
validateMissingArtifactSetter(artifact1, artifactName);
387369
}
388370

389371
/*
390372
* Purpose : This test is to validate read documents stored with JacksonHandle with valid POJO
391373
* specific URI. Uses SmallArtifactMissGetSet class
392-
* which has no @Id on any of its class members.
393-
*
394-
* Current results (10/13/2014) are: IllegalArgumentException
395-
*
374+
* which has no @Id on any of its class members.
396375
*/
397376

398377
@Test(expected=IllegalArgumentException.class)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ public void testPOJOWriteWithPojoPageReadAll() {
223223
System.out.println("Total number of estimated results:"+p.getTotalSize());
224224
assertEquals("Total number of estimated pages :",111,p.getTotalPages());
225225
System.out.println("Total number of estimated pages :"+p.getTotalPages());
226-
assertFalse("Is this First page :",p.isFirstPage());//this is bug
226+
assertTrue("Is this First page :",p.isFirstPage());
227227
assertFalse("Is this Last page :",p.isLastPage());
228228
assertTrue("Is this First page has content:",p.hasContent());
229229
// Need the Issue #75 to be fixed
230-
assertTrue("Is first page has previous page ?",p.hasPreviousPage());
230+
assertFalse("Is first page has previous page ?",p.hasPreviousPage());
231231
long pageNo=1,count=0;
232232
do{
233233
count=0;

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
import org.custommonkey.xmlunit.exceptions.XpathException;
2929
import org.junit.*;
30-
30+
import org.junit.runners.MethodSorters;
31+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
3132
public class TestRawCombinedQuery extends BasicJavaClientREST {
3233
private static String dbName = "TestRawCombinedQueryDB";
3334
private static String [] fNames = {"TestRawCombinedQueryDB-1"};
@@ -101,7 +102,7 @@ public void testBug22353() throws IOException, ParserConfigurationException, SAX
101102
}
102103

103104
@Test
104-
public void testRawCombinedQueryXML() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
105+
public void test1RawCombinedQueryXML() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
105106
{
106107
System.out.println("Running testRawCombinedQueryXML");
107108

@@ -153,7 +154,7 @@ public void testRawCombinedQueryXML() throws IOException, ParserConfigurationExc
153154
}
154155

155156
@Test
156-
public void testRawCombinedQueryXMLWithOptions() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
157+
public void test2RawCombinedQueryXMLWithOptions() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
157158
{
158159
System.out.println("Running testRawCombinedQueryXMLWithOptions");
159160

@@ -205,7 +206,7 @@ public void testRawCombinedQueryXMLWithOptions() throws IOException, ParserConfi
205206
}
206207

207208
@Test
208-
public void testRawCombinedQueryXMLWithOverwriteOptions() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
209+
public void test3RawCombinedQueryXMLWithOverwriteOptions() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
209210
{
210211
System.out.println("Running testRawCombinedQueryXMLWithOverwriteOptions");
211212

@@ -256,7 +257,7 @@ public void testRawCombinedQueryXMLWithOverwriteOptions() throws IOException, Pa
256257
}
257258

258259
@Test
259-
public void testRawCombinedQueryJSONWithOverwriteOptions() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
260+
public void test4RawCombinedQueryJSONWithOverwriteOptions() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
260261
{
261262
System.out.println("Running testRawCombinedQueryJSONWithOverwriteOptions");
262263

@@ -311,7 +312,7 @@ public void testRawCombinedQueryJSONWithOverwriteOptions() throws IOException, P
311312
}
312313

313314
@Test
314-
public void testRawCombinedQueryJSON() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
315+
public void test5RawCombinedQueryJSON() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
315316
{
316317
System.out.println("Running testRawCombinedQueryJSON");
317318

@@ -363,7 +364,7 @@ public void testRawCombinedQueryJSON() throws IOException, ParserConfigurationEx
363364
}
364365

365366
@Test
366-
public void testRawCombinedQueryWildcard() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
367+
public void test6RawCombinedQueryWildcard() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
367368
{
368369
System.out.println("Running testRawCombinedQueryWildcard");
369370

@@ -416,7 +417,7 @@ public void testRawCombinedQueryWildcard() throws IOException, ParserConfigurati
416417
}
417418

418419
@Test
419-
public void testRawCombinedQueryCollection() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
420+
public void test7RawCombinedQueryCollection() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
420421
{
421422
System.out.println("Running testRawCombinedQueryCollection");
422423

@@ -479,7 +480,7 @@ public void testRawCombinedQueryCollection() throws IOException, ParserConfigura
479480
}
480481

481482
@Test
482-
public void testRawCombinedQueryCombo() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
483+
public void test8RawCombinedQueryCombo() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
483484
{
484485
System.out.println("Running testRawCombinedQueryCombo");
485486

@@ -542,7 +543,7 @@ public void testRawCombinedQueryCombo() throws IOException, ParserConfigurationE
542543
}
543544

544545
@Test
545-
public void testRawCombinedQueryField() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
546+
public void test9RawCombinedQueryField() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
546547
{
547548
System.out.println("Running testRawCombinedQueryField");
548549

@@ -587,7 +588,7 @@ public void testRawCombinedQueryField() throws IOException, ParserConfigurationE
587588
}
588589

589590
@Test
590-
public void testRawCombinedQueryPathIndex() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
591+
public void test10RawCombinedQueryPathIndex() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
591592
{
592593
System.out.println("Running testRawCombinedQueryPathIndex");
593594

@@ -630,7 +631,7 @@ public void testRawCombinedQueryPathIndex() throws IOException, ParserConfigurat
630631
}
631632

632633
@Test
633-
public void testRawCombinedQueryComboJSON() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
634+
public void test11RawCombinedQueryComboJSON() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
634635
{
635636
System.out.println("Running testRawCombinedQueryComboJSON");
636637

@@ -694,15 +695,14 @@ public void testRawCombinedQueryComboJSON() throws IOException, ParserConfigurat
694695
String resultDoc = resultsHandle.get();
695696

696697
System.out.println(resultDoc);
697-
698-
assertTrue("Returned result is not correct", resultDoc.contains("<search:result index=\"1\" uri=\"/collection-constraint/constraint1.xml\" path=\"fn:doc(&quot;/collection-constraint/constraint1.xml&quot;)\" score=\"28672\" confidence=\"0.6951694\" fitness=\"0.9213214\" href=\"/v1/documents?uri=%2Fcollection-constraint%2Fconstraint1.xml\" mimetype=\"text/xml\" format=\"xml\">"));
698+
assertTrue("Returned result is not correct", resultDoc.contains("<search:result index=\"1\" uri=\"/collection-constraint/constraint1.xml\" path=\"fn:doc(&quot;/collection-constraint/constraint1.xml&quot;)\" score=\"28672\" confidence=\"0.6951694\" fitness=\"0.9213214\" href=\"/v1/documents?uri=%2Fcollection-constraint%2Fconstraint1.xml\" mimetype=\"application/xml\" format=\"xml\">"));
699699

700700
// release client
701701
client.release();
702702
}
703703

704704
@Test
705-
public void testRawCombinedQueryFieldJSON() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
705+
public void test12RawCombinedQueryFieldJSON() throws IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
706706
{
707707
System.out.println("Running testRawCombinedQueryFieldJSON");
708708

0 commit comments

Comments
 (0)