olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sklev...@apache.org
Subject [07/19] git commit: Adding tests for linked entity create / delete
Date Thu, 22 May 2014 10:35:50 GMT
Adding tests for linked entity create / delete


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

Branch: refs/heads/olingo-266-tecsvc
Commit: a12b2b115a9027ef93007d97264628a930cffaf6
Parents: 31550fd
Author: Francesco Chicchiriccò <--global>
Authored: Tue May 20 16:15:06 2014 +0200
Committer: Francesco Chicchiriccò <--global>
Committed: Tue May 20 16:15:06 2014 +0200

----------------------------------------------------------------------
 .../java/org/apache/olingo/fit/V4Services.java  | 24 +++++++++++++-
 .../olingo/fit/v4/PropertyTestITCase.java       | 34 +++++++++++++++++++-
 .../cud/ODataPropertyUpdateRequestImpl.java     |  8 +----
 3 files changed, 57 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a12b2b11/fit/src/main/java/org/apache/olingo/fit/V4Services.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V4Services.java b/fit/src/main/java/org/apache/olingo/fit/V4Services.java
index 9487d1e..52108a8 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V4Services.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V4Services.java
@@ -293,7 +293,7 @@ public class V4Services extends AbstractServices {
               addChangesetItemIntro(chbos, lastContebtID, cboundary);
 
               res = bodyPartRequest(new MimeBodyPart(part.getInputStream()), references);
-              if (res==null || res.getStatus() >= 400) {
+              if (res == null || res.getStatus() >= 400) {
                 throw new Exception("Failure processing changeset");
               }
 
@@ -1317,4 +1317,26 @@ public class V4Services extends AbstractServices {
       return xml.createFaultResponse(accept, e);
     }
   }
+
+  @POST
+  @Path("/Products({productId})/Categories/$ref")
+  public Response createLinked(
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
+          @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
+          final String entity) {
+
+    return xml.createResponse(null, null, null, Status.NO_CONTENT);
+  }
+
+  @DELETE
+  @Path("/Products({productId})/Categories({categoryId})/$ref")
+  public Response deleteLinked(
+          @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+          @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
+          @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
+          final String entity) {
+
+    return xml.createResponse(null, null, null, Status.NO_CONTENT);
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a12b2b11/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java
index 8dbeb86..4142e72 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java
@@ -22,14 +22,19 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 import java.io.IOException;
+import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
 import org.apache.olingo.client.api.communication.request.cud.ODataPropertyUpdateRequest;
 import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType;
 import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest;
+import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
+import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
 import org.apache.olingo.client.api.communication.response.ODataPropertyUpdateResponse;
 import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
 import org.apache.olingo.client.api.http.HttpMethod;
 import org.apache.olingo.client.api.uri.v4.URIBuilder;
 import org.apache.olingo.client.api.v4.ODataClient;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
 import org.apache.olingo.commons.api.domain.v4.ODataProperty;
 import org.apache.olingo.commons.api.domain.v4.ODataValuable;
 import org.apache.olingo.commons.api.format.ODataFormat;
@@ -104,7 +109,7 @@ public class PropertyTestITCase extends AbstractTestITCase {
     final ODataProperty prop = req.execute().getBody();
     assertNotNull(prop);
     // cast to workaround JDK 6 bug, fixed in JDK 7
-    assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Address", 
+    assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Address",
             ((ODataValuable) prop).getValue().getTypeName());
   }
 
@@ -167,4 +172,31 @@ public class PropertyTestITCase extends AbstractTestITCase {
     updateComplexProperty(ODataFormat.JSON_FULL_METADATA, UpdateType.PATCH);
   }
 
+  @Test
+  public void createAndDelete() {
+    // 1. create
+    final ODataEntity category = client.getObjectFactory().newEntity(null);
+    category.setReference(client.getURIBuilder(testStaticServiceRootURL).
+            appendEntitySetSegment("Categories").appendKeySegment(1).build().toASCIIString());
+
+    final URIBuilder createBuilder = client.getURIBuilder(testStaticServiceRootURL).
+            appendEntitySetSegment("Products").appendKeySegment(0).appendNavigationSegment("Categories").
+            appendRefSegment();    
+    final ODataEntityCreateRequest<ODataEntity> createReq = client.getCUDRequestFactory().
+            getEntityCreateRequest(createBuilder.build(), category);
+
+    final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
+    assertEquals(204, createRes.getStatusCode());
+
+    // 2. delete
+    final URIBuilder deleteBuilder = client.getURIBuilder(testStaticServiceRootURL).
+            appendEntitySetSegment("Products").appendKeySegment(0).appendNavigationSegment("Categories").
+            appendKeySegment(1).appendRefSegment();
+    final ODataDeleteRequest deleteReq = client.getCUDRequestFactory().
+            getDeleteRequest(deleteBuilder.build());
+
+    final ODataDeleteResponse deleteRes = deleteReq.execute();
+    assertEquals(204, deleteRes.getStatusCode());
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a12b2b11/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java
b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java
index 81e1dd4..fe2fdbb 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java
@@ -55,7 +55,7 @@ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest<OD
    * @param targetURI entity set or entity or entity property URI.
    * @param property value to be created.
    */
-  ODataPropertyUpdateRequestImpl(final CommonODataClient odataClient,
+  ODataPropertyUpdateRequestImpl(final CommonODataClient<?> odataClient,
           final HttpMethod method, final URI targetURI, final CommonODataProperty property)
{
 
     super(odataClient, ODataFormat.class, method, targetURI);
@@ -63,9 +63,6 @@ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest<OD
     this.property = property;
   }
 
-  /**
-   * {@inheritDoc }
-   */
   @Override
   public ODataPropertyUpdateResponse execute() {
     final InputStream input = getPayload();
@@ -78,9 +75,6 @@ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest<OD
     }
   }
 
-  /**
-   * {@inheritDoc }
-   */
   @Override
   protected InputStream getPayload() {
     return odataClient.getWriter().writeProperty(property, ODataFormat.fromString(getContentType()));


Mime
View raw message