From a12b2b115a9027ef93007d97264628a930cffaf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= <--global> Date: Tue, 20 May 2014 16:15:06 +0200 Subject: [PATCH] Adding tests for linked entity create / delete --- .../org/apache/olingo/fit/V4Services.java | 24 ++++++++++++- .../olingo/fit/v4/PropertyTestITCase.java | 34 ++++++++++++++++++- .../cud/ODataPropertyUpdateRequestImpl.java | 8 +---- 3 files changed, 57 insertions(+), 9 deletions(-) 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 9487d1e96..52108a8c4 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); + } } 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 8dbeb8647..4142e72b4 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 createReq = client.getCUDRequestFactory(). + getEntityCreateRequest(createBuilder.build(), category); + + final ODataEntityCreateResponse 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()); + } + } 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 81e1dd4b8..fe2fdbbbd 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 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