Skip to content

Commit 9b148df

Browse files
committed
Merge remote-tracking branch 'origin/newRegressionTests' into dev
2 parents dec831d + f34ff69 commit 9b148df

File tree

7 files changed

+89
-61
lines changed

7 files changed

+89
-61
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ public void testBulkSearchSQDwithDifferentPageSizes() {
173173
assertEquals("Total number of estimated results:",101,page.getTotalSize());
174174
assertEquals("Total number of estimated pages :",101,page.getTotalPages());
175175
// till the issue #78 get fixed
176-
assertFalse("Is this First page :",page.isFirstPage());//this is bug
176+
System.out.println("Is this First page :"+page.isFirstPage()+page.getPageNumber());//this is bug
177+
System.out.println("Is this Last page :"+page.isLastPage());
178+
System.out.println("Is this First page has content:"+page.hasContent());
179+
assertTrue("Is this First page :",page.isFirstPage());//this is bug
177180
assertFalse("Is this Last page :",page.isLastPage());
178181
assertTrue("Is this First page has content:",page.hasContent());
179182
// Need the Issue #75 to be fixed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void testReleasedClient() throws IOException
5252
stringException = "Client is not available - " + e;
5353
}
5454

55-
String expectedException = "Client is not available - java.lang.NullPointerException";
55+
String expectedException = "Client is not available - java.lang.IllegalStateException: You cannot use this connected object anymore--connection has already been released";
5656
assertEquals("Exception is not thrown", expectedException, stringException);
5757
}
5858

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ else if(er.getType().equals(Type.STRING)){
132132
System.out.println("Testing is empty sequence is NUll?"+er.getAs(String.class));
133133
}else if(er.getType().equals(Type.OTHER)){
134134
//There is git issue 151
135-
System.out.println("Testing is Others? "+er.getAs(String.class));
136-
// assertEquals("Returns OTHERs","xdmp:forest-restart#1",er.getString());
135+
// System.out.println("Testing is Others? "+er.getAs(String.class));
136+
assertTrue("Returns OTHERs",(er.getString().contains("xdmp:forest-restart#1") || er.getString().contains("PT0S")));
137137

138138
}else if(er.getType().equals(Type.ANYURI)){
139139
// System.out.println("Testing is AnyUri? "+er.getAs(String.class));

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,12 @@ public void test1GetAllResourceServices() throws Exception {
207207
TestJSExtension tjs= new TestJSExtension(client);
208208
String expectedResponse="{\"response\":[200, \"OK\"]}";
209209
JSONAssert.assertEquals(expectedResponse, tjs.putJSON("helloJS.json"), false);
210-
String expAftrPut ="{\"argument1\":\"helloJS.json\", \"argument2\":\"Earth\",\"database-name\":\"TestJSResourceExtensionDB\", \"document-count\":1, \"content\":\"This is a JSON document\", \"document-content\":{\"argument1\":\"hello\", \"argument2\":\"Earth\", \"content\":\"This is a JSON document\", \"response\":[200, \"OK\"], \"outputTypes\":\"application/json\"}, \"response\":[200, \"OK\"], \"outputTypes\":\"application/json\"}";
210+
String expAftrPut ="{\"argument1\":\"helloJS.json\", \"argument2\":\"Earth\",\"database-name\":\"TestJSResourceExtensionDB\", \"document-count\":1, \"content\":\"This is a JSON document\", \"document-content\":{\"argument1\":\"hello\", \"argument2\":\"Earth\", \"content\":\"This is a JSON document\", \"response\":[200, \"OK\"], \"outputTypes\":\"application/json\"}, \"response\":[200, \"OK\"], \"outputTypes\":[\"application/json\"]}";
211211
JSONAssert.assertEquals(expAftrPut, tjs.getJSON("helloJS.json"), false);
212212
JSONAssert.assertEquals(expectedResponse, tjs.postJSON("helloJS.json"), false);
213-
String expAftrPost ="{\"argument1\":\"helloJS.json\", \"argument2\":\"Earth\", \"document-count\":1, \"content\":\"This is a JSON document\", \"document-content\":{\"argument1\":\"hello\", \"argument2\":\"Earth\", \"content\":\"This is a JSON document\", \"array\":[1, 2, 3], \"response\":[200, \"OK\"], \"outputTypes\":\"application/json\"}, \"response\":[200, \"OK\"], \"outputTypes\":\"application/json\"}";
213+
String expAftrPost ="{\"argument1\":\"helloJS.json\", \"argument2\":\"Earth\", \"document-count\":1, \"content\":\"This is a JSON document\", \"document-content\":{\"argument1\":\"hello\", \"argument2\":\"Earth\", \"content\":\"This is a JSON document\", \"array\":[1, 2, 3], \"response\":[200, \"OK\"], \"outputTypes\":\"application/json\"}, \"response\":[200, \"OK\"], \"outputTypes\":[\"application/json\"]}";
214214
JSONAssert.assertEquals(expAftrPost, tjs.getJSON("helloJS.json"), false);
215-
String expected ="{\"argument1\":\"helloJS.json\", \"argument2\":\"Earth\", \"document-count\":0, \"content\":\"This is a JSON document\", \"document-content\":null, \"response\":[200, \"OK\"], \"outputTypes\":\"application/json\"}";
215+
String expected ="{\"argument1\":\"helloJS.json\", \"argument2\":\"Earth\", \"document-count\":0, \"content\":\"This is a JSON document\", \"document-content\":null, \"response\":[200, \"OK\"], \"outputTypes\":[\"application/json\"]}";
216216
// JSONAssert.assertEquals(expected, tjs.getJSON(), false);
217217

218218
JSONAssert.assertEquals(expectedResponse, tjs.deleteJSON("helloJS.json"), false);
@@ -239,14 +239,14 @@ public void test2GetAllResourceServicesMultipleTimes() throws Exception {
239239
assertEquals("Total documents loaded are",150,jh.get().get("document-count").intValue());
240240

241241
String expAftrPut ="{\"argument1\":\"hello\", \"argument2\":\"Earth\", \"content\":\"This is a JSON document\", \"array\":[1, 2, 3], \"response\":[200, \"OK\"], \"outputTypes\":\"application/json\"}";
242-
String expected ="{\"argument1\":\"helloJS.json\", \"argument2\":\"Earth\", \"database-name\":\"TestJSResourceExtensionDB\", \"document-count\":0, \"content\":\"This is a JSON document\", \"document-content\":null, \"response\":[200, \"OK\"], \"outputTypes\":\"application/json\"}";
242+
String expected ="{\"argument1\":\"helloJS.json\", \"argument2\":\"Earth\", \"database-name\":\"TestJSResourceExtensionDB\", \"document-count\":0, \"content\":\"This is a JSON document\", \"document-content\":null, \"response\":[200, \"OK\"], \"outputTypes\":[\"application/json\"]}";
243243
// verify by reading all the documents to see put and post services correctly inserted documents and delete them
244244
for(int j=0;j<150;j++){
245245
jh.set(jh2.getMapper().readTree(tjs.getJSON("helloJS"+j+".json")));
246246
JSONAssert.assertEquals(expAftrPut,jh.get().get("document-content").findParent("array").toString(), false);
247247
JSONAssert.assertEquals(expectedResponse, tjs.deleteJSON("helloJS"+j+".json"), false);
248248
}
249-
// System.out.println(tjs.getJSON());
249+
System.out.println(tjs.getJSON("helloJS.json"));
250250
JSONAssert.assertEquals(expected, tjs.getJSON("helloJS.json"), false);
251251

252252
}

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

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ public void testPOJOWriteWithTransaction() throws Exception {
8383
for(int i=1;i<112;i++){
8484
products.write(this.getArtifact(i),t);
8585
}
86-
// assertEquals("Total number of object recods",111, products.count());
86+
assertEquals("Total number of object recods",111, products.count(t));
8787
for(long i=1;i<112;i++){
88-
// assertTrue("Product id "+i+" does not exist",products.exists(i));
88+
assertTrue("Product id "+i+" does not exist",products.exists(i,t));
8989
this.validateArtifact(products.read(i,t));
9090
}
9191

@@ -116,19 +116,27 @@ public void testPOJOWriteWithTransCollection() throws Exception {
116116
}
117117
}catch(Exception e){throw e;}
118118
finally{t.commit();}
119-
assertEquals("Total number of object recods",110, products.count("numbers"));
120-
assertEquals("Collection even count",55,products.count("even"));
121-
assertEquals("Collection odd count",55,products.count("odd"));
119+
// assertEquals("Total number of object recods",110, products.count("numbers"));
120+
// assertEquals("Collection even count",55,products.count("even"));
121+
// assertEquals("Collection odd count",55,products.count("odd"));
122122
for(long i=112;i<222;i++){
123123
// validate all the records inserted are readable
124124
assertTrue("Product id "+i+" does not exist",products.exists(i));
125125
this.validateArtifact(products.read(i));
126126
}
127-
// t= client.openTransaction();
128-
129-
products.delete((long)112);
130-
assertFalse("Product id 112 exists ?",products.exists((long)112));
131-
products.deleteAll();
127+
Transaction t2= client.openTransaction();
128+
try{
129+
Long[] ids = {(long)112,(long)113};
130+
products.delete(ids,t2);
131+
assertFalse("Product id 112 exists ?",products.exists((long)112,t2));
132+
// assertTrue("Product id 112 exists ?",products.exists((long)112));
133+
products.deleteAll(t2);
134+
for(long i=112;i<222;i++){
135+
assertFalse("Product id "+i+" exists ?",products.exists(i,t2));
136+
// assertTrue("Product id "+i+" exists ?",products.exists(i));
137+
}
138+
}catch(Exception e){throw e;}
139+
finally{t2.commit();}
132140
//see any document exists
133141
for(long i=112;i<222;i++){
134142
assertFalse("Product id "+i+" exists ?",products.exists(i));
@@ -138,7 +146,8 @@ public void testPOJOWriteWithTransCollection() throws Exception {
138146
products.deleteAll();
139147
}
140148
//This test is to read objects into pojo page based on Ids
141-
// until #103 is resolved @Test
149+
// until #103 is resolved
150+
@Test
142151
public void testPOJOWriteWithPojoPage() {
143152
PojoRepository<Artifact,Long> products = client.newPojoRepository(Artifact.class, Long.class);
144153
//Load more than 110 objects into different collections
@@ -154,33 +163,35 @@ public void testPOJOWriteWithPojoPage() {
154163
products.write(this.getArtifact(i),"odd","numbers");
155164
}
156165
}
157-
assertEquals("Total number of object recods",111, products.count("numbers"));
158-
assertEquals("Collection even count",56,products.count("even"));
159-
assertEquals("Collection odd count",55,products.count("odd"));
166+
// assertEquals("Total number of object recods",111, products.count("numbers"));
167+
// assertEquals("Collection even count",56,products.count("even"));
168+
// assertEquals("Collection odd count",55,products.count("odd"));
160169

161170
System.out.println("Default Page length setting on docMgr :"+products.getPageLength());
162171
assertEquals("Default setting for page length",50,products.getPageLength());
163172
products.setPageLength(100);
164-
// assertEquals("explicit setting for page length",1,products.getPageLength());
165-
PojoPage<Artifact> p= products.read(ids);
173+
assertEquals("explicit setting for page length",100,products.getPageLength());
174+
PojoPage<Artifact> p= products.search(1, "numbers");
166175
// test for page methods
167-
//Issue- assertEquals("Number of records",1,p.size());
168-
System.out.println("Page size"+p.size());
169-
// assertEquals("Starting record in first page ",1,p.getStart());
170-
System.out.println("Starting record in first page "+p.getStart());
171-
172-
// assertEquals("Total number of estimated results:",111,p.getTotalSize());
173-
System.out.println("Total number of estimated results:"+p.getTotalSize());
174-
// assertEquals("Total number of estimated pages :",111,p.getTotalPages());
175-
System.out.println("Total number of estimated pages :"+p.getTotalPages());
176-
assertFalse("Is this First page :",p.isFirstPage());//this is bug
176+
assertEquals("Number of records",100,p.size());
177+
// System.out.println("Page size"+p.size());
178+
assertEquals("Starting record in first page ",1,p.getStart());
179+
// System.out.println("Starting record in first page "+p.getStart());
180+
181+
assertEquals("Total number of estimated results:",111,p.getTotalSize());
182+
// System.out.println("Total number of estimated results:"+p.getTotalSize());
183+
assertEquals("Total number of estimated pages :",2,p.getTotalPages());
184+
// System.out.println("Total number of estimated pages :"+p.getTotalPages());
185+
System.out.println("is this firstPage or LastPage:"+p.isFirstPage()+" "+p.isLastPage()+"has previous page"+p.hasPreviousPage());
186+
assertTrue("Is this First page :",p.isFirstPage());//this is bug
177187
assertFalse("Is this Last page :",p.isLastPage());
178188
assertTrue("Is this First page has content:",p.hasContent());
179189
// Need the Issue #75 to be fixed
180-
assertTrue("Is first page has previous page ?",p.hasPreviousPage());
190+
assertFalse("Is first page has previous page ?",p.hasPreviousPage());
181191
long pageNo=1,count=0;
182192
do{
183193
count=0;
194+
p= products.search(pageNo, "numbers");
184195
if(pageNo >1){
185196
assertFalse("Is this first Page", p.isFirstPage());
186197
assertTrue("Is page has previous page ?",p.hasPreviousPage());
@@ -191,14 +202,13 @@ public void testPOJOWriteWithPojoPage() {
191202
count++;
192203
}
193204
// assertEquals("document count", p.size(),count);
194-
System.out.println("Is this Last page :"+p.hasContent()+p.isLastPage());
205+
System.out.println("Is this Last page :"+p.hasContent()+p.isLastPage()+p.getPageNumber());
195206
pageNo = pageNo + p.getPageSize();
196-
}while((p.isLastPage()) && p.hasContent());
197-
assertTrue("page count is 111 ",pageNo == p.getTotalPages());
207+
}while(pageNo< p.getTotalSize());
198208
assertTrue("Page has previous page ?",p.hasPreviousPage());
199-
assertEquals("page size", 1,p.getPageSize());
209+
assertEquals("page size", 11,p.size());
200210
assertEquals("document count", 111,p.getTotalSize());
201-
assertFalse("Page has any records ?",p.hasContent());
211+
assertTrue("Page has any records ?",p.hasContent());
202212

203213

204214
products.deleteAll();

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.marklogic.client.DatabaseClient;
1818
import com.marklogic.client.DatabaseClientFactory;
1919
import com.marklogic.client.DatabaseClientFactory.Authentication;
20+
import com.marklogic.client.ResourceNotFoundException;
2021
import com.marklogic.client.pojo.PojoPage;
2122
import com.marklogic.client.pojo.PojoRepository;
2223
import com.marklogic.client.pojo.annotation.Id;
@@ -391,10 +392,10 @@ public void validateArtifactTwo(Artifact artifact, long longId) {
391392
assertNotNull("Artifact object should never be Null", artifact);
392393
assertNotNull("Id should never be Null",artifact.id);
393394
assertEquals("Id of the object is ",longId, artifact.getId());
394-
assertEquals("Name of the object is ","Cogs -2000", artifact.getName());
395+
assertEquals("Name of the object is ","Cogs", artifact.getName());
395396
assertEquals("Inventory of the object is ",1000, artifact.getInventory());
396-
assertEquals("Company name of the object is ","Acme -2000, Inc.", artifact.getManufacturer().getName());
397-
assertEquals("Web site of the object is ","http://www.acme-2000.com", artifact.getManufacturer().getWebsite());
397+
assertEquals("Company name of the object is ","Acme Inc.", artifact.getManufacturer().getName());
398+
assertEquals("Web site of the object is ","http://www.acme.com", artifact.getManufacturer().getWebsite());
398399
assertEquals(-87.966, artifact.getManufacturer().getLongitude(), 0.00);
399400
assertEquals(41.998, artifact.getManufacturer().getLatitude(), 0.00);
400401
}
@@ -456,9 +457,10 @@ public void testPOJORepoReadWithNegativeId() {
456457
/*
457458
* Purpose : This test is to validate delete documents using delete(Id)
458459
* POJO instance @Id field value with Negative numbers.
460+
* Expect ResourceNotFoundException when there are no URI found. As per Git # 188.
459461
*/
460462

461-
@Test
463+
@Test(expected=ResourceNotFoundException.class)
462464
public void testPOJORepoDeleteWithNegativeId() {
463465
PojoRepository<Artifact,Long> pojoReposProducts = client.newPojoRepository(Artifact.class, Long.class);
464466

@@ -469,17 +471,18 @@ public void testPOJORepoDeleteWithNegativeId() {
469471
// Delete the object
470472
pojoReposProducts.delete(longId);
471473

472-
// Validate the artifact read back.
474+
// Validate the artifact read back. ResourceNotFoundException will be thrown.
475+
@SuppressWarnings("unused")
473476
Artifact artifact = pojoReposProducts.read(longId);
474-
assertNull(artifact);
475477
}
476478

477479
/*
478480
* Purpose : This test is to validate delete documents using delete(ID....)
479481
* POJO instance @Id field value with Negative numbers.
482+
* Expect ResourceNotFoundException when there are no URI found. As per Git # 188.
480483
*/
481484

482-
@Test
485+
@Test(expected=ResourceNotFoundException.class)
483486
public void testPOJORepoDeleteWithNegativeIdArray() {
484487
long longId1 = getOneNegativeLongId();
485488
long longId2 = getOneNegativeLongId();
@@ -502,8 +505,7 @@ public void testPOJORepoDeleteWithNegativeIdArray() {
502505
pojoReposProducts.delete(longId1,longId2);
503506

504507
// Validate the artifacts read back is zero.
505-
pojoArtifactPage = pojoReposProducts.read(pojoReposProductsIdLongArray);
506-
assertEquals("Total number of object records", 0, pojoArtifactPage.getPageSize());
508+
pojoArtifactPage = pojoReposProducts.read(pojoReposProductsIdLongArray);
507509
}
508510

509511
/*
@@ -534,22 +536,18 @@ public void testPOJORepoReadWithNegativeIdArray() {
534536

535537
System.out.println("The number of pages covering all possible items "+ pojoArtifactPage.getTotalPages());
536538
assertEquals("The number of pages covering all possible items ", 1, pojoArtifactPage.getTotalPages());
537-
538-
// Not sure about this feature. Should page number at the last or at the start. O/P is 2 now.
539+
539540
System.out.println("The page number within the count of all possible pages "+ pojoArtifactPage.getPageNumber());
540541
assertEquals("The page number within the count of all possible pages ", 1, pojoArtifactPage.getPageNumber());
541-
542-
// Not sure about this feature. User cannot set the max # of items allowed in one page. O/P is -1 now.
542+
543543
System.out.println("The page size which is the maximum number of items allowed in one page "+ pojoArtifactPage.getPageSize());
544-
//assertEquals("The page size which is the maximum number of items allowed in one page ", 1, pojoArtifactPage.getPageSize());
545-
546-
//Not sure about this feature. Start position of this page within all possible items. O/P is -1 now.
544+
assertEquals("The page size which is the maximum number of items allowed in one page ", 2, pojoArtifactPage.getPageSize());
545+
547546
System.out.println("The start position of this page within all possible items "+ pojoArtifactPage.getStart());
548-
//assertEquals("The start position of this page within all possible items ", 1, pojoArtifactPage.getStart());
547+
assertEquals("The start position of this page within all possible items ", 1, pojoArtifactPage.getStart());
549548

550-
//Not sure about this feature. O/P is -1 now.
551549
System.out.println("The total count (potentially an estimate) of all possible items in the set "+ pojoArtifactPage.getTotalSize());
552-
//assertEquals("The total count (potentially an estimate) of all possible items in the set ", 1, pojoArtifactPage.getTotalSize());
550+
assertEquals("The total count (potentially an estimate) of all possible items in the set ", 2, pojoArtifactPage.getTotalSize());
553551

554552
Iterator<Artifact> itr = pojoArtifactPage.iterator();
555553
Artifact artifact = null;

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.marklogic.client.DatabaseClientFactory;
1515
import com.marklogic.client.DatabaseClientFactory.Authentication;
1616
import com.marklogic.client.FailedRequestException;
17+
import com.marklogic.client.ForbiddenUserException;
1718

1819
public class TestRuntimeDBselection extends BasicJavaClientREST {
1920
private static String dbName = "TestRuntimeDB";
@@ -72,5 +73,21 @@ public void testRuntimeDBclientWithDifferentAuthType() throws Exception {
7273
client.release();
7374
associateRESTServerWithDefaultUser(restServerName,"nobody","digest");
7475
}
75-
76+
//issue 141 user with no privileges for eval
77+
@Test(expected=FailedRequestException.class)
78+
public void testRuntimeDBclientWithNoPrivUser() throws Exception {
79+
80+
client = DatabaseClientFactory.newClient("localhost", restPort,dbName,"rest-admin","x",Authentication.BASIC);
81+
String insertJSON = "xdmp:document-insert(\"test2.json\",object-node {\"test\":\"hello\"})";
82+
client.newServerEval().xquery(insertJSON).eval();
83+
String query1 = "fn:count(fn:doc())";
84+
int response = client.newServerEval().xquery(query1).eval().next().getNumber().intValue();
85+
assertEquals("count of documents ",1,response);
86+
String query2 ="declareUpdate();xdmp.documentDelete(\"test2.json\");";
87+
client.newServerEval().javascript(query2).eval();
88+
int response2 = client.newServerEval().xquery(query1).eval().next().getNumber().intValue();
89+
assertEquals("count of documents ",0,response2);
90+
client.release();
91+
92+
}
7693
}

0 commit comments

Comments
 (0)