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/02/14 10:05:33 UTC
[13/50] [abbrv] git commit: [OLINGO-117] TDD Unit test and API design
[OLINGO-117] TDD Unit test and API design
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/d8159ab0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/d8159ab0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/d8159ab0
Branch: refs/heads/ODataServlet
Commit: d8159ab0fe7e6528288e23e0eebd0cc6bec9c366
Parents: 0efcc30
Author: Stephan Klevenz <sk...@apache.org>
Authored: Mon Jan 20 15:10:04 2014 +0100
Committer: Stephan Klevenz <sk...@apache.org>
Committed: Mon Jan 20 15:10:04 2014 +0100
----------------------------------------------------------------------
.../olingo/odata2/api/ep/feed/ODataFeed.java | 15 ++
.../odata2/core/ep/feed/ODataFeedImpl.java | 19 ++
.../JsonFeedWithDeltaLinkProducerTest.java | 2 +-
.../odata2/fit/client/ClientDeltaResponse.java | 83 --------
.../fit/client/ClientDeltaResponseTest.java | 197 +++++++++++++++++++
.../olingo/odata2/fit/client/util/Client.java | 27 ++-
6 files changed, 251 insertions(+), 92 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d8159ab0/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/feed/ODataFeed.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/feed/ODataFeed.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/feed/ODataFeed.java
index 9b98ec9..bd76e48 100644
--- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/feed/ODataFeed.java
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/feed/ODataFeed.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.api.ep.feed;
import java.util.List;
+import org.apache.olingo.odata2.api.ep.entry.EntryMetadata;
import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
/**
@@ -40,4 +41,18 @@ public interface ODataFeed {
*/
public FeedMetadata getFeedMetadata();
+ /**
+ * Delta responses can contain changed feed data and deleted entries metadata. A delta response it the result of
+ * a delta link.
+ * @return true in case of feed is result of a delta response (contains changed feed entries and deleted entries)
+ */
+ public boolean isDeltaFeed();
+
+ /**
+ * Delta responses can contain changed feed data and deleted entries metadata. A delta response it the result of
+ * a delta link.
+ * @return metadata of deleted entries in case of feed is result of a delta response
+ */
+ public List<EntryMetadata> getDeletedEntries();
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d8159ab0/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/feed/ODataFeedImpl.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/feed/ODataFeedImpl.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/feed/ODataFeedImpl.java
index 634c0bc..c81890a 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/feed/ODataFeedImpl.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/feed/ODataFeedImpl.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.core.ep.feed;
import java.util.List;
+import org.apache.olingo.odata2.api.ep.entry.EntryMetadata;
import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
import org.apache.olingo.odata2.api.ep.feed.FeedMetadata;
import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
@@ -28,11 +29,19 @@ public class ODataFeedImpl implements ODataFeed {
private final List<ODataEntry> entries;
private final FeedMetadata feedMetadata;
+ private boolean isDeltaFeed = false;
+ private List<EntryMetadata> deletedEntries = null;
public ODataFeedImpl(final List<ODataEntry> entries, final FeedMetadata feedMetadata) {
this.entries = entries;
this.feedMetadata = feedMetadata;
+ }
+ public ODataFeedImpl(final List<ODataEntry> entries, final FeedMetadata feedMetadata, boolean isDeltaFeed,
+ List<EntryMetadata> deletedEntries) {
+ this(entries, feedMetadata);
+ this.isDeltaFeed = isDeltaFeed;
+ this.deletedEntries = deletedEntries;
}
@Override
@@ -45,4 +54,14 @@ public class ODataFeedImpl implements ODataFeed {
return feedMetadata;
}
+ @Override
+ public boolean isDeltaFeed() {
+ return isDeltaFeed;
+ }
+
+ @Override
+ public List<EntryMetadata> getDeletedEntries() {
+ return deletedEntries;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d8159ab0/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 d1ff8ee..4dddc31 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
@@ -52,7 +52,7 @@ public class JsonFeedWithDeltaLinkProducerTest extends BaseTest {
EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).build();
private ArrayList<Map<String, Object>> deletedRoomData;
- protected ArrayList<Map<String, Object>> roomsData;
+ private ArrayList<Map<String, Object>> roomsData;
private Gson gson = new Gson();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d8159ab0/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientDeltaResponse.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientDeltaResponse.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientDeltaResponse.java
deleted file mode 100644
index 32f70af..0000000
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientDeltaResponse.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package org.apache.olingo.odata2.fit.client;
-
-import static org.junit.Assert.*;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
-
-import java.io.IOException;
-import java.net.Proxy;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.ODataService;
-import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
-import org.apache.olingo.odata2.api.edm.Edm;
-import org.apache.olingo.odata2.api.edm.EdmEntitySetInfo;
-import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-import org.apache.olingo.odata2.api.processor.part.MetadataProcessor;
-import org.apache.olingo.odata2.api.uri.info.GetMetadataUriInfo;
-import org.apache.olingo.odata2.core.processor.ODataSingleProcessorService;
-import org.apache.olingo.odata2.fit.client.util.Client;
-import org.apache.olingo.odata2.fit.client.util.HttpException;
-import org.apache.olingo.odata2.ref.edm.ScenarioEdmProvider;
-import org.apache.olingo.odata2.testutil.fit.AbstractFitTest;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-
-public class ClientDeltaResponse extends AbstractFitTest {
-
- private Client client;
-
- @Before
- @Override
- public void before() {
- super.before();
- try {
- client = new Client(getEndpoint().toASCIIString());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- private class StubProcessor extends ODataSingleProcessor {
-
- }
-
- @Override
- protected ODataService createService() throws ODataException {
- EdmProvider provider = new ScenarioEdmProvider();
- ODataSingleProcessor processor = new StubProcessor();
-
- return new ODataSingleProcessorService(provider, processor);
- }
-
- @Test
- public void dummy() throws Exception {}
-
- @Test
- public void testEdm() throws Exception {
- Edm edm = client.getEdm();
- assertNotNull(edm);
- assertNotNull(edm.getDefaultEntityContainer());
-
- System.out.println(edm.getDefaultEntityContainer().getName());
- }
-
- @Test
- public void testEntitySets() throws Exception {
- List<EdmEntitySetInfo> sets = client.getEntitySets();
- assertNotNull(sets);
- assertEquals(6, sets.size());
- }
-
- @Test
- public void testEntity() throws Exception {
- ODataFeed feed = client.readFeed("Container1", "Rooms", "application/atom+xml");
- assertNotNull(feed);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d8159ab0/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientDeltaResponseTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientDeltaResponseTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientDeltaResponseTest.java
new file mode 100644
index 0000000..f641577
--- /dev/null
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientDeltaResponseTest.java
@@ -0,0 +1,197 @@
+package org.apache.olingo.odata2.fit.client;
+
+import static org.junit.Assert.*;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.ODataCallback;
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.edm.Edm;
+import org.apache.olingo.odata2.api.edm.EdmEntitySetInfo;
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.ep.EntityProvider;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
+import org.apache.olingo.odata2.api.ep.callback.TombstoneCallback;
+import org.apache.olingo.odata2.api.ep.entry.EntryMetadata;
+import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.core.ep.producer.TombstoneCallbackImpl;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+import org.apache.olingo.odata2.core.processor.ODataSingleProcessorService;
+import org.apache.olingo.odata2.fit.client.util.Client;
+import org.apache.olingo.odata2.ref.edm.ScenarioEdmProvider;
+import org.apache.olingo.odata2.testutil.fit.AbstractFitTest;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class ClientDeltaResponseTest extends AbstractFitTest {
+
+ private static final String DELTATOKEN_1234 = "!deltatoken=1234";
+
+ private Client client;
+
+ private ArrayList<Map<String, Object>> createRoomData() {
+
+ Map<String, Object> roomData1 = new HashMap<String, Object>();
+ roomData1.put("Id", "1");
+ roomData1.put("Seats", 123);
+ roomData1.put("Version", 1);
+ Map<String, Object> roomData2 = new HashMap<String, Object>();
+ roomData2.put("Id", "2");
+ roomData2.put("Seats", 66);
+ roomData2.put("Version", 2);
+
+ ArrayList<Map<String, Object>> roomsData = new ArrayList<Map<String, Object>>();
+ roomsData.add(roomData1);
+ roomsData.add(roomData2);
+
+ return roomsData;
+ }
+
+ private ArrayList<Map<String, Object>> createDeletedRoomData() {
+ Map<String, Object> roomData1 = new HashMap<String, Object>();
+ roomData1.put("Id", "3");
+ roomData1.put("Seats", 123);
+ roomData1.put("Version", 1);
+ Map<String, Object> roomData2 = new HashMap<String, Object>();
+ roomData2.put("Id", "4");
+ roomData2.put("Seats", 66);
+ roomData2.put("Version", 2);
+
+ ArrayList<Map<String, Object>> deletedRoomData = new ArrayList<Map<String, Object>>();
+ deletedRoomData.add(roomData1);
+ deletedRoomData.add(roomData2);
+ return deletedRoomData;
+ }
+
+ @Before
+ @Override
+ public void before() {
+ super.before();
+ try {
+ client = new Client(getEndpoint().toASCIIString());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ createRoomData();
+ }
+
+ private class StubProcessor extends ODataSingleProcessor {
+
+ @Override
+ public ODataResponse readEntitySet(GetEntitySetUriInfo uriInfo, String contentType) throws ODataException {
+ try {
+ ArrayList<Map<String, Object>> deletedRoomData = null;
+ ODataResponse response = null;
+ EntityProviderWriteProperties properties = null;
+
+ URI requestUri = getContext().getPathInfo().getRequestUri();
+
+ if (requestUri.getQuery() != null && requestUri.getQuery().contains(DELTATOKEN_1234)) {
+ deletedRoomData = createDeletedRoomData();
+ }
+
+ URI deltaLink;
+ deltaLink =
+ new URI(requestUri.getScheme(), requestUri.getUserInfo(), requestUri.getHost(), requestUri.getPort(),
+ requestUri.getPath(), DELTATOKEN_1234, requestUri.getFragment());
+
+ TombstoneCallback tombstoneCallback =
+ new TombstoneCallbackImpl(deletedRoomData, deltaLink.toASCIIString());
+
+ HashMap<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
+ callbacks.put(TombstoneCallback.CALLBACK_KEY_TOMBSTONE, tombstoneCallback);
+
+ properties =
+ EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks(callbacks)
+ .build();
+
+ response = EntityProvider.writeFeed(contentType, uriInfo.getTargetEntitySet(), createRoomData(), properties);
+
+ return response;
+ } catch (URISyntaxException e) {
+ throw new ODataRuntimeException(e);
+
+ }
+ }
+ }
+
+ @Override
+ protected ODataService createService() throws ODataException {
+ EdmProvider provider = new ScenarioEdmProvider();
+ ODataSingleProcessor processor = new StubProcessor();
+
+ return new ODataSingleProcessorService(provider, processor);
+ }
+
+ @Test
+ public void dummy() throws Exception {}
+
+ @Test
+ public void testEdm() throws Exception {
+ Edm edm = client.getEdm();
+ assertNotNull(edm);
+ assertNotNull(edm.getDefaultEntityContainer());
+
+ System.out.println(edm.getDefaultEntityContainer().getName());
+ }
+
+ @Test
+ public void testEntitySets() throws Exception {
+ List<EdmEntitySetInfo> sets = client.getEntitySets();
+ assertNotNull(sets);
+ assertEquals(6, sets.size());
+ }
+
+ private void testDeltaFeedWithDeltaLink(String contentType) throws Exception {
+ ODataFeed feed = client.readFeed("Container1", "Rooms", contentType);
+ String deltaLink = feed.getFeedMetadata().getDeltaLink();
+
+ assertNotNull(feed);
+ assertEquals(2, feed.getEntries().size());
+ assertEquals(getEndpoint().toASCIIString() + "Rooms?" + DELTATOKEN_1234, feed.getFeedMetadata().getDeltaLink());
+ assertFalse(feed.isDeltaFeed());
+
+ URI uri = new URI(deltaLink);
+ String query = uri.getQuery();
+ ODataFeed deltaFeed = client.readFeed("Container1", "Rooms", contentType, query);
+
+ assertNotNull(deltaFeed);
+ assertEquals(2, deltaFeed.getEntries().size());
+ assertEquals(uri.toASCIIString(), deltaFeed.getFeedMetadata().getDeltaLink());
+
+ assertTrue(deltaFeed.isDeltaFeed());
+ List<EntryMetadata> deletedEntries = deltaFeed.getDeletedEntries();
+ assertNotNull(deletedEntries);
+ assertEquals(2, deletedEntries.size());
+
+ assertEquals("3", deletedEntries.get(0).getId());
+ assertEquals("uri3", deletedEntries.get(0).getUri());
+
+ assertEquals("4", deletedEntries.get(1).getId());
+ assertEquals("uri4", deletedEntries.get(1).getUri());
+ }
+
+ @Test
+ public void testDeltaFeedWithDeltaLinkXml() throws Exception {
+ testDeltaFeedWithDeltaLink("application/atom+xml");
+ }
+
+ @Test
+ @Ignore("not implemented")
+ public void testFeedWithDeltaLinkJson() throws Exception {
+ testDeltaFeedWithDeltaLink("application/json");
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d8159ab0/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/util/Client.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/util/Client.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/util/Client.java
index ef68b58..bf682b5 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/util/Client.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/util/Client.java
@@ -37,7 +37,8 @@ public class Client {
private Edm edm;
- public Client(String serviceUrl, Proxy.Type protocol, String proxy, int port) throws IOException, ODataException, HttpException {
+ public Client(String serviceUrl, Proxy.Type protocol, String proxy, int port) throws IOException, ODataException,
+ HttpException {
this.serviceUrl = serviceUrl;
this.protocol = protocol;
this.proxy = proxy;
@@ -56,7 +57,8 @@ public class Client {
edm = getEdmInternal();
}
- public Client(String serviceUrl, Proxy.Type protocol, String proxy, int port, String username, String password) throws IOException, ODataException, HttpException {
+ public Client(String serviceUrl, Proxy.Type protocol, String proxy, int port, String username, String password)
+ throws IOException, ODataException, HttpException {
this.serviceUrl = serviceUrl;
this.protocol = protocol;
this.proxy = proxy;
@@ -80,7 +82,7 @@ public class Client {
}
private Edm getEdmInternal() throws IOException, ODataException, HttpException {
- HttpURLConnection connection = connect(METADATA, APPLICATION_XML, "GET");
+ HttpURLConnection connection = connect(METADATA, null, APPLICATION_XML, "GET");
edm = EntityProvider.readMetadata((InputStream) connection.getContent(), false);
return edm;
}
@@ -100,7 +102,13 @@ public class Client {
return edm.getServiceMetadata().getEntitySetInfos();
}
- public ODataFeed readFeed(String entityContainerName, String entitySetName, String contentType) throws IOException, ODataException, HttpException {
+ public ODataFeed readFeed(String entityContainerName, String entitySetName, String contentType) throws IOException,
+ ODataException, HttpException {
+ return readFeed(entityContainerName, entitySetName, contentType, null);
+ }
+
+ public ODataFeed readFeed(String entityContainerName, String entitySetName, String contentType, String query)
+ throws IOException, ODataException, HttpException {
EdmEntityContainer entityContainer = edm.getEntityContainer(entityContainerName);
String relativeUri;
if (entityContainer.isDefaultEntityContainer()) {
@@ -109,12 +117,15 @@ public class Client {
relativeUri = entityContainerName + "." + entitySetName;
}
- InputStream content = (InputStream) connect(relativeUri, contentType, "GET").getContent();
- return EntityProvider.readFeed(contentType, entityContainer.getEntitySet(entitySetName), content, EntityProviderReadProperties.init().build());
+ InputStream content = (InputStream) connect(relativeUri, query, contentType, "GET").getContent();
+ return EntityProvider.readFeed(contentType, entityContainer.getEntitySet(entitySetName), content,
+ EntityProviderReadProperties.init().build());
}
- private HttpURLConnection connect(String relativeUri, String contentType, String httpMethod) throws IOException, HttpException {
- URL url = new URL(serviceUrl + relativeUri);
+ private HttpURLConnection connect(String relativeUri, String query, String contentType, String httpMethod)
+ throws IOException,
+ HttpException {
+ URL url = new URL(serviceUrl + relativeUri + (query != null ? "?" + query : ""));
HttpURLConnection connection;
if (useProxy) {
Proxy proxy = new Proxy(protocol, new InetSocketAddress(this.proxy, port));