From 9c3e506d5e530f600d7c9d298422689e2e0f062d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= <--global> Date: Thu, 15 May 2014 15:56:28 +0200 Subject: [PATCH] [OLINGO-260] Filter/orderby and search tests --- .../ext/proxy/EntityContainerFactory.java | 33 +++++++++------ .../commons/EntitySetInvocationHandler.java | 40 +++++++++++++++---- .../org/apache/olingo/fit/V3Services.java | 16 ++++++++ .../org/apache/olingo/fit/V4Services.java | 28 ++++++++++++- .../fit/proxy/v3/AbstractTestITCase.java | 18 ++++----- .../proxy/v3/ActionOverloadingTestITCase.java | 6 ++- .../olingo/fit/proxy/v3/AsyncTestITCase.java | 25 ++++++------ .../fit/proxy/v3/OpenTypeTestITCase.java | 11 ++--- .../fit/proxy/v3/PrimitiveKeysTestITCase.java | 7 +++- .../fit/proxy/v4/AbstractTestITCase.java | 5 ++- .../olingo/fit/proxy/v4/AsyncTestITCase.java | 6 +-- .../proxy/v4/EntityRetrieveTestITCase.java | 25 +++++++----- .../fit/proxy/v4/KeyAsSegmentTestITCase.java | 8 ++-- .../fit/proxy/v4/OpenTypeTestITCase.java | 20 +++++----- 14 files changed, 167 insertions(+), 81 deletions(-) diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java index 3e8606eb3..c378a7a0e 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java @@ -22,7 +22,6 @@ import java.lang.reflect.Proxy; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.lang3.StringUtils; -import org.apache.olingo.client.api.CommonConfiguration; import org.apache.olingo.client.api.CommonEdmEnabledODataClient; import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.format.ODataPubFormat; @@ -30,16 +29,18 @@ import org.apache.olingo.ext.proxy.commons.EntityContainerInvocationHandler; import org.apache.olingo.ext.proxy.context.Context; /** - * Entry point for ODataJClient proxy mode, gives access to entity container instances. + * Entry point for proxy mode, gives access to entity container instances. + * + * @param actual client class */ -public final class EntityContainerFactory { +public final class EntityContainerFactory> { private static final Object MONITOR = new Object(); private static Context context = null; - private static final Map FACTORY_PER_SERVICEROOT = - new ConcurrentHashMap(); + private static final Map> FACTORY_PER_SERVICEROOT = + new ConcurrentHashMap>(); private static final Map, Object> ENTITY_CONTAINERS = new ConcurrentHashMap, Object>(); @@ -57,23 +58,28 @@ public final class EntityContainerFactory { return context; } - private static > EntityContainerFactory getInstance( + @SuppressWarnings("unchecked") + private static > EntityContainerFactory getInstance( final C client, final String serviceRoot) { if (!FACTORY_PER_SERVICEROOT.containsKey(serviceRoot)) { - final EntityContainerFactory instance = new EntityContainerFactory(client, serviceRoot); + final EntityContainerFactory instance = new EntityContainerFactory(client, serviceRoot); FACTORY_PER_SERVICEROOT.put(serviceRoot, instance); } client.getConfiguration().setDefaultPubFormat(ODataPubFormat.JSON_FULL_METADATA); - - return FACTORY_PER_SERVICEROOT.get(serviceRoot); + + return (EntityContainerFactory) FACTORY_PER_SERVICEROOT.get(serviceRoot); } - public static EntityContainerFactory getV3(final String serviceRoot) { + public static EntityContainerFactory getV3( + final String serviceRoot) { + return getInstance(ODataClientFactory.getEdmEnabledV3(serviceRoot), serviceRoot); } - public static EntityContainerFactory getV4(final String serviceRoot) { + public static EntityContainerFactory getV4( + final String serviceRoot) { + return getInstance(ODataClientFactory.getEdmEnabledV4(serviceRoot), serviceRoot); } @@ -82,8 +88,9 @@ public final class EntityContainerFactory { this.serviceRoot = serviceRoot; } - public CommonConfiguration getConfiguration() { - return client.getConfiguration(); + @SuppressWarnings("unchecked") + public C getClient() { + return (C) client; } public String getServiceRoot() { diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java index bee8d128e..dcd78120e 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java @@ -36,16 +36,20 @@ import org.apache.commons.lang3.ArrayUtils; 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.uri.CommonURIBuilder; +import org.apache.olingo.client.api.v3.UnsupportedInV3Exception; +import org.apache.olingo.client.api.v4.EdmEnabledODataClient; import org.apache.olingo.client.api.v4.ODataClient; import org.apache.olingo.commons.api.domain.CommonODataEntity; import org.apache.olingo.commons.api.domain.CommonODataEntitySet; import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.format.ODataValueFormat; import org.apache.olingo.ext.proxy.EntityContainerFactory; import org.apache.olingo.ext.proxy.api.AbstractEntityCollection; import org.apache.olingo.ext.proxy.api.AbstractEntitySet; import org.apache.olingo.ext.proxy.api.AbstractSingleton; -import org.apache.olingo.ext.proxy.api.Query; +import org.apache.olingo.ext.proxy.api.Filter; +import org.apache.olingo.ext.proxy.api.Search; import org.apache.olingo.ext.proxy.api.annotations.CompoundKey; import org.apache.olingo.ext.proxy.api.annotations.CompoundKeyElement; import org.apache.olingo.ext.proxy.api.annotations.EntitySet; @@ -93,7 +97,7 @@ class EntitySetInvocationHandler< final String entitySetName) { super(containerHandler.getClient(), containerHandler); - + this.entitySetName = entitySetName; this.isSingleton = AbstractSingleton.class.isAssignableFrom(ref); @@ -245,7 +249,7 @@ class EntitySetInvocationHandler< uriBuilder.appendKeySegment(getCompoundKey(key)); } - LOG.debug("Execute query '{}'", uriBuilder.toString()); + LOG.debug("GET {}", uriBuilder.toString()); final ODataRetrieveResponse res = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()).execute(); @@ -355,15 +359,37 @@ class EntitySetInvocationHandler< } @Override - public Query createQuery() { - return new QueryImpl(this.client, this.collTypeRef, this.uri, this); + public Filter createFilter() { + return new FilterImpl(this.client, this.collTypeRef, this.uri, this); } @Override - public > Query createQuery( + @SuppressWarnings("unchecked") + public > Filter createFilter( final Class reference) { - return new QueryImpl(this.client, reference, this.uri, this); + return new FilterImpl( + this.client, reference, this.uri, (EntitySetInvocationHandler) this); + } + + @Override + public Search createSearch() { + if (client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) { + throw new UnsupportedInV3Exception(); + } + return new SearchImpl((EdmEnabledODataClient) this.client, this.collTypeRef, this.uri, this); + } + + @Override + @SuppressWarnings("unchecked") + public > Search createSearch( + final Class reference) { + + if (client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) { + throw new UnsupportedInV3Exception(); + } + return new SearchImpl( + (EdmEnabledODataClient) this.client, reference, this.uri, (EntitySetInvocationHandler) this); } @Override diff --git a/fit/src/main/java/org/apache/olingo/fit/V3Services.java b/fit/src/main/java/org/apache/olingo/fit/V3Services.java index 45642c37e..410fcad41 100644 --- a/fit/src/main/java/org/apache/olingo/fit/V3Services.java +++ b/fit/src/main/java/org/apache/olingo/fit/V3Services.java @@ -210,6 +210,22 @@ public class V3Services extends AbstractServices { return new ByteArrayInputStream(bos.toByteArray()); } + @GET + @Path("/Car/{type:.*}") + public Response filterCar( + @Context UriInfo uriInfo, + @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, + @QueryParam("$top") @DefaultValue(StringUtils.EMPTY) String top, + @QueryParam("$skip") @DefaultValue(StringUtils.EMPTY) String skip, + @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format, + @QueryParam("$inlinecount") @DefaultValue(StringUtils.EMPTY) String count, + @QueryParam("$filter") @DefaultValue(StringUtils.EMPTY) String filter, + @QueryParam("$orderby") @DefaultValue(StringUtils.EMPTY) String orderby, + @QueryParam("$skiptoken") @DefaultValue(StringUtils.EMPTY) String skiptoken) { + + return super.getEntitySet(uriInfo, accept, "Car", top, skip, format, count, filter, orderby, skiptoken); + } + @GET @Path("/Login({entityId})") public Response getLogin( diff --git a/fit/src/main/java/org/apache/olingo/fit/V4Services.java b/fit/src/main/java/org/apache/olingo/fit/V4Services.java index 2d774d548..52d8cb62c 100644 --- a/fit/src/main/java/org/apache/olingo/fit/V4Services.java +++ b/fit/src/main/java/org/apache/olingo/fit/V4Services.java @@ -54,6 +54,7 @@ import javax.ws.rs.core.UriInfo; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; import org.apache.cxf.interceptor.InInterceptors; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; @@ -102,7 +103,7 @@ public class V4Services extends AbstractServices { protected static final Pattern CROSSJOIN_PATTERN = Pattern.compile( "^\\$crossjoin\\(.*\\)\\?\\$filter=\\([a-zA-Z/]+ eq [a-zA-Z/]+\\)$"); - private Map providedAsync = new HashMap(); + private final Map providedAsync = new HashMap(); public V4Services() throws Exception { super(ODataServiceVersion.V40, Commons.getMetadata(ODataServiceVersion.V40)); @@ -345,6 +346,29 @@ public class V4Services extends AbstractServices { return new ByteArrayInputStream(bos.toByteArray()); } + @GET + @Path("/People/{type:.*}") + public Response getPeople( + @Context UriInfo uriInfo, + @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, + @PathParam("type") final String type, + @QueryParam("$top") @DefaultValue(StringUtils.EMPTY) String top, + @QueryParam("$skip") @DefaultValue(StringUtils.EMPTY) String skip, + @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format, + @QueryParam("$inlinecount") @DefaultValue(StringUtils.EMPTY) String count, + @QueryParam("$filter") @DefaultValue(StringUtils.EMPTY) String filter, + @QueryParam("$search") @DefaultValue(StringUtils.EMPTY) String search, + @QueryParam("$orderby") @DefaultValue(StringUtils.EMPTY) String orderby, + @QueryParam("$skiptoken") @DefaultValue(StringUtils.EMPTY) String skiptoken) { + + return StringUtils.isBlank(filter) && StringUtils.isBlank(search) + ? NumberUtils.isNumber(type) + ? super.getEntityInternal( + uriInfo.getRequestUri().toASCIIString(), accept, "People", type, format, null, null, true) + : super.getEntitySet(accept, "People", type) + : super.getEntitySet(uriInfo, accept, "People", top, skip, format, count, filter, orderby, skiptoken); + } + @GET @Path("/Boss") public Response getSingletonBoss( @@ -1239,7 +1263,7 @@ public class V4Services extends AbstractServices { acceptType = Accept.parse(accept, version); } - final Accept contentTypeValue = Accept.parse(contentType, version); + final Accept contentTypeValue = Accept.parse(contentType, version); final AtomEntityImpl entity = xml.readEntity(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING)); assert "Microsoft.Test.OData.Services.ODataWCFService.Address".equals(entity.getType()); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java index 987ecb5e1..de9cdc3b8 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java @@ -26,19 +26,17 @@ import static org.junit.Assert.assertNotNull; import java.io.IOException; import java.util.Arrays; import java.util.Collections; +import org.apache.olingo.client.api.v3.EdmEnabledODataClient; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.ext.proxy.EntityContainerFactory; import org.apache.olingo.ext.proxy.context.EntityContext; import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice. DefaultContainer; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice. - types.ContactDetails; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice. - types.Customer; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice. - types.Aliases; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice. - types.Phone; +import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types. + ContactDetails; +import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Customer; +import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Aliases; +import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Phone; import org.junit.BeforeClass; import org.slf4j.Logger; @@ -69,7 +67,7 @@ public abstract class AbstractTestITCase { protected final EntityContext entityContext = EntityContainerFactory.getContext().entityContext(); - protected static EntityContainerFactory containerFactory; + protected static EntityContainerFactory containerFactory; protected static DefaultContainer container; @@ -84,7 +82,7 @@ public abstract class AbstractTestITCase { testAuthServiceRootURL = "http://localhost:9080/stub/DefaultService.svc"; containerFactory = EntityContainerFactory.getV3(testStaticServiceRootURL); - containerFactory.getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); + containerFactory.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); container = containerFactory.getEntityContainer(DefaultContainer.class); assertNotNull(container); EntityContainerFactory.getContext().detachAll(); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java index c573af67b..c0e65c9b7 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import org.apache.olingo.client.api.v3.EdmEnabledODataClient; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.ext.proxy.EntityContainerFactory; import org.apache.olingo.fit.proxy.v3.actionoverloading.microsoft.test.odata.services.astoriadefaultservice. @@ -44,8 +45,9 @@ import org.junit.Test; public class ActionOverloadingTestITCase extends AbstractTestITCase { private DefaultContainer getContainer() { - final EntityContainerFactory ecf = EntityContainerFactory.getV3(testActionOverloadingServiceRootURL); - ecf.getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); + final EntityContainerFactory ecf = + EntityContainerFactory.getV3(testActionOverloadingServiceRootURL); + ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); return ecf.getEntityContainer(DefaultContainer.class); } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AsyncTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AsyncTestITCase.java index 3cd51bcd1..70346f74d 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AsyncTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AsyncTestITCase.java @@ -27,7 +27,7 @@ import java.util.UUID; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import org.apache.olingo.ext.proxy.api.AsyncCall; -import org.apache.olingo.ext.proxy.api.Query; +import org.apache.olingo.ext.proxy.api.Filter; import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Employee; import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types. EmployeeCollection; @@ -45,7 +45,7 @@ public class AsyncTestITCase extends AbstractTestITCase { @Test public void retrieveEntitySet() throws InterruptedException, ExecutionException { final Future futureProds = - new AsyncCall(containerFactory.getConfiguration()) { + new AsyncCall(containerFactory.getClient().getConfiguration()) { @Override public ProductCollection call() { @@ -73,7 +73,7 @@ public class AsyncTestITCase extends AbstractTestITCase { final Product product = container.getProduct().get(-10); product.setDescription("AsyncTest#updateEntity " + random); - final Future futureFlush = new AsyncCall(containerFactory.getConfiguration()) { + final Future futureFlush = new AsyncCall(containerFactory.getClient().getConfiguration()) { @Override public Void call() { @@ -87,7 +87,7 @@ public class AsyncTestITCase extends AbstractTestITCase { Thread.sleep(1000L); } - final Future futureProd = new AsyncCall(containerFactory.getConfiguration()) { + final Future futureProd = new AsyncCall(containerFactory.getClient().getConfiguration()) { @Override public Product call() { @@ -100,22 +100,23 @@ public class AsyncTestITCase extends AbstractTestITCase { @Test public void polymorphQuery() throws Exception { - final Future> queryEmployee = - new AsyncCall>(containerFactory.getConfiguration()) { + final Future> queryEmployee = + new AsyncCall>(containerFactory.getClient().getConfiguration()) { @Override - public Query call() { - return container.getPerson().createQuery(EmployeeCollection.class); + public Filter call() { + return container.getPerson().createFilter(EmployeeCollection.class); } }; assertFalse(queryEmployee.get().getResult().isEmpty()); - final Future> querySpecialEmployee = - new AsyncCall>(containerFactory.getConfiguration()) { + final Future> querySpecialEmployee = + new AsyncCall>( + containerFactory.getClient().getConfiguration()) { @Override - public Query call() { - return container.getPerson().createQuery(SpecialEmployeeCollection.class); + public Filter call() { + return container.getPerson().createFilter(SpecialEmployeeCollection.class); } }; assertFalse(querySpecialEmployee.get().getResult().isEmpty()); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java index 3cc863d54..28b768f7d 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java @@ -28,7 +28,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.UUID; - +import org.apache.olingo.client.api.v3.EdmEnabledODataClient; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.ext.proxy.EntityContainerFactory; import org.apache.olingo.ext.proxy.api.annotations.EntityType; @@ -37,7 +37,6 @@ import org.apache.olingo.fit.proxy.v3.opentype.microsoft.test.odata.services.ope import org.apache.olingo.fit.proxy.v3.opentype.microsoft.test.odata.services.opentypesservicev3.types.Row; import org.apache.olingo.fit.proxy.v3.opentype.microsoft.test.odata.services.opentypesservicev3.types.RowIndex; import org.junit.BeforeClass; - import org.junit.Test; /** @@ -49,8 +48,10 @@ public class OpenTypeTestITCase extends AbstractTestITCase { @BeforeClass public static void initContainer() { - final EntityContainerFactory otcontainerFactory = EntityContainerFactory.getV3(testOpenTypeServiceRootURL); - otcontainerFactory.getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); + final EntityContainerFactory otcontainerFactory = + EntityContainerFactory.getV3(testOpenTypeServiceRootURL); + otcontainerFactory.getClient().getConfiguration(). + setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); otcontainer = otcontainerFactory.getEntityContainer(DefaultContainer.class); assertNotNull(otcontainer); } @@ -93,7 +94,7 @@ public class OpenTypeTestITCase extends AbstractTestITCase { Calendar cal = Calendar.getInstance(); cal.clear(); - cal.setTime(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").parse("2001-04-05T05:05:05.001+00:01")); + cal.setTime(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse("2001-04-05T05:05:05.001")); contact.setLastContacted(cal); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/PrimitiveKeysTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/PrimitiveKeysTestITCase.java index a99a583bb..f0a491207 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/PrimitiveKeysTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/PrimitiveKeysTestITCase.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertEquals; import java.math.BigDecimal; import java.util.UUID; +import org.apache.olingo.client.api.v3.EdmEnabledODataClient; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.ext.proxy.EntityContainerFactory; import org.apache.olingo.fit.proxy.v3.primitivekeys.microsoft.test.odata.services.primitivekeysservice.TestContext; @@ -45,8 +46,10 @@ public class PrimitiveKeysTestITCase extends AbstractTestITCase { @Test public void readPrimitiveKeys() { - final EntityContainerFactory testContainerFactory = EntityContainerFactory.getV3(testPrimitiveKeysServiceRootURL); - testContainerFactory.getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); + final EntityContainerFactory testContainerFactory = + EntityContainerFactory.getV3(testPrimitiveKeysServiceRootURL); + testContainerFactory.getClient().getConfiguration(). + setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); final TestContext testContainer = testContainerFactory.getEntityContainer(TestContext.class); assertNotNull(testContainer); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AbstractTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AbstractTestITCase.java index f6be6c925..baa412898 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AbstractTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AbstractTestITCase.java @@ -27,6 +27,7 @@ import java.math.BigDecimal; import java.util.Arrays; import java.util.Calendar; import java.util.TimeZone; +import org.apache.olingo.client.api.v4.EdmEnabledODataClient; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.ext.proxy.EntityContainerFactory; import org.apache.olingo.ext.proxy.context.EntityContext; @@ -60,7 +61,7 @@ public abstract class AbstractTestITCase { protected final EntityContext entityContext = EntityContainerFactory.getContext().entityContext(); - protected static EntityContainerFactory containerFactory; + protected static EntityContainerFactory containerFactory; protected static InMemoryEntities container; @@ -74,7 +75,7 @@ public abstract class AbstractTestITCase { testAuthServiceRootURL = "http://localhost:9080/stub/DefaultService.svc"; containerFactory = EntityContainerFactory.getV4(testStaticServiceRootURL); - containerFactory.getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); + containerFactory.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); container = containerFactory.getEntityContainer(InMemoryEntities.class); assertNotNull(container); EntityContainerFactory.getContext().detachAll(); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AsyncTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AsyncTestITCase.java index f5f45616f..b0cbbddb0 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AsyncTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AsyncTestITCase.java @@ -37,7 +37,7 @@ public class AsyncTestITCase extends AbstractTestITCase { @Test public void retrieveEntitySet() throws InterruptedException, ExecutionException { final Future futureCustomers = - new AsyncCall(containerFactory.getConfiguration()) { + new AsyncCall(containerFactory.getClient().getConfiguration()) { @Override public CustomerCollection call() { @@ -65,7 +65,7 @@ public class AsyncTestITCase extends AbstractTestITCase { Person person = container.getPeople().get(1); person.setFirstName(randomFirstName); - final Future futureFlush = new AsyncCall(containerFactory.getConfiguration()) { + final Future futureFlush = new AsyncCall(containerFactory.getClient().getConfiguration()) { @Override public Void call() { @@ -79,7 +79,7 @@ public class AsyncTestITCase extends AbstractTestITCase { Thread.sleep(1000L); } - final Future futureProd = new AsyncCall(containerFactory.getConfiguration()) { + final Future futureProd = new AsyncCall(containerFactory.getClient().getConfiguration()) { @Override public Person call() { diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityRetrieveTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityRetrieveTestITCase.java index efad794a2..ee5b04901 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityRetrieveTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityRetrieveTestITCase.java @@ -29,6 +29,7 @@ import java.util.Calendar; import java.util.TimeZone; import org.apache.commons.lang3.StringUtils; import org.apache.olingo.ext.proxy.commons.EntityTypeInvocationHandler; +import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities; import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.AccessLevel; import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Address; import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Company; @@ -53,10 +54,14 @@ import org.junit.Test; */ public class EntityRetrieveTestITCase extends AbstractTestITCase { + protected InMemoryEntities getContainer() { + return container; + } + @Test public void exists() { - assertTrue(container.getCustomers().exists(1)); - assertFalse(container.getOrders().exists(1)); + assertTrue(getContainer().getCustomers().exists(1)); + assertFalse(getContainer().getOrders().exists(1)); } @Test @@ -66,21 +71,21 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { @Test public void getAll() { - final PersonCollection all = container.getPeople().getAll(); + final PersonCollection all = getContainer().getPeople().getAll(); assertNotNull(all); assertFalse(all.isEmpty()); for (Person person : all) { assertNotNull(person); } - final EmployeeCollection employees = container.getPeople().getAll(EmployeeCollection.class); + final EmployeeCollection employees = getContainer().getPeople().getAll(EmployeeCollection.class); assertNotNull(employees); assertFalse(employees.isEmpty()); for (Employee employee : employees) { assertNotNull(employee); } - final CustomerCollection customers = container.getPeople().getAll(CustomerCollection.class); + final CustomerCollection customers = getContainer().getPeople().getAll(CustomerCollection.class); assertNotNull(customers); assertFalse(customers.isEmpty()); for (Customer customer : customers) { @@ -92,7 +97,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { @Test public void navigate() { - final Order order = container.getOrders().get(8); + final Order order = getContainer().getOrders().get(8); assertNotNull(order); assertEquals(8, order.getOrderID(), 0); @@ -103,7 +108,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { actual.set(2011, 2, 4, 16, 3, 57); assertEquals(actual.getTimeInMillis(), date.getTimeInMillis()); - final Customer customer = container.getCustomers().get(1); + final Customer customer = getContainer().getCustomers().get(1); assertNotNull(customer); assertEquals(1, customer.getPersonID(), 0); final Address address = customer.getHomeAddress(); @@ -128,7 +133,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { @Test public void withActions() { - final Product product = container.getProducts().get(5); + final Product product = getContainer().getProducts().get(5); assertEquals(5, product.getProductID(), 0); try { @@ -144,7 +149,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { orderDetailKey.setOrderID(7); orderDetailKey.setProductID(5); - final OrderDetail orderDetail = container.getOrderDetails().get(orderDetailKey); + final OrderDetail orderDetail = getContainer().getOrderDetails().get(orderDetailKey); assertNotNull(orderDetail); assertEquals(7, orderDetail.getOrderID(), 0); assertEquals(5, orderDetail.getProductID(), 0); @@ -152,7 +157,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { @Test public void checkForETag() { - final Order order = container.getOrders().get(8); + final Order order = getContainer().getOrders().get(8); assertTrue(StringUtils.isNotBlank(((EntityTypeInvocationHandler) Proxy.getInvocationHandler(order)).getETag())); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/KeyAsSegmentTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/KeyAsSegmentTestITCase.java index 817d2716d..a99213354 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/KeyAsSegmentTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/KeyAsSegmentTestITCase.java @@ -21,6 +21,7 @@ package org.apache.olingo.fit.proxy.v4; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import org.apache.olingo.client.api.v4.EdmEnabledODataClient; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.ext.proxy.EntityContainerFactory; import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities; @@ -30,9 +31,10 @@ import org.junit.Test; public class KeyAsSegmentTestITCase extends AbstractTestITCase { private InMemoryEntities getContainer() { - final EntityContainerFactory ecf = EntityContainerFactory.getV3(testKeyAsSegmentServiceRootURL); - ecf.getConfiguration().setKeyAsSegment(true); - ecf.getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); + final EntityContainerFactory ecf = + EntityContainerFactory.getV4(testKeyAsSegmentServiceRootURL); + ecf.getClient().getConfiguration().setKeyAsSegment(true); + ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); return ecf.getEntityContainer(InMemoryEntities.class); } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/OpenTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/OpenTypeTestITCase.java index b1b61c8ea..11f7d07d5 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/OpenTypeTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/OpenTypeTestITCase.java @@ -18,7 +18,6 @@ */ package org.apache.olingo.fit.proxy.v4; - import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -29,7 +28,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.UUID; - +import org.apache.olingo.client.api.v4.EdmEnabledODataClient; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.ext.proxy.EntityContainerFactory; import org.apache.olingo.ext.proxy.api.annotations.EntityType; @@ -39,7 +38,6 @@ import org.apache.olingo.fit.proxy.v4.opentype.microsoft.test.odata.services.ope import org.apache.olingo.fit.proxy.v4.opentype.microsoft.test.odata.services.opentypesservicev4.types.Row; import org.apache.olingo.fit.proxy.v4.opentype.microsoft.test.odata.services.opentypesservicev4.types.RowIndex; import org.junit.BeforeClass; - import org.junit.Test; /** @@ -51,8 +49,10 @@ public class OpenTypeTestITCase extends AbstractTestITCase { @BeforeClass public static void initContainer() { - final EntityContainerFactory otcontainerFactory = EntityContainerFactory.getV4(testOpenTypeServiceRootURL); - otcontainerFactory.getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); + final EntityContainerFactory otcontainerFactory = + EntityContainerFactory.getV4(testOpenTypeServiceRootURL); + otcontainerFactory.getClient().getConfiguration(). + setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); otcontainer = otcontainerFactory.getEntityContainer(DefaultContainer.class); assertNotNull(otcontainer); } @@ -95,10 +95,10 @@ public class OpenTypeTestITCase extends AbstractTestITCase { Calendar cal = Calendar.getInstance(); cal.clear(); - cal.setTime(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").parse("2001-04-05T05:05:05.001+00:01")); + cal.setTime(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse("2001-04-05T05:05:05.001")); contact.setLastContacted(cal); - + cal = Calendar.getInstance(); cal.clear(); cal.setTime(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse("2001-04-05T05:05:04.001")); @@ -114,7 +114,7 @@ public class OpenTypeTestITCase extends AbstractTestITCase { contact.setInt(Integer.MAX_VALUE); rowIndex.addAdditionalProperty("aContact", contact); rowIndex.addAdditionalProperty("aColor", Color.Green); - + otcontainer.flush(); rowIndex = otcontainer.getRowIndex().get(id); @@ -129,10 +129,10 @@ public class OpenTypeTestITCase extends AbstractTestITCase { assertEquals(Color.Green, rowIndex.getAdditionalProperty("aColor")); entityContext.detachAll(); - + otcontainer.getRowIndex().delete(id); otcontainer.flush(); - + assertNull(otcontainer.getRowIndex().get(id)); } }