olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chr...@apache.org
Subject olingo-odata4 git commit: [OLINGO-704] Small fix TecSvc
Date Mon, 29 Jun 2015 21:56:01 GMT
Repository: olingo-odata4
Updated Branches:
  refs/heads/master b51117477 -> b3dcaa25b


[OLINGO-704] Small fix TecSvc


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

Branch: refs/heads/master
Commit: b3dcaa25b3d485b886f06913e4adc1635e3cd2bf
Parents: b511174
Author: Christian Holzer <c.holzer@sap.com>
Authored: Mon Jun 29 23:54:45 2015 +0200
Committer: Christian Holzer <c.holzer@sap.com>
Committed: Mon Jun 29 23:54:45 2015 +0200

----------------------------------------------------------------------
 .../tecsvc/client/EntityReferencesITCase.java   | 46 ++++++++++++++++++++
 .../processor/TechnicalEntityProcessor.java     | 13 +++++-
 .../tecsvc/processor/TechnicalProcessor.java    |  5 ++-
 3 files changed, 61 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b3dcaa25/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java
index 3e3377e..7b24bb5 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
 
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -37,7 +38,9 @@ import org.apache.olingo.client.api.communication.response.ODataReferenceAddingR
 import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
 import org.apache.olingo.client.api.domain.ClientEntity;
 import org.apache.olingo.client.api.domain.ClientEntitySet;
+import org.apache.olingo.client.api.domain.ClientObjectFactory;
 import org.apache.olingo.client.api.uri.QueryOption;
+import org.apache.olingo.client.api.uri.URIBuilder;
 import org.apache.olingo.client.core.ODataClientFactory;
 import org.apache.olingo.commons.api.format.ContentType;
 import org.apache.olingo.commons.api.http.HttpHeader;
@@ -984,6 +987,49 @@ public class EntityReferencesITCase extends AbstractBaseTestITCase {
     assertNull(responseGetESTwoKeyNav.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE));
   }
   
+  @Test
+  public void testCreateMissingNavigationProperty() throws Exception {
+    final ODataClient client = getClient();
+    final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendRefSegment().build();
+    final URI ref = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).build();
+    
+    try {
+      client.getCUDRequestFactory().getReferenceAddingRequest(new URI(SERVICE_URI), uri,
ref).execute();
+    } catch (ODataClientErrorException e) {
+      assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode());
+    }
+  }
+  
+  @Test
+  public void testUpdateMissingNavigationProperty() throws Exception {
+    final ODataClient client = getClient();
+    final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
+                                                     .appendKeySegment(1)
+                                                     .appendRefSegment()
+                                                     .build();
+    final URI ref = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).build();
+    
+    try {
+      client.getCUDRequestFactory().getReferenceSingleChangeRequest(new URI(SERVICE_URI),
uri, ref).execute();
+    } catch (ODataClientErrorException e) {
+      assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode());
+    }
+  }
+  
+  @Test
+  public void testDeleteMissingNavigationProperty() {
+    final ODataClient client = getClient();
+    final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
+                                                     .appendRefSegment()
+                                                     .build();
+    
+    try {
+      client.getCUDRequestFactory().getDeleteRequest(uri);
+    } catch (ODataClientErrorException e) {
+      assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode());
+    }
+  }
+  
   private void sendRequest(final URI uri, final int count, final String... expected) {
     final ODataClient client = getClient();
     final ODataRetrieveResponse<ClientEntitySet> response = client.getRetrieveRequestFactory()

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b3dcaa25/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 2904e18..2045704 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
@@ -318,6 +318,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
 
     final Entity entity = readEntity(uriInfo, true);
     final UriResourceNavigation navigationProperty = getLastNavigation(uriInfo);
+    ensureNavigationPropertyNotNull(navigationProperty);
     dataProvider.createReference(entity, navigationProperty.getProperty(), references.getEntityReferences().get(0),
         request.getRawBaseUri());
 
@@ -338,6 +339,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
 
     final Entity entity = readEntity(uriInfo, true);
     final UriResourceNavigation navigationProperty = getLastNavigation(uriInfo);
+    ensureNavigationPropertyNotNull(navigationProperty);
     dataProvider.createReference(entity, navigationProperty.getProperty(), references.getEntityReferences().get(0),
         request.getRawBaseUri());
 
@@ -350,7 +352,8 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
 
     final UriResourceNavigation lastNavigation = getLastNavigation(uriInfo);
     final IdOption idOption = uriInfo.getIdOption();
-
+    
+    ensureNavigationPropertyNotNull(lastNavigation);
     if (lastNavigation.isCollection() && idOption == null) {
       throw new ODataApplicationException("Id system query option must be provided",
           HttpStatusCode.BAD_REQUEST.getStatusCode(),
@@ -537,4 +540,12 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
         .suffix(isSingleEntity && entitySet != null ? Suffix.ENTITY : null);
     return builder.build();
   }
+  
+  private void ensureNavigationPropertyNotNull(final UriResourceNavigation navigationProperty)
+      throws ODataApplicationException {
+    if(navigationProperty == null) {
+      throw new ODataApplicationException("Missing navigation segment", HttpStatusCode.BAD_REQUEST.getStatusCode(),
+          Locale.ROOT);
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b3dcaa25/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
index 55c0761..e0dd7dd 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
@@ -213,8 +213,9 @@ public abstract class TechnicalProcessor implements Processor {
         && resourcePaths.get(navigationCount) instanceof UriResourceNavigation) {
       navigationCount++;
     }
-
-    return (UriResourceNavigation) resourcePaths.get(--navigationCount);
+    
+    final UriResource lastSegment = resourcePaths.get(--navigationCount);
+    return (lastSegment instanceof UriResourceNavigation) ? (UriResourceNavigation) lastSegment
: null;
   }
 
   private void blockTypeFilters(final UriResource uriResource) throws ODataApplicationException
{


Mime
View raw message