From 588df780bf1eb5e0860f48d55e7863a11e238c5e Mon Sep 17 00:00:00 2001 From: Christian Holzer Date: Fri, 12 Jun 2015 18:01:35 +0200 Subject: [PATCH] [OLINGO-704] Class ODataFormat removed --- .../olingo/ext/proxy/AbstractService.java | 4 +- .../EntityContainerInvocationHandler.java | 1 + .../commons/EntityInvocationHandler.java | 6 +- .../commons/EntitySetInvocationHandler.java | 6 +- .../ext/pojogen/AbstractPOJOGenMojo.java | 4 +- .../olingo/fit/AbstractBaseTestITCase.java | 11 +- .../fit/tecsvc/client/ActionImportITCase.java | 4 +- .../olingo/fit/tecsvc/client/BasicITCase.java | 9 +- .../fit/tecsvc/client/BatchClientITCase.java | 23 ++-- .../fit/tecsvc/client/BindingITCase.java | 6 +- .../fit/tecsvc/client/ConditionalITCase.java | 4 +- .../fit/tecsvc/client/DeepInsertITCase.java | 6 +- .../tecsvc/client/EntityReferencesITCase.java | 4 +- .../ExpandWithSystemQueryOptionsITCase.java | 4 +- .../client/FilterSystemQueryITCase.java | 4 +- .../tecsvc/client/FunctionImportITCase.java | 4 +- .../olingo/fit/tecsvc/client/MediaITCase.java | 3 +- .../fit/tecsvc/client/NavigationITCase.java | 4 +- .../client/OrderBySystemQueryITCase.java | 4 +- .../tecsvc/client/PrimitiveComplexITCase.java | 3 +- .../client/SystemQueryOptionITCase.java | 4 +- .../olingo/fit/v4/AbstractTestITCase.java | 17 ++- .../apache/olingo/fit/v4/AsyncTestITCase.java | 20 +-- .../olingo/fit/v4/AuthBatchTestITCase.java | 5 +- .../apache/olingo/fit/v4/BatchTestITCase.java | 21 ++- .../v4/BoundOperationInvokeTestITCase.java | 52 ++++---- .../olingo/fit/v4/ConformanceTestITCase.java | 30 ++--- .../apache/olingo/fit/v4/DeltaTestITCase.java | 8 +- .../olingo/fit/v4/DerivedTypeTestITCase.java | 22 +-- .../olingo/fit/v4/EntityCreateTestITCase.java | 26 ++-- .../fit/v4/EntityRetrieveTestITCase.java | 88 ++++++------ .../olingo/fit/v4/EntitySetTestITCase.java | 38 +++--- .../olingo/fit/v4/EntityUpdateTestITCase.java | 32 ++--- .../fit/v4/ErrorResponseTestITCase.java | 4 +- .../fit/v4/FilterFactoryTestITCase.java | 4 +- .../v4/JSONFormatConformanceTestITCase.java | 12 +- .../olingo/fit/v4/KeyAsSegmentTestITCase.java | 24 ++-- .../olingo/fit/v4/MediaEntityTestITCase.java | 28 ++-- .../olingo/fit/v4/OAuth2TestITCase.java | 14 +- .../olingo/fit/v4/OpenTypeTestITCase.java | 26 ++-- .../v4/OperationImportInvokeTestITCase.java | 38 +++--- .../olingo/fit/v4/PropertyTestITCase.java | 42 +++--- .../fit/v4/PropertyValueTestITCase.java | 22 +-- .../olingo/fit/v4/QueryOptionsTestITCase.java | 6 +- .../fit/v4/ServiceDocumentTestITCase.java | 10 +- .../olingo/fit/v4/SingletonTestITCase.java | 30 ++--- .../olingo/client/api/Configuration.java | 17 +-- .../apache/olingo/client/api/ODataClient.java | 8 +- .../olingo/client/api/ODataClientBuilder.java | 8 +- .../request/ODataBasicRequest.java | 8 +- .../streamed/ODataStreamedEntityRequest.java | 7 +- .../api/domain/ClientEntitySetIterator.java | 21 +-- .../client/api/serialization/ODataReader.java | 27 ++-- .../client/api/serialization/ODataWriter.java | 26 ++-- .../olingo/client/core/ConfigurationImpl.java | 31 +++-- .../client/core/ODataClientFactory.java | 4 +- .../olingo/client/core/ODataClientImpl.java | 17 +-- .../header/ODataErrorResponseChecker.java | 8 +- .../request/AbstractODataBasicRequest.java | 8 +- .../request/AbstractODataRequest.java | 8 +- .../request/cud/ODataDeleteRequestImpl.java | 4 +- .../cud/ODataEntityCreateRequestImpl.java | 10 +- .../cud/ODataEntityUpdateRequestImpl.java | 10 +- .../cud/ODataPropertyUpdateRequestImpl.java | 10 +- .../cud/ODataReferenceAddingRequestImpl.java | 6 +- .../cud/ODataValueUpdateRequestImpl.java | 13 +- .../invoke/AbstractODataInvokeRequest.java | 37 ++--- .../invoke/ODataInvokeRequestImpl.java | 14 +- .../retrieve/AbstractMetadataRequestImpl.java | 5 +- .../retrieve/ODataDeltaRequestImpl.java | 8 +- .../retrieve/ODataEntityRequestImpl.java | 8 +- .../ODataEntitySetIteratorRequestImpl.java | 8 +- .../retrieve/ODataEntitySetRequestImpl.java | 8 +- .../retrieve/ODataMediaRequestImpl.java | 8 +- .../retrieve/ODataPropertyRequestImpl.java | 8 +- .../request/retrieve/ODataRawRequestImpl.java | 4 +- .../ODataServiceDocumentRequestImpl.java | 8 +- .../retrieve/ODataValueRequestImpl.java | 11 +- .../retrieve/XMLMetadataRequestImpl.java | 4 +- .../AbstractODataStreamedEntityRequest.java | 16 +-- .../AbstractODataStreamedRequest.java | 3 +- .../ClientODataDeserializerImpl.java | 19 +-- .../core/serialization/ODataBinderImpl.java | 54 ++++---- .../core/serialization/ODataReaderImpl.java | 50 +++---- .../core/serialization/ODataWriterImpl.java | 28 ++-- .../olingo/client/core/AbstractTest.java | 8 +- .../olingo/client/core/v4/AtomTest.java | 22 +-- .../olingo/client/core/v4/EntitySetTest.java | 44 +++--- .../olingo/client/core/v4/EntityTest.java | 105 +++++++-------- .../olingo/client/core/v4/ErrorTest.java | 22 +-- .../olingo/client/core/v4/JSONTest.java | 52 ++++---- .../olingo/client/core/v4/MetadataTest.java | 14 +- .../olingo/client/core/v4/PropertyTest.java | 67 +++++----- .../client/core/v4/ServiceDocumentTest.java | 41 +++--- .../olingo/commons/api/format/AcceptType.java | 6 +- .../commons/api/format/ContentType.java | 65 +++++++-- .../olingo/commons/api/format/Format.java | 41 ++++++ .../commons/api/format/ODataFormat.java | 126 ------------------ .../commons/api/format/AcceptTypeTest.java | 6 +- .../serialization/JsonEntitySerializer.java | 12 +- .../core/serialization/JsonSerializer.java | 16 +-- .../org/apache/olingo/server/api/OData.java | 2 +- .../olingo/server/core/ErrorHandler.java | 5 +- .../olingo/server/core/ServiceRequest.java | 8 +- .../server/example/TripPinDataModel.java | 4 +- .../olingo/server/core/ContentNegotiator.java | 20 +-- .../olingo/server/core/ODataHandler.java | 3 +- .../apache/olingo/server/core/ODataImpl.java | 6 +- .../serializer/json/ODataJsonSerializer.java | 14 +- .../json/ServiceDocumentJsonSerializer.java | 11 +- .../olingo/server/core/uri/parser/Parser.java | 8 +- .../server/core/ContentNegotiatorTest.java | 3 +- .../json/ODataJsonDeserializerBasicTest.java | 26 ++-- .../json/ODataJsonSerializerTest.java | 4 +- .../json/ServerErrorSerializerTest.java | 6 +- .../MetadataDocumentXmlSerializerTest.java | 4 +- .../processor/TechnicalActionProcessor.java | 12 +- .../processor/TechnicalEntityProcessor.java | 6 +- .../TechnicalPrimitiveComplexProcessor.java | 4 +- .../olingo/server/core/ODataHandlerTest.java | 5 +- .../json/AbstractODataDeserializerTest.java | 3 +- .../json/ODataJsonSerializerTest.java | 7 +- .../serializer/json/ServiceDocumentTest.java | 4 +- .../serializer/xml/MetadataDocumentTest.java | 4 +- .../sample/processor/CarsProcessor.java | 11 +- 125 files changed, 1035 insertions(+), 1081 deletions(-) create mode 100644 lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/Format.java delete mode 100644 lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ODataFormat.java diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/AbstractService.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/AbstractService.java index f8506c22a..0fd8c46e6 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/AbstractService.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/AbstractService.java @@ -34,7 +34,7 @@ import org.apache.olingo.client.core.edm.ClientCsdlEdmProvider; import org.apache.olingo.commons.api.ODataRuntimeException; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.core.edm.EdmProviderImpl; import org.apache.olingo.ext.proxy.api.AbstractTerm; import org.apache.olingo.ext.proxy.api.PersistenceManager; @@ -96,7 +96,7 @@ public abstract class AbstractService { } this.client = ODataClientFactory.getEdmEnabledClient(serviceRoot, edm, metadataETag); - this.client.getConfiguration().setDefaultPubFormat(ODataFormat.JSON_FULL_METADATA); + this.client.getConfiguration().setDefaultPubFormat(ContentType.JSON_FULL_METADATA); this.transactional = transactional; this.context = new Context(); } diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java index b31e624c0..f3f1b4d7b 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java @@ -24,6 +24,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.net.URI; + import org.apache.commons.lang3.ArrayUtils; import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.commons.api.edm.FullQualifiedName; diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java index 66bc66c97..c124402d3 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java @@ -33,12 +33,12 @@ import org.apache.commons.lang3.StringUtils; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataMediaRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; -import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.client.api.domain.ClientAnnotation; import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientProperty; +import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.ext.proxy.AbstractService; import org.apache.olingo.ext.proxy.api.AbstractTerm; import org.apache.olingo.ext.proxy.api.Annotatable; @@ -335,7 +335,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler getClient().getRetrieveRequestFactory().getMediaEntityRequest(contentSource); if (StringUtils.isNotBlank(getEntity().getMediaContentType())) { - retrieveReq.setFormat(ODataFormat.fromString(getEntity().getMediaContentType())); + retrieveReq.setFormat(ContentType.parse(getEntity().getMediaContentType())); } final ODataRetrieveResponse res = retrieveReq.execute(); diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java index 6c8d35f89..8250f7224 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java @@ -29,11 +29,11 @@ import java.util.concurrent.Future; import org.apache.commons.lang3.tuple.Triple; import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest; -import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.client.api.domain.ClientAnnotation; import org.apache.olingo.client.api.domain.ClientEntity; +import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.ext.proxy.AbstractService; import org.apache.olingo.ext.proxy.api.AbstractEntitySet; import org.apache.olingo.ext.proxy.api.AbstractSingleton; @@ -95,7 +95,7 @@ public class EntitySetInvocationHandler< public Long count() { final ODataValueRequest req = getClient().getRetrieveRequestFactory(). getValueRequest(getClient().newURIBuilder(this.uri.build().toASCIIString()).count().build()); - req.setFormat(ODataFormat.TEXT_PLAIN); + req.setFormat(ContentType.TEXT_PLAIN); return Long.valueOf(req.execute().getBody().asPrimitive().toString()); } diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java index 9321c6429..295d1c24a 100644 --- a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java +++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java @@ -55,7 +55,7 @@ import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmEnumType; import org.apache.olingo.commons.api.edm.EdmSchema; import org.apache.olingo.commons.api.edm.EdmTerm; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.Velocity; @@ -218,7 +218,7 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo { } else if (StringUtils.isNotEmpty(localEdm)) { final FileInputStream fis = new FileInputStream(FileUtils.getFile(localEdm)); try { - metadata = getClient().getDeserializer(ODataFormat.XML).toMetadata(fis); + metadata = getClient().getDeserializer(ContentType.APPLICATION_XML).toMetadata(fis); edm = getClient().getReader().readMetadata(metadata.getSchemaByNsOrAlias()); } finally { IOUtils.closeQuietly(fis); diff --git a/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java index 523aedd51..a83839016 100644 --- a/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java @@ -35,7 +35,7 @@ import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.domain.ClientValue; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntityCollection; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataSerializerException; import org.apache.olingo.fit.server.TomcatTestServer; import org.apache.olingo.server.tecsvc.TechnicalServlet; @@ -72,7 +72,7 @@ public abstract class AbstractBaseTestITCase { if (LOG.isDebugEnabled()) { final StringWriter writer = new StringWriter(); try { - getClient().getSerializer(ODataFormat.JSON).write(writer, entity); + getClient().getSerializer(ContentType.JSON).write(writer, entity); } catch (final ODataSerializerException e) { // Debug } @@ -85,7 +85,7 @@ public abstract class AbstractBaseTestITCase { if (LOG.isDebugEnabled()) { final StringWriter writer = new StringWriter(); try { - getClient().getSerializer(ODataFormat.JSON).write(writer, entitySet); + getClient().getSerializer(ContentType.JSON).write(writer, entitySet); } catch (final ODataSerializerException e) { // Debug } @@ -106,7 +106,8 @@ public abstract class AbstractBaseTestITCase { if (LOG.isDebugEnabled()) { StringWriter writer = new StringWriter(); try { - getClient().getSerializer(ODataFormat.ATOM).write(writer, getClient().getBinder().getEntity(entity)); + getClient().getSerializer(ContentType.APPLICATION_ATOM_XML).write(writer, getClient().getBinder() + .getEntity(entity)); } catch (final ODataSerializerException e) { // Debug } @@ -115,7 +116,7 @@ public abstract class AbstractBaseTestITCase { writer = new StringWriter(); try { - getClient().getSerializer(ODataFormat.JSON).write(writer, getClient().getBinder().getEntity(entity)); + getClient().getSerializer(ContentType.JSON).write(writer, getClient().getBinder().getEntity(entity)); } catch (final ODataSerializerException e) { // Debug } diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java index 0c40003c4..8661af4f9 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java @@ -41,7 +41,7 @@ import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.domain.ClientValue; import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.fit.AbstractBaseTestITCase; import org.apache.olingo.fit.tecsvc.TecSvcConst; import org.junit.Test; @@ -298,7 +298,7 @@ public class ActionImportITCase extends AbstractBaseTestITCase { @Override protected ODataClient getClient() { ODataClient odata = ODataClientFactory.getClient(); - odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON_NO_METADATA); + odata.getConfiguration().setDefaultPubFormat(ContentType.JSON_NO_METADATA); return odata; } diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java index 936569e1b..fc0a32ec0 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java @@ -72,7 +72,6 @@ import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.fit.AbstractBaseTestITCase; @@ -421,7 +420,7 @@ public class BasicITCase extends AbstractBaseTestITCase { @Test public void readEntityWithExpandedNavigationProperty() { final ODataClient client = ODataClientFactory.getEdmEnabledClient(SERVICE_URI); - client.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + client.getConfiguration().setDefaultPubFormat(ContentType.JSON); final URI uri = client.newURIBuilder(SERVICE_URI) .appendEntitySetSegment("ESKeyNav") @@ -938,7 +937,7 @@ public class BasicITCase extends AbstractBaseTestITCase { @Test public void createEntityWithIEEE754CompatibleParameter() { final ODataClient client = ODataClientFactory.getEdmEnabledClient(SERVICE_URI); - client.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + client.getConfiguration().setDefaultPubFormat(ContentType.JSON); final ClientObjectFactory of = client.getObjectFactory(); final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).build(); final URI linkURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_PRIM) @@ -965,7 +964,7 @@ public class BasicITCase extends AbstractBaseTestITCase { @Test public void createEntityInt64AndDecimalAsStringWithoutIEEE754ComaptibleParameter() { final ODataClient client = ODataClientFactory.getEdmEnabledClient(SERVICE_URI); - client.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + client.getConfiguration().setDefaultPubFormat(ContentType.JSON); final ClientObjectFactory of = client.getObjectFactory(); final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).build(); final URI linkURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_PRIM) @@ -1104,7 +1103,7 @@ public class BasicITCase extends AbstractBaseTestITCase { @Override protected ODataClient getClient() { ODataClient odata = ODataClientFactory.getClient(); - odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + odata.getConfiguration().setDefaultPubFormat(ContentType.JSON); return odata; } } diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java index 72a4ef394..ef8012621 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java @@ -51,7 +51,6 @@ import org.apache.olingo.client.core.communication.request.batch.ODataChangesetR import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.fit.tecsvc.TecSvcConst; @@ -123,7 +122,7 @@ public class BatchClientITCase extends AbstractTestITCase { assertTrue(changeSetResponse.isBreaking()); assertEquals(HttpStatusCode.NOT_FOUND.getStatusCode(), updateResponse.getStatusCode()); - assertEquals(ODataFormat.JSON.toString(), updateResponse.getContentType()); + assertEquals(ContentType.JSON.toContentTypeString(), updateResponse.getContentType()); } @Test @@ -258,7 +257,7 @@ public class BatchClientITCase extends AbstractTestITCase { final BatchManager payload = request.payloadManager(); final URI uri = new URI(SERVICE_URI + "/../ESAllPrim(32767)"); final ODataEntityRequest queryReq = client.getRetrieveRequestFactory().getEntityRequest(uri); - queryReq.setFormat(ODataFormat.JSON); + queryReq.setFormat(ContentType.JSON); payload.addRequest(queryReq); // Fetch result @@ -283,7 +282,7 @@ public class BatchClientITCase extends AbstractTestITCase { final BatchManager payload = request.payloadManager(); final URI uri = new URI("http://otherhost/odata/ESAllPrim(32767)"); final ODataEntityRequest queryReq = client.getRetrieveRequestFactory().getEntityRequest(uri); - queryReq.setFormat(ODataFormat.JSON); + queryReq.setFormat(ContentType.JSON); payload.addRequest(queryReq); // Fetch result @@ -298,7 +297,7 @@ public class BatchClientITCase extends AbstractTestITCase { final BatchManager payload = request.payloadManager(); final URI uri = new URI("/ESAllPrim(32767)"); final ODataEntityRequest queryReq = client.getRetrieveRequestFactory().getEntityRequest(uri); - queryReq.setFormat(ODataFormat.JSON); + queryReq.setFormat(ContentType.JSON); payload.addRequest(queryReq); // Fetch result @@ -389,7 +388,7 @@ public class BatchClientITCase extends AbstractTestITCase { // add create request final ODataEntityCreateRequest createReq = client.getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), entityESAllPrim); - createReq.setFormat(ODataFormat.JSON); + createReq.setFormat(ContentType.JSON); changeset.addRequest(createReq); // retrieve request reference @@ -403,7 +402,7 @@ public class BatchClientITCase extends AbstractTestITCase { final ODataEntityUpdateRequest updateReq = client.getCUDRequestFactory().getEntityUpdateRequest( URI.create("$" + createRequestRef), UpdateType.PATCH, entityUpdate); - updateReq.setFormat(ODataFormat.JSON); + updateReq.setFormat(ContentType.JSON); changeset.addRequest(updateReq); @@ -429,7 +428,7 @@ public class BatchClientITCase extends AbstractTestITCase { final ODataEntitySetRequest req = client.getRetrieveRequestFactory().getEntitySetRequest( new URI(createResponse.getHeader(HttpHeader.LOCATION).iterator().next() + "/NavPropertyETTwoPrimMany")); - req.setFormat(ODataFormat.JSON); + req.setFormat(ContentType.JSON); req.addCustomHeader(HttpHeader.COOKIE, cookie); final ODataRetrieveResponse getResponse = req.execute(); @@ -478,7 +477,7 @@ public class BatchClientITCase extends AbstractTestITCase { final ODataEntityCreateRequest createRequest = client.getCUDRequestFactory().getEntityCreateRequest(editLink, postEntity); - createRequest.setFormat(ODataFormat.JSON); + createRequest.setFormat(ContentType.JSON); changeset.addRequest(createRequest); @@ -497,7 +496,7 @@ public class BatchClientITCase extends AbstractTestITCase { ODataEntityUpdateRequest changeReq = client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.PATCH, patchEntity); - changeReq.setFormat(ODataFormat.JSON); + changeReq.setFormat(ContentType.JSON); changeset.addRequest(changeReq); // ------------------------ @@ -518,7 +517,7 @@ public class BatchClientITCase extends AbstractTestITCase { .build())); changeReq = client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.PATCH, patchEntity); - changeReq.setFormat(ODataFormat.JSON); + changeReq.setFormat(ContentType.JSON); changeset.addRequest(changeReq); // ----------------------------- @@ -594,7 +593,7 @@ public class BatchClientITCase extends AbstractTestITCase { final URI uri = (isRelative) ? new URI(SERVICE_URI).relativize(targetURI.build()) : targetURI.build(); ODataEntityRequest queryReq = client.getRetrieveRequestFactory().getEntityRequest(uri); - queryReq.setFormat(ODataFormat.JSON); + queryReq.setFormat(ContentType.JSON); manager.addRequest(queryReq); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java index 48c4a0028..9be4cc8ad 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java @@ -43,7 +43,7 @@ import org.apache.olingo.client.api.domain.ClientValue; import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.fit.AbstractBaseTestITCase; @@ -324,7 +324,7 @@ public class BindingITCase extends AbstractBaseTestITCase { @Test public void testDeepInsertWithBindingSameNavigationProperty() { final EdmEnabledODataClient client = ODataClientFactory.getEdmEnabledClient(SERVICE_URI); - client.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + client.getConfiguration().setDefaultPubFormat(ContentType.JSON); final ClientObjectFactory of = client.getObjectFactory(); final ClientEntity entity = of.newEntity(ET_KEY_NAV); @@ -392,7 +392,7 @@ public class BindingITCase extends AbstractBaseTestITCase { @Override protected ODataClient getClient() { ODataClient odata = ODataClientFactory.getClient(); - odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + odata.getConfiguration().setDefaultPubFormat(ContentType.JSON); return odata; } } diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ConditionalITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ConditionalITCase.java index 9f5efc39e..e5ebd406c 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ConditionalITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ConditionalITCase.java @@ -51,7 +51,7 @@ import org.apache.olingo.client.api.domain.ClientServiceDocument; import org.apache.olingo.client.api.http.HttpClientException; import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.fit.AbstractBaseTestITCase; @@ -251,7 +251,7 @@ public final class ConditionalITCase extends AbstractBaseTestITCase { @Override protected ODataClient getClient() { ODataClient odata = ODataClientFactory.getClient(); - odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + odata.getConfiguration().setDefaultPubFormat(ContentType.JSON); return odata; } } diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java index b4b8efeff..d1b4a8dda 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java @@ -51,7 +51,7 @@ import org.apache.olingo.client.api.domain.ClientValue; import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.fit.AbstractBaseTestITCase; @@ -91,7 +91,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase { @Test public void testDeepInsertExpandedResponse() { final ODataClient client = ODataClientFactory.getEdmEnabledClient(SERVICE_URI); - client.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + client.getConfiguration().setDefaultPubFormat(ContentType.JSON); final URI createURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build(); final ClientObjectFactory of = client.getObjectFactory(); final ClientEntity entity = of.newEntity(ET_KEY_NAV); @@ -900,7 +900,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase { @Override protected ODataClient getClient() { ODataClient odata = ODataClientFactory.getClient(); - odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + odata.getConfiguration().setDefaultPubFormat(ContentType.JSON); return odata; } } diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java index e6c2bcff0..3e3377e35 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java @@ -39,7 +39,7 @@ import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientEntitySet; import org.apache.olingo.client.api.uri.QueryOption; import org.apache.olingo.client.core.ODataClientFactory; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.fit.AbstractBaseTestITCase; @@ -1002,7 +1002,7 @@ public class EntityReferencesITCase extends AbstractBaseTestITCase { @Override protected ODataClient getClient() { final EdmEnabledODataClient client = ODataClientFactory.getEdmEnabledClient(SERVICE_URI); - client.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + client.getConfiguration().setDefaultPubFormat(ContentType.JSON); return client; } diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java index 7516e4df9..75cdecfc6 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java @@ -35,7 +35,7 @@ import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientEntitySet; import org.apache.olingo.client.api.uri.QueryOption; import org.apache.olingo.client.core.ODataClientFactory; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.fit.AbstractBaseTestITCase; @@ -471,7 +471,7 @@ public class ExpandWithSystemQueryOptionsITCase extends AbstractBaseTestITCase { @Override protected ODataClient getClient() { EdmEnabledODataClient odata = ODataClientFactory.getEdmEnabledClient(SERVICE_URI); - odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + odata.getConfiguration().setDefaultPubFormat(ContentType.JSON); return odata; } } diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java index 1e27357b1..8bfd70c4e 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java @@ -34,7 +34,7 @@ import org.apache.olingo.client.api.domain.ClientEntitySet; import org.apache.olingo.client.api.domain.ClientObjectFactory; import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.fit.AbstractBaseTestITCase; @@ -1008,7 +1008,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase { @Override protected ODataClient getClient() { ODataClient odata = ODataClientFactory.getClient(); - odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + odata.getConfiguration().setDefaultPubFormat(ContentType.JSON); return odata; } diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FunctionImportITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FunctionImportITCase.java index 5632bda19..f2ea75e1f 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FunctionImportITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FunctionImportITCase.java @@ -39,7 +39,7 @@ import org.apache.olingo.client.api.domain.ClientPrimitiveValue; import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.domain.ClientValue; import org.apache.olingo.client.core.ODataClientFactory; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.fit.AbstractBaseTestITCase; import org.apache.olingo.fit.tecsvc.TecSvcConst; @@ -223,7 +223,7 @@ public class FunctionImportITCase extends AbstractBaseTestITCase { @Override protected ODataClient getClient() { ODataClient odata = ODataClientFactory.getClient(); - odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + odata.getConfiguration().setDefaultPubFormat(ContentType.JSON); return odata; } } diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/MediaITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/MediaITCase.java index 3bd14c1e4..e5952a18c 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/MediaITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/MediaITCase.java @@ -43,7 +43,6 @@ import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.fit.AbstractBaseTestITCase; @@ -156,7 +155,7 @@ public final class MediaITCase extends AbstractBaseTestITCase { @Override protected ODataClient getClient() { ODataClient odata = ODataClientFactory.getClient(); - odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + odata.getConfiguration().setDefaultPubFormat(ContentType.JSON); return odata; } } diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/NavigationITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/NavigationITCase.java index e20d44ed7..e8147a4ed 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/NavigationITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/NavigationITCase.java @@ -27,7 +27,7 @@ import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientEntitySet; import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.core.ODataClientFactory; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.fit.AbstractBaseTestITCase; import org.apache.olingo.fit.tecsvc.TecSvcConst; @@ -135,7 +135,7 @@ public final class NavigationITCase extends AbstractBaseTestITCase { @Override protected ODataClient getClient() { ODataClient odata = ODataClientFactory.getClient(); - odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + odata.getConfiguration().setDefaultPubFormat(ContentType.JSON); return odata; } } diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/OrderBySystemQueryITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/OrderBySystemQueryITCase.java index aa91ed979..f576afa3c 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/OrderBySystemQueryITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/OrderBySystemQueryITCase.java @@ -30,7 +30,7 @@ import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientEntitySet; import org.apache.olingo.client.api.domain.ClientValuable; import org.apache.olingo.client.core.ODataClientFactory; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.fit.AbstractBaseTestITCase; import org.apache.olingo.fit.tecsvc.TecSvcConst; @@ -164,7 +164,7 @@ public class OrderBySystemQueryITCase extends AbstractBaseTestITCase { @Override protected ODataClient getClient() { ODataClient odata = ODataClientFactory.getClient(); - odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + odata.getConfiguration().setDefaultPubFormat(ContentType.JSON); return odata; } } diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/PrimitiveComplexITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/PrimitiveComplexITCase.java index 1dbd0e616..855096945 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/PrimitiveComplexITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/PrimitiveComplexITCase.java @@ -50,7 +50,6 @@ import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.domain.ClientValue; import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.fit.AbstractBaseTestITCase; @@ -405,7 +404,7 @@ public class PrimitiveComplexITCase extends AbstractBaseTestITCase { @Override protected ODataClient getClient() { ODataClient odata = ODataClientFactory.getClient(); - odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + odata.getConfiguration().setDefaultPubFormat(ContentType.JSON); return odata; } } diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java index bbd9d51f6..a117d0864 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java @@ -29,7 +29,7 @@ import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientEntitySet; import org.apache.olingo.client.core.ODataClientFactory; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.fit.AbstractBaseTestITCase; import org.apache.olingo.fit.tecsvc.TecSvcConst; @@ -296,7 +296,7 @@ public class SystemQueryOptionITCase extends AbstractBaseTestITCase { @Override protected ODataClient getClient() { ODataClient odata = ODataClientFactory.getClient(); - odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + odata.getConfiguration().setDefaultPubFormat(ContentType .JSON); return odata; } } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java index 5339bffee..6f1645002 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java @@ -46,7 +46,6 @@ import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.fit.AbstractBaseTestITCase; import org.junit.BeforeClass; @@ -97,23 +96,23 @@ public abstract class AbstractTestITCase extends AbstractBaseTestITCase { return client; } - protected ClientEntity read(final ODataFormat format, final URI editLink) { + protected ClientEntity read(final ContentType contentType, final URI editLink) { final ODataEntityRequest req = getClient().getRetrieveRequestFactory().getEntityRequest(editLink); - req.setFormat(format); + req.setFormat(contentType); final ODataRetrieveResponse res = req.execute(); final ClientEntity entity = res.getBody(); assertNotNull(entity); - if (ODataFormat.JSON_FULL_METADATA == format || ODataFormat.ATOM == format) { + if (ContentType.JSON_FULL_METADATA == contentType || ContentType.APPLICATION_ATOM_XML == contentType) { assertEquals(req.getURI(), entity.getEditLink()); } return entity; } - protected void createAndDeleteOrder(final String serviceRoot, final ODataFormat format, final int id) { + protected void createAndDeleteOrder(final String serviceRoot, final ContentType contentType, final int id) { final ClientEntity order = getClient().getObjectFactory().newEntity( new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Order")); @@ -147,19 +146,19 @@ public abstract class AbstractTestITCase extends AbstractBaseTestITCase { final ODataEntityCreateRequest req = getClient().getCUDRequestFactory().getEntityCreateRequest( getClient().newURIBuilder(serviceRoot). appendEntitySetSegment("Orders").build(), order); - req.setFormat(format); + req.setFormat(contentType); final ClientEntity created = req.execute().getBody(); assertNotNull(created); assertEquals(2, created.getProperty("OrderShelfLifes").getCollectionValue().size()); - if (format == ODataFormat.JSON_NO_METADATA) { + if (contentType.equals(ContentType.JSON_NO_METADATA)) { assertEquals(0, created.getNavigationLinks().size()); assertNull(created.getEditLink()); - } else if (format == ODataFormat.JSON_FULL_METADATA) { + } else if (contentType.equals(ContentType.JSON_FULL_METADATA)) { assertEquals(3, created.getNavigationLinks().size()); assertThat(created.getTypeName().getNamespace(), is("Microsoft.Test.OData.Services.ODataWCFService")); assertThat(created.getEditLink().toASCIIString(), startsWith("http://localhost:9080/stub/StaticService")); - } else if (format == ODataFormat.JSON || format == ODataFormat.APPLICATION_JSON) { + } else if (contentType.equals(ContentType.JSON) || contentType.equals(ContentType.APPLICATION_JSON)) { assertEquals(0, created.getNavigationLinks().size()); assertNull(created.getEditLink()); } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/AsyncTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/AsyncTestITCase.java index ded0d97d9..a9436b1ff 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/AsyncTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/AsyncTestITCase.java @@ -39,7 +39,7 @@ import org.apache.olingo.client.api.domain.ClientInlineEntity; import org.apache.olingo.client.api.domain.ClientLink; import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.uri.URIBuilder; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; public class AsyncTestITCase extends AbstractTestITCase { @@ -62,13 +62,13 @@ public class AsyncTestITCase extends AbstractTestITCase { assertFalse(res.getBody().getEntities().isEmpty()); } - private void withInlineEntry(final ODataFormat format) { + private void withInlineEntry(final ContentType contentType) { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Customers").appendKeySegment(1).expand("Company"); final ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()); - req.setFormat(format); + req.setFormat(contentType); final AsyncRequestWrapper> async = client.getAsyncRequestFactory().> getAsyncRequestWrapper(req); @@ -86,7 +86,7 @@ public class AsyncTestITCase extends AbstractTestITCase { assertEquals(3, entity.getNavigationLinks().size()); - if (ODataFormat.ATOM == format) { + if (ContentType.APPLICATION_ATOM_XML.equals(contentType)) { assertTrue(entity.getAssociationLinks().isEmpty()); // In JSON, association links for each $ref link will exist. } @@ -121,22 +121,22 @@ public class AsyncTestITCase extends AbstractTestITCase { @Test public void withInlineEntryAsAtom() { - withInlineEntry(ODataFormat.ATOM); + withInlineEntry(ContentType.APPLICATION_ATOM_XML); } @Test public void withInlineEntryAsJSON() { // this needs to be full, otherwise there is no mean to recognize links - withInlineEntry(ODataFormat.JSON_FULL_METADATA); + withInlineEntry(ContentType.JSON_FULL_METADATA); } - private void asyncOrders(final ODataFormat format) { + private void asyncOrders(final ContentType contentType) { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("async").appendEntitySetSegment("Orders"); final ODataEntitySetRequest req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build()); - req.setFormat(format); + req.setFormat(contentType); final AsyncRequestWrapper> async = client.getAsyncRequestFactory().> getAsyncRequestWrapper(req); @@ -155,11 +155,11 @@ public class AsyncTestITCase extends AbstractTestITCase { @Test public void asyncOrdersAsAtom() { - asyncOrders(ODataFormat.ATOM); + asyncOrders(ContentType.APPLICATION_ATOM_XML); } @Test public void asyncOrdersAsJSON() { - asyncOrders(ODataFormat.JSON); + asyncOrders(ContentType.JSON); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/AuthBatchTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/AuthBatchTestITCase.java index 47d50c053..123dcd91c 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/AuthBatchTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/AuthBatchTestITCase.java @@ -39,7 +39,6 @@ import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; import org.junit.Test; public class AuthBatchTestITCase extends AbstractTestITCase { @@ -84,7 +83,7 @@ public class AuthBatchTestITCase extends AbstractTestITCase { // create new request ODataEntityRequest queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build()); - queryReq.setFormat(ODataFormat.JSON); + queryReq.setFormat(ContentType.JSON); streamManager.addRequest(queryReq); // ------------------------------------------- @@ -108,7 +107,7 @@ public class AuthBatchTestITCase extends AbstractTestITCase { final ODataEntityUpdateRequest changeReq = client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.PATCH, patch); - changeReq.setFormat(ODataFormat.JSON_FULL_METADATA); + changeReq.setFormat(ContentType.JSON_FULL_METADATA); changeset.addRequest(changeReq); // ------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/BatchTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/BatchTestITCase.java index 50a62603c..d039ab272 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/BatchTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/BatchTestITCase.java @@ -67,7 +67,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; import org.junit.Test; public class BatchTestITCase extends AbstractTestITCase { @@ -128,20 +127,20 @@ public class BatchTestITCase extends AbstractTestITCase { for (int i = 1; i <= 2; i++) { // Create Customer into the changeset createReq = client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), newOrder(100 + i)); - createReq.setFormat(ODataFormat.JSON); + createReq.setFormat(ContentType.JSON); changeset.addRequest(createReq); } targetURI = client.newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("WrongEntitySet"); createReq = client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), newOrder(105)); - createReq.setFormat(ODataFormat.JSON); + createReq.setFormat(ContentType.JSON); changeset.addRequest(createReq); targetURI = client.newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders"); for (int i = 3; i <= 4; i++) { // Create Customer into the changeset createReq = client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), newOrder(100 + i)); - createReq.setFormat(ODataFormat.JSON); + createReq.setFormat(ContentType.JSON); changeset.addRequest(createReq); } @@ -193,7 +192,7 @@ public class BatchTestITCase extends AbstractTestITCase { // create new request ODataEntityRequest queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build()); - queryReq.setFormat(ODataFormat.JSON); + queryReq.setFormat(ContentType.JSON); streamManager.addRequest(queryReq); // ------------------------------------------- @@ -340,7 +339,7 @@ public class BatchTestITCase extends AbstractTestITCase { // create new request ODataEntityRequest queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build()); - queryReq.setFormat(ODataFormat.JSON); + queryReq.setFormat(ContentType.JSON); streamManager.addRequest(queryReq); // ------------------------------------------- @@ -353,7 +352,7 @@ public class BatchTestITCase extends AbstractTestITCase { final ClientEntity original = newOrder(2000); final ODataEntityCreateRequest createReq = client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), original); - createReq.setFormat(ODataFormat.JSON); + createReq.setFormat(ContentType.JSON); streamManager.addRequest(createReq); // ------------------------------------------- @@ -407,7 +406,7 @@ public class BatchTestITCase extends AbstractTestITCase { // create new request ODataEntityRequest queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build()); - queryReq.setFormat(ODataFormat.JSON); + queryReq.setFormat(ContentType.JSON); streamManager.addRequest(queryReq); // ------------------------------------------- @@ -431,7 +430,7 @@ public class BatchTestITCase extends AbstractTestITCase { final ODataEntityUpdateRequest changeReq = client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.PATCH, patch); - changeReq.setFormat(ODataFormat.JSON_FULL_METADATA); + changeReq.setFormat(ContentType.JSON_FULL_METADATA); changeset.addRequest(changeReq); @@ -440,7 +439,7 @@ public class BatchTestITCase extends AbstractTestITCase { final ClientEntity original = newOrder(1000); final ODataEntityCreateRequest createReq = client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), original); - createReq.setFormat(ODataFormat.JSON); + createReq.setFormat(ContentType.JSON); changeset.addRequest(createReq); // ------------------------------------------- @@ -531,7 +530,7 @@ public class BatchTestITCase extends AbstractTestITCase { // create new request ODataEntityRequest queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build()); - queryReq.setFormat(ODataFormat.JSON); + queryReq.setFormat(ContentType.JSON); async.addRetrieve(queryReq); // ------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java index 890b8787c..9782ff0d8 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java @@ -45,17 +45,17 @@ import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; public class BoundOperationInvokeTestITCase extends AbstractTestITCase { - private void functions(final ODataFormat format) throws EdmPrimitiveTypeException { + private void functions(final ContentType contentType) throws EdmPrimitiveTypeException { // GetEmployeesCount URIBuilder builder = client.newURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company"); final ODataEntityRequest singletonReq = client.getRetrieveRequestFactory().getSingletonRequest(builder.build()); - singletonReq.setFormat(format); + singletonReq.setFormat(contentType); final ClientSingleton company = singletonReq.execute().getBody(); assertNotNull(company); @@ -64,7 +64,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { final ODataInvokeRequest getEmployeesCountReq = client.getInvokeRequestFactory().getFunctionInvokeRequest(boundOp.getTarget(), ClientProperty.class); - getEmployeesCountReq.setFormat(format); + getEmployeesCountReq.setFormat(contentType); final ClientProperty getEmployeesCountRes = getEmployeesCountReq.execute().getBody(); assertNotNull(getEmployeesCountRes); assertTrue(getEmployeesCountRes.hasPrimitiveValue()); @@ -74,7 +74,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { appendEntitySetSegment("Products").appendKeySegment(5); ODataEntityRequest entityReq = client.getRetrieveRequestFactory(). getEntityRequest(builder.build()); - entityReq.setFormat(format); + entityReq.setFormat(contentType); ClientEntity entity = entityReq.execute().getBody(); assertNotNull(entity); @@ -85,7 +85,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { final ODataInvokeRequest getProductDetailsReq = client.getInvokeRequestFactory().getFunctionInvokeRequest(boundOp.getTarget(), ClientEntitySet.class, Collections. singletonMap("count", count)); - getProductDetailsReq.setFormat(format); + getProductDetailsReq.setFormat(contentType); final ClientEntitySet getProductDetailsRes = getProductDetailsReq.execute().getBody(); assertNotNull(getProductDetailsRes); assertEquals(1, getProductDetailsRes.getEntities().size()); @@ -97,7 +97,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { builder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("ProductDetails").appendKeySegment(keyMap); entityReq = client.getRetrieveRequestFactory().getEntityRequest(builder.build()); - entityReq.setFormat(format); + entityReq.setFormat(contentType); entity = entityReq.execute().getBody(); assertNotNull(entity); @@ -106,7 +106,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { final ODataInvokeRequest getRelatedProductReq = client.getInvokeRequestFactory().getFunctionInvokeRequest(boundOp.getTarget(), ClientEntity.class); - getRelatedProductReq.setFormat(format); + getRelatedProductReq.setFormat(contentType); final ClientEntity getRelatedProductRes = getRelatedProductReq.execute().getBody(); assertNotNull(getRelatedProductRes); assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Product", @@ -117,7 +117,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { builder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Accounts").appendKeySegment(102); entityReq = client.getRetrieveRequestFactory().getEntityRequest(builder.build()); - entityReq.setFormat(format); + entityReq.setFormat(contentType); entity = entityReq.execute().getBody(); assertNotNull(entity); @@ -126,7 +126,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { final ODataInvokeRequest getDefaultPIReq = client.getInvokeRequestFactory().getFunctionInvokeRequest(boundOp.getTarget(), ClientEntity.class); - getDefaultPIReq.setFormat(format); + getDefaultPIReq.setFormat(contentType); final ClientEntity getDefaultPIRes = getDefaultPIReq.execute().getBody(); assertNotNull(getDefaultPIRes); assertEquals("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument", @@ -140,7 +140,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { final ODataInvokeRequest getAccountInfoReq = client.getInvokeRequestFactory().getFunctionInvokeRequest(boundOp.getTarget(), ClientProperty.class); - getAccountInfoReq.setFormat(format); + getAccountInfoReq.setFormat(contentType); final ClientProperty getAccountInfoRes = getAccountInfoReq.execute().getBody(); assertNotNull(getAccountInfoRes); assertTrue(getAccountInfoRes.hasComplexValue()); @@ -150,7 +150,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { // GetActualAmount entityReq = client.getRetrieveRequestFactory().getEntityRequest( entity.getNavigationLink("MyGiftCard").getLink()); - entityReq.setFormat(format); + entityReq.setFormat(contentType); entity = entityReq.execute().getBody(); assertNotNull(entity); assertEquals(301, entity.getProperty("GiftCardID").getPrimitiveValue().toCastValue(Integer.class), 0); @@ -162,7 +162,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { final ODataInvokeRequest getActualAmountReq = client.getInvokeRequestFactory().getFunctionInvokeRequest(boundOp.getTarget(), ClientProperty.class, Collections. singletonMap("bonusRate", bonusRate)); - getActualAmountReq.setFormat(format); + getActualAmountReq.setFormat(contentType); final ClientProperty getActualAmountRes = getActualAmountReq.execute().getBody(); assertNotNull(getActualAmountRes); assertEquals(41.79, getActualAmountRes.getPrimitiveValue().toCastValue(Double.class), 0); @@ -170,12 +170,12 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { @Test public void atomFunctions() throws EdmPrimitiveTypeException { - functions(ODataFormat.ATOM); + functions(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonFunctions() throws EdmPrimitiveTypeException { - functions(ODataFormat.JSON_FULL_METADATA); + functions(ContentType.JSON_FULL_METADATA); } @Test @@ -264,12 +264,12 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { assertEquals(41.79, getActualAmountRes.getPrimitiveValue().toCastValue(Double.class), 0); } - private void actions(final ODataFormat format) throws EdmPrimitiveTypeException { + private void actions(final ContentType contentType) throws EdmPrimitiveTypeException { // IncreaseRevenue URIBuilder builder = client.newURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company"); ODataEntityRequest entityReq = client.getRetrieveRequestFactory().getEntityRequest(builder.build()); - entityReq.setFormat(format); + entityReq.setFormat(contentType); ClientEntity entity = entityReq.execute().getBody(); assertNotNull(entity); @@ -281,7 +281,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { final ODataInvokeRequest increaseRevenueReq = client.getInvokeRequestFactory().getActionInvokeRequest(boundOp.getTarget(), ClientProperty.class, Collections. singletonMap("IncreaseValue", increaseValue)); - increaseRevenueReq.setFormat(format); + increaseRevenueReq.setFormat(contentType); final ClientProperty increaseRevenueRes = increaseRevenueReq.execute().getBody(); assertNotNull(increaseRevenueRes); assertTrue(increaseRevenueRes.hasPrimitiveValue()); @@ -290,7 +290,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { builder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Products").appendKeySegment(5); entityReq = client.getRetrieveRequestFactory().getEntityRequest(builder.build()); - entityReq.setFormat(format); + entityReq.setFormat(contentType); entity = entityReq.execute().getBody(); assertNotNull(entity); @@ -302,7 +302,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { final ODataInvokeRequest getProductDetailsReq = client.getInvokeRequestFactory().getActionInvokeRequest(boundOp.getTarget(), ClientProperty.class, Collections. singletonMap("accessRight", accessRight)); - getProductDetailsReq.setFormat(format); + getProductDetailsReq.setFormat(contentType); final ClientProperty getProductDetailsRes = getProductDetailsReq.execute().getBody(); assertNotNull(getProductDetailsRes); assertTrue(getProductDetailsRes.hasEnumValue()); @@ -311,7 +311,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { builder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Customers").appendKeySegment(2); entityReq = client.getRetrieveRequestFactory().getEntityRequest(builder.build()); - entityReq.setFormat(format); + entityReq.setFormat(contentType); entity = entityReq.execute().getBody(); assertNotNull(entity); @@ -336,7 +336,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { params.put("index", index); final ODataInvokeRequest resetAddressReq = client.getInvokeRequestFactory().getActionInvokeRequest(boundOp.getTarget(), ClientEntity.class, params); - resetAddressReq.setFormat(format); + resetAddressReq.setFormat(contentType); final ClientEntity resetAddressRes = resetAddressReq.execute().getBody(); assertNotNull(resetAddressRes); assertEquals(2, resetAddressRes.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class), 0); @@ -345,7 +345,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { builder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Accounts").appendKeySegment(102); entityReq = client.getRetrieveRequestFactory().getEntityRequest(builder.build()); - entityReq.setFormat(format); + entityReq.setFormat(contentType); entity = entityReq.execute().getBody(); assertNotNull(entity); @@ -359,7 +359,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { final ODataInvokeRequest getDefaultPIReq = client.getInvokeRequestFactory().getActionInvokeRequest(boundOp.getTarget(), ClientEntity.class, Collections. singletonMap("newDate", newDate)); - getDefaultPIReq.setFormat(format); + getDefaultPIReq.setFormat(contentType); final ClientEntity getDefaultPIRes = getDefaultPIReq.execute().getBody(); assertNotNull(getDefaultPIRes); assertEquals("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument", @@ -370,12 +370,12 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { @Test public void atomActions() throws EdmPrimitiveTypeException { - actions(ODataFormat.ATOM); + actions(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonActions() throws EdmPrimitiveTypeException { - actions(ODataFormat.JSON_FULL_METADATA); + actions(ContentType.JSON_FULL_METADATA); } @Test diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/ConformanceTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/ConformanceTestITCase.java index 472928f97..2e9fe5ae3 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/ConformanceTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/ConformanceTestITCase.java @@ -54,7 +54,7 @@ import org.apache.olingo.client.core.http.DefaultHttpClientFactory; import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; /** @@ -118,7 +118,7 @@ public class ConformanceTestITCase extends AbstractTestITCase { final ODataEntityCreateRequest req = getClient().getCUDRequestFactory().getEntityCreateRequest( getClient().newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Orders").build(), order); - req.setFormat(ODataFormat.JSON_FULL_METADATA); + req.setFormat(ContentType.JSON_FULL_METADATA); // check for OData-Version assertEquals("4.0", req.getHeader("OData-Version")); @@ -126,13 +126,13 @@ public class ConformanceTestITCase extends AbstractTestITCase { // check for Content-Type assertEquals( - ODataFormat.JSON_FULL_METADATA.getContentType().toContentTypeString(), + ContentType.JSON_FULL_METADATA.toContentTypeString(), req.getHeader("Content-Type")); assertEquals( - ODataFormat.JSON_FULL_METADATA.getContentType().toContentTypeString(), + ContentType.JSON_FULL_METADATA.toContentTypeString(), req.getHeader(HeaderName.contentType.toString())); assertEquals( - ODataFormat.JSON_FULL_METADATA.getContentType().toContentTypeString(), + ContentType.JSON_FULL_METADATA.toContentTypeString(), req.getContentType()); final ClientEntity created = req.execute().getBody(); @@ -179,7 +179,7 @@ public class ConformanceTestITCase extends AbstractTestITCase { ODataEntitySetRequest req = client.getRetrieveRequestFactory(). getEntitySetRequest(uriBuilder.build()); - req.setFormat(ODataFormat.JSON_FULL_METADATA); + req.setFormat(ContentType.JSON_FULL_METADATA); req.setPrefer(client.newPreferences().maxPageSize(5)); ODataRetrieveResponse res = req.execute(); @@ -196,7 +196,7 @@ public class ConformanceTestITCase extends AbstractTestITCase { assertEquals(expected, found); req = client.getRetrieveRequestFactory().getEntitySetRequest(found); - req.setFormat(ODataFormat.JSON_FULL_METADATA); + req.setFormat(ContentType.JSON_FULL_METADATA); res = req.execute(); feed = res.getBody(); @@ -236,7 +236,7 @@ public class ConformanceTestITCase extends AbstractTestITCase { final URIBuilder builder = getClient().newURIBuilder(testOpenTypeServiceRootURL). appendEntitySetSegment("RowIndex").appendKeySegment(id); - rowIndex = read(ODataFormat.JSON_FULL_METADATA, builder.build()); + rowIndex = read(ContentType.JSON_FULL_METADATA, builder.build()); assertNotNull(rowIndex); assertEquals(EdmPrimitiveTypeKind.Int32, rowIndex.getProperty("Id").getPrimitiveValue().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.String, rowIndex.getProperty("aString").getPrimitiveValue().getTypeKind()); @@ -269,7 +269,7 @@ public class ConformanceTestITCase extends AbstractTestITCase { final ODataEntityUpdateResponse res = req.execute(); assertEquals(204, res.getStatusCode()); - final ClientEntity actual = read(ODataFormat.JSON, uri); + final ClientEntity actual = read(ContentType.JSON, uri); assertEquals(newname, actual.getProperty("FirstName").getPrimitiveValue().toString()); } @@ -288,7 +288,7 @@ public class ConformanceTestITCase extends AbstractTestITCase { final ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()); - req.setFormat(ODataFormat.JSON_FULL_METADATA); + req.setFormat(ContentType.JSON_FULL_METADATA); assertNotNull(req.execute().getBody()); @@ -305,7 +305,7 @@ public class ConformanceTestITCase extends AbstractTestITCase { appendRefSegment(); ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()); - req.setFormat(ODataFormat.JSON_FULL_METADATA); + req.setFormat(ContentType.JSON_FULL_METADATA); ODataRetrieveResponse res = req.execute(); assertNotNull(res); @@ -318,7 +318,7 @@ public class ConformanceTestITCase extends AbstractTestITCase { appendEntityIdSegment(entity.getId().toASCIIString()).build(); req = client.getRetrieveRequestFactory().getEntityRequest(referenceURI); - req.setFormat(ODataFormat.JSON_FULL_METADATA); + req.setFormat(ContentType.JSON_FULL_METADATA); res = req.execute(); assertNotNull(res); @@ -339,7 +339,7 @@ public class ConformanceTestITCase extends AbstractTestITCase { assertNotNull(customers.getDeltaLink()); final ODataDeltaRequest deltaReq = client.getRetrieveRequestFactory().getDeltaRequest(customers.getDeltaLink()); - deltaReq.setFormat(ODataFormat.JSON_FULL_METADATA); + deltaReq.setFormat(ContentType.JSON_FULL_METADATA); final ClientDelta delta = deltaReq.execute().getBody(); assertNotNull(delta); @@ -381,7 +381,7 @@ public class ConformanceTestITCase extends AbstractTestITCase { final ODataEntitySetRequest req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build()); - req.setFormat(ODataFormat.JSON_FULL_METADATA); + req.setFormat(ContentType.JSON_FULL_METADATA); final AsyncRequestWrapper> async = client.getAsyncRequestFactory().> getAsyncRequestWrapper(req); @@ -408,7 +408,7 @@ public class ConformanceTestITCase extends AbstractTestITCase { final ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()); - req.setFormat(ODataFormat.JSON); + req.setFormat(ContentType.JSON); assertEquals("application/json;odata.metadata=minimal", req.getHeader("Accept")); assertEquals("application/json;odata.metadata=minimal", req.getHeader(HeaderName.accept.toString())); diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/DeltaTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/DeltaTestITCase.java index 1d021418f..dc2c24663 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/DeltaTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/DeltaTestITCase.java @@ -27,12 +27,12 @@ import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySe import org.apache.olingo.client.api.domain.ClientDelta; import org.apache.olingo.client.api.domain.ClientEntitySet; import org.apache.olingo.client.api.domain.ClientProperty; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; public class DeltaTestITCase extends AbstractTestITCase { - private void parse(final ODataFormat format) { + private void parse(final ContentType format) { final ODataEntitySetRequest req = client.getRetrieveRequestFactory().getEntitySetRequest( client.newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customers").build()); req.setPrefer(client.newPreferences().trackChanges()); @@ -76,11 +76,11 @@ public class DeltaTestITCase extends AbstractTestITCase { @Test public void atomParse() { - parse(ODataFormat.ATOM); + parse(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonParse() { - parse(ODataFormat.JSON); + parse(ContentType.JSON); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/DerivedTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/DerivedTypeTestITCase.java index 401f6e8e1..47e71e0d7 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/DerivedTypeTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/DerivedTypeTestITCase.java @@ -36,19 +36,19 @@ import org.apache.olingo.client.api.domain.ClientValuable; import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; public class DerivedTypeTestITCase extends AbstractTestITCase { - private void read(final ODataFormat format) { + private void read(final ContentType contentType) { // 1. entity set URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("People"). appendDerivedEntityTypeSegment("Microsoft.Test.OData.Services.ODataWCFService.Customer"); ODataEntitySetRequest req = client.getRetrieveRequestFactory(). getEntitySetRequest(uriBuilder.build()); - req.setFormat(format); + req.setFormat(contentType); for (ClientEntity customer : req.execute().getBody().getEntities()) { assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", customer.getTypeName().toString()); @@ -60,7 +60,7 @@ public class DerivedTypeTestITCase extends AbstractTestITCase { appendNavigationSegment("MyPaymentInstruments"). appendDerivedEntityTypeSegment("Microsoft.Test.OData.Services.ODataWCFService.CreditCardPI"); req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build()); - req.setFormat(format); + req.setFormat(contentType); for (ClientEntity customer : req.execute().getBody().getEntities()) { assertEquals("Microsoft.Test.OData.Services.ODataWCFService.CreditCardPI", customer.getTypeName().toString()); @@ -69,15 +69,15 @@ public class DerivedTypeTestITCase extends AbstractTestITCase { @Test public void readfromAtom() { - read(ODataFormat.ATOM); + read(ContentType.APPLICATION_ATOM_XML); } @Test public void readfromJSON() { - read(ODataFormat.JSON_FULL_METADATA); + read(ContentType.JSON_FULL_METADATA); } - private void createDelete(final ODataFormat format) { + private void createDelete(final ContentType conentType) { final ClientEntity customer = client.getObjectFactory(). newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Customer")); @@ -119,7 +119,7 @@ public class DerivedTypeTestITCase extends AbstractTestITCase { getEntityCreateRequest( client.newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("People").build(), customer); - createReq.setFormat(format); + createReq.setFormat(conentType); final ODataEntityCreateResponse createRes = createReq.execute(); assertEquals(201, createRes.getStatusCode()); @@ -127,7 +127,7 @@ public class DerivedTypeTestITCase extends AbstractTestITCase { final ODataEntityRequest fetchReq = client.getRetrieveRequestFactory(). getEntityRequest(client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("People").appendKeySegment(976).build()); - fetchReq.setFormat(format); + fetchReq.setFormat(conentType); final ClientEntity actual = fetchReq.execute().getBody(); assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", actual.getTypeName().toString()); @@ -140,11 +140,11 @@ public class DerivedTypeTestITCase extends AbstractTestITCase { @Test public void createDeleteAsAtom() { - createDelete(ODataFormat.ATOM); + createDelete(ContentType.APPLICATION_ATOM_XML); } @Test public void createDeleteAsJSON() { - createDelete(ODataFormat.JSON_FULL_METADATA); + createDelete(ContentType.JSON_FULL_METADATA); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/EntityCreateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/EntityCreateTestITCase.java index 796649523..781396663 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/EntityCreateTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/EntityCreateTestITCase.java @@ -35,24 +35,24 @@ import org.apache.olingo.client.api.domain.ClientLink; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; public class EntityCreateTestITCase extends AbstractTestITCase { @Test public void atomCreateAndDelete() { - createAndDeleteOrder(testStaticServiceRootURL, ODataFormat.ATOM, 1000); + createAndDeleteOrder(testStaticServiceRootURL, ContentType.APPLICATION_ATOM_XML, 1000); } @Test public void jsonCreateAndDelete() { - createAndDeleteOrder(testStaticServiceRootURL, ODataFormat.JSON, 1001); - createAndDeleteOrder(testStaticServiceRootURL, ODataFormat.JSON_NO_METADATA, 1001); - createAndDeleteOrder(testStaticServiceRootURL, ODataFormat.JSON_FULL_METADATA, 1001); + createAndDeleteOrder(testStaticServiceRootURL, ContentType.JSON, 1001); + createAndDeleteOrder(testStaticServiceRootURL, ContentType.JSON_NO_METADATA, 1001); + createAndDeleteOrder(testStaticServiceRootURL, ContentType.JSON_FULL_METADATA, 1001); } - private void onContained(final ODataFormat format) { + private void onContained(final ContentType contentType) { final URI uri = getClient().newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Accounts"). appendKeySegment(101).appendNavigationSegment("MyPaymentInstruments").build(); @@ -77,7 +77,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase { // 3. create it as contained entity final ODataEntityCreateRequest req = getClient().getCUDRequestFactory(). getEntityCreateRequest(uri, instrument); - req.setFormat(format); + req.setFormat(contentType); final ODataEntityCreateResponse res = req.execute(); assertEquals(201, res.getStatusCode()); @@ -102,15 +102,15 @@ public class EntityCreateTestITCase extends AbstractTestITCase { @Test public void atomOnContained() { - onContained(ODataFormat.ATOM); + onContained(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonOnContained() { - onContained(ODataFormat.JSON); + onContained(ContentType.JSON); } - private void deepInsert(final ODataFormat format, final int productId, final int productDetailId) + private void deepInsert(final ContentType contentType, final int productId, final int productDetailId) throws EdmPrimitiveTypeException { final ClientEntity product = getClient().getObjectFactory(). @@ -161,7 +161,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase { final ODataEntityCreateRequest req = getClient().getCUDRequestFactory().getEntityCreateRequest( getClient().newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Products").build(), product); - req.setFormat(format); + req.setFormat(contentType); final ODataEntityCreateResponse res = req.execute(); assertEquals(201, res.getStatusCode()); @@ -181,11 +181,11 @@ public class EntityCreateTestITCase extends AbstractTestITCase { @Test public void atomDeepInsert() throws EdmPrimitiveTypeException { - deepInsert(ODataFormat.ATOM, 10, 10); + deepInsert(ContentType.APPLICATION_ATOM_XML, 10, 10); } @Test public void jsonDeepInsert() throws EdmPrimitiveTypeException { - deepInsert(ODataFormat.JSON_FULL_METADATA, 11, 11); + deepInsert(ContentType.JSON_FULL_METADATA, 11, 11); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/EntityRetrieveTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/EntityRetrieveTestITCase.java index 91461dbf4..903684db1 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/EntityRetrieveTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/EntityRetrieveTestITCase.java @@ -45,7 +45,8 @@ import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; +import org.apache.olingo.commons.api.format.Format; import org.junit.Test; /** @@ -53,13 +54,13 @@ import org.junit.Test; */ public class EntityRetrieveTestITCase extends AbstractTestITCase { - private void withInlineEntity(final ODataClient client, final ODataFormat format) { + private void withInlineEntity(final ODataClient client, final ContentType contentType) { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Customers").appendKeySegment(1).expand("Company"); final ODataEntityRequest req = client.getRetrieveRequestFactory(). getEntityRequest(uriBuilder.build()); - req.setFormat(format); + req.setFormat(contentType); final ODataRetrieveResponse res = req.execute(); final ClientEntity entity = res.getBody(); @@ -70,11 +71,12 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { assertEquals("Edm.GeographyPoint", entity.getProperty("Home").getPrimitiveValue().getTypeName()); // In JSON with minimal metadata, links are not provided - if (format == ODataFormat.ATOM || format == ODataFormat.JSON_FULL_METADATA) { + if (contentType.getODataFormat() == Format.ATOM + || contentType.getODataFormat() == Format.JSON_FULL_METADATA) { assertEquals(testStaticServiceRootURL + "/Customers(1)", entity.getEditLink().toASCIIString()); assertEquals(3, entity.getNavigationLinks().size()); - if (ODataFormat.ATOM == format) { + if (ContentType.APPLICATION_ATOM_XML == contentType) { assertTrue(entity.getAssociationLinks().isEmpty()); // In JSON, association links for each $ref link will exist. } @@ -110,26 +112,26 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { @Test public void withInlineEntityFromAtom() { - withInlineEntity(client, ODataFormat.ATOM); + withInlineEntity(client, ContentType.APPLICATION_ATOM_XML); } @Test public void withInlineEntityFromFullJSON() { - withInlineEntity(client, ODataFormat.JSON_FULL_METADATA); + withInlineEntity(client, ContentType.JSON_FULL_METADATA); } @Test public void withInlineEntityFromJSON() { - withInlineEntity(edmClient, ODataFormat.JSON); + withInlineEntity(edmClient, ContentType.JSON); } - private void withInlineEntitySet(final ODataClient client, final ODataFormat format) { + private void withInlineEntitySet(final ODataClient client, final ContentType contentType) { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Customers").appendKeySegment(1).expand("Orders"); final ODataEntityRequest req = client.getRetrieveRequestFactory(). getEntityRequest(uriBuilder.build()); - req.setFormat(format); + req.setFormat(contentType); final ODataRetrieveResponse res = req.execute(); final ClientEntity entity = res.getBody(); @@ -137,7 +139,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString()); // In JSON with minimal metadata, links are not provided - if (format == ODataFormat.ATOM || format == ODataFormat.JSON_FULL_METADATA) { + if (contentType.equals(ContentType.APPLICATION_ATOM_XML) || contentType.equals(ContentType.JSON_FULL_METADATA)) { boolean found = false; for (ClientLink link : entity.getNavigationLinks()) { if (link instanceof ClientInlineEntitySet) { @@ -153,25 +155,25 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { @Test public void withInlineEntitySetFromAtom() { - withInlineEntitySet(client, ODataFormat.ATOM); + withInlineEntitySet(client, ContentType.APPLICATION_ATOM_XML); } @Test public void withInlineEntitySetFromFullJSON() { - withInlineEntitySet(client, ODataFormat.JSON_FULL_METADATA); + withInlineEntitySet(client, ContentType.JSON_FULL_METADATA); } @Test public void withInlineEntitySetFromJSON() { - withInlineEntitySet(edmClient, ODataFormat.JSON); + withInlineEntitySet(edmClient, ContentType.JSON); } - private void rawRequest(final ODataFormat format) { + private void rawRequest(final ContentType contentType) { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("People").appendKeySegment(5); final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build()); - req.setFormat(format.getContentType().toContentTypeString()); + req.setFormat(contentType.toContentTypeString()); final ODataRawResponse res = req.execute(); assertNotNull(res); @@ -185,16 +187,16 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { @Test public void rawRequestAsAtom() { - rawRequest(ODataFormat.ATOM); + rawRequest(ContentType.APPLICATION_ATOM_XML); } @Test public void rawRequestAsJSON() { // this needs to be full, otherwise reference will not be provided - rawRequest(ODataFormat.JSON_FULL_METADATA); + rawRequest(ContentType.JSON_FULL_METADATA); } - private void multiKey(final ODataFormat format) throws EdmPrimitiveTypeException { + private void multiKey(final ContentType contentType) throws EdmPrimitiveTypeException { final LinkedHashMap multiKey = new LinkedHashMap(); multiKey.put("ProductID", "6"); multiKey.put("ProductDetailID", 1); @@ -204,7 +206,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { final ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()); - req.setFormat(format); + req.setFormat(contentType); final ODataRetrieveResponse res = req.execute(); final ClientEntity entity = res.getBody(); @@ -215,21 +217,21 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { @Test public void multiKeyAsAtom() throws EdmPrimitiveTypeException { - multiKey(ODataFormat.ATOM); + multiKey(ContentType.APPLICATION_ATOM_XML); } @Test public void multiKeyAsJSON() throws EdmPrimitiveTypeException { - multiKey(ODataFormat.JSON_FULL_METADATA); + multiKey(ContentType.JSON_FULL_METADATA); } - private void checkForETag(final ODataClient client, final ODataFormat format) { + private void checkForETag(final ODataClient client, final ContentType contentType) { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders").appendKeySegment(8); final ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()); - req.setFormat(format); + req.setFormat(contentType); final ODataRetrieveResponse res = req.execute(); assertEquals(200, res.getStatusCode()); @@ -248,17 +250,17 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { @Test public void checkForETagAsAtom() { - checkForETag(client, ODataFormat.ATOM); + checkForETag(client, ContentType.APPLICATION_ATOM_XML); } @Test public void checkForETagAsFullJSON() { - checkForETag(client, ODataFormat.JSON_FULL_METADATA); + checkForETag(client, ContentType.JSON_FULL_METADATA); } @Test public void checkForETagAsJSON() { - checkForETag(edmClient, ODataFormat.JSON); + checkForETag(edmClient, ContentType.JSON); } @Test(expected = IllegalArgumentException.class) @@ -267,20 +269,20 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { final ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()); - req.setFormat(ODataFormat.JSON); + req.setFormat(ContentType.JSON); // this statement should cause an IllegalArgumentException bearing JsonParseException // since we are attempting to parse an EntitySet as if it was an Entity req.execute().getBody(); } - private void reference(final ODataFormat format) { + private void reference(final ContentType contentType) { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Orders").appendKeySegment(8).appendNavigationSegment("CustomerForOrder"). appendRefSegment(); ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()); - req.setFormat(format); + req.setFormat(contentType); ODataRetrieveResponse res = req.execute(); assertNotNull(res); @@ -293,7 +295,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { appendEntityIdSegment(entity.getId().toASCIIString()).build(); req = client.getRetrieveRequestFactory().getEntityRequest(referenceURI); - req.setFormat(format); + req.setFormat(contentType); res = req.execute(); assertNotNull(res); @@ -302,20 +304,20 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { @Test public void atomReference() { - reference(ODataFormat.ATOM); + reference(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonReference() { - reference(ODataFormat.JSON_FULL_METADATA); + reference(ContentType.JSON_FULL_METADATA); } - private void contained(final ODataClient client, final ODataFormat format) throws EdmPrimitiveTypeException { + private void contained(final ODataClient client, final ContentType contentType) throws EdmPrimitiveTypeException { final URI uri = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Accounts").appendKeySegment(101). appendNavigationSegment("MyPaymentInstruments").appendKeySegment(101902).build(); final ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uri); - req.setFormat(format); + req.setFormat(contentType); final ClientEntity contained = req.execute().getBody(); assertNotNull(contained); @@ -328,30 +330,30 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { @Test public void containedFromAtom() throws EdmPrimitiveTypeException { - contained(client, ODataFormat.ATOM); + contained(client, ContentType.APPLICATION_ATOM_XML); } @Test public void containedFromFullJSON() throws EdmPrimitiveTypeException { - contained(client, ODataFormat.JSON_FULL_METADATA); + contained(client, ContentType.JSON_FULL_METADATA); } @Test public void containedFromJSON() throws EdmPrimitiveTypeException { - contained(edmClient, ODataFormat.JSON); + contained(edmClient, ContentType.JSON); } - private void entitySetNavigationLink(final ODataClient client, final ODataFormat format) { + private void entitySetNavigationLink(final ODataClient client, final ContentType contentType) { final URI uri = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Accounts").appendKeySegment(101).build(); final ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uri); - req.setFormat(format); + req.setFormat(contentType); final ClientEntity entity = req.execute().getBody(); assertNotNull(entity); // With JSON, entity set navigation links are only recognizable via Edm - if (format == ODataFormat.ATOM || client instanceof EdmEnabledODataClient) { + if (contentType.equals(ContentType.APPLICATION_ATOM_XML) || client instanceof EdmEnabledODataClient) { assertEquals(ClientLinkType.ENTITY_SET_NAVIGATION, entity.getNavigationLink("MyPaymentInstruments").getType()); assertEquals(ClientLinkType.ENTITY_SET_NAVIGATION, entity.getNavigationLink("ActiveSubscriptions").getType()); } @@ -359,13 +361,13 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { @Test public void entitySetNavigationLinkFromAtom() { - entitySetNavigationLink(client, ODataFormat.ATOM); + entitySetNavigationLink(client, ContentType.APPLICATION_ATOM_XML); } @Test public void entitySetNavigationLinkFromJSON() { // only JSON_FULL_METADATA has links, only Edm can recognize entity set navigation - entitySetNavigationLink(edmClient, ODataFormat.JSON_FULL_METADATA); + entitySetNavigationLink(edmClient, ContentType.JSON_FULL_METADATA); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java index b94e891c1..64d425b04 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java @@ -37,7 +37,7 @@ import org.apache.olingo.client.api.domain.ClientEntitySetIterator; import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; /** @@ -45,11 +45,11 @@ import org.junit.Test; */ public class EntitySetTestITCase extends AbstractTestITCase { - private void rawRequest(final ODataFormat format) { + private void rawRequest(final ContentType contentType) { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("People"); final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build()); - req.setFormat(format.getContentType().toContentTypeString()); + req.setFormat(contentType.toContentTypeString()); final ODataRawResponse res = req.execute(); assertNotNull(res); @@ -61,20 +61,20 @@ public class EntitySetTestITCase extends AbstractTestITCase { @Test public void rawRequestAsAtom() throws IOException { - rawRequest(ODataFormat.ATOM); + rawRequest(ContentType.APPLICATION_ATOM_XML); } @Test public void rawRequestAsJSON() throws IOException { - rawRequest(ODataFormat.JSON); + rawRequest(ContentType.JSON); } - private void readWithInlineCount(final ODataClient client, final ODataFormat format) { + private void readWithInlineCount(final ODataClient client, final ContentType contentType) { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("People").count(true); final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build()); - req.setFormat(format.getContentType().toContentTypeString()); + req.setFormat(contentType.toContentTypeString()); final ODataRawResponse res = req.execute(); assertNotNull(res); @@ -88,25 +88,25 @@ public class EntitySetTestITCase extends AbstractTestITCase { @Test public void readWithInlineCountAsJSON() throws IOException { - readWithInlineCount(edmClient, ODataFormat.JSON); + readWithInlineCount(edmClient, ContentType.JSON); } @Test public void readWithInlineCountAsFullJSON() throws IOException { - readWithInlineCount(client, ODataFormat.JSON_FULL_METADATA); + readWithInlineCount(client, ContentType.JSON_FULL_METADATA); } @Test public void readWithInlineCountAsAtom() throws IOException { - readWithInlineCount(client, ODataFormat.ATOM); + readWithInlineCount(client, ContentType.APPLICATION_ATOM_XML); } - private void readODataEntitySetIterator(final ODataFormat format) { + private void readODataEntitySetIterator(final ContentType contentType) { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("People"); final ODataEntitySetIteratorRequest req = client.getRetrieveRequestFactory().getEntitySetIteratorRequest(uriBuilder.build()); - req.setFormat(format); + req.setFormat(contentType); final ODataRetrieveResponse> res = req.execute(); final ClientEntitySetIterator feedIterator = res.getBody(); @@ -125,25 +125,25 @@ public class EntitySetTestITCase extends AbstractTestITCase { @Test public void readODataEntitySetIteratorFromAtom() { - readODataEntitySetIterator(ODataFormat.ATOM); + readODataEntitySetIterator(ContentType.APPLICATION_ATOM_XML); } @Test public void readODataEntitySetIteratorFromJSON() { - readODataEntitySetIterator(ODataFormat.JSON); + readODataEntitySetIterator(ContentType.JSON); } @Test public void readODataEntitySetIteratorFromJSONFull() { - readODataEntitySetIterator(ODataFormat.JSON_FULL_METADATA); + readODataEntitySetIterator(ContentType.JSON_FULL_METADATA); } @Test public void readODataEntitySetIteratorFromJSONNo() { - readODataEntitySetIterator(ODataFormat.JSON_NO_METADATA); + readODataEntitySetIterator(ContentType.JSON_NO_METADATA); } - private void readWithNext(final ODataFormat format) { + private void readWithNext(final ContentType format) { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("People"); final ODataEntitySetRequest req = client.getRetrieveRequestFactory(). @@ -167,12 +167,12 @@ public class EntitySetTestITCase extends AbstractTestITCase { @Test public void readWithNextFromAtom() { - readWithNext(ODataFormat.ATOM); + readWithNext(ContentType.APPLICATION_ATOM_XML); } @Test public void readWithNextFromJSON() { - readWithNext(ODataFormat.JSON_FULL_METADATA); + readWithNext(ContentType.JSON_FULL_METADATA); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/EntityUpdateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/EntityUpdateTestITCase.java index 6ac0e8da5..875034895 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/EntityUpdateTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/EntityUpdateTestITCase.java @@ -37,13 +37,13 @@ import org.apache.olingo.client.api.domain.ClientLink; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Ignore; import org.junit.Test; public class EntityUpdateTestITCase extends AbstractTestITCase { - private void upsert(final UpdateType updateType, final ODataFormat format) { + private void upsert(final UpdateType updateType, final ContentType contentType) { final ClientEntity order = getClient().getObjectFactory(). newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Order")); @@ -61,11 +61,11 @@ public class EntityUpdateTestITCase extends AbstractTestITCase { appendEntitySetSegment("Orders").appendKeySegment(9).build(); final ODataEntityUpdateRequest req = getClient().getCUDRequestFactory(). getEntityUpdateRequest(upsertURI, updateType, order); - req.setFormat(format); + req.setFormat(contentType); req.execute(); try { - final ClientEntity read = read(format, upsertURI); + final ClientEntity read = read(contentType, upsertURI); assertNotNull(read); assertEquals(order.getProperty("OrderID"), read.getProperty("OrderID")); assertEquals(order.getProperty("OrderDate").getPrimitiveValue().toString(), @@ -103,17 +103,17 @@ public class EntityUpdateTestITCase extends AbstractTestITCase { @Test public void atomUpsert() { - upsert(UpdateType.PATCH, ODataFormat.ATOM); - upsert(UpdateType.REPLACE, ODataFormat.ATOM); + upsert(UpdateType.PATCH, ContentType.APPLICATION_ATOM_XML); + upsert(UpdateType.REPLACE, ContentType.APPLICATION_ATOM_XML); } @Test public void jsonUpsert() { - upsert(UpdateType.PATCH, ODataFormat.JSON); - upsert(UpdateType.REPLACE, ODataFormat.JSON); + upsert(UpdateType.PATCH, ContentType.JSON); + upsert(UpdateType.REPLACE, ContentType.JSON); } - private void onContained(final ODataFormat format) { + private void onContained(final ContentType contentType) { final String newName = UUID.randomUUID().toString(); final ClientEntity changes = getClient().getObjectFactory().newEntity( new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument")); @@ -125,7 +125,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase { appendNavigationSegment("MyPaymentInstruments").appendKeySegment(101901).build(); final ODataEntityUpdateRequest req = getClient().getCUDRequestFactory(). getEntityUpdateRequest(uri, UpdateType.PATCH, changes); - req.setFormat(format); + req.setFormat(contentType); final ODataEntityUpdateResponse res = req.execute(); assertEquals(204, res.getStatusCode()); @@ -137,15 +137,15 @@ public class EntityUpdateTestITCase extends AbstractTestITCase { @Test public void atomOnContained() { - onContained(ODataFormat.ATOM); + onContained(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonOnContained() { - onContained(ODataFormat.JSON); + onContained(ContentType.JSON); } - private void bindOperation(final ODataFormat format) throws EdmPrimitiveTypeException { + private void bindOperation(final ContentType contentType) throws EdmPrimitiveTypeException { final ClientEntity changes = getClient().getObjectFactory().newEntity( new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Customer")); final ClientLink parent = getClient().getObjectFactory().newEntityNavigationLink("Parent", @@ -157,7 +157,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase { appendEntitySetSegment("People").appendKeySegment(5).build(); final ODataEntityUpdateRequest req = getClient().getCUDRequestFactory(). getEntityUpdateRequest(uri, UpdateType.PATCH, changes); - req.setFormat(format); + req.setFormat(contentType); final ODataEntityUpdateResponse res = req.execute(); assertEquals(204, res.getStatusCode()); @@ -175,11 +175,11 @@ public class EntityUpdateTestITCase extends AbstractTestITCase { @Test public void atomBindOperation() throws EdmPrimitiveTypeException { - bindOperation(ODataFormat.ATOM); + bindOperation(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonBindOperation() throws EdmPrimitiveTypeException { - bindOperation(ODataFormat.JSON); + bindOperation(ContentType.JSON); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/ErrorResponseTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/ErrorResponseTestITCase.java index 33d3ba4d5..983957669 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/ErrorResponseTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/ErrorResponseTestITCase.java @@ -27,7 +27,7 @@ import java.util.Map; import org.apache.olingo.client.api.communication.ODataClientErrorException; import org.apache.olingo.commons.api.ODataError; import org.apache.olingo.commons.api.ODataErrorDetail; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; public class ErrorResponseTestITCase extends AbstractTestITCase { @@ -39,7 +39,7 @@ public class ErrorResponseTestITCase extends AbstractTestITCase { build(); try { - read(ODataFormat.JSON, readURI); + read(ContentType.JSON, readURI); fail("should have got exception"); } catch (Exception ex) { final ODataError err = ((ODataClientErrorException) ex).getODataError(); diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/FilterFactoryTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/FilterFactoryTestITCase.java index b7a4f8c29..f25cfd3b7 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/FilterFactoryTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/FilterFactoryTestITCase.java @@ -27,7 +27,7 @@ import org.apache.olingo.client.api.uri.FilterArgFactory; import org.apache.olingo.client.api.uri.FilterFactory; import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.client.api.uri.URIFilter; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; public class FilterFactoryTestITCase extends AbstractTestITCase { @@ -50,7 +50,7 @@ public class FilterFactoryTestITCase extends AbstractTestITCase { final ODataEntitySetRequest req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build()); - req.setFormat(ODataFormat.JSON_FULL_METADATA); + req.setFormat(ContentType.JSON_FULL_METADATA); final ClientEntitySet feed = req.execute().getBody(); assertEquals(3, feed.getEntities().size()); diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/JSONFormatConformanceTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/JSONFormatConformanceTestITCase.java index 648dcec2c..f738ed47a 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/JSONFormatConformanceTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/JSONFormatConformanceTestITCase.java @@ -40,7 +40,7 @@ import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.commons.api.data.ResWrap; 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.apache.olingo.commons.api.format.ContentType; import org.junit.Test; /** @@ -91,7 +91,7 @@ public class JSONFormatConformanceTestITCase extends AbstractTestITCase { final URI uri = edmClient.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Accounts").appendKeySegment(102).build(); final ODataEntityRequest req = edmClient.getRetrieveRequestFactory().getEntityRequest(uri); - req.setFormat(ODataFormat.JSON_FULL_METADATA); + req.setFormat(ContentType.JSON_FULL_METADATA); // request format (via Accept header) is set to full metadata assertEquals("application/json;odata.metadata=full", req.getAccept()); @@ -148,7 +148,7 @@ public class JSONFormatConformanceTestITCase extends AbstractTestITCase { + "\"GeographyPoint\": {\"type\": \"Point\",\"coordinates\":[142.1,64.1]}" + "}"; - final ClientEntity entity = client.getReader().readEntity(IOUtils.toInputStream(fromSection71), ODataFormat.JSON); + final ClientEntity entity = client.getReader().readEntity(IOUtils.toInputStream(fromSection71), ContentType.JSON); assertTrue(entity.getProperty("NullValue").hasNullValue()); @@ -219,7 +219,7 @@ public class JSONFormatConformanceTestITCase extends AbstractTestITCase { + "}"; final ResWrap entity = - client.getDeserializer(ODataFormat.JSON).toEntity(IOUtils.toInputStream(fromSection45_1)); + client.getDeserializer(ContentType.JSON).toEntity(IOUtils.toInputStream(fromSection45_1)); assertEquals("http://host/service/$metadata#Customers/$entity", entity.getContextURL().toASCIIString()); assertEquals("W/\"A1FF3E230954908F\"", entity.getMetadataETag()); @@ -241,7 +241,7 @@ public class JSONFormatConformanceTestITCase extends AbstractTestITCase { + "}"; final ResWrap entitySet = - client.getDeserializer(ODataFormat.JSON).toEntitySet(IOUtils.toInputStream(fromSection45_2)); + client.getDeserializer(ContentType.JSON).toEntitySet(IOUtils.toInputStream(fromSection45_2)); assertEquals(5, entitySet.getPayload().getCount(), 0); assertEquals("Customers?$expand=Orders&$skipToken=5", entitySet.getPayload().getNext().toASCIIString()); @@ -271,7 +271,7 @@ public class JSONFormatConformanceTestITCase extends AbstractTestITCase { + "}"; final ClientEntitySet entitySet = client.getReader(). - readEntitySet(IOUtils.toInputStream(sample), ODataFormat.JSON); + readEntitySet(IOUtils.toInputStream(sample), ContentType.JSON); assertEquals(2, entitySet.getAnnotations().size()); diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/KeyAsSegmentTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/KeyAsSegmentTestITCase.java index f3e7d76db..54206fb51 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/KeyAsSegmentTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/KeyAsSegmentTestITCase.java @@ -33,7 +33,7 @@ import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -50,20 +50,20 @@ public class KeyAsSegmentTestITCase extends AbstractTestITCase { client.getConfiguration().setKeyAsSegment(false); } - private void read(final ODataFormat format) { + private void read(final ContentType contentType) { final URIBuilder uriBuilder = client.newURIBuilder(testKeyAsSegmentServiceRootURL). appendEntitySetSegment("Accounts").appendKeySegment(101); final ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()); - req.setFormat(format); + req.setFormat(contentType); final ODataRetrieveResponse res = req.execute(); final ClientEntity entity = res.getBody(); assertNotNull(entity); // In JSON with minimal metadata, links are not provided - if (format == ODataFormat.ATOM || format == ODataFormat.JSON_FULL_METADATA) { + if (contentType.equals(ContentType.APPLICATION_ATOM_XML) || contentType.equals(ContentType.JSON_FULL_METADATA)) { assertFalse(entity.getEditLink().toASCIIString().contains("(")); assertFalse(entity.getEditLink().toASCIIString().contains(")")); } @@ -71,25 +71,25 @@ public class KeyAsSegmentTestITCase extends AbstractTestITCase { @Test public void atomRead() { - read(ODataFormat.ATOM); + read(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonRead() { - read(ODataFormat.JSON); + read(ContentType.JSON); } @Test public void atomCreateAndDelete() { - createAndDeleteOrder(testKeyAsSegmentServiceRootURL, ODataFormat.ATOM, 1000); + createAndDeleteOrder(testKeyAsSegmentServiceRootURL, ContentType.APPLICATION_ATOM_XML, 1000); } @Test public void jsonCreateAndDelete() { - createAndDeleteOrder(testKeyAsSegmentServiceRootURL, ODataFormat.JSON_FULL_METADATA, 1001); + createAndDeleteOrder(testKeyAsSegmentServiceRootURL, ContentType.JSON_FULL_METADATA, 1001); } - private void update(final ODataFormat format) { + private void update(final ContentType contentType) { final ClientEntity changes = getClient().getObjectFactory().newEntity( new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Customer")); final ClientProperty middleName = getClient().getObjectFactory().newPrimitiveProperty("MiddleName", @@ -100,7 +100,7 @@ public class KeyAsSegmentTestITCase extends AbstractTestITCase { appendEntitySetSegment("People").appendKeySegment(5).build(); final ODataEntityUpdateRequest req = getClient().getCUDRequestFactory(). getEntityUpdateRequest(uri, UpdateType.PATCH, changes); - req.setFormat(format); + req.setFormat(contentType); final ODataEntityUpdateResponse res = req.execute(); assertEquals(204, res.getStatusCode()); @@ -117,11 +117,11 @@ public class KeyAsSegmentTestITCase extends AbstractTestITCase { @Test public void atomUpdate() { - update(ODataFormat.ATOM); + update(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonUpdate() { - update(ODataFormat.JSON); + update(ContentType.JSON); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/MediaEntityTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/MediaEntityTestITCase.java index a39e71b88..0c6352dc8 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/MediaEntityTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/MediaEntityTestITCase.java @@ -52,18 +52,18 @@ import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; public class MediaEntityTestITCase extends AbstractTestITCase { - private void read(final ODataClient client, final ODataFormat format) throws IOException { + private void read(final ODataClient client, final ContentType contentType) throws IOException { final URIBuilder builder = client.newURIBuilder(testDemoServiceRootURL). appendEntitySetSegment("Advertisements"). appendKeySegment(UUID.fromString("f89dee73-af9f-4cd4-b330-db93c25ff3c7")); final ODataEntityRequest entityReq = client.getRetrieveRequestFactory().getEntityRequest(builder.build()); - entityReq.setFormat(format); + entityReq.setFormat(contentType); final ClientEntity entity = entityReq.execute().getBody(); assertNotNull(entity); @@ -83,20 +83,20 @@ public class MediaEntityTestITCase extends AbstractTestITCase { @Test public void readAsAtom() throws IOException { - read(client, ODataFormat.ATOM); + read(client, ContentType.APPLICATION_ATOM_XML); } @Test public void readAsJSON() throws IOException { - read(ODataClientFactory.getEdmEnabledClient(testDemoServiceRootURL), ODataFormat.JSON); + read(ODataClientFactory.getEdmEnabledClient(testDemoServiceRootURL), ContentType.JSON); } @Test public void readAsJSONFull() throws IOException { - read(client, ODataFormat.JSON_FULL_METADATA); + read(client, ContentType.JSON_FULL_METADATA); } - private void create(final ODataFormat format) throws IOException { + private void create(final ContentType contentType) throws IOException { final String random = RandomStringUtils.random(110); final InputStream input = IOUtils.toInputStream(random); @@ -120,7 +120,7 @@ public class MediaEntityTestITCase extends AbstractTestITCase { final ODataEntityUpdateRequest updateReq = getClient().getCUDRequestFactory(). getEntityUpdateRequest(createdLocation, UpdateType.PATCH, changes); - updateReq.setFormat(format); + updateReq.setFormat(contentType); final ODataEntityUpdateResponse updateRes = updateReq.execute(); assertEquals(204, updateRes.getStatusCode()); @@ -137,15 +137,15 @@ public class MediaEntityTestITCase extends AbstractTestITCase { @Test public void createAsAtom() throws IOException { - create(ODataFormat.ATOM); + create(ContentType.APPLICATION_ATOM_XML); } @Test public void createAsJSON() throws IOException { - create(ODataFormat.JSON); + create(ContentType.JSON); } - private void update(final ODataFormat format) throws IOException, EdmPrimitiveTypeException { + private void update(final ContentType contentType) throws IOException, EdmPrimitiveTypeException { final URI uri = client.newURIBuilder(testDemoServiceRootURL). appendEntitySetSegment("Advertisements"). appendKeySegment(UUID.fromString("f89dee73-af9f-4cd4-b330-db93c25ff3c7")).build(); @@ -155,7 +155,7 @@ public class MediaEntityTestITCase extends AbstractTestITCase { // 1. update providing media content final ODataMediaEntityUpdateRequest updateReq = client.getCUDRequestFactory(). getMediaEntityUpdateRequest(uri, IOUtils.toInputStream(random)); - updateReq.setFormat(format); + updateReq.setFormat(contentType); final MediaEntityUpdateStreamManager streamManager = updateReq.payloadManager(); final ODataMediaEntityUpdateResponse createRes = streamManager.getResponse(); @@ -173,11 +173,11 @@ public class MediaEntityTestITCase extends AbstractTestITCase { @Test public void updateAsAtom() throws IOException, EdmPrimitiveTypeException { - update(ODataFormat.ATOM); + update(ContentType.APPLICATION_ATOM_XML); } @Test public void updateAsJSON() throws IOException, EdmPrimitiveTypeException { - update(ODataFormat.JSON); + update(ContentType.JSON); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/OAuth2TestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/OAuth2TestITCase.java index 7e8c13158..1285fa201 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/OAuth2TestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/OAuth2TestITCase.java @@ -32,7 +32,7 @@ import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.client.core.http.DefaultHttpClientFactory; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.fit.CXFOAuth2HttpClientFactory; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -76,13 +76,13 @@ public class OAuth2TestITCase extends AbstractTestITCase { return _edmClient; } - private void read(final ODataClient client, final ODataFormat format) { + private void read(final ODataClient client, final ContentType contentType) { final URIBuilder uriBuilder = client.newURIBuilder(testOAuth2ServiceRootURL).appendEntitySetSegment("Orders").appendKeySegment(8); final ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()); - req.setFormat(format); + req.setFormat(contentType); final ODataRetrieveResponse res = req.execute(); assertEquals(200, res.getStatusCode()); @@ -127,19 +127,19 @@ public class OAuth2TestITCase extends AbstractTestITCase { } public void readAsAtom() { - read(getLocalClient(), ODataFormat.ATOM); + read(getLocalClient(), ContentType.APPLICATION_ATOM_XML); } public void readAsFullJSON() { - read(getLocalClient(), ODataFormat.JSON_FULL_METADATA); + read(getLocalClient(), ContentType.JSON_FULL_METADATA); } public void readAsJSON() { - read(getEdmClient(), ODataFormat.JSON); + read(getEdmClient(), ContentType.JSON); } public void createAndDelete() { - createAndDeleteOrder(testOAuth2ServiceRootURL, ODataFormat.JSON, 1002); + createAndDeleteOrder(testOAuth2ServiceRootURL, ContentType.JSON, 1002); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/OpenTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/OpenTypeTestITCase.java index f4fe4f8d0..c3b033704 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/OpenTypeTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/OpenTypeTestITCase.java @@ -36,7 +36,7 @@ import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.EdmSchema; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; public class OpenTypeTestITCase extends AbstractTestITCase { @@ -53,32 +53,32 @@ public class OpenTypeTestITCase extends AbstractTestITCase { assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "RowIndex")).isOpenType()); } - private ClientEntity readRow(final ODataFormat format, final String uuid) { + private ClientEntity readRow(final ContentType contentType, final String uuid) { final URIBuilder builder = getClient().newURIBuilder(testOpenTypeServiceRootURL). appendEntitySetSegment("Row").appendKeySegment(UUID.fromString(uuid)); - return read(format, builder.build()); + return read(contentType, builder.build()); } - private void read(final ODataFormat format) { - ClientEntity row = readRow(format, "71f7d0dc-ede4-45eb-b421-555a2aa1e58f"); + private void read(final ContentType contentType) { + ClientEntity row = readRow(contentType, "71f7d0dc-ede4-45eb-b421-555a2aa1e58f"); assertEquals(EdmPrimitiveTypeKind.Double, row.getProperty("Double").getPrimitiveValue().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.Guid, row.getProperty("Id").getPrimitiveValue().getTypeKind()); - row = readRow(format, "672b8250-1e6e-4785-80cf-b94b572e42b3"); + row = readRow(contentType, "672b8250-1e6e-4785-80cf-b94b572e42b3"); assertEquals(EdmPrimitiveTypeKind.Decimal, row.getProperty("Decimal").getPrimitiveValue().getTypeKind()); } @Test public void readAsAtom() { - read(ODataFormat.ATOM); + read(ContentType.APPLICATION_ATOM_XML); } @Test public void readAsJSON() { - read(ODataFormat.JSON_FULL_METADATA); + read(ContentType.JSON_FULL_METADATA); } - private void cud(final ODataFormat format) { + private void cud(final ContentType contentType) { final Integer id = 1426; ClientEntity rowIndex = getClient().getObjectFactory().newEntity( @@ -154,13 +154,13 @@ public class OpenTypeTestITCase extends AbstractTestITCase { final ODataEntityCreateRequest createReq = getClient().getCUDRequestFactory(). getEntityCreateRequest(getClient().newURIBuilder(testOpenTypeServiceRootURL). appendEntitySetSegment("RowIndex").build(), rowIndex); - createReq.setFormat(format); + createReq.setFormat(contentType); final ODataEntityCreateResponse createRes = createReq.execute(); assertEquals(201, createRes.getStatusCode()); final URIBuilder builder = getClient().newURIBuilder(testOpenTypeServiceRootURL). appendEntitySetSegment("RowIndex").appendKeySegment(id); - rowIndex = read(format, builder.build()); + rowIndex = read(contentType, builder.build()); assertNotNull(rowIndex); assertEquals(EdmPrimitiveTypeKind.Int32, rowIndex.getProperty("Id").getPrimitiveValue().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.String, rowIndex.getProperty("aString").getPrimitiveValue().getTypeKind()); @@ -179,12 +179,12 @@ public class OpenTypeTestITCase extends AbstractTestITCase { @Test public void cudAsAtom() { - cud(ODataFormat.ATOM); + cud(ContentType.APPLICATION_ATOM_XML); } @Test public void cudAsJSON() { - cud(ODataFormat.JSON_FULL_METADATA); + cud(ContentType.JSON_FULL_METADATA); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/OperationImportInvokeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/OperationImportInvokeTestITCase.java index 1b27efa06..d6d535bae 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/OperationImportInvokeTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/OperationImportInvokeTestITCase.java @@ -37,17 +37,17 @@ import org.apache.olingo.client.api.domain.ClientPrimitiveValue; import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.domain.ClientValue; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; public class OperationImportInvokeTestITCase extends AbstractTestITCase { - private void functionImports(final ODataFormat format) throws EdmPrimitiveTypeException { + private void functionImports(final ContentType contentType) throws EdmPrimitiveTypeException { // GetDefaultColor final ODataInvokeRequest defaultColorReq = getClient().getInvokeRequestFactory(). getFunctionInvokeRequest(getClient().newURIBuilder(testStaticServiceRootURL). appendOperationCallSegment("GetDefaultColor").build(), ClientProperty.class); - defaultColorReq.setFormat(format); + defaultColorReq.setFormat(contentType); final ClientProperty defaultColor = defaultColorReq.execute().getBody(); assertNotNull(defaultColor); assertTrue(defaultColor.hasEnumValue()); @@ -61,7 +61,7 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase { getFunctionInvokeRequest(getClient().newURIBuilder(testStaticServiceRootURL). appendOperationCallSegment("GetPerson2").build(), ClientEntity.class, Collections. singletonMap("city", city)); - person2Req.setFormat(format); + person2Req.setFormat(contentType); final ClientEntity person2 = person2Req.execute().getBody(); assertNotNull(person2); assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", person2.getTypeName().toString()); @@ -81,7 +81,7 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase { getFunctionInvokeRequest(getClient().newURIBuilder(testStaticServiceRootURL). appendOperationCallSegment("GetPerson").build(), ClientEntity.class, Collections. singletonMap("address", address)); - personReq.setFormat(format); + personReq.setFormat(contentType); final ClientEntity person = personReq.execute().getBody(); assertNotNull(person); assertEquals(person2, person); @@ -90,7 +90,7 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase { final ODataInvokeRequest productsReq = getClient().getInvokeRequestFactory() .getFunctionInvokeRequest(getClient().newURIBuilder(testStaticServiceRootURL). appendOperationCallSegment("GetAllProducts").build(), ClientEntitySet.class); - productsReq.setFormat(format); + productsReq.setFormat(contentType); final ClientEntitySet products = productsReq.execute().getBody(); assertNotNull(products); assertEquals(5, products.getEntities().size()); @@ -103,7 +103,7 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase { getFunctionInvokeRequest(getClient().newURIBuilder(testStaticServiceRootURL). appendOperationCallSegment("GetProductsByAccessLevel").build(), ClientProperty.class, Collections. singletonMap("accessLevel", accessLevel)); - prodByALReq.setFormat(format); + prodByALReq.setFormat(contentType); final ClientProperty prodByAL = prodByALReq.execute().getBody(); assertNotNull(prodByAL); assertTrue(prodByAL.hasCollectionValue()); @@ -113,12 +113,12 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase { @Test public void atomFunctionImports() throws EdmPrimitiveTypeException { - functionImports(ODataFormat.ATOM); + functionImports(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonFunctionImports() throws EdmPrimitiveTypeException { - functionImports(ODataFormat.JSON_FULL_METADATA); + functionImports(ContentType.JSON_FULL_METADATA); } @Test @@ -182,14 +182,14 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase { assertTrue(prodByAL.getCollectionValue().asJavaCollection().contains("Car")); } - private void actionImports(final ODataFormat format) { + private void actionImports(final ContentType contentType) { // Discount final ClientPrimitiveValue percentage = getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(22); final ODataInvokeRequest discountReq = getClient().getInvokeRequestFactory(). getActionInvokeRequest(getClient().newURIBuilder(testStaticServiceRootURL). appendOperationCallSegment("Discount").build(), ClientNoContent.class, Collections. singletonMap("percentage", percentage)); - discountReq.setFormat(format); + discountReq.setFormat(contentType); final ClientNoContent discount = discountReq.execute().getBody(); assertNotNull(discount); @@ -207,7 +207,7 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase { getActionInvokeRequest(getClient().newURIBuilder(testStaticServiceRootURL). appendOperationCallSegment("ResetBossAddress").build(), ClientProperty.class, Collections. singletonMap("address", address)); - resetBossAddressReq.setFormat(format); + resetBossAddressReq.setFormat(contentType); final ClientProperty resetBossAddress = resetBossAddressReq.execute().getBody(); assertNotNull(resetBossAddress); assertEquals(address, resetBossAddress.getComplexValue()); @@ -215,12 +215,12 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase { @Test public void atomActionImports() { - actionImports(ODataFormat.ATOM); + actionImports(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonActionImports() { - actionImports(ODataFormat.JSON_FULL_METADATA); + actionImports(ContentType.JSON_FULL_METADATA); } @Test @@ -251,7 +251,7 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase { assertEquals(address.getTypeName(), resetBossAddress.getComplexValue().getTypeName()); } - private void bossEmails(final ODataFormat format) { + private void bossEmails(final ContentType contentType) { // ResetBossEmail final ClientCollectionValue emails = getClient().getObjectFactory().newCollectionValue("Collection(Edm.String)"); @@ -261,7 +261,7 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase { getActionInvokeRequest(getClient().newURIBuilder(testStaticServiceRootURL). appendOperationCallSegment("ResetBossEmail").build(), ClientProperty.class, Collections. singletonMap("emails", emails)); - bossEmailsReq.setFormat(format); + bossEmailsReq.setFormat(contentType); final ClientProperty bossEmails = bossEmailsReq.execute().getBody(); assertNotNull(bossEmails); assertTrue(bossEmails.hasCollectionValue()); @@ -273,7 +273,7 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase { bossEmailsReq = getClient().getInvokeRequestFactory().getFunctionInvokeRequest( getClient().newURIBuilder(testStaticServiceRootURL). appendOperationCallSegment("GetBossEmails").build(), ClientProperty.class, params); - bossEmailsReq.setFormat(format); + bossEmailsReq.setFormat(contentType); final ClientProperty bossEmailsViaGET = bossEmailsReq.execute().getBody(); assertNotNull(bossEmailsViaGET); assertTrue(bossEmailsViaGET.hasCollectionValue()); @@ -284,11 +284,11 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase { @Test public void atomBossEmails() throws EdmPrimitiveTypeException { - bossEmails(ODataFormat.ATOM); + bossEmails(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonBossEmails() throws EdmPrimitiveTypeException { - bossEmails(ODataFormat.JSON_FULL_METADATA); + bossEmails(ContentType.JSON_FULL_METADATA); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java index e2c625045..cb94f83fe 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java @@ -37,18 +37,18 @@ import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.domain.ClientValuable; import org.apache.olingo.client.api.uri.URIBuilder; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpMethod; import org.junit.Test; public class PropertyTestITCase extends AbstractTestITCase { - private void _enum(final ODataClient client, final ODataFormat format) { + private void _enum(final ODataClient client, final ContentType contentType) { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Products").appendKeySegment(5).appendPropertySegment("CoverColors"); final ODataPropertyRequest req = client.getRetrieveRequestFactory(). getPropertyRequest(uriBuilder.build()); - req.setFormat(format); + req.setFormat(contentType); final ClientProperty prop = req.execute().getBody(); assertNotNull(prop); @@ -59,25 +59,25 @@ public class PropertyTestITCase extends AbstractTestITCase { @Test public void enumFromXML() { - _enum(client, ODataFormat.XML); + _enum(client, ContentType.APPLICATION_XML); } @Test public void enumFromJSON() { - _enum(edmClient, ODataFormat.JSON); + _enum(edmClient, ContentType.JSON); } @Test public void enumFromFullJSON() { - _enum(client, ODataFormat.JSON_FULL_METADATA); + _enum(client, ContentType.JSON_FULL_METADATA); } - private void geospatial(final ODataClient client, final ODataFormat format) { + private void geospatial(final ODataClient client, final ContentType contentType) { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("Home"); final ODataPropertyRequest req = client.getRetrieveRequestFactory(). getPropertyRequest(uriBuilder.build()); - req.setFormat(format); + req.setFormat(contentType); final ClientProperty prop = req.execute().getBody(); assertNotNull(prop); @@ -87,25 +87,25 @@ public class PropertyTestITCase extends AbstractTestITCase { @Test public void geospatialFromXML() { - geospatial(client, ODataFormat.XML); + geospatial(client, ContentType.APPLICATION_XML); } @Test public void geospatialFromJSON() { - geospatial(edmClient, ODataFormat.JSON); + geospatial(edmClient, ContentType.JSON); } @Test public void geospatialFromFullJSON() { - geospatial(client, ODataFormat.JSON_FULL_METADATA); + geospatial(client, ContentType.JSON_FULL_METADATA); } - private void complex(final ODataClient client, final ODataFormat format) { + private void complex(final ODataClient client, final ContentType contentType) { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Customers").appendKeySegment(2).appendPropertySegment("HomeAddress"); final ODataPropertyRequest req = client.getRetrieveRequestFactory(). getPropertyRequest(uriBuilder.build()); - req.setFormat(format); + req.setFormat(contentType); final ClientProperty prop = req.execute().getBody(); assertNotNull(prop); @@ -116,26 +116,26 @@ public class PropertyTestITCase extends AbstractTestITCase { @Test public void complexFromXML() { - complex(client, ODataFormat.XML); + complex(client, ContentType.APPLICATION_XML); } @Test public void complexFromJSON() { - complex(edmClient, ODataFormat.JSON); + complex(edmClient, ContentType.JSON); } @Test public void complexFromFullJSON() { - complex(client, ODataFormat.JSON_FULL_METADATA); + complex(client, ContentType.JSON_FULL_METADATA); } - private void updateComplexProperty(final ODataFormat format, final UpdateType type) throws IOException { + private void updateComplexProperty(final ContentType contentType, final UpdateType type) throws IOException { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Customers").appendKeySegment(1).appendPropertySegment("HomeAddress"); ODataPropertyRequest retrieveReq = client.getRetrieveRequestFactory().getPropertyRequest(uriBuilder.build()); - retrieveReq.setFormat(format); + retrieveReq.setFormat(contentType); ODataRetrieveResponse retrieveRes = retrieveReq.execute(); assertEquals(200, retrieveRes.getStatusCode()); @@ -153,13 +153,13 @@ public class PropertyTestITCase extends AbstractTestITCase { } else { assertEquals(type.getMethod(), updateReq.getMethod()); } - updateReq.setFormat(format); + updateReq.setFormat(contentType); final ODataPropertyUpdateResponse updateRes = updateReq.execute(); assertEquals(204, updateRes.getStatusCode()); retrieveReq = client.getRetrieveRequestFactory().getPropertyRequest(uriBuilder.build()); - retrieveReq.setFormat(format); + retrieveReq.setFormat(contentType); retrieveRes = retrieveReq.execute(); assertEquals(200, retrieveRes.getStatusCode()); @@ -170,7 +170,7 @@ public class PropertyTestITCase extends AbstractTestITCase { @Test public void patchComplexPropertyAsJSON() throws IOException { - updateComplexProperty(ODataFormat.JSON_FULL_METADATA, UpdateType.PATCH); + updateComplexProperty(ContentType.JSON_FULL_METADATA, UpdateType.PATCH); } @Test diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/PropertyValueTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/PropertyValueTestITCase.java index 123c1696a..c2eadc231 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/PropertyValueTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/PropertyValueTestITCase.java @@ -32,7 +32,7 @@ import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.domain.ClientValuable; import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; public class PropertyValueTestITCase extends AbstractTestITCase { @@ -42,7 +42,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("PersonID"); final ODataValueRequest req = client.getRetrieveRequestFactory().getPropertyValueRequest(uriBuilder.build()); - req.setFormat(ODataFormat.TEXT_PLAIN); + req.setFormat(ContentType.TEXT_PLAIN); assertEquals("5", req.execute().getBody().toString()); } @@ -51,7 +51,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("IsRegistered"); final ODataValueRequest req = client.getRetrieveRequestFactory().getPropertyValueRequest(uriBuilder.build()); - req.setFormat(ODataFormat.TEXT_PLAIN); + req.setFormat(ContentType.TEXT_PLAIN); assertEquals("true", req.execute().getBody().toString()); } @@ -60,7 +60,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("FirstName"); final ODataValueRequest req = client.getRetrieveRequestFactory().getPropertyValueRequest(uriBuilder.build()); - req.setFormat(ODataFormat.TEXT_PLAIN); + req.setFormat(ContentType.TEXT_PLAIN); assertEquals("Peter", req.execute().getBody().toString()); } @@ -69,7 +69,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("Orders").appendKeySegment(8).appendPropertySegment("OrderDate"); final ODataValueRequest req = client.getRetrieveRequestFactory().getPropertyValueRequest(uriBuilder.build()); - req.setFormat(ODataFormat.TEXT_PLAIN); + req.setFormat(ContentType.TEXT_PLAIN); final ClientPrimitiveValue property = req.execute().getBody(); assertEquals("2011-03-04T16:03:57Z", property.toString()); } @@ -79,7 +79,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("Height"); final ODataValueRequest req = client.getRetrieveRequestFactory().getPropertyValueRequest(uriBuilder.build()); - req.setFormat(ODataFormat.TEXT_PLAIN); + req.setFormat(ContentType.TEXT_PLAIN); final ClientPrimitiveValue property = req.execute().getBody(); assertEquals("179", property.toString()); } @@ -89,7 +89,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("PDC"); final ODataValueRequest req = client.getRetrieveRequestFactory().getPropertyValueRequest(uriBuilder.build()); - req.setFormat(ODataFormat.TEXT_PLAIN); + req.setFormat(ContentType.TEXT_PLAIN); final ClientPrimitiveValue property = req.execute().getBody(); assertEquals("fi653p3+MklA/LdoBlhWgnMTUUEo8tEgtbMXnF0a3CUNL9BZxXpSRiD9ebTnmNR0zWPjJ" + "VIDx4tdmCnq55XrJh+RW9aI/b34wAogK3kcORw=", property.toString()); @@ -100,7 +100,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("PDC"); final ODataValueRequest req = client.getRetrieveRequestFactory().getPropertyValueRequest(uriBuilder.build()); - req.setAccept(ODataFormat.ATOM.getContentType().toContentTypeString()); + req.setAccept(ContentType.APPLICATION_ATOM_XML.toContentTypeString()); req.execute().getBody(); } @@ -109,7 +109,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("PDC"); final ODataValueRequest req = client.getRetrieveRequestFactory().getPropertyValueRequest(uriBuilder.build()); - req.setAccept(ODataFormat.XML.getContentType().toContentTypeString()); + req.setAccept(ContentType.APPLICATION_XML.toContentTypeString()); req.execute().getBody(); } @@ -119,7 +119,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase { appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("Numbers"); final ODataPropertyRequest req = client.getRetrieveRequestFactory(). getPropertyRequest(uriBuilder.build()); - req.setFormat(ODataFormat.XML); + req.setFormat(ContentType.APPLICATION_XML); final ClientProperty property = req.execute().getBody(); // cast to workaround JDK 6 bug, fixed in JDK 7 assertTrue(((ClientValuable) property).getValue().isCollection()); @@ -131,7 +131,7 @@ public class PropertyValueTestITCase extends AbstractTestITCase { final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL). appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("HomeAddress"); final ODataValueRequest req = client.getRetrieveRequestFactory().getPropertyValueRequest(uriBuilder.build()); - req.setFormat(ODataFormat.TEXT_PLAIN); + req.setFormat(ContentType.TEXT_PLAIN); final ClientPrimitiveValue property = req.execute().getBody(); assertTrue(StringUtils.isBlank(property.toString())); } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/QueryOptionsTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/QueryOptionsTestITCase.java index 19af510d4..b9119f8b7 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/QueryOptionsTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/QueryOptionsTestITCase.java @@ -36,7 +36,7 @@ import org.apache.olingo.client.api.domain.ClientInlineEntitySet; import org.apache.olingo.client.api.uri.QueryOption; import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; /** @@ -128,12 +128,12 @@ public class QueryOptionsTestITCase extends AbstractTestITCase { final ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()); - req.setFormat(ODataFormat.ATOM); + req.setFormat(ContentType.APPLICATION_ATOM_XML); final ODataRetrieveResponse res = req.execute(); assertNotNull(res); assertTrue(res.getContentType().replaceAll(" ", ""). - startsWith(ODataFormat.JSON.getContentType().toContentTypeString())); + startsWith(ContentType.JSON.toContentTypeString())); } /** diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/ServiceDocumentTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/ServiceDocumentTestITCase.java index 13f762855..69a869c3b 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/ServiceDocumentTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/ServiceDocumentTestITCase.java @@ -25,15 +25,15 @@ import java.net.URI; import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.domain.ClientServiceDocument; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; public class ServiceDocumentTestITCase extends AbstractTestITCase { - private void retrieveServiceDocument(final ODataFormat format) { + private void retrieveServiceDocument(final ContentType contentType) { final ODataServiceDocumentRequest req = client.getRetrieveRequestFactory().getServiceDocumentRequest(testStaticServiceRootURL); - req.setFormat(format); + req.setFormat(contentType); final ODataRetrieveResponse res = req.execute(); assertEquals(200, res.getStatusCode()); @@ -53,11 +53,11 @@ public class ServiceDocumentTestITCase extends AbstractTestITCase { @Test public void retrieveServiceDocumentAsXML() { - retrieveServiceDocument(ODataFormat.XML); + retrieveServiceDocument(ContentType.APPLICATION_XML); } @Test public void retrieveServiceDocumentAsJSON() { - retrieveServiceDocument(ODataFormat.JSON); + retrieveServiceDocument(ContentType.JSON); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/SingletonTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/SingletonTestITCase.java index 14d9f1faa..7f4e2f8d2 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/SingletonTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/SingletonTestITCase.java @@ -36,16 +36,16 @@ import org.apache.olingo.client.api.domain.ClientValuable; import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; public class SingletonTestITCase extends AbstractTestITCase { - private void read(final ODataClient client, final ODataFormat format) throws EdmPrimitiveTypeException { + private void read(final ODataClient client, final ContentType contentType) throws EdmPrimitiveTypeException { final URIBuilder builder = client.newURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company"); final ODataEntityRequest singleton = client.getRetrieveRequestFactory().getSingletonRequest(builder.build()); - singleton.setFormat(format); + singleton.setFormat(contentType); final ClientSingleton company = singleton.execute().getBody(); assertNotNull(company); @@ -58,26 +58,26 @@ public class SingletonTestITCase extends AbstractTestITCase { @Test public void readFromAtom() throws EdmPrimitiveTypeException { - read(client, ODataFormat.ATOM); + read(client, ContentType.APPLICATION_ATOM_XML); } @Test public void readFromJSON() throws EdmPrimitiveTypeException { - read(edmClient, ODataFormat.JSON); + read(edmClient, ContentType.JSON); } @Test public void readfromJSONFull() throws EdmPrimitiveTypeException { - read(client, ODataFormat.JSON_FULL_METADATA); + read(client, ContentType.JSON_FULL_METADATA); } - private void readWithAnnotations(final ODataClient client, final ODataFormat format) + private void readWithAnnotations(final ODataClient client, final ContentType contentType) throws EdmPrimitiveTypeException { final URIBuilder builder = client.newURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Boss"); final ODataEntityRequest singleton = client.getRetrieveRequestFactory().getSingletonRequest(builder.build()); - singleton.setFormat(format); + singleton.setFormat(contentType); singleton.setPrefer(client.newPreferences().includeAnnotations("*")); final ClientSingleton boss = singleton.execute().getBody(); assertNotNull(boss); @@ -89,20 +89,20 @@ public class SingletonTestITCase extends AbstractTestITCase { @Test public void readWithAnnotationsFromAtom() throws EdmPrimitiveTypeException { - readWithAnnotations(client, ODataFormat.ATOM); + readWithAnnotations(client, ContentType.APPLICATION_ATOM_XML); } @Test public void readWithAnnotationsFromJSON() throws EdmPrimitiveTypeException { - readWithAnnotations(edmClient, ODataFormat.JSON); + readWithAnnotations(edmClient, ContentType.JSON); } @Test public void readWithAnnotationsFromJSONFull() throws EdmPrimitiveTypeException { - readWithAnnotations(client, ODataFormat.JSON_FULL_METADATA); + readWithAnnotations(client, ContentType.JSON_FULL_METADATA); } - private void update(final ODataFormat format) throws EdmPrimitiveTypeException { + private void update(final ContentType contentType) throws EdmPrimitiveTypeException { final ClientSingleton changes = getClient().getObjectFactory().newSingleton( new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Company")); changes.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Revenue", @@ -111,7 +111,7 @@ public class SingletonTestITCase extends AbstractTestITCase { final URI uri = client.newURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company").build(); final ODataEntityUpdateRequest req = getClient().getCUDRequestFactory(). getSingletonUpdateRequest(uri, UpdateType.PATCH, changes); - req.setFormat(format); + req.setFormat(contentType); final ODataEntityUpdateResponse res = req.execute(); assertEquals(204, res.getStatusCode()); @@ -124,12 +124,12 @@ public class SingletonTestITCase extends AbstractTestITCase { @Test public void atomUpdate() throws EdmPrimitiveTypeException { - update(ODataFormat.ATOM); + update(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonUpdate() throws EdmPrimitiveTypeException { - update(ODataFormat.JSON); + update(ContentType.JSON); } } diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/Configuration.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/Configuration.java index a02780069..f9ef1cc46 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/Configuration.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/Configuration.java @@ -23,7 +23,6 @@ import java.util.concurrent.ExecutorService; import org.apache.olingo.client.api.http.HttpClientFactory; import org.apache.olingo.client.api.http.HttpUriRequestFactory; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; /** * Configuration wrapper. @@ -49,16 +48,15 @@ public interface Configuration { * JSON_FULL_METADATA format will be used as default. * * @return configured OData format for AtomPub if specified; JSON_FULL_METADATA format otherwise. - * @see ODataFormat#JSON_FULL_METADATA */ - ODataFormat getDefaultPubFormat(); + ContentType getDefaultPubFormat(); /** * Sets the default OData format for AtomPub exchanges. * * @param format default format. */ - void setDefaultPubFormat(ODataFormat format); + void setDefaultPubFormat(ContentType format); /** * Gets the configured OData format. This value depends on what is returned from getDefaultPubFormat(). @@ -66,23 +64,22 @@ public interface Configuration { * @return configured OData format * @see #getDefaultPubFormat() */ - ODataFormat getDefaultFormat(); + ContentType getDefaultFormat(); /** * Gets the configured OData value format. If this configuration parameter doesn't exist the TEXT format will be used * as default. * * @return configured OData value format if specified; TEXT_PLAIN format otherwise. - * @see ODataFormat#TEXT_PLAIN */ - ODataFormat getDefaultValueFormat(); + ContentType getDefaultValueFormat(); /** * Sets the default OData value format. * * @param format default format. */ - void setDefaultValueFormat(ODataFormat format); + void setDefaultValueFormat(ContentType format); /** * Gets the configured OData media format. If this configuration parameter doesn't exist the APPLICATION_OCTET_STREAM @@ -90,14 +87,14 @@ public interface Configuration { * * @return configured OData media format if specified; APPLICATION_OCTET_STREAM format otherwise. */ - ODataFormat getDefaultMediaFormat(); + ContentType getDefaultMediaFormat(); /** * Sets the default OData media format. * * @param format default format. */ - void setDefaultMediaFormat(ODataFormat format); + void setDefaultMediaFormat(ContentType format); /** * Gets the HttpClient factory to be used for executing requests. diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/ODataClient.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/ODataClient.java index 214ab98dd..b3ac39c1a 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/ODataClient.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/ODataClient.java @@ -25,6 +25,7 @@ import org.apache.olingo.client.api.communication.request.batch.BatchRequestFact import org.apache.olingo.client.api.communication.request.cud.CUDRequestFactory; import org.apache.olingo.client.api.communication.request.invoke.InvokeRequestFactory; import org.apache.olingo.client.api.communication.request.retrieve.RetrieveRequestFactory; +import org.apache.olingo.client.api.domain.ClientObjectFactory; import org.apache.olingo.client.api.serialization.ClientODataDeserializer; import org.apache.olingo.client.api.serialization.ODataBinder; import org.apache.olingo.client.api.serialization.ODataReader; @@ -32,9 +33,8 @@ import org.apache.olingo.client.api.serialization.ODataWriter; import org.apache.olingo.client.api.uri.FilterFactory; import org.apache.olingo.client.api.uri.SearchFactory; import org.apache.olingo.client.api.uri.URIBuilder; -import org.apache.olingo.client.api.domain.ClientObjectFactory; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataSerializer; public interface ODataClient { @@ -47,13 +47,13 @@ public interface ODataClient { ODataPreferences newPreferences(); - ODataSerializer getSerializer(ODataFormat format); + ODataSerializer getSerializer(ContentType contentType); ODataWriter getWriter(); InvokeRequestFactory getInvokeRequestFactory(); - ClientODataDeserializer getDeserializer(ODataFormat format); + ClientODataDeserializer getDeserializer(ContentType contentType); ODataReader getReader(); diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/ODataClientBuilder.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/ODataClientBuilder.java index bd3cbdeae..99949776f 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/ODataClientBuilder.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/ODataClientBuilder.java @@ -18,12 +18,12 @@ */ package org.apache.olingo.client.api; -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.format.ODataFormat; - import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.format.ContentType; + /** *

* Builder to create an ODataClient for the API client library. @@ -142,7 +142,7 @@ public final class ODataClientBuilder { loadClass(EdmEnabledODataClient.class, clientImplClassName, new Class[] { String.class, Edm.class, String.class }, new Object[] { serviceRoot, edm, metadataETag }); - instance.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + instance.getConfiguration().setDefaultPubFormat(ContentType.JSON); return instance; } diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/ODataBasicRequest.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/ODataBasicRequest.java index 6bcb3b8ea..c977a0b48 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/ODataBasicRequest.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/ODataBasicRequest.java @@ -21,7 +21,7 @@ package org.apache.olingo.client.api.communication.request; import java.util.concurrent.Future; import org.apache.olingo.client.api.communication.response.ODataResponse; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; /** * Basic OData request. @@ -45,9 +45,9 @@ public interface ODataBasicRequest extends ODataRequest Future asyncExecute(); /** - * Override configured request format. + * Override configured request Content-Type. * - * @param format request format. + * @param contentType request Content-Type. */ - void setFormat(ODataFormat format); + void setFormat(ContentType contentType); } diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/streamed/ODataStreamedEntityRequest.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/streamed/ODataStreamedEntityRequest.java index a34e41c4b..0221285a3 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/streamed/ODataStreamedEntityRequest.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/streamed/ODataStreamedEntityRequest.java @@ -21,7 +21,7 @@ package org.apache.olingo.client.api.communication.request.streamed; import org.apache.olingo.client.api.communication.request.ODataPayloadManager; import org.apache.olingo.client.api.communication.request.ODataStreamedRequest; import org.apache.olingo.client.api.communication.response.ODataResponse; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; /** * Abstract class representing a request concerning a streamed entity. @@ -38,13 +38,12 @@ public interface ODataStreamedEntityRequest= 0) { - jsonEntity = odataClient.getDeserializer(ODataFormat.JSON).toEntity( + jsonEntity = odataClient.getDeserializer(ContentType.JSON).toEntity( new ByteArrayInputStream(entity.toByteArray())); } } else { @@ -240,7 +241,7 @@ public class ClientEntitySetIterator".getBytes(Constants.UTF8)); if (consume(input, "", entity, true) >= 0) { - atomEntity = odataClient.getDeserializer(ODataFormat.ATOM). + atomEntity = odataClient.getDeserializer(ContentType.APPLICATION_ATOM_XML). toEntity(new ByteArrayInputStream(entity.toByteArray())); } } diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataReader.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataReader.java index 7e4aa963f..746d69726 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataReader.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataReader.java @@ -21,15 +21,15 @@ package org.apache.olingo.client.api.serialization; import java.io.InputStream; import java.util.Map; -import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientEntitySet; -import org.apache.olingo.commons.api.ODataError; import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.domain.ClientServiceDocument; +import org.apache.olingo.commons.api.ODataError; +import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.provider.CsdlSchema; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; /** @@ -61,51 +61,52 @@ public interface ODataReader { * Parses an OData service document. * * @param input stream to de-serialize. - * @param format de-serialize as XML or JSON + * @param contentType de-serialize as XML or JSON * @return List of URIs. * @throws ODataDeserializerException */ - ClientServiceDocument readServiceDocument(InputStream input, ODataFormat format) throws ODataDeserializerException; + ClientServiceDocument readServiceDocument(InputStream input, ContentType contentType) + throws ODataDeserializerException; /** * De-Serializes a stream into an OData entity set. * * @param input stream to de-serialize. - * @param format de-serialize format + * @param contentType de-serialize format * @return de-serialized entity set. * @throws ODataDeserializerException */ - ClientEntitySet readEntitySet(InputStream input, ODataFormat format) throws ODataDeserializerException; + ClientEntitySet readEntitySet(InputStream input, ContentType contentType) throws ODataDeserializerException; /** * Parses a stream taking care to de-serializes the first OData entity found. * * @param input stream to de-serialize. - * @param format de-serialize format + * @param contentType de-serialize format * @return entity de-serialized. * @throws ODataDeserializerException */ - ClientEntity readEntity(InputStream input, ODataFormat format) throws ODataDeserializerException; + ClientEntity readEntity(InputStream input, ContentType contentType) throws ODataDeserializerException; /** * Parses a stream taking care to de-serialize the first OData entity property found. * * @param input stream to de-serialize. - * @param format de-serialize as XML or JSON + * @param contentType de-serialize as XML or JSON * @return OData entity property de-serialized. * @throws ODataDeserializerException */ - ClientProperty readProperty(InputStream input, ODataFormat format) throws ODataDeserializerException; + ClientProperty readProperty(InputStream input, ContentType contentType) throws ODataDeserializerException; /** * Parses a stream into an OData error. * * @param inputStream stream to de-serialize. - * @param format format + * @param contentType format * @return OData error. * @throws ODataDeserializerException */ - ODataError readError(InputStream inputStream, ODataFormat format) throws ODataDeserializerException; + ODataError readError(InputStream inputStream, ContentType contentType) throws ODataDeserializerException; /** * Parses a stream into the object type specified by the given reference. diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataWriter.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataWriter.java index 5287c94d9..4515cdf18 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataWriter.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataWriter.java @@ -22,11 +22,11 @@ import java.io.InputStream; import java.net.URI; import java.util.Collection; -import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.client.api.domain.ClientEntity; -import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.domain.ClientLink; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.client.api.domain.ClientProperty; +import org.apache.olingo.commons.api.data.ResWrap; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataSerializerException; /** @@ -42,54 +42,54 @@ public interface ODataWriter { * Writes a collection of OData entities. * * @param entities entities to be serialized. - * @param format serialization format. + * @param contentType serialization format. * @return stream of serialized objects. * @throws ODataSerializerException */ - InputStream writeEntities(Collection entities, ODataFormat format) + InputStream writeEntities(Collection entities, ContentType contentType) throws ODataSerializerException; /** * Serializes a single OData entity. * * @param entity entity to be serialized. - * @param format serialization format. + * @param contentType serialization format. * @return stream of serialized object. * @throws ODataSerializerException */ - InputStream writeEntity(ClientEntity entity, ODataFormat format) + InputStream writeEntity(ClientEntity entity, ContentType format) throws ODataSerializerException; /** * Writes a single OData entity property. * * @param property entity property to be serialized. - * @param format serialization format. + * @param contentType serialization format. * @return stream of serialized object. * @throws ODataSerializerException */ - InputStream writeProperty(ClientProperty property, ODataFormat format) + InputStream writeProperty(ClientProperty property, ContentType format) throws ODataSerializerException; /** * Writes an OData link. * * @param link link to be serialized. - * @param format serialization format. + * @param contentType serialization format. * @return stream of serialized object. * @throws ODataSerializerException */ - InputStream writeLink(ClientLink link, ODataFormat format) + InputStream writeLink(ClientLink link, ContentType format) throws ODataSerializerException; /** * Writes a entity reference * * @param reference reference to be serialized - * @param format serialization format + * @param contentType serialization format * @return stream of serialized objects * @throws ODataSerializerException */ - InputStream writeReference(ResWrap reference, ODataFormat format) + InputStream writeReference(ResWrap reference, ContentType format) throws ODataSerializerException; } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/ConfigurationImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/ConfigurationImpl.java index cd17ad0d4..14c59d6e8 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/ConfigurationImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/ConfigurationImpl.java @@ -29,7 +29,6 @@ import org.apache.olingo.client.api.http.HttpUriRequestFactory; import org.apache.olingo.client.core.http.DefaultHttpClientFactory; import org.apache.olingo.client.core.http.DefaultHttpUriRequestFactory; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; public class ConfigurationImpl implements Configuration { @@ -96,39 +95,39 @@ public class ConfigurationImpl implements Configuration { } @Override - public ODataFormat getDefaultPubFormat() { - return (ODataFormat) getProperty(DEFAULT_PUB_FORMAT, ODataFormat.JSON_FULL_METADATA); + public ContentType getDefaultPubFormat() { + return (ContentType) getProperty(DEFAULT_PUB_FORMAT, ContentType.JSON_FULL_METADATA); } @Override - public void setDefaultPubFormat(final ODataFormat format) { - setProperty(DEFAULT_PUB_FORMAT, format); + public void setDefaultPubFormat(final ContentType contentType) { + setProperty(DEFAULT_PUB_FORMAT, contentType); } @Override - public ODataFormat getDefaultFormat() { - final ODataFormat format = getDefaultPubFormat(); - return format == ODataFormat.ATOM ? ODataFormat.XML : format; + public ContentType getDefaultFormat() { + final ContentType contenType = getDefaultPubFormat(); + return contenType == ContentType.APPLICATION_ATOM_XML ? ContentType.APPLICATION_XML : contenType; } @Override - public ODataFormat getDefaultValueFormat() { - return (ODataFormat) getProperty(DEFAULT_VALUE_FORMAT, ODataFormat.TEXT_PLAIN); + public ContentType getDefaultValueFormat() { + return (ContentType) getProperty(DEFAULT_VALUE_FORMAT, ContentType.TEXT_PLAIN); } @Override - public void setDefaultValueFormat(final ODataFormat format) { - setProperty(DEFAULT_VALUE_FORMAT, format); + public void setDefaultValueFormat(final ContentType contentType) { + setProperty(DEFAULT_VALUE_FORMAT, contentType); } @Override - public ODataFormat getDefaultMediaFormat() { - return (ODataFormat) getProperty(DEFAULT_VALUE_FORMAT, ODataFormat.APPLICATION_OCTET_STREAM); + public ContentType getDefaultMediaFormat() { + return (ContentType) getProperty(DEFAULT_VALUE_FORMAT, ContentType.APPLICATION_OCTET_STREAM); } @Override - public void setDefaultMediaFormat(final ODataFormat format) { - setProperty(DEFAULT_MEDIA_FORMAT, format); + public void setDefaultMediaFormat(final ContentType contentType) { + setProperty(DEFAULT_MEDIA_FORMAT, contentType); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientFactory.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientFactory.java index b9f18a89c..d8b54e993 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientFactory.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientFactory.java @@ -21,7 +21,7 @@ package org.apache.olingo.client.core; import org.apache.olingo.client.api.EdmEnabledODataClient; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; public final class ODataClientFactory { @@ -38,7 +38,7 @@ public final class ODataClientFactory { final EdmEnabledODataClient instance = new EdmEnabledODataClientImpl(serviceRoot, edm, metadataETag); - instance.getConfiguration().setDefaultPubFormat(ODataFormat.JSON); + instance.getConfiguration().setDefaultPubFormat(ContentType.JSON); return instance; } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientImpl.java index a934e3e2f..6018c8712 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientImpl.java @@ -28,6 +28,7 @@ import org.apache.olingo.client.api.communication.request.batch.BatchRequestFact import org.apache.olingo.client.api.communication.request.cud.CUDRequestFactory; import org.apache.olingo.client.api.communication.request.invoke.InvokeRequestFactory; import org.apache.olingo.client.api.communication.request.retrieve.RetrieveRequestFactory; +import org.apache.olingo.client.api.domain.ClientObjectFactory; import org.apache.olingo.client.api.serialization.ClientODataDeserializer; import org.apache.olingo.client.api.serialization.ODataBinder; import org.apache.olingo.client.api.serialization.ODataReader; @@ -41,17 +42,17 @@ import org.apache.olingo.client.core.communication.request.batch.BatchRequestFac import org.apache.olingo.client.core.communication.request.cud.CUDRequestFactoryImpl; import org.apache.olingo.client.core.communication.request.invoke.InvokeRequestFactoryImpl; import org.apache.olingo.client.core.communication.request.retrieve.RetrieveRequestFactoryImpl; +import org.apache.olingo.client.core.domain.ClientObjectFactoryImpl; import org.apache.olingo.client.core.serialization.ClientODataDeserializerImpl; import org.apache.olingo.client.core.serialization.ODataBinderImpl; import org.apache.olingo.client.core.serialization.ODataReaderImpl; import org.apache.olingo.client.core.serialization.ODataWriterImpl; import org.apache.olingo.client.core.uri.FilterFactoryImpl; import org.apache.olingo.client.core.uri.URIBuilderImpl; -import org.apache.olingo.client.api.domain.ClientObjectFactory; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; +import org.apache.olingo.commons.api.format.Format; import org.apache.olingo.commons.api.serialization.ODataSerializer; -import org.apache.olingo.client.core.domain.ClientObjectFactoryImpl; import org.apache.olingo.commons.core.serialization.AtomSerializer; import org.apache.olingo.commons.core.serialization.JsonSerializer; @@ -125,15 +126,15 @@ public class ODataClientImpl implements ODataClient { } @Override - public ClientODataDeserializer getDeserializer(final ODataFormat format) { - return new ClientODataDeserializerImpl(false, format); + public ClientODataDeserializer getDeserializer(final ContentType contentType) { + return new ClientODataDeserializerImpl(false, contentType); } @Override - public ODataSerializer getSerializer(final ODataFormat format) { - return format == ODataFormat.ATOM || format == ODataFormat.XML ? + public ODataSerializer getSerializer(final ContentType contentType) { + return contentType.getODataFormat() == Format.ATOM || contentType.getODataFormat() == Format.XML ? new AtomSerializer() : - new JsonSerializer(false, format); + new JsonSerializer(false, contentType); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java index 2008149ed..802e67e60 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java @@ -24,9 +24,9 @@ import org.apache.http.StatusLine; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.communication.ODataClientErrorException; import org.apache.olingo.client.api.communication.ODataServerErrorException; -import org.apache.olingo.commons.api.ODataRuntimeException; import org.apache.olingo.commons.api.ODataError; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.ODataRuntimeException; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,11 +51,11 @@ public final class ODataErrorResponseChecker { if (entity == null) { result = new ODataClientErrorException(statusLine); } else { - final ODataFormat format = accept.contains("xml") ? ODataFormat.XML : ODataFormat.JSON; + final ContentType contentType = accept.contains("xml") ? ContentType.APPLICATION_ATOM_XML : ContentType.JSON; ODataError error; try { - error = odataClient.getReader().readError(entity, format); + error = odataClient.getReader().readError(entity, contentType); } catch (final RuntimeException e) { LOG.warn("Error deserializing error response", e); error = getGenericError( diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataBasicRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataBasicRequest.java index c5c313cac..7a5346829 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataBasicRequest.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataBasicRequest.java @@ -32,7 +32,7 @@ import org.apache.olingo.client.api.communication.request.ODataBasicRequest; import org.apache.olingo.client.api.communication.request.ODataStreamer; import org.apache.olingo.client.api.communication.request.batch.ODataBatchRequest; import org.apache.olingo.client.api.communication.response.ODataResponse; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpMethod; /** @@ -55,9 +55,9 @@ public abstract class AbstractODataBasicRequest } @Override - public void setFormat(final ODataFormat format) { - if (format != null) { - final String formatString = format.getContentType().toContentTypeString(); + public void setFormat(final ContentType contentType) { + if (contentType != null) { + final String formatString = contentType.toContentTypeString(); setAccept(formatString); setContentType(formatString); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java index bdfd11831..4037a6f41 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java @@ -41,7 +41,7 @@ import org.apache.olingo.client.api.communication.request.ODataStreamer; import org.apache.olingo.client.api.communication.response.ODataResponse; import org.apache.olingo.client.api.http.HttpClientException; import org.apache.olingo.commons.api.ODataRuntimeException; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpMethod; /** @@ -102,7 +102,7 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD this.request = odataClient.getConfiguration().getHttpUriRequestFactory().create(this.method, uri); } - public abstract ODataFormat getDefaultFormat(); + public abstract ContentType getDefaultFormat(); @Override public URI getURI() { @@ -178,7 +178,7 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD public String getAccept() { final String acceptHead = odataHeaders.getHeader(HeaderName.accept); return StringUtils.isBlank(acceptHead) - ? getDefaultFormat().getContentType().toContentTypeString() + ? getDefaultFormat().toContentTypeString() : acceptHead; } @@ -201,7 +201,7 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD public String getContentType() { final String contentTypeHead = odataHeaders.getHeader(HeaderName.contentType); return StringUtils.isBlank(contentTypeHead) - ? getDefaultFormat().getContentType().toContentTypeString() + ? getDefaultFormat().toContentTypeString() : contentTypeHead; } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataDeleteRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataDeleteRequestImpl.java index 35f51185a..245c9b548 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataDeleteRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataDeleteRequestImpl.java @@ -28,7 +28,7 @@ import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest import org.apache.olingo.client.api.communication.response.ODataDeleteResponse; import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest; import org.apache.olingo.client.core.communication.response.AbstractODataResponse; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpMethod; /** @@ -42,7 +42,7 @@ public class ODataDeleteRequestImpl extends AbstractODataBasicRequest } @Override - public ODataFormat getDefaultFormat() { + public ContentType getDefaultFormat() { return odataClient.getConfiguration().getDefaultPubFormat(); } @Override protected InputStream getPayload() { try { - return odataClient.getWriter().writeEntity(entity, ODataFormat.fromString(getContentType())); + return odataClient.getWriter().writeEntity(entity, ContentType.parse(getContentType())); } catch (final ODataSerializerException e) { throw new IllegalArgumentException(e); } @@ -112,7 +112,7 @@ public class ODataEntityCreateRequestImpl public E getBody() { if (resEntity == null) { try { - final ResWrap resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())). + final ResWrap resource = odataClient.getDeserializer(ContentType.parse(getAccept())). toEntity(getRawResponse()); resEntity = (E) odataClient.getBinder().getODataEntity(resource); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java index 195eaeba2..e0b5d2c28 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java @@ -29,13 +29,13 @@ import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest; import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse; +import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest; import org.apache.olingo.client.core.communication.response.AbstractODataResponse; import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.client.api.domain.ClientEntity; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpMethod; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; import org.apache.olingo.commons.api.serialization.ODataSerializerException; @@ -70,14 +70,14 @@ public class ODataEntityUpdateRequestImpl } @Override - public ODataFormat getDefaultFormat() { + public ContentType getDefaultFormat() { return odataClient.getConfiguration().getDefaultPubFormat(); } @Override protected InputStream getPayload() { try { - return odataClient.getWriter().writeEntity(changes, ODataFormat.fromString(getContentType())); + return odataClient.getWriter().writeEntity(changes, ContentType.parse(getContentType())); } catch (final ODataSerializerException e) { throw new IllegalArgumentException(e); } @@ -122,7 +122,7 @@ public class ODataEntityUpdateRequestImpl public E getBody() { if (entity == null) { try { - final ResWrap resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())). + final ResWrap resource = odataClient.getDeserializer(ContentType.parse(getAccept())). toEntity(getRawResponse()); entity = (E) odataClient.getBinder().getODataEntity(resource); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java index a88652fe3..9166a1269 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java @@ -28,13 +28,13 @@ import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.communication.request.cud.ODataPropertyUpdateRequest; import org.apache.olingo.client.api.communication.response.ODataPropertyUpdateResponse; +import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest; import org.apache.olingo.client.core.communication.response.AbstractODataResponse; import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.client.api.domain.ClientProperty; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpMethod; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; import org.apache.olingo.commons.api.serialization.ODataSerializerException; @@ -67,7 +67,7 @@ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())). + final ResWrap resource = odataClient.getDeserializer(ContentType.parse(getAccept())). toProperty(getRawResponse()); resProperty = odataClient.getBinder().getODataProperty(resource); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataReferenceAddingRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataReferenceAddingRequestImpl.java index 477a91a89..592509e53 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataReferenceAddingRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataReferenceAddingRequestImpl.java @@ -33,7 +33,7 @@ import org.apache.olingo.client.core.communication.request.AbstractODataBasicReq import org.apache.olingo.client.core.communication.response.AbstractODataResponse; import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpMethod; import org.apache.olingo.commons.api.serialization.ODataSerializerException; @@ -54,7 +54,7 @@ public class ODataReferenceAddingRequestImpl extends AbstractODataBasicRequest } @Override - public ODataFormat getDefaultFormat() { + public ContentType getDefaultFormat() { return odataClient.getConfiguration().getDefaultPubFormat(); } - private String getActualFormat(final ODataFormat format) { - return ((ClientProperty.class.isAssignableFrom(reference) && format == ODataFormat.ATOM) - ? ODataFormat.XML : format).getContentType().toContentTypeString(); + private String getActualFormat(final ContentType contentType) { + return ((ClientProperty.class.isAssignableFrom(reference) && contentType.getODataFormat() == Format.ATOM) + ? ContentType.APPLICATION_XML : contentType).toContentTypeString(); } @Override - public void setFormat(final ODataFormat format) { - final String _format = getActualFormat(format); - setAccept(_format); - setContentType(_format); + public void setFormat(final ContentType contentType) { + final String _contentType = getActualFormat(contentType); + setAccept(_contentType); + setContentType(_contentType); } - protected abstract ODataFormat getPOSTParameterFormat(); + protected abstract ContentType getPOSTParameterFormat(); @Override protected InputStream getPayload() { @@ -197,13 +198,13 @@ public abstract class AbstractODataInvokeRequest final InputStream responseStream = this.payload == null ? res.getEntity().getContent() : this.payload; if (ClientEntitySet.class.isAssignableFrom(reference)) { invokeResult = reference.cast(odataClient.getReader().readEntitySet(responseStream, - ODataFormat.fromString(getContentType()))); + ContentType.parse(getContentType()))); } else if (ClientEntity.class.isAssignableFrom(reference)) { invokeResult = reference.cast(odataClient.getReader().readEntity(responseStream, - ODataFormat.fromString(getContentType()))); + ContentType.parse(getContentType()))); } else if (ClientProperty.class.isAssignableFrom(reference)) { invokeResult = reference.cast(odataClient.getReader().readProperty(responseStream, - ODataFormat.fromString(getContentType()))); + ContentType.parse(getContentType()))); } } } catch (IOException e) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/ODataInvokeRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/ODataInvokeRequestImpl.java index 5e8736e9b..6d6cc01e5 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/ODataInvokeRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/ODataInvokeRequestImpl.java @@ -22,12 +22,12 @@ import java.net.URI; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.domain.ClientInvokeResult; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpMethod; public class ODataInvokeRequestImpl extends AbstractODataInvokeRequest { - private ODataFormat format; + private ContentType contentType; public ODataInvokeRequestImpl(final ODataClient odataClient, final Class reference, final HttpMethod method, final URI uri) { @@ -36,13 +36,13 @@ public class ODataInvokeRequestImpl extends Abstra } @Override - public void setFormat(final ODataFormat format) { - super.setFormat(format); - this.format = format; + public void setFormat(final ContentType contentType) { + super.setFormat(contentType); + this.contentType = contentType; } @Override - protected ODataFormat getPOSTParameterFormat() { - return format == null ? getDefaultFormat() : format; + protected ContentType getPOSTParameterFormat() { + return contentType == null ? getDefaultFormat() : contentType; } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractMetadataRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractMetadataRequestImpl.java index 3cdd34963..201a662c5 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractMetadataRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractMetadataRequestImpl.java @@ -23,7 +23,6 @@ import java.net.URI; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.communication.request.ODataRequest; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; public abstract class AbstractMetadataRequestImpl extends AbstractODataRetrieveRequest { @@ -34,8 +33,8 @@ public abstract class AbstractMetadataRequestImpl extends AbstractODataRetrie } @Override - public ODataFormat getDefaultFormat() { - return ODataFormat.XML; + public ContentType getDefaultFormat() { + return ContentType.APPLICATION_XML; } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataDeltaRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataDeltaRequestImpl.java index 601e4bae0..1680940a8 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataDeltaRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataDeltaRequestImpl.java @@ -26,11 +26,11 @@ import org.apache.http.client.HttpClient; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.communication.request.retrieve.ODataDeltaRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; +import org.apache.olingo.client.api.domain.ClientDelta; import org.apache.olingo.client.api.http.HttpClientException; import org.apache.olingo.commons.api.data.Delta; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.client.api.domain.ClientDelta; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest @@ -41,7 +41,7 @@ public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())). + final ResWrap resource = odataClient.getDeserializer(ContentType.parse(getContentType())). toDelta(res.getEntity().getContent()); delta = odataClient.getBinder().getODataDelta(resource); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java index 57acf2af4..7e3518956 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java @@ -25,10 +25,10 @@ import org.apache.http.client.HttpClient; import org.apache.olingo.client.api.ODataClient; 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.domain.ClientEntity; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.client.api.domain.ClientEntity; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; /** @@ -48,7 +48,7 @@ public class ODataEntityRequestImpl } @Override - public ODataFormat getDefaultFormat() { + public ContentType getDefaultFormat() { return odataClient.getConfiguration().getDefaultPubFormat(); } @@ -75,7 +75,7 @@ public class ODataEntityRequestImpl public E getBody() { if (entity == null) { try { - final ResWrap resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())). + final ResWrap resource = odataClient.getDeserializer(ContentType.parse(getContentType())). toEntity(getRawResponse()); entity = (E) odataClient.getBinder().getODataEntity(resource); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java index dcb31e9c5..db390a0df 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java @@ -25,10 +25,10 @@ import org.apache.http.client.HttpClient; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetIteratorRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; -import org.apache.olingo.client.api.domain.ClientEntitySetIterator; import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientEntitySet; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.client.api.domain.ClientEntitySetIterator; +import org.apache.olingo.commons.api.format.ContentType; /** * This class implements an OData EntitySet query request. @@ -50,7 +50,7 @@ public class ODataEntitySetIteratorRequestImpl getBody() { if (entitySetIterator == null) { entitySetIterator = new ClientEntitySetIterator( - odataClient, getRawResponse(), ODataFormat.fromString(getContentType())); + odataClient, getRawResponse(), ContentType.parse(getContentType())); } return entitySetIterator; } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java index 620a88df3..6779f52ab 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java @@ -25,10 +25,10 @@ import org.apache.http.client.HttpClient; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; +import org.apache.olingo.client.api.domain.ClientEntitySet; import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.client.api.domain.ClientEntitySet; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; /** @@ -52,7 +52,7 @@ public class ODataEntitySetRequestImpl } @Override - public ODataFormat getDefaultFormat() { + public ContentType getDefaultFormat() { return odataClient.getConfiguration().getDefaultPubFormat(); } @@ -79,7 +79,7 @@ public class ODataEntitySetRequestImpl if (entitySet == null) { try { final ResWrap resource = - odataClient.getDeserializer(ODataFormat.fromString(getContentType())). + odataClient.getDeserializer(ContentType.parse(getContentType())). toEntitySet(getRawResponse()); entitySet = (ES) odataClient.getBinder().getODataEntitySet(resource); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataMediaRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataMediaRequestImpl.java index 7c7c34c1f..3f32f1b2c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataMediaRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataMediaRequestImpl.java @@ -28,7 +28,7 @@ import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.communication.request.retrieve.ODataMediaRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.http.HttpClientException; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; /** * This class implements an OData media query request. @@ -44,12 +44,12 @@ public class ODataMediaRequestImpl extends AbstractODataRetrieveRequest } @Override - public ODataFormat getDefaultFormat() { + public ContentType getDefaultFormat() { return odataClient.getConfiguration().getDefaultFormat(); } @@ -75,7 +75,7 @@ public class ODataPropertyRequestImpl public T getBody() { if (property == null) { try { - final ResWrap resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())) + final ResWrap resource = odataClient.getDeserializer(ContentType.parse(getContentType())) .toProperty(res.getEntity().getContent()); property = (T) odataClient.getBinder().getODataProperty(resource); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java index 4c22c312f..4ea6c61e1 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java @@ -31,7 +31,7 @@ import org.apache.olingo.client.api.communication.response.ODataRawResponse; import org.apache.olingo.client.core.communication.request.AbstractODataRequest; import org.apache.olingo.client.core.communication.response.AbstractODataResponse; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpMethod; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; @@ -51,7 +51,7 @@ public class ODataRawRequestImpl extends AbstractODataRequest implements ODataRa } @Override - public ODataFormat getDefaultFormat() { + public ContentType getDefaultFormat() { return odataClient.getConfiguration().getDefaultPubFormat(); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java index 363ba8741..e8fc2aad8 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java @@ -26,9 +26,9 @@ import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.data.ServiceDocument; -import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.client.api.domain.ClientServiceDocument; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.data.ResWrap; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; /** @@ -48,7 +48,7 @@ public class ODataServiceDocumentRequestImpl extends AbstractODataRetrieveReques } @Override - public ODataFormat getDefaultFormat() { + public ContentType getDefaultFormat() { return odataClient.getConfiguration().getDefaultFormat(); } @@ -76,7 +76,7 @@ public class ODataServiceDocumentRequestImpl extends AbstractODataRetrieveReques if (serviceDocument == null) { try { final ResWrap resource = odataClient. - getDeserializer(ODataFormat.fromString(getContentType())).toServiceDocument(getRawResponse()); + getDeserializer(ContentType.parse(getContentType())).toServiceDocument(getRawResponse()); serviceDocument = odataClient.getBinder().getODataServiceDocument(resource.getPayload()); } catch (final ODataDeserializerException e) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataValueRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataValueRequestImpl.java index 9bbce7c7f..229ab1a8c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataValueRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataValueRequestImpl.java @@ -26,10 +26,11 @@ import org.apache.http.client.HttpClient; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; -import org.apache.olingo.client.api.http.HttpClientException; import org.apache.olingo.client.api.domain.ClientPrimitiveValue; +import org.apache.olingo.client.api.http.HttpClientException; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; +import org.apache.olingo.commons.api.format.Format; /** * This class implements an OData entity property value query request. @@ -48,7 +49,7 @@ public class ODataValueRequestImpl extends AbstractODataRetrieveRequest implements ODataStreamedEntityRequest { - private ODataFormat format; + private ContentType contentType; /** * Constructor. @@ -50,17 +50,17 @@ public abstract class AbstractODataStreamedEntityRequest toServiceDocument(final InputStream input) throws ODataDeserializerException { - return format == ODataFormat.XML ? + return contentType.getODataFormat() == Format.XML ? new XMLServiceDocumentDeserializer(false).toServiceDocument(input) : new JSONServiceDocumentDeserializer(false).toServiceDocument(input); } @@ -130,7 +131,7 @@ public class ClientODataDeserializerImpl implements ClientODataDeserializer { @Override public ResWrap toDelta(final InputStream input) throws ODataDeserializerException { try { - return format == ODataFormat.ATOM ? + return contentType.getODataFormat() == Format.ATOM ? new AtomDeserializer().delta(input) : new JsonDeltaDeserializer(false).toDelta(input); } catch (XMLStreamException e) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java index adecc20a6..8a84d952c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java @@ -30,25 +30,6 @@ import org.apache.olingo.client.api.EdmEnabledODataClient; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.data.ServiceDocument; import org.apache.olingo.client.api.data.ServiceDocumentItem; -import org.apache.olingo.client.api.serialization.ODataBinder; -import org.apache.olingo.client.core.uri.URIUtils; -import org.apache.olingo.commons.api.Constants; -import org.apache.olingo.commons.api.data.Annotatable; -import org.apache.olingo.commons.api.data.Annotation; -import org.apache.olingo.commons.api.data.ComplexValue; -import org.apache.olingo.commons.api.data.ContextURL; -import org.apache.olingo.commons.api.data.DeletedEntity; -import org.apache.olingo.commons.api.data.Delta; -import org.apache.olingo.commons.api.data.DeltaLink; -import org.apache.olingo.commons.api.data.Entity; -import org.apache.olingo.commons.api.data.EntityCollection; -import org.apache.olingo.commons.api.data.Link; -import org.apache.olingo.commons.api.data.Linked; -import org.apache.olingo.commons.api.data.Operation; -import org.apache.olingo.commons.api.data.Property; -import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Valuable; -import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.client.api.domain.ClientAnnotatable; import org.apache.olingo.client.api.domain.ClientAnnotation; import org.apache.olingo.client.api.domain.ClientCollectionValue; @@ -68,6 +49,29 @@ import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.domain.ClientServiceDocument; import org.apache.olingo.client.api.domain.ClientValuable; import org.apache.olingo.client.api.domain.ClientValue; +import org.apache.olingo.client.api.serialization.ODataBinder; +import org.apache.olingo.client.core.domain.ClientAnnotationImpl; +import org.apache.olingo.client.core.domain.ClientDeletedEntityImpl; +import org.apache.olingo.client.core.domain.ClientDeltaLinkImpl; +import org.apache.olingo.client.core.domain.ClientPropertyImpl; +import org.apache.olingo.client.core.uri.URIUtils; +import org.apache.olingo.commons.api.Constants; +import org.apache.olingo.commons.api.data.Annotatable; +import org.apache.olingo.commons.api.data.Annotation; +import org.apache.olingo.commons.api.data.ComplexValue; +import org.apache.olingo.commons.api.data.ContextURL; +import org.apache.olingo.commons.api.data.DeletedEntity; +import org.apache.olingo.commons.api.data.Delta; +import org.apache.olingo.commons.api.data.DeltaLink; +import org.apache.olingo.commons.api.data.Entity; +import org.apache.olingo.commons.api.data.EntityCollection; +import org.apache.olingo.commons.api.data.Link; +import org.apache.olingo.commons.api.data.Linked; +import org.apache.olingo.commons.api.data.Operation; +import org.apache.olingo.commons.api.data.Property; +import org.apache.olingo.commons.api.data.ResWrap; +import org.apache.olingo.commons.api.data.Valuable; +import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmBindingTarget; import org.apache.olingo.commons.api.edm.EdmComplexType; @@ -86,14 +90,10 @@ import org.apache.olingo.commons.api.edm.EdmTerm; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.geo.Geospatial; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataSerializerException; -import org.apache.olingo.client.core.domain.ClientAnnotationImpl; -import org.apache.olingo.client.core.domain.ClientDeletedEntityImpl; -import org.apache.olingo.client.core.domain.ClientDeltaLinkImpl; -import org.apache.olingo.client.core.domain.ClientPropertyImpl; -import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; import org.apache.olingo.commons.core.edm.EdmTypeInfo; +import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; import org.apache.olingo.commons.core.serialization.ContextURLParser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -392,7 +392,7 @@ public class ODataBinderImpl implements ODataBinder { if (LOG.isDebugEnabled()) { final StringWriter writer = new StringWriter(); try { - client.getSerializer(ODataFormat.JSON).write(writer, resource.getPayload()); + client.getSerializer(ContentType.JSON).write(writer, resource.getPayload()); } catch (final ODataSerializerException e) { LOG.debug("EntitySet -> ODataEntitySet:\n{}", writer.toString()); } @@ -589,7 +589,7 @@ public class ODataBinderImpl implements ODataBinder { if (LOG.isDebugEnabled()) { final StringWriter writer = new StringWriter(); try { - client.getSerializer(ODataFormat.JSON).write(writer, resource.getPayload()); + client.getSerializer(ContentType.JSON).write(writer, resource.getPayload()); } catch (final ODataSerializerException e) { LOG.debug("EntityResource -> ODataEntity:\n{}", writer.toString()); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java index 6c97cdb2e..17436e9f9 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java @@ -25,24 +25,24 @@ import java.util.Map; import org.apache.commons.io.IOUtils; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.data.ServiceDocument; +import org.apache.olingo.client.api.domain.ClientEntity; +import org.apache.olingo.client.api.domain.ClientEntitySet; import org.apache.olingo.client.api.domain.ClientEntitySetIterator; +import org.apache.olingo.client.api.domain.ClientProperty; +import org.apache.olingo.client.api.domain.ClientServiceDocument; +import org.apache.olingo.client.api.domain.ClientValue; import org.apache.olingo.client.api.edm.xml.XMLMetadata; import org.apache.olingo.client.api.serialization.ODataReader; import org.apache.olingo.client.core.edm.ClientCsdlEdmProvider; +import org.apache.olingo.commons.api.ODataError; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.client.api.domain.ClientEntity; -import org.apache.olingo.client.api.domain.ClientEntitySet; -import org.apache.olingo.commons.api.ODataError; -import org.apache.olingo.client.api.domain.ClientProperty; -import org.apache.olingo.client.api.domain.ClientServiceDocument; -import org.apache.olingo.client.api.domain.ClientValue; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.provider.CsdlSchema; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; import org.apache.olingo.commons.core.edm.EdmProviderImpl; import org.slf4j.Logger; @@ -63,7 +63,7 @@ public class ODataReaderImpl implements ODataReader { @Override public Edm readMetadata(final InputStream input) { - return readMetadata(client.getDeserializer(ODataFormat.XML).toMetadata(input).getSchemaByNsOrAlias()); + return readMetadata(client.getDeserializer(ContentType.APPLICATION_XML).toMetadata(input).getSchemaByNsOrAlias()); } @Override @@ -73,16 +73,16 @@ public class ODataReaderImpl implements ODataReader { } @Override - public ClientServiceDocument readServiceDocument(final InputStream input, final ODataFormat format) + public ClientServiceDocument readServiceDocument(final InputStream input, final ContentType contentType) throws ODataDeserializerException { return client.getBinder().getODataServiceDocument( - client.getDeserializer(format).toServiceDocument(input).getPayload()); + client.getDeserializer(contentType).toServiceDocument(input).getPayload()); } @Override - public ODataError readError(final InputStream inputStream, final ODataFormat format) + public ODataError readError(final InputStream inputStream, final ContentType contentType) throws ODataDeserializerException { - return client.getDeserializer(format).toError(inputStream); + return client.getDeserializer(contentType).toError(inputStream); } @Override @@ -96,22 +96,22 @@ public class ODataReaderImpl implements ODataReader { (URI) null, null, reference.cast(new ClientEntitySetIterator( - client, src, ODataFormat.fromString(format)))); + client, src, ContentType.parse(format)))); } else if (ClientEntitySet.class.isAssignableFrom(reference)) { - final ResWrap resource = client.getDeserializer(ODataFormat.fromString(format)) + final ResWrap resource = client.getDeserializer(ContentType.parse(format)) .toEntitySet(src); res = new ResWrap( resource.getContextURL(), resource.getMetadataETag(), reference.cast(client.getBinder().getODataEntitySet(resource))); } else if (ClientEntity.class.isAssignableFrom(reference)) { - final ResWrap container = client.getDeserializer(ODataFormat.fromString(format)).toEntity(src); + final ResWrap container = client.getDeserializer(ContentType.parse(format)).toEntity(src); res = new ResWrap( container.getContextURL(), container.getMetadataETag(), reference.cast(client.getBinder().getODataEntity(container))); } else if (ClientProperty.class.isAssignableFrom(reference)) { - final ResWrap container = client.getDeserializer(ODataFormat.fromString(format)).toProperty(src); + final ResWrap container = client.getDeserializer(ContentType.parse(format)).toProperty(src); res = new ResWrap( container.getContextURL(), container.getMetadataETag(), @@ -121,7 +121,7 @@ public class ODataReaderImpl implements ODataReader { (URI) null, null, reference.cast(client.getObjectFactory().newPrimitiveValueBuilder(). - setType(ODataFormat.fromString(format) == ODataFormat.TEXT_PLAIN + setType(ContentType.parse(format).equals(ContentType.TEXT_PLAIN) ? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream). setValue(IOUtils.toString(src)) // TODO: set correct value .build())); @@ -132,7 +132,7 @@ public class ODataReaderImpl implements ODataReader { reference.cast(readMetadata(src))); } else if (ClientServiceDocument.class.isAssignableFrom(reference)) { final ResWrap resource = - client.getDeserializer(ODataFormat.fromString(format)).toServiceDocument(src); + client.getDeserializer(ContentType.parse(format)).toServiceDocument(src); res = new ResWrap( resource.getContextURL(), resource.getMetadataETag(), @@ -141,7 +141,7 @@ public class ODataReaderImpl implements ODataReader { res = new ResWrap( (URI) null, null, - reference.cast(readError(src, ODataFormat.fromString(format)))); + reference.cast(readError(src, ContentType.parse(format)))); } else { throw new IllegalArgumentException("Invalid reference type " + reference); } @@ -158,20 +158,20 @@ public class ODataReaderImpl implements ODataReader { } @Override - public ClientEntitySet readEntitySet(final InputStream input, final ODataFormat format) + public ClientEntitySet readEntitySet(final InputStream input, final ContentType contentType) throws ODataDeserializerException { - return client.getBinder().getODataEntitySet(client.getDeserializer(format).toEntitySet(input)); + return client.getBinder().getODataEntitySet(client.getDeserializer(contentType).toEntitySet(input)); } @Override - public ClientEntity readEntity(final InputStream input, final ODataFormat format) + public ClientEntity readEntity(final InputStream input, final ContentType contentType) throws ODataDeserializerException { - return client.getBinder().getODataEntity(client.getDeserializer(format).toEntity(input)); + return client.getBinder().getODataEntity(client.getDeserializer(contentType).toEntity(input)); } @Override - public ClientProperty readProperty(final InputStream input, final ODataFormat format) + public ClientProperty readProperty(final InputStream input, final ContentType contentType) throws ODataDeserializerException { - return client.getBinder().getODataProperty(client.getDeserializer(format).toProperty(input)); + return client.getBinder().getODataProperty(client.getDeserializer(contentType).toProperty(input)); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataWriterImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataWriterImpl.java index c891f1e14..fe93cb1e2 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataWriterImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataWriterImpl.java @@ -29,13 +29,13 @@ import java.util.Collections; import org.apache.commons.io.IOUtils; import org.apache.olingo.client.api.ODataClient; -import org.apache.olingo.client.api.serialization.ODataWriter; -import org.apache.olingo.commons.api.Constants; -import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientLink; import org.apache.olingo.client.api.domain.ClientProperty; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.client.api.serialization.ODataWriter; +import org.apache.olingo.commons.api.Constants; +import org.apache.olingo.commons.api.data.ResWrap; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataSerializerException; public class ODataWriterImpl implements ODataWriter { @@ -47,7 +47,7 @@ public class ODataWriterImpl implements ODataWriter { } @Override - public InputStream writeEntities(final Collection entities, final ODataFormat format) + public InputStream writeEntities(final Collection entities, final ContentType contentType) throws ODataSerializerException { ByteArrayOutputStream output = new ByteArrayOutputStream(); OutputStreamWriter writer; @@ -58,7 +58,7 @@ public class ODataWriterImpl implements ODataWriter { } try { for (ClientEntity entity : entities) { - client.getSerializer(format).write(writer, client.getBinder().getEntity(entity)); + client.getSerializer(contentType).write(writer, client.getBinder().getEntity(entity)); } return new ByteArrayInputStream(output.toByteArray()); @@ -68,13 +68,13 @@ public class ODataWriterImpl implements ODataWriter { } @Override - public InputStream writeEntity(final ClientEntity entity, final ODataFormat format) + public InputStream writeEntity(final ClientEntity entity, final ContentType contentType) throws ODataSerializerException { - return writeEntities(Collections.singleton(entity), format); + return writeEntities(Collections.singleton(entity), contentType); } @Override - public InputStream writeProperty(final ClientProperty property, final ODataFormat format) + public InputStream writeProperty(final ClientProperty property, final ContentType contentType) throws ODataSerializerException { final ByteArrayOutputStream output = new ByteArrayOutputStream(); OutputStreamWriter writer; @@ -84,7 +84,7 @@ public class ODataWriterImpl implements ODataWriter { writer = null; } try { - client.getSerializer(format).write(writer, client.getBinder().getProperty(property)); + client.getSerializer(contentType).write(writer, client.getBinder().getProperty(property)); return new ByteArrayInputStream(output.toByteArray()); } finally { @@ -93,7 +93,7 @@ public class ODataWriterImpl implements ODataWriter { } @Override - public InputStream writeLink(final ClientLink link, final ODataFormat format) throws ODataSerializerException { + public InputStream writeLink(final ClientLink link, final ContentType contentType) throws ODataSerializerException { final ByteArrayOutputStream output = new ByteArrayOutputStream(); OutputStreamWriter writer; try { @@ -102,7 +102,7 @@ public class ODataWriterImpl implements ODataWriter { writer = null; } try { - client.getSerializer(format).write(writer, client.getBinder().getLink(link)); + client.getSerializer(contentType).write(writer, client.getBinder().getLink(link)); return new ByteArrayInputStream(output.toByteArray()); } finally { @@ -111,7 +111,7 @@ public class ODataWriterImpl implements ODataWriter { } @Override - public InputStream writeReference(ResWrap reference, ODataFormat format) throws ODataSerializerException { + public InputStream writeReference(ResWrap reference, ContentType contenType) throws ODataSerializerException { final ByteArrayOutputStream output = new ByteArrayOutputStream(); OutputStreamWriter writer; @@ -122,7 +122,7 @@ public class ODataWriterImpl implements ODataWriter { } try { - client.getSerializer(format).write(writer, reference); + client.getSerializer(contenType).write(writer, reference); return new ByteArrayInputStream(output.toByteArray()); } finally { diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/AbstractTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/AbstractTest.java index c0a346a5a..ed21e2450 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/AbstractTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/AbstractTest.java @@ -19,7 +19,8 @@ package org.apache.olingo.client.core; import org.apache.olingo.client.api.ODataClient; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; +import org.apache.olingo.commons.api.format.Format; import org.custommonkey.xmlunit.XMLUnit; import org.junit.BeforeClass; @@ -43,7 +44,8 @@ public abstract class AbstractTest { v4Client = ODataClientFactory.getClient(); } - protected String getSuffix(final ODataFormat format) { - return format == ODataFormat.ATOM || format == ODataFormat.XML ? "xml" : "json"; + protected String getSuffix(final ContentType contentType) { + return contentType.getODataFormat() == Format.ATOM + || contentType.getODataFormat() == Format.XML ? "xml" : "json"; } } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/AtomTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/AtomTest.java index 3d445d81a..4618d3be5 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/AtomTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/AtomTest.java @@ -20,11 +20,8 @@ package org.apache.olingo.client.core.v4; import static org.junit.Assert.assertTrue; -import org.apache.commons.io.IOUtils; -import org.apache.olingo.client.api.ODataClient; -import org.apache.olingo.client.core.AtomLinksQualifier; -import org.apache.olingo.commons.api.format.ODataFormat; -import org.custommonkey.xmlunit.Diff; +import java.io.ByteArrayInputStream; +import java.io.StringWriter; import javax.xml.transform.Source; import javax.xml.transform.Transformer; @@ -32,8 +29,11 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; -import java.io.ByteArrayInputStream; -import java.io.StringWriter; +import org.apache.commons.io.IOUtils; +import org.apache.olingo.client.api.ODataClient; +import org.apache.olingo.client.core.AtomLinksQualifier; +import org.apache.olingo.commons.api.format.ContentType; +import org.custommonkey.xmlunit.Diff; public class AtomTest extends JSONTest { @@ -43,13 +43,13 @@ public class AtomTest extends JSONTest { } @Override - protected ODataFormat getODataPubFormat() { - return ODataFormat.ATOM; + protected ContentType getODataPubFormat() { + return ContentType.APPLICATION_ATOM_XML; } @Override - protected ODataFormat getODataFormat() { - return ODataFormat.XML; + protected ContentType getODataFormat() { + return ContentType.APPLICATION_XML; } private String cleanup(final String input) throws Exception { diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java index 5395472f9..e64d15851 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java @@ -18,23 +18,23 @@ */ package org.apache.olingo.client.core.v4; -import org.apache.olingo.client.api.ODataClient; -import org.apache.olingo.client.core.AbstractTest; -import org.apache.olingo.commons.api.data.EntityCollection; -import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.client.api.domain.ClientEntity; -import org.apache.olingo.client.api.domain.ClientEntitySet; -import org.apache.olingo.commons.api.format.ODataFormat; -import org.apache.olingo.commons.api.serialization.ODataDeserializerException; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import org.apache.olingo.client.api.ODataClient; +import org.apache.olingo.client.api.domain.ClientEntity; +import org.apache.olingo.client.api.domain.ClientEntitySet; +import org.apache.olingo.client.core.AbstractTest; +import org.apache.olingo.commons.api.data.EntityCollection; +import org.apache.olingo.commons.api.data.ResWrap; +import org.apache.olingo.commons.api.format.ContentType; +import org.apache.olingo.commons.api.serialization.ODataDeserializerException; +import org.junit.Test; public class EntitySetTest extends AbstractTest { @@ -43,10 +43,10 @@ public class EntitySetTest extends AbstractTest { return v4Client; } - private void read(final ODataFormat format) throws IOException, ODataDeserializerException { - final InputStream input = getClass().getResourceAsStream("Customers." + getSuffix(format)); + private void read(final ContentType contentType) throws IOException, ODataDeserializerException { + final InputStream input = getClass().getResourceAsStream("Customers." + getSuffix(contentType)); final ClientEntitySet entitySet = getClient().getBinder().getODataEntitySet( - getClient().getDeserializer(format).toEntitySet(input)); + getClient().getDeserializer(contentType).toEntitySet(input)); assertNotNull(entitySet); assertEquals(2, entitySet.getEntities().size()); @@ -60,18 +60,18 @@ public class EntitySetTest extends AbstractTest { @Test public void fromAtom() throws Exception { - read(ODataFormat.ATOM); + read(ContentType.APPLICATION_ATOM_XML); } @Test public void fromJSON() throws Exception { - read(ODataFormat.JSON); + read(ContentType.JSON); } - private void ref(final ODataFormat format) throws ODataDeserializerException { - final InputStream input = getClass().getResourceAsStream("collectionOfEntityReferences." + getSuffix(format)); + private void ref(final ContentType contentType) throws ODataDeserializerException { + final InputStream input = getClass().getResourceAsStream("collectionOfEntityReferences." + getSuffix(contentType)); final ClientEntitySet entitySet = getClient().getBinder().getODataEntitySet( - getClient().getDeserializer(format).toEntitySet(input)); + getClient().getDeserializer(contentType).toEntitySet(input)); assertNotNull(entitySet); for (ClientEntity entity : entitySet.getEntities()) { @@ -87,11 +87,11 @@ public class EntitySetTest extends AbstractTest { @Test public void atomRef() throws Exception { - ref(ODataFormat.ATOM); + ref(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonRef() throws Exception { - ref(ODataFormat.JSON); + ref(ContentType.JSON); } } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java index 7373da6f7..98ba7f916 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java @@ -29,10 +29,6 @@ import java.util.Iterator; import org.apache.olingo.client.api.EdmEnabledODataClient; import org.apache.olingo.client.api.ODataClient; -import org.apache.olingo.client.core.AbstractTest; -import org.apache.olingo.client.core.EdmEnabledODataClientImpl; -import org.apache.olingo.commons.api.data.Entity; -import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.client.api.domain.ClientAnnotation; import org.apache.olingo.client.api.domain.ClientComplexValue; import org.apache.olingo.client.api.domain.ClientEntity; @@ -42,9 +38,14 @@ import org.apache.olingo.client.api.domain.ClientLinkType; import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.domain.ClientValuable; import org.apache.olingo.client.api.domain.ClientValue; +import org.apache.olingo.client.core.AbstractTest; +import org.apache.olingo.client.core.EdmEnabledODataClientImpl; +import org.apache.olingo.commons.api.data.Entity; +import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; +import org.apache.olingo.commons.api.format.Format; import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset; import org.apache.olingo.commons.core.edm.primitivetype.EdmDuration; import org.junit.Ignore; @@ -78,10 +79,10 @@ public class EntityTest extends AbstractTest { }; } - private void singleton(final ODataFormat format) throws Exception { - final InputStream input = getClass().getResourceAsStream("VipCustomer." + getSuffix(format)); + private void singleton(final ContentType contentType) throws Exception { + final InputStream input = getClass().getResourceAsStream("VipCustomer." + getSuffix(contentType)); final ClientEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer(format).toEntity(input)); + getClient().getDeserializer(contentType).toEntity(input)); assertNotNull(entity); assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString()); @@ -102,7 +103,7 @@ public class EntityTest extends AbstractTest { } if ("Orders".equals(link.getName())) { checked++; - if (format == ODataFormat.ATOM) { + if (contentType.getODataFormat() == Format.ATOM) { assertEquals(ClientLinkType.ENTITY_SET_NAVIGATION, link.getType()); } } @@ -129,18 +130,18 @@ public class EntityTest extends AbstractTest { @Test public void atomSingleton() throws Exception { - singleton(ODataFormat.ATOM); + singleton(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonSingleton() throws Exception { - singleton(ODataFormat.JSON_FULL_METADATA); + singleton(ContentType.JSON_FULL_METADATA); } - private void withEnums(final ODataFormat format) throws Exception { - final InputStream input = getClass().getResourceAsStream("Products_5." + getSuffix(format)); + private void withEnums(final ContentType contentType) throws Exception { + final InputStream input = getClass().getResourceAsStream("Products_5." + getSuffix(contentType)); final ClientEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer(format).toEntity(input)); + getClient().getDeserializer(contentType).toEntity(input)); assertNotNull(entity); final ClientProperty skinColor = entity.getProperty("SkinColor"); @@ -165,19 +166,19 @@ public class EntityTest extends AbstractTest { @Test public void atomWithEnums() throws Exception { - withEnums(ODataFormat.ATOM); + withEnums(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonWithEnums() throws Exception { - withEnums(ODataFormat.JSON_FULL_METADATA); + withEnums(ContentType.JSON_FULL_METADATA); } - private void withInlineEntitySet(final ODataFormat format) throws Exception { + private void withInlineEntitySet(final ContentType contentType) throws Exception { final InputStream input = getClass().getResourceAsStream( - "Accounts_101_expand_MyPaymentInstruments." + getSuffix(format)); + "Accounts_101_expand_MyPaymentInstruments." + getSuffix(contentType)); final ClientEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer(format).toEntity(input)); + getClient().getDeserializer(contentType).toEntity(input)); assertNotNull(entity); final ClientLink instruments = entity.getNavigationLink("MyPaymentInstruments"); @@ -200,19 +201,19 @@ public class EntityTest extends AbstractTest { @Test public void atomWithInlineEntitySet() throws Exception { - withInlineEntitySet(ODataFormat.ATOM); + withInlineEntitySet(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonWithInlineEntitySet() throws Exception { - withInlineEntitySet(ODataFormat.JSON_FULL_METADATA); + withInlineEntitySet(ContentType.JSON_FULL_METADATA); } - private void mediaEntity(final ODataFormat format) throws Exception { + private void mediaEntity(final ContentType contentType) throws Exception { final InputStream input = getClass().getResourceAsStream( - "Advertisements_f89dee73-af9f-4cd4-b330-db93c25ff3c7." + getSuffix(format)); + "Advertisements_f89dee73-af9f-4cd4-b330-db93c25ff3c7." + getSuffix(contentType)); final ClientEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer(format).toEntity(input)); + getClient().getDeserializer(contentType).toEntity(input)); assertNotNull(entity); assertTrue(entity.isMediaEntity()); @@ -227,18 +228,18 @@ public class EntityTest extends AbstractTest { @Test public void atomMediaEntity() throws Exception { - mediaEntity(ODataFormat.ATOM); + mediaEntity(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonMediaEntity() throws Exception { - mediaEntity(ODataFormat.JSON_FULL_METADATA); + mediaEntity(ContentType.JSON_FULL_METADATA); } - private void withStream(final ODataFormat format) throws Exception { - final InputStream input = getClass().getResourceAsStream("PersonDetails_1." + getSuffix(format)); + private void withStream(final ContentType contentType) throws Exception { + final InputStream input = getClass().getResourceAsStream("PersonDetails_1." + getSuffix(contentType)); final ClientEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer(format).toEntity(input)); + getClient().getDeserializer(contentType).toEntity(input)); assertNotNull(entity); assertFalse(entity.isMediaEntity()); @@ -254,18 +255,18 @@ public class EntityTest extends AbstractTest { @Test public void atomWithStream() throws Exception { - withStream(ODataFormat.ATOM); + withStream(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonWithStream() throws Exception { - withStream(ODataFormat.JSON_FULL_METADATA); + withStream(ContentType.JSON_FULL_METADATA); } - private void ref(final ODataFormat format) throws Exception { - final InputStream input = getClass().getResourceAsStream("entityReference." + getSuffix(format)); + private void ref(final ContentType contentType) throws Exception { + final InputStream input = getClass().getResourceAsStream("entityReference." + getSuffix(contentType)); final ClientEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer(format).toEntity(input)); + getClient().getDeserializer(contentType).toEntity(input)); assertNotNull(entity); assertNotNull(entity.getId()); @@ -278,18 +279,18 @@ public class EntityTest extends AbstractTest { @Test public void atomRef() throws Exception { - ref(ODataFormat.ATOM); + ref(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonRef() throws Exception { - ref(ODataFormat.JSON); + ref(ContentType.JSON); } - private void complexNavigationProperties(final ODataFormat format) throws Exception { - final InputStream input = getClass().getResourceAsStream("entity.withcomplexnavigation." + getSuffix(format)); + private void complexNavigationProperties(final ContentType contentType) throws Exception { + final InputStream input = getClass().getResourceAsStream("entity.withcomplexnavigation." + getSuffix(contentType)); final ClientEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer(format).toEntity(input)); + getClient().getDeserializer(contentType).toEntity(input)); assertNotNull(entity); final ClientComplexValue addressValue = entity.getProperty("Address").getComplexValue(); @@ -306,18 +307,18 @@ public class EntityTest extends AbstractTest { @Test public void atomComplexNavigationProperties() throws Exception { - complexNavigationProperties(ODataFormat.ATOM); + complexNavigationProperties(ContentType.APPLICATION_ATOM_XML); } @Test public void jsonComplexNavigationProperties() throws Exception { - complexNavigationProperties(ODataFormat.JSON); + complexNavigationProperties(ContentType.JSON); } - private void annotated(final ODataFormat format) throws EdmPrimitiveTypeException, Exception { - final InputStream input = getClass().getResourceAsStream("annotated." + getSuffix(format)); + private void annotated(final ContentType contentType) throws EdmPrimitiveTypeException, Exception { + final InputStream input = getClass().getResourceAsStream("annotated." + getSuffix(contentType)); final ClientEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer(format).toEntity(input)); + getClient().getDeserializer(contentType).toEntity(input)); assertNotNull(entity); assertFalse(entity.getAnnotations().isEmpty()); @@ -353,18 +354,18 @@ public class EntityTest extends AbstractTest { @Test @Ignore public void atomAnnotated() throws Exception { - annotated(ODataFormat.ATOM); + annotated(ContentType.APPLICATION_ATOM_XML); } @Test @Ignore public void jsonAnnotated() throws Exception { - annotated(ODataFormat.JSON); + annotated(ContentType.JSON); } - private void derived(final ODataClient client, final ODataFormat format) throws Exception { - final InputStream input = getClass().getResourceAsStream("Customer." + getSuffix(format)); - final ClientEntity entity = client.getBinder().getODataEntity(client.getDeserializer(format).toEntity(input)); + private void derived(final ODataClient client, final ContentType contentType) throws Exception { + final InputStream input = getClass().getResourceAsStream("Customer." + getSuffix(contentType)); + final ClientEntity entity = client.getBinder().getODataEntity(client.getDeserializer(contentType).toEntity(input)); assertNotNull(entity); assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString()); @@ -375,16 +376,16 @@ public class EntityTest extends AbstractTest { @Test public void derivedFromAtom() throws Exception { - derived(getClient(), ODataFormat.ATOM); + derived(getClient(), ContentType.APPLICATION_ATOM_XML); } @Test public void derivedFromJSON() throws Exception { - derived(getEdmEnabledClient(), ODataFormat.JSON); + derived(getEdmEnabledClient(), ContentType.JSON); } @Test public void derivedFromFullJSON() throws Exception { - derived(getClient(), ODataFormat.JSON_FULL_METADATA); + derived(getClient(), ContentType.JSON_FULL_METADATA); } } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java index 057c0de1b..7fd7c4557 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java @@ -18,16 +18,16 @@ */ package org.apache.olingo.client.core.v4; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.core.AbstractTest; import org.apache.olingo.commons.api.ODataError; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - public class ErrorTest extends AbstractTest { @Override @@ -35,15 +35,15 @@ public class ErrorTest extends AbstractTest { return v4Client; } - private ODataError error(final String name, final ODataFormat format) throws ODataDeserializerException { - final ODataError error = getClient().getDeserializer(format).toError( - getClass().getResourceAsStream(name + "." + getSuffix(format))); + private ODataError error(final String name, final ContentType contentType) throws ODataDeserializerException { + final ODataError error = getClient().getDeserializer(contentType).toError( + getClass().getResourceAsStream(name + "." + getSuffix(contentType))); assertNotNull(error); return error; } - private void simple(final ODataFormat format) throws ODataDeserializerException { - final ODataError error = error("error", format); + private void simple(final ContentType contentType) throws ODataDeserializerException { + final ODataError error = error("error", contentType); assertEquals("501", error.getCode()); assertEquals("Unsupported functionality", error.getMessage()); assertEquals("query", error.getTarget()); @@ -51,12 +51,12 @@ public class ErrorTest extends AbstractTest { @Test public void jsonSimple() throws Exception { - simple(ODataFormat.JSON); + simple(ContentType.JSON); } @Test public void atomSimple() throws Exception { - simple(ODataFormat.ATOM); + simple(ContentType.APPLICATION_ATOM_XML); } } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java index 83c495c59..87edec17d 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java @@ -31,16 +31,16 @@ import java.util.Map; import org.apache.commons.io.IOUtils; import org.apache.olingo.client.api.ODataClient; -import org.apache.olingo.client.core.AbstractTest; -import org.apache.olingo.commons.api.Constants; -import org.apache.olingo.commons.api.data.Delta; -import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.client.api.domain.ClientCollectionValue; import org.apache.olingo.client.api.domain.ClientComplexValue; import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientValue; +import org.apache.olingo.client.core.AbstractTest; +import org.apache.olingo.commons.api.Constants; +import org.apache.olingo.commons.api.data.Delta; +import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.junit.Test; import com.fasterxml.jackson.databind.JsonNode; @@ -56,12 +56,12 @@ public class JSONTest extends AbstractTest { return v4Client; } - protected ODataFormat getODataPubFormat() { - return ODataFormat.JSON; + protected ContentType getODataPubFormat() { + return ContentType.JSON; } - protected ODataFormat getODataFormat() { - return ODataFormat.JSON; + protected ContentType getODataFormat() { + return ContentType.JSON; } private void cleanup(final ObjectNode node) { @@ -128,12 +128,12 @@ public class JSONTest extends AbstractTest { assertEquals(expected, actualNode); } - protected void entitySet(final String filename, final ODataFormat format) throws Exception { + protected void entitySet(final String filename, final ContentType contentType) throws Exception { final StringWriter writer = new StringWriter(); - getClient().getSerializer(format).write(writer, getClient().getDeserializer(format).toEntitySet( - getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload()); + getClient().getSerializer(contentType).write(writer, getClient().getDeserializer(contentType).toEntitySet( + getClass().getResourceAsStream(filename + "." + getSuffix(contentType))).getPayload()); - assertSimilar(filename + "." + getSuffix(format), writer.toString()); + assertSimilar(filename + "." + getSuffix(contentType), writer.toString()); } @Test @@ -142,12 +142,12 @@ public class JSONTest extends AbstractTest { entitySet("collectionOfEntityReferences", getODataPubFormat()); } - protected void entity(final String filename, final ODataFormat format) throws Exception { + protected void entity(final String filename, final ContentType contentType) throws Exception { final StringWriter writer = new StringWriter(); - getClient().getSerializer(format).write(writer, getClient().getDeserializer(format).toEntity( - getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload()); + getClient().getSerializer(contentType).write(writer, getClient().getDeserializer(contentType).toEntity( + getClass().getResourceAsStream(filename + "." + getSuffix(contentType))).getPayload()); - assertSimilar(filename + "." + getSuffix(format), writer.toString()); + assertSimilar(filename + "." + getSuffix(contentType), writer.toString()); } @Test @@ -169,12 +169,12 @@ public class JSONTest extends AbstractTest { entity("annotated", getODataPubFormat()); } - protected void property(final String filename, final ODataFormat format) throws Exception { + protected void property(final String filename, final ContentType contentType) throws Exception { final StringWriter writer = new StringWriter(); - getClient().getSerializer(format).write(writer, getClient().getDeserializer(format). - toProperty(getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload()); + getClient().getSerializer(contentType).write(writer, getClient().getDeserializer(contentType). + toProperty(getClass().getResourceAsStream(filename + "." + getSuffix(contentType))).getPayload()); - assertSimilar(filename + "." + getSuffix(format), writer.toString()); + assertSimilar(filename + "." + getSuffix(contentType), writer.toString()); } @Test @@ -187,13 +187,13 @@ public class JSONTest extends AbstractTest { @Test public void crossjoin() throws Exception { - assertNotNull(getClient().getDeserializer(ODataFormat.JSON_FULL_METADATA).toEntitySet( + assertNotNull(getClient().getDeserializer(ContentType.JSON_FULL_METADATA).toEntitySet( getClass().getResourceAsStream("crossjoin.json"))); } - protected void delta(final String filename, final ODataFormat format) throws Exception { - final Delta delta = getClient().getDeserializer(format).toDelta( - getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload(); + protected void delta(final String filename, final ContentType contentType) throws Exception { + final Delta delta = getClient().getDeserializer(contentType).toDelta( + getClass().getResourceAsStream(filename + "." + getSuffix(contentType))).getPayload(); assertNotNull(delta); assertNotNull(delta.getDeltaLink()); assertEquals(5, delta.getCount(), 0); @@ -248,7 +248,7 @@ public class JSONTest extends AbstractTest { getClient().getObjectFactory().newEnumValue("Microsoft.Exchange.Services.OData.Model.BodyType", "text"))); message.getProperties().add(getClient().getObjectFactory().newComplexProperty("Body", body)); - final String actual = IOUtils.toString(getClient().getWriter().writeEntity(message, ODataFormat.JSON)); + final String actual = IOUtils.toString(getClient().getWriter().writeEntity(message, ContentType.JSON)); final JsonNode expected = OBJECT_MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream("olingo390.json")). replace(Constants.JSON_NAVIGATION_LINK, Constants.JSON_BIND_LINK_SUFFIX)); diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java index 562a25534..1f603ad93 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java @@ -64,7 +64,7 @@ import org.apache.olingo.commons.api.edm.provider.annotation.ConstantAnnotationE import org.apache.olingo.commons.api.edm.provider.annotation.Path; import org.apache.olingo.commons.api.edm.provider.annotation.TwoParamsOpDynamicAnnotationExpression; import org.apache.olingo.commons.api.edm.provider.annotation.UrlRef; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.core.edm.primitivetype.EdmDecimal; import org.apache.olingo.commons.core.edm.primitivetype.EdmInt32; import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; @@ -140,7 +140,7 @@ public class MetadataTest extends AbstractTest { @Test public void demo() { - final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML). + final XMLMetadata metadata = getClient().getDeserializer(ContentType.APPLICATION_XML). toMetadata(getClass().getResourceAsStream("demo-metadata.xml")); assertNotNull(metadata); @@ -181,7 +181,7 @@ public class MetadataTest extends AbstractTest { @Test public void multipleSchemas() { - final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML). + final XMLMetadata metadata = getClient().getDeserializer(ContentType.APPLICATION_XML). toMetadata(getClass().getResourceAsStream("northwind-metadata.xml")); assertNotNull(metadata); @@ -201,7 +201,7 @@ public class MetadataTest extends AbstractTest { */ @Test public void fromdoc1() { - final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML). + final XMLMetadata metadata = getClient().getDeserializer(ContentType.APPLICATION_XML). toMetadata(getClass().getResourceAsStream("fromdoc1-metadata.xml")); assertNotNull(metadata); @@ -281,7 +281,7 @@ public class MetadataTest extends AbstractTest { */ @Test public void fromdoc2() { - final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML) + final XMLMetadata metadata = getClient().getDeserializer(ContentType.APPLICATION_XML) .toMetadata(getClass().getResourceAsStream("fromdoc2-metadata.xml")); assertNotNull(metadata); @@ -343,7 +343,7 @@ public class MetadataTest extends AbstractTest { */ @Test public void fromdoc4() { - final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML). + final XMLMetadata metadata = getClient().getDeserializer(ContentType.APPLICATION_XML). toMetadata(getClass().getResourceAsStream("fromdoc4-metadata.xml")); assertNotNull(metadata); @@ -399,7 +399,7 @@ public class MetadataTest extends AbstractTest { @Test public void metadataWithCapabilities() throws Exception { InputStream input = getClass().getResourceAsStream("Metadata-With-Capabilities.xml"); - final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML). + final XMLMetadata metadata = getClient().getDeserializer(ContentType.APPLICATION_XML). toMetadata(input); CsdlSchema schema = metadata.getSchema("Capabilities"); diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PropertyTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PropertyTest.java index 46e0d222d..ccce8044b 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PropertyTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PropertyTest.java @@ -18,23 +18,24 @@ */ package org.apache.olingo.client.core.v4; -import org.apache.olingo.client.api.ODataClient; -import org.apache.olingo.client.core.AbstractTest; -import org.apache.olingo.client.api.domain.ClientCollectionValue; -import org.apache.olingo.client.api.domain.ClientComplexValue; -import org.apache.olingo.client.api.domain.ClientProperty; -import org.apache.olingo.client.api.domain.ClientValue; -import org.apache.olingo.commons.api.format.ODataFormat; -import org.apache.olingo.commons.api.serialization.ODataDeserializerException; -import org.apache.olingo.commons.api.serialization.ODataSerializerException; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.io.InputStream; import java.util.Iterator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import org.apache.olingo.client.api.ODataClient; +import org.apache.olingo.client.api.domain.ClientCollectionValue; +import org.apache.olingo.client.api.domain.ClientComplexValue; +import org.apache.olingo.client.api.domain.ClientProperty; +import org.apache.olingo.client.api.domain.ClientValue; +import org.apache.olingo.client.core.AbstractTest; +import org.apache.olingo.commons.api.format.ContentType; +import org.apache.olingo.commons.api.format.Format; +import org.apache.olingo.commons.api.serialization.ODataDeserializerException; +import org.apache.olingo.commons.api.serialization.ODataSerializerException; +import org.junit.Test; public class PropertyTest extends AbstractTest { @@ -43,16 +44,16 @@ public class PropertyTest extends AbstractTest { return v4Client; } - private void _enum(final ODataFormat format) throws ODataDeserializerException, ODataSerializerException { - final InputStream input = getClass().getResourceAsStream("Products_5_SkinColor." + getSuffix(format)); - final ClientProperty property = getClient().getReader().readProperty(input, format); + private void _enum(final ContentType contentType) throws ODataDeserializerException, ODataSerializerException { + final InputStream input = getClass().getResourceAsStream("Products_5_SkinColor." + getSuffix(contentType)); + final ClientProperty property = getClient().getReader().readProperty(input, contentType); assertNotNull(property); assertTrue(property.hasEnumValue()); final ClientProperty written = getClient().getReader().readProperty( - getClient().getWriter().writeProperty(property, format), format); + getClient().getWriter().writeProperty(property, contentType), contentType); // This is needed because type information gets lost with serialization - if (format == ODataFormat.XML) { + if (contentType.getODataFormat() == Format.APPLICATION_XML) { final ClientProperty comparable = getClient().getObjectFactory().newEnumProperty(property.getName(), getClient().getObjectFactory(). newEnumValue(property.getEnumValue().getTypeName(), written.getEnumValue().getValue())); @@ -63,23 +64,23 @@ public class PropertyTest extends AbstractTest { @Test public void xmlEnum() throws Exception { - _enum(ODataFormat.XML); + _enum(ContentType.APPLICATION_XML); } @Test public void jsonEnum() throws Exception { - _enum(ODataFormat.JSON); + _enum(ContentType.JSON); } - private void complex(final ODataFormat format) throws ODataDeserializerException, ODataSerializerException { - final InputStream input = getClass().getResourceAsStream("Employees_3_HomeAddress." + getSuffix(format)); - final ClientProperty property = getClient().getReader().readProperty(input, format); + private void complex(final ContentType contentType) throws ODataDeserializerException, ODataSerializerException { + final InputStream input = getClass().getResourceAsStream("Employees_3_HomeAddress." + getSuffix(contentType)); + final ClientProperty property = getClient().getReader().readProperty(input, contentType); assertNotNull(property); assertTrue(property.hasComplexValue()); assertEquals(3, property.getComplexValue().size()); final ClientProperty written = getClient().getReader().readProperty( - getClient().getWriter().writeProperty(property, format), format); + getClient().getWriter().writeProperty(property, contentType), contentType); // This is needed because type information gets lost with JSON serialization final ClientComplexValue typedValue = getClient().getObjectFactory(). newComplexValue(property.getComplexValue().getTypeName()); @@ -95,25 +96,25 @@ public class PropertyTest extends AbstractTest { @Test public void xmlComplex() throws Exception { - complex(ODataFormat.XML); + complex(ContentType.APPLICATION_XML); } @Test public void jsonComplex() throws Exception { - complex(ODataFormat.JSON); + complex(ContentType.JSON); } - private void collection(final ODataFormat format) throws ODataDeserializerException, ODataSerializerException { - final InputStream input = getClass().getResourceAsStream("Products_5_CoverColors." + getSuffix(format)); - final ClientProperty property = getClient().getReader().readProperty(input, format); + private void collection(final ContentType contentType) throws ODataDeserializerException, ODataSerializerException { + final InputStream input = getClass().getResourceAsStream("Products_5_CoverColors." + getSuffix(contentType)); + final ClientProperty property = getClient().getReader().readProperty(input, contentType); assertNotNull(property); assertTrue(property.hasCollectionValue()); assertEquals(3, property.getCollectionValue().size()); final ClientProperty written = getClient().getReader().readProperty( - getClient().getWriter().writeProperty(property, format), format); + getClient().getWriter().writeProperty(property, contentType), contentType); // This is needed because type information gets lost with JSON serialization - if (format == ODataFormat.XML) { + if (contentType.getODataFormat() == Format.APPLICATION_XML) { final ClientCollectionValue typedValue = getClient().getObjectFactory(). newCollectionValue(property.getCollectionValue().getTypeName()); for (final Iterator itor = written.getCollectionValue().iterator(); itor.hasNext();) { @@ -129,11 +130,11 @@ public class PropertyTest extends AbstractTest { @Test public void xmlCollection() throws Exception { - collection(ODataFormat.XML); + collection(ContentType.APPLICATION_XML); } @Test public void jsonCollection() throws Exception { - collection(ODataFormat.JSON); + collection(ContentType.JSON); } } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ServiceDocumentTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ServiceDocumentTest.java index 1a2de09ff..65bd697dc 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ServiceDocumentTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ServiceDocumentTest.java @@ -18,21 +18,22 @@ */ package org.apache.olingo.client.core.v4; -import org.apache.olingo.client.api.ODataClient; -import org.apache.olingo.client.api.data.ServiceDocument; -import org.apache.olingo.client.core.AbstractTest; -import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.client.api.domain.ClientServiceDocument; -import org.apache.olingo.commons.api.format.ODataFormat; -import org.apache.olingo.commons.api.serialization.ODataDeserializerException; -import org.junit.Test; - -import java.net.URI; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.net.URI; + +import org.apache.olingo.client.api.ODataClient; +import org.apache.olingo.client.api.data.ServiceDocument; +import org.apache.olingo.client.api.domain.ClientServiceDocument; +import org.apache.olingo.client.core.AbstractTest; +import org.apache.olingo.commons.api.data.ResWrap; +import org.apache.olingo.commons.api.format.ContentType; +import org.apache.olingo.commons.api.format.Format; +import org.apache.olingo.commons.api.serialization.ODataDeserializerException; +import org.junit.Test; + public class ServiceDocumentTest extends AbstractTest { @Override @@ -40,13 +41,13 @@ public class ServiceDocumentTest extends AbstractTest { return v4Client; } - private String getFileExtension(final ODataFormat format) { - return format == ODataFormat.XML ? "xml" : "json"; + private String getFileExtension(final ContentType contentType) { + return contentType.getODataFormat() == Format.XML ? "xml" : "json"; } - private ClientServiceDocument parse(final ODataFormat format) throws ODataDeserializerException { - ResWrap service = getClient().getDeserializer(format).toServiceDocument( - getClass().getResourceAsStream("serviceDocument." + getFileExtension(format))); + private ClientServiceDocument parse(final ContentType contentType) throws ODataDeserializerException { + ResWrap service = getClient().getDeserializer(contentType).toServiceDocument( + getClass().getResourceAsStream("serviceDocument." + getFileExtension(contentType))); assertEquals(URI.create("http://host/service/$metadata"), service.getContextURL()); assertEquals("W/\"MjAxMy0wNS0xM1QxNDo1NFo=\"", service.getMetadataETag()); @@ -56,20 +57,20 @@ public class ServiceDocumentTest extends AbstractTest { assertTrue(serviceDocument.getEntitySetNames().contains("Order Details")); assertEquals(URI.create("http://host/service/TopProducts"), - serviceDocument.getFunctionImportURI("TopProducts")); + serviceDocument.getFunctionImportURI("TopProducts")); assertEquals(URI.create("http://host/HR/"), - serviceDocument.getRelatedServiceDocumentsURIs().iterator().next()); + serviceDocument.getRelatedServiceDocumentsURIs().iterator().next()); return serviceDocument; } @Test public void json() throws Exception { - parse(ODataFormat.JSON); + parse(ContentType.JSON); } @Test public void xml() throws Exception { - parse(ODataFormat.XML); + parse(ContentType.APPLICATION_XML); } } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java index 734e007a5..874944b4d 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java @@ -122,14 +122,14 @@ public class AcceptType { /** * Creates a list of {@link AcceptType} objects based on given input string (format). - * @param format accept types, comma-separated, as specified for the HTTP header Accept + * @param contentType accept types, comma-separated, as specified for the HTTP header Accept * @return a list of AcceptType objects * @throws IllegalArgumentException if input string is not parseable */ - public static List create(final String format) { + public static List create(final String contentType) { List result = new ArrayList(); - String[] values = format.split(","); + String[] values = contentType.split(","); for (String value : values) { result.add(new AcceptType(value.trim())); } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java index 6ab29b67e..90572a465 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java @@ -49,14 +49,20 @@ public final class ContentType { private static final String APPLICATION = "application"; private static final String TEXT = "text"; private static final String MULTIPART = "multipart"; - + + public static final ContentType APPLICATION_JSON = new ContentType(APPLICATION, "json", null); + public static final ContentType JSON = ContentType.create(ContentType.APPLICATION_JSON, "odata.metadata=minimal"); + public static final ContentType JSON_NO_METADATA = ContentType.create(ContentType.APPLICATION_JSON, + "odata.metadata=none"); + public static final ContentType JSON_FULL_METADATA = ContentType.create(ContentType.APPLICATION_JSON, + "odata.metadata=full"); + public static final ContentType APPLICATION_XML = new ContentType(APPLICATION, "xml", null); public static final ContentType APPLICATION_ATOM_XML = new ContentType(APPLICATION, "atom+xml", null); public static final ContentType APPLICATION_ATOM_XML_ENTRY = create(APPLICATION_ATOM_XML, "type=entry"); public static final ContentType APPLICATION_ATOM_XML_FEED = create(APPLICATION_ATOM_XML, "type=feed"); public static final ContentType APPLICATION_ATOM_SVC = new ContentType(APPLICATION, "atomsvc+xml", null); - public static final ContentType APPLICATION_JSON = new ContentType(APPLICATION, "json", null); public static final ContentType APPLICATION_OCTET_STREAM = new ContentType(APPLICATION, "octet-stream", null); @@ -74,9 +80,9 @@ public final class ContentType { public static final ContentType MULTIPART_FORM_DATA = new ContentType(MULTIPART, "form-data", null); - public static final String PARAMETER_CHARSET= "charset"; + public static final String PARAMETER_CHARSET = "charset"; public static final String PARAMETER_IEEE754_COMPATIBLE = "IEEE754Compatible"; - + private final String type; private final String subtype; private final Map parameters; @@ -132,12 +138,12 @@ public final class ContentType { /** * Creates a content type from format and key-value pairs for parameters. * - * @param format for example "application/json" + * @param contentType for example "application/json" * @param parameters for example "a=b", "c=d" * @return a new ContentType object */ - public static ContentType create(final String format, final String... parameters) { - ContentType ct = parse(format); + public static ContentType create(final String contentType, final String... parameters) { + ContentType ct = parse(contentType); for (String p : parameters) { final String[] keyvalue = TypeUtil.parseParameter(p); @@ -326,11 +332,54 @@ public final class ContentType { for (String key : parameters.keySet()) { sb.append(TypeUtil.PARAMETER_SEPARATOR).append(key) - .append(TypeUtil.PARAMETER_KEY_VALUE_SEPARATOR).append(parameters.get(key)); + .append(TypeUtil.PARAMETER_KEY_VALUE_SEPARATOR).append(parameters.get(key)); } return sb.toString(); } + /** + * Returns the {@link Format} of the current Content-Type + * + * @return {@link Format} + */ + public Format getODataFormat() { + if (isCompatible(ContentType.APPLICATION_ATOM_XML) + || isCompatible(ContentType.APPLICATION_ATOM_SVC)) { + return Format.ATOM; + } else if (isCompatible(ContentType.APPLICATION_XML)) { + return Format.XML; + } else if (isCompatible(ContentType.APPLICATION_JSON)) { + String jsonVariant = getParameters().get("odata.metadata"); + if (jsonVariant != null) { + if ("none".equals(jsonVariant)) { + return Format.JSON_NO_METADATA; + } else if ("minimal".equals(jsonVariant)) { + return Format.JSON; + } else if ("full".equals(jsonVariant)) { + return Format.JSON_FULL_METADATA; + } + } + return Format.JSON; + } else if (isCompatible(ContentType.APPLICATION_OCTET_STREAM)) { + return Format.APPLICATION_OCTET_STREAM; + } else if (isCompatible(ContentType.TEXT_PLAIN)) { + return Format.TEXT_PLAIN; + } else if (isCompatible(ContentType.APPLICATION_XHTML_XML)) { + return Format.APPLICATION_XHTML_XML; + } else if (isCompatible(ContentType.APPLICATION_SVG_XML)) { + return Format.APPLICATION_SVG_XML; + } else if (isCompatible(ContentType.APPLICATION_FORM_URLENCODED)) { + return Format.APPLICATION_FORM_URLENCODED; + } else if (isCompatible(ContentType.MULTIPART_FORM_DATA)) { + return Format.MULTIPART_FORM_DATA; + } else if (isCompatible(ContentType.TEXT_XML)) { + return Format.TEXT_XML; + } else if (isCompatible(ContentType.TEXT_HTML)) { + return Format.TEXT_HTML; + } + return null; + } + @Override public String toString() { return toContentTypeString(); diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/Format.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/Format.java new file mode 100644 index 000000000..09e6a014e --- /dev/null +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/Format.java @@ -0,0 +1,41 @@ +/* + * 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.api.format; + +/** + * Available formats to be used in various contexts. + */ +public enum Format { + JSON_NO_METADATA, + JSON, + JSON_FULL_METADATA, + ATOM, + XML, + APPLICATION_XML, + APPLICATION_XHTML_XML, + APPLICATION_SVG_XML, + APPLICATION_JSON, + APPLICATION_FORM_URLENCODED, + MULTIPART_FORM_DATA, + APPLICATION_OCTET_STREAM, + TEXT_PLAIN, + TEXT_XML, + TEXT_HTML +} + diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ODataFormat.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ODataFormat.java deleted file mode 100644 index 211494243..000000000 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ODataFormat.java +++ /dev/null @@ -1,126 +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.commons.api.format; - -/** - * Available formats to be used in various contexts. - */ -public enum ODataFormat { - - /** JSON format with no metadata. */ - JSON_NO_METADATA(ContentType.create(ContentType.APPLICATION_JSON, "odata.metadata=none")), - /** JSON format with minimal metadata (default). */ - JSON(ContentType.create(ContentType.APPLICATION_JSON, "odata.metadata=minimal")), - /** JSON format with full metadata. */ - JSON_FULL_METADATA(ContentType.create(ContentType.APPLICATION_JSON, "odata.metadata=full")), - - /** XML format. */ - XML(ContentType.APPLICATION_XML), - /** Atom format. */ - ATOM(ContentType.APPLICATION_ATOM_XML), - - // media formats - APPLICATION_XML(ContentType.APPLICATION_XML), - APPLICATION_ATOM_XML(ContentType.APPLICATION_ATOM_XML), - APPLICATION_XHTML_XML(ContentType.APPLICATION_XHTML_XML), - APPLICATION_SVG_XML(ContentType.APPLICATION_SVG_XML), - APPLICATION_JSON(ContentType.APPLICATION_JSON), - APPLICATION_FORM_URLENCODED(ContentType.APPLICATION_FORM_URLENCODED), - MULTIPART_FORM_DATA(ContentType.MULTIPART_FORM_DATA), - APPLICATION_OCTET_STREAM(ContentType.APPLICATION_OCTET_STREAM), - TEXT_PLAIN(ContentType.TEXT_PLAIN), - TEXT_XML(ContentType.TEXT_XML), - TEXT_HTML(ContentType.TEXT_HTML); - - private final ContentType contentType; - - ODataFormat(final ContentType contentType) { - this.contentType = contentType; - } - - /** - * Gets format as {@link ContentType}. - * @return format as ContentType. - */ - public ContentType getContentType() { - return contentType; - } - - @Override - public String toString() { - if (contentType == null) { - throw new UnsupportedOperationException(); - } else { - return contentType.toContentTypeString(); - } - } - - /** - * Gets OData format from a content type. - * - * @param contentType content type - * @return OData format. - */ - public static ODataFormat fromContentType(final ContentType contentType) { - if (contentType == null) { - return null; - } - - if (contentType.isCompatible(ContentType.APPLICATION_ATOM_XML) - || contentType.isCompatible(ContentType.APPLICATION_ATOM_SVC)) { - return ATOM; - } else if (contentType.isCompatible(ContentType.APPLICATION_XML)) { - return XML; - } else if (contentType.isCompatible(ContentType.APPLICATION_JSON)) { - String jsonVariant = contentType.getParameters().get("odata.metadata"); - if (jsonVariant != null) { - if ("none".equals(jsonVariant)) { - return JSON_NO_METADATA; - } else if ("minimal".equals(jsonVariant)) { - return ODataFormat.JSON; - } else if ("full".equals(jsonVariant)) { - return ODataFormat.JSON_FULL_METADATA; - } - } - return JSON; - } else if (contentType.isCompatible(ContentType.APPLICATION_OCTET_STREAM)) { - return APPLICATION_OCTET_STREAM; - } else if (contentType.isCompatible(ContentType.TEXT_PLAIN)) { - return TEXT_PLAIN; - } else if (contentType.isCompatible(ContentType.APPLICATION_XHTML_XML)) { - return APPLICATION_XHTML_XML; - } else if (contentType.isCompatible(ContentType.APPLICATION_SVG_XML)) { - return APPLICATION_SVG_XML; - } else if (contentType.isCompatible(ContentType.APPLICATION_FORM_URLENCODED)) { - return APPLICATION_FORM_URLENCODED; - } else if (contentType.isCompatible(ContentType.MULTIPART_FORM_DATA)) { - return MULTIPART_FORM_DATA; - } else if (contentType.isCompatible(ContentType.TEXT_XML)) { - return TEXT_XML; - } else if (contentType.isCompatible(ContentType.TEXT_HTML)) { - return TEXT_HTML; - } - - throw new IllegalArgumentException("Unsupported content Type: " + contentType); - } - - public static ODataFormat fromString(final String contentType) { - return contentType == null ? null : fromContentType(ContentType.parse(contentType)); - } -} diff --git a/lib/commons-api/src/test/java/org/apache/olingo/commons/api/format/AcceptTypeTest.java b/lib/commons-api/src/test/java/org/apache/olingo/commons/api/format/AcceptTypeTest.java index a6248f39c..47cfc3f0f 100644 --- a/lib/commons-api/src/test/java/org/apache/olingo/commons/api/format/AcceptTypeTest.java +++ b/lib/commons-api/src/test/java/org/apache/olingo/commons/api/format/AcceptTypeTest.java @@ -18,15 +18,13 @@ */ package org.apache.olingo.commons.api.format; -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 static org.junit.Assert.*; import java.util.List; import org.junit.Test; + public class AcceptTypeTest { @Test diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java index ddb789d19..9117ade01 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java @@ -29,7 +29,7 @@ import org.apache.olingo.commons.api.data.Operation; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.core.edm.EdmTypeInfo; import com.fasterxml.jackson.core.JsonGenerator; @@ -43,8 +43,8 @@ public class JsonEntitySerializer extends JsonSerializer { super(serverMode); } - public JsonEntitySerializer(final boolean serverMode, final ODataFormat format) { - super(serverMode, format); + public JsonEntitySerializer(final boolean serverMode, final ContentType contentType) { + super(serverMode, contentType); } protected void doSerialize(final Entity entity, final JsonGenerator jgen) @@ -73,12 +73,12 @@ public class JsonEntitySerializer extends JsonSerializer { } } - if (StringUtils.isNotBlank(entity.getType()) && format != ODataFormat.JSON_NO_METADATA) { + if (StringUtils.isNotBlank(entity.getType()) && contentType != ContentType.JSON_NO_METADATA) { jgen.writeStringField(Constants.JSON_TYPE, new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external()); } - if (entity.getId() != null && format != ODataFormat.JSON_NO_METADATA) { + if (entity.getId() != null && contentType != ContentType.JSON_NO_METADATA) { jgen.writeStringField(Constants.JSON_ID, entity.getId().toASCIIString()); } @@ -100,7 +100,7 @@ public class JsonEntitySerializer extends JsonSerializer { } } - if (format != ODataFormat.JSON_NO_METADATA) { + if (contentType != ContentType.JSON_NO_METADATA) { links(entity, jgen); } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java index 92ce269d8..1cc7e1a5d 100755 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java @@ -43,7 +43,7 @@ import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.geo.Geospatial; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataSerializer; import org.apache.olingo.commons.api.serialization.ODataSerializerException; import org.apache.olingo.commons.core.edm.EdmTypeInfo; @@ -65,15 +65,15 @@ public class JsonSerializer implements ODataSerializer { protected boolean serverMode; - protected ODataFormat format; + protected ContentType contentType; public JsonSerializer(final boolean serverMode) { - this(serverMode, ODataFormat.JSON_FULL_METADATA); + this(serverMode, ContentType.JSON_FULL_METADATA); } - public JsonSerializer(final boolean serverMode, final ODataFormat format) { + public JsonSerializer(final boolean serverMode, final ContentType contentType) { this.serverMode = serverMode; - this.format = format; + this.contentType = contentType; } @Override @@ -83,7 +83,7 @@ public class JsonSerializer implements ODataSerializer { if (obj instanceof EntityCollection) { new JsonEntitySetSerializer(serverMode).doSerialize((EntityCollection) obj, json); } else if (obj instanceof Entity) { - new JsonEntitySerializer(serverMode, format).doSerialize((Entity) obj, json); + new JsonEntitySerializer(serverMode, contentType).doSerialize((Entity) obj, json); } else if (obj instanceof Property) { new JsonPropertySerializer(serverMode).doSerialize((Property) obj, json); } else if (obj instanceof Link) { @@ -312,7 +312,7 @@ public class JsonSerializer implements ODataSerializer { throws IOException, EdmPrimitiveTypeException { jgen.writeStartObject(); - if (typeInfo != null && format != ODataFormat.JSON_NO_METADATA) { + if (typeInfo != null && contentType != ContentType.JSON_NO_METADATA) { jgen.writeStringField(Constants.JSON_TYPE, typeInfo.external()); } @@ -359,7 +359,7 @@ public class JsonSerializer implements ODataSerializer { valuable.isPrimitive()) || valuable.isNull()) { type = EdmPrimitiveTypeKind.String.getFullQualifiedName().toString(); } - if (StringUtils.isNotBlank(type) && format != ODataFormat.JSON_NO_METADATA) { + if (StringUtils.isNotBlank(type) && contentType != ContentType.JSON_NO_METADATA) { jgen.writeFieldName( name + StringUtils.prependIfMissing(Constants.JSON_TYPE, "@")); jgen.writeString(new EdmTypeInfo.Builder().setTypeExpression(type).build().external()); diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/OData.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/OData.java index 8599982ab..1ed12d252 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/OData.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/OData.java @@ -119,7 +119,7 @@ public abstract class OData { * Creates a new deserializer object for reading content in the specified format. * Deserializer are used in Processor implementations. * - * @param format any content type supported by Olingo (XML, JSON ...) + * @param contentType any content type supported by Olingo (XML, JSON ...) */ public abstract ODataDeserializer createDeserializer(ContentType contentType) throws DeserializerException; diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java index 65842626e..ad27ced8e 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java @@ -21,7 +21,6 @@ package org.apache.olingo.server.core; import java.io.ByteArrayInputStream; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.OData; @@ -96,9 +95,9 @@ public class ErrorHandler { requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, this.customContent, RepresentationType.ERROR); } catch (final ContentNegotiatorException e) { - requestedContentType = ODataFormat.JSON.getContentType(); + requestedContentType = ContentType.JSON; } catch (UriParserException e) { - requestedContentType = ODataFormat.JSON.getContentType(); + requestedContentType = ContentType.JSON; } processError(response, serverError, requestedContentType); } diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java index c0428d491..26895de9b 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java @@ -28,7 +28,7 @@ import java.util.StringTokenizer; import org.apache.olingo.commons.api.data.ContextURL; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.Format; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpMethod; import org.apache.olingo.server.api.OData; @@ -143,16 +143,16 @@ public abstract class ServiceRequest { @SuppressWarnings("unchecked") public T getSerializerOptions(Class serilizerOptions, ContextURL contextUrl, boolean references) throws ContentNegotiatorException { - final ODataFormat format = ODataFormat.fromContentType(getResponseContentType()); + final Format format = getResponseContentType().getODataFormat(); if (serilizerOptions.isAssignableFrom(EntitySerializerOptions.class)) { return (T) EntitySerializerOptions.with() - .contextURL(format == ODataFormat.JSON_NO_METADATA ? null : contextUrl) + .contextURL(format == Format.JSON_NO_METADATA ? null : contextUrl) .expand(uriInfo.getExpandOption()).select(this.uriInfo.getSelectOption()) .setWriteOnlyReferences(references).build(); } else if (serilizerOptions.isAssignableFrom(EntityCollectionSerializerOptions.class)) { return (T) EntityCollectionSerializerOptions.with() - .contextURL(format == ODataFormat.JSON_NO_METADATA ? null : contextUrl) + .contextURL(format == Format.JSON_NO_METADATA ? null : contextUrl) .count(uriInfo.getCountOption()).expand(uriInfo.getExpandOption()) .select(uriInfo.getSelectOption()).setWriteOnlyReferences(references).build(); } else if (serilizerOptions.isAssignableFrom(ComplexSerializerOptions.class)) { diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java index b37c2ae90..646e835b1 100644 --- a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java +++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java @@ -45,7 +45,7 @@ import org.apache.olingo.commons.api.edm.EdmProperty; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.constants.EdmTypeKind; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.deserializer.DeserializerException; @@ -116,7 +116,7 @@ public class TripPinDataModel { private EntityCollection loadEnities(String entitySetName, EdmEntityType type) { try { - ODataJsonDeserializer deserializer = new ODataJsonDeserializer(ODataFormat.JSON.getContentType()); + ODataJsonDeserializer deserializer = new ODataJsonDeserializer(ContentType.JSON); EntityCollection set = deserializer.entityCollection(new FileInputStream(new File( "src/test/resources/" + entitySetName.toLowerCase() + ".json")), type).getEntityCollection(); diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java index db0eef129..f7675d6be 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java @@ -23,7 +23,7 @@ import java.util.List; import org.apache.olingo.commons.api.format.AcceptType; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.Format; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.serializer.CustomContentTypeSupport; @@ -48,9 +48,9 @@ public class ContentNegotiator { return Arrays.asList(ContentType.MULTIPART_MIXED); default: return Arrays.asList( - ODataFormat.JSON.getContentType(), - ODataFormat.JSON_NO_METADATA.getContentType(), - ODataFormat.APPLICATION_JSON.getContentType()); + ContentType.JSON, + ContentType.JSON_NO_METADATA, + ContentType.APPLICATION_JSON); } } @@ -78,14 +78,14 @@ public class ContentNegotiator { if (formatOption != null && formatOption.getFormat() != null) { final String formatString = formatOption.getFormat().trim(); - final ODataFormat format = - ODataFormat.JSON.name().equalsIgnoreCase(formatString) ? ODataFormat.JSON : - ODataFormat.XML.name().equalsIgnoreCase(formatString) ? ODataFormat.XML : - ODataFormat.ATOM.name().equalsIgnoreCase(formatString) ? ODataFormat.ATOM : null; + final ContentType contentType = + Format.JSON.name().equalsIgnoreCase(formatString) ? ContentType.JSON : + Format.XML.name().equalsIgnoreCase(formatString) ? ContentType.APPLICATION_XML : + Format.ATOM.name().equalsIgnoreCase(formatString) ? ContentType.APPLICATION_ATOM_XML : null; try { result = getAcceptedType( - AcceptType.fromContentType(format == null ? - ContentType.create(formatOption.getFormat()) : format.getContentType()), + AcceptType.fromContentType(contentType == null ? + ContentType.create(formatOption.getFormat()) : contentType), supportedContentTypes); } catch (final IllegalArgumentException e) { // Exception results in result = null for next check. diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java index b9989f037..47bef3d7c 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java @@ -23,7 +23,6 @@ import java.util.List; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpMethod; import org.apache.olingo.server.api.OData; @@ -140,7 +139,7 @@ public class ODataHandler { uriInfo == null ? null : uriInfo.getFormatOption(), request, getCustomContentTypeSupport(), RepresentationType.ERROR); } catch (final ContentNegotiatorException e) { - requestedContentType = ODataFormat.JSON.getContentType(); + requestedContentType = ContentType.JSON; } exceptionProcessor.processError(request, response, serverError, requestedContentType); } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java index a134887d3..55c6b717f 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java @@ -24,7 +24,7 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.Format; import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.ODataHttpHandler; @@ -51,7 +51,7 @@ public class ODataImpl extends OData { @Override public ODataSerializer createSerializer(final ContentType contentType) throws SerializerException { - final ODataFormat format = ODataFormat.fromContentType(contentType); + final Format format = contentType.getODataFormat(); ODataSerializer serializer; switch (format) { @@ -105,7 +105,7 @@ public class ODataImpl extends OData { @Override public ODataDeserializer createDeserializer(final ContentType contentType) throws DeserializerException { - final ODataFormat format = ODataFormat.fromContentType(contentType); + final Format format = contentType.getODataFormat(); ODataDeserializer deserializer; switch (format) { diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java index 13c0fad1c..671a06914 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java @@ -42,7 +42,7 @@ import org.apache.olingo.commons.api.edm.EdmProperty; import org.apache.olingo.commons.api.edm.EdmStructuredType; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.Format; import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; import org.apache.olingo.server.api.ODataServerError; import org.apache.olingo.server.api.ServiceMetadata; @@ -75,12 +75,12 @@ public class ODataJsonSerializer implements ODataSerializer { private static final Logger log = LoggerFactory.getLogger(ODataJsonSerializer.class); - private final ODataFormat format; + private final ContentType contentType; private final boolean isIEEE754Compatible; public ODataJsonSerializer(final ContentType contentType) { this.isIEEE754Compatible = isODataIEEE754Compatible(contentType); - this.format = ODataFormat.fromContentType(contentType); + this.contentType = contentType; } @Override @@ -94,7 +94,7 @@ public class ODataJsonSerializer implements ODataSerializer { gen = new JsonFactory().createGenerator(buffer.getOutputStream()) .setPrettyPrinter(new DefaultPrettyPrinter()); - new ServiceDocumentJsonSerializer(metadata, serviceRoot, format).writeServiceDocument(gen); + new ServiceDocumentJsonSerializer(metadata, serviceRoot, contentType).writeServiceDocument(gen); gen.close(); @@ -196,7 +196,7 @@ public class ODataJsonSerializer implements ODataSerializer { } private ContextURL checkContextURL(final ContextURL contextURL) throws SerializerException { - if (format == ODataFormat.JSON_NO_METADATA) { + if (contentType.getODataFormat() == Format.JSON_NO_METADATA) { return null; } else if (contextURL == null) { throw new SerializerException("ContextURL null!", SerializerException.MessageKeys.NO_CONTEXT_URL); @@ -205,7 +205,7 @@ public class ODataJsonSerializer implements ODataSerializer { } private void writeMetadataETag(final ServiceMetadata metadata, JsonGenerator json) throws IOException { - if (format != ODataFormat.JSON_NO_METADATA + if (contentType.getODataFormat() != Format.JSON_NO_METADATA && metadata != null && metadata.getServiceMetadataETagSupport() != null && metadata.getServiceMetadataETagSupport().getMetadataETag() != null) { @@ -236,7 +236,7 @@ public class ODataJsonSerializer implements ODataSerializer { final SelectOption select, final boolean onlyReference, final JsonGenerator json) throws IOException, SerializerException { json.writeStartObject(); - if (format != ODataFormat.JSON_NO_METADATA) { + if (contentType.getODataFormat() != Format.JSON_NO_METADATA) { if (contextURL != null) { // top-level entity json.writeStringField(Constants.JSON_CONTEXT, ContextURLBuilder.create(contextURL).toASCIIString()); writeMetadataETag(metadata, json); diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java index 65b467370..ad98aa74a 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java @@ -26,7 +26,8 @@ import org.apache.olingo.commons.api.edm.EdmEntityContainer; import org.apache.olingo.commons.api.edm.EdmEntitySet; import org.apache.olingo.commons.api.edm.EdmFunctionImport; import org.apache.olingo.commons.api.edm.EdmSingleton; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; +import org.apache.olingo.commons.api.format.Format; import org.apache.olingo.server.api.ServiceMetadata; import com.fasterxml.jackson.core.JsonGenerator; @@ -40,13 +41,13 @@ public class ServiceDocumentJsonSerializer { private final ServiceMetadata metadata; private final String serviceRoot; - private final ODataFormat format; + private final ContentType contentType; public ServiceDocumentJsonSerializer(final ServiceMetadata metadata, final String serviceRoot, - final ODataFormat format) { + final ContentType contentType) { this.metadata = metadata; this.serviceRoot = serviceRoot; - this.format = format; + this.contentType = contentType; } public void writeServiceDocument(final JsonGenerator gen) throws IOException { @@ -58,7 +59,7 @@ public class ServiceDocumentJsonSerializer { + Constants.METADATA; gen.writeObjectField(Constants.JSON_CONTEXT, metadataUri); - if (format != ODataFormat.JSON_NO_METADATA + if (contentType.getODataFormat() != Format.JSON_NO_METADATA && metadata != null && metadata.getServiceMetadataETagSupport() != null && metadata.getServiceMetadataETagSupport().getMetadataETag() != null) { diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java index 6391212e0..69651b34e 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java @@ -32,7 +32,7 @@ import org.antlr.v4.runtime.atn.PredictionMode; import org.antlr.v4.runtime.misc.ParseCancellationException; import org.apache.olingo.commons.api.ODataRuntimeException; import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.Format; import org.apache.olingo.server.api.uri.UriInfo; import org.apache.olingo.server.api.uri.UriInfoKind; import org.apache.olingo.server.api.uri.UriResource; @@ -177,9 +177,9 @@ public class Parser { FormatOptionImpl formatOption = new FormatOptionImpl(); formatOption.setName(option.name); formatOption.setText(option.value); - if (option.value.equalsIgnoreCase(ODataFormat.JSON.name()) - || option.value.equalsIgnoreCase(ODataFormat.XML.name()) - || option.value.equalsIgnoreCase(ODataFormat.ATOM.name()) + if (option.value.equalsIgnoreCase(Format.JSON.name()) + || option.value.equalsIgnoreCase(Format.XML.name()) + || option.value.equalsIgnoreCase(Format.ATOM.name()) || isFormatSyntaxValid(option.value)) { formatOption.setFormat(option.value); } else { diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java index b959bb672..07e06ca69 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java @@ -31,7 +31,6 @@ import java.util.Arrays; import java.util.List; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.http.HttpContentType; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.server.api.ODataRequest; @@ -154,7 +153,7 @@ public class ContentNegotiatorTest { @Test public void checkSupport() throws Exception { - ContentNegotiator.checkSupport(ODataFormat.JSON.getContentType(), null, + ContentNegotiator.checkSupport(ContentType.JSON, null, RepresentationType.ENTITY); ContentNegotiator.checkSupport(ContentType.TEXT_PLAIN, null, RepresentationType.VALUE); try { diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java index da34caa7c..d29fdf84d 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java @@ -26,7 +26,7 @@ import java.io.InputStream; import java.net.URI; import java.util.List; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.deserializer.DeserializerException; import org.apache.olingo.server.api.deserializer.ODataDeserializer; @@ -36,15 +36,15 @@ public class ODataJsonDeserializerBasicTest { @Test public void checkSupportedJsonFormats() throws Exception { - ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON.getContentType()); + ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON); assertNotNull(deserializer); deserializer = null; - deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON_NO_METADATA.getContentType()); + deserializer = OData.newInstance().createDeserializer(ContentType.JSON_NO_METADATA); assertNotNull(deserializer); deserializer = null; - deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON_FULL_METADATA.getContentType()); + deserializer = OData.newInstance().createDeserializer(ContentType.JSON_FULL_METADATA); assertNotNull(deserializer); deserializer = null; } @@ -58,7 +58,7 @@ public class ODataJsonDeserializerBasicTest { " { \"@odata.id\": \"Orders(10759)\" }\n" + " ]\n" + "}"; - ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON.getContentType()); + ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON); List values = deserializer.entityReferences(new ByteArrayInputStream(payload.getBytes())) .getEntityReferences(); assertEquals(2, values.size()); @@ -72,7 +72,7 @@ public class ODataJsonDeserializerBasicTest { " \"@odata.context\": \"http://host/service/$metadata#$ref\",\n" + " \"@odata.id\": \"Orders(10643)\"\n" + "}"; - ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON.getContentType()); + ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON); List values = deserializer.entityReferences(new ByteArrayInputStream(payload .getBytes())).getEntityReferences(); assertEquals(1, values.size()); @@ -87,7 +87,7 @@ public class ODataJsonDeserializerBasicTest { + "}"; InputStream stream = new ByteArrayInputStream(entityString.getBytes()); - ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON.getContentType()); + ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON); final List entityReferences = deserializer.entityReferences(stream).getEntityReferences(); assertEquals(1, entityReferences.size()); @@ -105,7 +105,7 @@ public class ODataJsonDeserializerBasicTest { "}"; InputStream stream = new ByteArrayInputStream(entityString.getBytes()); - ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON.getContentType()); + ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON); final List entityReferences = deserializer.entityReferences(stream).getEntityReferences(); assertEquals(2, entityReferences.size()); @@ -124,7 +124,7 @@ public class ODataJsonDeserializerBasicTest { "}"; InputStream stream = new ByteArrayInputStream(entityString.getBytes()); - ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON.getContentType()); + ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON); final List entityReferences = deserializer.entityReferences(stream).getEntityReferences(); assertEquals(1, entityReferences.size()); @@ -142,7 +142,7 @@ public class ODataJsonDeserializerBasicTest { "}"; InputStream stream = new ByteArrayInputStream(entityString.getBytes()); - ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON.getContentType()); + ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON); final List entityReferences = deserializer.entityReferences(stream).getEntityReferences(); assertEquals(1, entityReferences.size()); @@ -158,7 +158,7 @@ public class ODataJsonDeserializerBasicTest { "}"; InputStream stream = new ByteArrayInputStream(entityString.getBytes()); - ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON.getContentType()); + ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON); final List entityReferences = deserializer.entityReferences(stream).getEntityReferences(); assertEquals(0, entityReferences.size()); @@ -173,7 +173,7 @@ public class ODataJsonDeserializerBasicTest { String entityString = "{ }"; InputStream stream = new ByteArrayInputStream(entityString.getBytes()); - ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON.getContentType()); + ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON); final List entityReferences = deserializer.entityReferences(stream).getEntityReferences(); assertEquals(0, entityReferences.size()); @@ -187,7 +187,7 @@ public class ODataJsonDeserializerBasicTest { "}"; InputStream stream = new ByteArrayInputStream(entityString.getBytes()); - ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON.getContentType()); + ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON); deserializer.entityReferences(stream); } } diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java index ad09ff931..1994e0c66 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java @@ -32,7 +32,7 @@ import org.apache.olingo.commons.api.data.ComplexValue; import org.apache.olingo.commons.api.data.ContextURL; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ValueType; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.server.api.serializer.ComplexSerializerOptions; import org.junit.Test; @@ -44,7 +44,7 @@ public class ODataJsonSerializerTest { col.add(getValues(2)); final Property complexCollection = new Property(null, "ComplexCol", ValueType.COLLECTION_COMPLEX, col); - final ODataJsonSerializer serializer = new ODataJsonSerializer(ODataFormat.APPLICATION_JSON.getContentType()); + final ODataJsonSerializer serializer = new ODataJsonSerializer(ContentType.APPLICATION_JSON); final ComplexSerializerOptions options = ComplexSerializerOptions.with() .contextURL(ContextURL.with().selectList("ComplexCollection").build()).build(); final InputStream in = serializer.complexCollection(null, ComplexTypeHelper.createType(), diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ServerErrorSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ServerErrorSerializerTest.java index 9f67e497c..324207689 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ServerErrorSerializerTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ServerErrorSerializerTest.java @@ -27,9 +27,9 @@ import java.util.List; import org.apache.commons.io.IOUtils; import org.apache.olingo.commons.api.ODataErrorDetail; -import org.apache.olingo.commons.api.format.ODataFormat; -import org.apache.olingo.server.api.ODataServerError; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.server.api.OData; +import org.apache.olingo.server.api.ODataServerError; import org.apache.olingo.server.api.serializer.ODataSerializer; import org.apache.olingo.server.api.serializer.SerializerException; import org.junit.Before; @@ -45,7 +45,7 @@ public class ServerErrorSerializerTest { @Before public void before() throws Exception { - ser = OData.newInstance().createSerializer(ODataFormat.JSON.getContentType()); + ser = OData.newInstance().createSerializer(ContentType.JSON); } @Test diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java index 752b254e5..4423308cd 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java @@ -57,7 +57,7 @@ import org.apache.olingo.commons.api.edm.provider.CsdlPropertyRef; import org.apache.olingo.commons.api.edm.provider.CsdlReturnType; import org.apache.olingo.commons.api.edm.provider.CsdlSchema; import org.apache.olingo.commons.api.edm.provider.CsdlSingleton; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.core.edm.EdmComplexTypeImpl; import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.ServiceMetadata; @@ -76,7 +76,7 @@ public class MetadataDocumentXmlSerializerTest { @BeforeClass public static void init() throws SerializerException { - serializer = OData.newInstance().createSerializer(ODataFormat.XML.getContentType()); + serializer = OData.newInstance().createSerializer(ContentType.APPLICATION_XML); } @Test diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalActionProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalActionProcessor.java index fe1c1da76..b6159fffb 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalActionProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalActionProcessor.java @@ -31,7 +31,7 @@ import org.apache.olingo.commons.api.edm.EdmEntitySet; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.Format; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpStatusCode; import org.apache.olingo.server.api.ODataApplicationException; @@ -93,10 +93,9 @@ public class TechnicalActionProcessor extends TechnicalProcessor } final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo.asUriInfoResource()); final EdmEntityType type = (EdmEntityType) action.getReturnType().getType(); - final ODataFormat format = ODataFormat.fromContentType(responseFormat); EntityCollectionSerializerOptions options = EntityCollectionSerializerOptions.with() - .contextURL(format == ODataFormat.JSON_NO_METADATA ? null : getContextUrl(edmEntitySet, type, false)) - .build(); + .contextURL(responseFormat.getODataFormat() == Format.JSON_NO_METADATA ? null : + getContextUrl(edmEntitySet, type, false)).build(); response.setContent(odata.createSerializer(requestFormat) .entityCollection(serviceMetadata, type, collection, options).getContent()); response.setStatusCode(HttpStatusCode.OK.getStatusCode()); @@ -127,14 +126,13 @@ public class TechnicalActionProcessor extends TechnicalProcessor HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT); } } else { - final ODataFormat format = ODataFormat.fromContentType(responseFormat); response.setContent(odata.createSerializer(requestFormat).entity( serviceMetadata, type, entityResult.getEntity(), EntitySerializerOptions.with() - .contextURL(format == ODataFormat.JSON_NO_METADATA ? null : getContextUrl(edmEntitySet, type, true)) - .build()) + .contextURL(responseFormat.getODataFormat() == Format.JSON_NO_METADATA ? null : + getContextUrl(edmEntitySet, type, true)).build()) .getContent()); response.setStatusCode((entityResult.isCreated() ? HttpStatusCode.CREATED : HttpStatusCode.OK) .getStatusCode()); diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java index 61dbfc96a..32f76b12d 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java @@ -28,7 +28,7 @@ import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.commons.api.edm.EdmEntitySet; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.Format; import org.apache.olingo.commons.api.http.HttpContentType; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpMethod; @@ -451,7 +451,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor edmEntityType, entityCollection, EntityCollectionSerializerOptions.with() - .contextURL(ODataFormat.fromContentType(requestedFormat) == ODataFormat.JSON_NO_METADATA ? null : + .contextURL(requestedFormat.getODataFormat() == Format.JSON_NO_METADATA ? null : getContextUrl(edmEntitySet, edmEntityType, false, expand, select)) .count(countOption) .expand(expand).select(select) @@ -484,7 +484,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor edmEntityType, entity, EntitySerializerOptions.with() - .contextURL(ODataFormat.fromContentType(requestedFormat) == ODataFormat.JSON_NO_METADATA ? null : + .contextURL(requestedFormat.getODataFormat() == Format.JSON_NO_METADATA ? null : getContextUrl(edmEntitySet, edmEntityType, true, expand, select)) .expand(expand).select(select) .build()); diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java index e8257dd8c..50e1c1bd6 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java @@ -38,7 +38,7 @@ import org.apache.olingo.commons.api.edm.EdmStructuredType; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.edm.constants.EdmTypeKind; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.Format; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpMethod; import org.apache.olingo.commons.api.http.HttpStatusCode; @@ -396,7 +396,7 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor final RepresentationType representationType, final ContentType responseFormat, final ExpandOption expand, final SelectOption select) throws ODataLibraryException { ODataSerializer serializer = odata.createSerializer(responseFormat); - final ContextURL contextURL = ODataFormat.fromContentType(responseFormat) == ODataFormat.JSON_NO_METADATA ? null : + final ContextURL contextURL = responseFormat.getODataFormat() == Format.JSON_NO_METADATA ? null : getContextUrl(edmEntitySet, entity, path, type, representationType, expand, select); SerializerResult result = null; switch (representationType) { diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java index 755c4f140..c9a5f32ab 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java @@ -43,16 +43,15 @@ import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.edm.provider.CsdlAbstractEdmProvider; import org.apache.olingo.commons.api.edm.provider.CsdlEntitySet; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.http.HttpContentType; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpMethod; import org.apache.olingo.commons.api.http.HttpStatusCode; -import org.apache.olingo.server.api.ODataServerError; import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.ODataResponse; +import org.apache.olingo.server.api.ODataServerError; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.edmx.EdmxReference; import org.apache.olingo.server.api.processor.ActionComplexCollectionProcessor; @@ -736,7 +735,7 @@ public class ODataHandlerTest { if (request.getHeaders(HttpHeader.CONTENT_TYPE) == null) { request.addHeader(HttpHeader.CONTENT_TYPE, Collections.singletonList( - ODataFormat.JSON.getContentType().toContentTypeString())); + ContentType.JSON.toContentTypeString())); } final OData odata = OData.newInstance(); diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/AbstractODataDeserializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/AbstractODataDeserializerTest.java index 7030b1352..c0e188ad0 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/AbstractODataDeserializerTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/AbstractODataDeserializerTest.java @@ -24,13 +24,12 @@ import java.util.Collections; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.edmx.EdmxReference; import org.apache.olingo.server.tecsvc.provider.EdmTechProvider; public class AbstractODataDeserializerTest { - protected static final ContentType CONTENT_TYPE_JSON = ODataFormat.JSON.getContentType(); + protected static final ContentType CONTENT_TYPE_JSON = ContentType.JSON; protected static final ContentType CONTENT_TYPE_JSON_IEEE754Compatible = ContentType.parse("application/json;odata.format=minimal;IEEE754Compatible=true"); diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java index c7d1782fa..15dd99b1c 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java @@ -37,7 +37,6 @@ import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.commons.api.edm.EdmProperty; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.edmx.EdmxReference; import org.apache.olingo.server.api.serializer.ComplexSerializerOptions; @@ -71,7 +70,7 @@ public class ODataJsonSerializerTest { new EdmTechProvider(), Collections. emptyList(), new MetadataETagSupport("W/\"metadataETag\"")); private static final EdmEntityContainer entityContainer = metadata.getEdm().getEntityContainer(); private final DataProvider data = new DataProvider(); - private final ODataSerializer serializer = new ODataJsonSerializer(ODataFormat.JSON.getContentType()); + private final ODataSerializer serializer = new ODataJsonSerializer(ContentType.JSON); private final ODataSerializer serializerIEEECompatible = new ODataJsonSerializer(ContentType.parse("application/json;odata.metadata=minimal;IEEE754Compatible=true")); private final UriHelper helper = new UriHelperImpl(); @@ -307,7 +306,7 @@ public class ODataJsonSerializerTest { public void entityTwoPrimNoMetadata() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim"); final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); - InputStream result = new ODataJsonSerializer(ODataFormat.JSON_NO_METADATA.getContentType()) + InputStream result = new ODataJsonSerializer(ContentType.JSON_NO_METADATA) .entity(metadata, edmEntitySet.getEntityType(), entity, null).getContent(); final String resultString = IOUtils.toString(result); final String expectedResult = "{\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}"; @@ -318,7 +317,7 @@ public class ODataJsonSerializerTest { public void entitySetTwoPrimNoMetadata() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim"); final EntityCollection entitySet = data.readAll(edmEntitySet); - InputStream result = new ODataJsonSerializer(ODataFormat.JSON_NO_METADATA.getContentType()) + InputStream result = new ODataJsonSerializer(ContentType.JSON_NO_METADATA) .entityCollection(metadata, edmEntitySet.getEntityType(), entitySet, EntityCollectionSerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).build()).build()).getContent(); diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java index 845197653..bd4a55166 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java @@ -26,7 +26,7 @@ import java.io.InputStream; import java.util.Collections; import org.apache.commons.io.IOUtils; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.edmx.EdmxReference; @@ -47,7 +47,7 @@ public class ServiceDocumentTest { OData server = OData.newInstance(); assertNotNull(server); - ODataSerializer serializer = server.createSerializer(ODataFormat.JSON.getContentType()); + ODataSerializer serializer = server.createSerializer(ContentType.JSON); assertNotNull(serializer); InputStream result = serializer.serviceDocument(metadata, serviceRoot).getContent(); diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java index f69ee602c..ef27e2483 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java @@ -27,7 +27,7 @@ import java.util.Arrays; import java.util.List; import org.apache.commons.io.IOUtils; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.edmx.EdmxReference; @@ -48,7 +48,7 @@ public class MetadataDocumentTest { new EdmTechProvider(references), references); final String metadata = IOUtils.toString( - odata.createSerializer(ODataFormat.XML.getContentType()).metadataDocument(serviceMetadata).getContent()); + odata.createSerializer(ContentType.APPLICATION_XML).metadataDocument(serviceMetadata).getContent()); assertNotNull(metadata); assertThat(metadata, containsString("" diff --git a/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java b/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java index 27e77f662..013462c95 100644 --- a/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java +++ b/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java @@ -34,7 +34,7 @@ import org.apache.olingo.commons.api.edm.EdmEntitySet; import org.apache.olingo.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.commons.api.edm.EdmProperty; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.format.Format; import org.apache.olingo.commons.api.http.HttpContentType; import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpStatusCode; @@ -102,7 +102,6 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor // Next we create a serializer based on the requested format. This could also be a custom format but we do not // support them in this example - final ODataFormat format = ODataFormat.fromContentType(requestedContentType); ODataSerializer serializer = odata.createSerializer(requestedContentType); // Now the content is serialized using the serializer. @@ -110,7 +109,7 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor final SelectOption select = uriInfo.getSelectOption(); InputStream serializedContent = serializer.entityCollection(edm, edmEntitySet.getEntityType(), entitySet, EntityCollectionSerializerOptions.with() - .contextURL(format == ODataFormat.JSON_NO_METADATA ? null : + .contextURL(requestedContentType.getODataFormat() == Format.JSON_NO_METADATA ? null : getContextUrl(edmEntitySet, false, expand, select, null)) .count(uriInfo.getCountOption()) .expand(expand).select(select) @@ -142,13 +141,12 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor .getStatusCode(), Locale.ENGLISH); } else { // If an entity was found we proceed by serializing it and sending it to the client. - final ODataFormat format = ODataFormat.fromContentType(requestedContentType); ODataSerializer serializer = odata.createSerializer(requestedContentType); final ExpandOption expand = uriInfo.getExpandOption(); final SelectOption select = uriInfo.getSelectOption(); InputStream serializedContent = serializer.entity(edm, edmEntitySet.getEntityType(), entity, EntitySerializerOptions.with() - .contextURL(format == ODataFormat.JSON_NO_METADATA ? null : + .contextURL(requestedContentType.getODataFormat() == Format.JSON_NO_METADATA ? null : getContextUrl(edmEntitySet, true, expand, select, null)) .expand(expand).select(select) .build()).getContent(); @@ -254,9 +252,8 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor if (property.getValue() == null) { response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); } else { - final ODataFormat format = ODataFormat.fromContentType(contentType); ODataSerializer serializer = odata.createSerializer(contentType); - final ContextURL contextURL = format == ODataFormat.JSON_NO_METADATA ? null : + final ContextURL contextURL = contentType.getODataFormat() == Format.JSON_NO_METADATA ? null : getContextUrl(edmEntitySet, true, null, null, edmProperty.getName()); InputStream serializerContent = complex ? serializer.complex(edm, (EdmComplexType) edmProperty.getType(), property,