olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [44/50] [abbrv] git commit: [OLINGO-402] Implement omitETag flag
Date Tue, 02 Sep 2014 11:50:04 GMT
[OLINGO-402] Implement omitETag flag


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/868e7e86
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/868e7e86
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/868e7e86

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 868e7e86ff8ecfc2f4d40b48486a9bd773786591
Parents: 575c59f
Author: Christian Amend <chrisam@apache.org>
Authored: Tue Aug 12 17:08:38 2014 +0200
Committer: Christian Amend <chrisam@apache.org>
Committed: Tue Aug 12 17:08:38 2014 +0200

----------------------------------------------------------------------
 .../api/ep/EntityProviderWriteProperties.java   | 11 +++
 .../ep/producer/AtomEntryEntityProducer.java    | 10 ++-
 .../ep/producer/JsonEntryEntityProducer.java    | 10 ++-
 .../ep/ODataEntityProviderPropertiesTest.java   |  4 +
 .../core/ep/producer/AtomEntryProducerTest.java | 82 +++++++++++++++++---
 .../producer/JsonEntryEntityProducerTest.java   | 71 +++++++++++++++++
 6 files changed, 171 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/868e7e86/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java
b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java
index cd6aad6..838c431 100644
--- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java
@@ -44,9 +44,14 @@ public class EntityProviderWriteProperties {
   private Map<String, Map<String, Object>> additionalLinks;
   private boolean omitJsonWrapper;
   private boolean contentOnly;
+  private boolean omitETag;
 
   private EntityProviderWriteProperties() {}
 
+  public final boolean isOmitETag() {
+    return omitETag;
+  }
+
   public final boolean isContentOnly() {
     return contentOnly;
   }
@@ -224,6 +229,11 @@ public class EntityProviderWriteProperties {
       properties.contentOnly = contentOnly;
       return this;
     }
+    
+    public ODataEntityProviderPropertiesBuilder omitETag(final boolean omitETag) {
+      properties.omitETag = omitETag;
+      return this;
+    }
 
     public ODataEntityProviderPropertiesBuilder fromProperties(final EntityProviderWriteProperties
properties) {
       this.properties.inlineCountType = properties.getInlineCountType();
@@ -236,6 +246,7 @@ public class EntityProviderWriteProperties {
       this.properties.additionalLinks = properties.additionalLinks;
       this.properties.omitJsonWrapper = properties.omitJsonWrapper;
       this.properties.contentOnly = properties.contentOnly;
+      this.properties.omitETag = properties.omitETag;
       return this;
     }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/868e7e86/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java
index 97c606f..9715f3d 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java
@@ -90,11 +90,13 @@ public class AtomEntryEntityProducer {
             .toASCIIString());
       }
 
-      etag = createETag(eia, data);
-      if (etag != null) {
-        writer.writeAttribute(Edm.NAMESPACE_M_2007_08, FormatXml.M_ETAG, etag);
+      if (!properties.isContentOnly() && !properties.isOmitETag()) {
+        etag = createETag(eia, data);
+        if (etag != null) {
+          writer.writeAttribute(Edm.NAMESPACE_M_2007_08, FormatXml.M_ETAG, etag);
+        }
       }
-
+      
       String selfLink = null;
       if (!properties.isContentOnly()) {
         // write all atom infos (mandatory and optional)

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/868e7e86/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java
index ab2daf8..fea6a49 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java
@@ -209,10 +209,12 @@ public class JsonEntryEntityProducer {
     jsonStreamWriter.namedStringValue(FormatJson.URI, location);
     jsonStreamWriter.separator();
     jsonStreamWriter.namedStringValueRaw(FormatJson.TYPE, type.getNamespace() + Edm.DELIMITER
+ type.getName());
-    eTag = AtomEntryEntityProducer.createETag(entityInfo, data);
-    if (eTag != null) {
-      jsonStreamWriter.separator();
-      jsonStreamWriter.namedStringValue(FormatJson.ETAG, eTag);
+    if (!properties.isOmitETag()) {
+      eTag = AtomEntryEntityProducer.createETag(entityInfo, data);
+      if (eTag != null) {
+        jsonStreamWriter.separator();
+        jsonStreamWriter.namedStringValue(FormatJson.ETAG, eTag);
+      }
     }
     if (type.hasStream()) {
       jsonStreamWriter.separator();

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/868e7e86/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ODataEntityProviderPropertiesTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ODataEntityProviderPropertiesTest.java
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ODataEntityProviderPropertiesTest.java
index 94f6650..a484eef 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ODataEntityProviderPropertiesTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ODataEntityProviderPropertiesTest.java
@@ -75,6 +75,7 @@ public class ODataEntityProviderPropertiesTest extends BaseTest {
         .additionalLinks(links)
         .omitJsonWrapper(true)
         .contentOnly(true)
+        .omitETag(true)
         .build();
 
     assertEquals("Wrong amount of callbacks.", 1, properties.getCallbacks().size());
@@ -89,6 +90,7 @@ public class ODataEntityProviderPropertiesTest extends BaseTest {
     assertEquals(Collections.emptyMap(), properties.getAdditionalLinks().get("aNavigationProperty"));
     assertTrue("Json Wrapper should be omitted", properties.isOmitJsonWrapper());
     assertTrue("ContentOnlyFlag should be set", properties.isContentOnly());
+    assertTrue("OmitETag should be set", properties.isOmitETag());
   }
 
   @Test
@@ -111,6 +113,7 @@ public class ODataEntityProviderPropertiesTest extends BaseTest {
         .additionalLinks(links)
         .omitJsonWrapper(true)
         .contentOnly(true)
+        .omitETag(true)
         .build();
 
     //
@@ -130,5 +133,6 @@ public class ODataEntityProviderPropertiesTest extends BaseTest {
     assertEquals(Collections.emptyMap(), fromProperties.getAdditionalLinks().get("aNavigationProperty"));
     assertTrue("Json Wrapper should be omitted", properties.isOmitJsonWrapper());
     assertTrue("ContentOnlyFlag should be set", properties.isContentOnly());
+    assertTrue("OmitETag should be set", properties.isOmitETag());
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/868e7e86/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
index 7c26984..f3e4545 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
@@ -68,9 +68,6 @@ import org.custommonkey.xmlunit.exceptions.XpathException;
 import org.junit.Test;
 import org.xml.sax.SAXException;
 
-/**
- *  
- */
 public class AtomEntryProducerTest extends AbstractProviderTest {
 
   public AtomEntryProducerTest(final StreamWriterImplType type) {
@@ -78,6 +75,66 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
   }
 
   @Test
+  public void omitETagTestPropertyPresent() throws Exception {
+    final EntityProviderWriteProperties properties =
+        EntityProviderWriteProperties.serviceRoot(BASE_URI).omitETag(true).build();
+    AtomEntityProvider ser = createAtomEntityProvider();
+
+    Map<String, Object> localRoomData = new HashMap<String, Object>();
+    localRoomData.put("Id", "1");
+    localRoomData.put("Name", "Neu Schwanstein");
+    localRoomData.put("Seats", new Integer(20));
+    localRoomData.put("Version", new Integer(3));
+    ODataResponse response =
+        ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"),
localRoomData,
+            properties);
+    String xmlString = verifyResponse(response);
+    assertXpathNotExists("/a:entry[@m:etag]", xmlString);
+  }
+
+  @Test
+  public void omitETagTestPropertyNOTPresentMustNotResultInException() throws Exception {
+    final EntityProviderWriteProperties properties =
+        EntityProviderWriteProperties.serviceRoot(BASE_URI).omitETag(true).build();
+    AtomEntityProvider ser = createAtomEntityProvider();
+
+    Map<String, Object> localRoomData = new HashMap<String, Object>();
+    localRoomData.put("Id", "1");
+    localRoomData.put("Name", "Neu Schwanstein");
+    localRoomData.put("Seats", new Integer(20));
+    ODataResponse response =
+        ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"),
localRoomData,
+            properties);
+    String xmlString = verifyResponse(response);
+    assertXpathNotExists("/a:entry[@m:etag]", xmlString);
+  }
+
+  @Test
+  public void omitETagTestNonNullablePropertyNOTPresentMustNotResultInException() throws
Exception {
+    EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
+    EdmProperty versionProperty = (EdmProperty) entitySet.getEntityType().getProperty("Version");
+    EdmFacets facets = versionProperty.getFacets();
+    when(facets.isNullable()).thenReturn(new Boolean(false));
+    List<String> selectedPropertyNames = new ArrayList<String>();
+    selectedPropertyNames.add("Id");
+    selectedPropertyNames.add("Name");
+    selectedPropertyNames.add("Seats");
+    ExpandSelectTreeNode selectNode =
+        ExpandSelectTreeNode.entitySet(entitySet).selectedProperties(selectedPropertyNames).build();
+    final EntityProviderWriteProperties properties =
+        EntityProviderWriteProperties.serviceRoot(BASE_URI).omitETag(true).expandSelectTree(selectNode).build();
+    AtomEntityProvider ser = createAtomEntityProvider();
+
+    Map<String, Object> localRoomData = new HashMap<String, Object>();
+    localRoomData.put("Id", "1");
+    localRoomData.put("Name", "Neu Schwanstein");
+    localRoomData.put("Seats", new Integer(20));
+    ODataResponse response = ser.writeEntry(entitySet, localRoomData, properties);
+    String xmlString = verifyResponse(response);
+    assertXpathNotExists("/a:entry[@m:etag]", xmlString);
+  }
+
+  @Test
   public void contentOnly() throws Exception {
     final EntityProviderWriteProperties properties =
         EntityProviderWriteProperties.serviceRoot(BASE_URI).contentOnly(true).build();
@@ -90,6 +147,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
     assertXpathExists("/a:entry", xmlString);
     assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString);
 
+    assertXpathNotExists("/a:entry[@m:etag]", xmlString);
     assertXpathNotExists("/a:entry/a:id", xmlString);
     assertXpathNotExists("/a:entry/a:title", xmlString);
     assertXpathNotExists("/a:entry/a:updated", xmlString);
@@ -121,7 +179,8 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
     String xmlString = verifyResponse(response);
     assertXpathExists("/a:entry", xmlString);
     assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString);
-
+    assertXpathNotExists("/a:entry[@m:etag]", xmlString);
+    
     assertXpathNotExists("/a:entry/a:id", xmlString);
     assertXpathNotExists("/a:entry/a:title", xmlString);
     assertXpathNotExists("/a:entry/a:updated", xmlString);
@@ -155,7 +214,8 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
     String xmlString = verifyResponse(response);
     assertXpathExists("/a:entry", xmlString);
     assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString);
-
+    assertXpathNotExists("/a:entry[@m:etag]", xmlString);
+    
     assertXpathNotExists("/a:entry/a:id", xmlString);
     assertXpathNotExists("/a:entry/a:title", xmlString);
     assertXpathNotExists("/a:entry/a:updated", xmlString);
@@ -189,7 +249,8 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
     String xmlString = verifyResponse(response);
     assertXpathExists("/a:entry", xmlString);
     assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString);
-
+    assertXpathNotExists("/a:entry[@m:etag]", xmlString);
+    
     assertXpathNotExists("/a:entry/a:id", xmlString);
     assertXpathNotExists("/a:entry/a:title", xmlString);
     assertXpathNotExists("/a:entry/a:updated", xmlString);
@@ -221,7 +282,8 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
     String xmlString = verifyResponse(response);
     assertXpathExists("/a:entry", xmlString);
     assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString);
-
+    assertXpathNotExists("/a:entry[@m:etag]", xmlString);
+    
     assertXpathNotExists("/a:entry/a:id", xmlString);
     assertXpathNotExists("/a:entry/a:title", xmlString);
     assertXpathNotExists("/a:entry/a:updated", xmlString);
@@ -264,7 +326,8 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
     String xmlString = verifyResponse(response);
     assertXpathExists("/a:entry", xmlString);
     assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString);
-
+    assertXpathNotExists("/a:entry[@m:etag]", xmlString);
+    
     assertXpathNotExists("/a:entry/a:id", xmlString);
     assertXpathNotExists("/a:entry/a:title", xmlString);
     assertXpathNotExists("/a:entry/a:updated", xmlString);
@@ -305,7 +368,8 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
     String xmlString = verifyResponse(response);
     assertXpathExists("/a:entry", xmlString);
     assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString);
-
+    assertXpathNotExists("/a:entry[@m:etag]", xmlString);
+    
     assertXpathNotExists("/a:entry/a:id", xmlString);
     assertXpathNotExists("/a:entry/a:title", xmlString);
     assertXpathNotExists("/a:entry/a:updated", xmlString);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/868e7e86/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
index 7052fb0..7845b6d 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
@@ -19,6 +19,7 @@
 package org.apache.olingo.odata2.core.ep.producer;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -40,6 +41,7 @@ import java.util.TimeZone;
 import org.apache.olingo.odata2.api.ODataCallback;
 import org.apache.olingo.odata2.api.edm.EdmEntitySet;
 import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmFacets;
 import org.apache.olingo.odata2.api.edm.EdmMapping;
 import org.apache.olingo.odata2.api.edm.EdmProperty;
 import org.apache.olingo.odata2.api.ep.EntityProviderException;
@@ -89,6 +91,75 @@ public class JsonEntryEntityProducerTest extends BaseTest {
 
   @SuppressWarnings("unchecked")
   @Test
+  public void omitETagTestPropertyPresent() throws Exception {
+    final EntityProviderWriteProperties properties =
+        EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).omitETag(true).omitJsonWrapper(true).build();
+
+    Map<String, Object> localRoomData = new HashMap<String, Object>();
+    localRoomData.put("Id", "1");
+    localRoomData.put("Name", "Neu Schwanstein");
+    localRoomData.put("Seats", new Integer(20));
+    localRoomData.put("Version", new Integer(3));
+    final ODataResponse response =
+        new JsonEntityProvider().writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"),
+            localRoomData, properties);
+    Map<String, Object> room =
+        (Map<String, Object>) new Gson().fromJson(new InputStreamReader((InputStream)
response.getEntity()), Map.class);
+
+    room = (Map<String, Object>) room.get("__metadata");
+    assertFalse(room.containsKey("etag"));
+  }
+
+  @SuppressWarnings("unchecked")
+  @Test
+  public void omitETagTestPropertyNOTPresentMustNotResultInException() throws Exception {
+    final EntityProviderWriteProperties properties =
+        EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).omitETag(true).omitJsonWrapper(true).build();
+
+    Map<String, Object> localRoomData = new HashMap<String, Object>();
+    localRoomData.put("Id", "1");
+    localRoomData.put("Name", "Neu Schwanstein");
+    localRoomData.put("Seats", new Integer(20));
+    final ODataResponse response =
+        new JsonEntityProvider().writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"),
+            localRoomData, properties);
+    Map<String, Object> room =
+        (Map<String, Object>) new Gson().fromJson(new InputStreamReader((InputStream)
response.getEntity()), Map.class);
+
+    room = (Map<String, Object>) room.get("__metadata");
+    assertFalse(room.containsKey("etag"));
+  }
+
+  @SuppressWarnings("unchecked")
+  @Test
+  public void omitETagTestNonNullablePropertyNOTPresentMustNotResultInException() throws
Exception {
+    EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
+    EdmProperty versionProperty = (EdmProperty) entitySet.getEntityType().getProperty("Version");
+    EdmFacets facets = versionProperty.getFacets();
+    when(facets.isNullable()).thenReturn(new Boolean(false));
+    List<String> selectedPropertyNames = new ArrayList<String>();
+    selectedPropertyNames.add("Id");
+    selectedPropertyNames.add("Name");
+    selectedPropertyNames.add("Seats");
+    ExpandSelectTreeNode selectNode =
+        ExpandSelectTreeNode.entitySet(entitySet).selectedProperties(selectedPropertyNames).build();
+    final EntityProviderWriteProperties properties =
+        EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).omitETag(true).omitJsonWrapper(true)
+            .expandSelectTree(selectNode).build();
+    Map<String, Object> localRoomData = new HashMap<String, Object>();
+    localRoomData.put("Id", "1");
+    localRoomData.put("Name", "Neu Schwanstein");
+    localRoomData.put("Seats", new Integer(20));
+    final ODataResponse response = new JsonEntityProvider().writeEntry(entitySet, localRoomData,
properties);
+    Map<String, Object> room =
+        (Map<String, Object>) new Gson().fromJson(new InputStreamReader((InputStream)
response.getEntity()), Map.class);
+
+    room = (Map<String, Object>) room.get("__metadata");
+    assertFalse(room.containsKey("etag"));
+  }
+
+  @SuppressWarnings("unchecked")
+  @Test
   public void contentOnly() throws Exception {
     HashMap<String, Object> employeeData = new HashMap<String, Object>();
     Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));


Mime
View raw message