[OLINGO-260] Filter/orderby and search tests

This commit is contained in:
Francesco Chicchiriccò 2014-05-15 15:56:28 +02:00 committed by Stephan Klevenz
parent 5bcf4752b7
commit 9c3e506d5e
14 changed files with 167 additions and 81 deletions

View File

@ -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 <C> actual client class
*/
public final class EntityContainerFactory {
public final class EntityContainerFactory<C extends CommonEdmEnabledODataClient<?>> {
private static final Object MONITOR = new Object();
private static Context context = null;
private static final Map<String, EntityContainerFactory> FACTORY_PER_SERVICEROOT =
new ConcurrentHashMap<String, EntityContainerFactory>();
private static final Map<String, EntityContainerFactory<?>> FACTORY_PER_SERVICEROOT =
new ConcurrentHashMap<String, EntityContainerFactory<?>>();
private static final Map<Class<?>, Object> ENTITY_CONTAINERS = new ConcurrentHashMap<Class<?>, Object>();
@ -57,23 +58,28 @@ public final class EntityContainerFactory {
return context;
}
private static <C extends CommonEdmEnabledODataClient<?>> EntityContainerFactory getInstance(
@SuppressWarnings("unchecked")
private static <C extends CommonEdmEnabledODataClient<?>> EntityContainerFactory<C> getInstance(
final C client, final String serviceRoot) {
if (!FACTORY_PER_SERVICEROOT.containsKey(serviceRoot)) {
final EntityContainerFactory instance = new EntityContainerFactory(client, serviceRoot);
final EntityContainerFactory<C> instance = new EntityContainerFactory<C>(client, serviceRoot);
FACTORY_PER_SERVICEROOT.put(serviceRoot, instance);
}
client.getConfiguration().setDefaultPubFormat(ODataPubFormat.JSON_FULL_METADATA);
return FACTORY_PER_SERVICEROOT.get(serviceRoot);
return (EntityContainerFactory<C>) FACTORY_PER_SERVICEROOT.get(serviceRoot);
}
public static EntityContainerFactory getV3(final String serviceRoot) {
public static EntityContainerFactory<org.apache.olingo.client.api.v3.EdmEnabledODataClient> getV3(
final String serviceRoot) {
return getInstance(ODataClientFactory.getEdmEnabledV3(serviceRoot), serviceRoot);
}
public static EntityContainerFactory getV4(final String serviceRoot) {
public static EntityContainerFactory<org.apache.olingo.client.api.v4.EdmEnabledODataClient> 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() {

View File

@ -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<CommonODataEntity> res =
client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()).execute();
@ -355,15 +359,37 @@ class EntitySetInvocationHandler<
}
@Override
public Query<T, EC> createQuery() {
return new QueryImpl<T, EC>(this.client, this.collTypeRef, this.uri, this);
public Filter<T, EC> createFilter() {
return new FilterImpl<T, EC>(this.client, this.collTypeRef, this.uri, this);
}
@Override
public <S extends T, SEC extends AbstractEntityCollection<S>> Query<S, SEC> createQuery(
@SuppressWarnings("unchecked")
public <S extends T, SEC extends AbstractEntityCollection<S>> Filter<S, SEC> createFilter(
final Class<SEC> reference) {
return new QueryImpl<S, SEC>(this.client, reference, this.uri, this);
return new FilterImpl<S, SEC>(
this.client, reference, this.uri, (EntitySetInvocationHandler<S, ?, SEC>) this);
}
@Override
public Search<T, EC> createSearch() {
if (client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) {
throw new UnsupportedInV3Exception();
}
return new SearchImpl<T, EC>((EdmEnabledODataClient) this.client, this.collTypeRef, this.uri, this);
}
@Override
@SuppressWarnings("unchecked")
public <S extends T, SEC extends AbstractEntityCollection<S>> Search<S, SEC> createSearch(
final Class<SEC> reference) {
if (client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) {
throw new UnsupportedInV3Exception();
}
return new SearchImpl<S, SEC>(
(EdmEnabledODataClient) this.client, reference, this.uri, (EntitySetInvocationHandler<S, ?, SEC>) this);
}
@Override

View File

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

View File

@ -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<String, String> providedAsync = new HashMap<String, String>();
private final Map<String, String> providedAsync = new HashMap<String, String>();
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());

View File

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

View File

@ -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<EdmEnabledODataClient> ecf =
EntityContainerFactory.getV3(testActionOverloadingServiceRootURL);
ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
return ecf.getEntityContainer(DefaultContainer.class);
}

View File

@ -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<ProductCollection> futureProds =
new AsyncCall<ProductCollection>(containerFactory.getConfiguration()) {
new AsyncCall<ProductCollection>(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<Void> futureFlush = new AsyncCall<Void>(containerFactory.getConfiguration()) {
final Future<Void> futureFlush = new AsyncCall<Void>(containerFactory.getClient().getConfiguration()) {
@Override
public Void call() {
@ -87,7 +87,7 @@ public class AsyncTestITCase extends AbstractTestITCase {
Thread.sleep(1000L);
}
final Future<Product> futureProd = new AsyncCall<Product>(containerFactory.getConfiguration()) {
final Future<Product> futureProd = new AsyncCall<Product>(containerFactory.getClient().getConfiguration()) {
@Override
public Product call() {
@ -100,22 +100,23 @@ public class AsyncTestITCase extends AbstractTestITCase {
@Test
public void polymorphQuery() throws Exception {
final Future<Query<Employee, EmployeeCollection>> queryEmployee =
new AsyncCall<Query<Employee, EmployeeCollection>>(containerFactory.getConfiguration()) {
final Future<Filter<Employee, EmployeeCollection>> queryEmployee =
new AsyncCall<Filter<Employee, EmployeeCollection>>(containerFactory.getClient().getConfiguration()) {
@Override
public Query<Employee, EmployeeCollection> call() {
return container.getPerson().createQuery(EmployeeCollection.class);
public Filter<Employee, EmployeeCollection> call() {
return container.getPerson().createFilter(EmployeeCollection.class);
}
};
assertFalse(queryEmployee.get().getResult().isEmpty());
final Future<Query<SpecialEmployee, SpecialEmployeeCollection>> querySpecialEmployee =
new AsyncCall<Query<SpecialEmployee, SpecialEmployeeCollection>>(containerFactory.getConfiguration()) {
final Future<Filter<SpecialEmployee, SpecialEmployeeCollection>> querySpecialEmployee =
new AsyncCall<Filter<SpecialEmployee, SpecialEmployeeCollection>>(
containerFactory.getClient().getConfiguration()) {
@Override
public Query<SpecialEmployee, SpecialEmployeeCollection> call() {
return container.getPerson().createQuery(SpecialEmployeeCollection.class);
public Filter<SpecialEmployee, SpecialEmployeeCollection> call() {
return container.getPerson().createFilter(SpecialEmployeeCollection.class);
}
};
assertFalse(querySpecialEmployee.get().getResult().isEmpty());

View File

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

View File

@ -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<EdmEnabledODataClient> testContainerFactory =
EntityContainerFactory.getV3(testPrimitiveKeysServiceRootURL);
testContainerFactory.getClient().getConfiguration().
setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
final TestContext testContainer = testContainerFactory.getEntityContainer(TestContext.class);
assertNotNull(testContainer);

View File

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

View File

@ -37,7 +37,7 @@ public class AsyncTestITCase extends AbstractTestITCase {
@Test
public void retrieveEntitySet() throws InterruptedException, ExecutionException {
final Future<CustomerCollection> futureCustomers =
new AsyncCall<CustomerCollection>(containerFactory.getConfiguration()) {
new AsyncCall<CustomerCollection>(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<Void> futureFlush = new AsyncCall<Void>(containerFactory.getConfiguration()) {
final Future<Void> futureFlush = new AsyncCall<Void>(containerFactory.getClient().getConfiguration()) {
@Override
public Void call() {
@ -79,7 +79,7 @@ public class AsyncTestITCase extends AbstractTestITCase {
Thread.sleep(1000L);
}
final Future<Person> futureProd = new AsyncCall<Person>(containerFactory.getConfiguration()) {
final Future<Person> futureProd = new AsyncCall<Person>(containerFactory.getClient().getConfiguration()) {
@Override
public Person call() {

View File

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

View File

@ -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<EdmEnabledODataClient> ecf =
EntityContainerFactory.getV4(testKeyAsSegmentServiceRootURL);
ecf.getClient().getConfiguration().setKeyAsSegment(true);
ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
return ecf.getEntityContainer(InMemoryEntities.class);
}

View File

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