You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ra...@apache.org on 2019/05/14 09:45:46 UTC
[olingo-odata4] branch master updated: [OLINGO-1276]Problem with
ClientEntitySetIterator
This is an automated email from the ASF dual-hosted git repository.
ramyav pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata4.git
The following commit(s) were added to refs/heads/master by this push:
new bf12185 [OLINGO-1276]Problem with ClientEntitySetIterator
bf12185 is described below
commit bf12185b5922ccd254dbc7687b5baad187492025
Author: ramya vasanth <ra...@sap.com>
AuthorDate: Tue May 14 15:15:33 2019 +0530
[OLINGO-1276]Problem with ClientEntitySetIterator
---
.../client/api/domain/ClientEntitySetIterator.java | 25 ++-
.../core/domain/ClientEntitySetIteratorTest.java | 206 +++++++++++++++++++++
2 files changed, 225 insertions(+), 6 deletions(-)
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ClientEntitySetIterator.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ClientEntitySetIterator.java
index 837ba3a..8a0f60d 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ClientEntitySetIterator.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ClientEntitySetIterator.java
@@ -192,17 +192,30 @@ public class ClientEntitySetIterator<T extends ClientEntitySet, E extends Client
} while (c >= 0);
if (foundNewOne) {
- int count = 1;
+ int objectCount = 1;
+ int stringCount = 0;
c = 0;
- while (count > 0 && c >= 0) {
+ boolean previousCharIsEscape = false;
+
+ while (objectCount > 0 && c >= 0) {
c = input.read();
- if (c == '{') {
- count++;
- } else if (c == '}') {
- count--;
+ if (c == '{' && stringCount <= 0) {
+ objectCount++;
+ } else if (c == '}' && stringCount <= 0) {
+ objectCount--;
+ // Detect JSON Strings to be able to correctly detect an Entity
+ } else if (c == '"' && stringCount <= 0 && !previousCharIsEscape) {
+ stringCount++;
+ } else if (c == '"' && stringCount > 0 && !previousCharIsEscape) {
+ stringCount--;
}
entity.write(c);
+ if (c == '\\' && !previousCharIsEscape) {
+ previousCharIsEscape = true;
+ } else {
+ previousCharIsEscape = false;
+ }
}
if (c >= 0) {
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/domain/ClientEntitySetIteratorTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/domain/ClientEntitySetIteratorTest.java
new file mode 100644
index 0000000..62b0c0b
--- /dev/null
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/domain/ClientEntitySetIteratorTest.java
@@ -0,0 +1,206 @@
+package org.apache.olingo.client.core.domain;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+
+import org.apache.olingo.client.api.ODataClient;
+import org.apache.olingo.client.api.domain.ClientEntity;
+import org.apache.olingo.client.api.domain.ClientEntitySet;
+import org.apache.olingo.client.api.domain.ClientEntitySetIterator;
+import org.apache.olingo.client.core.ODataClientFactory;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ClientEntitySetIteratorTest {
+
+ @Test
+ public void testGetEntitySetIterator1() throws IOException, URISyntaxException {
+ String str = "{ \"@odata.context\": \"http://bdh-df5.wdf.sap.corp:8080/CloudDataIntegration/providers"
+ + "/CLOUD_DATA_INTEGRATION_TEST%3ABUG_CURLY_BRACKETS/$metadata#BUG_CURLY_BRACKETSResult/$delta\", "
+ + "\"value\": [ "
+ + "{ \"@odata.id\": \"BUG_CURLY_BRACKETSResult(1)\", \"ID\": 1, \"TEXT\": \"ABC\", \"TEXT2\": \"DEF\" }, "
+ + "{ \"@odata.id\": \"BUG_CURLY_BRACKETSResult(2)\", \"ID\": 2, "
+ + "\"TEXT\": "
+ + "\"QN6 1311 &&&AmpersandCheck&&& "
+ + "~!@#$%^&*()_+=-[];',./?><\\\":}{| @AlmikaPhone\", "
+ + "\"TEXT2\": \"QN6 1311 &&&AmpersandCheck&&& ~!@#$%^&*()_+=-[];',./?><\\\":}{| @AlmikaPhone\" }, "
+ + "{ \"@odata.id\": "
+ + "\"BUG_CURLY_BRACKETSResult(3)\", \"ID\": 3, \"TEXT\": \"}XYZ\", \"TEXT2\": \"LMN\" } ] }";
+
+ InputStream stream = new ByteArrayInputStream(str.getBytes());
+ ODataClient oDataClient = ODataClientFactory.getClient();
+ ClientEntitySetIterator<ClientEntitySet, ClientEntity> entitySetIterator =
+ new ClientEntitySetIterator<ClientEntitySet, ClientEntity>(
+ oDataClient, stream, ContentType.parse(ContentType.JSON.toString()));
+
+ ArrayList<ClientEntity> entities = new ArrayList<ClientEntity>();
+ while (entitySetIterator.hasNext()) {
+ ClientEntity next = entitySetIterator.next();
+ entities.add(next);
+ }
+
+ Assert.assertEquals(3, entities.size());
+
+ Assert.assertEquals("1", entities.get(0).getProperty("ID").getPrimitiveValue().toString());
+ Assert.assertEquals("ABC",
+ entities.get(0).getProperty("TEXT").getPrimitiveValue().toString());
+ Assert.assertEquals("2", entities.get(1).getProperty("ID").getPrimitiveValue().toString());
+ Assert.assertEquals(
+ "QN6 1311 &&&AmpersandCheck&&& ~!@#$%^&*()_+=-[];',./?><\":}{| @AlmikaPhone",
+ entities.get(1).getProperty("TEXT").getPrimitiveValue().toString());
+ Assert.assertEquals("3", entities.get(2).getProperty("ID").getPrimitiveValue().toString());
+ Assert.assertEquals("}XYZ",
+ entities.get(2).getProperty("TEXT").getPrimitiveValue().toString());
+ }
+
+ @Test
+ public void testGetEntitySetIteratorWithInnerNav() throws IOException, URISyntaxException {
+ String str = "{\"@odata.context\":\"$metadata#Cubes(Name)\","
+ + "\"value\":[{\"@odata.etag\":\"W/\\\"c24af675e00a3f95ef63f223fb9c2cc8d6455459\\\"\","
+ + "\"Name\":\"}Capabilities\","
+ + "\"NavProp\":{\"PropertyInt\":1}}]}";
+
+ InputStream stream = new ByteArrayInputStream(str.getBytes());
+ ODataClient oDataClient = ODataClientFactory.getClient();
+ ClientEntitySetIterator<ClientEntitySet, ClientEntity> entitySetIterator =
+ new ClientEntitySetIterator<ClientEntitySet, ClientEntity>(
+ oDataClient, stream, ContentType.parse(ContentType.JSON.toString()));
+
+ ArrayList<ClientEntity> entities = new ArrayList<ClientEntity>();
+ while (entitySetIterator.hasNext()) {
+ ClientEntity next = entitySetIterator.next();
+ entities.add(next);
+ }
+
+ Assert.assertEquals(1, entities.size());
+ Assert.assertNotNull(entities.get(0).getProperty("NavProp"));
+ Assert.assertEquals("}Capabilities", entities.get(0).getProperty("Name").getPrimitiveValue().toString());
+ }
+
+ @Test
+ public void testGetEntitySetIteratorWithInnerNavArray() throws IOException, URISyntaxException {
+ String str = "{\"@odata.context\":\"$metadata#Cubes(Name)\","
+ + "\"value\":[{\"@odata.etag\":\"W/\\\"c24af675e00a3f95ef63f223fb9c2cc8d6455459\\\"\","
+ + "\"Name\":\"}Capabilities\","
+ + "\"NavProp\":[{\"PropertyInt1\":1},{\"PropertyInt2\":2}]},"
+ + "{\"@odata.etag\":\"W/\\\"c24af675e00a3f95ef63f223fb9c2cc8d6455459\\\"\",\"Name\":\"ABC()}\","
+ + "\"NavProp\":[{\"PropertyInt1\":3}]}]}";
+
+ InputStream stream = new ByteArrayInputStream(str.getBytes());
+ ODataClient oDataClient = ODataClientFactory.getClient();
+ ClientEntitySetIterator<ClientEntitySet, ClientEntity> entitySetIterator =
+ new ClientEntitySetIterator<ClientEntitySet, ClientEntity>(
+ oDataClient, stream, ContentType.parse(ContentType.JSON.toString()));
+
+ ArrayList<ClientEntity> entities = new ArrayList<ClientEntity>();
+ while (entitySetIterator.hasNext()) {
+ ClientEntity next = entitySetIterator.next();
+ entities.add(next);
+ }
+
+ Assert.assertEquals(2, entities.size());
+ Assert.assertNotNull(entities.get(0).getProperty("NavProp"));
+ Assert.assertTrue(entities.get(0).getProperty("NavProp").hasCollectionValue());
+ Assert.assertEquals("}Capabilities", entities.get(0).getProperty("Name").getPrimitiveValue().toString());
+ }
+ @Test
+ public void testGetEntitySetIterator3() throws IOException, URISyntaxException {
+ String str = "{\"@odata.context\":\"$metadata#Cubes(Name)\","
+ + "\"@odata.metadataEtag\": \"W/\\\"582997db-15b9-4a23-a8b0-c91bf45b4194\\\"\","
+ + "\"value\":[{\"PropertyInt16\": 0,\"PropertyString\": \"\"}]}";
+
+ InputStream stream = new ByteArrayInputStream(str.getBytes());
+ ODataClient oDataClient = ODataClientFactory.getClient();
+ ClientEntitySetIterator<ClientEntitySet, ClientEntity> entitySetIterator =
+ new ClientEntitySetIterator<ClientEntitySet, ClientEntity>(
+ oDataClient, stream, ContentType.parse(ContentType.JSON.toString()));
+
+ ArrayList<ClientEntity> entities = new ArrayList<ClientEntity>();
+ while (entitySetIterator.hasNext()) {
+ ClientEntity next = entitySetIterator.next();
+ entities.add(next);
+ }
+
+ Assert.assertEquals(1, entities.size());
+
+ Assert.assertEquals("", entities.get(0).getProperty("PropertyString").getPrimitiveValue().toString());
+ }
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void testEntitySetIteratorRemoveMethod() throws IOException, URISyntaxException {
+ String str = "{\"@odata.context\":\"$metadata#Cubes(Name)\","
+ + "\"@odata.metadataEtag\": \"W/\\\"582997db-15b9-4a23-a8b0-c91bf45b4194\\\"\","
+ + "\"value\":[{\"PropertyInt16\": 0,\"PropertyString\": \"\"}]}";
+
+ InputStream stream = new ByteArrayInputStream(str.getBytes());
+ ODataClient oDataClient = ODataClientFactory.getClient();
+ ClientEntitySetIterator<ClientEntitySet, ClientEntity> entitySetIterator =
+ new ClientEntitySetIterator<ClientEntitySet, ClientEntity>(
+ oDataClient, stream, ContentType.parse(ContentType.JSON.toString()));
+
+ entitySetIterator.remove();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void testEntitySetIteratorGetNextMethod() throws IOException, URISyntaxException {
+ String str = "{\"@odata.context\":\"$metadata#Cubes(Name)\","
+ + "\"@odata.metadataEtag\": \"W/\\\"582997db-15b9-4a23-a8b0-c91bf45b4194\\\"\","
+ + "\"value\":[{\"PropertyInt16\": 0,\"PropertyString\": \"\"}]}";
+
+ InputStream stream = new ByteArrayInputStream(str.getBytes());
+ ODataClient oDataClient = ODataClientFactory.getClient();
+ ClientEntitySetIterator<ClientEntitySet, ClientEntity> entitySetIterator =
+ new ClientEntitySetIterator<ClientEntitySet, ClientEntity>(
+ oDataClient, stream, ContentType.parse(ContentType.JSON.toString()));
+
+ entitySetIterator.getNext();
+ }
+
+ @Test
+ public void testEntitySetIteratorNextLink() throws IOException, URISyntaxException {
+ String str = "{\"@odata.context\":\"$metadata#Cubes(Name)\","
+ + "\"@odata.metadataEtag\": \"W/\\\"582997db-15b9-4a23-a8b0-c91bf45b4194\\\"\","
+ + "\"@odata.nextLink\":\"http://localhost:8082/odata-server-tecsvc/odata.svc/"
+ + "ESServerSidePaging?%24skiptoken=1%2A10\","
+ + "\"value\":[{\"PropertyInt16\": 0,\"PropertyString\": \"\"}]}";
+
+ InputStream stream = new ByteArrayInputStream(str.getBytes());
+ ODataClient oDataClient = ODataClientFactory.getClient();
+ ClientEntitySetIterator<ClientEntitySet, ClientEntity> entitySetIterator =
+ new ClientEntitySetIterator<ClientEntitySet, ClientEntity>(
+ oDataClient, stream, ContentType.parse(ContentType.JSON.toString()));
+
+ ArrayList<ClientEntity> entities = new ArrayList<ClientEntity>();
+ while (entitySetIterator.hasNext()) {
+ ClientEntity next = entitySetIterator.next();
+ entities.add(next);
+ }
+
+ Assert.assertEquals(1, entities.size());
+ Assert.assertNotNull(entitySetIterator.getNext());
+ Assert.assertEquals("http://localhost:8082/odata-server-tecsvc/"
+ + "odata.svc/ESServerSidePaging?%24skiptoken=1%2A10", entitySetIterator.getNext().toString());
+ }
+}