[OLINGO-704] Class ODataFormat removed

This commit is contained in:
Christian Holzer 2015-06-12 18:01:35 +02:00
parent be55285ce3
commit 588df780bf
125 changed files with 1035 additions and 1081 deletions

View File

@ -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<C extends EdmEnabledODataClient> {
}
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();
}

View File

@ -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;

View File

@ -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<InputStream> res = retrieveReq.execute();

View File

@ -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());
}

View File

@ -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);

View File

@ -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
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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<ClientEntity> 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<ClientEntity> 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<ClientEntity> 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<ClientEntity> 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<ClientEntity> 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<ClientEntitySet> 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<ClientEntitySet> getResponse = req.execute();
@ -478,7 +477,7 @@ public class BatchClientITCase extends AbstractTestITCase {
final ODataEntityCreateRequest<ClientEntity> 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<ClientEntity> 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<ClientEntity> queryReq = client.getRetrieveRequestFactory().getEntityRequest(uri);
queryReq.setFormat(ODataFormat.JSON);
queryReq.setFormat(ContentType.JSON);
manager.addRequest(queryReq);
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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<ClientEntity> req = getClient().getRetrieveRequestFactory().getEntityRequest(editLink);
req.setFormat(format);
req.setFormat(contentType);
final ODataRetrieveResponse<ClientEntity> 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<ClientEntity> 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());
}

View File

@ -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<ClientEntity> req =
client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(format);
req.setFormat(contentType);
final AsyncRequestWrapper<ODataRetrieveResponse<ClientEntity>> async =
client.getAsyncRequestFactory().<ODataRetrieveResponse<ClientEntity>> 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<ClientEntitySet> req =
client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
req.setFormat(format);
req.setFormat(contentType);
final AsyncRequestWrapper<ODataRetrieveResponse<ClientEntitySet>> async =
client.getAsyncRequestFactory().<ODataRetrieveResponse<ClientEntitySet>> 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);
}
}

View File

@ -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<ClientEntity> 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<ClientEntity> changeReq =
client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.PATCH, patch);
changeReq.setFormat(ODataFormat.JSON_FULL_METADATA);
changeReq.setFormat(ContentType.JSON_FULL_METADATA);
changeset.addRequest(changeReq);
// -------------------------------------------

View File

@ -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<ClientEntity> 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<ClientEntity> 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<ClientEntity> 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<ClientEntity> 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<ClientEntity> 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<ClientEntity> 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<ClientEntity> queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
queryReq.setFormat(ODataFormat.JSON);
queryReq.setFormat(ContentType.JSON);
async.addRetrieve(queryReq);
// -------------------------------------------

View File

@ -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<ClientSingleton> 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<ClientProperty> 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<ClientEntity> 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<ClientEntitySet> getProductDetailsReq =
client.getInvokeRequestFactory().getFunctionInvokeRequest(boundOp.getTarget(), ClientEntitySet.class,
Collections.<String, ClientValue> 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<ClientEntity> 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<ClientEntity> 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<ClientProperty> 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<ClientProperty> getActualAmountReq =
client.getInvokeRequestFactory().getFunctionInvokeRequest(boundOp.getTarget(), ClientProperty.class,
Collections.<String, ClientValue> 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<ClientEntity> 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<ClientProperty> increaseRevenueReq =
client.getInvokeRequestFactory().getActionInvokeRequest(boundOp.getTarget(), ClientProperty.class,
Collections.<String, ClientValue> 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<ClientProperty> getProductDetailsReq =
client.getInvokeRequestFactory().getActionInvokeRequest(boundOp.getTarget(), ClientProperty.class,
Collections.<String, ClientValue> 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<ClientEntity> 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<ClientEntity> getDefaultPIReq =
client.getInvokeRequestFactory().getActionInvokeRequest(boundOp.getTarget(), ClientEntity.class,
Collections.<String, ClientValue> 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

View File

@ -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<ClientEntity> 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<ClientEntitySet> 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<ClientEntitySet> 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<ClientEntity> 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<ClientEntity> 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<ClientEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(ODataFormat.JSON_FULL_METADATA);
req.setFormat(ContentType.JSON_FULL_METADATA);
ODataRetrieveResponse<ClientEntity> 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<ClientEntitySet> req =
client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
req.setFormat(ODataFormat.JSON_FULL_METADATA);
req.setFormat(ContentType.JSON_FULL_METADATA);
final AsyncRequestWrapper<ODataRetrieveResponse<ClientEntitySet>> async =
client.getAsyncRequestFactory().<ODataRetrieveResponse<ClientEntitySet>> getAsyncRequestWrapper(req);
@ -408,7 +408,7 @@ public class ConformanceTestITCase extends AbstractTestITCase {
final ODataEntityRequest<ClientEntity> 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()));

View File

@ -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<ClientEntitySet> 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);
}
}

View File

@ -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<ClientEntitySet> 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<ClientEntity> createRes = createReq.execute();
assertEquals(201, createRes.getStatusCode());
@ -127,7 +127,7 @@ public class DerivedTypeTestITCase extends AbstractTestITCase {
final ODataEntityRequest<ClientEntity> 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);
}
}

View File

@ -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<ClientEntity> req = getClient().getCUDRequestFactory().
getEntityCreateRequest(uri, instrument);
req.setFormat(format);
req.setFormat(contentType);
final ODataEntityCreateResponse<ClientEntity> 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<ClientEntity> req = getClient().getCUDRequestFactory().getEntityCreateRequest(
getClient().newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Products").build(), product);
req.setFormat(format);
req.setFormat(contentType);
final ODataEntityCreateResponse<ClientEntity> 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);
}
}

View File

@ -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<ClientEntity> req = client.getRetrieveRequestFactory().
getEntityRequest(uriBuilder.build());
req.setFormat(format);
req.setFormat(contentType);
final ODataRetrieveResponse<ClientEntity> 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<ClientEntity> req = client.getRetrieveRequestFactory().
getEntityRequest(uriBuilder.build());
req.setFormat(format);
req.setFormat(contentType);
final ODataRetrieveResponse<ClientEntity> 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<String, Object> multiKey = new LinkedHashMap<String, Object>();
multiKey.put("ProductID", "6");
multiKey.put("ProductDetailID", 1);
@ -204,7 +206,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
final ODataEntityRequest<ClientEntity> req =
client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(format);
req.setFormat(contentType);
final ODataRetrieveResponse<ClientEntity> 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<ClientEntity> req =
client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(format);
req.setFormat(contentType);
final ODataRetrieveResponse<ClientEntity> 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<ClientEntity> 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<ClientEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(format);
req.setFormat(contentType);
ODataRetrieveResponse<ClientEntity> 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<ClientEntity> 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<ClientEntity> 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);
}
}

View File

@ -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<ClientEntitySet, ClientEntity> req =
client.getRetrieveRequestFactory().getEntitySetIteratorRequest(uriBuilder.build());
req.setFormat(format);
req.setFormat(contentType);
final ODataRetrieveResponse<ClientEntitySetIterator<ClientEntitySet, ClientEntity>> res = req.execute();
final ClientEntitySetIterator<ClientEntitySet, ClientEntity> 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<ClientEntitySet> 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);
}
}

View File

@ -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<ClientEntity> 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<ClientEntity> req = getClient().getCUDRequestFactory().
getEntityUpdateRequest(uri, UpdateType.PATCH, changes);
req.setFormat(format);
req.setFormat(contentType);
final ODataEntityUpdateResponse<ClientEntity> 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<ClientEntity> req = getClient().getCUDRequestFactory().
getEntityUpdateRequest(uri, UpdateType.PATCH, changes);
req.setFormat(format);
req.setFormat(contentType);
final ODataEntityUpdateResponse<ClientEntity> 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);
}
}

View File

@ -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();

View File

@ -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<ClientEntitySet> 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());

View File

@ -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<ClientEntity> 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> 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<EntityCollection> 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());

View File

@ -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<ClientEntity> req =
client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(format);
req.setFormat(contentType);
final ODataRetrieveResponse<ClientEntity> 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<ClientEntity> req = getClient().getCUDRequestFactory().
getEntityUpdateRequest(uri, UpdateType.PATCH, changes);
req.setFormat(format);
req.setFormat(contentType);
final ODataEntityUpdateResponse<ClientEntity> 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);
}
}

View File

@ -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<ClientEntity> 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<ClientEntity> updateReq = getClient().getCUDRequestFactory().
getEntityUpdateRequest(createdLocation, UpdateType.PATCH, changes);
updateReq.setFormat(format);
updateReq.setFormat(contentType);
final ODataEntityUpdateResponse<ClientEntity> 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<ClientEntity> updateReq = client.getCUDRequestFactory().
getMediaEntityUpdateRequest(uri, IOUtils.toInputStream(random));
updateReq.setFormat(format);
updateReq.setFormat(contentType);
final MediaEntityUpdateStreamManager<ClientEntity> streamManager = updateReq.payloadManager();
final ODataMediaEntityUpdateResponse<ClientEntity> 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);
}
}

View File

@ -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<ClientEntity> req =
client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(format);
req.setFormat(contentType);
final ODataRetrieveResponse<ClientEntity> 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);
}
}

View File

@ -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<ClientEntity> createReq = getClient().getCUDRequestFactory().
getEntityCreateRequest(getClient().newURIBuilder(testOpenTypeServiceRootURL).
appendEntitySetSegment("RowIndex").build(), rowIndex);
createReq.setFormat(format);
createReq.setFormat(contentType);
final ODataEntityCreateResponse<ClientEntity> 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);
}
}

View File

@ -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<ClientProperty> 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.<String, ClientValue> 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.<String, ClientValue> 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<ClientEntitySet> 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.<String, ClientValue> 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<ClientNoContent> discountReq = getClient().getInvokeRequestFactory().
getActionInvokeRequest(getClient().newURIBuilder(testStaticServiceRootURL).
appendOperationCallSegment("Discount").build(), ClientNoContent.class,
Collections.<String, ClientValue> 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.<String, ClientValue> 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<ClientValue> 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.<String, ClientValue> 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);
}
}

View File

@ -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<ClientProperty> 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<ClientProperty> 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<ClientProperty> 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<ClientProperty> retrieveReq =
client.getRetrieveRequestFactory().getPropertyRequest(uriBuilder.build());
retrieveReq.setFormat(format);
retrieveReq.setFormat(contentType);
ODataRetrieveResponse<ClientProperty> 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

View File

@ -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<ClientProperty> 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()));
}

View File

@ -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<ClientEntity> req =
client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(ODataFormat.ATOM);
req.setFormat(ContentType.APPLICATION_ATOM_XML);
final ODataRetrieveResponse<ClientEntity> res = req.execute();
assertNotNull(res);
assertTrue(res.getContentType().replaceAll(" ", "").
startsWith(ODataFormat.JSON.getContentType().toContentTypeString()));
startsWith(ContentType.JSON.toContentTypeString()));
}
/**

View File

@ -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<ClientServiceDocument> 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);
}
}

View File

@ -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<ClientSingleton> 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<ClientSingleton> 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<ClientSingleton> req = getClient().getCUDRequestFactory().
getSingletonUpdateRequest(uri, UpdateType.PATCH, changes);
req.setFormat(format);
req.setFormat(contentType);
final ODataEntityUpdateResponse<ClientSingleton> 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);
}
}

View File

@ -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 <tt>getDefaultPubFormat()</tt>.
@ -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.

View File

@ -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();

View File

@ -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;
/**
* <p>
* 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;
}

View File

@ -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<T extends ODataResponse> extends ODataRequest
Future<T> 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);
}

View File

@ -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<V extends ODataResponse, T extends O
* @return the configured format (or default if not specified).
* @see org.apache.olingo.client.api.Configuration#getDefaultPubFormat()
*/
ODataFormat getFormat();
ContentType getFormat();
/**
* Override configured request format.
*
* @param format request format.
* @see ODataFormat
*/
void setFormat(final ODataFormat format);
void setFormat(final ContentType contentType);
}

View File

@ -33,7 +33,8 @@ import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.Entity;
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.format.Format;
import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -60,7 +61,7 @@ public class ClientEntitySetIterator<ES extends ClientEntitySet, E extends Clien
private final InputStream stream;
private final ODataFormat format;
private final ContentType contentType;
private ES entitySet;
@ -75,17 +76,17 @@ public class ClientEntitySetIterator<ES extends ClientEntitySet, E extends Clien
*
* @param odataClient client instance getting this request
* @param stream source stream.
* @param format OData format.
* @param contentType OData format.
*/
public ClientEntitySetIterator(final ODataClient odataClient, final InputStream stream,
final ODataFormat format) {
final ContentType contentType) {
this.odataClient = odataClient;
this.stream = stream;
this.format = format;
this.contentType = contentType;
this.osEntitySet = new ByteArrayOutputStream();
if (format == ODataFormat.ATOM) {
if (contentType.getODataFormat() == Format.ATOM) {
namespaces = getAllElementAttributes(stream, "feed", osEntitySet);
} else {
namespaces = null;
@ -110,7 +111,7 @@ public class ClientEntitySetIterator<ES extends ClientEntitySet, E extends Clien
@SuppressWarnings("unchecked")
public boolean hasNext() {
if (available && cached == null) {
if (format == ODataFormat.ATOM) {
if (contentType.getODataFormat() == Format.ATOM) {
cached = nextAtomEntityFromEntitySet(stream, osEntitySet, namespaces);
} else {
cached = nextJSONEntityFromEntitySet(stream, osEntitySet);
@ -120,7 +121,7 @@ public class ClientEntitySetIterator<ES extends ClientEntitySet, E extends Clien
available = false;
try {
entitySet = (ES) odataClient.getReader().
readEntitySet(new ByteArrayInputStream(osEntitySet.toByteArray()), format);
readEntitySet(new ByteArrayInputStream(osEntitySet.toByteArray()), contentType);
} catch (final ODataDeserializerException e) {
available = false;
}
@ -211,7 +212,7 @@ public class ClientEntitySetIterator<ES extends ClientEntitySet, E extends Clien
}
if (c >= 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<ES extends ClientEntitySet, E extends Clien
entity.write(">".getBytes(Constants.UTF8));
if (consume(input, "</entry>", entity, true) >= 0) {
atomEntity = odataClient.getDeserializer(ODataFormat.ATOM).
atomEntity = odataClient.getDeserializer(ContentType.APPLICATION_ATOM_XML).
toEntity(new ByteArrayInputStream(entity.toByteArray()));
}
}

View File

@ -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.

View File

@ -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<ClientEntity> entities, ODataFormat format)
InputStream writeEntities(Collection<ClientEntity> 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<URI> reference, ODataFormat format)
InputStream writeReference(ResWrap<URI> reference, ContentType format)
throws ODataSerializerException;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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(

View File

@ -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<T extends ODataResponse>
}
@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);
}

View File

@ -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;
}

View File

@ -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<ODataDelet
}
@Override
public ODataFormat getDefaultFormat() {
public ContentType getDefaultFormat() {
return odataClient.getConfiguration().getDefaultPubFormat();
}

View File

@ -28,13 +28,13 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
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;
@ -66,14 +66,14 @@ public class ODataEntityCreateRequestImpl<E extends ClientEntity>
}
@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<E extends ClientEntity>
public E getBody() {
if (resEntity == null) {
try {
final ResWrap<Entity> resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())).
final ResWrap<Entity> resource = odataClient.getDeserializer(ContentType.parse(getAccept())).
toEntity(getRawResponse());
resEntity = (E) odataClient.getBinder().getODataEntity(resource);

View File

@ -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<E extends ClientEntity>
}
@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<E extends ClientEntity>
public E getBody() {
if (entity == null) {
try {
final ResWrap<Entity> resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())).
final ResWrap<Entity> resource = odataClient.getDeserializer(ContentType.parse(getAccept())).
toEntity(getRawResponse());
entity = (E) odataClient.getBinder().getODataEntity(resource);

View File

@ -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<OD
}
@Override
public ODataFormat getDefaultFormat() {
public ContentType getDefaultFormat() {
return odataClient.getConfiguration().getDefaultFormat();
}
@ -86,7 +86,7 @@ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest<OD
@Override
protected InputStream getPayload() {
try {
return odataClient.getWriter().writeProperty(property, ODataFormat.fromString(getContentType()));
return odataClient.getWriter().writeProperty(property, ContentType.parse(getContentType()));
} catch (final ODataSerializerException e) {
throw new IllegalArgumentException(e);
}
@ -109,7 +109,7 @@ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest<OD
public ClientProperty getBody() {
if (resProperty == null) {
try {
final ResWrap<Property> resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())).
final ResWrap<Property> resource = odataClient.getDeserializer(ContentType.parse(getAccept())).
toProperty(getRawResponse());
resProperty = odataClient.getBinder().getODataProperty(resource);

View File

@ -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<O
}
@Override
public ODataFormat getDefaultFormat() {
public ContentType getDefaultFormat() {
return odataClient.getConfiguration().getDefaultPubFormat();
}
@ -68,7 +68,7 @@ public class ODataReferenceAddingRequestImpl extends AbstractODataBasicRequest<O
} else {
ODataWriter writer = odataClient.getWriter();
try {
return writer.writeReference(reference, ODataFormat.fromString(getContentType()));
return writer.writeReference(reference, ContentType.parse(getContentType()));
} catch (ODataSerializerException e) {
LOG.warn("Error serializing reference {}", reference);
throw new IllegalArgumentException(e);

View File

@ -28,13 +28,14 @@ import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.request.cud.ODataValueUpdateRequest;
import org.apache.olingo.client.api.communication.response.ODataValueUpdateResponse;
import org.apache.olingo.client.api.domain.ClientPrimitiveValue;
import org.apache.olingo.client.api.http.HttpClientException;
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.client.api.domain.ClientPrimitiveValue;
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;
import org.apache.olingo.commons.api.http.HttpMethod;
/**
@ -65,7 +66,7 @@ public class ODataValueUpdateRequestImpl extends AbstractODataBasicRequest<OData
}
@Override
public ODataFormat getDefaultFormat() {
public ContentType getDefaultFormat() {
return odataClient.getConfiguration().getDefaultValueFormat();
}
@ -105,11 +106,11 @@ public class ODataValueUpdateRequestImpl extends AbstractODataBasicRequest<OData
@Override
public ClientPrimitiveValue getBody() {
if (resValue == null) {
final ODataFormat format = ODataFormat.fromString(getAccept());
final ContentType contentType = ContentType.parse(getAccept());
try {
resValue = odataClient.getObjectFactory().newPrimitiveValueBuilder().
setType(format == ODataFormat.TEXT_PLAIN
setType(contentType.getODataFormat() == Format.TEXT_PLAIN
? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
setValue(getRawResponse()).
build();

View File

@ -31,19 +31,20 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
import org.apache.olingo.client.api.communication.request.invoke.ClientNoContent;
import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
import org.apache.olingo.client.api.communication.response.ODataInvokeResponse;
import org.apache.olingo.client.api.http.HttpClientException;
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.client.api.domain.ClientEntity;
import org.apache.olingo.client.api.domain.ClientEntitySet;
import org.apache.olingo.client.api.domain.ClientInvokeResult;
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.client.api.http.HttpClientException;
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.format.ContentType;
import org.apache.olingo.commons.api.format.Format;
import org.apache.olingo.commons.api.http.HttpMethod;
import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
import org.apache.olingo.commons.api.serialization.ODataSerializerException;
@ -91,23 +92,23 @@ public abstract class AbstractODataInvokeRequest<T extends ClientInvokeResult>
}
@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<T extends ClientInvokeResult>
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) {

View File

@ -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<T extends ClientInvokeResult> extends AbstractODataInvokeRequest<T> {
private ODataFormat format;
private ContentType contentType;
public ODataInvokeRequestImpl(final ODataClient odataClient, final Class<T> reference,
final HttpMethod method, final URI uri) {
@ -36,13 +36,13 @@ public class ODataInvokeRequestImpl<T extends ClientInvokeResult> 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;
}
}

View File

@ -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<V> extends AbstractODataRetrieveRequest<V> {
@ -34,8 +33,8 @@ public abstract class AbstractMetadataRequestImpl<V> extends AbstractODataRetrie
}
@Override
public ODataFormat getDefaultFormat() {
return ODataFormat.XML;
public ContentType getDefaultFormat() {
return ContentType.APPLICATION_XML;
}
@Override

View File

@ -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<ClientDelta>
@ -41,7 +41,7 @@ public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest<ClientDe
}
@Override
public ODataFormat getDefaultFormat() {
public ContentType getDefaultFormat() {
return odataClient.getConfiguration().getDefaultPubFormat();
}
@ -65,7 +65,7 @@ public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest<ClientDe
public ClientDelta getBody() {
if (delta == null) {
try {
final ResWrap<Delta> resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())).
final ResWrap<Delta> resource = odataClient.getDeserializer(ContentType.parse(getContentType())).
toDelta(res.getEntity().getContent());
delta = odataClient.getBinder().getODataDelta(resource);

View File

@ -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<E extends ClientEntity>
}
@Override
public ODataFormat getDefaultFormat() {
public ContentType getDefaultFormat() {
return odataClient.getConfiguration().getDefaultPubFormat();
}
@ -75,7 +75,7 @@ public class ODataEntityRequestImpl<E extends ClientEntity>
public E getBody() {
if (entity == null) {
try {
final ResWrap<Entity> resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())).
final ResWrap<Entity> resource = odataClient.getDeserializer(ContentType.parse(getContentType())).
toEntity(getRawResponse());
entity = (E) odataClient.getBinder().getODataEntity(resource);

View File

@ -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<ES extends ClientEntitySet, E ext
}
@Override
public ODataFormat getDefaultFormat() {
public ContentType getDefaultFormat() {
return odataClient.getConfiguration().getDefaultPubFormat();
}
@ -75,7 +75,7 @@ public class ODataEntitySetIteratorRequestImpl<ES extends ClientEntitySet, E ext
public ClientEntitySetIterator<ES, E> getBody() {
if (entitySetIterator == null) {
entitySetIterator = new ClientEntitySetIterator<ES, E>(
odataClient, getRawResponse(), ODataFormat.fromString(getContentType()));
odataClient, getRawResponse(), ContentType.parse(getContentType()));
}
return entitySetIterator;
}

View File

@ -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<ES extends ClientEntitySet>
}
@Override
public ODataFormat getDefaultFormat() {
public ContentType getDefaultFormat() {
return odataClient.getConfiguration().getDefaultPubFormat();
}
@ -79,7 +79,7 @@ public class ODataEntitySetRequestImpl<ES extends ClientEntitySet>
if (entitySet == null) {
try {
final ResWrap<EntityCollection> resource =
odataClient.getDeserializer(ODataFormat.fromString(getContentType())).
odataClient.getDeserializer(ContentType.parse(getContentType())).
toEntitySet(getRawResponse());
entitySet = (ES) odataClient.getBinder().getODataEntitySet(resource);

View File

@ -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<InputStr
ODataMediaRequestImpl(final ODataClient odataClient, final URI query) {
super(odataClient, query);
setAccept(ODataFormat.APPLICATION_OCTET_STREAM.toString());
setContentType(ODataFormat.APPLICATION_OCTET_STREAM.toString());
setAccept(ContentType.APPLICATION_OCTET_STREAM.toString());
setContentType(ContentType.APPLICATION_OCTET_STREAM.toString());
}
@Override
public ODataFormat getDefaultFormat() {
public ContentType getDefaultFormat() {
return odataClient.getConfiguration().getDefaultMediaFormat();
}

View File

@ -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.ODataPropertyRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.client.api.domain.ClientProperty;
import org.apache.olingo.client.api.http.HttpClientException;
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.serialization.ODataDeserializerException;
/**
@ -50,7 +50,7 @@ public class ODataPropertyRequestImpl<T extends ClientProperty>
}
@Override
public ODataFormat getDefaultFormat() {
public ContentType getDefaultFormat() {
return odataClient.getConfiguration().getDefaultFormat();
}
@ -75,7 +75,7 @@ public class ODataPropertyRequestImpl<T extends ClientProperty>
public T getBody() {
if (property == null) {
try {
final ResWrap<Property> resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType()))
final ResWrap<Property> resource = odataClient.getDeserializer(ContentType.parse(getContentType()))
.toProperty(res.getEntity().getContent());
property = (T) odataClient.getBinder().getODataProperty(resource);

View File

@ -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();
}

View File

@ -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<ServiceDocument> resource = odataClient.
getDeserializer(ODataFormat.fromString(getContentType())).toServiceDocument(getRawResponse());
getDeserializer(ContentType.parse(getContentType())).toServiceDocument(getRawResponse());
serviceDocument = odataClient.getBinder().getODataServiceDocument(resource.getPayload());
} catch (final ODataDeserializerException e) {

View File

@ -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<ClientPr
}
@Override
public ODataFormat getDefaultFormat() {
public ContentType getDefaultFormat() {
return odataClient.getConfiguration().getDefaultValueFormat();
}
@ -74,11 +75,11 @@ public class ODataValueRequestImpl extends AbstractODataRetrieveRequest<ClientPr
@Override
public ClientPrimitiveValue getBody() {
if (value == null) {
final ODataFormat format = ODataFormat.fromString(getContentType());
final ContentType contentType = ContentType.parse(getContentType());
try {
value = odataClient.getObjectFactory().newPrimitiveValueBuilder().
setType(format == ODataFormat.TEXT_PLAIN
setType(contentType.getODataFormat() == Format.TEXT_PLAIN
? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
setValue(IOUtils.toString(getRawResponse())).build();
} catch (Exception e) {

View File

@ -34,7 +34,7 @@ import org.apache.olingo.client.api.edm.xml.XMLMetadata;
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotations;
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.http.HttpStatusCode;
public class XMLMetadataRequestImpl
@ -170,7 +170,7 @@ public class XMLMetadataRequestImpl
public XMLMetadata getBody() {
if (metadata == null) {
try {
metadata = odataClient.getDeserializer(ODataFormat.XML).toMetadata(getRawResponse());
metadata = odataClient.getDeserializer(ContentType.APPLICATION_XML).toMetadata(getRawResponse());
} finally {
this.close();
}

View File

@ -24,7 +24,7 @@ import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.request.ODataPayloadManager;
import org.apache.olingo.client.api.communication.request.streamed.ODataStreamedEntityRequest;
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;
/**
@ -37,7 +37,7 @@ public abstract class AbstractODataStreamedEntityRequest<V extends ODataResponse
extends AbstractODataStreamedRequest<V, T>
implements ODataStreamedEntityRequest<V, T> {
private ODataFormat format;
private ContentType contentType;
/**
* Constructor.
@ -50,17 +50,17 @@ public abstract class AbstractODataStreamedEntityRequest<V extends ODataResponse
final URI uri) {
super(odataClient, method, uri);
setAccept(getFormat().getContentType().toContentTypeString());
setAccept(getFormat().toContentTypeString());
}
@Override
public final ODataFormat getFormat() {
return format == null ? odataClient.getConfiguration().getDefaultPubFormat() : format;
public final ContentType getFormat() {
return contentType == null ? odataClient.getConfiguration().getDefaultPubFormat() : contentType;
}
@Override
public final void setFormat(final ODataFormat format) {
this.format = format;
setAccept(format.getContentType().toContentTypeString());
public final void setFormat(final ContentType contentType) {
this.contentType = contentType;
setAccept(contentType.toContentTypeString());
}
}

View File

@ -39,7 +39,6 @@ import org.apache.olingo.client.core.communication.request.AbstractODataRequest;
import org.apache.olingo.client.core.communication.request.Wrapper;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpMethod;
/**
@ -78,7 +77,7 @@ public abstract class AbstractODataStreamedRequest<V extends ODataResponse, T ex
}
@Override
public ODataFormat getDefaultFormat() {
public ContentType getDefaultFormat() {
return odataClient.getConfiguration().getDefaultMediaFormat();
}

View File

@ -28,16 +28,17 @@ import org.apache.olingo.client.api.edm.xml.XMLMetadata;
import org.apache.olingo.client.api.serialization.ClientODataDeserializer;
import org.apache.olingo.client.core.data.JSONServiceDocumentDeserializer;
import org.apache.olingo.client.core.data.XMLServiceDocumentDeserializer;
import org.apache.olingo.client.core.edm.xml.ClientCsdlEdmx;
import org.apache.olingo.client.core.edm.ClientCsdlXMLMetadata;
import org.apache.olingo.client.core.edm.xml.ClientCsdlEdmx;
import org.apache.olingo.commons.api.ODataError;
import org.apache.olingo.commons.api.data.Delta;
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.commons.api.ODataError;
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.api.serialization.ODataDeserializer;
import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
import org.apache.olingo.commons.core.serialization.AtomDeserializer;
@ -59,11 +60,11 @@ public class ClientODataDeserializerImpl implements ClientODataDeserializer {
private final ODataDeserializer deserializer;
private final ODataFormat format;
private final ContentType contentType;
public ClientODataDeserializerImpl(final boolean serverMode, final ODataFormat format) {
this.format = format;
if (format == ODataFormat.XML || format == ODataFormat.ATOM) {
public ClientODataDeserializerImpl(final boolean serverMode, final ContentType contentType) {
this.contentType = contentType;
if (contentType.getODataFormat() == Format.XML || contentType.getODataFormat() == Format.ATOM) {
deserializer = new AtomDeserializer();
} else {
deserializer = new JsonDeserializer(serverMode);
@ -122,7 +123,7 @@ public class ClientODataDeserializerImpl implements ClientODataDeserializer {
@Override
public ResWrap<ServiceDocument> 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<Delta> 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) {

View File

@ -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());
}

View File

@ -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<ClientEntitySet, ClientEntity>(
client, src, ODataFormat.fromString(format))));
client, src, ContentType.parse(format))));
} else if (ClientEntitySet.class.isAssignableFrom(reference)) {
final ResWrap<EntityCollection> resource = client.getDeserializer(ODataFormat.fromString(format))
final ResWrap<EntityCollection> resource = client.getDeserializer(ContentType.parse(format))
.toEntitySet(src);
res = new ResWrap<T>(
resource.getContextURL(),
resource.getMetadataETag(),
reference.cast(client.getBinder().getODataEntitySet(resource)));
} else if (ClientEntity.class.isAssignableFrom(reference)) {
final ResWrap<Entity> container = client.getDeserializer(ODataFormat.fromString(format)).toEntity(src);
final ResWrap<Entity> container = client.getDeserializer(ContentType.parse(format)).toEntity(src);
res = new ResWrap<T>(
container.getContextURL(),
container.getMetadataETag(),
reference.cast(client.getBinder().getODataEntity(container)));
} else if (ClientProperty.class.isAssignableFrom(reference)) {
final ResWrap<Property> container = client.getDeserializer(ODataFormat.fromString(format)).toProperty(src);
final ResWrap<Property> container = client.getDeserializer(ContentType.parse(format)).toProperty(src);
res = new ResWrap<T>(
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<ServiceDocument> resource =
client.getDeserializer(ODataFormat.fromString(format)).toServiceDocument(src);
client.getDeserializer(ContentType.parse(format)).toServiceDocument(src);
res = new ResWrap<T>(
resource.getContextURL(),
resource.getMetadataETag(),
@ -141,7 +141,7 @@ public class ODataReaderImpl implements ODataReader {
res = new ResWrap<T>(
(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));
}
}

View File

@ -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<ClientEntity> entities, final ODataFormat format)
public InputStream writeEntities(final Collection<ClientEntity> 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.<ClientEntity>singleton(entity), format);
return writeEntities(Collections.<ClientEntity>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<URI> reference, ODataFormat format) throws ODataSerializerException {
public InputStream writeReference(ResWrap<URI> 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 {

View File

@ -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";
}
}

View File

@ -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 {

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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));

View File

@ -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");

View File

@ -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<ClientValue> typedValue = getClient().getObjectFactory().
newCollectionValue(property.getCollectionValue().getTypeName());
for (final Iterator<ClientValue> 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);
}
}

View File

@ -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<ServiceDocument> service = getClient().getDeserializer(format).toServiceDocument(
getClass().getResourceAsStream("serviceDocument." + getFileExtension(format)));
private ClientServiceDocument parse(final ContentType contentType) throws ODataDeserializerException {
ResWrap<ServiceDocument> service = getClient().getDeserializer(contentType).toServiceDocument(
getClass().getResourceAsStream("serviceDocument." + getFileExtension(contentType)));
assertEquals(URI.create("http://host/service/$metadata"), service.getContextURL());
assertEquals("W/\"MjAxMy0wNS0xM1QxNDo1NFo=\"", service.getMetadataETag());
@ -65,11 +66,11 @@ public class ServiceDocumentTest extends AbstractTest {
@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);
}
}

View File

@ -122,14 +122,14 @@ public class AcceptType {
/**
* Creates a list of {@link AcceptType} objects based on given input string (<code>format</code>).
* @param format accept types, comma-separated, as specified for the HTTP header <code>Accept</code>
* @param contentType accept types, comma-separated, as specified for the HTTP header <code>Accept</code>
* @return a list of <code>AcceptType</code> objects
* @throws IllegalArgumentException if input string is not parseable
*/
public static List<AcceptType> create(final String format) {
public static List<AcceptType> create(final String contentType) {
List<AcceptType> result = new ArrayList<AcceptType>();
String[] values = format.split(",");
String[] values = contentType.split(",");
for (String value : values) {
result.add(new AcceptType(value.trim()));
}

View File

@ -50,13 +50,19 @@ public final class ContentType {
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);
@ -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 <code>ContentType</code> 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);
@ -331,6 +337,49 @@ public final class ContentType {
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();

View File

@ -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
}

View File

@ -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));
}
}

View File

@ -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

View File

@ -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);
}

Some files were not shown because too many files have changed in this diff Show More