Repository: olingo-odata4 Updated Branches: refs/heads/master 2800fa0e9 -> e41b81ea0
[OLINGO-1077] EntityIterator count support Signed-off-by: Christian Amend <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/e41b81ea Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/e41b81ea Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/e41b81ea Branch: refs/heads/master Commit: e41b81ea09c34353414d43280e535242133c4793 Parents: 2800fa0 Author: Archana Rai <[email protected]> Authored: Tue Feb 7 11:28:41 2017 +0530 Committer: Christian Amend <[email protected]> Committed: Tue Feb 7 12:09:16 2017 +0100 ---------------------------------------------------------------------- .../fit/tecsvc/http/BasicStreamITCase.java | 84 ++++++++++++++++++++ .../olingo/commons/api/data/EntityIterator.java | 19 +++-- .../processor/TechnicalEntityProcessor.java | 5 ++ 3 files changed, 103 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e41b81ea/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicStreamITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicStreamITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicStreamITCase.java index ce77536..42ddb93 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicStreamITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicStreamITCase.java @@ -20,6 +20,7 @@ package org.apache.olingo.fit.tecsvc.http; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; import java.net.HttpURLConnection; import java.net.URL; @@ -154,6 +155,89 @@ public class BasicStreamITCase extends AbstractBaseTestITCase { assertTrue(content.contains("ESStreamServerSidePaging?$format=json&%24skiptoken=2%2A10")); } + + @Test + public void streamCountXml() throws Exception { + URL url = new URL(SERVICE_URI + "ESStreamServerSidePaging?$count=true&$format=xml"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod(HttpMethod.GET.name()); + connection.connect(); + + assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); + assertEquals(ContentType.APPLICATION_XML, ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); + + final String content = IOUtils.toString(connection.getInputStream()); + assertTrue(content.contains("<a:link rel=\"next\" href=")); + assertTrue(content.contains("ESStreamServerSidePaging?$count=true&$format=xml&%24skiptoken=1%2A10\"/>")); + assertTrue(content.contains("<a:id>ESStreamServerSidePaging(1)</a:id>")); + assertTrue(content.contains("<m:count>504</m:count>")); + assertTrue(content.contains("<d:PropertyInt16 m:type=\"Int16\">1</d:PropertyInt16>")); + assertTrue(content.contains("<d:PropertyStream m:type=\"Stream\">readLink</d:PropertyStream>")); + } + + + @Test + public void streamCountJson() throws Exception { + URL url = new URL(SERVICE_URI + "ESStreamServerSidePaging?$count=true&$format=json"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod(HttpMethod.GET.name()); + connection.connect(); + + assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); + assertEquals(ContentType.JSON, ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); + + final String content = IOUtils.toString(connection.getInputStream()); + + assertTrue(content.contains("{\"PropertyInt16\":2,"+ + "\"[email protected]\":\"eTag\",\"[email protected]\":\"image/jpeg\"}")); + assertTrue(content.contains("\"@odata.nextLink\"")); + assertTrue(content.contains("ESStreamServerSidePaging?$count=true&$format=json&%24skiptoken=1%2A10")); + assertTrue(content.contains("\"@odata.count\":504")); + } + + @Test + public void streamCountFalsetXml() throws Exception { + URL url = new URL(SERVICE_URI + "ESStreamServerSidePaging?$count=false&$format=xml"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod(HttpMethod.GET.name()); + connection.connect(); + + assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); + assertEquals(ContentType.APPLICATION_XML, ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); + + final String content = IOUtils.toString(connection.getInputStream()); + assertTrue(content.contains("<a:link rel=\"next\" href=")); + assertTrue(content.contains("ESStreamServerSidePaging?$count=false&$format=xml&%24skiptoken=1%2A10\"/>")); + assertTrue(content.contains("<a:id>ESStreamServerSidePaging(1)</a:id>")); + assertTrue(content.contains("<d:PropertyInt16 m:type=\"Int16\">1</d:PropertyInt16>")); + assertTrue(content.contains("<d:PropertyStream m:type=\"Stream\">readLink</d:PropertyStream>")); + assertFalse(content.contains("<m:count>504</m:count>")); + } + + + @Test + public void streamCountFalseJson() throws Exception { + URL url = new URL(SERVICE_URI + "ESStreamServerSidePaging?$count=false&$format=json"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod(HttpMethod.GET.name()); + connection.connect(); + + assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); + assertEquals(ContentType.JSON, ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); + + final String content = IOUtils.toString(connection.getInputStream()); + + assertTrue(content.contains("{\"PropertyInt16\":2,"+ + "\"[email protected]\":\"eTag\",\"[email protected]\":\"image/jpeg\"}")); + assertTrue(content.contains("\"@odata.nextLink\"")); + assertTrue(content.contains("ESStreamServerSidePaging?$count=false&$format=json&%24skiptoken=1%2A10")); + assertFalse(content.contains("\"@odata.count\":504")); + } + @Override protected ODataClient getClient() { return null; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e41b81ea/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java index 145b2ac..809a40e 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java @@ -30,6 +30,8 @@ import java.util.List; public abstract class EntityIterator extends AbstractEntityCollection implements Iterator<Entity> { private URI next; + + private Integer count; /** * {@inheritDoc} */ @@ -72,18 +74,16 @@ public abstract class EntityIterator extends AbstractEntityCollection implements } /** - * {@inheritDoc} - * <p/> - * <b>ATTENTION:</b> <code>getCount</code> is not supported by default. + * Gets count + * */ public Integer getCount() { - throw new ODataNotSupportedException("Entity Iterator does not support getCount()"); + return count; } /** * Gets next link. * - * @param next next link. */ public URI getNext() { return next; @@ -106,4 +106,13 @@ public abstract class EntityIterator extends AbstractEntityCollection implements public void setNext(final URI next) { this.next = next; } + + /** + * Sets count. + * + * @param count count value. + */ + public void setCount(final Integer count) { + this.count = count; + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e41b81ea/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java index e21b646..d7830be 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java @@ -633,6 +633,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor EntityIterator streamCollection = new EntityIterator() { Iterator<Entity> entityIterator = entityCollection.iterator(); private URI next = entityCollection.getNext(); + private Integer count = entityCollection.getCount(); @Override public List<Operation> getOperations() { return entityCollection.getOperations(); @@ -642,6 +643,10 @@ public class TechnicalEntityProcessor extends TechnicalProcessor return next; } + public Integer getCount() { + return count; + } + @Override public boolean hasNext() { return entityIterator.hasNext();
