@@ -81,7 +81,7 @@ public void tearDown() throws DocumentClientException {
8181 private static String getStringFromInputStream (InputStream is ) {
8282 BufferedReader br = null ;
8383 StringBuilder sb = new StringBuilder ();
84-
84+
8585 String line ;
8686 try {
8787 br = new BufferedReader (new InputStreamReader (is , "UTF-8" ));
@@ -258,6 +258,33 @@ public void testCollectionCrud() throws DocumentClientException {
258258 }
259259 }
260260
261+ @ Test
262+ public void testQueryIterableCrud () throws DocumentClientException {
263+ DocumentClient client = new DocumentClient (HOST ,
264+ MASTER_KEY ,
265+ ConnectionPolicy .GetDefault (),
266+ ConsistencyLevel .Session );
267+
268+ List <Document > documents = client .readDocuments (this .collectionForTest .getSelfLink (),
269+ null ).getQueryIterable ().toList ();
270+ int beforeCreateDocumentsCount = documents .size ();
271+
272+ // Create 20 collection.
273+ for (int i = 0 ; i < 20 ; ++i ) {
274+ Document documentDefinition = new Document ("{ 'name': 'For test' }" );
275+ client .createDocument (this .collectionForTest .getSelfLink (), documentDefinition , null , false );
276+ }
277+
278+ FeedOptions fo = new FeedOptions ();
279+ // Page size of "1" is for test only. Please choose a more reasonable value in practice.
280+ fo .setPageSize (1 );
281+
282+ documents = client .readDocuments (this .collectionForTest .getSelfLink (),
283+ null ).getQueryIterable ().toList ();
284+
285+ Assert .assertEquals (beforeCreateDocumentsCount + 20 , documents .size ());
286+ }
287+
261288 @ Test
262289 public void testCollectionIndexingPolicy () throws DocumentClientException {
263290 DocumentClient client = new DocumentClient (HOST ,
@@ -324,7 +351,7 @@ public void testCollectionIndexingPolicy() throws DocumentClientException {
324351 collectionWithSecondaryIndex .getIndexingPolicy ().getIncludedPaths ().iterator ().next ().getIndexType ());
325352 Assert .assertEquals (1 , collectionWithSecondaryIndex .getIndexingPolicy ().getExcludedPaths ().size ());
326353 }
327-
354+
328355 @ Test
329356 public void testDocumentCrud () throws DocumentClientException {
330357 DocumentClient client = new DocumentClient (HOST ,
@@ -384,7 +411,7 @@ public void testDocumentCrud() throws DocumentClientException {
384411 // Read document.
385412 Document oneDocumentFromRead = client .readDocument (replacedDocument .getSelfLink (), null ).getResource ();
386413 Assert .assertEquals (replacedDocument .getId (), oneDocumentFromRead .getId ());
387-
414+
388415 AccessCondition accessCondition = new AccessCondition ();
389416 accessCondition .setCondition (oneDocumentFromRead .getETag ()) ;
390417 accessCondition .setType (AccessConditionType .IfNoneMatch );
@@ -409,31 +436,31 @@ public void testDocumentCrud() throws DocumentClientException {
409436
410437 class TestPOJOInner {
411438 public int intProperty ;
412-
413- public TestPOJOInner (int i ) {
439+
440+ public TestPOJOInner (int i ) {
414441 this .intProperty = i ;
415442 }
416443 }
417-
444+
418445 class TestPOJO {
419-
420- private String privateStringProperty ;
421-
446+
447+ private String privateStringProperty ;
448+
422449 public String id ;
423450 public int intProperty ;
424451 public String stringProperty ;
425452 public TestPOJOInner objectProperty ;
426453 public List <String > stringList ;
427454 public String [] stringArray ;
428455
429- public TestPOJO (int i ) {
430- this .intProperty = i ;
431-
456+ public TestPOJO (int i ) {
457+ this .intProperty = i ;
458+
432459 this .stringList = new ArrayList <String >();
433460 this .stringList .add ("ONE" );
434461 this .stringList .add ("TWO" );
435462 this .stringList .add ("THREE" );
436-
463+
437464 this .stringArray = new String [] { "One" , "Two" , "Three" };
438465 }
439466
@@ -444,27 +471,27 @@ public void setPrivateStringProperty(String value) {
444471 this .privateStringProperty = value ;
445472 }
446473 }
447-
474+
448475 @ Test
449476 public void testPOJODocumentCrud () throws DocumentClientException {
450-
451-
477+
478+
452479 DocumentClient client = new DocumentClient (HOST ,
453480 MASTER_KEY ,
454481 ConnectionPolicy .GetDefault (),
455482 ConsistencyLevel .Session );
456-
483+
457484 TestPOJO testPojo = new TestPOJO (10 );
458485 testPojo .id = "MyPojoObejct" + GatewayTests .getUID ();
459486 testPojo .stringProperty = "testString" ;
460487 testPojo .objectProperty = new TestPOJOInner (100 );
461488 testPojo .setPrivateStringProperty ("testStringAccess" );
462-
489+
463490 Document document = client .createDocument (this .collectionForTest .getSelfLink (),
464491 testPojo ,
465492 null ,
466493 false ).getResource ();
467-
494+
468495 Assert .assertEquals (document .getInt ("intProperty" ).intValue (), testPojo .intProperty );
469496
470497 Assert .assertEquals (document .getString ("stringProperty" ), testPojo .stringProperty );
@@ -487,7 +514,7 @@ public void testPOJODocumentCrud() throws DocumentClientException {
487514 testPojo .stringProperty = "updatedTestString" ;
488515 document = client .replaceDocument (document .getSelfLink (), testPojo , null ).getResource ();
489516 Assert .assertEquals (document .getString ("stringProperty" ), testPojo .stringProperty );
490-
517+
491518 }
492519
493520 @ Test
@@ -807,7 +834,7 @@ public void testStoredProcedureFunctionality()
807834 // POJO
808835 class TempPOJO {
809836 @ SuppressWarnings ("unused" )
810- public String temp = "so2" ;
837+ public String temp = "so2" ;
811838 }
812839 TempPOJO tempPOJO = new TempPOJO ();
813840 StoredProcedure sproc4 = new StoredProcedure (
@@ -969,7 +996,7 @@ public void testPermissionCrud() throws DocumentClientException {
969996 null ).getQueryIterable ().toList ();
970997 Assert .assertEquals (1 , permissions .size ());
971998
972- // Replace permission.
999+ // Replace permission.
9731000 permission .setId ("replaced permission" );
9741001 Permission replacedPermission = client .replacePermission (
9751002 permission , null ).getResource ();
@@ -997,12 +1024,12 @@ public void testDatabaseAccount() throws DocumentClientException {
9971024 MASTER_KEY ,
9981025 ConnectionPolicy .GetDefault (),
9991026 ConsistencyLevel .Session );
1000-
1027+
10011028 DatabaseAccount dba = client .getDatabaseAccount ();
1002- Assert .assertNotNull ("dba Address link works" , dba .getAddressesLink ());
1029+ Assert .assertNotNull ("dba Address link works" , dba .getAddressesLink ());
10031030 Assert .assertTrue ("provision storage must larger than 10000MB" ,
10041031 dba .getProvisionedDocumentStorageInMB () > 10000 );
1005-
1032+
10061033 if (dba .getConsistencyPolicy ().getDefaultConsistencyLevel () == ConsistencyLevel .BoundedStaleness ) {
10071034 Assert .assertTrue ("StaleInternal should be larger than 5 seconds" ,
10081035 dba .getConsistencyPolicy ().getMaxStalenessIntervalInSeconds () >= 5 );
@@ -1044,7 +1071,7 @@ public void testAuthorization() throws DocumentClientException {
10441071 " 'permissionMode': 'Read'," +
10451072 " 'resource': '%s'" +
10461073 "}" , collectionForTest .getSelfLink ()));
1047- // Create permission for collectionForTest
1074+ // Create permission for collectionForTest
10481075 Permission permission1 = client .createPermission (user1 .getSelfLink (),
10491076 permission1Definition ,
10501077 null ).getResource ();
0 commit comments