mirror of
https://github.com/apache/olingo-odata4.git
synced 2025-03-05 16:19:05 +00:00
[OLINGO-200] V4 ODataValue full reachable via API
This commit is contained in:
parent
117cf6f0d0
commit
dc2922c956
@ -35,11 +35,12 @@ public interface CommonCUDRequestFactory extends Serializable {
|
||||
* <br/>
|
||||
* Use this kind of request to create a new entity.
|
||||
*
|
||||
* @param <E> concrete ODataEntity implementation
|
||||
* @param targetURI entity set URI.
|
||||
* @param entity entity to be created.
|
||||
* @return new ODataEntityCreateRequest instance.
|
||||
*/
|
||||
ODataEntityCreateRequest getEntityCreateRequest(URI targetURI, CommonODataEntity entity);
|
||||
<E extends CommonODataEntity> ODataEntityCreateRequest<E> getEntityCreateRequest(URI targetURI, E entity);
|
||||
|
||||
/**
|
||||
* Gets an update request object instance.
|
||||
|
@ -20,10 +20,14 @@ package org.apache.olingo.client.api.communication.request.cud;
|
||||
|
||||
import org.apache.olingo.client.api.communication.request.ODataBasicRequest;
|
||||
import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
|
||||
/**
|
||||
* This class implements an OData create request.
|
||||
* This interface describes an OData create request.
|
||||
*
|
||||
* @param <E> concrete ODataEntity implementation
|
||||
*/
|
||||
public interface ODataEntityCreateRequest extends ODataBasicRequest<ODataEntityCreateResponse, ODataPubFormat>{
|
||||
public interface ODataEntityCreateRequest<E extends CommonODataEntity>
|
||||
extends ODataBasicRequest<ODataEntityCreateResponse<E>, ODataPubFormat> {
|
||||
}
|
||||
|
@ -22,8 +22,10 @@ import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
|
||||
/**
|
||||
* This class implements an OData EntitySet query request.
|
||||
* This interface describes an OData EntitySet query request.
|
||||
*
|
||||
* @param <ES> concrete ODataEntitySet implementation
|
||||
*/
|
||||
public interface ODataEntitySetRequest<T extends CommonODataEntitySet>
|
||||
extends ODataRetrieveRequest<T, ODataPubFormat> {
|
||||
public interface ODataEntitySetRequest<ES extends CommonODataEntitySet>
|
||||
extends ODataRetrieveRequest<ES, ODataPubFormat> {
|
||||
}
|
||||
|
@ -28,21 +28,18 @@ import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public interface RetrieveRequestFactory extends CommonRetrieveRequestFactory {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
ODataEntitySetRequest<ODataEntitySet> getEntitySetRequest(URI uri);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
ODataEntitySetIteratorRequest<ODataEntitySet, ODataEntity> getEntitySetIteratorRequest(URI uri);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
ODataEntityRequest<ODataEntity> getEntityRequest(URI uri);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
ODataPropertyRequest<ODataProperty> getPropertyRequest(URI uri);
|
||||
|
||||
|
@ -34,7 +34,6 @@ public interface RetrieveRequestFactory extends CommonRetrieveRequestFactory {
|
||||
@Override
|
||||
ODataEntitySetRequest<ODataEntitySet> getEntitySetRequest(URI uri);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
ODataEntitySetIteratorRequest<ODataEntitySet, ODataEntity> getEntitySetIteratorRequest(URI uri);
|
||||
|
||||
|
@ -21,16 +21,17 @@ package org.apache.olingo.client.api.communication.response;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||
|
||||
/**
|
||||
* This class implements the response to an OData entity create request.
|
||||
* This interface describes the response to an OData entity create request.
|
||||
*
|
||||
* @param <E> concrete ODataEntity implementation
|
||||
* @see org.apache.olingo.client.core.communication.request.cud.ODataEntityCreateRequest
|
||||
*/
|
||||
public interface ODataEntityCreateResponse extends ODataResponse {
|
||||
public interface ODataEntityCreateResponse<E extends CommonODataEntity> extends ODataResponse {
|
||||
|
||||
/**
|
||||
* Gets created object.
|
||||
*
|
||||
* @return created object.
|
||||
*/
|
||||
CommonODataEntity getBody();
|
||||
E getBody();
|
||||
}
|
||||
|
@ -41,6 +41,9 @@ import org.slf4j.LoggerFactory;
|
||||
* OData entity set iterator class.
|
||||
* <br/>
|
||||
* <b>Please don't forget to call the <tt>close()>/<tt> method when not needed any more.</b>
|
||||
*
|
||||
* @param <E> concrete ODataEntity implementation
|
||||
* @param <ES> concrete ODataEntitySet implementation
|
||||
*/
|
||||
public class ODataEntitySetIterator<ES extends CommonODataEntitySet, E extends CommonODataEntity>
|
||||
implements Iterator<E> {
|
||||
|
@ -22,9 +22,22 @@ import java.io.InputStream;
|
||||
import org.apache.olingo.client.api.domain.v3.ODataLinkCollection;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.client.api.op.CommonODataReader;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
|
||||
public interface ODataReader extends CommonODataReader {
|
||||
|
||||
@Override
|
||||
ODataEntitySet readEntitySet(InputStream input, ODataPubFormat format);
|
||||
|
||||
@Override
|
||||
ODataEntity readEntity(InputStream input, ODataPubFormat format);
|
||||
|
||||
@Override
|
||||
ODataProperty readProperty(InputStream input, ODataFormat format);
|
||||
|
||||
/**
|
||||
* Parses a $links request response.
|
||||
*
|
||||
|
@ -18,8 +18,22 @@
|
||||
*/
|
||||
package org.apache.olingo.client.api.op.v4;
|
||||
|
||||
import java.io.InputStream;
|
||||
import org.apache.olingo.client.api.op.CommonODataReader;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
|
||||
public interface ODataReader extends CommonODataReader {
|
||||
|
||||
@Override
|
||||
ODataEntitySet readEntitySet(InputStream input, ODataPubFormat format);
|
||||
|
||||
@Override
|
||||
ODataEntity readEntity(InputStream input, ODataPubFormat format);
|
||||
|
||||
@Override
|
||||
ODataProperty readProperty(InputStream input, ODataFormat format);
|
||||
}
|
||||
|
@ -46,8 +46,10 @@ public abstract class AbstractCUDRequestFactory implements CommonCUDRequestFacto
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataEntityCreateRequest getEntityCreateRequest(final URI targetURI, final CommonODataEntity entity) {
|
||||
return new ODataEntityCreateRequestImpl(client, targetURI, entity);
|
||||
public <E extends CommonODataEntity> ODataEntityCreateRequest<E> getEntityCreateRequest(
|
||||
final URI targetURI, final E entity) {
|
||||
|
||||
return new ODataEntityCreateRequestImpl<E>(client, targetURI, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,14 +39,17 @@ import org.apache.olingo.commons.api.data.Entry;
|
||||
|
||||
/**
|
||||
* This class implements an OData create request.
|
||||
*
|
||||
* @param <E> concrete ODataEntity implementation
|
||||
*/
|
||||
public class ODataEntityCreateRequestImpl extends AbstractODataBasicRequest<ODataEntityCreateResponse, ODataPubFormat>
|
||||
implements ODataEntityCreateRequest, ODataBatchableRequest {
|
||||
public class ODataEntityCreateRequestImpl<E extends CommonODataEntity>
|
||||
extends AbstractODataBasicRequest<ODataEntityCreateResponse<E>, ODataPubFormat>
|
||||
implements ODataEntityCreateRequest<E>, ODataBatchableRequest {
|
||||
|
||||
/**
|
||||
* Entity to be created.
|
||||
*/
|
||||
private final CommonODataEntity entity;
|
||||
private final E entity;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -55,9 +58,7 @@ public class ODataEntityCreateRequestImpl extends AbstractODataBasicRequest<ODat
|
||||
* @param targetURI entity set URI.
|
||||
* @param entity entity to be created.
|
||||
*/
|
||||
ODataEntityCreateRequestImpl(final CommonODataClient odataClient, final URI targetURI,
|
||||
final CommonODataEntity entity) {
|
||||
|
||||
ODataEntityCreateRequestImpl(final CommonODataClient odataClient, final URI targetURI, final E entity) {
|
||||
super(odataClient, ODataPubFormat.class, HttpMethod.POST, targetURI);
|
||||
this.entity = entity;
|
||||
}
|
||||
@ -74,7 +75,7 @@ public class ODataEntityCreateRequestImpl extends AbstractODataBasicRequest<ODat
|
||||
* {@inheritDoc }
|
||||
*/
|
||||
@Override
|
||||
public ODataEntityCreateResponse execute() {
|
||||
public ODataEntityCreateResponse<E> execute() {
|
||||
final InputStream input = getPayload();
|
||||
((HttpPost) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
|
||||
|
||||
@ -88,9 +89,9 @@ public class ODataEntityCreateRequestImpl extends AbstractODataBasicRequest<ODat
|
||||
/**
|
||||
* Response class about an ODataEntityCreateRequest.
|
||||
*/
|
||||
private class ODataEntityCreateResponseImpl extends AbstractODataResponse implements ODataEntityCreateResponse {
|
||||
private class ODataEntityCreateResponseImpl extends AbstractODataResponse implements ODataEntityCreateResponse<E> {
|
||||
|
||||
private CommonODataEntity entity = null;
|
||||
private E entity = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -98,6 +99,7 @@ public class ODataEntityCreateRequestImpl extends AbstractODataBasicRequest<ODat
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataEntityCreateResponseImpl() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,13 +116,14 @@ public class ODataEntityCreateRequestImpl extends AbstractODataBasicRequest<ODat
|
||||
* {@inheritDoc }
|
||||
*/
|
||||
@Override
|
||||
public CommonODataEntity getBody() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public E getBody() {
|
||||
if (entity == null) {
|
||||
try {
|
||||
final Container<Entry> container = odataClient.getDeserializer().toEntry(getRawResponse(),
|
||||
ODataPubFormat.fromString(getAccept()));
|
||||
|
||||
entity = odataClient.getBinder().getODataEntity(extractFromContainer(container));
|
||||
entity = (E) odataClient.getBinder().getODataEntity(extractFromContainer(container));
|
||||
} finally {
|
||||
this.close();
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ import org.apache.olingo.client.api.http.HttpMethod;
|
||||
import org.apache.olingo.client.core.uri.URIUtils;
|
||||
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
|
||||
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
|
||||
import org.apache.olingo.commons.core.domain.ODataPrimitiveValueImpl;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
|
||||
/**
|
||||
@ -101,6 +100,7 @@ public class ODataValueUpdateRequestImpl extends AbstractODataBasicRequest<OData
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataValueUpdateResponseImpl() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,7 +122,7 @@ public class ODataValueUpdateRequestImpl extends AbstractODataBasicRequest<OData
|
||||
final ODataValueFormat format = ODataValueFormat.fromString(getAccept());
|
||||
|
||||
try {
|
||||
value = new ODataPrimitiveValueImpl.BuilderImpl(odataClient.getServiceVersion()).
|
||||
value = odataClient.getObjectFactory().newPrimitiveValueBuilder().
|
||||
setType(format == ODataValueFormat.TEXT
|
||||
? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
|
||||
setText(IOUtils.toString(getRawResponse())).
|
||||
|
@ -31,11 +31,13 @@ import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
|
||||
/**
|
||||
* This class implements an OData EntitySet query request.
|
||||
*
|
||||
* @param <ES> concrete ODataEntitySet implementation
|
||||
*/
|
||||
public class ODataEntitySetRequestImpl<T extends CommonODataEntitySet>
|
||||
extends AbstractODataRetrieveRequest<T, ODataPubFormat> implements ODataEntitySetRequest<T> {
|
||||
public class ODataEntitySetRequestImpl<ES extends CommonODataEntitySet>
|
||||
extends AbstractODataRetrieveRequest<ES, ODataPubFormat> implements ODataEntitySetRequest<ES> {
|
||||
|
||||
private T entitySet = null;
|
||||
private ES entitySet = null;
|
||||
|
||||
/**
|
||||
* Private constructor.
|
||||
@ -51,7 +53,7 @@ public class ODataEntitySetRequestImpl<T extends CommonODataEntitySet>
|
||||
* {@inheritDoc }
|
||||
*/
|
||||
@Override
|
||||
public ODataRetrieveResponse<T> execute() {
|
||||
public ODataRetrieveResponse<ES> execute() {
|
||||
final HttpResponse res = doExecute();
|
||||
return new ODataEntitySetResponseImpl(httpClient, res);
|
||||
}
|
||||
@ -67,6 +69,7 @@ public class ODataEntitySetRequestImpl<T extends CommonODataEntitySet>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataEntitySetResponseImpl() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,13 +87,13 @@ public class ODataEntitySetRequestImpl<T extends CommonODataEntitySet>
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T getBody() {
|
||||
public ES getBody() {
|
||||
if (entitySet == null) {
|
||||
try {
|
||||
final Container<Feed> container =
|
||||
odataClient.getDeserializer().toFeed(getRawResponse(), ODataPubFormat.fromString(getContentType()));
|
||||
|
||||
entitySet = (T) odataClient.getBinder().getODataEntitySet(extractFromContainer(container));
|
||||
entitySet = (ES) odataClient.getBinder().getODataEntitySet(extractFromContainer(container));
|
||||
} finally {
|
||||
this.close();
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.format.ODataValueFormat;
|
||||
import org.apache.olingo.client.api.http.HttpClientException;
|
||||
import org.apache.olingo.commons.core.domain.ODataPrimitiveValueImpl;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
|
||||
/**
|
||||
@ -69,6 +68,7 @@ public class ODataValueRequestImpl extends AbstractODataRetrieveRequest<ODataPri
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataValueResponseImpl() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,7 +90,7 @@ public class ODataValueRequestImpl extends AbstractODataRetrieveRequest<ODataPri
|
||||
final ODataValueFormat format = ODataValueFormat.fromString(getContentType());
|
||||
|
||||
try {
|
||||
value = new ODataPrimitiveValueImpl.BuilderImpl(odataClient.getServiceVersion()).
|
||||
value = odataClient.getObjectFactory().newPrimitiveValueBuilder().
|
||||
setType(format == ODataValueFormat.TEXT
|
||||
? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
|
||||
setText(IOUtils.toString(getRawResponse())).
|
||||
|
@ -209,27 +209,6 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
||||
return linkResource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property getProperty(final CommonODataProperty property, final Class<? extends Entry> reference,
|
||||
final boolean setType) {
|
||||
|
||||
final Property propertyResource = ResourceFactory.newProperty(reference);
|
||||
propertyResource.setName(property.getName());
|
||||
propertyResource.setValue(getValue(property.getValue(), reference, setType));
|
||||
|
||||
if (setType) {
|
||||
if (property.hasPrimitiveValue()) {
|
||||
propertyResource.setType(property.getPrimitiveValue().getType().toString());
|
||||
} else if (property.hasComplexValue()) {
|
||||
propertyResource.setType(property.getComplexValue().getTypeName());
|
||||
} else if (property.hasCollectionValue()) {
|
||||
propertyResource.setType(property.getCollectionValue().getTypeName());
|
||||
}
|
||||
}
|
||||
|
||||
return propertyResource;
|
||||
}
|
||||
|
||||
protected Value getValue(final ODataValue value, final Class<? extends Entry> reference, final boolean setType) {
|
||||
Value valueResource = null;
|
||||
|
||||
@ -240,17 +219,17 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
||||
? new GeospatialValueImpl((Geospatial) value.asPrimitive().toValue())
|
||||
: new PrimitiveValueImpl(value.asPrimitive().toString());
|
||||
} else if (value.isComplex()) {
|
||||
final ODataComplexValue _value = value.asComplex();
|
||||
final ODataComplexValue<? extends CommonODataProperty> _value = value.asComplex();
|
||||
valueResource = new ComplexValueImpl();
|
||||
|
||||
for (final Iterator<CommonODataProperty> itor = _value.iterator(); itor.hasNext();) {
|
||||
for (final Iterator<? extends CommonODataProperty> itor = _value.iterator(); itor.hasNext();) {
|
||||
valueResource.asComplex().get().add(getProperty(itor.next(), reference, setType));
|
||||
}
|
||||
} else if (value.isCollection()) {
|
||||
final ODataCollectionValue _value = value.asCollection();
|
||||
final ODataCollectionValue<? extends ODataValue> _value = value.asCollection();
|
||||
valueResource = new CollectionValueImpl();
|
||||
|
||||
for (final Iterator<ODataValue> itor = _value.iterator(); itor.hasNext();) {
|
||||
for (final Iterator<? extends ODataValue> itor = _value.iterator(); itor.hasNext();) {
|
||||
valueResource.asCollection().get().add(getValue(itor.next(), reference, setType));
|
||||
}
|
||||
}
|
||||
|
@ -77,22 +77,6 @@ public abstract class AbstractODataReader implements CommonODataReader {
|
||||
client.getDeserializer().toServiceDocument(input, format).getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonODataEntitySet readEntitySet(final InputStream input, final ODataPubFormat format) {
|
||||
return client.getBinder().getODataEntitySet(client.getDeserializer().toFeed(input, format).getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonODataEntity readEntity(final InputStream input, final ODataPubFormat format) {
|
||||
return client.getBinder().getODataEntity(client.getDeserializer().toEntry(input, format).getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonODataProperty readProperty(final InputStream input, final ODataFormat format) {
|
||||
final Property property = client.getDeserializer().toProperty(input, format).getObject();
|
||||
return client.getBinder().getODataProperty(property);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataError readError(final InputStream inputStream, final boolean isXML) {
|
||||
return client.getDeserializer().toError(inputStream, isXML);
|
||||
|
@ -34,6 +34,7 @@ import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
|
||||
import org.apache.olingo.commons.core.domain.v3.ODataPropertyImpl;
|
||||
import org.apache.olingo.commons.core.op.ResourceFactory;
|
||||
|
||||
public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder {
|
||||
|
||||
@ -53,6 +54,27 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
|
||||
return ((ODataEntitySet) entitySet).getEntities().add((ODataEntity) entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property getProperty(final CommonODataProperty property, final Class<? extends Entry> reference,
|
||||
final boolean setType) {
|
||||
|
||||
final Property propertyResource = ResourceFactory.newProperty(reference);
|
||||
propertyResource.setName(property.getName());
|
||||
propertyResource.setValue(getValue(property.getValue(), reference, setType));
|
||||
|
||||
if (setType) {
|
||||
if (property.hasPrimitiveValue()) {
|
||||
propertyResource.setType(property.getPrimitiveValue().getTypeName());
|
||||
} else if (property.hasComplexValue()) {
|
||||
propertyResource.setType(((ODataProperty) property).getComplexValue().getTypeName());
|
||||
} else if (property.hasCollectionValue()) {
|
||||
propertyResource.setType(((ODataProperty) property).getCollectionValue().getTypeName());
|
||||
}
|
||||
}
|
||||
|
||||
return propertyResource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataEntitySet getODataEntitySet(final Feed resource) {
|
||||
return (ODataEntitySet) super.getODataEntitySet(resource);
|
||||
|
@ -26,7 +26,12 @@ import org.apache.olingo.client.api.op.v3.ODataReader;
|
||||
import org.apache.olingo.client.api.v3.ODataClient;
|
||||
import org.apache.olingo.client.core.op.AbstractODataReader;
|
||||
import org.apache.olingo.commons.api.data.Container;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.v3.LinkCollection;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
|
||||
public class ODataReaderImpl extends AbstractODataReader implements ODataReader {
|
||||
|
||||
@ -36,6 +41,24 @@ public class ODataReaderImpl extends AbstractODataReader implements ODataReader
|
||||
super(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataEntitySet readEntitySet(final InputStream input, final ODataPubFormat format) {
|
||||
return ((ODataClient) client).getBinder().
|
||||
getODataEntitySet(client.getDeserializer().toFeed(input, format).getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataEntity readEntity(final InputStream input, final ODataPubFormat format) {
|
||||
return ((ODataClient) client).getBinder().
|
||||
getODataEntity(client.getDeserializer().toEntry(input, format).getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataProperty readProperty(final InputStream input, final ODataFormat format) {
|
||||
final Property property = client.getDeserializer().toProperty(input, format).getObject();
|
||||
return ((ODataClient) client).getBinder().getODataProperty(property);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataLinkCollection readLinks(final InputStream input, final ODataFormat format) {
|
||||
return ((ODataClient) client).getBinder().getLinkCollection(
|
||||
|
@ -21,11 +21,10 @@ package org.apache.olingo.client.core.op.impl.v4;
|
||||
import java.net.URI;
|
||||
import org.apache.olingo.client.api.data.ServiceDocument;
|
||||
import org.apache.olingo.client.api.data.ServiceDocumentItem;
|
||||
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
|
||||
import org.apache.olingo.client.api.op.v4.ODataBinder;
|
||||
import org.apache.olingo.client.core.uri.URIUtils;
|
||||
import org.apache.olingo.client.api.v4.ODataClient;
|
||||
import org.apache.olingo.client.core.op.AbstractODataBinder;
|
||||
import org.apache.olingo.client.core.uri.URIUtils;
|
||||
import org.apache.olingo.commons.api.data.Entry;
|
||||
import org.apache.olingo.commons.api.data.Feed;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
@ -33,6 +32,7 @@ import org.apache.olingo.commons.api.data.Value;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
|
||||
@ -40,6 +40,7 @@ import org.apache.olingo.commons.api.domain.v4.ODataProperty;
|
||||
import org.apache.olingo.commons.core.data.EnumValueImpl;
|
||||
import org.apache.olingo.commons.core.domain.v4.ODataPropertyImpl;
|
||||
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
|
||||
import org.apache.olingo.commons.core.op.ResourceFactory;
|
||||
|
||||
public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder {
|
||||
|
||||
@ -93,10 +94,24 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
|
||||
public Property getProperty(final CommonODataProperty property, final Class<? extends Entry> reference,
|
||||
final boolean setType) {
|
||||
|
||||
final Property propertyResource = super.getProperty(property, reference, setType);
|
||||
if (property instanceof ODataProperty && ((ODataProperty) property).hasEnumValue() && setType) {
|
||||
propertyResource.setType(((ODataProperty) property).getEnumValue().getTypeName());
|
||||
final ODataProperty _property = (ODataProperty) property;
|
||||
|
||||
final Property propertyResource = ResourceFactory.newProperty(reference);
|
||||
propertyResource.setName(_property.getName());
|
||||
propertyResource.setValue(getValue(_property.getValue(), reference, setType));
|
||||
|
||||
if (setType) {
|
||||
if (_property.hasPrimitiveValue()) {
|
||||
propertyResource.setType(_property.getPrimitiveValue().getTypeName());
|
||||
} else if (_property.hasEnumValue()) {
|
||||
propertyResource.setType(_property.getEnumValue().getTypeName());
|
||||
} else if (_property.hasComplexValue()) {
|
||||
propertyResource.setType(_property.getComplexValue().getTypeName());
|
||||
} else if (_property.hasCollectionValue()) {
|
||||
propertyResource.setType(_property.getCollectionValue().getTypeName());
|
||||
}
|
||||
}
|
||||
|
||||
return propertyResource;
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,16 @@
|
||||
*/
|
||||
package org.apache.olingo.client.core.op.impl.v4;
|
||||
|
||||
import java.io.InputStream;
|
||||
import org.apache.olingo.client.api.op.v4.ODataReader;
|
||||
import org.apache.olingo.client.api.v4.ODataClient;
|
||||
import org.apache.olingo.client.core.op.AbstractODataReader;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
|
||||
public class ODataReaderImpl extends AbstractODataReader implements ODataReader {
|
||||
|
||||
@ -29,4 +36,22 @@ public class ODataReaderImpl extends AbstractODataReader implements ODataReader
|
||||
public ODataReaderImpl(final ODataClient client) {
|
||||
super(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataEntitySet readEntitySet(final InputStream input, final ODataPubFormat format) {
|
||||
return ((ODataClient) client).getBinder().
|
||||
getODataEntitySet(client.getDeserializer().toFeed(input, format).getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataEntity readEntity(final InputStream input, final ODataPubFormat format) {
|
||||
return ((ODataClient) client).getBinder().
|
||||
getODataEntity(client.getDeserializer().toEntry(input, format).getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataProperty readProperty(final InputStream input, final ODataFormat format) {
|
||||
final Property property = client.getDeserializer().toProperty(input, format).getObject();
|
||||
return ((ODataClient) client).getBinder().getODataProperty(property);
|
||||
}
|
||||
}
|
||||
|
@ -20,9 +20,8 @@ package org.apache.olingo.client.core.it;
|
||||
|
||||
import org.apache.olingo.client.api.CommonODataClient;
|
||||
|
||||
public abstract class AbstractMetadataTestITCase extends AbstractTestITCase {
|
||||
public abstract class AbstractMetadataTestITCase {
|
||||
|
||||
@Override
|
||||
protected abstract CommonODataClient getClient();
|
||||
|
||||
protected String getTestServiceRoot() {
|
||||
|
@ -1,562 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.client.core.it;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URI;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.client.api.CommonODataClient;
|
||||
import org.apache.olingo.client.api.communication.ODataClientErrorException;
|
||||
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.ODataEntityUpdateRequest;
|
||||
import org.apache.olingo.client.api.communication.request.cud.UpdateType;
|
||||
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
|
||||
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.ODataEntityUpdateResponse;
|
||||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||
import org.apache.olingo.commons.api.data.Entry;
|
||||
import org.apache.olingo.commons.api.data.Feed;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataLink;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
import org.apache.olingo.client.api.http.HttpMethod;
|
||||
import org.apache.olingo.client.api.uri.CommonURIBuilder;
|
||||
import org.apache.olingo.client.core.uri.URIUtils;
|
||||
import org.apache.olingo.commons.core.data.AtomEntryImpl;
|
||||
import org.apache.olingo.commons.core.data.JSONEntryImpl;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class AbstractTestITCase {
|
||||
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
protected static final Logger LOG = LoggerFactory.getLogger(AbstractTestITCase.class);
|
||||
|
||||
protected static final String TEST_PRODUCT_TYPE = "Microsoft.Test.OData.Services.AstoriaDefaultService.Product";
|
||||
|
||||
protected static final String servicesODataServiceRootURL =
|
||||
"http://services.odata.org/V3/(S(csquyjnoaywmz5xcdbfhlc1p))/OData/OData.svc/";
|
||||
|
||||
/**
|
||||
* This is needed for correct number handling (Double, for example).
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void setEnglishLocale() {
|
||||
Locale.setDefault(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
protected abstract CommonODataClient getClient();
|
||||
|
||||
protected void checkLinks(final Collection<ODataLink> original, final Collection<ODataLink> actual) {
|
||||
assertTrue(original.size() <= actual.size());
|
||||
|
||||
for (ODataLink originalLink : original) {
|
||||
ODataLink foundOriginal = null;
|
||||
ODataLink foundActual = null;
|
||||
|
||||
for (ODataLink actualLink : actual) {
|
||||
|
||||
if (actualLink.getType() == originalLink.getType()
|
||||
&& (originalLink.getLink() == null
|
||||
|| actualLink.getLink().toASCIIString().endsWith(originalLink.getLink().toASCIIString()))
|
||||
&& actualLink.getName().equals(originalLink.getName())) {
|
||||
|
||||
foundOriginal = originalLink;
|
||||
foundActual = actualLink;
|
||||
}
|
||||
}
|
||||
|
||||
assertNotNull(foundOriginal);
|
||||
assertNotNull(foundActual);
|
||||
|
||||
if (foundOriginal instanceof ODataInlineEntity && foundActual instanceof ODataInlineEntity) {
|
||||
final CommonODataEntity originalInline = ((ODataInlineEntity) foundOriginal).getEntity();
|
||||
assertNotNull(originalInline);
|
||||
|
||||
final CommonODataEntity actualInline = ((ODataInlineEntity) foundActual).getEntity();
|
||||
assertNotNull(actualInline);
|
||||
|
||||
checkProperties(originalInline.getProperties(), actualInline.getProperties());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkProperties(final Collection<? extends CommonODataProperty> original,
|
||||
final Collection<? extends CommonODataProperty> actual) {
|
||||
|
||||
assertTrue(original.size() <= actual.size());
|
||||
|
||||
// re-organize actual properties into a Map<String, ODataProperty>
|
||||
final Map<String, CommonODataProperty> actualProps = new HashMap<String, CommonODataProperty>(actual.size());
|
||||
|
||||
for (CommonODataProperty prop : actual) {
|
||||
assertFalse(actualProps.containsKey(prop.getName()));
|
||||
actualProps.put(prop.getName(), prop);
|
||||
}
|
||||
|
||||
assertTrue(actual.size() <= actualProps.size());
|
||||
|
||||
for (CommonODataProperty prop : original) {
|
||||
assertNotNull(prop);
|
||||
if (actualProps.containsKey(prop.getName())) {
|
||||
final CommonODataProperty actualProp = actualProps.get(prop.getName());
|
||||
assertNotNull(actualProp);
|
||||
|
||||
if (prop.getValue() != null && actualProp.getValue() != null) {
|
||||
checkPropertyValue(prop.getName(), prop.getValue(), actualProp.getValue());
|
||||
}
|
||||
} else {
|
||||
// nothing ... maybe :FC_KeepInContent="false"
|
||||
// ..... no assert can be done ....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkPropertyValue(final String propertyName,
|
||||
final ODataValue original, final ODataValue actual) {
|
||||
|
||||
assertNotNull("Null original value for " + propertyName, original);
|
||||
assertNotNull("Null actual value for " + propertyName, actual);
|
||||
|
||||
assertEquals("Type mismatch for '" + propertyName + "': "
|
||||
+ original.getClass().getSimpleName() + "-" + actual.getClass().getSimpleName(),
|
||||
original.getClass().getSimpleName(), actual.getClass().getSimpleName());
|
||||
|
||||
if (original.isComplex()) {
|
||||
final List<CommonODataProperty> originalFileds = new ArrayList<CommonODataProperty>();
|
||||
for (CommonODataProperty prop : original.asComplex()) {
|
||||
originalFileds.add(prop);
|
||||
}
|
||||
|
||||
final List<CommonODataProperty> actualFileds = new ArrayList<CommonODataProperty>();
|
||||
for (CommonODataProperty prop : (ODataComplexValue) actual) {
|
||||
actualFileds.add(prop);
|
||||
}
|
||||
|
||||
checkProperties(originalFileds, actualFileds);
|
||||
} else if (original.isCollection()) {
|
||||
assertTrue(original.asCollection().size() <= actual.asCollection().size());
|
||||
|
||||
boolean found = original.asCollection().isEmpty();
|
||||
|
||||
for (ODataValue originalValue : original.asCollection()) {
|
||||
for (ODataValue actualValue : actual.asCollection()) {
|
||||
try {
|
||||
checkPropertyValue(propertyName, originalValue, actualValue);
|
||||
found = true;
|
||||
} catch (AssertionError ignore) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("Found " + actual + " but expected " + original, found);
|
||||
} else {
|
||||
assertTrue("Primitive value for '" + propertyName + "' type mismatch: " + original.asPrimitive().
|
||||
getTypeKind() + "-" + actual.asPrimitive().getTypeKind(),
|
||||
original.asPrimitive().getTypeKind().equals(actual.asPrimitive().getTypeKind()));
|
||||
|
||||
assertEquals("Primitive value for '" + propertyName + "' mismatch: " + original.asPrimitive().toString()
|
||||
+ "-" + actual.asPrimitive().toString(),
|
||||
original.asPrimitive().toString(), actual.asPrimitive().toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected CommonODataEntity getSampleCustomerInfo(final int id, final String sampleinfo) {
|
||||
final CommonODataEntity entity = getClient().getObjectFactory().newEntity(
|
||||
"Microsoft.Test.OData.Services.AstoriaDefaultService.CustomerInfo");
|
||||
entity.setMediaEntity(true);
|
||||
|
||||
getClient().getBinder().add(entity,
|
||||
getClient().getObjectFactory().newPrimitiveProperty("Information",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().setText(sampleinfo).
|
||||
setType(EdmPrimitiveTypeKind.String).build()));
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
protected CommonODataEntity getSampleCustomerProfile(
|
||||
final int id, final String sampleName, final boolean withInlineInfo) {
|
||||
|
||||
final CommonODataEntity entity =
|
||||
getClient().getObjectFactory().newEntity("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer");
|
||||
|
||||
// add name attribute
|
||||
getClient().getBinder().add(entity,
|
||||
getClient().getObjectFactory().newPrimitiveProperty("Name",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().setText(sampleName).
|
||||
setType(EdmPrimitiveTypeKind.String).build()));
|
||||
|
||||
// add key attribute
|
||||
getClient().getBinder().add(entity,
|
||||
getClient().getObjectFactory().newPrimitiveProperty("CustomerId",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().setText(String.valueOf(id)).
|
||||
setType(EdmPrimitiveTypeKind.Int32).build()));
|
||||
|
||||
// add BackupContactInfo attribute (collection)
|
||||
final ODataCollectionValue backupContactInfoValue = getClient().getObjectFactory().newCollectionValue(
|
||||
"Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails)");
|
||||
getClient().getBinder().add(entity,
|
||||
getClient().getObjectFactory().newCollectionProperty("BackupContactInfo", backupContactInfoValue));
|
||||
|
||||
// add BackupContactInfo.ContactDetails attribute (complex)
|
||||
final ODataComplexValue contactDetails = getClient().getObjectFactory().newComplexValue(
|
||||
"Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails");
|
||||
backupContactInfoValue.add(contactDetails);
|
||||
|
||||
// add BackupContactInfo.ContactDetails.AlternativeNames attribute (collection)
|
||||
final ODataCollectionValue altNamesValue = getClient().getObjectFactory().
|
||||
newCollectionValue("Collection(Edm.String)");
|
||||
altNamesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setText("myname").setType(EdmPrimitiveTypeKind.String).build());
|
||||
contactDetails.add(getClient().getObjectFactory().newCollectionProperty("AlternativeNames", altNamesValue));
|
||||
|
||||
// add BackupContactInfo.ContactDetails.EmailBag attribute (collection)
|
||||
final ODataCollectionValue emailBagValue = getClient().getObjectFactory().
|
||||
newCollectionValue("Collection(Edm.String)");
|
||||
emailBagValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setText("myname@mydomain.com").setType(EdmPrimitiveTypeKind.String).build());
|
||||
contactDetails.add(getClient().getObjectFactory().newCollectionProperty("EmailBag", emailBagValue));
|
||||
|
||||
// add BackupContactInfo.ContactDetails.ContactAlias attribute (complex)
|
||||
final ODataComplexValue contactAliasValue = getClient().getObjectFactory().newComplexValue(
|
||||
"Microsoft.Test.OData.Services.AstoriaDefaultService.Aliases");
|
||||
contactDetails.add(getClient().getObjectFactory().newComplexProperty("ContactAlias", contactAliasValue));
|
||||
|
||||
// add BackupContactInfo.ContactDetails.ContactAlias.AlternativeNames attribute (collection)
|
||||
final ODataCollectionValue aliasAltNamesValue = getClient().getObjectFactory().
|
||||
newCollectionValue("Collection(Edm.String)");
|
||||
aliasAltNamesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setText("myAlternativeName").setType(EdmPrimitiveTypeKind.String).build());
|
||||
contactAliasValue.add(getClient().getObjectFactory().newCollectionProperty("AlternativeNames", aliasAltNamesValue));
|
||||
|
||||
if (withInlineInfo) {
|
||||
final ODataInlineEntity inlineInfo = getClient().getObjectFactory().newInlineEntity(
|
||||
"Info",
|
||||
URI.create("Customer(" + id + ")/Info"),
|
||||
getSampleCustomerInfo(id, sampleName + "_Info"));
|
||||
inlineInfo.getEntity().setMediaEntity(true);
|
||||
entity.addLink(inlineInfo);
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
protected void debugEntry(final Entry entry, final String message) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
final StringWriter writer = new StringWriter();
|
||||
getClient().getSerializer().entry(entry, writer);
|
||||
writer.flush();
|
||||
LOG.debug(message + "\n{}", writer.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected void debugFeed(final Feed feed, final String message) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
final StringWriter writer = new StringWriter();
|
||||
getClient().getSerializer().feed(feed, writer);
|
||||
writer.flush();
|
||||
LOG.debug(message + "\n{}", writer.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected void debugODataProperty(final CommonODataProperty property, final String message) {
|
||||
LOG.debug(message + "\n{}", property.toString());
|
||||
}
|
||||
|
||||
protected void debugODataValue(final ODataValue value, final String message) {
|
||||
LOG.debug(message + "\n{}", value.toString());
|
||||
}
|
||||
|
||||
protected void debugODataEntity(final CommonODataEntity entity, final String message) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
StringWriter writer = new StringWriter();
|
||||
getClient().getSerializer().entry(getClient().getBinder().getEntry(entity, AtomEntryImpl.class), writer);
|
||||
writer.flush();
|
||||
LOG.debug(message + " (Atom)\n{}", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
getClient().getSerializer().entry(getClient().getBinder().getEntry(entity, JSONEntryImpl.class), writer);
|
||||
writer.flush();
|
||||
LOG.debug(message + " (JSON)\n{}", writer.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected void debugInputStream(final InputStream input, final String message) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
try {
|
||||
LOG.debug(message + "\n{}", IOUtils.toString(input));
|
||||
} catch (IOException e) {
|
||||
LOG.error("Error writing stream", e);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String getETag(final URI uri) {
|
||||
final ODataRetrieveResponse<CommonODataEntity> res = getClient().getRetrieveRequestFactory().
|
||||
getEntityRequest(uri).execute();
|
||||
try {
|
||||
return res.getEtag();
|
||||
} finally {
|
||||
res.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected CommonODataEntity read(final ODataPubFormat format, final URI editLink) {
|
||||
final ODataEntityRequest<CommonODataEntity> req = getClient().getRetrieveRequestFactory().
|
||||
getEntityRequest(editLink);
|
||||
req.setFormat(format);
|
||||
|
||||
final ODataRetrieveResponse<CommonODataEntity> res = req.execute();
|
||||
final CommonODataEntity entity = res.getBody();
|
||||
|
||||
assertNotNull(entity);
|
||||
|
||||
if (ODataPubFormat.JSON_FULL_METADATA == format || ODataPubFormat.ATOM == format) {
|
||||
assertEquals(req.getURI(), entity.getEditLink());
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
protected CommonODataEntity createEntity(
|
||||
final String serviceRootURL,
|
||||
final ODataPubFormat format,
|
||||
final CommonODataEntity original,
|
||||
final String entitySetName) {
|
||||
|
||||
final CommonURIBuilder<?> uriBuilder = getClient().getURIBuilder(serviceRootURL).
|
||||
appendEntitySetSegment(entitySetName);
|
||||
|
||||
debugODataEntity(original, "About to create");
|
||||
|
||||
final ODataEntityCreateRequest createReq =
|
||||
getClient().getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), original);
|
||||
createReq.setFormat(format);
|
||||
|
||||
final ODataEntityCreateResponse createRes = createReq.execute();
|
||||
assertEquals(201, createRes.getStatusCode());
|
||||
assertEquals("Created", createRes.getStatusMessage());
|
||||
|
||||
final CommonODataEntity created = createRes.getBody();
|
||||
assertNotNull(created);
|
||||
|
||||
debugODataEntity(created, "Just created");
|
||||
|
||||
return created;
|
||||
}
|
||||
|
||||
protected CommonODataEntity compareEntities(final String serviceRootURL,
|
||||
final ODataPubFormat format,
|
||||
final CommonODataEntity original,
|
||||
final int actualObjectId,
|
||||
final Collection<String> expands) {
|
||||
|
||||
final CommonURIBuilder<?> uriBuilder = getClient().getURIBuilder(serviceRootURL).
|
||||
appendEntitySetSegment("Customer").appendKeySegment(actualObjectId);
|
||||
|
||||
// search expanded
|
||||
if (expands != null) {
|
||||
for (String expand : expands) {
|
||||
uriBuilder.expand(expand);
|
||||
}
|
||||
}
|
||||
|
||||
final ODataEntityRequest<CommonODataEntity> req = getClient().getRetrieveRequestFactory().
|
||||
getEntityRequest(uriBuilder.build());
|
||||
req.setFormat(format);
|
||||
|
||||
final ODataRetrieveResponse<CommonODataEntity> res = req.execute();
|
||||
assertEquals(200, res.getStatusCode());
|
||||
|
||||
final CommonODataEntity actual = res.getBody();
|
||||
assertNotNull(actual);
|
||||
|
||||
// check defined links
|
||||
checkLinks(original.getAssociationLinks(), actual.getAssociationLinks());
|
||||
checkLinks(original.getEditMediaLinks(), actual.getEditMediaLinks());
|
||||
checkLinks(original.getNavigationLinks(), actual.getNavigationLinks());
|
||||
|
||||
// check defined properties equality
|
||||
checkProperties(original.getProperties(), actual.getProperties());
|
||||
|
||||
return actual;
|
||||
}
|
||||
|
||||
protected void cleanAfterCreate(
|
||||
final ODataPubFormat format,
|
||||
final CommonODataEntity created,
|
||||
final boolean includeInline,
|
||||
final String baseUri) {
|
||||
|
||||
final Set<URI> toBeDeleted = new HashSet<URI>();
|
||||
toBeDeleted.add(created.getEditLink());
|
||||
|
||||
if (includeInline) {
|
||||
for (ODataLink link : created.getNavigationLinks()) {
|
||||
if (link instanceof ODataInlineEntity) {
|
||||
final CommonODataEntity inline = ((ODataInlineEntity) link).getEntity();
|
||||
if (inline.getEditLink() != null) {
|
||||
toBeDeleted.add(URIUtils.getURI(baseUri, inline.getEditLink().toASCIIString()));
|
||||
}
|
||||
}
|
||||
|
||||
if (link instanceof ODataInlineEntitySet) {
|
||||
final CommonODataEntitySet inline = ((ODataInlineEntitySet) link).getEntitySet();
|
||||
for (CommonODataEntity entity : inline.getEntities()) {
|
||||
if (entity.getEditLink() != null) {
|
||||
toBeDeleted.add(URIUtils.getURI(baseUri, entity.getEditLink().toASCIIString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertFalse(toBeDeleted.isEmpty());
|
||||
|
||||
for (URI link : toBeDeleted) {
|
||||
final ODataDeleteRequest deleteReq = getClient().getCUDRequestFactory().getDeleteRequest(link);
|
||||
final ODataDeleteResponse deleteRes = deleteReq.execute();
|
||||
|
||||
assertEquals(204, deleteRes.getStatusCode());
|
||||
assertEquals("No Content", deleteRes.getStatusMessage());
|
||||
|
||||
deleteRes.close();
|
||||
|
||||
final ODataEntityRequest<CommonODataEntity> retrieveReq = getClient().getRetrieveRequestFactory().
|
||||
getEntityRequest(link);
|
||||
// bug that needs to be fixed on the SampleService - cannot get entity not found with header
|
||||
// Accept: application/json;odata=minimalmetadata
|
||||
retrieveReq.setFormat(format == ODataPubFormat.JSON_FULL_METADATA ? ODataPubFormat.JSON : format);
|
||||
|
||||
Exception exception = null;
|
||||
try {
|
||||
retrieveReq.execute();
|
||||
fail();
|
||||
} catch (ODataClientErrorException e) {
|
||||
exception = e;
|
||||
assertEquals(404, e.getStatusLine().getStatusCode());
|
||||
}
|
||||
assertNotNull(exception);
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateEntityDescription(
|
||||
final ODataPubFormat format, final CommonODataEntity changes, final UpdateType type) {
|
||||
|
||||
updateEntityDescription(format, changes, type, null);
|
||||
}
|
||||
|
||||
protected void updateEntityDescription(
|
||||
final ODataPubFormat format, final CommonODataEntity changes, final UpdateType type, final String etag) {
|
||||
|
||||
updateEntityStringProperty("Description", format, changes, type, etag);
|
||||
}
|
||||
|
||||
protected void updateEntityStringProperty(final String propertyName,
|
||||
final ODataPubFormat format, final CommonODataEntity changes, final UpdateType type, final String etag) {
|
||||
|
||||
final URI editLink = changes.getEditLink();
|
||||
|
||||
final String newm = "New " + propertyName + "(" + System.currentTimeMillis() + ")";
|
||||
|
||||
CommonODataProperty propertyValue = changes.getProperty(propertyName);
|
||||
|
||||
final String oldm;
|
||||
if (propertyValue == null) {
|
||||
oldm = null;
|
||||
} else {
|
||||
oldm = propertyValue.getValue().toString();
|
||||
changes.getProperties().remove(propertyValue);
|
||||
}
|
||||
|
||||
assertNotEquals(newm, oldm);
|
||||
|
||||
getClient().getBinder().add(changes,
|
||||
getClient().getObjectFactory().newPrimitiveProperty(propertyName,
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().setText(newm).build()));
|
||||
|
||||
update(type, changes, format, etag);
|
||||
|
||||
final CommonODataEntity actual = read(format, editLink);
|
||||
|
||||
propertyValue = null;
|
||||
|
||||
for (CommonODataProperty prop : actual.getProperties()) {
|
||||
if (prop.getName().equals(propertyName)) {
|
||||
propertyValue = prop;
|
||||
}
|
||||
}
|
||||
|
||||
assertNotNull(propertyValue);
|
||||
assertEquals(newm, propertyValue.getValue().toString());
|
||||
}
|
||||
|
||||
protected void update(
|
||||
final UpdateType type, final CommonODataEntity changes, final ODataPubFormat format, final String etag) {
|
||||
final ODataEntityUpdateRequest req = getClient().getCUDRequestFactory().getEntityUpdateRequest(type, changes);
|
||||
|
||||
if (getClient().getConfiguration().isUseXHTTPMethod()) {
|
||||
assertEquals(HttpMethod.POST, req.getMethod());
|
||||
} else {
|
||||
assertEquals(type.getMethod(), req.getMethod());
|
||||
}
|
||||
req.setFormat(format);
|
||||
|
||||
if (StringUtils.isNotBlank(etag)) {
|
||||
req.setIfMatch(etag); // Product include ETag header into the response .....
|
||||
}
|
||||
|
||||
final ODataEntityUpdateResponse res = req.execute();
|
||||
assertEquals(204, res.getStatusCode());
|
||||
}
|
||||
}
|
@ -19,11 +19,72 @@
|
||||
package org.apache.olingo.client.core.it.v3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.client.api.communication.ODataClientErrorException;
|
||||
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.ODataEntityUpdateRequest;
|
||||
import org.apache.olingo.client.api.communication.request.cud.UpdateType;
|
||||
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
|
||||
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.ODataEntityUpdateResponse;
|
||||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||
import org.apache.olingo.client.api.http.HttpMethod;
|
||||
import org.apache.olingo.client.api.uri.CommonURIBuilder;
|
||||
import org.apache.olingo.client.api.v3.ODataClient;
|
||||
import org.apache.olingo.client.core.ODataClientFactory;
|
||||
import org.junit.BeforeClass;
|
||||
import org.apache.olingo.client.core.uri.URIUtils;
|
||||
import org.apache.olingo.commons.api.data.Entry;
|
||||
import org.apache.olingo.commons.api.data.Feed;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataLink;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
import org.apache.olingo.commons.core.data.AtomEntryImpl;
|
||||
import org.apache.olingo.commons.core.data.JSONEntryImpl;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public abstract class AbstractTestITCase extends org.apache.olingo.client.core.it.AbstractTestITCase {
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class AbstractTestITCase {
|
||||
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
protected static final Logger LOG = LoggerFactory.getLogger(AbstractTestITCase.class);
|
||||
|
||||
protected static final String TEST_PRODUCT_TYPE = "Microsoft.Test.OData.Services.AstoriaDefaultService.Product";
|
||||
|
||||
protected static final String servicesODataServiceRootURL =
|
||||
"http://services.odata.org/V3/(S(csquyjnoaywmz5xcdbfhlc1p))/OData/OData.svc/";
|
||||
|
||||
protected static ODataClient client;
|
||||
|
||||
@ -45,8 +106,473 @@ public abstract class AbstractTestITCase extends org.apache.olingo.client.core.i
|
||||
client = ODataClientFactory.getV3();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ODataClient getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
protected void checkLinks(final Collection<ODataLink> original, final Collection<ODataLink> actual) {
|
||||
assertTrue(original.size() <= actual.size());
|
||||
|
||||
for (ODataLink originalLink : original) {
|
||||
ODataLink foundOriginal = null;
|
||||
ODataLink foundActual = null;
|
||||
|
||||
for (ODataLink actualLink : actual) {
|
||||
|
||||
if (actualLink.getType() == originalLink.getType()
|
||||
&& (originalLink.getLink() == null
|
||||
|| actualLink.getLink().toASCIIString().endsWith(originalLink.getLink().toASCIIString()))
|
||||
&& actualLink.getName().equals(originalLink.getName())) {
|
||||
|
||||
foundOriginal = originalLink;
|
||||
foundActual = actualLink;
|
||||
}
|
||||
}
|
||||
|
||||
assertNotNull(foundOriginal);
|
||||
assertNotNull(foundActual);
|
||||
|
||||
if (foundOriginal instanceof ODataInlineEntity && foundActual instanceof ODataInlineEntity) {
|
||||
final CommonODataEntity originalInline = ((ODataInlineEntity) foundOriginal).getEntity();
|
||||
assertNotNull(originalInline);
|
||||
|
||||
final CommonODataEntity actualInline = ((ODataInlineEntity) foundActual).getEntity();
|
||||
assertNotNull(actualInline);
|
||||
|
||||
checkProperties(originalInline.getProperties(), actualInline.getProperties());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkProperties(final Collection<? extends CommonODataProperty> original,
|
||||
final Collection<? extends CommonODataProperty> actual) {
|
||||
|
||||
assertTrue(original.size() <= actual.size());
|
||||
|
||||
// re-organize actual properties into a Map<String, ODataProperty>
|
||||
final Map<String, CommonODataProperty> actualProps = new HashMap<String, CommonODataProperty>(actual.size());
|
||||
|
||||
for (CommonODataProperty prop : actual) {
|
||||
assertFalse(actualProps.containsKey(prop.getName()));
|
||||
actualProps.put(prop.getName(), prop);
|
||||
}
|
||||
|
||||
assertTrue(actual.size() <= actualProps.size());
|
||||
|
||||
for (CommonODataProperty prop : original) {
|
||||
assertNotNull(prop);
|
||||
if (actualProps.containsKey(prop.getName())) {
|
||||
final CommonODataProperty actualProp = actualProps.get(prop.getName());
|
||||
assertNotNull(actualProp);
|
||||
|
||||
if (prop.getValue() != null && actualProp.getValue() != null) {
|
||||
checkPropertyValue(prop.getName(), prop.getValue(), actualProp.getValue());
|
||||
}
|
||||
} else {
|
||||
// nothing ... maybe :FC_KeepInContent="false"
|
||||
// ..... no assert can be done ....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkPropertyValue(final String propertyName,
|
||||
final ODataValue original, final ODataValue actual) {
|
||||
|
||||
assertNotNull("Null original value for " + propertyName, original);
|
||||
assertNotNull("Null actual value for " + propertyName, actual);
|
||||
|
||||
assertEquals("Type mismatch for '" + propertyName + "': "
|
||||
+ original.getClass().getSimpleName() + "-" + actual.getClass().getSimpleName(),
|
||||
original.getClass().getSimpleName(), actual.getClass().getSimpleName());
|
||||
|
||||
if (original.isComplex()) {
|
||||
final List<CommonODataProperty> originalFileds = new ArrayList<CommonODataProperty>();
|
||||
for (CommonODataProperty prop : original.asComplex()) {
|
||||
originalFileds.add(prop);
|
||||
}
|
||||
|
||||
final List<CommonODataProperty> actualFileds = new ArrayList<CommonODataProperty>();
|
||||
for (CommonODataProperty prop : actual.asComplex()) {
|
||||
actualFileds.add(prop);
|
||||
}
|
||||
|
||||
checkProperties(originalFileds, actualFileds);
|
||||
} else if (original.isCollection()) {
|
||||
assertTrue(original.asCollection().size() <= actual.asCollection().size());
|
||||
|
||||
boolean found = original.asCollection().isEmpty();
|
||||
|
||||
for (ODataValue originalValue : original.asCollection()) {
|
||||
for (ODataValue actualValue : actual.asCollection()) {
|
||||
try {
|
||||
checkPropertyValue(propertyName, originalValue, actualValue);
|
||||
found = true;
|
||||
} catch (AssertionError ignore) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("Found " + actual + " but expected " + original, found);
|
||||
} else {
|
||||
assertTrue("Primitive value for '" + propertyName + "' type mismatch: " + original.asPrimitive().
|
||||
getTypeKind() + "-" + actual.asPrimitive().getTypeKind(),
|
||||
original.asPrimitive().getTypeKind().equals(actual.asPrimitive().getTypeKind()));
|
||||
|
||||
assertEquals("Primitive value for '" + propertyName + "' mismatch: " + original.asPrimitive().toString()
|
||||
+ "-" + actual.asPrimitive().toString(),
|
||||
original.asPrimitive().toString(), actual.asPrimitive().toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected ODataEntity getSampleCustomerInfo(final int id, final String sampleinfo) {
|
||||
final ODataEntity entity = getClient().getObjectFactory().newEntity(
|
||||
"Microsoft.Test.OData.Services.AstoriaDefaultService.CustomerInfo");
|
||||
entity.setMediaEntity(true);
|
||||
|
||||
getClient().getBinder().add(entity,
|
||||
getClient().getObjectFactory().newPrimitiveProperty("Information",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().setText(sampleinfo).
|
||||
setType(EdmPrimitiveTypeKind.String).build()));
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
protected ODataEntity getSampleCustomerProfile(
|
||||
final int id, final String sampleName, final boolean withInlineInfo) {
|
||||
|
||||
final ODataEntity entity =
|
||||
getClient().getObjectFactory().newEntity("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer");
|
||||
|
||||
// add name attribute
|
||||
getClient().getBinder().add(entity,
|
||||
getClient().getObjectFactory().newPrimitiveProperty("Name",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().setText(sampleName).
|
||||
setType(EdmPrimitiveTypeKind.String).build()));
|
||||
|
||||
// add key attribute
|
||||
getClient().getBinder().add(entity,
|
||||
getClient().getObjectFactory().newPrimitiveProperty("CustomerId",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().setText(String.valueOf(id)).
|
||||
setType(EdmPrimitiveTypeKind.Int32).build()));
|
||||
|
||||
// add BackupContactInfo attribute (collection)
|
||||
final ODataCollectionValue<ODataValue> backupContactInfoValue = getClient().getObjectFactory().newCollectionValue(
|
||||
"Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails)");
|
||||
getClient().getBinder().add(entity,
|
||||
getClient().getObjectFactory().newCollectionProperty("BackupContactInfo", backupContactInfoValue));
|
||||
|
||||
// add BackupContactInfo.ContactDetails attribute (complex)
|
||||
final ODataComplexValue<ODataProperty> contactDetails = getClient().getObjectFactory().newComplexValue(
|
||||
"Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails");
|
||||
backupContactInfoValue.add(contactDetails);
|
||||
|
||||
// add BackupContactInfo.ContactDetails.AlternativeNames attribute (collection)
|
||||
final ODataCollectionValue<ODataValue> altNamesValue = getClient().getObjectFactory().
|
||||
newCollectionValue("Collection(Edm.String)");
|
||||
altNamesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setText("myname").setType(EdmPrimitiveTypeKind.String).build());
|
||||
contactDetails.add(getClient().getObjectFactory().newCollectionProperty("AlternativeNames", altNamesValue));
|
||||
|
||||
// add BackupContactInfo.ContactDetails.EmailBag attribute (collection)
|
||||
final ODataCollectionValue<ODataValue> emailBagValue = getClient().getObjectFactory().
|
||||
newCollectionValue("Collection(Edm.String)");
|
||||
emailBagValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setText("myname@mydomain.com").setType(EdmPrimitiveTypeKind.String).build());
|
||||
contactDetails.add(getClient().getObjectFactory().newCollectionProperty("EmailBag", emailBagValue));
|
||||
|
||||
// add BackupContactInfo.ContactDetails.ContactAlias attribute (complex)
|
||||
final ODataComplexValue<ODataProperty> contactAliasValue = getClient().getObjectFactory().newComplexValue(
|
||||
"Microsoft.Test.OData.Services.AstoriaDefaultService.Aliases");
|
||||
contactDetails.add(getClient().getObjectFactory().newComplexProperty("ContactAlias", contactAliasValue));
|
||||
|
||||
// add BackupContactInfo.ContactDetails.ContactAlias.AlternativeNames attribute (collection)
|
||||
final ODataCollectionValue<ODataValue> aliasAltNamesValue = getClient().getObjectFactory().
|
||||
newCollectionValue("Collection(Edm.String)");
|
||||
aliasAltNamesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setText("myAlternativeName").setType(EdmPrimitiveTypeKind.String).build());
|
||||
contactAliasValue.add(getClient().getObjectFactory().newCollectionProperty("AlternativeNames", aliasAltNamesValue));
|
||||
|
||||
if (withInlineInfo) {
|
||||
final ODataInlineEntity inlineInfo = getClient().getObjectFactory().newInlineEntity(
|
||||
"Info",
|
||||
URI.create("Customer(" + id + ")/Info"),
|
||||
getSampleCustomerInfo(id, sampleName + "_Info"));
|
||||
inlineInfo.getEntity().setMediaEntity(true);
|
||||
entity.addLink(inlineInfo);
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
protected void debugEntry(final Entry entry, final String message) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
final StringWriter writer = new StringWriter();
|
||||
getClient().getSerializer().entry(entry, writer);
|
||||
writer.flush();
|
||||
LOG.debug(message + "\n{}", writer.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected void debugFeed(final Feed feed, final String message) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
final StringWriter writer = new StringWriter();
|
||||
getClient().getSerializer().feed(feed, writer);
|
||||
writer.flush();
|
||||
LOG.debug(message + "\n{}", writer.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected void debugODataProperty(final ODataProperty property, final String message) {
|
||||
LOG.debug(message + "\n{}", property.toString());
|
||||
}
|
||||
|
||||
protected void debugODataValue(final ODataValue value, final String message) {
|
||||
LOG.debug(message + "\n{}", value.toString());
|
||||
}
|
||||
|
||||
protected void debugODataEntity(final ODataEntity entity, final String message) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
StringWriter writer = new StringWriter();
|
||||
getClient().getSerializer().entry(getClient().getBinder().getEntry(entity, AtomEntryImpl.class), writer);
|
||||
writer.flush();
|
||||
LOG.debug(message + " (Atom)\n{}", writer.toString());
|
||||
|
||||
writer = new StringWriter();
|
||||
getClient().getSerializer().entry(getClient().getBinder().getEntry(entity, JSONEntryImpl.class), writer);
|
||||
writer.flush();
|
||||
LOG.debug(message + " (JSON)\n{}", writer.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected void debugInputStream(final InputStream input, final String message) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
try {
|
||||
LOG.debug(message + "\n{}", IOUtils.toString(input));
|
||||
} catch (IOException e) {
|
||||
LOG.error("Error writing stream", e);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String getETag(final URI uri) {
|
||||
final ODataRetrieveResponse<ODataEntity> res = getClient().getRetrieveRequestFactory().
|
||||
getEntityRequest(uri).execute();
|
||||
try {
|
||||
return res.getEtag();
|
||||
} finally {
|
||||
res.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected ODataEntity read(final ODataPubFormat format, final URI editLink) {
|
||||
final ODataEntityRequest<ODataEntity> req = getClient().getRetrieveRequestFactory().
|
||||
getEntityRequest(editLink);
|
||||
req.setFormat(format);
|
||||
|
||||
final ODataRetrieveResponse<ODataEntity> res = req.execute();
|
||||
final ODataEntity entity = res.getBody();
|
||||
|
||||
assertNotNull(entity);
|
||||
|
||||
if (ODataPubFormat.JSON_FULL_METADATA == format || ODataPubFormat.ATOM == format) {
|
||||
assertEquals(req.getURI(), entity.getEditLink());
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
protected ODataEntity createEntity(
|
||||
final String serviceRootURL,
|
||||
final ODataPubFormat format,
|
||||
final ODataEntity original,
|
||||
final String entitySetName) {
|
||||
|
||||
final CommonURIBuilder<?> uriBuilder = getClient().getURIBuilder(serviceRootURL).
|
||||
appendEntitySetSegment(entitySetName);
|
||||
|
||||
debugODataEntity(original, "About to create");
|
||||
|
||||
final ODataEntityCreateRequest<ODataEntity> createReq =
|
||||
getClient().getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), original);
|
||||
createReq.setFormat(format);
|
||||
|
||||
final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
|
||||
assertEquals(201, createRes.getStatusCode());
|
||||
assertEquals("Created", createRes.getStatusMessage());
|
||||
|
||||
final ODataEntity created = createRes.getBody();
|
||||
assertNotNull(created);
|
||||
|
||||
debugODataEntity(created, "Just created");
|
||||
|
||||
return created;
|
||||
}
|
||||
|
||||
protected ODataEntity compareEntities(final String serviceRootURL,
|
||||
final ODataPubFormat format,
|
||||
final ODataEntity original,
|
||||
final int actualObjectId,
|
||||
final Collection<String> expands) {
|
||||
|
||||
final CommonURIBuilder<?> uriBuilder = getClient().getURIBuilder(serviceRootURL).
|
||||
appendEntitySetSegment("Customer").appendKeySegment(actualObjectId);
|
||||
|
||||
// search expanded
|
||||
if (expands != null) {
|
||||
for (String expand : expands) {
|
||||
uriBuilder.expand(expand);
|
||||
}
|
||||
}
|
||||
|
||||
final ODataEntityRequest<ODataEntity> req = getClient().getRetrieveRequestFactory().
|
||||
getEntityRequest(uriBuilder.build());
|
||||
req.setFormat(format);
|
||||
|
||||
final ODataRetrieveResponse<ODataEntity> res = req.execute();
|
||||
assertEquals(200, res.getStatusCode());
|
||||
|
||||
final ODataEntity actual = res.getBody();
|
||||
assertNotNull(actual);
|
||||
|
||||
// check defined links
|
||||
checkLinks(original.getAssociationLinks(), actual.getAssociationLinks());
|
||||
checkLinks(original.getEditMediaLinks(), actual.getEditMediaLinks());
|
||||
checkLinks(original.getNavigationLinks(), actual.getNavigationLinks());
|
||||
|
||||
// check defined properties equality
|
||||
checkProperties(original.getProperties(), actual.getProperties());
|
||||
|
||||
return actual;
|
||||
}
|
||||
|
||||
protected void cleanAfterCreate(
|
||||
final ODataPubFormat format,
|
||||
final ODataEntity created,
|
||||
final boolean includeInline,
|
||||
final String baseUri) {
|
||||
|
||||
final Set<URI> toBeDeleted = new HashSet<URI>();
|
||||
toBeDeleted.add(created.getEditLink());
|
||||
|
||||
if (includeInline) {
|
||||
for (ODataLink link : created.getNavigationLinks()) {
|
||||
if (link instanceof ODataInlineEntity) {
|
||||
final CommonODataEntity inline = ((ODataInlineEntity) link).getEntity();
|
||||
if (inline.getEditLink() != null) {
|
||||
toBeDeleted.add(URIUtils.getURI(baseUri, inline.getEditLink().toASCIIString()));
|
||||
}
|
||||
}
|
||||
|
||||
if (link instanceof ODataInlineEntitySet) {
|
||||
final CommonODataEntitySet inline = ((ODataInlineEntitySet) link).getEntitySet();
|
||||
for (CommonODataEntity entity : inline.getEntities()) {
|
||||
if (entity.getEditLink() != null) {
|
||||
toBeDeleted.add(URIUtils.getURI(baseUri, entity.getEditLink().toASCIIString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertFalse(toBeDeleted.isEmpty());
|
||||
|
||||
for (URI link : toBeDeleted) {
|
||||
final ODataDeleteRequest deleteReq = getClient().getCUDRequestFactory().getDeleteRequest(link);
|
||||
final ODataDeleteResponse deleteRes = deleteReq.execute();
|
||||
|
||||
assertEquals(204, deleteRes.getStatusCode());
|
||||
assertEquals("No Content", deleteRes.getStatusMessage());
|
||||
|
||||
deleteRes.close();
|
||||
|
||||
final ODataEntityRequest<ODataEntity> retrieveReq = getClient().getRetrieveRequestFactory().
|
||||
getEntityRequest(link);
|
||||
// bug that needs to be fixed on the SampleService - cannot get entity not found with header
|
||||
// Accept: application/json;odata=minimalmetadata
|
||||
retrieveReq.setFormat(format == ODataPubFormat.JSON_FULL_METADATA ? ODataPubFormat.JSON : format);
|
||||
|
||||
Exception exception = null;
|
||||
try {
|
||||
retrieveReq.execute();
|
||||
fail();
|
||||
} catch (ODataClientErrorException e) {
|
||||
exception = e;
|
||||
assertEquals(404, e.getStatusLine().getStatusCode());
|
||||
}
|
||||
assertNotNull(exception);
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateEntityDescription(
|
||||
final ODataPubFormat format, final ODataEntity changes, final UpdateType type) {
|
||||
|
||||
updateEntityDescription(format, changes, type, null);
|
||||
}
|
||||
|
||||
protected void updateEntityDescription(
|
||||
final ODataPubFormat format, final ODataEntity changes, final UpdateType type, final String etag) {
|
||||
|
||||
updateEntityStringProperty("Description", format, changes, type, etag);
|
||||
}
|
||||
|
||||
protected void updateEntityStringProperty(final String propertyName,
|
||||
final ODataPubFormat format, final ODataEntity changes, final UpdateType type, final String etag) {
|
||||
|
||||
final URI editLink = changes.getEditLink();
|
||||
|
||||
final String newm = "New " + propertyName + "(" + System.currentTimeMillis() + ")";
|
||||
|
||||
ODataProperty propertyValue = changes.getProperty(propertyName);
|
||||
|
||||
final String oldm;
|
||||
if (propertyValue == null) {
|
||||
oldm = null;
|
||||
} else {
|
||||
oldm = propertyValue.getValue().toString();
|
||||
changes.getProperties().remove(propertyValue);
|
||||
}
|
||||
|
||||
assertNotEquals(newm, oldm);
|
||||
|
||||
getClient().getBinder().add(changes,
|
||||
getClient().getObjectFactory().newPrimitiveProperty(propertyName,
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().setText(newm).build()));
|
||||
|
||||
update(type, changes, format, etag);
|
||||
|
||||
final ODataEntity actual = read(format, editLink);
|
||||
|
||||
propertyValue = null;
|
||||
|
||||
for (ODataProperty prop : actual.getProperties()) {
|
||||
if (prop.getName().equals(propertyName)) {
|
||||
propertyValue = prop;
|
||||
}
|
||||
}
|
||||
|
||||
assertNotNull(propertyValue);
|
||||
assertEquals(newm, propertyValue.getValue().toString());
|
||||
}
|
||||
|
||||
protected void update(
|
||||
final UpdateType type, final ODataEntity changes, final ODataPubFormat format, final String etag) {
|
||||
final ODataEntityUpdateRequest req = getClient().getCUDRequestFactory().getEntityUpdateRequest(type, changes);
|
||||
|
||||
if (getClient().getConfiguration().isUseXHTTPMethod()) {
|
||||
assertEquals(HttpMethod.POST, req.getMethod());
|
||||
} else {
|
||||
assertEquals(type.getMethod(), req.getMethod());
|
||||
}
|
||||
req.setFormat(format);
|
||||
|
||||
if (StringUtils.isNotBlank(etag)) {
|
||||
req.setIfMatch(etag); // Product include ETag header into the response .....
|
||||
}
|
||||
|
||||
final ODataEntityUpdateResponse res = req.execute();
|
||||
assertEquals(204, res.getStatusCode());
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,11 @@
|
||||
*/
|
||||
package org.apache.olingo.client.core.it.v3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@ -37,21 +42,14 @@ import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse
|
||||
import org.apache.olingo.client.api.http.NoContentException;
|
||||
import org.apache.olingo.client.api.uri.CommonURIBuilder;
|
||||
import org.apache.olingo.client.core.uri.URIUtils;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataLink;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -68,10 +66,10 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
public void createAsAtom() {
|
||||
final ODataPubFormat format = ODataPubFormat.ATOM;
|
||||
final int id = 1;
|
||||
final CommonODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
|
||||
final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
|
||||
|
||||
createEntity(getServiceRoot(), format, original, "Customer");
|
||||
final CommonODataEntity actual = compareEntities(getServiceRoot(), format, original, id, null);
|
||||
final ODataEntity actual = compareEntities(getServiceRoot(), format, original, id, null);
|
||||
|
||||
cleanAfterCreate(format, actual, false, getServiceRoot());
|
||||
}
|
||||
@ -80,10 +78,10 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
public void createAsJSON() {
|
||||
final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
|
||||
final int id = 2;
|
||||
final CommonODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
|
||||
final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
|
||||
|
||||
createEntity(getServiceRoot(), format, original, "Customer");
|
||||
final CommonODataEntity actual = compareEntities(getServiceRoot(), format, original, id, null);
|
||||
final ODataEntity actual = compareEntities(getServiceRoot(), format, original, id, null);
|
||||
|
||||
cleanAfterCreate(format, actual, false, getServiceRoot());
|
||||
}
|
||||
@ -92,10 +90,10 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
public void createWithInlineAsAtom() {
|
||||
final ODataPubFormat format = ODataPubFormat.ATOM;
|
||||
final int id = 3;
|
||||
final CommonODataEntity original = getSampleCustomerProfile(id, "Sample customer", true);
|
||||
final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", true);
|
||||
|
||||
createEntity(getServiceRoot(), format, original, "Customer");
|
||||
final CommonODataEntity actual =
|
||||
final ODataEntity actual =
|
||||
compareEntities(getServiceRoot(), format, original, id, Collections.<String>singleton("Info"));
|
||||
|
||||
cleanAfterCreate(format, actual, true, getServiceRoot());
|
||||
@ -106,10 +104,10 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
// this needs to be full, otherwise there is no mean to recognize links
|
||||
final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
|
||||
final int id = 4;
|
||||
final CommonODataEntity original = getSampleCustomerProfile(id, "Sample customer", true);
|
||||
final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", true);
|
||||
|
||||
createEntity(getServiceRoot(), format, original, "Customer");
|
||||
final CommonODataEntity actual =
|
||||
final ODataEntity actual =
|
||||
compareEntities(getServiceRoot(), format, original, id, Collections.<String>singleton("Info"));
|
||||
|
||||
cleanAfterCreate(format, actual, true, getServiceRoot());
|
||||
@ -119,13 +117,13 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
public void createInlineWithoutLinkAsAtom() {
|
||||
final ODataPubFormat format = ODataPubFormat.ATOM;
|
||||
final int id = 5;
|
||||
final CommonODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
|
||||
final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
|
||||
|
||||
original.addLink(client.getObjectFactory().newInlineEntity(
|
||||
"Info", null, getSampleCustomerInfo(id, "Sample Customer_Info")));
|
||||
|
||||
createEntity(getServiceRoot(), format, original, "Customer");
|
||||
final CommonODataEntity actual =
|
||||
final ODataEntity actual =
|
||||
compareEntities(getServiceRoot(), format, original, id, Collections.<String>singleton("Info"));
|
||||
|
||||
boolean found = false;
|
||||
@ -146,13 +144,13 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
public void createInlineWithoutLinkAsJSON() {
|
||||
final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
|
||||
final int id = 6;
|
||||
final CommonODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
|
||||
final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
|
||||
|
||||
original.addLink(client.getObjectFactory().newInlineEntity(
|
||||
"Info", null, getSampleCustomerInfo(id, "Sample Customer_Info")));
|
||||
|
||||
createEntity(getServiceRoot(), format, original, "Customer");
|
||||
final CommonODataEntity actual =
|
||||
final ODataEntity actual =
|
||||
compareEntities(getServiceRoot(), format, original, id, Collections.<String>singleton("Info"));
|
||||
|
||||
boolean found = false;
|
||||
@ -172,7 +170,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
@Test
|
||||
public void createWithNavigationAsAtom() {
|
||||
final ODataPubFormat format = ODataPubFormat.ATOM;
|
||||
final CommonODataEntity actual = createWithNavigationLink(format, 5);
|
||||
final ODataEntity actual = createWithNavigationLink(format, 5);
|
||||
cleanAfterCreate(format, actual, false, getServiceRoot());
|
||||
}
|
||||
|
||||
@ -180,14 +178,14 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
public void createWithNavigationAsJSON() {
|
||||
// this needs to be full, otherwise there is no mean to recognize links
|
||||
final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
|
||||
final CommonODataEntity actual = createWithNavigationLink(format, 6);
|
||||
final ODataEntity actual = createWithNavigationLink(format, 6);
|
||||
cleanAfterCreate(format, actual, false, getServiceRoot());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithFeedNavigationAsAtom() throws EdmPrimitiveTypeException {
|
||||
final ODataPubFormat format = ODataPubFormat.ATOM;
|
||||
final CommonODataEntity actual = createWithFeedNavigationLink(format, 7);
|
||||
final ODataEntity actual = createWithFeedNavigationLink(format, 7);
|
||||
cleanAfterCreate(format, actual, false, getServiceRoot());
|
||||
}
|
||||
|
||||
@ -195,14 +193,14 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
public void createWithFeedNavigationAsJSON() throws EdmPrimitiveTypeException {
|
||||
// this needs to be full, otherwise there is no mean to recognize links
|
||||
final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
|
||||
final CommonODataEntity actual = createWithFeedNavigationLink(format, 8);
|
||||
final ODataEntity actual = createWithFeedNavigationLink(format, 8);
|
||||
cleanAfterCreate(format, actual, false, getServiceRoot());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithBackNavigationAsAtom() throws EdmPrimitiveTypeException {
|
||||
final ODataPubFormat format = ODataPubFormat.ATOM;
|
||||
final CommonODataEntity actual = createWithBackNavigationLink(format, 9);
|
||||
final ODataEntity actual = createWithBackNavigationLink(format, 9);
|
||||
cleanAfterCreate(format, actual, true, getServiceRoot());
|
||||
}
|
||||
|
||||
@ -210,7 +208,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
public void createWithBackNavigationAsJSON() throws EdmPrimitiveTypeException {
|
||||
// this needs to be full, otherwise there is no mean to recognize links
|
||||
final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
|
||||
final CommonODataEntity actual = createWithBackNavigationLink(format, 10);
|
||||
final ODataEntity actual = createWithBackNavigationLink(format, 10);
|
||||
cleanAfterCreate(format, actual, true, getServiceRoot());
|
||||
}
|
||||
|
||||
@ -227,13 +225,13 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
@Test
|
||||
public void createReturnNoContent() {
|
||||
final int id = 1;
|
||||
final CommonODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
|
||||
final ODataEntity original = (ODataEntity) getSampleCustomerProfile(id, "Sample customer", false);
|
||||
|
||||
final ODataEntityCreateRequest createReq = client.getCUDRequestFactory().getEntityCreateRequest(
|
||||
final ODataEntityCreateRequest<ODataEntity> createReq = client.getCUDRequestFactory().getEntityCreateRequest(
|
||||
client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer").build(), original);
|
||||
createReq.setPrefer(new ODataPreferences(client.getServiceVersion()).returnNoContent());
|
||||
|
||||
final ODataEntityCreateResponse createRes = createReq.execute();
|
||||
final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
|
||||
assertEquals(204, createRes.getStatusCode());
|
||||
assertEquals(new ODataPreferences(client.getServiceVersion()).returnNoContent(),
|
||||
createRes.getHeader(HeaderName.preferenceApplied).iterator().next());
|
||||
@ -255,10 +253,10 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
@Ignore
|
||||
public void issue135() {
|
||||
final int id = 2;
|
||||
final CommonODataEntity original = getSampleCustomerProfile(id, "Sample customer for issue 135", false);
|
||||
final ODataEntity original = (ODataEntity) getSampleCustomerProfile(id, "Sample customer for issue 135", false);
|
||||
|
||||
final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer");
|
||||
final ODataEntityCreateRequest createReq =
|
||||
final ODataEntityCreateRequest<ODataEntity> createReq =
|
||||
client.getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), original);
|
||||
createReq.setFormat(ODataPubFormat.JSON_FULL_METADATA);
|
||||
createReq.setContentType(ContentType.APPLICATION_ATOM_XML.getMimeType());
|
||||
@ -278,18 +276,18 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
}
|
||||
}
|
||||
|
||||
private CommonODataEntity createWithFeedNavigationLink(final ODataPubFormat format, final int id)
|
||||
private ODataEntity createWithFeedNavigationLink(final ODataPubFormat format, final int id)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
final String sampleName = "Sample customer";
|
||||
final CommonODataEntity original = getSampleCustomerProfile(id, sampleName, false);
|
||||
final ODataEntity original = (ODataEntity) getSampleCustomerProfile(id, sampleName, false);
|
||||
|
||||
final Set<Integer> keys = new HashSet<Integer>();
|
||||
keys.add(-100);
|
||||
keys.add(-101);
|
||||
|
||||
for (Integer key : keys) {
|
||||
final CommonODataEntity order =
|
||||
final ODataEntity order =
|
||||
client.getObjectFactory().newEntity("Microsoft.Test.OData.Services.AstoriaDefaultService.Order");
|
||||
|
||||
getClient().getBinder().add(order,
|
||||
@ -301,7 +299,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
client.getObjectFactory().newPrimitiveValueBuilder().setValue(id).
|
||||
setType(EdmPrimitiveTypeKind.Int32).build()));
|
||||
|
||||
final ODataEntityCreateRequest createReq = client.getCUDRequestFactory().getEntityCreateRequest(
|
||||
final ODataEntityCreateRequest<ODataEntity> createReq = client.getCUDRequestFactory().getEntityCreateRequest(
|
||||
client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Order").build(), order);
|
||||
createReq.setFormat(format);
|
||||
|
||||
@ -310,9 +308,9 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
createReq.execute().getBody().getEditLink()));
|
||||
}
|
||||
|
||||
final CommonODataEntity created = createEntity(getServiceRoot(), format, original, "Customer");
|
||||
final ODataEntity created = (ODataEntity) createEntity(getServiceRoot(), format, original, "Customer");
|
||||
// now, compare the created one with the actual one and go deeply into the associated customer info.....
|
||||
final CommonODataEntity actual = compareEntities(getServiceRoot(), format, created, id, null);
|
||||
final ODataEntity actual = (ODataEntity) compareEntities(getServiceRoot(), format, created, id, null);
|
||||
|
||||
final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot());
|
||||
uriBuilder.appendEntitySetSegment("Customer").appendKeySegment(id).appendEntitySetSegment("Orders");
|
||||
@ -324,11 +322,11 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
|
||||
assertEquals(200, res.getStatusCode());
|
||||
|
||||
final CommonODataEntitySet entitySet = res.getBody();
|
||||
final ODataEntitySet entitySet = res.getBody();
|
||||
assertNotNull(entitySet);
|
||||
assertEquals(2, entitySet.getCount());
|
||||
|
||||
for (CommonODataEntity entity : entitySet.getEntities()) {
|
||||
for (ODataEntity entity : entitySet.getEntities()) {
|
||||
final Integer key = entity.getProperty("OrderId").getPrimitiveValue().toCastValue(Integer.class);
|
||||
final Integer customerId = entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class);
|
||||
assertTrue(keys.contains(key));
|
||||
@ -345,16 +343,16 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
return actual;
|
||||
}
|
||||
|
||||
private CommonODataEntity createWithNavigationLink(final ODataPubFormat format, final int id) {
|
||||
private ODataEntity createWithNavigationLink(final ODataPubFormat format, final int id) {
|
||||
final String sampleName = "Sample customer";
|
||||
|
||||
final CommonODataEntity original = getSampleCustomerProfile(id, sampleName, false);
|
||||
final ODataEntity original = getSampleCustomerProfile(id, sampleName, false);
|
||||
original.addLink(client.getObjectFactory().newEntityNavigationLink(
|
||||
"Info", URI.create(getServiceRoot() + "/CustomerInfo(12)")));
|
||||
|
||||
final CommonODataEntity created = createEntity(getServiceRoot(), format, original, "Customer");
|
||||
final ODataEntity created = createEntity(getServiceRoot(), format, original, "Customer");
|
||||
// now, compare the created one with the actual one and go deeply into the associated customer info.....
|
||||
final CommonODataEntity actual = compareEntities(getServiceRoot(), format, created, id, null);
|
||||
final ODataEntity actual = compareEntities(getServiceRoot(), format, created, id, null);
|
||||
|
||||
final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot());
|
||||
uriBuilder.appendEntitySetSegment("Customer").appendKeySegment(id).appendEntitySetSegment("Info");
|
||||
@ -365,12 +363,12 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
final ODataRetrieveResponse<ODataEntity> res = req.execute();
|
||||
assertEquals(200, res.getStatusCode());
|
||||
|
||||
final CommonODataEntity info = res.getBody();
|
||||
final ODataEntity info = res.getBody();
|
||||
assertNotNull(info);
|
||||
|
||||
boolean found = false;
|
||||
|
||||
for (CommonODataProperty prop : info.getProperties()) {
|
||||
for (ODataProperty prop : info.getProperties()) {
|
||||
if ("CustomerInfoId".equals(prop.getName())) {
|
||||
assertEquals("12", prop.getValue().toString());
|
||||
found = true;
|
||||
@ -382,7 +380,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
return actual;
|
||||
}
|
||||
|
||||
private CommonODataEntity createWithBackNavigationLink(final ODataPubFormat format, final int id)
|
||||
private ODataEntity createWithBackNavigationLink(final ODataPubFormat format, final int id)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
final String sampleName = "Sample customer";
|
||||
@ -451,7 +449,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
}
|
||||
|
||||
private void multiKey(final ODataPubFormat format) {
|
||||
final CommonODataEntity message = client.getObjectFactory().newEntity(
|
||||
final ODataEntity message = client.getObjectFactory().newEntity(
|
||||
"Microsoft.Test.OData.Services.AstoriaDefaultService.Message");
|
||||
|
||||
getClient().getBinder().add(message,
|
||||
@ -481,11 +479,11 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
|
||||
|
||||
final CommonURIBuilder<?> builder =
|
||||
client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Message");
|
||||
final ODataEntityCreateRequest req = client.getCUDRequestFactory().getEntityCreateRequest(builder.build(),
|
||||
message);
|
||||
final ODataEntityCreateRequest<ODataEntity> req = client.getCUDRequestFactory().
|
||||
getEntityCreateRequest(builder.build(), message);
|
||||
req.setFormat(format);
|
||||
|
||||
final ODataEntityCreateResponse res = req.execute();
|
||||
final ODataEntityCreateResponse<ODataEntity> res = req.execute();
|
||||
assertNotNull(res);
|
||||
assertEquals(201, res.getStatusCode());
|
||||
|
||||
|
@ -27,7 +27,6 @@ import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateR
|
||||
import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
|
||||
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
|
||||
import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
@ -53,7 +52,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
|
||||
final URI uri = client.getURIBuilder(getServiceRoot()).
|
||||
appendEntitySetSegment("Product").appendKeySegment(-10).build();
|
||||
final String etag = getETag(uri);
|
||||
final CommonODataEntity merge = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
|
||||
final ODataEntity merge = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
|
||||
merge.setEditLink(uri);
|
||||
updateEntityDescription(format, merge, UpdateType.MERGE, etag);
|
||||
}
|
||||
@ -64,7 +63,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
|
||||
final URI uri = client.getURIBuilder(getServiceRoot()).
|
||||
appendEntitySetSegment("Product").appendKeySegment(-10).build();
|
||||
final String etag = getETag(uri);
|
||||
final CommonODataEntity merge = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
|
||||
final ODataEntity merge = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
|
||||
merge.setEditLink(uri);
|
||||
updateEntityDescription(format, merge, UpdateType.MERGE, etag);
|
||||
}
|
||||
@ -75,7 +74,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
|
||||
final URI uri = client.getURIBuilder(getServiceRoot()).
|
||||
appendEntitySetSegment("Product").appendKeySegment(-10).build();
|
||||
final String etag = getETag(uri);
|
||||
final CommonODataEntity patch = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
|
||||
final ODataEntity patch = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
|
||||
patch.setEditLink(uri);
|
||||
updateEntityDescription(format, patch, UpdateType.PATCH, etag);
|
||||
}
|
||||
@ -86,7 +85,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
|
||||
final URI uri = client.getURIBuilder(getServiceRoot()).
|
||||
appendEntitySetSegment("Product").appendKeySegment(-10).build();
|
||||
final String etag = getETag(uri);
|
||||
final CommonODataEntity patch = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
|
||||
final ODataEntity patch = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
|
||||
patch.setEditLink(uri);
|
||||
updateEntityDescription(format, patch, UpdateType.PATCH, etag);
|
||||
}
|
||||
@ -94,7 +93,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
|
||||
@Test
|
||||
public void replaceAsAtom() {
|
||||
final ODataPubFormat format = ODataPubFormat.ATOM;
|
||||
final CommonODataEntity changes = read(format, client.getURIBuilder(getServiceRoot()).
|
||||
final ODataEntity changes = read(format, client.getURIBuilder(getServiceRoot()).
|
||||
appendEntitySetSegment("Car").appendKeySegment(14).build());
|
||||
updateEntityDescription(format, changes, UpdateType.REPLACE);
|
||||
}
|
||||
@ -102,7 +101,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
|
||||
@Test
|
||||
public void replaceAsJSON() {
|
||||
final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
|
||||
final CommonODataEntity changes = read(format, client.getURIBuilder(getServiceRoot()).
|
||||
final ODataEntity changes = read(format, client.getURIBuilder(getServiceRoot()).
|
||||
appendEntitySetSegment("Car").appendKeySegment(14).build());
|
||||
updateEntityDescription(format, changes, UpdateType.REPLACE);
|
||||
}
|
||||
@ -121,7 +120,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
|
||||
final URI uri = client.getURIBuilder(getServiceRoot()).
|
||||
appendEntitySetSegment("Customer").appendKeySegment(-10).build();
|
||||
|
||||
final CommonODataEntity patch =
|
||||
final ODataEntity patch =
|
||||
client.getObjectFactory().newEntity("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer");
|
||||
patch.setEditLink(uri);
|
||||
|
||||
@ -141,7 +140,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
|
||||
ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(customerInfoURI);
|
||||
req.setFormat(format);
|
||||
|
||||
CommonODataEntity newInfo = req.execute().getBody();
|
||||
ODataEntity newInfo = req.execute().getBody();
|
||||
|
||||
assertEquals(Integer.valueOf(12),
|
||||
newInfo.getProperty("CustomerInfoId").getPrimitiveValue().toCastValue(Integer.class));
|
||||
@ -179,7 +178,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
|
||||
final LinkedHashMap<String, Object> multiKey = new LinkedHashMap<String, Object>();
|
||||
multiKey.put("FromUsername", "1");
|
||||
multiKey.put("MessageId", -10);
|
||||
final CommonODataEntity message = read(format, client.getURIBuilder(getServiceRoot()).
|
||||
final ODataEntity message = read(format, client.getURIBuilder(getServiceRoot()).
|
||||
appendEntitySetSegment("Message").appendKeySegment(multiKey).build());
|
||||
message.getAssociationLinks().clear();
|
||||
message.getNavigationLinks().clear();
|
||||
@ -226,7 +225,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
|
||||
final URI uri = client.getURIBuilder(getServiceRoot()).
|
||||
appendEntitySetSegment("Product").appendKeySegment(-10).build();
|
||||
String etag = getETag(uri);
|
||||
final CommonODataEntity product = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
|
||||
final ODataEntity product = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
|
||||
product.setEditLink(uri);
|
||||
updateEntityStringProperty("BaseConcurrency",
|
||||
client.getConfiguration().getDefaultPubFormat(), product, UpdateType.MERGE, etag);
|
||||
|
@ -22,7 +22,6 @@ import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
|
||||
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
|
||||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||
import org.apache.olingo.client.api.uri.CommonURIBuilder;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
import org.junit.AfterClass;
|
||||
@ -68,10 +67,10 @@ public class KeyAsSegmentTestITCase extends AbstractTestITCase {
|
||||
public void createODataEntityAsAtom() {
|
||||
final ODataPubFormat format = ODataPubFormat.ATOM;
|
||||
final int id = 1;
|
||||
final CommonODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
|
||||
final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
|
||||
|
||||
createEntity(testStaticServiceRootURL, format, original, "Customer");
|
||||
final CommonODataEntity actual = compareEntities(testStaticServiceRootURL, format, original, id, null);
|
||||
final ODataEntity actual = compareEntities(testStaticServiceRootURL, format, original, id, null);
|
||||
|
||||
cleanAfterCreate(format, actual, false, testStaticServiceRootURL);
|
||||
}
|
||||
@ -80,10 +79,10 @@ public class KeyAsSegmentTestITCase extends AbstractTestITCase {
|
||||
public void createODataEntityAsJSON() {
|
||||
final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
|
||||
final int id = 2;
|
||||
final CommonODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
|
||||
final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
|
||||
|
||||
createEntity(testStaticServiceRootURL, format, original, "Customer");
|
||||
final CommonODataEntity actual = compareEntities(testStaticServiceRootURL, format, original, id, null);
|
||||
final ODataEntity actual = compareEntities(testStaticServiceRootURL, format, original, id, null);
|
||||
|
||||
cleanAfterCreate(format, actual, false, testStaticServiceRootURL);
|
||||
}
|
||||
@ -91,7 +90,7 @@ public class KeyAsSegmentTestITCase extends AbstractTestITCase {
|
||||
@Test
|
||||
public void replaceODataEntityAsAtom() {
|
||||
final ODataPubFormat format = ODataPubFormat.ATOM;
|
||||
final CommonODataEntity changes = read(format, client.getURIBuilder(testStaticServiceRootURL).
|
||||
final ODataEntity changes = read(format, client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("Car").appendKeySegment(14).build());
|
||||
updateEntityDescription(format, changes, UpdateType.REPLACE);
|
||||
}
|
||||
@ -99,7 +98,7 @@ public class KeyAsSegmentTestITCase extends AbstractTestITCase {
|
||||
@Test
|
||||
public void replaceODataEntityAsJSON() {
|
||||
final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
|
||||
final CommonODataEntity changes = read(format, client.getURIBuilder(testStaticServiceRootURL).
|
||||
final ODataEntity changes = read(format, client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("Car").appendKeySegment(14).build());
|
||||
updateEntityDescription(format, changes, UpdateType.REPLACE);
|
||||
}
|
||||
|
@ -18,6 +18,11 @@
|
||||
*/
|
||||
package org.apache.olingo.client.core.it.v3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -39,22 +44,18 @@ import org.apache.olingo.client.core.uri.URIUtils;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataLink;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -66,7 +67,7 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
final ODataPubFormat format = ODataPubFormat.ATOM;
|
||||
final String contentType = "application/atom+xml";
|
||||
final String prefer = "return-content";
|
||||
final CommonODataEntity actual = createNavigation(format, 20, contentType, prefer);
|
||||
final ODataEntity actual = createNavigation(format, 20, contentType, prefer);
|
||||
delete(format, actual, false, testStaticServiceRootURL);
|
||||
}
|
||||
// create navigation link with JSON full metadata
|
||||
@ -76,7 +77,7 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
|
||||
final String contentType = "application/json;odata=fullmetadata";
|
||||
final String prefer = "return-content";
|
||||
final CommonODataEntity actual = createNavigation(format, 21, contentType, prefer);
|
||||
final ODataEntity actual = createNavigation(format, 21, contentType, prefer);
|
||||
delete(format, actual, false, testStaticServiceRootURL);
|
||||
}
|
||||
// throws Null pointer exception when the format is JSON No metadata
|
||||
@ -86,7 +87,7 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
final ODataPubFormat format = ODataPubFormat.JSON_NO_METADATA;
|
||||
final String contentType = "application/json;odata=nometadata";
|
||||
final String prefer = "return-content";
|
||||
final CommonODataEntity actual = createNavigation(format, 22, contentType, prefer);
|
||||
final ODataEntity actual = createNavigation(format, 22, contentType, prefer);
|
||||
delete(format, actual, false, testStaticServiceRootURL);
|
||||
}
|
||||
// test with JSON accept and atom content type
|
||||
@ -97,7 +98,7 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
|
||||
final String contentType = "application/atom+xml";
|
||||
final String prefer = "return-content";
|
||||
final CommonODataEntity actual = createNavigation(format, 23, contentType, prefer);
|
||||
final ODataEntity actual = createNavigation(format, 23, contentType, prefer);
|
||||
delete(format, actual, false, testStaticServiceRootURL);
|
||||
}
|
||||
// test with JSON full metadata in format and json no metadata in content type
|
||||
@ -107,7 +108,7 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
|
||||
final String contentType = "application/json;odata=nometadata";
|
||||
final String prefer = "return-content";
|
||||
final CommonODataEntity actual = createNavigation(format, 24, contentType, prefer);
|
||||
final ODataEntity actual = createNavigation(format, 24, contentType, prefer);
|
||||
delete(format, actual, false, testStaticServiceRootURL);
|
||||
}
|
||||
// test with JSON no metadata format and json no metadata in content type
|
||||
@ -117,7 +118,7 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
final ODataPubFormat format = ODataPubFormat.JSON_NO_METADATA;
|
||||
final String contentType = "application/json;odata=fullmetadata";
|
||||
final String prefer = "return-content";
|
||||
final CommonODataEntity actual = createNavigation(format, 25, contentType, prefer);
|
||||
final ODataEntity actual = createNavigation(format, 25, contentType, prefer);
|
||||
delete(format, actual, false, testStaticServiceRootURL);
|
||||
}
|
||||
// create collection navigation link with ATOM
|
||||
@ -127,7 +128,7 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
final ODataPubFormat format = ODataPubFormat.ATOM;
|
||||
final String contentType = "application/atom+xml";
|
||||
final String prefer = "return-content";
|
||||
final CommonODataEntity actual = createCollectionNavigation(format, 55, contentType, prefer);
|
||||
final ODataEntity actual = createCollectionNavigation(format, 55, contentType, prefer);
|
||||
delete(format, actual, false, testStaticServiceRootURL);
|
||||
}
|
||||
// create collection navigation link with JSON
|
||||
@ -137,22 +138,22 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
|
||||
final String contentType = "application/json;odata=fullmetadata";
|
||||
final String prefer = "return-content";
|
||||
final CommonODataEntity actual = createCollectionNavigation(format, 77, contentType, prefer);
|
||||
final ODataEntity actual = createCollectionNavigation(format, 77, contentType, prefer);
|
||||
delete(format, actual, false, testStaticServiceRootURL);
|
||||
}
|
||||
|
||||
// create a navigation link
|
||||
public CommonODataEntity createNavigation(final ODataPubFormat format, final int id, final String contenttype,
|
||||
public ODataEntity createNavigation(final ODataPubFormat format, final int id, final String contenttype,
|
||||
final String prefer) {
|
||||
final String name = "Customer Navigation test";
|
||||
|
||||
final CommonODataEntity original = getNewCustomer(id, name, false);
|
||||
final ODataEntity original = getNewCustomer(id, name, false);
|
||||
original.addLink(client.getObjectFactory().newEntityNavigationLink(
|
||||
"Info", URI.create(testStaticServiceRootURL + "/CustomerInfo(11)")));
|
||||
final CommonODataEntity created = createNav(testStaticServiceRootURL, format, original, "Customer", contenttype,
|
||||
final ODataEntity created = createNav(testStaticServiceRootURL, format, original, "Customer", contenttype,
|
||||
prefer);
|
||||
|
||||
final CommonODataEntity actual = validateEntities(testStaticServiceRootURL, format, created, id, null, "Customer");
|
||||
final ODataEntity actual = validateEntities(testStaticServiceRootURL, format, created, id, null, "Customer");
|
||||
|
||||
final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
|
||||
uriBuilder.appendEntitySetSegment("Customer").appendKeySegment(id).appendEntitySetSegment("Info");
|
||||
@ -175,38 +176,38 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
}
|
||||
|
||||
// create a navigation link
|
||||
public CommonODataEntity createNav(final String url, final ODataPubFormat format, final CommonODataEntity original,
|
||||
public ODataEntity createNav(final String url, final ODataPubFormat format, final ODataEntity original,
|
||||
final String entitySetName, final String contentType, final String prefer) {
|
||||
final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(url);
|
||||
uriBuilder.appendEntitySetSegment(entitySetName);
|
||||
final ODataEntityCreateRequest createReq =
|
||||
final ODataEntityCreateRequest<ODataEntity> createReq =
|
||||
client.getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), original);
|
||||
createReq.setFormat(format);
|
||||
createReq.setContentType(contentType);
|
||||
createReq.setPrefer(prefer);
|
||||
final ODataEntityCreateResponse createRes = createReq.execute();
|
||||
final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
|
||||
assertEquals(201, createRes.getStatusCode());
|
||||
|
||||
assertEquals("Created", createRes.getStatusMessage());
|
||||
|
||||
final CommonODataEntity created = createRes.getBody();
|
||||
final ODataEntity created = createRes.getBody();
|
||||
assertNotNull(created);
|
||||
return created;
|
||||
}
|
||||
// create collection navigation link
|
||||
|
||||
public CommonODataEntity createCollectionNavigation(final ODataPubFormat format, final int id,
|
||||
public ODataEntity createCollectionNavigation(final ODataPubFormat format, final int id,
|
||||
final String contentType, final String prefer) throws EdmPrimitiveTypeException {
|
||||
{
|
||||
final String name = "Collection Navigation Key Customer";
|
||||
final CommonODataEntity original = getNewCustomer(id, name, false);
|
||||
final ODataEntity original = getNewCustomer(id, name, false);
|
||||
|
||||
final Set<Integer> navigationKeys = new HashSet<Integer>();
|
||||
navigationKeys.add(-118);
|
||||
navigationKeys.add(-119);
|
||||
|
||||
for (Integer key : navigationKeys) {
|
||||
final CommonODataEntity orderEntity =
|
||||
final ODataEntity orderEntity =
|
||||
client.getObjectFactory().newEntity("Microsoft.Test.OData.Services.AstoriaDefaultService.Order");
|
||||
|
||||
getClient().getBinder().add(orderEntity,
|
||||
@ -218,7 +219,7 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
client.getObjectFactory().newPrimitiveValueBuilder().setValue(id).
|
||||
setType(EdmPrimitiveTypeKind.Int32).build()));
|
||||
|
||||
final ODataEntityCreateRequest createReq = client.getCUDRequestFactory().getEntityCreateRequest(
|
||||
final ODataEntityCreateRequest<ODataEntity> createReq = client.getCUDRequestFactory().getEntityCreateRequest(
|
||||
client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Order").build(),
|
||||
orderEntity);
|
||||
createReq.setFormat(format);
|
||||
@ -227,9 +228,9 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
"Orders",
|
||||
createReq.execute().getBody().getEditLink()));
|
||||
}
|
||||
final CommonODataEntity createdEntity = createNav(testStaticServiceRootURL, format, original, "Customer",
|
||||
final ODataEntity createdEntity = createNav(testStaticServiceRootURL, format, original, "Customer",
|
||||
contentType, prefer);
|
||||
final CommonODataEntity actualEntity =
|
||||
final ODataEntity actualEntity =
|
||||
validateEntities(testStaticServiceRootURL, format, createdEntity, id, null, "Customer");
|
||||
|
||||
final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
|
||||
@ -242,12 +243,12 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
|
||||
assertEquals(200, res.getStatusCode());
|
||||
|
||||
final CommonODataEntitySet entitySet = res.getBody();
|
||||
final ODataEntitySet entitySet = res.getBody();
|
||||
assertNotNull(entitySet);
|
||||
|
||||
assertEquals(2, entitySet.getCount());
|
||||
|
||||
for (CommonODataEntity entity : entitySet.getEntities()) {
|
||||
for (ODataEntity entity : entitySet.getEntities()) {
|
||||
final Integer key = entity.getProperty("OrderId").getPrimitiveValue().toCastValue(Integer.class);
|
||||
final Integer customerId = entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class);
|
||||
assertTrue(navigationKeys.contains(key));
|
||||
@ -265,10 +266,10 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
}
|
||||
// get a Customer entity to be created
|
||||
|
||||
public CommonODataEntity getNewCustomer(
|
||||
public ODataEntity getNewCustomer(
|
||||
final int id, final String name, final boolean withInlineInfo) {
|
||||
|
||||
final CommonODataEntity entity =
|
||||
final ODataEntity entity =
|
||||
client.getObjectFactory().newEntity("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer");
|
||||
|
||||
// add name attribute
|
||||
@ -284,35 +285,35 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
client.getObjectFactory().newPrimitiveValueBuilder().setText(String.valueOf(id)).
|
||||
setType(EdmPrimitiveTypeKind.Int32).build()));
|
||||
}
|
||||
final ODataCollectionValue backupContactInfoValue = getClient().getObjectFactory().newCollectionValue(
|
||||
final ODataCollectionValue<ODataValue> backupContactInfoValue = getClient().getObjectFactory().newCollectionValue(
|
||||
"Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails)");
|
||||
|
||||
final ODataComplexValue contactDetails = getClient().getObjectFactory().newComplexValue(
|
||||
final ODataComplexValue<ODataProperty> contactDetails = getClient().getObjectFactory().newComplexValue(
|
||||
"Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails");
|
||||
|
||||
final ODataCollectionValue altNamesValue = getClient().getObjectFactory().
|
||||
final ODataCollectionValue<ODataValue> altNamesValue = getClient().getObjectFactory().
|
||||
newCollectionValue("Collection(Edm.String)");
|
||||
altNamesValue.add(client.getObjectFactory().newPrimitiveValueBuilder().
|
||||
setText("My Alternative name").setType(EdmPrimitiveTypeKind.String).build());
|
||||
contactDetails.add(client.getObjectFactory().newCollectionProperty("AlternativeNames", altNamesValue));
|
||||
|
||||
final ODataCollectionValue emailBagValue = getClient().getObjectFactory().
|
||||
final ODataCollectionValue<ODataValue> emailBagValue = getClient().getObjectFactory().
|
||||
newCollectionValue("Collection(Edm.String)");
|
||||
emailBagValue.add(client.getObjectFactory().newPrimitiveValueBuilder().
|
||||
setText("altname@mydomain.com").setType(EdmPrimitiveTypeKind.String).build());
|
||||
contactDetails.add(client.getObjectFactory().newCollectionProperty("EmailBag", emailBagValue));
|
||||
|
||||
final ODataComplexValue contactAliasValue = getClient().getObjectFactory().newComplexValue(
|
||||
final ODataComplexValue<ODataProperty> contactAliasValue = getClient().getObjectFactory().newComplexValue(
|
||||
"Microsoft.Test.OData.Services.AstoriaDefaultService.Aliases");
|
||||
contactDetails.add(client.getObjectFactory().newComplexProperty("ContactAlias", contactAliasValue));
|
||||
|
||||
final ODataCollectionValue aliasAltNamesValue = getClient().getObjectFactory().
|
||||
final ODataCollectionValue<ODataValue> aliasAltNamesValue = getClient().getObjectFactory().
|
||||
newCollectionValue("Collection(Edm.String)");
|
||||
aliasAltNamesValue.add(client.getObjectFactory().newPrimitiveValueBuilder().
|
||||
setText("myAlternativeName").setType(EdmPrimitiveTypeKind.String).build());
|
||||
contactAliasValue.add(client.getObjectFactory().newCollectionProperty("AlternativeNames", aliasAltNamesValue));
|
||||
|
||||
final ODataComplexValue homePhone = getClient().getObjectFactory().newComplexValue(
|
||||
final ODataComplexValue<ODataProperty> homePhone = getClient().getObjectFactory().newComplexValue(
|
||||
"Microsoft.Test.OData.Services.AstoriaDefaultService.Phone");
|
||||
homePhone.add(client.getObjectFactory().newPrimitiveProperty("PhoneNumber",
|
||||
client.getObjectFactory().newPrimitiveValueBuilder().setText("8437568356834568").
|
||||
@ -338,7 +339,7 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
}
|
||||
//delete an entity and associated links after creation
|
||||
|
||||
public void delete(final ODataPubFormat format, final CommonODataEntity created, final boolean includeInline,
|
||||
public void delete(final ODataPubFormat format, final ODataEntity created, final boolean includeInline,
|
||||
final String baseUri) {
|
||||
final Set<URI> toBeDeleted = new HashSet<URI>();
|
||||
toBeDeleted.add(created.getEditLink());
|
||||
@ -376,8 +377,8 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
}
|
||||
// add Information property
|
||||
|
||||
public CommonODataEntity getInfo(final int id, final String info) {
|
||||
final CommonODataEntity entity =
|
||||
public ODataEntity getInfo(final int id, final String info) {
|
||||
final ODataEntity entity =
|
||||
client.getObjectFactory().newEntity("Microsoft.Test.OData.Services.AstoriaDefaultService.CustomerInfo");
|
||||
entity.setMediaEntity(true);
|
||||
|
||||
@ -388,9 +389,9 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
}
|
||||
// validate newly created entities
|
||||
|
||||
public CommonODataEntity validateEntities(final String serviceRootURL,
|
||||
public ODataEntity validateEntities(final String serviceRootURL,
|
||||
final ODataPubFormat format,
|
||||
final CommonODataEntity original,
|
||||
final ODataEntity original,
|
||||
final int actualObjectId,
|
||||
final Collection<String> expands, final String entitySetName) {
|
||||
|
||||
@ -501,7 +502,7 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
|
||||
}
|
||||
|
||||
final List<CommonODataProperty> actualPropertyValue = new ArrayList<CommonODataProperty>();
|
||||
for (CommonODataProperty prop : (ODataComplexValue) actual) {
|
||||
for (CommonODataProperty prop : actual.asComplex()) {
|
||||
actualPropertyValue.add(prop);
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,6 @@
|
||||
*/
|
||||
package org.apache.olingo.client.core.it.v3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@ -28,10 +25,11 @@ import java.util.UUID;
|
||||
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
|
||||
import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
|
||||
import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.client.api.uri.v3.URIBuilder;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
import org.apache.olingo.client.api.uri.CommonURIBuilder;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmSchema;
|
||||
@ -43,6 +41,10 @@ import org.apache.olingo.commons.api.edm.geo.MultiPoint;
|
||||
import org.apache.olingo.commons.api.edm.geo.MultiPolygon;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
import org.apache.olingo.commons.api.edm.geo.Polygon;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -61,10 +63,10 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
|
||||
// assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "RowIndex")).isOpenType());
|
||||
}
|
||||
|
||||
private CommonODataEntity readRow(final ODataPubFormat format, final String uuid) {
|
||||
final CommonURIBuilder<?> builder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
private ODataEntity readRow(final ODataPubFormat format, final String uuid) {
|
||||
final URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("Row").appendKeySegment(UUID.fromString(uuid));
|
||||
return read(format, builder.build());
|
||||
return (ODataEntity) read(format, builder.build());
|
||||
}
|
||||
|
||||
private void read(final ODataPubFormat format) {
|
||||
@ -91,7 +93,7 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
|
||||
private void cud(final ODataPubFormat format) {
|
||||
final UUID guid = UUID.randomUUID();
|
||||
|
||||
CommonODataEntity row = client.getObjectFactory().newEntity("Microsoft.Test.OData.Services.OpenTypesService.Row");
|
||||
ODataEntity row = client.getObjectFactory().newEntity("Microsoft.Test.OData.Services.OpenTypesService.Row");
|
||||
getClient().getBinder().add(row,
|
||||
client.getObjectFactory().newPrimitiveProperty("Id",
|
||||
client.getObjectFactory().newPrimitiveValueBuilder().
|
||||
@ -192,7 +194,7 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
|
||||
setType(EdmPrimitiveTypeKind.GeographyCollection).
|
||||
setValue(geoColl).build()));
|
||||
|
||||
final ODataComplexValue contactDetails = client.getObjectFactory().newComplexValue(
|
||||
final ODataComplexValue<ODataProperty> contactDetails = client.getObjectFactory().newComplexValue(
|
||||
"Microsoft.Test.OData.Services.OpenTypesService.ContactDetails");
|
||||
contactDetails.add(client.getObjectFactory().newPrimitiveProperty("FirstContacted",
|
||||
client.getObjectFactory().newPrimitiveValueBuilder().
|
||||
@ -233,11 +235,11 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
|
||||
getClient().getBinder().add(row,
|
||||
client.getObjectFactory().newComplexProperty("aContact", contactDetails));
|
||||
|
||||
final ODataEntityCreateRequest createReq = client.getCUDRequestFactory().
|
||||
final ODataEntityCreateRequest<ODataEntity> createReq = client.getCUDRequestFactory().
|
||||
getEntityCreateRequest(client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("Row").build(), row);
|
||||
createReq.setFormat(format);
|
||||
final ODataEntityCreateResponse createRes = createReq.execute();
|
||||
final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
|
||||
assertEquals(201, createRes.getStatusCode());
|
||||
|
||||
row = readRow(format, guid.toString());
|
||||
|
@ -18,6 +18,11 @@
|
||||
*/
|
||||
package org.apache.olingo.client.core.it.v3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.apache.olingo.client.api.communication.ODataClientErrorException;
|
||||
import org.apache.olingo.client.api.communication.request.cud.ODataPropertyUpdateRequest;
|
||||
@ -36,14 +41,11 @@ import org.apache.olingo.client.api.uri.CommonURIBuilder;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.commons.api.format.ODataValueFormat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@ -218,7 +220,7 @@ public class PropertyTestITCase extends AbstractTestITCase {
|
||||
|
||||
final String newItem = "new item " + System.currentTimeMillis();
|
||||
|
||||
final ODataCollectionValue originalValue =
|
||||
final ODataCollectionValue<ODataValue> originalValue =
|
||||
primaryContactInfo.getComplexValue().get("EmailBag").getCollectionValue();
|
||||
|
||||
final int origSize = originalValue.size();
|
||||
@ -266,7 +268,7 @@ public class PropertyTestITCase extends AbstractTestITCase {
|
||||
|
||||
final String newItem = "new item " + System.currentTimeMillis();
|
||||
|
||||
final ODataCollectionValue originalValue = alternativeNames.getCollectionValue();
|
||||
final ODataCollectionValue<ODataValue> originalValue = alternativeNames.getCollectionValue();
|
||||
|
||||
final int origSize = originalValue.size();
|
||||
|
||||
|
@ -23,7 +23,7 @@ import org.apache.olingo.client.api.v4.ODataClient;
|
||||
import org.apache.olingo.client.core.ODataClientFactory;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public abstract class AbstractTestITCase extends org.apache.olingo.client.core.it.AbstractTestITCase {
|
||||
public abstract class AbstractTestITCase {
|
||||
|
||||
protected static ODataClient client;
|
||||
|
||||
@ -45,7 +45,6 @@ public abstract class AbstractTestITCase extends org.apache.olingo.client.core.i
|
||||
client = ODataClientFactory.getV4();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ODataClient getClient() {
|
||||
return client;
|
||||
}
|
||||
|
@ -18,6 +18,11 @@
|
||||
*/
|
||||
package org.apache.olingo.client.core.it.v4;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@ -27,7 +32,6 @@ import org.apache.olingo.client.api.communication.request.retrieve.ODataRawReque
|
||||
import org.apache.olingo.client.api.communication.response.ODataRawResponse;
|
||||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||
import org.apache.olingo.client.api.uri.CommonURIBuilder;
|
||||
import static org.apache.olingo.client.core.it.v4.AbstractTestITCase.client;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
@ -38,12 +42,6 @@ import org.apache.olingo.commons.api.domain.v4.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
import org.apache.olingo.commons.core.op.ResourceFactory;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -81,9 +79,6 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
|
||||
final CommonODataEntity inline = ((ODataInlineEntity) link).getEntity();
|
||||
assertNotNull(inline);
|
||||
|
||||
debugEntry(client.getBinder().getEntry(
|
||||
inline, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)), "Just read");
|
||||
|
||||
final List<? extends CommonODataProperty> properties = inline.getProperties();
|
||||
assertEquals(5, properties.size());
|
||||
|
||||
@ -136,9 +131,6 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
|
||||
final CommonODataEntitySet inline = ((ODataInlineEntitySet) link).getEntitySet();
|
||||
assertNotNull(inline);
|
||||
|
||||
debugFeed(client.getBinder().getFeed(inline, ResourceFactory.feedClassForFormat(
|
||||
format == ODataPubFormat.ATOM)), "Just read");
|
||||
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
import org.apache.olingo.commons.core.op.ResourceFactory;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -109,9 +108,6 @@ public class EntitySetTestITCase extends AbstractTestITCase {
|
||||
|
||||
assertTrue(res.getContextURL().toASCIIString().endsWith("$metadata#People"));
|
||||
|
||||
debugFeed(client.getBinder().getFeed(feed, ResourceFactory.feedClassForFormat(
|
||||
ODataPubFormat.ATOM == format)), "Just retrieved feed");
|
||||
|
||||
assertEquals(5, feed.getEntities().size());
|
||||
assertNotNull(feed.getNext());
|
||||
|
||||
|
@ -23,7 +23,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.client.api.communication.ODataClientErrorException;
|
||||
import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest;
|
||||
import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest;
|
||||
import org.apache.olingo.client.api.uri.CommonURIBuilder;
|
||||
import org.apache.olingo.client.api.uri.v4.URIBuilder;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
@ -38,7 +38,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test
|
||||
public void retrieveIntPropertyValueTest() throws EdmPrimitiveTypeException {
|
||||
final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("PersonID").
|
||||
appendValueSegment();
|
||||
final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
|
||||
@ -48,7 +48,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test
|
||||
public void retrieveBooleanPropertyValueTest() throws EdmPrimitiveTypeException {
|
||||
final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("IsRegistered").
|
||||
appendValueSegment();
|
||||
final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
|
||||
@ -58,7 +58,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test
|
||||
public void retrieveStringPropertyValueTest() throws EdmPrimitiveTypeException {
|
||||
final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("FirstName").
|
||||
appendValueSegment();
|
||||
final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
|
||||
@ -68,7 +68,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test
|
||||
public void retrieveDatePropertyValueTest() {
|
||||
final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("Orders").appendKeySegment(8).appendPropertySegment("OrderDate").
|
||||
appendValueSegment();
|
||||
final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
|
||||
@ -79,7 +79,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test
|
||||
public void retrieveDecimalPropertyValueTest() throws EdmPrimitiveTypeException {
|
||||
final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("Height").
|
||||
appendValueSegment();
|
||||
final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
|
||||
@ -90,7 +90,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test
|
||||
public void retrieveBinaryPropertyValueTest() throws IOException {
|
||||
final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("PDC").
|
||||
appendValueSegment();
|
||||
final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
|
||||
@ -102,7 +102,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test(expected = ODataClientErrorException.class)
|
||||
public void retrieveBinaryPropertyValueTestWithAtom() throws IOException {
|
||||
final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("PDC").
|
||||
appendValueSegment();
|
||||
final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
|
||||
@ -112,7 +112,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test(expected = ODataClientErrorException.class)
|
||||
public void retrieveBinaryPropertyValueTestWithXML() throws IOException {
|
||||
final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("PDC").
|
||||
appendValueSegment();
|
||||
final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
|
||||
@ -122,7 +122,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test
|
||||
public void retrieveCollectionPropertyValueTest() {
|
||||
CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("Numbers");
|
||||
final ODataPropertyRequest<ODataProperty> req = client.getRetrieveRequestFactory().
|
||||
getPropertyRequest(uriBuilder.build());
|
||||
@ -134,7 +134,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test
|
||||
public void retrieveNullPropertyValueTest() {
|
||||
CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("MiddleName").
|
||||
appendValueSegment();
|
||||
final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
|
||||
|
@ -31,11 +31,12 @@ import org.apache.olingo.client.core.AbstractTest;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class PropertyTest extends AbstractTest {
|
||||
@ -57,15 +58,15 @@ public class PropertyTest extends AbstractTest {
|
||||
assertEquals("-10", value.toString());
|
||||
}
|
||||
|
||||
private CommonODataProperty primitive(final ODataFormat format) throws IOException, EdmPrimitiveTypeException {
|
||||
private ODataProperty primitive(final ODataFormat format) throws IOException, EdmPrimitiveTypeException {
|
||||
final InputStream input = getClass().getResourceAsStream("Customer_-10_CustomerId." + getSuffix(format));
|
||||
final CommonODataProperty property = getClient().getReader().readProperty(input, format);
|
||||
final ODataProperty property = getClient().getReader().readProperty(input, format);
|
||||
assertNotNull(property);
|
||||
assertTrue(property.hasPrimitiveValue());
|
||||
assertTrue(-10 == property.getPrimitiveValue().toCastValue(Integer.class));
|
||||
|
||||
CommonODataProperty comparable;
|
||||
final CommonODataProperty written = getClient().getReader().readProperty(
|
||||
ODataProperty comparable;
|
||||
final ODataProperty written = getClient().getReader().readProperty(
|
||||
getClient().getWriter().writeProperty(property, format), format);
|
||||
if (format == ODataFormat.XML) {
|
||||
comparable = written;
|
||||
@ -93,24 +94,24 @@ public class PropertyTest extends AbstractTest {
|
||||
primitive(ODataFormat.JSON);
|
||||
}
|
||||
|
||||
private CommonODataProperty complex(final ODataFormat format) throws IOException {
|
||||
private ODataProperty complex(final ODataFormat format) throws IOException {
|
||||
final InputStream input = getClass().getResourceAsStream("Customer_-10_PrimaryContactInfo." + getSuffix(format));
|
||||
final CommonODataProperty property = getClient().getReader().readProperty(input, format);
|
||||
final ODataProperty property = getClient().getReader().readProperty(input, format);
|
||||
assertNotNull(property);
|
||||
assertTrue(property.hasComplexValue());
|
||||
assertEquals(6, property.getComplexValue().size());
|
||||
|
||||
CommonODataProperty comparable;
|
||||
final CommonODataProperty written = getClient().getReader().readProperty(
|
||||
ODataProperty comparable;
|
||||
final ODataProperty written = getClient().getReader().readProperty(
|
||||
getClient().getWriter().writeProperty(property, format), format);
|
||||
if (format == ODataFormat.XML) {
|
||||
comparable = written;
|
||||
} else {
|
||||
// This is needed because type information gets lost with JSON serialization
|
||||
final ODataComplexValue typedValue = getClient().getObjectFactory().
|
||||
final ODataComplexValue<ODataProperty> typedValue = getClient().getObjectFactory().
|
||||
newComplexValue(property.getComplexValue().getTypeName());
|
||||
for (final Iterator<CommonODataProperty> itor = written.getComplexValue().iterator(); itor.hasNext();) {
|
||||
final CommonODataProperty prop = itor.next();
|
||||
for (final Iterator<ODataProperty> itor = written.getComplexValue().iterator(); itor.hasNext();) {
|
||||
final ODataProperty prop = itor.next();
|
||||
typedValue.add(prop);
|
||||
}
|
||||
comparable = getClient().getObjectFactory().newComplexProperty(written.getName(), typedValue);
|
||||
@ -131,21 +132,21 @@ public class PropertyTest extends AbstractTest {
|
||||
complex(ODataFormat.JSON);
|
||||
}
|
||||
|
||||
private CommonODataProperty collection(final ODataFormat format) throws IOException {
|
||||
private ODataProperty collection(final ODataFormat format) throws IOException {
|
||||
final InputStream input = getClass().getResourceAsStream("Customer_-10_BackupContactInfo." + getSuffix(format));
|
||||
final CommonODataProperty property = getClient().getReader().readProperty(input, format);
|
||||
final ODataProperty property = getClient().getReader().readProperty(input, format);
|
||||
assertNotNull(property);
|
||||
assertTrue(property.hasCollectionValue());
|
||||
assertEquals(9, property.getCollectionValue().size());
|
||||
|
||||
CommonODataProperty comparable;
|
||||
final CommonODataProperty written = getClient().getReader().readProperty(
|
||||
ODataProperty comparable;
|
||||
final ODataProperty written = getClient().getReader().readProperty(
|
||||
getClient().getWriter().writeProperty(property, format), format);
|
||||
if (format == ODataFormat.XML) {
|
||||
comparable = written;
|
||||
} else {
|
||||
// This is needed because type information gets lost with JSON serialization
|
||||
final ODataCollectionValue typedValue = getClient().getObjectFactory().
|
||||
final ODataCollectionValue<ODataValue> typedValue = getClient().getObjectFactory().
|
||||
newCollectionValue(property.getCollectionValue().getTypeName());
|
||||
for (final Iterator<ODataValue> itor = written.getCollectionValue().iterator(); itor.hasNext();) {
|
||||
final ODataValue value = itor.next();
|
||||
|
@ -28,9 +28,9 @@ import org.apache.olingo.client.api.v4.ODataClient;
|
||||
import org.apache.olingo.client.core.AbstractTest;
|
||||
import org.apache.olingo.commons.api.domain.ODataLink;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkType;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
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.ODataValue;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDuration;
|
||||
@ -107,12 +107,12 @@ public class EntityTest extends AbstractTest {
|
||||
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Color", skinColor.getEnumValue().getTypeName());
|
||||
assertEquals("Red", skinColor.getEnumValue().getValue());
|
||||
|
||||
// final ODataProperty coverColors = entity.getProperty("CoverColors");
|
||||
// assertTrue(coverColors.hasCollectionValue());
|
||||
// for (final Iterator<ODataValue> itor = coverColors.getCollectionValue().iterator(); itor.hasNext();) {
|
||||
// final ODataValue item = itor.next();
|
||||
// assertTrue(item.isEnum());
|
||||
// }
|
||||
final ODataProperty coverColors = entity.getProperty("CoverColors");
|
||||
assertTrue(coverColors.hasCollectionValue());
|
||||
for (final Iterator<ODataValue> itor = coverColors.getCollectionValue().iterator(); itor.hasNext();) {
|
||||
final ODataValue item = itor.next();
|
||||
assertTrue(item.isEnum());
|
||||
}
|
||||
|
||||
// operations won't get serialized
|
||||
entity.getOperations().clear();
|
||||
|
@ -35,7 +35,7 @@ public abstract class AbstractODataValue implements ODataValue {
|
||||
*/
|
||||
private final String typeName;
|
||||
|
||||
public AbstractODataValue(String typeName) {
|
||||
public AbstractODataValue(final String typeName) {
|
||||
this.typeName = typeName;
|
||||
}
|
||||
|
||||
@ -79,9 +79,10 @@ public abstract class AbstractODataValue implements ODataValue {
|
||||
*
|
||||
* @return complex value.
|
||||
*/
|
||||
// @SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ODataComplexValue asComplex() {
|
||||
return isComplex() ? (ODataComplexValue) this : null;
|
||||
public <OP extends CommonODataProperty> ODataComplexValue<OP> asComplex() {
|
||||
return isComplex() ? (ODataComplexValue<OP>) this : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,9 +100,10 @@ public abstract class AbstractODataValue implements ODataValue {
|
||||
*
|
||||
* @return collection value.
|
||||
*/
|
||||
// @SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ODataCollectionValue asCollection() {
|
||||
return isCollection() ? (ODataCollectionValue) this : null;
|
||||
public <OV extends ODataValue> ODataCollectionValue<OV> asCollection() {
|
||||
return isCollection() ? (ODataCollectionValue<OV>) this : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -177,9 +177,9 @@ public interface CommonODataObjectFactory {
|
||||
|
||||
ODataPrimitiveValue.Builder newPrimitiveValueBuilder();
|
||||
|
||||
ODataComplexValue newComplexValue(String typeName);
|
||||
ODataComplexValue<? extends CommonODataProperty> newComplexValue(String typeName);
|
||||
|
||||
ODataCollectionValue newCollectionValue(String typeName);
|
||||
ODataCollectionValue<? extends ODataValue> newCollectionValue(String typeName);
|
||||
|
||||
/**
|
||||
* Instantiates a new primitive property.
|
||||
@ -197,7 +197,7 @@ public interface CommonODataObjectFactory {
|
||||
* @param value value.
|
||||
* @return complex property.
|
||||
*/
|
||||
CommonODataProperty newComplexProperty(String name, ODataComplexValue value);
|
||||
CommonODataProperty newComplexProperty(String name, ODataComplexValue<? extends CommonODataProperty> value);
|
||||
|
||||
/**
|
||||
* Instantiates a new collection property.
|
||||
@ -206,5 +206,5 @@ public interface CommonODataObjectFactory {
|
||||
* @param value value.
|
||||
* @return collection property.
|
||||
*/
|
||||
CommonODataProperty newCollectionProperty(String name, ODataCollectionValue value);
|
||||
CommonODataProperty newCollectionProperty(String name, ODataCollectionValue<? extends ODataValue> value);
|
||||
}
|
||||
|
@ -67,13 +67,6 @@ public interface CommonODataProperty extends ODataInvokeResult, Serializable {
|
||||
*/
|
||||
boolean hasCollectionValue();
|
||||
|
||||
/**
|
||||
* Gets collection value.
|
||||
*
|
||||
* @return collection value if exists; null otherwise.
|
||||
*/
|
||||
ODataCollectionValue getCollectionValue();
|
||||
|
||||
/**
|
||||
* Checks if has complex value.
|
||||
*
|
||||
@ -81,11 +74,4 @@ public interface CommonODataProperty extends ODataInvokeResult, Serializable {
|
||||
*/
|
||||
boolean hasComplexValue();
|
||||
|
||||
/**
|
||||
* Gets complex value.
|
||||
*
|
||||
* @return complex value if exists; null otherwise.
|
||||
*/
|
||||
ODataComplexValue getComplexValue();
|
||||
|
||||
}
|
||||
|
@ -20,15 +20,17 @@ package org.apache.olingo.commons.api.domain;
|
||||
|
||||
/**
|
||||
* OData collection property value.
|
||||
*
|
||||
* @param <OV> The actual ODataValue interface.
|
||||
*/
|
||||
public interface ODataCollectionValue extends ODataValue, Iterable<ODataValue> {
|
||||
public interface ODataCollectionValue<OV extends ODataValue> extends ODataValue, Iterable<OV> {
|
||||
|
||||
/**
|
||||
* Adds a value to the collection.
|
||||
*
|
||||
* @param value value to be added.
|
||||
*/
|
||||
void add(ODataValue value);
|
||||
void add(OV value);
|
||||
|
||||
/**
|
||||
* Checks if collection is empty.
|
||||
|
@ -20,15 +20,17 @@ package org.apache.olingo.commons.api.domain;
|
||||
|
||||
/**
|
||||
* OData complex property value.
|
||||
*
|
||||
* @param <OP> The actual ODataProperty interface.
|
||||
*/
|
||||
public interface ODataComplexValue extends ODataValue, Iterable<CommonODataProperty> {
|
||||
public interface ODataComplexValue<OP extends CommonODataProperty> extends ODataValue, Iterable<OP> {
|
||||
|
||||
/**
|
||||
* Adds field to the complex type.
|
||||
*
|
||||
* @param field field to be added.
|
||||
*/
|
||||
void add(CommonODataProperty field);
|
||||
void add(OP field);
|
||||
|
||||
/**
|
||||
* Gets field.
|
||||
@ -36,7 +38,7 @@ public interface ODataComplexValue extends ODataValue, Iterable<CommonODataPrope
|
||||
* @param name name of the field to be retrieved.
|
||||
* @return requested field.
|
||||
*/
|
||||
CommonODataProperty get(String name);
|
||||
OP get(String name);
|
||||
|
||||
/**
|
||||
* Gets number of fields.
|
||||
|
@ -56,9 +56,10 @@ public interface ODataValue extends Serializable {
|
||||
/**
|
||||
* Casts to collection value.
|
||||
*
|
||||
* @param <OV> The actual ODataValue interface.
|
||||
* @return collection value.
|
||||
*/
|
||||
ODataCollectionValue asCollection();
|
||||
<OV extends ODataValue> ODataCollectionValue<OV> asCollection();
|
||||
|
||||
/**
|
||||
* Check is is a complex value.
|
||||
@ -70,8 +71,9 @@ public interface ODataValue extends Serializable {
|
||||
/**
|
||||
* Casts to complex value.
|
||||
*
|
||||
* @param <OP> The actual ODataProperty interface.
|
||||
* @return complex value.
|
||||
*/
|
||||
ODataComplexValue asComplex();
|
||||
<OP extends CommonODataProperty> ODataComplexValue<OP> asComplex();
|
||||
|
||||
}
|
||||
|
@ -20,9 +20,11 @@ package org.apache.olingo.commons.api.domain.v3;
|
||||
|
||||
import java.net.URI;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataObjectFactory;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
|
||||
public interface ODataObjectFactory extends CommonODataObjectFactory {
|
||||
|
||||
@ -38,13 +40,19 @@ public interface ODataObjectFactory extends CommonODataObjectFactory {
|
||||
@Override
|
||||
ODataEntity newEntity(String name, URI link);
|
||||
|
||||
@Override
|
||||
ODataComplexValue<ODataProperty> newComplexValue(String typeName);
|
||||
|
||||
@Override
|
||||
ODataCollectionValue<ODataValue> newCollectionValue(String typeName);
|
||||
|
||||
@Override
|
||||
ODataProperty newPrimitiveProperty(String name, ODataPrimitiveValue value);
|
||||
|
||||
@Override
|
||||
ODataProperty newComplexProperty(String name, ODataComplexValue value);
|
||||
ODataProperty newComplexProperty(String name, ODataComplexValue<? extends CommonODataProperty> value);
|
||||
|
||||
@Override
|
||||
ODataProperty newCollectionProperty(String name, ODataCollectionValue value);
|
||||
ODataProperty newCollectionProperty(String name, ODataCollectionValue<? extends ODataValue> value);
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,23 @@
|
||||
package org.apache.olingo.commons.api.domain.v3;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
|
||||
public interface ODataProperty extends CommonODataProperty {
|
||||
|
||||
/**
|
||||
* Gets collection value.
|
||||
*
|
||||
* @return collection value if exists; null otherwise.
|
||||
*/
|
||||
ODataCollectionValue<ODataValue> getCollectionValue();
|
||||
|
||||
/**
|
||||
* Gets complex value.
|
||||
*
|
||||
* @return complex value if exists; null otherwise.
|
||||
*/
|
||||
ODataComplexValue<ODataProperty> getComplexValue();
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ package org.apache.olingo.commons.api.domain.v4;
|
||||
|
||||
import java.net.URI;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataObjectFactory;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
@ -40,15 +41,22 @@ public interface ODataObjectFactory extends CommonODataObjectFactory {
|
||||
|
||||
ODataEnumValue newEnumValue(String typeName, String value);
|
||||
|
||||
@Override
|
||||
ODataComplexValue<ODataProperty> newComplexValue(String typeName);
|
||||
|
||||
@Override
|
||||
ODataCollectionValue<ODataValue> newCollectionValue(String typeName);
|
||||
|
||||
@Override
|
||||
ODataProperty newPrimitiveProperty(String name, ODataPrimitiveValue value);
|
||||
|
||||
ODataProperty newEnumProperty(String name, ODataEnumValue value);
|
||||
|
||||
@Override
|
||||
ODataProperty newComplexProperty(String name, ODataComplexValue value);
|
||||
ODataProperty newComplexProperty(String name, ODataComplexValue<? extends CommonODataProperty> value);
|
||||
|
||||
@Override
|
||||
ODataProperty newCollectionProperty(String name, ODataCollectionValue value);
|
||||
ODataProperty newCollectionProperty(String name,
|
||||
ODataCollectionValue<? extends org.apache.olingo.commons.api.domain.ODataValue> value);
|
||||
|
||||
}
|
||||
|
@ -19,9 +19,25 @@
|
||||
package org.apache.olingo.commons.api.domain.v4;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
|
||||
public interface ODataProperty extends CommonODataProperty {
|
||||
|
||||
/**
|
||||
* Gets collection value.
|
||||
*
|
||||
* @return collection value if exists; null otherwise.
|
||||
*/
|
||||
ODataCollectionValue<ODataValue> getCollectionValue();
|
||||
|
||||
/**
|
||||
* Gets complex value.
|
||||
*
|
||||
* @return complex value if exists; null otherwise.
|
||||
*/
|
||||
ODataComplexValue<ODataProperty> getComplexValue();
|
||||
|
||||
/**
|
||||
* Checks if has enum value.
|
||||
*
|
||||
|
@ -27,22 +27,25 @@ import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
|
||||
/**
|
||||
* OData collection property value.
|
||||
*
|
||||
* @param <OV> The actual ODataValue interface.
|
||||
*/
|
||||
public class ODataCollectionValueImpl extends AbstractODataValue implements ODataCollectionValue {
|
||||
public abstract class AbstractODataCollectionValue<OV extends ODataValue>
|
||||
extends AbstractODataValue implements ODataCollectionValue<OV> {
|
||||
|
||||
private static final long serialVersionUID = -3665659846001987187L;
|
||||
|
||||
/**
|
||||
* Values.
|
||||
*/
|
||||
private final List<ODataValue> values = new ArrayList<ODataValue>();
|
||||
private final List<OV> values = new ArrayList<OV>();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param typeName type name.
|
||||
*/
|
||||
public ODataCollectionValueImpl(final String typeName) {
|
||||
public AbstractODataCollectionValue(final String typeName) {
|
||||
super(typeName);
|
||||
}
|
||||
|
||||
@ -52,7 +55,7 @@ public class ODataCollectionValueImpl extends AbstractODataValue implements ODat
|
||||
* @param value value to be added.
|
||||
*/
|
||||
@Override
|
||||
public void add(final ODataValue value) {
|
||||
public void add(final OV value) {
|
||||
if (value.isPrimitive() || value.isComplex()) {
|
||||
values.add(value);
|
||||
}
|
||||
@ -64,7 +67,7 @@ public class ODataCollectionValueImpl extends AbstractODataValue implements ODat
|
||||
* @return value iterator.
|
||||
*/
|
||||
@Override
|
||||
public Iterator<ODataValue> iterator() {
|
||||
public Iterator<OV> iterator() {
|
||||
return values.iterator();
|
||||
}
|
||||
|
@ -27,22 +27,25 @@ import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
|
||||
/**
|
||||
* OData complex property value.
|
||||
*
|
||||
* @param <OP> The actual ODataProperty interface.
|
||||
*/
|
||||
public class ODataComplexValueImpl extends AbstractODataValue implements ODataComplexValue {
|
||||
public abstract class AbstractODataComplexValue<OP extends CommonODataProperty>
|
||||
extends AbstractODataValue implements ODataComplexValue<OP> {
|
||||
|
||||
private static final long serialVersionUID = -1878555027714020431L;
|
||||
|
||||
/**
|
||||
* Complex type fields.
|
||||
*/
|
||||
private final Map<String, CommonODataProperty> fields = new LinkedHashMap<String, CommonODataProperty>();
|
||||
private final Map<String, OP> fields = new LinkedHashMap<String, OP>();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param typeName type name.
|
||||
*/
|
||||
public ODataComplexValueImpl(final String typeName) {
|
||||
public AbstractODataComplexValue(final String typeName) {
|
||||
super(typeName);
|
||||
}
|
||||
|
||||
@ -52,8 +55,9 @@ public class ODataComplexValueImpl extends AbstractODataValue implements ODataCo
|
||||
* @param field field to be added.
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void add(final CommonODataProperty field) {
|
||||
fields.put(field.getName(), field);
|
||||
fields.put(field.getName(), (OP) field);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,7 +67,7 @@ public class ODataComplexValueImpl extends AbstractODataValue implements ODataCo
|
||||
* @return requested field.
|
||||
*/
|
||||
@Override
|
||||
public CommonODataProperty get(final String name) {
|
||||
public OP get(final String name) {
|
||||
return fields.get(name);
|
||||
}
|
||||
|
||||
@ -73,7 +77,7 @@ public class ODataComplexValueImpl extends AbstractODataValue implements ODataCo
|
||||
* @return fields iterator.
|
||||
*/
|
||||
@Override
|
||||
public Iterator<CommonODataProperty> iterator() {
|
||||
public Iterator<OP> iterator() {
|
||||
return fields.values().iterator();
|
||||
}
|
||||
|
@ -20,15 +20,12 @@ package org.apache.olingo.commons.core.domain;
|
||||
|
||||
import java.net.URI;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkType;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataLink;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataObjectFactory;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
|
||||
public abstract class AbstractODataObjectFactory implements CommonODataObjectFactory {
|
||||
@ -115,19 +112,4 @@ public abstract class AbstractODataObjectFactory implements CommonODataObjectFac
|
||||
setType(ODataLinkType.MEDIA_EDIT).setTitle(name).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue.Builder newPrimitiveValueBuilder() {
|
||||
return new ODataPrimitiveValueImpl.BuilderImpl(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataComplexValue newComplexValue(final String typeName) {
|
||||
return new ODataComplexValueImpl(typeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataCollectionValue newCollectionValue(final String typeName) {
|
||||
return new ODataCollectionValueImpl(typeName);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,23 +29,22 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
|
||||
public class ODataPrimitiveValueImpl extends AbstractODataValue implements ODataPrimitiveValue {
|
||||
public abstract class AbstractODataPrimitiveValue extends AbstractODataValue implements ODataPrimitiveValue {
|
||||
|
||||
private static final long serialVersionUID = 8889282662298376036L;
|
||||
|
||||
public static class BuilderImpl implements Builder {
|
||||
public static abstract class AbstractBuilder implements Builder {
|
||||
|
||||
private final ODataServiceVersion version;
|
||||
|
||||
private final ODataPrimitiveValueImpl instance;
|
||||
|
||||
public BuilderImpl(final ODataServiceVersion version) {
|
||||
public AbstractBuilder(final ODataServiceVersion version) {
|
||||
this.version = version;
|
||||
this.instance = new ODataPrimitiveValueImpl();
|
||||
}
|
||||
|
||||
protected abstract AbstractODataPrimitiveValue getInstance();
|
||||
|
||||
@Override
|
||||
public BuilderImpl setType(final EdmPrimitiveTypeKind type) {
|
||||
public AbstractBuilder setType(final EdmPrimitiveTypeKind type) {
|
||||
if (type != null && !type.getSupportedVersions().contains(version)) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Type %s not supported by OData version %s", type.toString(), version));
|
||||
@ -62,60 +61,60 @@ public class ODataPrimitiveValueImpl extends AbstractODataValue implements OData
|
||||
+ "Each value MUST be of some subtype.");
|
||||
}
|
||||
|
||||
this.instance.typeKind = type == null ? EdmPrimitiveTypeKind.String : type;
|
||||
this.instance.type = EdmPrimitiveTypeFactory.getInstance(this.instance.typeKind);
|
||||
getInstance().typeKind = type == null ? EdmPrimitiveTypeKind.String : type;
|
||||
getInstance().type = EdmPrimitiveTypeFactory.getInstance(getInstance().typeKind);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuilderImpl setText(final String text) {
|
||||
this.instance.text = text;
|
||||
public AbstractBuilder setText(final String text) {
|
||||
getInstance().text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuilderImpl setValue(final Object value) {
|
||||
this.instance.value = value;
|
||||
public AbstractBuilder setValue(final Object value) {
|
||||
getInstance().value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValueImpl build() {
|
||||
if (this.instance.text == null && this.instance.value == null) {
|
||||
public AbstractODataPrimitiveValue build() {
|
||||
if (getInstance().text == null && getInstance().value == null) {
|
||||
throw new IllegalArgumentException("Must provide either text or value");
|
||||
}
|
||||
if (this.instance.text != null && this.instance.value != null) {
|
||||
if (getInstance().text != null && getInstance().value != null) {
|
||||
throw new IllegalArgumentException("Cannot provide both text and value");
|
||||
}
|
||||
|
||||
if (this.instance.type == null) {
|
||||
if (getInstance().type == null) {
|
||||
setType(EdmPrimitiveTypeKind.String);
|
||||
}
|
||||
|
||||
if (this.instance.text != null) {
|
||||
final Class<?> returnType = this.instance.type.getDefaultType().isAssignableFrom(Calendar.class)
|
||||
? Timestamp.class : this.instance.type.getDefaultType();
|
||||
if (getInstance().text != null) {
|
||||
final Class<?> returnType = getInstance().type.getDefaultType().isAssignableFrom(Calendar.class)
|
||||
? Timestamp.class : getInstance().type.getDefaultType();
|
||||
try {
|
||||
// TODO: when Edm is available, set facets when calling this method
|
||||
this.instance.value = this.instance.type.valueOfString(
|
||||
this.instance.text, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null,
|
||||
getInstance().value = getInstance().type.valueOfString(
|
||||
getInstance().text, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null,
|
||||
returnType);
|
||||
} catch (EdmPrimitiveTypeException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
if (this.instance.value != null) {
|
||||
if (getInstance().value != null) {
|
||||
try {
|
||||
// TODO: when Edm is available, set facets when calling this method
|
||||
this.instance.text = this.instance.type.valueToString(
|
||||
this.instance.value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null);
|
||||
getInstance().text = getInstance().type.valueToString(
|
||||
getInstance().value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null);
|
||||
} catch (EdmPrimitiveTypeException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return this.instance;
|
||||
return getInstance();
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,7 +138,7 @@ public class ODataPrimitiveValueImpl extends AbstractODataValue implements OData
|
||||
*/
|
||||
private Object value;
|
||||
|
||||
private ODataPrimitiveValueImpl() {
|
||||
protected AbstractODataPrimitiveValue() {
|
||||
super(null);
|
||||
}
|
||||
|
@ -22,8 +22,6 @@ import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
@ -113,16 +111,6 @@ public abstract class AbstractODataProperty implements CommonODataProperty {
|
||||
return !hasNullValue() && this.value.isComplex();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets complex value.
|
||||
*
|
||||
* @return complex value if exists; null otherwise.
|
||||
*/
|
||||
@Override
|
||||
public ODataComplexValue getComplexValue() {
|
||||
return hasComplexValue() ? this.value.asComplex() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if has collection value.
|
||||
*
|
||||
@ -133,16 +121,6 @@ public abstract class AbstractODataProperty implements CommonODataProperty {
|
||||
return !hasNullValue() && this.value.isCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets collection value.
|
||||
*
|
||||
* @return collection value if exists; null otherwise.
|
||||
*/
|
||||
@Override
|
||||
public ODataCollectionValue getCollectionValue() {
|
||||
return hasCollectionValue() ? this.value.asCollection() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc }
|
||||
*/
|
||||
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.domain.v3;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
import org.apache.olingo.commons.core.domain.AbstractODataCollectionValue;
|
||||
|
||||
public class ODataCollectionValueImpl extends AbstractODataCollectionValue<ODataValue> {
|
||||
|
||||
private static final long serialVersionUID = 5887168245885401351L;
|
||||
|
||||
public ODataCollectionValueImpl(final String typeName) {
|
||||
super(typeName);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.domain.v3;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
|
||||
import org.apache.olingo.commons.core.domain.AbstractODataComplexValue;
|
||||
|
||||
public class ODataComplexValueImpl extends AbstractODataComplexValue<ODataProperty> {
|
||||
|
||||
private static final long serialVersionUID = 1143925901934898802L;
|
||||
|
||||
public ODataComplexValueImpl(final String typeName) {
|
||||
super(typeName);
|
||||
}
|
||||
|
||||
}
|
@ -19,9 +19,11 @@
|
||||
package org.apache.olingo.commons.core.domain.v3;
|
||||
|
||||
import java.net.URI;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataObjectFactory;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
||||
@ -57,18 +59,37 @@ public class ODataObjectFactoryImpl extends AbstractODataObjectFactory implement
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue.Builder newPrimitiveValueBuilder() {
|
||||
return new ODataPrimitiveValueImpl.BuilderImpl(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataComplexValue<ODataProperty> newComplexValue(final String typeName) {
|
||||
return new ODataComplexValueImpl(typeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataCollectionValue<ODataValue> newCollectionValue(final String typeName) {
|
||||
return new ODataCollectionValueImpl(typeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataProperty newPrimitiveProperty(final String name, final ODataPrimitiveValue value) {
|
||||
return new ODataPropertyImpl(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataProperty newComplexProperty(final String name, final ODataComplexValue value) {
|
||||
public ODataProperty newComplexProperty(final String name,
|
||||
final ODataComplexValue<? extends CommonODataProperty> value) {
|
||||
|
||||
return new ODataPropertyImpl(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataProperty newCollectionProperty(final String name, final ODataCollectionValue value) {
|
||||
public ODataProperty newCollectionProperty(final String name,
|
||||
final ODataCollectionValue<? extends ODataValue> value) {
|
||||
|
||||
return new ODataPropertyImpl(name, value);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.domain.v3;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
import org.apache.olingo.commons.core.domain.AbstractODataPrimitiveValue;
|
||||
|
||||
public class ODataPrimitiveValueImpl extends AbstractODataPrimitiveValue {
|
||||
|
||||
private static final long serialVersionUID = -5201738902625613179L;
|
||||
|
||||
public static class BuilderImpl extends AbstractBuilder {
|
||||
|
||||
private final ODataPrimitiveValueImpl instance;
|
||||
|
||||
public BuilderImpl(final ODataServiceVersion version) {
|
||||
super(version);
|
||||
this.instance = new ODataPrimitiveValueImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractODataPrimitiveValue getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -18,6 +18,8 @@
|
||||
*/
|
||||
package org.apache.olingo.commons.core.domain.v3;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
|
||||
import org.apache.olingo.commons.core.domain.AbstractODataProperty;
|
||||
@ -30,4 +32,14 @@ public class ODataPropertyImpl extends AbstractODataProperty implements ODataPro
|
||||
super(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataComplexValue<ODataProperty> getComplexValue() {
|
||||
return hasComplexValue() ? getValue().<ODataProperty>asComplex() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataCollectionValue<ODataValue> getCollectionValue() {
|
||||
return hasCollectionValue() ? getValue().<ODataValue>asCollection() : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.domain.v4;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataValue;
|
||||
import org.apache.olingo.commons.core.domain.AbstractODataCollectionValue;
|
||||
|
||||
public class ODataCollectionValueImpl extends AbstractODataCollectionValue<ODataValue> implements ODataValue {
|
||||
|
||||
private static final long serialVersionUID = 5887168245885401351L;
|
||||
|
||||
public ODataCollectionValueImpl(final String typeName) {
|
||||
super(typeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnum() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataEnumValue asEnum() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.domain.v4;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataValue;
|
||||
import org.apache.olingo.commons.core.domain.AbstractODataComplexValue;
|
||||
|
||||
public class ODataComplexValueImpl extends AbstractODataComplexValue<ODataProperty> implements ODataValue {
|
||||
|
||||
private static final long serialVersionUID = 1143925901934898802L;
|
||||
|
||||
public ODataComplexValueImpl(final String typeName) {
|
||||
super(typeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnum() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataEnumValue asEnum() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
package org.apache.olingo.commons.core.domain.v4;
|
||||
|
||||
import java.net.URI;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
@ -27,6 +28,7 @@ import org.apache.olingo.commons.api.domain.v4.ODataObjectFactory;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataValue;
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
import org.apache.olingo.commons.core.domain.AbstractODataObjectFactory;
|
||||
|
||||
@ -58,23 +60,42 @@ public class ODataObjectFactoryImpl extends AbstractODataObjectFactory implement
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPrimitiveValue.Builder newPrimitiveValueBuilder() {
|
||||
return new ODataPrimitiveValueImpl.BuilderImpl(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataEnumValue newEnumValue(final String typeName, final String value) {
|
||||
return new ODataEnumValueImpl(typeName, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataComplexValue<ODataProperty> newComplexValue(final String typeName) {
|
||||
return new ODataComplexValueImpl(typeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataCollectionValue<ODataValue> newCollectionValue(final String typeName) {
|
||||
return new ODataCollectionValueImpl(typeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataProperty newPrimitiveProperty(final String name, final ODataPrimitiveValue value) {
|
||||
return new ODataPropertyImpl(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataProperty newComplexProperty(final String name, final ODataComplexValue value) {
|
||||
public ODataProperty newComplexProperty(final String name,
|
||||
final ODataComplexValue<? extends CommonODataProperty> value) {
|
||||
|
||||
return new ODataPropertyImpl(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataProperty newCollectionProperty(final String name, final ODataCollectionValue value) {
|
||||
public ODataProperty newCollectionProperty(final String name,
|
||||
final ODataCollectionValue<? extends org.apache.olingo.commons.api.domain.ODataValue> value) {
|
||||
|
||||
return new ODataPropertyImpl(name, value);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.domain.v4;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataValue;
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
import org.apache.olingo.commons.core.domain.AbstractODataPrimitiveValue;
|
||||
|
||||
public class ODataPrimitiveValueImpl extends AbstractODataPrimitiveValue implements ODataValue {
|
||||
|
||||
private static final long serialVersionUID = -5201738902625613179L;
|
||||
|
||||
public static class BuilderImpl extends AbstractBuilder {
|
||||
|
||||
private final ODataPrimitiveValueImpl instance;
|
||||
|
||||
public BuilderImpl(final ODataServiceVersion version) {
|
||||
super(version);
|
||||
this.instance = new ODataPrimitiveValueImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractODataPrimitiveValue getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnum() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataEnumValue asEnum() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -18,8 +18,11 @@
|
||||
*/
|
||||
package org.apache.olingo.commons.core.domain.v4;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataValue;
|
||||
import org.apache.olingo.commons.core.domain.AbstractODataProperty;
|
||||
|
||||
public class ODataPropertyImpl extends AbstractODataProperty implements ODataProperty {
|
||||
@ -41,4 +44,14 @@ public class ODataPropertyImpl extends AbstractODataProperty implements ODataPro
|
||||
return hasEnumValue() ? ((org.apache.olingo.commons.api.domain.v4.ODataValue) getValue()).asEnum() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataComplexValue<ODataProperty> getComplexValue() {
|
||||
return hasComplexValue() ? getValue().<ODataProperty>asComplex() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataCollectionValue<ODataValue> getCollectionValue() {
|
||||
return hasCollectionValue() ? getValue().<ODataValue>asCollection() : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
5
pom.xml
5
pom.xml
@ -231,6 +231,11 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<showWarnings>true</showWarnings>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<compilerArgument>-Xlint:unchecked</compilerArgument>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
Loading…
x
Reference in New Issue
Block a user