You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2014/01/14 12:28:04 UTC
[12/12] git commit: [OLINGO-117] deleted entries support]
[OLINGO-117] deleted entries support]
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/0848b544
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/0848b544
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/0848b544
Branch: refs/heads/olingo-117
Commit: 0848b5448db49d097fb91f6339f81cfe6bc298db
Parents: 171352a
Author: Stephan Klevenz <sk...@apache.org>
Authored: Tue Jan 14 09:50:51 2014 +0100
Committer: Stephan Klevenz <sk...@apache.org>
Committed: Tue Jan 14 12:26:56 2014 +0100
----------------------------------------------------------------------
.../JsonDeletedEntryEntityProducer.java | 26 ++++++++-
.../JsonFeedWithDeltaLinkProducerTest.java | 57 ++++++++++++++++----
2 files changed, 72 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0848b544/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonDeletedEntryEntityProducer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonDeletedEntryEntityProducer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonDeletedEntryEntityProducer.java
index 88f54f2..14baf52 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonDeletedEntryEntityProducer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonDeletedEntryEntityProducer.java
@@ -1,3 +1,21 @@
+/*******************************************************************************
+ * 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.
+ ******************************************************************************/
package org.apache.olingo.odata2.core.ep.producer;
import java.io.IOException;
@@ -25,6 +43,7 @@ public class JsonDeletedEntryEntityProducer {
try {
if (deletedEntries.size() > 0) {
jsonStreamWriter.separator();
+ int counter = 0;
for (Map<String, Object> deletedEntry : deletedEntries) {
jsonStreamWriter.beginObject();
@@ -35,8 +54,13 @@ public class JsonDeletedEntryEntityProducer {
jsonStreamWriter.namedStringValue(FormatJson.ODATA_CONTEXT, odataContextValue);
jsonStreamWriter.separator();
jsonStreamWriter.namedStringValue(FormatJson.ID, idValue);
-
jsonStreamWriter.endObject();
+
+ if (counter < deletedEntries.size()) {
+ jsonStreamWriter.separator();
+ }
+
+ counter++;
}
}
} catch (final IOException e) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0848b544/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedWithDeltaLinkProducerTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedWithDeltaLinkProducerTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedWithDeltaLinkProducerTest.java
index 03d7e0c..a3c5fc0 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedWithDeltaLinkProducerTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedWithDeltaLinkProducerTest.java
@@ -1,15 +1,33 @@
+/*******************************************************************************
+ * 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.
+ ******************************************************************************/
package org.apache.olingo.odata2.core.ep.producer;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.InputStream;
-import java.lang.reflect.Type;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.apache.olingo.odata2.api.ODataCallback;
@@ -26,8 +44,6 @@ import org.junit.Before;
import org.junit.Test;
import com.google.gson.Gson;
-import com.google.gson.internal.StringMap;
-import com.google.gson.reflect.TypeToken;
public class JsonFeedWithDeltaLinkProducerTest extends BaseTest {
@@ -38,6 +54,8 @@ public class JsonFeedWithDeltaLinkProducerTest extends BaseTest {
private ArrayList<Map<String, Object>> deletedRoomData;
protected ArrayList<Map<String, Object>> roomsData;
+ private Gson gson = new Gson();
+
private void initializeRoomData() {
Map<String, Object> roomData1 = new HashMap<String, Object>();
roomData1.put("Id", "1");
@@ -55,7 +73,7 @@ public class JsonFeedWithDeltaLinkProducerTest extends BaseTest {
private void initializeDeletedRoomData() {
deletedRoomData = new ArrayList<Map<String, Object>>();
- for (int i = 2; i <= roomsData.size(); i = i + 2) {
+ for (int i = roomsData.size() + 1; i <= roomsData.size() + 1 + 2; i++) {
HashMap<String, Object> tmp = new HashMap<String, Object>();
tmp.put("Id", "" + i);
tmp.put("Name", "Neu Schwanstein" + i);
@@ -93,9 +111,7 @@ public class JsonFeedWithDeltaLinkProducerTest extends BaseTest {
final String json = writeRoomData(entitySet, tombstoneCallback);
- assertTrue("Somthing wring with @odata.context!", json
- .contains("{\"@odata.context\":\"$metadata#Rooms/$deletedEntity\",\""));
- System.out.println(json);
+ assertDeletedEntries(json);
}
@Test
@@ -109,8 +125,21 @@ public class JsonFeedWithDeltaLinkProducerTest extends BaseTest {
assertTrue("Delta Link missing or wrong!", json
.contains("__delta\":\"http://host:80/service/Rooms?!deltatoken=1234"));
- assertTrue("Somthing wring with @odata.context!", json
+ assertDeletedEntries(json);
+ }
+
+ private void assertDeletedEntries(final String json) {
+ assertTrue("Somthing wrong with @odata.context!", json
.contains("{\"@odata.context\":\"$metadata#Rooms/$deletedEntity\",\""));
+ assertTrue(
+ "Somthing wrong with deleted entry!",
+ json.contains("{\"@odata.context\":\"$metadata#Rooms/$deletedEntity\",\"id\":\"http://host:80/service/Rooms('3')\"}"));
+ assertTrue(
+ "Somthing wrong with deleted entry!",
+ json.contains("{\"@odata.context\":\"$metadata#Rooms/$deletedEntity\",\"id\":\"http://host:80/service/Rooms('4')\"}"));
+ assertTrue(
+ "Somthing wrong with deleted entry!",
+ json.contains("{\"@odata.context\":\"$metadata#Rooms/$deletedEntity\",\"id\":\"http://host:80/service/Rooms('5')\"}"));
}
private String writeRoomData(final EdmEntitySet entitySet, TombstoneCallback tombstoneCallback)
@@ -129,7 +158,15 @@ public class JsonFeedWithDeltaLinkProducerTest extends BaseTest {
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
+
+ validate(json);
+
return json;
}
+ private void validate(String json) {
+ Object obj = gson.fromJson(json, Object.class);
+ assertNotNull(obj);
+ }
+
}