Adding tests for linked entity create / delete
This commit is contained in:
parent
31550fd3bc
commit
a12b2b115a
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
|
|
Loading…
Reference in New Issue