provided the possibility to specify query options at proxy layer

This commit is contained in:
fmartelli 2014-07-13 18:08:58 +02:00
parent 2df9426bd3
commit baf2cd1098
62 changed files with 808 additions and 846 deletions

View File

@ -36,24 +36,24 @@ import org.apache.olingo.ext.proxy.context.Context;
*
* @param <C> actual client class
*/
public final class EntityContainerFactory<C extends CommonEdmEnabledODataClient<?>> {
public final class Service<C extends CommonEdmEnabledODataClient<?>> {
private static final Map<String, EntityContainerFactory<?>> FACTORY_PER_SERVICEROOT =
new ConcurrentHashMap<String, EntityContainerFactory<?>>();
private static final Map<String, Service<?>> FACTORY_PER_SERVICEROOT =
new ConcurrentHashMap<String, Service<?>>();
private final Map<Class<?>, Object> ENTITY_CONTAINERS = new ConcurrentHashMap<Class<?>, Object>();
@SuppressWarnings("unchecked")
private static <C extends CommonEdmEnabledODataClient<?>> EntityContainerFactory<C> getInstance(
private static <C extends CommonEdmEnabledODataClient<?>> Service<C> getInstance(
final C client, final boolean transactional) {
if (!FACTORY_PER_SERVICEROOT.containsKey(client.getServiceRoot())) {
client.getConfiguration().setDefaultPubFormat(ODataFormat.JSON_FULL_METADATA);
final EntityContainerFactory<C> instance = new EntityContainerFactory<C>(client, transactional);
final Service<C> instance = new Service<C>(client, transactional);
FACTORY_PER_SERVICEROOT.put(client.getServiceRoot(), instance);
}
return (EntityContainerFactory<C>) FACTORY_PER_SERVICEROOT.get(client.getServiceRoot());
return (Service<C>) FACTORY_PER_SERVICEROOT.get(client.getServiceRoot());
}
/**
@ -62,7 +62,7 @@ public final class EntityContainerFactory<C extends CommonEdmEnabledODataClient<
* @param serviceRoot OData service root
* @return OData 3.0 instance for given service root, operating in transactions (with batch requests)
*/
public static EntityContainerFactory<org.apache.olingo.client.api.v3.EdmEnabledODataClient> getV3(
public static Service<org.apache.olingo.client.api.v3.EdmEnabledODataClient> getV3(
final String serviceRoot) {
return getV3(serviceRoot, true);
@ -75,7 +75,7 @@ public final class EntityContainerFactory<C extends CommonEdmEnabledODataClient<
* @param transactional whether operating in transactions (with batch requests) or not
* @return OData 3.0 instance for given service root
*/
public static EntityContainerFactory<org.apache.olingo.client.api.v3.EdmEnabledODataClient> getV3(
public static Service<org.apache.olingo.client.api.v3.EdmEnabledODataClient> getV3(
final String serviceRoot, final boolean transactional) {
return getInstance(ODataClientFactory.getEdmEnabledV3(serviceRoot), transactional);
@ -87,7 +87,7 @@ public final class EntityContainerFactory<C extends CommonEdmEnabledODataClient<
* @param serviceRoot OData service root
* @return OData 4.0 instance for given service root, operating in transactions (with batch requests)
*/
public static EntityContainerFactory<org.apache.olingo.client.api.v4.EdmEnabledODataClient> getV4(
public static Service<org.apache.olingo.client.api.v4.EdmEnabledODataClient> getV4(
final String serviceRoot) {
return getV4(serviceRoot, true);
@ -100,7 +100,7 @@ public final class EntityContainerFactory<C extends CommonEdmEnabledODataClient<
* @param transactional whether operating in transactions (with batch requests) or not
* @return OData 4.0 instance for given service root
*/
public static EntityContainerFactory<org.apache.olingo.client.api.v4.EdmEnabledODataClient> getV4(
public static Service<org.apache.olingo.client.api.v4.EdmEnabledODataClient> getV4(
final String serviceRoot, final boolean transactional) {
return getInstance(ODataClientFactory.getEdmEnabledV4(serviceRoot), transactional);
@ -114,7 +114,7 @@ public final class EntityContainerFactory<C extends CommonEdmEnabledODataClient<
private PersistenceManager persistenceManager;
private EntityContainerFactory(final CommonEdmEnabledODataClient<?> client, final boolean transactional) {
private Service(final CommonEdmEnabledODataClient<?> client, final boolean transactional) {
this.client = client;
this.context = new Context();
this.transactional = transactional;

View File

@ -24,7 +24,7 @@ import java.io.Serializable;
* Interface for synchronous CRUD operations on an EntitySet.
*/
public interface AbstractEntitySet<
T extends Serializable, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
T extends StructuredType, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
extends Iterable<T>, Serializable {
/**
@ -43,7 +43,7 @@ public interface AbstractEntitySet<
* @return the entity with the given id or null if none found
* @throws IllegalArgumentException in case the given key is null
*/
T get(KEY key) throws IllegalArgumentException;
T getByKey(KEY key) throws IllegalArgumentException;
/**
* Retrieves an entity by its key, considering polymorphism.
@ -54,7 +54,7 @@ public interface AbstractEntitySet<
* @return the entity with the given id or null if none found
* @throws IllegalArgumentException in case the given key is null
*/
<S extends T> S get(KEY key, Class<S> reference) throws IllegalArgumentException;
<S extends T> S getByKey(KEY key, Class<S> reference) throws IllegalArgumentException;
/**
* Returns the number of entities available.
@ -63,23 +63,6 @@ public interface AbstractEntitySet<
*/
Long count();
/**
* Returns all instances.
*
* @return all entities
*/
EC getAll();
/**
* Returns all instances of the given subtype.
*
* @param <S>
* @param <SEC>
* @param reference entity collection class to be returned
* @return all entities of the given subtype
*/
<S extends T, SEC extends AbstractEntityCollection<S>> SEC getAll(Class<SEC> reference);
/**
* Deletes the entity with the given key.
*
@ -96,23 +79,6 @@ public interface AbstractEntitySet<
*/
<S extends T> void delete(Iterable<S> entities);
/**
* Create an instance of <tt>Filter</tt>.
*
* @return the new filter instance
*/
Filter<T, EC> createFilter();
/**
* Create an instance of <tt>Filter</tt>.
*
* @param <S>
* @param <SEC>
* @param reference
* @return the new filter instance
*/
<S extends T, SEC extends AbstractEntityCollection<S>> Filter<S, SEC> createFilter(Class<SEC> reference);
/**
* Create an instance of <tt>Search</tt>.
*

View File

@ -23,11 +23,4 @@ import java.io.Serializable;
public interface AbstractSingleton<
T extends Serializable, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
extends Serializable {
/**
* Retrieves a singleton.
*
* @return the singleton
*/
T get();
}

View File

@ -18,13 +18,78 @@
*/
package org.apache.olingo.ext.proxy.api;
import java.io.Serializable;
import org.apache.olingo.client.api.uri.URIFilter;
public interface CollectionQuery<T extends Serializable, EC extends AbstractEntityCollection<T>> {
public interface CollectionQuery<T extends StructuredType, EC extends AbstractEntityCollection<T>>
extends CommonQuery<CollectionQuery<T, EC>> {
/**
* Returns all instances.
*
* @return structured type.
* @return all entities
*/
EC execute();
/**
* Returns all instances of the given subtype.
*
* @param <S>
* @param <SEC>
* @param reference entity collection class to be returned
* @return all entities of the given subtype
*/
<S extends T, SEC extends AbstractEntityCollection<S>> SEC execute(Class<SEC> reference);
/**
* Sets the <tt>$filter</tt> expression.
* <br/>
* Any of available operators and functions can be embodied here.
*
* @param filter the <tt>$filter</tt> expression.
* @return the same query instance.
*/
CollectionQuery<T, EC> filter(String filter);
/**
* Sets the filter generating the <tt>$filter</tt> expression.
*
* @param filter filter instance (to be obtained via factory): note that <tt>build()</tt> method will be immediately
* invoked.
* @return the same query instance.
*/
CollectionQuery<T, EC> filter(URIFilter filter);
/**
* Sets the <tt>$orderBy</tt> expression.
*
* @param sort sort options.
* @return the same query instance.
*/
CollectionQuery<T, EC> orderBy(Sort... sort);
/**
* Sets the <tt>$orderBy</tt> expression.
*
* @param orderBy the <tt>$orderBy</tt> expression.
* @return the same query instance.
*/
CollectionQuery<T, EC> orderBy(String orderBy);
/**
* Sets the maximum number of results to retrieve (<tt>$top</tt>).
*
* @param top maximum number of results to retrieve
* @return the same query instance.
* @throws IllegalArgumentException if the argument is negative
*/
CollectionQuery<T, EC> top(int top) throws IllegalArgumentException;
/**
* Sets the position of the first result to retrieve (<tt>$skip</tt>).
*
* @param skip position of the first result, numbered from 0
* @return the same query instance.
* @throws IllegalArgumentException if the argument is negative
*/
CollectionQuery<T, EC> skip(int skip) throws IllegalArgumentException;
}

View File

@ -0,0 +1,45 @@
/*
* 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.ext.proxy.api;
public interface CommonQuery<T> {
/**
* Sets <tt>$expand</tt> expression.
*
* @param expand <tt>$expand</tt> expression items.
* @return the same query instance.
*/
T expand(String... expand);
/**
* Sets <tt>$select</tt> expression.
*
* @param select <tt>$select</tt> expression items.
* @return the same query instance.
*/
T select(String... select);
/**
* Remove all query options.
*
* @return the same query instance.
*/
T clear();
}

View File

@ -1,131 +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.ext.proxy.api;
import java.io.Serializable;
import org.apache.olingo.client.api.uri.URIFilter;
/**
* Interface used to control filter execution.
*
* @param <T> filter result type
* @param <EC>
*/
public interface Filter<T extends Serializable, EC extends AbstractEntityCollection<T>> extends Serializable {
/**
* Sets the <tt>$filter</tt> expression for this filter.
* <br/>
* Any of available operators and functions can be embodied here.
*
* @param filter the <tt>$filter</tt> expression for this filter
* @return the same filter instance
*/
Filter<T, EC> setFilter(String filter);
/**
* Sets the filter generating the <tt>$filter</tt> expression for this filter.
*
* @param filter filter instance (to be obtained via factory): note that <tt>build()</tt> method
* will be immediately invoked.
* @return the same filter instance
*/
Filter<T, EC> setFilter(URIFilter filter);
/**
* The <tt>$filter</tt> expression for this filter.
*
* @return the <tt>$filter</tt> expression for this filter
*/
String getFilter();
/**
* Sets the <tt>$orderBy</tt> expression for this filter via sort options.
*
* @param sort sort options
* @return the same filter instance
*/
Filter<T, EC> setOrderBy(Sort... sort);
/**
* Sets the <tt>$orderBy</tt> expression for this filter.
*
* @param orderBy the <tt>$orderBy</tt> expression for this filter
* @return the same filter instance
*/
Filter<T, EC> setOrderBy(String orderBy);
/**
* The <tt>$orderBy</tt> expression for this filter.
*
* @return the <tt>$orderBy</tt> expression for this filter
*/
String getOrderBy();
/**
* Sets the maximum number of results to retrieve (<tt>$top</tt>).
*
* @param maxResults maximum number of results to retrieve
* @return the same filter instance
* @throws IllegalArgumentException if the argument is negative
*/
Filter<T, EC> setMaxResults(int maxResults) throws IllegalArgumentException;
/**
* The maximum number of results the filter object was set to retrieve (<tt>$top</tt>). Returns
* <tt>Integer.MAX_VALUE</tt> if setMaxResults was not applied to the filter object.
*
* @return maximum number of results
*/
int getMaxResults();
/**
* Sets the position of the first result to retrieve (<tt>$skip</tt>).
*
* @param firstResult position of the first result, numbered from 0
* @return the same filter instance
* @throws IllegalArgumentException if the argument is negative
*/
Filter<T, EC> setFirstResult(int firstResult) throws IllegalArgumentException;
/**
* The position of the first result the filter object was set to retrieve (<tt>$skip</tt>).
*
* Returns 0 if <tt>setFirstResult</tt> was not applied to the filter object.
*
* @return position of the first result
*/
int getFirstResult();
/**
* Executes a <tt>$filter</tt> filter that returns a single result.
*
* @return the result
* @throws NoResultException if there is no result
* @throws NonUniqueResultException if more than one result
*/
T getSingleResult() throws NoResultException, NonUniqueResultException;
/**
* Executes a <tt>$filter</tt> filter and return the filter results as collection.
*
* @return an iterable view of the results
*/
EC getResult();
}

View File

@ -18,10 +18,10 @@
*/
package org.apache.olingo.ext.proxy.api;
public interface SingleQuery<T extends StructuredType> {
public interface SingleQuery<T extends StructuredType> extends CommonQuery<T> {
/**
*
*
* @return structured type.
*/
T load();

View File

@ -47,7 +47,7 @@ import org.apache.olingo.commons.api.edm.EdmOperation;
import org.apache.olingo.commons.api.edm.EdmReturnType;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
import org.apache.olingo.ext.proxy.EntityContainerFactory;
import org.apache.olingo.ext.proxy.Service;
import org.apache.olingo.ext.proxy.api.OperationType;
import org.apache.olingo.ext.proxy.api.annotations.Operation;
import org.apache.olingo.ext.proxy.api.annotations.Parameter;
@ -60,11 +60,11 @@ abstract class AbstractInvocationHandler implements InvocationHandler {
private static final long serialVersionUID = 358520026931462958L;
protected EntityContainerFactory<?> factory;
protected Service<?> factory;
protected EntityContainerInvocationHandler containerHandler;
protected AbstractInvocationHandler(final EntityContainerFactory<?> factory) {
protected AbstractInvocationHandler(final Service<?> factory) {
this.factory = factory;
}

View File

@ -42,7 +42,7 @@ import org.apache.olingo.commons.api.domain.ODataLinkType;
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.ext.proxy.EntityContainerFactory;
import org.apache.olingo.ext.proxy.Service;
import org.apache.olingo.ext.proxy.api.PersistenceManager;
import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty;
import org.apache.olingo.ext.proxy.context.AttachedEntity;
@ -61,9 +61,9 @@ abstract class AbstractPersistenceManager implements PersistenceManager {
private static final long serialVersionUID = 2065240290461241515L;
protected final EntityContainerFactory<?> factory;
protected final Service<?> factory;
AbstractPersistenceManager(final EntityContainerFactory<?> factory) {
AbstractPersistenceManager(final Service<?> factory) {
this.factory = factory;
}

View File

@ -115,7 +115,10 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
if (isSelfMethod(method, args)) {
if ("expand".equals(method.getName()) || "select".equals(method.getName())) {
invokeSelfMethod(method, args);
return proxy;
} else if (isSelfMethod(method, args)) {
return invokeSelfMethod(method, args);
} else if ("load".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
load();

View File

@ -22,7 +22,7 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.olingo.ext.proxy.EntityContainerFactory;
import org.apache.olingo.ext.proxy.Service;
import org.apache.olingo.ext.proxy.api.annotations.EntityContainer;
import org.apache.olingo.ext.proxy.api.annotations.EntitySet;
import org.apache.olingo.ext.proxy.api.annotations.Singleton;
@ -39,14 +39,14 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
private final boolean defaultEC;
public static EntityContainerInvocationHandler getInstance(
final Class<?> ref, final EntityContainerFactory<?> factory) {
final Class<?> ref, final Service<?> factory) {
final EntityContainerInvocationHandler instance = new EntityContainerInvocationHandler(ref, factory);
instance.containerHandler = instance;
return instance;
}
private EntityContainerInvocationHandler(final Class<?> ref, final EntityContainerFactory<?> factory) {
private EntityContainerInvocationHandler(final Class<?> ref, final Service<?> factory) {
super(factory);
final Annotation annotation = ref.getAnnotation(EntityContainer.class);
@ -60,7 +60,7 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
this.namespace = ((EntityContainer) annotation).namespace();
}
protected EntityContainerFactory<?> getFactory() {
protected Service<?> getFactory() {
return factory;
}

View File

@ -67,7 +67,9 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
private static final long serialVersionUID = 2629912294765040037L;
protected URI entityURI;
private URI baseURI;
private CommonURIBuilder<?> uri;
protected final Map<String, Object> propertyChanges = new HashMap<String, Object>();
@ -109,7 +111,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
return new EntityInvocationHandler(key, entity, entitySetURI, typeRef, containerHandler);
}
static EntityInvocationHandler getInstance(
public static EntityInvocationHandler getInstance(
final CommonODataEntity entity,
final URI entitySetURI,
final Class<?> typeRef,
@ -128,8 +130,12 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
super(typeRef, entity, containerHandler);
final Object key = entityKey == null ? CoreUtils.getKey(getClient(), this, typeRef, entity) : entityKey;
if (key!=null && entity.getEditLink() == null) {
final CommonURIBuilder<?> uriBuilder = containerHandler.getClient().newURIBuilder(entitySetURI.toASCIIString());
if (entity.getEditLink() != null) {
this.baseURI = entity.getEditLink();
this.uri = getClient().newURIBuilder(baseURI.toASCIIString());
} else if (key != null) {
final CommonURIBuilder<?> uriBuilder = getClient().newURIBuilder(entitySetURI.toASCIIString());
if (key.getClass().getAnnotation(CompoundKey.class) == null) {
LOG.debug("Append key segment '{}'", key);
@ -139,10 +145,12 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
uriBuilder.appendKeySegment(getCompoundKey(key));
}
this.entityURI = uriBuilder.build();
entity.setEditLink(entityURI);
this.uri = uriBuilder;
this.baseURI = this.uri.build();
entity.setEditLink(this.baseURI);
} else {
this.entityURI = entity.getEditLink();
this.baseURI = null;
this.uri = null;
}
this.internal = entity;
@ -166,8 +174,9 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
CoreUtils.getKey(getClient(), this, typeRef, entity));
// fix for OLINGO-353
if (this.entityURI == null) {
this.entityURI = entity.getEditLink();
if (this.uri == null) {
this.baseURI = entity.getEditLink();
this.uri = this.baseURI == null ? null : getClient().newURIBuilder(this.baseURI.toASCIIString());
}
this.streamedPropertyChanges.clear();
@ -195,7 +204,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
}
public URI getEntityURI() {
return entityURI;
return this.baseURI;
}
/**
@ -514,7 +523,8 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
try {
final ODataEntityRequest<CommonODataEntity> req =
getClient().getRetrieveRequestFactory().getEntityRequest(entityURI);
getClient().getRetrieveRequestFactory().getEntityRequest(uri.build());
if (getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) > 0) {
req.setPrefer(getClient().newPreferences().includeAnnotations("*"));
}
@ -566,6 +576,18 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
return map;
}
public void expand(final String... expand) {
this.uri.expand(expand);
}
public void select(final String... select) {
this.uri.select(select);
}
public void clear() {
this.uri = getClient().newURIBuilder(baseURI.toASCIIString());
}
@Override
public String toString() {
return uuid.toString();

View File

@ -33,6 +33,7 @@ import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySe
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.uri.URIFilter;
import org.apache.olingo.client.api.v3.UnsupportedInV3Exception;
import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.client.api.v4.ODataClient;
@ -46,9 +47,10 @@ import org.apache.olingo.commons.api.format.ODataFormat;
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.Filter;
import org.apache.olingo.ext.proxy.api.Search;
import org.apache.olingo.ext.proxy.api.SingleQuery;
import org.apache.olingo.ext.proxy.api.Sort;
import org.apache.olingo.ext.proxy.api.StructuredType;
import org.apache.olingo.ext.proxy.api.annotations.EntitySet;
import org.apache.olingo.ext.proxy.context.AttachedEntityStatus;
import org.apache.olingo.ext.proxy.context.EntityContext;
@ -58,7 +60,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class EntitySetInvocationHandler<
T extends Serializable, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
T extends StructuredType, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
extends AbstractInvocationHandler
implements AbstractEntitySet<T, KEY, EC> {
@ -75,7 +77,9 @@ class EntitySetInvocationHandler<
private Class<EC> collTypeRef = null;
private final URI uri;
private final URI baseURI;
private CommonURIBuilder<?> uri;
@SuppressWarnings({"rawtypes", "unchecked"})
static EntitySetInvocationHandler getInstance(
@ -91,14 +95,15 @@ class EntitySetInvocationHandler<
uriBuilder.appendEntitySetSegment(entitySetSegment.toString());
return new EntitySetInvocationHandler(ref, containerHandler, entitySetName, uriBuilder.build());
return new EntitySetInvocationHandler(ref, containerHandler, entitySetName, uriBuilder);
}
@SuppressWarnings({"rawtypes", "unchecked"})
static EntitySetInvocationHandler getInstance(
final Class<?> ref, final EntityContainerInvocationHandler containerHandler, final URI uri) {
final Class<?> ref, final EntityContainerInvocationHandler containerHandler, final URI uri) {;
return new EntitySetInvocationHandler(ref, containerHandler, (ref.getAnnotation(EntitySet.class)).name(), uri);
return new EntitySetInvocationHandler(ref, containerHandler, (ref.getAnnotation(EntitySet.class)).name(),
containerHandler.getClient().newURIBuilder(uri.toASCIIString()));
}
@SuppressWarnings("unchecked")
@ -106,17 +111,18 @@ class EntitySetInvocationHandler<
final Class<?> ref,
final EntityContainerInvocationHandler containerHandler,
final String entitySetName,
final URI uri) {
final CommonURIBuilder<?> uri) {
super(containerHandler);
this.uri = uri;
this.baseURI = uri.build();
this.isSingleton = AbstractSingleton.class.isAssignableFrom(ref);
final Type[] entitySetParams = ClassUtils.extractGenericType(ref, AbstractEntitySet.class, AbstractSingleton.class);
this.typeRef = (Class<T>) entitySetParams[0];
this.collTypeRef = (Class<EC>) entitySetParams[2];
this.uri = uri;
}
protected Class<T> getTypeRef() {
@ -128,12 +134,20 @@ class EntitySetInvocationHandler<
}
protected URI getEntitySetURI() {
return uri;
return this.baseURI;
}
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
if (isSelfMethod(method, args)) {
if ("filter".equals(method.getName())
|| "orderBy".equals(method.getName())
|| "top".equals(method.getName())
|| "skip".equals(method.getName())
|| "expand".equals(method.getName())
|| "select".equals(method.getName())) {
invokeSelfMethod(method, args);
return proxy;
} else if (isSelfMethod(method, args)) {
return invokeSelfMethod(method, args);
} else if (method.getName().startsWith("new") && ArrayUtils.isEmpty(args)) {
if (method.getName().endsWith("Collection")) {
@ -152,7 +166,7 @@ class EntitySetInvocationHandler<
new FullQualifiedName(containerHandler.getSchemaName(), ClassUtils.getEntityTypeName(reference)));
final EntityInvocationHandler handler =
EntityInvocationHandler.getInstance(entity, uri, reference, containerHandler);
EntityInvocationHandler.getInstance(entity, this.baseURI, reference, containerHandler);
getContext().entityContext().attachNew(handler);
return (NE) Proxy.newProxyInstance(
@ -172,7 +186,7 @@ class EntitySetInvocationHandler<
@Override
public Long count() {
final ODataValueRequest req = getClient().getRetrieveRequestFactory().
getValueRequest(getClient().newURIBuilder(this.uri.toASCIIString()).count().build());
getValueRequest(getClient().newURIBuilder(this.uri.build().toASCIIString()).count().build());
req.setFormat(ODataFormat.TEXT_PLAIN);
return Long.valueOf(req.execute().getBody().asPrimitive().toString());
}
@ -180,7 +194,7 @@ class EntitySetInvocationHandler<
@Override
public Boolean exists(final KEY key) throws IllegalArgumentException {
try {
SingleQuery.class.cast(get(key)).load();
SingleQuery.class.cast(getByKey(key)).load();
return true;
} catch (Exception e) {
LOG.error("Could not check existence of {}({})", this.uri, key, e);
@ -189,18 +203,18 @@ class EntitySetInvocationHandler<
}
@Override
public T get(final KEY key) throws IllegalArgumentException {
return get(key, typeRef);
public T getByKey(final KEY key) throws IllegalArgumentException {
return getByKey(key, typeRef);
}
@Override
@SuppressWarnings("unchecked")
public <S extends T> S get(final KEY key, final Class<S> typeRef) throws IllegalArgumentException {
public <S extends T> S getByKey(final KEY key, final Class<S> typeRef) throws IllegalArgumentException {
if (key == null) {
throw new IllegalArgumentException("Null key");
}
final EntityUUID uuid = new EntityUUID(containerHandler.getEntityContainerName(), uri, typeRef, key);
final EntityUUID uuid = new EntityUUID(containerHandler.getEntityContainerName(), this.baseURI, typeRef, key);
LOG.debug("Ask for '{}({})'", typeRef.getSimpleName(), key);
EntityInvocationHandler handler = getContext().entityContext().getEntity(uuid);
@ -209,7 +223,7 @@ class EntitySetInvocationHandler<
final CommonODataEntity entity = getClient().getObjectFactory().newEntity(
new FullQualifiedName(containerHandler.getSchemaName(), ClassUtils.getEntityTypeName(typeRef)));
handler = EntityInvocationHandler.getInstance(key, entity, uri, typeRef, containerHandler);
handler = EntityInvocationHandler.getInstance(key, entity, this.baseURI, typeRef, containerHandler);
} else if (isDeleted(handler)) {
// object deleted
@ -295,19 +309,17 @@ class EntitySetInvocationHandler<
entityCollectionHandler);
}
@Override
public EC getAll() {
return getAll(collTypeRef);
public EC execute() {
return execute(collTypeRef);
}
@SuppressWarnings("unchecked")
@Override
public <S extends T, SEC extends AbstractEntityCollection<S>> SEC getAll(final Class<SEC> collTypeRef) {
public <S extends T, SEC extends AbstractEntityCollection<S>> SEC execute(final Class<SEC> collTypeRef) {
final Class<S> ref = (Class<S>) ClassUtils.extractTypeArg(collTypeRef,
AbstractEntitySet.class, AbstractSingleton.class, AbstractEntityCollection.class);
final Class<S> oref = (Class<S>) ClassUtils.extractTypeArg(this.collTypeRef);
final CommonURIBuilder<?> uriBuilder = getClient().newURIBuilder(this.uri.toASCIIString());
final CommonURIBuilder<?> uriBuilder = getClient().newURIBuilder(this.uri.build().toASCIIString());
final URI entitySetURI;
if (oref.equals(ref)) {
@ -320,25 +332,12 @@ class EntitySetInvocationHandler<
return fetchWholeEntitySet(entitySetURI, ref, collTypeRef);
}
@Override
public Filter<T, EC> createFilter() {
return new FilterImpl<T, EC>(getClient(), this.collTypeRef, this.uri, this);
}
@Override
@SuppressWarnings("unchecked")
public <S extends T, SEC extends AbstractEntityCollection<S>> Filter<S, SEC> createFilter(
final Class<SEC> reference) {
return new FilterImpl<S, SEC>(getClient(), reference, this.uri, (EntitySetInvocationHandler<S, ?, SEC>) this);
}
@Override
public Search<T, EC> createSearch() {
if (getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) {
throw new UnsupportedInV3Exception();
}
return new SearchImpl<T, EC>((EdmEnabledODataClient) getClient(), this.collTypeRef, this.uri, this);
return new SearchImpl<T, EC>((EdmEnabledODataClient) getClient(), this.collTypeRef, this.baseURI, this);
}
@Override
@ -350,7 +349,10 @@ class EntitySetInvocationHandler<
throw new UnsupportedInV3Exception();
}
return new SearchImpl<S, SEC>(
(EdmEnabledODataClient) getClient(), reference, this.uri, (EntitySetInvocationHandler<S, ?, SEC>) this);
(EdmEnabledODataClient) getClient(),
reference,
baseURI,
(EntitySetInvocationHandler<S, ?, SEC>) this);
}
@Override
@ -359,13 +361,13 @@ class EntitySetInvocationHandler<
EntityInvocationHandler entity = entityContext.getEntity(new EntityUUID(
containerHandler.getEntityContainerName(),
uri,
baseURI,
typeRef,
key));
if (entity == null) {
// search for entity
final T searched = get(key);
final T searched = getByKey(key);
entity = (EntityInvocationHandler) Proxy.getInvocationHandler(searched);
entityContext.attach(entity, AttachedEntityStatus.DELETED);
} else {
@ -393,6 +395,48 @@ class EntitySetInvocationHandler<
@Override
public EntitySetIterator<T, KEY, EC> iterator() {
return new EntitySetIterator<T, KEY, EC>(getClient().newURIBuilder(this.uri.toASCIIString()).build(), this);
return new EntitySetIterator<T, KEY, EC>(getClient().newURIBuilder(this.uri.build().toASCIIString()).build(), this);
}
public void filter(final String filter) {
this.uri.filter(filter);
}
public void filter(final URIFilter filter) {
this.uri.filter(filter);
}
public void orderBy(final Sort... sort) {
final StringBuilder builder = new StringBuilder();
for (Sort sortClause : sort) {
builder.append(sortClause.getKey()).append(' ').append(sortClause.getValue()).append(',');
}
builder.deleteCharAt(builder.length() - 1);
this.uri.orderBy(builder.toString());
}
public void orderBy(final String orderBy) {
this.uri.orderBy(orderBy);
}
public void top(final int top) throws IllegalArgumentException {
this.uri.top(top);
}
public void skip(final int skip) throws IllegalArgumentException {
this.uri.skip(skip);
}
public void expand(final String... expand) {
this.uri.expand(expand);
}
public void select(final String... select) {
this.uri.select(select);
}
public void clear() {
this.uri = getClient().newURIBuilder(baseURI.toASCIIString());
}
}

View File

@ -27,8 +27,9 @@ import java.util.NoSuchElementException;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.olingo.commons.api.domain.v4.ODataAnnotation;
import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
import org.apache.olingo.ext.proxy.api.StructuredType;
class EntitySetIterator<T extends Serializable, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
class EntitySetIterator<T extends StructuredType, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
implements Iterator<T> {
private final EntitySetInvocationHandler<T, KEY, EC> esi;

View File

@ -1,174 +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.ext.proxy.commons;
import java.io.Serializable;
import java.net.URI;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.uri.CommonURIBuilder;
import org.apache.olingo.client.api.uri.URIFilter;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
import org.apache.olingo.ext.proxy.api.NoResultException;
import org.apache.olingo.ext.proxy.api.NonUniqueResultException;
import org.apache.olingo.ext.proxy.api.Filter;
import org.apache.olingo.ext.proxy.api.Sort;
import org.apache.olingo.ext.proxy.utils.ClassUtils;
public class FilterImpl<T extends Serializable, EC extends AbstractEntityCollection<T>> implements Filter<T, EC> {
private static final long serialVersionUID = -300830736753191114L;
private final CommonODataClient<?> client;
private final Class<T> typeRef;
private final Class<EC> collTypeRef;
private final EntitySetInvocationHandler<T, ?, EC> handler;
private final URI baseURI;
private String filter;
private String orderBy;
private Integer maxResults;
private Integer firstResult;
@SuppressWarnings("unchecked")
FilterImpl(final CommonODataClient<?> client,
final Class<EC> collTypeRef, final URI baseURI, final EntitySetInvocationHandler<T, ?, EC> handler) {
this.client = client;
this.typeRef = (Class<T>) ClassUtils.extractTypeArg(collTypeRef);
this.collTypeRef = collTypeRef;
this.baseURI = baseURI;
this.handler = handler;
}
@Override
public Filter<T, EC> setFilter(final String filter) {
this.filter = filter;
return this;
}
@Override
public Filter<T, EC> setFilter(final URIFilter filter) {
this.filter = filter.build();
return this;
}
@Override
public String getFilter() {
return filter;
}
@Override
public Filter<T, EC> setOrderBy(final Sort... sort) {
final StringBuilder builder = new StringBuilder();
for (Sort sortClause : sort) {
builder.append(sortClause.getKey()).append(' ').append(sortClause.getValue()).append(',');
}
builder.deleteCharAt(builder.length() - 1);
this.orderBy = builder.toString();
return this;
}
@Override
public Filter<T, EC> setOrderBy(final String orderBy) {
this.orderBy = orderBy;
return this;
}
@Override
public String getOrderBy() {
return orderBy;
}
@Override
public Filter<T, EC> setMaxResults(final int maxResults) throws IllegalArgumentException {
if (maxResults <= 0) {
throw new IllegalArgumentException("maxResults must be positive");
}
this.maxResults = maxResults;
return this;
}
@Override
public int getMaxResults() {
return maxResults;
}
@Override
public Filter<T, EC> setFirstResult(final int firstResult) throws IllegalArgumentException {
if (firstResult <= 0) {
throw new IllegalArgumentException("firstResult must be positive");
}
this.firstResult = firstResult;
return this;
}
@Override
public int getFirstResult() {
return firstResult;
}
@Override
public T getSingleResult() throws NoResultException, NonUniqueResultException {
final EC result = getResult();
if (result.isEmpty()) {
throw new NoResultException();
}
if (result.size() > 1) {
throw new NonUniqueResultException();
}
return result.iterator().next();
}
@Override
public EC getResult() {
CommonURIBuilder<?> uriBuilder = client.newURIBuilder(this.baseURI.toASCIIString());
if(this.client.getConfiguration().isAddressingDerivedTypes()){
uriBuilder = uriBuilder.appendDerivedEntityTypeSegment(new FullQualifiedName(
ClassUtils.getNamespace(typeRef), ClassUtils.getEntityTypeName(typeRef)).toString());
}
if (StringUtils.isNotBlank(filter)) {
uriBuilder.filter(filter);
}
if (StringUtils.isNotBlank(orderBy)) {
uriBuilder.orderBy(orderBy);
}
if (maxResults != null) {
uriBuilder.top(maxResults);
}
if (firstResult != null) {
uriBuilder.skip(firstResult);
}
return handler.fetchWholeEntitySet(uriBuilder.build(), typeRef, collTypeRef);
}
}

View File

@ -24,7 +24,7 @@ import org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
import org.apache.olingo.client.api.communication.response.ODataResponse;
import org.apache.olingo.ext.proxy.EntityContainerFactory;
import org.apache.olingo.ext.proxy.Service;
/**
* {@link org.apache.olingo.ext.proxy.api.PersistenceManager} implementation not using OData batch requests: any
@ -35,7 +35,7 @@ public class NonTransactionalPersistenceManagerImpl extends AbstractPersistenceM
private static final long serialVersionUID = 5082907388513308752L;
public NonTransactionalPersistenceManagerImpl(final EntityContainerFactory<?> factory) {
public NonTransactionalPersistenceManagerImpl(final Service<?> factory) {
super(factory);
}

View File

@ -18,7 +18,6 @@
*/
package org.apache.olingo.ext.proxy.commons;
import java.io.Serializable;
import java.net.URI;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.uri.v4.URIBuilder;
@ -27,9 +26,10 @@ import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
import org.apache.olingo.ext.proxy.api.Search;
import org.apache.olingo.ext.proxy.api.StructuredType;
import org.apache.olingo.ext.proxy.utils.ClassUtils;
public class SearchImpl<T extends Serializable, EC extends AbstractEntityCollection<T>> implements Search<T, EC> {
public class SearchImpl<T extends StructuredType, EC extends AbstractEntityCollection<T>> implements Search<T, EC> {
private static final long serialVersionUID = 4383858176507769973L;

View File

@ -36,7 +36,6 @@ public class SingletonInvocationHandler<
return new SingletonInvocationHandler(ref, containerHandler, singletonName);
}
private final EntitySetInvocationHandler<?, ?, ?> entitySetHandler;
@SuppressWarnings({"rawtypes", "unchecked"})
@ -56,9 +55,8 @@ public class SingletonInvocationHandler<
}
}
@Override
@SuppressWarnings("unchecked")
public T get() {
return (T) this.entitySetHandler.getAll().iterator().next();
public T load() {
return (T) this.entitySetHandler.execute().iterator().next();
}
}

View File

@ -32,7 +32,7 @@ import org.apache.olingo.client.api.communication.response.ODataEntityCreateResp
import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
import org.apache.olingo.client.api.communication.response.ODataResponse;
import org.apache.olingo.client.core.communication.request.batch.ODataChangesetResponseItem;
import org.apache.olingo.ext.proxy.EntityContainerFactory;
import org.apache.olingo.ext.proxy.Service;
/**
* {@link org.apache.olingo.ext.proxy.api.PersistenceManager} implementation using OData batch requests to implement
@ -43,7 +43,7 @@ public class TransactionalPersistenceManagerImpl extends AbstractPersistenceMana
private static final long serialVersionUID = -3320312269235907501L;
public TransactionalPersistenceManagerImpl(final EntityContainerFactory<?> factory) {
public TransactionalPersistenceManagerImpl(final Service<?> factory) {
super(factory);
}

View File

@ -282,7 +282,10 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo {
parseObj(typesBaseDir, typesPkg, "complexType", className + ".java", objs);
}
final List<EdmEntityType> entities = new ArrayList<EdmEntityType>();
for (EdmEntityType entity : schema.getEntityTypes()) {
entities.add(entity);
objs.clear();
objs.put("entityType", entity);
@ -345,6 +348,16 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo {
}
}
}
objs.clear();
objs.put("namespace", schema.getNamespace());
objs.put("complexes", complexes);
parseObj(base, pkg, "complexCreator", "ComplexCreator.java", objs);
objs.clear();
objs.put("namespace", schema.getNamespace());
objs.put("entities", entities);
parseObj(base, pkg, "entityCreator", "EntityCreator.java", objs);
}
final File metaInf = mkdir("META-INF");

View File

@ -0,0 +1,32 @@
#*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*#
package ${package};
import org.apache.olingo.ext.proxy.api.annotations.Namespace;
import org.apache.olingo.ext.proxy.api.annotations.Property;
@org.apache.olingo.ext.proxy.api.annotations.Namespace("$namespace")
public interface ComplexCreator {
#foreach($complex in $complexes)
#set( $type = "${namespace}.${complex.Name}" )
@org.apache.olingo.ext.proxy.api.annotations.Property(name = "$complex.Name", type = "$type")
$utility.getJavaType($type) new$utility.capitalize($complex.Name)();
#end
}

View File

@ -0,0 +1,37 @@
#*
* 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 ${package};
import org.apache.olingo.ext.proxy.api.annotations.Namespace;
import org.apache.olingo.ext.proxy.api.annotations.Property;
@org.apache.olingo.ext.proxy.api.annotations.Namespace("$namespace")
public interface EntityCreator {
#foreach($entity in $entities)
#set( $type = "${namespace}.${entity.Name}" )
#set( $javaType = $utility.getJavaType($type) )
@org.apache.olingo.ext.proxy.api.annotations.Property(name = "$entity.Name", type = "$type")
$javaType new$utility.capitalize($entity.Name)();
@org.apache.olingo.ext.proxy.api.annotations.Property(name = "$entity.Name", type = "$type")
${javaType}Collection new${utility.capitalize($entity.Name)}Collection();
#end
}

View File

@ -239,9 +239,11 @@ public interface $utility.capitalize($entityType.Name)
#set( $type = "" )
#end
#set ( $javaEntityType = $utility.getJavaType($property.Type) )
@org.apache.olingo.ext.proxy.api.annotations.EntitySet(name = "$property.Name", contained = true)
interface $utility.capitalize($property.Name)
extends AbstractEntitySet<$utility.getJavaType($property.Type), $type, $utility.getJavaType($property.Type)Collection> {
extends org.apache.olingo.ext.proxy.api.CollectionQuery<$javaEntityType, ${javaEntityType}Collection>, AbstractEntitySet<$javaEntityType, $type, ${javaEntityType}Collection> {
#foreach( $dos in $utility.getDescendantsOrSelf($utility.getEdmType($property)) )
#set( $djt = $utility.getJavaType($dos) )

View File

@ -29,7 +29,7 @@ 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.Service;
//CHECKSTYLE:OFF (Maven checkstyle)
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.Aliases;
@ -62,7 +62,7 @@ public abstract class AbstractTestITCase {
protected static String testLargeModelServiceRootURL;
protected static EntityContainerFactory<EdmEnabledODataClient> containerFactory;
protected static Service<EdmEnabledODataClient> service;
protected static DefaultContainer container;
@ -75,11 +75,11 @@ public abstract class AbstractTestITCase {
testOpenTypeServiceRootURL = "http://localhost:9080/stub/StaticService/V30/OpenType.svc";
testLargeModelServiceRootURL = "http://localhost:9080/stub/StaticService/V30/Static.svc/large";
containerFactory = EntityContainerFactory.getV3(testStaticServiceRootURL);
containerFactory.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
container = containerFactory.getEntityContainer(DefaultContainer.class);
service = Service.getV3(testStaticServiceRootURL);
service.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
container = service.getEntityContainer(DefaultContainer.class);
assertNotNull(container);
containerFactory.getContext().detachAll();
service.getContext().detachAll();
}
protected Customer getSampleCustomerProfile(
@ -139,7 +139,7 @@ public abstract class AbstractTestITCase {
}
protected Customer readCustomer(final DefaultContainer container, final int id) {
final Customer customer = container.getCustomer().get(id).load();
final Customer customer = container.getCustomer().getByKey(id).load();
assertNotNull(customer);
assertEquals(Integer.valueOf(id), customer.getCustomerId());

View File

@ -24,7 +24,7 @@ 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.ext.proxy.Service;
//CHECKSTYLE:OFF (Maven checkstyle)
import org.apache.olingo.fit.proxy.v3.actionoverloading.microsoft.test.odata.services.astoriadefaultservice.DefaultContainer;
import org.apache.olingo.fit.proxy.v3.actionoverloading.microsoft.test.odata.services.astoriadefaultservice.types.Employee;
@ -41,8 +41,8 @@ import org.junit.Test;
public class ActionOverloadingTestITCase extends AbstractTestITCase {
private DefaultContainer getContainer() {
final EntityContainerFactory<EdmEnabledODataClient> ecf =
EntityContainerFactory.getV3(testActionOverloadingServiceRootURL);
final Service<EdmEnabledODataClient> ecf =
Service.getV3(testActionOverloadingServiceRootURL);
ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
return ecf.getEntityContainer(DefaultContainer.class);
}
@ -54,18 +54,18 @@ public class ActionOverloadingTestITCase extends AbstractTestITCase {
int res = aocontainer.operations().retrieveProduct();
assertEquals(-10, res);
containerFactory.getContext().detachAll();
service.getContext().detachAll();
res = aocontainer.getProduct().get(-10).operations().retrieveProduct();
res = aocontainer.getProduct().getByKey(-10).operations().retrieveProduct();
assertEquals(-10, res);
containerFactory.getContext().detachAll();
service.getContext().detachAll();
final OrderLineKey key = new OrderLineKey();
key.setOrderId(-10);
key.setProductId(-10);
res = aocontainer.getOrderLine().get(key).operations().retrieveProduct();
res = aocontainer.getOrderLine().getByKey(key).operations().retrieveProduct();
assertEquals(-10, res);
}
@ -73,7 +73,7 @@ public class ActionOverloadingTestITCase extends AbstractTestITCase {
public void increaseSalaries() {
final DefaultContainer aocontainer = getContainer();
EmployeeCollection ecoll = aocontainer.getPerson().getAll(EmployeeCollection.class);
EmployeeCollection ecoll = aocontainer.getPerson().execute(EmployeeCollection.class);
assertFalse(ecoll.isEmpty());
Employee empl = ecoll.iterator().next();
@ -85,13 +85,13 @@ public class ActionOverloadingTestITCase extends AbstractTestITCase {
ecoll.operations().increaseSalaries(5);
// the invoke above changed the local entities, re-read
containerFactory.getContext().detachAll();
ecoll = aocontainer.getPerson().getAll(EmployeeCollection.class);
service.getContext().detachAll();
ecoll = aocontainer.getPerson().execute(EmployeeCollection.class);
empl = ecoll.iterator().next();
assertEquals(salary + 5, empl.getSalary(), 0);
SpecialEmployeeCollection secoll = aocontainer.getPerson().getAll(SpecialEmployeeCollection.class);
SpecialEmployeeCollection secoll = aocontainer.getPerson().execute(SpecialEmployeeCollection.class);
assertFalse(secoll.isEmpty());
SpecialEmployee sempl = secoll.toArray(new SpecialEmployee[secoll.size()])[1];
@ -103,8 +103,8 @@ public class ActionOverloadingTestITCase extends AbstractTestITCase {
secoll.operations().increaseSalaries(5);
// the invoke above changed the local entities, re-read
containerFactory.getContext().detachAll();
secoll = aocontainer.getPerson().getAll(SpecialEmployeeCollection.class);
service.getContext().detachAll();
secoll = aocontainer.getPerson().execute(SpecialEmployeeCollection.class);
sempl = secoll.toArray(new SpecialEmployee[secoll.size()])[1];
assertEquals(salary + 5, sempl.getSalary(), 0);

View File

@ -28,13 +28,11 @@ 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.Filter;
import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.Person;
//CHECKSTYLE:OFF (Maven checkstyle)
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;
import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Product;
import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.ProductCollection;
import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.SpecialEmployee;
import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.SpecialEmployeeCollection;
//CHECKSTYLE:ON (Maven checkstyle)
import org.junit.Test;
@ -44,13 +42,12 @@ public class AsyncTestITCase extends AbstractTestITCase {
@Test
public void retrieveEntitySet() throws InterruptedException, ExecutionException {
final Future<ProductCollection> futureProds =
new AsyncCall<ProductCollection>(containerFactory.getClient().getConfiguration()) {
@Override
public ProductCollection call() {
return container.getProduct().getAll();
}
};
new AsyncCall<ProductCollection>(service.getClient().getConfiguration()) {
@Override
public ProductCollection call() {
return container.getProduct().execute();
}
};
assertNotNull(futureProds);
while (!futureProds.isDone()) {
@ -69,11 +66,10 @@ public class AsyncTestITCase extends AbstractTestITCase {
public void updateEntity() throws InterruptedException, ExecutionException {
final String random = UUID.randomUUID().toString();
final Product product = container.getProduct().get(-10);
final Product product = container.getProduct().getByKey(-10);
product.setDescription("AsyncTest#updateEntity " + random);
final Future<Void> futureFlush = new AsyncCall<Void>(containerFactory.getClient().getConfiguration()) {
final Future<Void> futureFlush = new AsyncCall<Void>(service.getClient().getConfiguration()) {
@Override
public Void call() {
container.flush();
@ -86,11 +82,10 @@ public class AsyncTestITCase extends AbstractTestITCase {
Thread.sleep(1000L);
}
final Future<Product> futureProd = new AsyncCall<Product>(containerFactory.getClient().getConfiguration()) {
final Future<Product> futureProd = new AsyncCall<Product>(service.getClient().getConfiguration()) {
@Override
public Product call() {
return container.getProduct().get(-10);
return container.getProduct().getByKey(-10);
}
};
@ -99,28 +94,24 @@ public class AsyncTestITCase extends AbstractTestITCase {
@Test
public void polymorphQuery() throws Exception {
final Future<Filter<Employee, EmployeeCollection>> queryEmployee =
new AsyncCall<Filter<Employee, EmployeeCollection>>(containerFactory.getClient().getConfiguration()) {
final Future<Person> queryEmployee = new AsyncCall<Person>(service.getClient().getConfiguration()) {
@Override
public Person call() {
return container.getPerson();
}
};
assertFalse(queryEmployee.get().execute(EmployeeCollection.class).isEmpty());
@Override
public Filter<Employee, EmployeeCollection> call() {
return container.getPerson().createFilter(EmployeeCollection.class);
}
};
assertFalse(queryEmployee.get().getResult().isEmpty());
final Future<Person> querySpecialEmployee = new AsyncCall<Person>(service.getClient().getConfiguration()) {
@Override
public Person call() {
return container.getPerson();
}
};
assertFalse(querySpecialEmployee.get().execute(SpecialEmployeeCollection.class).isEmpty());
final Future<Filter<SpecialEmployee, SpecialEmployeeCollection>> querySpecialEmployee =
new AsyncCall<Filter<SpecialEmployee, SpecialEmployeeCollection>>(
containerFactory.getClient().getConfiguration()) {
@Override
public Filter<SpecialEmployee, SpecialEmployeeCollection> call() {
return container.getPerson().createFilter(SpecialEmployeeCollection.class);
}
};
assertFalse(querySpecialEmployee.get().getResult().isEmpty());
assertTrue(container.getPerson().getAll().size()
> queryEmployee.get().getResult().size() + querySpecialEmployee.get().getResult().size());
assertTrue(container.getPerson().execute().size()
> container.getPerson().execute(EmployeeCollection.class).size()
+ container.getPerson().execute(SpecialEmployeeCollection.class).size());
}
}

View File

@ -62,23 +62,23 @@ public class ContextTestITCase extends AbstractTestITCase {
final EntityInvocationHandler source2 =
(EntityInvocationHandler) Proxy.getInvocationHandler(customer2);
assertTrue(containerFactory.getContext().entityContext().isAttached(source1));
assertTrue(containerFactory.getContext().entityContext().isAttached(source2));
assertTrue(service.getContext().entityContext().isAttached(source1));
assertTrue(service.getContext().entityContext().isAttached(source2));
containerFactory.getContext().entityContext().detach(source1);
assertFalse(containerFactory.getContext().entityContext().isAttached(source1));
assertTrue(containerFactory.getContext().entityContext().isAttached(source2));
service.getContext().entityContext().detach(source1);
assertFalse(service.getContext().entityContext().isAttached(source1));
assertTrue(service.getContext().entityContext().isAttached(source2));
containerFactory.getContext().entityContext().detach(source2);
assertFalse(containerFactory.getContext().entityContext().isAttached(source1));
assertFalse(containerFactory.getContext().entityContext().isAttached(source2));
service.getContext().entityContext().detach(source2);
assertFalse(service.getContext().entityContext().isAttached(source1));
assertFalse(service.getContext().entityContext().isAttached(source2));
}
@Test
public void attachDetachExistingEntity() {
final Customer customer1 = container.getCustomer().get(-10);
final Customer customer2 = container.getCustomer().get(-9);
final Customer customer3 = container.getCustomer().get(-10);
final Customer customer1 = container.getCustomer().getByKey(-10);
final Customer customer2 = container.getCustomer().getByKey(-9);
final Customer customer3 = container.getCustomer().getByKey(-10);
final EntityInvocationHandler source1 =
(EntityInvocationHandler) Proxy.getInvocationHandler(customer1);
@ -87,42 +87,42 @@ public class ContextTestITCase extends AbstractTestITCase {
final EntityInvocationHandler source3 =
(EntityInvocationHandler) Proxy.getInvocationHandler(customer3);
assertFalse(containerFactory.getContext().entityContext().isAttached(source1));
assertFalse(containerFactory.getContext().entityContext().isAttached(source2));
assertFalse(containerFactory.getContext().entityContext().isAttached(source3));
assertFalse(service.getContext().entityContext().isAttached(source1));
assertFalse(service.getContext().entityContext().isAttached(source2));
assertFalse(service.getContext().entityContext().isAttached(source3));
containerFactory.getContext().entityContext().attach(source1);
assertTrue(containerFactory.getContext().entityContext().isAttached(source1));
assertFalse(containerFactory.getContext().entityContext().isAttached(source2));
assertTrue(containerFactory.getContext().entityContext().isAttached(source3));
service.getContext().entityContext().attach(source1);
assertTrue(service.getContext().entityContext().isAttached(source1));
assertFalse(service.getContext().entityContext().isAttached(source2));
assertTrue(service.getContext().entityContext().isAttached(source3));
containerFactory.getContext().entityContext().attach(source2);
assertTrue(containerFactory.getContext().entityContext().isAttached(source1));
assertTrue(containerFactory.getContext().entityContext().isAttached(source2));
assertTrue(containerFactory.getContext().entityContext().isAttached(source3));
service.getContext().entityContext().attach(source2);
assertTrue(service.getContext().entityContext().isAttached(source1));
assertTrue(service.getContext().entityContext().isAttached(source2));
assertTrue(service.getContext().entityContext().isAttached(source3));
try {
containerFactory.getContext().entityContext().attach(source3);
service.getContext().entityContext().attach(source3);
fail();
} catch (IllegalStateException ignore) {
// ignore
}
containerFactory.getContext().entityContext().detach(source1);
assertFalse(containerFactory.getContext().entityContext().isAttached(source1));
assertTrue(containerFactory.getContext().entityContext().isAttached(source2));
assertFalse(containerFactory.getContext().entityContext().isAttached(source3));
service.getContext().entityContext().detach(source1);
assertFalse(service.getContext().entityContext().isAttached(source1));
assertTrue(service.getContext().entityContext().isAttached(source2));
assertFalse(service.getContext().entityContext().isAttached(source3));
containerFactory.getContext().entityContext().detach(source2);
assertFalse(containerFactory.getContext().entityContext().isAttached(source1));
assertFalse(containerFactory.getContext().entityContext().isAttached(source2));
assertFalse(containerFactory.getContext().entityContext().isAttached(source3));
service.getContext().entityContext().detach(source2);
assertFalse(service.getContext().entityContext().isAttached(source1));
assertFalse(service.getContext().entityContext().isAttached(source2));
assertFalse(service.getContext().entityContext().isAttached(source3));
}
@Test
public void linkTargetExisting() {
final Customer customer = container.getCustomer().newCustomer();
final CustomerInfo customerInfo = container.getCustomerInfo().get(11);
final CustomerInfo customerInfo = container.getCustomerInfo().getByKey(11);
customer.setInfo(customerInfo);
@ -133,22 +133,22 @@ public class ContextTestITCase extends AbstractTestITCase {
final EntityInvocationHandler target =
(EntityInvocationHandler) Proxy.getInvocationHandler(customerInfo);
assertTrue(containerFactory.getContext().entityContext().isAttached(source));
assertEquals(AttachedEntityStatus.NEW, containerFactory.getContext().entityContext().getStatus(source));
assertTrue(containerFactory.getContext().entityContext().isAttached(target));
assertEquals(AttachedEntityStatus.LINKED, containerFactory.getContext().entityContext().getStatus(target));
assertTrue(service.getContext().entityContext().isAttached(source));
assertEquals(AttachedEntityStatus.NEW, service.getContext().entityContext().getStatus(source));
assertTrue(service.getContext().entityContext().isAttached(target));
assertEquals(AttachedEntityStatus.LINKED, service.getContext().entityContext().getStatus(target));
checkUnidirectional("Info", source, "Customer", target, false);
containerFactory.getContext().entityContext().detachAll();
service.getContext().entityContext().detachAll();
assertFalse(containerFactory.getContext().entityContext().isAttached(source));
assertFalse(containerFactory.getContext().entityContext().isAttached(target));
assertFalse(service.getContext().entityContext().isAttached(source));
assertFalse(service.getContext().entityContext().isAttached(target));
}
@Test
public void linkSourceExisting() {
final Customer customer = container.getCustomer().get(-10);
final Customer customer = container.getCustomer().getByKey(-10);
final CustomerInfo customerInfo = container.getCustomerInfo().newCustomerInfo();
@ -161,23 +161,23 @@ public class ContextTestITCase extends AbstractTestITCase {
final EntityInvocationHandler target =
(EntityInvocationHandler) Proxy.getInvocationHandler(customerInfo);
assertTrue(containerFactory.getContext().entityContext().isAttached(source));
assertEquals(AttachedEntityStatus.CHANGED, containerFactory.getContext().entityContext().getStatus(source));
assertTrue(containerFactory.getContext().entityContext().isAttached(target));
assertEquals(AttachedEntityStatus.NEW, containerFactory.getContext().entityContext().getStatus(target));
assertTrue(service.getContext().entityContext().isAttached(source));
assertEquals(AttachedEntityStatus.CHANGED, service.getContext().entityContext().getStatus(source));
assertTrue(service.getContext().entityContext().isAttached(target));
assertEquals(AttachedEntityStatus.NEW, service.getContext().entityContext().getStatus(target));
checkUnidirectional("Info", source, "Customer", target, false);
containerFactory.getContext().entityContext().detachAll();
service.getContext().entityContext().detachAll();
assertFalse(containerFactory.getContext().entityContext().isAttached(source));
assertFalse(containerFactory.getContext().entityContext().isAttached(target));
assertFalse(service.getContext().entityContext().isAttached(source));
assertFalse(service.getContext().entityContext().isAttached(target));
}
@Test
public void linkBothExisting() {
final Customer customer = container.getCustomer().get(-10);
final CustomerInfo customerInfo = container.getCustomerInfo().get(12);
final Customer customer = container.getCustomer().getByKey(-10);
final CustomerInfo customerInfo = container.getCustomerInfo().getByKey(12);
customer.setInfo(customerInfo);
@ -188,17 +188,17 @@ public class ContextTestITCase extends AbstractTestITCase {
final EntityInvocationHandler target =
(EntityInvocationHandler) Proxy.getInvocationHandler(customerInfo);
assertTrue(containerFactory.getContext().entityContext().isAttached(source));
assertEquals(AttachedEntityStatus.CHANGED, containerFactory.getContext().entityContext().getStatus(source));
assertTrue(containerFactory.getContext().entityContext().isAttached(target));
assertEquals(AttachedEntityStatus.LINKED, containerFactory.getContext().entityContext().getStatus(target));
assertTrue(service.getContext().entityContext().isAttached(source));
assertEquals(AttachedEntityStatus.CHANGED, service.getContext().entityContext().getStatus(source));
assertTrue(service.getContext().entityContext().isAttached(target));
assertEquals(AttachedEntityStatus.LINKED, service.getContext().entityContext().getStatus(target));
checkUnidirectional("Info", source, "Customer", target, false);
containerFactory.getContext().entityContext().detachAll();
service.getContext().entityContext().detachAll();
assertFalse(containerFactory.getContext().entityContext().isAttached(source));
assertFalse(containerFactory.getContext().entityContext().isAttached(target));
assertFalse(service.getContext().entityContext().isAttached(source));
assertFalse(service.getContext().entityContext().isAttached(target));
}
@Test
@ -216,24 +216,24 @@ public class ContextTestITCase extends AbstractTestITCase {
final EntityInvocationHandler source = (EntityInvocationHandler) Proxy.getInvocationHandler(customer);
assertTrue(containerFactory.getContext().entityContext().isAttached(source));
assertEquals(AttachedEntityStatus.NEW, containerFactory.getContext().entityContext().getStatus(source));
assertTrue(service.getContext().entityContext().isAttached(source));
assertEquals(AttachedEntityStatus.NEW, service.getContext().entityContext().getStatus(source));
assertEquals(3, ((Collection) (source.getLinkChanges().entrySet().iterator().next().getValue())).size());
for (Order order : toBeLinked) {
final EntityInvocationHandler target = (EntityInvocationHandler) Proxy.getInvocationHandler(order);
assertTrue(containerFactory.getContext().entityContext().isAttached(target));
assertEquals(AttachedEntityStatus.NEW, containerFactory.getContext().entityContext().getStatus(target));
assertTrue(service.getContext().entityContext().isAttached(target));
assertEquals(AttachedEntityStatus.NEW, service.getContext().entityContext().getStatus(target));
checkUnidirectional("Orders", source, "Customer", target, true);
}
containerFactory.getContext().entityContext().detachAll();
service.getContext().entityContext().detachAll();
assertFalse(containerFactory.getContext().entityContext().isAttached(source));
assertFalse(service.getContext().entityContext().isAttached(source));
for (Order order : toBeLinked) {
assertFalse(containerFactory.getContext().entityContext().
assertFalse(service.getContext().entityContext().
isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(order)));
}
}
@ -262,38 +262,38 @@ public class ContextTestITCase extends AbstractTestITCase {
final EntityInvocationHandler source = (EntityInvocationHandler) Proxy.getInvocationHandler(customer);
assertTrue(containerFactory.getContext().entityContext().isAttached(source));
assertEquals(AttachedEntityStatus.NEW, containerFactory.getContext().entityContext().getStatus(source));
assertTrue(service.getContext().entityContext().isAttached(source));
assertEquals(AttachedEntityStatus.NEW, service.getContext().entityContext().getStatus(source));
containerFactory.getContext().entityContext().detachAll();
service.getContext().entityContext().detachAll();
assertFalse(containerFactory.getContext().entityContext().isAttached(source));
assertFalse(service.getContext().entityContext().isAttached(source));
}
@Test
public void readEntityInTheContext() {
CustomerInfo customerInfo = container.getCustomerInfo().get(16).load();
CustomerInfo customerInfo = container.getCustomerInfo().getByKey(16).load();
customerInfo.setInformation("some other info ...");
assertEquals("some other info ...", customerInfo.getInformation());
customerInfo = container.getCustomerInfo().get(16);
customerInfo = container.getCustomerInfo().getByKey(16);
assertEquals("some other info ...", customerInfo.getInformation());
containerFactory.getContext().entityContext().detachAll();
customerInfo = container.getCustomerInfo().get(16);
service.getContext().entityContext().detachAll();
customerInfo = container.getCustomerInfo().getByKey(16);
assertNotEquals("some other info ...", customerInfo.getInformation());
}
@Test
public void readAllWithEntityInTheContext() {
CustomerInfo customerInfo = container.getCustomerInfo().get(16).load();
CustomerInfo customerInfo = container.getCustomerInfo().getByKey(16).load();
customerInfo.setInformation("some other info ...");
assertEquals("some other info ...", customerInfo.getInformation());
boolean found = false;
for (CustomerInfo info : container.getCustomerInfo().getAll()) {
for (CustomerInfo info : container.getCustomerInfo().execute()) {
if (info.getCustomerInfoId() == 16) {
assertEquals("some other info ...", customerInfo.getInformation());
found = true;
@ -301,10 +301,10 @@ public class ContextTestITCase extends AbstractTestITCase {
}
assertTrue(found);
containerFactory.getContext().entityContext().detachAll();
service.getContext().entityContext().detachAll();
found = false;
for (CustomerInfo info : container.getCustomerInfo().getAll()) {
for (CustomerInfo info : container.getCustomerInfo().execute()) {
if (info.getCustomerInfoId() == 16) {
assertNotEquals("some other info ...", info.getInformation());
found = true;
@ -319,7 +319,7 @@ public class ContextTestITCase extends AbstractTestITCase {
final EntityInvocationHandler handler = (EntityInvocationHandler) Proxy.getInvocationHandler(login);
assertTrue(containerFactory.getContext().entityContext().isAttached(handler));
assertTrue(service.getContext().entityContext().isAttached(handler));
try {
container.flush();
@ -328,23 +328,23 @@ public class ContextTestITCase extends AbstractTestITCase {
// ignore
}
assertTrue(containerFactory.getContext().entityContext().isAttached(handler));
assertTrue(service.getContext().entityContext().isAttached(handler));
login.setCustomerId(-10);
login.setUsername("customer");
container.flush();
assertFalse(containerFactory.getContext().entityContext().isAttached(handler));
assertNotNull(container.getLogin().get("customer"));
assertFalse(service.getContext().entityContext().isAttached(handler));
assertNotNull(container.getLogin().getByKey("customer"));
container.getLogin().delete(login.getUsername());
assertTrue(containerFactory.getContext().entityContext().isAttached(handler));
assertTrue(service.getContext().entityContext().isAttached(handler));
container.flush();
assertFalse(containerFactory.getContext().entityContext().isAttached(handler));
assertFalse(service.getContext().entityContext().isAttached(handler));
try {
container.getLogin().get("customer").load();
container.getLogin().getByKey("customer").load();
fail();
} catch (IllegalArgumentException e) {
}
@ -372,7 +372,7 @@ public class ContextTestITCase extends AbstractTestITCase {
customer.setOrders(toBeLinked);
final CustomerInfo customerInfo = container.getCustomerInfo().get(16);
final CustomerInfo customerInfo = container.getCustomerInfo().getByKey(16);
customerInfo.setInformation("some new info ...");
customer.setInfo(customerInfo);
@ -389,44 +389,44 @@ public class ContextTestITCase extends AbstractTestITCase {
customer.setPrimaryContactInfo(cd);
customer.setBackupContactInfo(Collections.<ContactDetails>singletonList(bcd));
assertTrue(containerFactory.getContext().entityContext().
assertTrue(service.getContext().entityContext().
isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customerInfo)));
assertTrue(containerFactory.getContext().entityContext().
assertTrue(service.getContext().entityContext().
isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customer)));
for (Order linked : toBeLinked) {
assertTrue(containerFactory.getContext().entityContext().
assertTrue(service.getContext().entityContext().
isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(linked)));
}
container.flush();
assertFalse(containerFactory.getContext().entityContext().
assertFalse(service.getContext().entityContext().
isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customerInfo)));
assertFalse(containerFactory.getContext().entityContext().
assertFalse(service.getContext().entityContext().
isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customer)));
for (Order linked : toBeLinked) {
assertFalse(containerFactory.getContext().entityContext().
assertFalse(service.getContext().entityContext().
isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(linked)));
}
assertEquals("some new info ...", container.getCustomerInfo().get(16).load().getInformation());
assertEquals("some new info ...", container.getCustomerInfo().getByKey(16).load().getInformation());
container.getOrder().delete(toBeLinked);
container.getCustomer().delete(customer.getCustomerId());
assertTrue(containerFactory.getContext().entityContext().
assertTrue(service.getContext().entityContext().
isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customer)));
for (Order linked : toBeLinked) {
assertTrue(containerFactory.getContext().entityContext().
assertTrue(service.getContext().entityContext().
isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(linked)));
}
container.flush();
assertFalse(containerFactory.getContext().entityContext().
assertFalse(service.getContext().entityContext().
isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customer)));
for (Order linked : toBeLinked) {
assertFalse(containerFactory.getContext().entityContext().
assertFalse(service.getContext().entityContext().
isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(linked)));
}
}

View File

@ -42,7 +42,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
@Test
public void create() {
container.getCustomer().get(-10);
container.getCustomer().getByKey(-10);
final String sampleName = "sample customer from proxy";
final Integer id = 100;
@ -53,25 +53,25 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
checkSampleCustomerProfile(actual, id, sampleName);
container.getCustomer().delete(actual.getCustomerId());
actual = container.getCustomer().get(id);
actual = container.getCustomer().getByKey(id);
assertNull(actual);
containerFactory.getContext().detachAll();
actual = container.getCustomer().get(id).load();
service.getContext().detachAll();
actual = container.getCustomer().getByKey(id).load();
container.getCustomer().delete(actual.getCustomerId());
container.flush();
try {
container.getCustomer().get(id).load();
container.getCustomer().getByKey(id).load();
fail();
} catch (IllegalArgumentException e) {
}
containerFactory.getContext().detachAll();
service.getContext().detachAll();
try {
container.getCustomer().get(id).load();
container.getCustomer().getByKey(id).load();
fail();
} catch (IllegalArgumentException e) {
}
@ -90,27 +90,27 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
container.flush();
Employee actual = container.getPerson().get(id, Employee.class).load();
Employee actual = container.getPerson().getByKey(id, Employee.class).load();
assertNotNull(actual);
assertEquals(id, actual.getPersonId());
containerFactory.getContext().detachAll();
actual = container.getPerson().get(id, Employee.class).load();
service.getContext().detachAll();
actual = container.getPerson().getByKey(id, Employee.class).load();
assertNotNull(actual);
container.getPerson().delete(actual.getPersonId());
container.flush();
try {
container.getPerson().get(id, Employee.class).load();
container.getPerson().getByKey(id, Employee.class).load();
fail();
} catch (IllegalArgumentException e) {
}
containerFactory.getContext().detachAll();
service.getContext().detachAll();
try {
container.getPerson().get(id, Employee.class).load();
container.getPerson().getByKey(id, Employee.class).load();
fail();
} catch (IllegalArgumentException e) {
}
@ -122,7 +122,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
final Integer id = 101;
final Customer original = getSampleCustomerProfile(id, sampleName, container);
original.setInfo(container.getCustomerInfo().get(16));
original.setInfo(container.getCustomerInfo().getByKey(16));
container.flush();
Customer actual = readCustomer(container, id);
@ -133,7 +133,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
container.flush();
try {
container.getCustomer().get(id).load();
container.getCustomer().getByKey(id).load();
fail();
} catch (IllegalArgumentException e) {
}
@ -167,7 +167,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
assertEquals(id, actual.getOrders().iterator().next().getOrderId());
assertEquals(id, actual.getOrders().iterator().next().getCustomerId());
order = container.getOrder().get(id);
order = container.getOrder().getByKey(id);
assertNotNull(order);
assertEquals(id, order.getCustomer().getCustomerId());
@ -175,7 +175,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
container.flush();
try {
container.getOrder().get(id).load();
container.getOrder().getByKey(id).load();
fail();
} catch (IllegalArgumentException e) {
}
@ -187,7 +187,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
container.flush();
try {
container.getCustomer().get(id).load();
container.getCustomer().getByKey(id).load();
fail();
} catch (IllegalArgumentException e) {
}
@ -209,7 +209,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
key.setFromUsername("fromusername");
key.setMessageId(100);
message = container.getMessage().get(key).load();
message = container.getMessage().getByKey(key).load();
assertNotNull(message);
assertEquals(Integer.valueOf(100), message.getMessageId());
assertEquals("fromusername", message.getFromUsername());
@ -221,7 +221,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
container.flush();
try {
container.getMessage().get(key).load();
container.getMessage().getByKey(key).load();
fail();
} catch (IllegalArgumentException e) {
}

View File

@ -82,14 +82,14 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
@Test
public void getAll() {
final PersonCollection all = getContainer().getPerson().getAll();
final PersonCollection all = getContainer().getPerson().execute();
assertNotNull(all);
assertFalse(all.isEmpty());
for (Person person : all) {
assertNotNull(person);
}
final EmployeeCollection employees = getContainer().getPerson().getAll(EmployeeCollection.class);
final EmployeeCollection employees = getContainer().getPerson().execute(EmployeeCollection.class);
assertNotNull(employees);
assertFalse(employees.isEmpty());
for (Employee employee : employees) {
@ -97,14 +97,14 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
}
final SpecialEmployeeCollection specialEmployees =
getContainer().getPerson().getAll(SpecialEmployeeCollection.class);
getContainer().getPerson().execute(SpecialEmployeeCollection.class);
assertNotNull(specialEmployees);
assertFalse(specialEmployees.isEmpty());
for (SpecialEmployee employee : specialEmployees) {
assertNotNull(employee);
}
final ContractorCollection contractors = getContainer().getPerson().getAll(ContractorCollection.class);
final ContractorCollection contractors = getContainer().getPerson().execute(ContractorCollection.class);
assertNotNull(contractors);
assertFalse(contractors.isEmpty());
for (Contractor contractor : contractors) {
@ -117,7 +117,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
@Test
public void navigate() {
final Order order = getContainer().getOrder().get(-9).load();
final Order order = getContainer().getOrder().getByKey(-9).load();
assertEquals(-9, order.getOrderId(), 0);
final ConcurrencyInfo concurrency = order.getConcurrency();
@ -132,7 +132,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
@Test
public void withGeospatial() {
final AllSpatialTypes allSpatialTypes = getContainer().getAllGeoTypesSet().get(-10).load();
final AllSpatialTypes allSpatialTypes = getContainer().getAllGeoTypesSet().getByKey(-10).load();
assertNotNull(allSpatialTypes);
assertEquals(-10, allSpatialTypes.getId(), 0);
@ -167,7 +167,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
@Test
public void withActions() {
final ComputerDetail computerDetail = getContainer().getComputerDetail().get(-10).load();
final ComputerDetail computerDetail = getContainer().getComputerDetail().getByKey(-10).load();
assertEquals(-10, computerDetail.getComputerDetailId(), 0);
try {
@ -184,13 +184,13 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
messageKey.setFromUsername("1");
messageKey.setMessageId(-10);
final Message message = getContainer().getMessage().get(messageKey).load();
final Message message = getContainer().getMessage().getByKey(messageKey).load();
assertEquals("1", message.getFromUsername());
}
@Test
public void checkForETag() {
Product product = getContainer().getProduct().get(-10).load();
Product product = getContainer().getProduct().getByKey(-10).load();
assertTrue(StringUtils.isNotBlank(
((EntityInvocationHandler) Proxy.getInvocationHandler(product)).getETag()));
}

View File

@ -46,7 +46,7 @@ public class EntitySetTestITCase extends AbstractTestITCase {
@Test
public void getAll() {
int count = 0;
for (Customer customer : container.getCustomer().getAll()) {
for (Customer customer : container.getCustomer().execute()) {
assertNotNull(customer);
count++;
}
@ -56,7 +56,7 @@ public class EntitySetTestITCase extends AbstractTestITCase {
@Test
public void readEntitySetWithNextLink() {
int count = 0;
for (Customer customer : container.getCustomer().getAll()) {
for (Customer customer : container.getCustomer().execute()) {
assertNotNull(customer);
count++;
}
@ -74,7 +74,7 @@ public class EntitySetTestITCase extends AbstractTestITCase {
public void readODataEntitySet() throws IOException {
assertTrue(container.getCar().count() >= 10);
final Iterable<Car> car = container.getCar().getAll();
final Iterable<Car> car = container.getCar().execute();
assertNotNull(car);
final Iterator<Car> itor = car.iterator();

View File

@ -43,14 +43,14 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
@Test
public void update() {
Order order = container.getOrder().get(-9).load();
Order order = container.getOrder().getByKey(-9).load();
final ConcurrencyInfo ci = order.getConcurrency();
ci.setToken("XXX");
container.flush();
order = container.getOrder().get(-9).load();
order = container.getOrder().getByKey(-9).load();
assertEquals("XXX", order.getConcurrency().getToken());
}
@ -60,13 +60,13 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
key.setFromUsername("1");
key.setMessageId(-10);
Message message = container.getMessage().get(key);
Message message = container.getMessage().getByKey(key);
message.setBody("XXX");
container.flush();
message = container.getMessage().get(key).load();
message = container.getMessage().getByKey(key).load();
assertEquals("XXX", message.getBody());
}
@ -79,17 +79,17 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
OrderCollection orders = container.getOrder().newOrderCollection();
orders.add(order);
Customer customer = container.getCustomer().get(-9);
Customer customer = container.getCustomer().getByKey(-9);
customer.setOrders(orders);
order.setCustomer(customer);
container.flush();
order = container.getOrder().get(400).load();
order = container.getOrder().getByKey(400).load();
assertEquals(400, order.getOrderId().intValue());
assertEquals(-9, order.getCustomerId().intValue());
customer = container.getCustomer().get(-9);
customer = container.getCustomer().getByKey(-9);
assertEquals(2, customer.getOrders().size());
@ -105,7 +105,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
@Test
public void concurrentModification() {
Product product = container.getProduct().get(-10).load();
Product product = container.getProduct().getByKey(-10).load();
final String etag = ((EntityInvocationHandler) Proxy.getInvocationHandler(product)).getETag();
assertTrue(StringUtils.isNotBlank(etag));
@ -114,7 +114,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
container.flush();
product = container.getProduct().get(-10).load();
product = container.getProduct().getByKey(-10).load();
assertEquals(baseConcurrency, product.getBaseConcurrency());
}
}

View File

@ -20,23 +20,21 @@ package org.apache.olingo.fit.proxy.v3;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.olingo.ext.proxy.api.Filter;
import org.apache.olingo.ext.proxy.api.NonUniqueResultException;
import org.apache.olingo.ext.proxy.api.Sort;
import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.Person;
//CHECKSTYLE:OFF (Maven checkstyle)
import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Car;
import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.CarCollection;
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.Customer;
import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.EmployeeCollection;
import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.SpecialEmployee;
import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Order;
import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.SpecialEmployeeCollection;
//CHECKSTYLE:ON (Maven checkstyle)
import org.junit.Test;
@ -45,10 +43,10 @@ public class FilterTestITCase extends AbstractTestITCase {
@Test
public void filterOrderby() {
final Filter<Car, CarCollection> filter = container.getCar().createFilter().
setFilter(containerFactory.getClient().getFilterFactory().lt("VIN", 16));
CarCollection result = filter.getResult();
assertNotNull(result);
org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.Car cars =
container.getCar();
CarCollection result = cars.filter(service.getClient().getFilterFactory().lt("VIN", 16)).execute();
// 1. check that filtered entity set looks as expected
assertEquals(5, result.size());
@ -61,7 +59,7 @@ public class FilterTestITCase extends AbstractTestITCase {
}
// 3. add orderby clause to filter above
result = filter.setOrderBy(new Sort("VIN", Sort.Direction.DESC)).getResult();
result = cars.orderBy(new Sort("VIN", Sort.Direction.DESC)).execute();
assertNotNull(result);
assertEquals(5, result.size());
@ -79,34 +77,49 @@ public class FilterTestITCase extends AbstractTestITCase {
@Test
public void single() {
final Filter<Car, CarCollection> filter = container.getCar().createFilter().
setFilter(containerFactory.getClient().getFilterFactory().lt("VIN", 16));
org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.Car cars =
container.getCar();
Exception exception = null;
try {
filter.getSingleResult();
fail();
} catch (NonUniqueResultException e) {
exception = e;
}
assertNotNull(exception);
filter.setFilter(containerFactory.getClient().getFilterFactory().eq("VIN", 16));
final Car result = filter.getSingleResult();
assertNotNull(result);
assertEquals(1, cars.filter(service.getClient().getFilterFactory().eq("VIN", 16)).execute().size());
}
@Test
public void derived() {
final Filter<Employee, EmployeeCollection> filterEmployee =
container.getPerson().createFilter(EmployeeCollection.class);
assertFalse(filterEmployee.getResult().isEmpty());
final Person person = container.getPerson();
final EmployeeCollection employee = person.execute(EmployeeCollection.class);
final SpecialEmployeeCollection specialEmployee = person.execute(SpecialEmployeeCollection.class);
final Filter<SpecialEmployee, SpecialEmployeeCollection> filterSpecialEmployee =
container.getPerson().createFilter(SpecialEmployeeCollection.class);
assertFalse(filterSpecialEmployee.getResult().isEmpty());
assertFalse(employee.isEmpty());
assertFalse(specialEmployee.isEmpty());
assertTrue(container.getPerson().getAll().size()
> filterEmployee.getResult().size() + filterSpecialEmployee.getResult().size());
assertTrue(person.execute().size() > employee.size() + specialEmployee.size());
}
@Test
public void loadWithSelect() {
final Order order = container.getOrder().getByKey(-9);
assertNull(order.getCustomerId());
assertNull(order.getOrderId());
order.select("OrderId");
order.load();
assertNull(order.getCustomerId());
assertNotNull(order.getOrderId());
order.clear();
order.load();
assertNotNull(order.getCustomerId());
assertNotNull(order.getOrderId());
}
@Test
public void loadWithSelectAndExpand() {
final Customer customer = container.getCustomer().getByKey(-10);
customer.expand("Info");
customer.select("Info", "CustomerId");
customer.load();
assertEquals(11, customer.getInfo().getCustomerInfoId(), 0);
}
}

View File

@ -96,7 +96,7 @@ public class InvokeTestITCase extends AbstractTestITCase {
container.flush();
employee = container.getPerson().get(id, Employee.class).load();
employee = container.getPerson().getByKey(id, Employee.class).load();
assertNotNull(employee);
assertEquals(id, employee.getPersonId());
@ -105,7 +105,7 @@ public class InvokeTestITCase extends AbstractTestITCase {
employee.operations().sack();
// 2. check that invoked action has effectively run
employee = container.getPerson().get(id, Employee.class).load();
employee = container.getPerson().getByKey(id, Employee.class).load();
assertEquals(0, employee.getSalary(), 0);
assertTrue(employee.getTitle().endsWith("[Sacked]"));
} catch (Exception e) {
@ -119,7 +119,7 @@ public class InvokeTestITCase extends AbstractTestITCase {
@Test
public void entityCollectionBoundPostWithParam() {
EmployeeCollection employees = container.getPerson().getAll(EmployeeCollection.class);
EmployeeCollection employees = container.getPerson().execute(EmployeeCollection.class);
assertFalse(employees.isEmpty());
final Map<Integer, Integer> preSalaries = new HashMap<Integer, Integer>(employees.size());
for (Employee employee : employees) {
@ -129,7 +129,7 @@ public class InvokeTestITCase extends AbstractTestITCase {
employees.operations().increaseSalaries(1);
employees = container.getPerson().getAll(EmployeeCollection.class);
employees = container.getPerson().execute(EmployeeCollection.class);
assertFalse(employees.isEmpty());
for (Employee employee : employees) {
assertTrue(preSalaries.get(employee.getPersonId()) < employee.getSalary());
@ -153,7 +153,7 @@ public class InvokeTestITCase extends AbstractTestITCase {
container.flush();
product = container.getProduct().get(id).load();
product = container.getProduct().getByKey(id).load();
assertNotNull(product);
assertEquals(id, product.getProductId());
assertEquals(BigDecimal.ZERO, product.getDimensions().getDepth());
@ -170,7 +170,7 @@ public class InvokeTestITCase extends AbstractTestITCase {
product.operations().changeProductDimensions(newDimensions);
// 2. check that invoked action has effectively run
product = container.getProduct().get(id).load();
product = container.getProduct().getByKey(id).load();
assertEquals(BigDecimal.ONE, product.getDimensions().getDepth());
assertEquals(BigDecimal.ONE, product.getDimensions().getHeight());
assertEquals(BigDecimal.ONE, product.getDimensions().getWidth());
@ -201,7 +201,7 @@ public class InvokeTestITCase extends AbstractTestITCase {
container.flush();
computerDetail = container.getComputerDetail().get(id).load();
computerDetail = container.getComputerDetail().getByKey(id).load();
assertNotNull(computerDetail);
assertEquals(id, computerDetail.getComputerDetailId());
assertEquals(1, computerDetail.getSpecificationsBag().size());
@ -214,7 +214,7 @@ public class InvokeTestITCase extends AbstractTestITCase {
Collections.singleton("Second spec"), new Timestamp(Calendar.getInstance().getTimeInMillis()));
// 2. check that invoked action has effectively run
computerDetail = container.getComputerDetail().get(id).load();
computerDetail = container.getComputerDetail().getByKey(id).load();
assertNotNull(computerDetail);
assertEquals(id, computerDetail.getComputerDetailId());
assertEquals(1, computerDetail.getSpecificationsBag().size());

View File

@ -38,7 +38,7 @@ public class MediaEntityTestITCase extends AbstractTestITCase {
@Test
public void read() throws IOException {
final InputStream is = container.getCar().get(12).load().getStream();
final InputStream is = container.getCar().getByKey(12).load().getStream();
assertNotNull(is);
IOUtils.closeQuietly(is);
}
@ -48,12 +48,12 @@ public class MediaEntityTestITCase extends AbstractTestITCase {
final String TO_BE_UPDATED = "buffered stream sample (" + System.currentTimeMillis() + ")";
final InputStream input = new ByteArrayInputStream(TO_BE_UPDATED.getBytes());
Car car = container.getCar().get(12).load();
Car car = container.getCar().getByKey(12).load();
car.setPhoto(input);
container.flush();
car = container.getCar().get(12).load();
car = container.getCar().getByKey(12).load();
final InputStream is = car.getPhoto();
assertEquals(TO_BE_UPDATED, IOUtils.toString(is));
IOUtils.closeQuietly(is);
@ -61,7 +61,7 @@ public class MediaEntityTestITCase extends AbstractTestITCase {
@Test
public void update() throws IOException {
final Car car = container.getCar().get(14);
final Car car = container.getCar().getByKey(14);
assertNotNull(car);
final String TO_BE_UPDATED = "buffered stream sample (" + System.currentTimeMillis() + ")";
@ -71,7 +71,7 @@ public class MediaEntityTestITCase extends AbstractTestITCase {
container.flush();
input = container.getCar().get(14).load().getStream();
input = container.getCar().getByKey(14).load().getStream();
assertEquals(TO_BE_UPDATED, IOUtils.toString(input));
IOUtils.closeQuietly(input);
}
@ -92,9 +92,9 @@ public class MediaEntityTestITCase extends AbstractTestITCase {
int key = car.getVIN();
assertTrue(key > 0);
containerFactory.getContext().detachAll();
service.getContext().detachAll();
car = container.getCar().get(key).load();
car = container.getCar().getByKey(key).load();
assertEquals(DESC, car.getDescription());
input = car.getStream();
assertEquals(TO_BE_UPDATED, IOUtils.toString(input));
@ -104,7 +104,7 @@ public class MediaEntityTestITCase extends AbstractTestITCase {
container.flush();
try {
container.getCar().get(key).load();
container.getCar().getByKey(key).load();
fail();
} catch (IllegalArgumentException e) {
}

View File

@ -31,7 +31,7 @@ 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.Service;
import org.apache.olingo.ext.proxy.api.annotations.EntityType;
import org.apache.olingo.fit.proxy.v3.opentype.microsoft.test.odata.services.opentypesservicev3.DefaultContainer;
import org.apache.olingo.fit.proxy.v3.opentype.microsoft.test.odata.services.opentypesservicev3.types.ContactDetails;
@ -45,13 +45,13 @@ import org.junit.Test;
*/
public class OpenTypeTestITCase extends AbstractTestITCase {
private static EntityContainerFactory<EdmEnabledODataClient> otcontainerFactory;
private static Service<EdmEnabledODataClient> otcontainerFactory;
private static DefaultContainer otcontainer;
@BeforeClass
public static void initContainer() {
otcontainerFactory = EntityContainerFactory.getV3(testOpenTypeServiceRootURL);
otcontainerFactory = Service.getV3(testOpenTypeServiceRootURL);
otcontainerFactory.getClient().getConfiguration().
setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
otcontainer = otcontainerFactory.getEntityContainer(DefaultContainer.class);
@ -71,11 +71,11 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
@Test
public void read() {
Row row = otcontainer.getRow().get(UUID.fromString("71f7d0dc-ede4-45eb-b421-555a2aa1e58f")).load();
Row row = otcontainer.getRow().getByKey(UUID.fromString("71f7d0dc-ede4-45eb-b421-555a2aa1e58f")).load();
assertEquals(Double.class, row.getAdditionalProperty("Double").getClass());
assertEquals("71f7d0dc-ede4-45eb-b421-555a2aa1e58f", row.getId().toString());
row = otcontainer.getRow().get(UUID.fromString("672b8250-1e6e-4785-80cf-b94b572e42b3")).load();
row = otcontainer.getRow().getByKey(UUID.fromString("672b8250-1e6e-4785-80cf-b94b572e42b3")).load();
assertEquals(BigDecimal.class, row.getAdditionalProperty("Decimal").getClass());
}
@ -117,7 +117,7 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
otcontainer.flush();
rowIndex = otcontainer.getRowIndex().get(id).load();
rowIndex = otcontainer.getRowIndex().getByKey(id).load();
assertEquals(String.class, rowIndex.getAdditionalProperty("aString").getClass());
assertEquals(Boolean.class, rowIndex.getAdditionalProperty("aBoolean").getClass());
assertEquals(Double.class, rowIndex.getAdditionalProperty("aDouble").getClass());
@ -132,7 +132,7 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
otcontainer.flush();
try {
otcontainer.getRowIndex().get(id).load();
otcontainer.getRowIndex().getByKey(id).load();
} catch (IllegalArgumentException e) {
}
}

View File

@ -26,7 +26,7 @@ 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.Service;
import org.apache.olingo.fit.proxy.v3.primitivekeys.microsoft.test.odata.services.primitivekeysservice.TestContext;
import org.apache.olingo.fit.proxy.v3.primitivekeys.microsoft.test.odata.services.primitivekeysservice.types.EdmBoolean;
import org.apache.olingo.fit.proxy.v3.primitivekeys.microsoft.test.odata.services.primitivekeysservice.types.EdmByte;
@ -47,43 +47,43 @@ public class PrimitiveKeysTestITCase extends AbstractTestITCase {
@Test
public void readPrimitiveKeys() {
final EntityContainerFactory<EdmEnabledODataClient> testContainerFactory =
EntityContainerFactory.getV3(testPrimitiveKeysServiceRootURL);
final Service<EdmEnabledODataClient> testContainerFactory =
Service.getV3(testPrimitiveKeysServiceRootURL);
testContainerFactory.getClient().getConfiguration().
setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
final TestContext testContainer = testContainerFactory.getEntityContainer(TestContext.class);
assertNotNull(testContainer);
final EdmBoolean edmBooleanSet = testContainer.getEdmBooleanSet().get(Boolean.TRUE).load();
final EdmBoolean edmBooleanSet = testContainer.getEdmBooleanSet().getByKey(Boolean.TRUE).load();
assertEquals(Boolean.TRUE, edmBooleanSet.getId());
final EdmByte edmByteSet = testContainer.getEdmByteSet().get(Short.valueOf("255")).load();
final EdmByte edmByteSet = testContainer.getEdmByteSet().getByKey(Short.valueOf("255")).load();
assertEquals(Short.valueOf("255"), edmByteSet.getId());
final EdmDecimal edmDecimalSet =
testContainer.getEdmDecimalSet().get(new BigDecimal("79228162514264337593543950335")).load();
testContainer.getEdmDecimalSet().getByKey(new BigDecimal("79228162514264337593543950335")).load();
assertEquals(new BigDecimal("79228162514264337593543950335"), edmDecimalSet.getId());
final EdmDouble edmDoubleSet = testContainer.getEdmDoubleSet().get(1.7976931348623157E+308D).load();
final EdmDouble edmDoubleSet = testContainer.getEdmDoubleSet().getByKey(1.7976931348623157E+308D).load();
assertEquals(1.7976931348623157E+308D, edmDoubleSet.getId(), 0);
final EdmSingle edmSingleSet = testContainer.getEdmSingleSet().get(3.4028235E+38F).load();
final EdmSingle edmSingleSet = testContainer.getEdmSingleSet().getByKey(3.4028235E+38F).load();
assertEquals(3.4028235E+38F, edmSingleSet.getId(), 0);
final EdmGuid edmGuidSet =
testContainer.getEdmGuidSet().get(UUID.fromString("00000000-0000-0000-0000-000000000000")).load();
testContainer.getEdmGuidSet().getByKey(UUID.fromString("00000000-0000-0000-0000-000000000000")).load();
assertEquals(UUID.fromString("00000000-0000-0000-0000-000000000000"), edmGuidSet.getId());
final EdmInt16 edmInt16Set = testContainer.getEdmInt16Set().get(Short.valueOf("32767")).load();
final EdmInt16 edmInt16Set = testContainer.getEdmInt16Set().getByKey(Short.valueOf("32767")).load();
assertEquals(Short.valueOf("32767"), edmInt16Set.getId(), 0);
final EdmInt32 edmInt32Set = testContainer.getEdmInt32Set().get(-2147483648).load();
final EdmInt32 edmInt32Set = testContainer.getEdmInt32Set().getByKey(-2147483648).load();
assertEquals(-2147483648, edmInt32Set.getId(), 0);
final EdmInt64 edmInt64Set = testContainer.getEdmInt64Set().get(9223372036854775807L).load();
final EdmInt64 edmInt64Set = testContainer.getEdmInt64Set().getByKey(9223372036854775807L).load();
assertEquals(9223372036854775807L, edmInt64Set.getId(), 0);
final EdmString edmStringSet = testContainer.getEdmStringSet().get("$").load();
final EdmString edmStringSet = testContainer.getEdmStringSet().getByKey("$").load();
assertEquals("$", edmStringSet.getId());
}
}

View File

@ -32,16 +32,16 @@ public class PropertyTestITCase extends AbstractTestITCase {
@Test
public void nullNullableProperty() {
Order order = container.getOrder().get(-8);
Order order = container.getOrder().getByKey(-8);
order.setCustomerId(null);
container.flush();
assertNull(container.getOrder().get(-8).getCustomerId());
assertNull(container.getOrder().getByKey(-8).getCustomerId());
}
@Test
public void nullNonNullableProperty() {
Driver driver = container.getDriver().get("2");
Driver driver = container.getDriver().getByKey("2");
driver.setBirthDate(null);
try {
@ -49,7 +49,7 @@ public class PropertyTestITCase extends AbstractTestITCase {
fail();
} catch (IllegalStateException e) {
// ignore and detach all
containerFactory.getContext().detachAll();
service.getContext().detachAll();
}
}
}

View File

@ -32,7 +32,7 @@ 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.Service;
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.Customer;
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Order;
@ -63,7 +63,7 @@ public abstract class AbstractTestITCase {
protected static String testAuthServiceRootURL;
protected static EntityContainerFactory<EdmEnabledODataClient> containerFactory;
protected static Service<EdmEnabledODataClient> containerFactory;
protected static InMemoryEntities container;
@ -77,7 +77,7 @@ public abstract class AbstractTestITCase {
testLargeModelServiceRootURL = "http://localhost:9080/stub/StaticService/V40/Static.svc/large";
testAuthServiceRootURL = "http://localhost:9080/stub/DefaultService.svc/V40/Static.svc";
containerFactory = EntityContainerFactory.getV4(testStaticServiceRootURL);
containerFactory = Service.getV4(testStaticServiceRootURL);
containerFactory.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
container = containerFactory.getEntityContainer(InMemoryEntities.class);
assertNotNull(container);
@ -85,7 +85,7 @@ public abstract class AbstractTestITCase {
}
protected Customer readCustomer(final InMemoryEntities container, final int id) {
final Customer customer = container.getCustomers().get(id).load();
final Customer customer = container.getCustomers().getByKey(id).load();
assertNotNull(customer);
assertEquals(id, customer.getPersonID(), 0);
@ -93,7 +93,7 @@ public abstract class AbstractTestITCase {
}
protected void createPatchAndDeleteOrder(
final InMemoryEntities container, final EntityContainerFactory<EdmEnabledODataClient> containerFactory) {
final InMemoryEntities container, final Service<EdmEnabledODataClient> containerFactory) {
// Create order ....
final Order order = container.getOrders().newOrder();
@ -113,7 +113,7 @@ public abstract class AbstractTestITCase {
order.setShelfLife(BigDecimal.TEN);
container.flush();
Order actual = container.getOrders().get(105).load();
Order actual = container.getOrders().getByKey(105).load();
assertEquals(105, actual.getOrderID(), 0);
assertEquals(orderDate.getTimeInMillis(), actual.getOrderDate().getTime());
assertEquals(BigDecimal.TEN, actual.getShelfLife());
@ -121,22 +121,22 @@ public abstract class AbstractTestITCase {
// Delete order ...
container.getOrders().delete(105);
actual = container.getOrders().get(105);
actual = container.getOrders().getByKey(105);
assertNull(actual);
containerFactory.getContext().detachAll();
actual = container.getOrders().get(105);
actual = container.getOrders().getByKey(105);
assertNotNull(actual);
container.getOrders().delete(105);
actual = container.getOrders().get(105);
actual = container.getOrders().getByKey(105);
assertNull(actual);
container.flush();
containerFactory.getContext().detachAll();
try {
container.getOrders().get(105).load();
container.getOrders().getByKey(105).load();
fail();
} catch (IllegalArgumentException e) {
}

View File

@ -43,7 +43,7 @@ public class AsyncTestITCase extends AbstractTestITCase {
@Override
public CustomerCollection call() {
return container.getCustomers().getAll();
return container.getCustomers().execute();
}
};
assertNotNull(futureCustomers);
@ -64,7 +64,7 @@ public class AsyncTestITCase extends AbstractTestITCase {
public void updateEntity() throws InterruptedException {
final String randomFirstName = RandomStringUtils.random(10, "abcedfghijklmnopqrstuvwxyz");
Person person = container.getPeople().get(1);
Person person = container.getPeople().getByKey(1);
person.setFirstName(randomFirstName);
final Future<Void> futureFlush = new AsyncCall<Void>(containerFactory.getClient().getConfiguration()) {
@ -85,7 +85,7 @@ public class AsyncTestITCase extends AbstractTestITCase {
@Override
public Person call() {
return container.getPeople().get(1);
return container.getPeople().getByKey(1);
}
};

View File

@ -21,19 +21,19 @@ package org.apache.olingo.fit.proxy.v4;
import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.ext.proxy.EntityContainerFactory;
import org.apache.olingo.ext.proxy.Service;
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities;
public class AuthEntityCreateTestITCase extends EntityCreateTestITCase {
private EntityContainerFactory<EdmEnabledODataClient> ecf;
private Service<EdmEnabledODataClient> ecf;
private InMemoryEntities ime;
@Override
protected EntityContainerFactory<EdmEnabledODataClient> getContainerFactory() {
protected Service<EdmEnabledODataClient> getContainerFactory() {
if (ecf == null) {
ecf = EntityContainerFactory.getV4(testAuthServiceRootURL);
ecf = Service.getV4(testAuthServiceRootURL);
ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
ecf.getClient().getConfiguration().
setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient"));

View File

@ -21,14 +21,14 @@ package org.apache.olingo.fit.proxy.v4;
import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.ext.proxy.EntityContainerFactory;
import org.apache.olingo.ext.proxy.Service;
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities;
public class AuthEntityRetrieveTestITCase extends EntityRetrieveTestITCase {
@Override
protected InMemoryEntities getContainer() {
final EntityContainerFactory<EdmEnabledODataClient> ecf = EntityContainerFactory.getV4(testAuthServiceRootURL);
final Service<EdmEnabledODataClient> ecf = Service.getV4(testAuthServiceRootURL);
ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
ecf.getClient().getConfiguration().
setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient"));

View File

@ -42,12 +42,12 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
@Test
public void getEmployeesCount() {
assertNotNull(container.getCompany().get().operations().getEmployeesCount());
assertNotNull(container.getCompany().load().operations().getEmployeesCount());
}
@Test
public void getProductDetails() {
final ProductDetailCollection result = container.getProducts().get(5).operations().getProductDetails(1);
final ProductDetailCollection result = container.getProducts().getByKey(5).operations().getProductDetails(1);
assertEquals(1, result.size());
}
@ -57,57 +57,58 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
key.setProductID(6);
key.setProductDetailID(1);
final Product product = container.getProductDetails().get(key).operations().getRelatedProduct();
final Product product = container.getProductDetails().getByKey(key).operations().getRelatedProduct();
assertEquals(6, product.getProductID(), 0);
}
@Test
public void getDefaultPI() {
final PaymentInstrument pi = container.getAccounts().get(101).operations().getDefaultPI();
final PaymentInstrument pi = container.getAccounts().getByKey(101).operations().getDefaultPI();
assertEquals(101901, pi.getPaymentInstrumentID(), 0);
}
@Test
public void getAccountInfo() {
final AccountInfo accountInfo = container.getAccounts().get(101).operations().getAccountInfo();
final AccountInfo accountInfo = container.getAccounts().getByKey(101).operations().getAccountInfo();
assertNotNull(accountInfo);
}
@Test
public void getActualAmount() {
final Double amount = container.getAccounts().get(101).getMyGiftCard().operations().getActualAmount(1.1);
final Double amount = container.getAccounts().getByKey(101).getMyGiftCard().operations().getActualAmount(1.1);
assertEquals(41.79, amount, 0);
}
@Test
public void increaseRevenue() {
final Long result = container.getCompany().get().operations().increaseRevenue(12L);
final Long result = container.getCompany().load().operations().increaseRevenue(12L);
assertNotNull(result);
}
@Test
public void addAccessRight() {
final AccessLevel accessLevel = container.getProducts().get(5).operations().addAccessRight(AccessLevel.Execute);
final AccessLevel accessLevel =
container.getProducts().getByKey(5).operations().addAccessRight(AccessLevel.Execute);
assertNotNull(accessLevel);
}
@Test
public void resetAddress() {
final Customer customer = container.getCustomers().get(2);
final Customer customer = container.getCustomers().getByKey(2);
final Address address = customer.factory().newHomeAddress();
address.setStreet("Via Le Mani Dal Naso, 123");
address.setPostalCode("Tollo");
address.setCity("66010");
final Person person = container.getCustomers().get(2).operations().
final Person person = container.getCustomers().getByKey(2).operations().
resetAddress(Collections.singletonList(address), 0);
assertEquals(2, person.getPersonID(), 0);
}
@Test
public void refreshDefaultPI() {
final PaymentInstrument pi = container.getAccounts().get(101).operations().
final PaymentInstrument pi = container.getAccounts().getByKey(101).operations().
refreshDefaultPI(new Timestamp(Calendar.getInstance().getTimeInMillis()));
assertEquals(101901, pi.getPaymentInstrumentID(), 0);
}

View File

@ -41,15 +41,15 @@ public class DerivedTypeTestITCase extends AbstractTestITCase {
@Test
public void read() {
final CustomerCollection customers = container.getPeople().getAll(CustomerCollection.class);
final CustomerCollection customers = container.getPeople().execute(CustomerCollection.class);
assertNotNull(customers);
for (Customer customer : customers) {
assertTrue(customer instanceof Customer);
}
final CreditCardPICollection creditCards = container.getAccounts().get(101).
getMyPaymentInstruments().getAll(CreditCardPICollection.class);
final CreditCardPICollection creditCards = container.getAccounts().getByKey(101).
getMyPaymentInstruments().execute(CreditCardPICollection.class);
assertNotNull(creditCards);
for (CreditCardPI creditCard : creditCards) {
assertTrue(creditCard instanceof CreditCardPI);
@ -82,7 +82,7 @@ public class DerivedTypeTestITCase extends AbstractTestITCase {
container.flush();
final Person actual = container.getPeople().get(976, Customer.class).load();
final Person actual = container.getPeople().getByKey(976, Customer.class).load();
assertTrue(actual instanceof Customer);
assertTrue(actual.getHomeAddress() instanceof CompanyAddress);

View File

@ -32,7 +32,7 @@ import java.util.TimeZone;
import org.apache.commons.lang3.RandomUtils;
import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.ext.proxy.EntityContainerFactory;
import org.apache.olingo.ext.proxy.Service;
//CHECKSTYLE:OFF (Maven checkstyle)
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;
@ -57,7 +57,7 @@ import org.junit.Test;
*/
public class EntityCreateTestITCase extends AbstractTestITCase {
protected EntityContainerFactory<EdmEnabledODataClient> getContainerFactory() {
protected Service<EdmEnabledODataClient> getContainerFactory() {
return containerFactory;
}
@ -92,13 +92,13 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
getContainer().flush();
Employee actual = getContainer().getPeople().get(id, Employee.class).load();
Employee actual = getContainer().getPeople().getByKey(id, Employee.class).load();
assertNotNull(actual);
assertEquals(id, actual.getPersonID());
assertEquals(homeAddress.getCity(), actual.getHomeAddress().getCity());
getContainerFactory().getContext().detachAll();
actual = getContainer().getPeople().get(id, Employee.class).load();
actual = getContainer().getPeople().getByKey(id, Employee.class).load();
assertNotNull(actual);
assertEquals(id, actual.getPersonID());
assertEquals(homeAddress.getCity(), actual.getHomeAddress().getCity());
@ -107,14 +107,14 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
getContainer().flush();
try {
getContainer().getPeople().get(id, Employee.class).load();
getContainer().getPeople().getByKey(id, Employee.class).load();
fail();
} catch (IllegalArgumentException e) {
}
getContainerFactory().getContext().detachAll();
try {
getContainer().getPeople().get(id, Employee.class).load();
getContainer().getPeople().getByKey(id, Employee.class).load();
fail();
} catch (IllegalArgumentException e) {
}
@ -139,7 +139,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
customer.setNumbers(Arrays.asList(new String[] {"3204725072", "08569930"}));
final OrderCollection orders = getContainer().getOrders().newOrderCollection();
orders.add(getContainer().getOrders().get(8));
orders.add(getContainer().getOrders().getByKey(8));
customer.setOrders(orders);
getContainer().flush();
@ -153,7 +153,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
getContainer().flush();
try {
getContainer().getCustomers().get(id).load();
getContainer().getCustomers().getByKey(id).load();
fail();
} catch (IllegalArgumentException e) {
}
@ -216,7 +216,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
assertEquals(1, actual.getOrders().size());
assertEquals(id, actual.getOrders().iterator().next().getOrderID());
order = getContainer().getOrders().get(id);
order = getContainer().getOrders().getByKey(id);
assertNotNull(order);
assertEquals(id, order.getCustomerForOrder().getPersonID());
@ -224,7 +224,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
getContainer().flush();
try {
getContainer().getOrders().get(id).load();
getContainer().getOrders().getByKey(id).load();
fail();
} catch (IllegalArgumentException e) {
}
@ -236,7 +236,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
getContainer().flush();
try {
getContainer().getCustomers().get(id).load();
getContainer().getCustomers().getByKey(id).load();
fail();
} catch (IllegalArgumentException e) {
}
@ -256,7 +256,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
key.setOrderID(8);
key.setProductID(1);
details = getContainer().getOrderDetails().get(key).load();
details = getContainer().getOrderDetails().getByKey(key).load();
assertNotNull(details);
assertEquals(Integer.valueOf(100), details.getQuantity());
assertEquals(8, details.getOrderID(), 0);
@ -267,7 +267,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
getContainer().flush();
try {
getContainer().getOrderDetails().get(key).load();
getContainer().getOrderDetails().getByKey(key).load();
fail();
} catch (IllegalArgumentException e) {
}
@ -299,17 +299,18 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
getContainer().flush();
product = getContainer().getProducts().get(12).load();
product = getContainer().getProducts().getByKey(12).load();
assertEquals("Latte", product.getName());
assertEquals(12, product.getDetails().iterator().next().getProductDetailID(), 0);
}
@Test
public void contained() {
PaymentInstrumentCollection instruments = getContainer().getAccounts().get(101).getMyPaymentInstruments().getAll();
PaymentInstrumentCollection instruments =
getContainer().getAccounts().getByKey(101).getMyPaymentInstruments().execute();
final int sizeBefore = instruments.size();
final PaymentInstrument instrument = getContainer().getAccounts().get(101).
final PaymentInstrument instrument = getContainer().getAccounts().getByKey(101).
getMyPaymentInstruments().newPaymentInstrument();
final int id = RandomUtils.nextInt(101999, 105000);
@ -319,15 +320,15 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
getContainer().flush();
instruments = getContainer().getAccounts().get(101).getMyPaymentInstruments().getAll();
instruments = getContainer().getAccounts().getByKey(101).getMyPaymentInstruments().execute();
final int sizeAfter = instruments.size();
assertEquals(sizeBefore + 1, sizeAfter);
getContainer().getAccounts().get(101).getMyPaymentInstruments().delete(id);
getContainer().getAccounts().getByKey(101).getMyPaymentInstruments().delete(id);
getContainer().flush();
instruments = getContainer().getAccounts().get(101).getMyPaymentInstruments().getAll();
instruments = getContainer().getAccounts().getByKey(101).getMyPaymentInstruments().execute();
final int sizeEnd = instruments.size();
assertEquals(sizeBefore, sizeEnd);
}

View File

@ -73,21 +73,21 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
@Test
public void getAll() {
final PersonCollection all = getContainer().getPeople().getAll();
final PersonCollection all = getContainer().getPeople().execute();
assertNotNull(all);
assertFalse(all.isEmpty());
for (Person person : all) {
assertNotNull(person);
}
final EmployeeCollection employees = getContainer().getPeople().getAll(EmployeeCollection.class);
final EmployeeCollection employees = getContainer().getPeople().execute(EmployeeCollection.class);
assertNotNull(employees);
assertFalse(employees.isEmpty());
for (Employee employee : employees) {
assertNotNull(employee);
}
final CustomerCollection customers = getContainer().getPeople().getAll(CustomerCollection.class);
final CustomerCollection customers = getContainer().getPeople().execute(CustomerCollection.class);
assertNotNull(customers);
assertFalse(customers.isEmpty());
for (Customer customer : customers) {
@ -99,7 +99,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
@Test
public void navigate() {
final Order order = getContainer().getOrders().get(8).load();
final Order order = getContainer().getOrders().getByKey(8).load();
assertNotNull(order);
assertEquals(8, order.getOrderID(), 0);
@ -110,7 +110,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
actual.set(2011, 2, 4, 16, 3, 57);
assertEquals(actual.getTimeInMillis(), date.getTime());
final Customer customer = getContainer().getCustomers().get(1).load();
final Customer customer = getContainer().getCustomers().getByKey(1).load();
assertNotNull(customer);
assertEquals(1, customer.getPersonID(), 0);
final Address address = customer.getHomeAddress();
@ -135,7 +135,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
@Test
public void withActions() {
final Product product = getContainer().getProducts().get(5).load();
final Product product = getContainer().getProducts().getByKey(5).load();
assertEquals(5, product.getProductID(), 0);
try {
@ -151,7 +151,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
orderDetailKey.setOrderID(7);
orderDetailKey.setProductID(5);
final OrderDetail orderDetail = getContainer().getOrderDetails().get(orderDetailKey).load();
final OrderDetail orderDetail = getContainer().getOrderDetails().getByKey(orderDetailKey).load();
assertNotNull(orderDetail);
assertEquals(7, orderDetail.getOrderID(), 0);
assertEquals(5, orderDetail.getProductID(), 0);
@ -159,14 +159,14 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
@Test
public void checkForETag() {
final Order order = getContainer().getOrders().get(8).load();
final Order order = getContainer().getOrders().getByKey(8).load();
assertTrue(StringUtils.isNotBlank(((EntityInvocationHandler) Proxy.getInvocationHandler(order)).getETag()));
}
@Test
public void contained() {
final PaymentInstrument instrument =
getContainer().getAccounts().get(101).getMyPaymentInstruments().get(101901).load();
getContainer().getAccounts().getByKey(101).getMyPaymentInstruments().getByKey(101901).load();
assertEquals(101901, instrument.getPaymentInstrumentID(), 0);
assertNotNull(instrument.getCreatedDate());
}

View File

@ -39,7 +39,7 @@ public class EntitySetTestITCase extends AbstractTestITCase {
@Test
public void getAll() {
int count = 0;
for (Customer customer : container.getCustomers().getAll()) {
for (Customer customer : container.getCustomers().execute()) {
assertNotNull(customer);
count++;
}
@ -59,7 +59,7 @@ public class EntitySetTestITCase extends AbstractTestITCase {
@Test
public void readEntitySetWithNextLink() {
int count = 0;
for (Person people : container.getPeople().getAll()) {
for (Person people : container.getPeople().execute()) {
assertNotNull(people);
count++;
}

View File

@ -32,7 +32,7 @@ import java.util.UUID;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.ext.proxy.EntityContainerFactory;
import org.apache.olingo.ext.proxy.Service;
import org.apache.olingo.ext.proxy.commons.EntityInvocationHandler;
//CHECKSTYLE:OFF (Maven checkstyle)
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities;
@ -52,7 +52,7 @@ import org.junit.Test;
*/
public class EntityUpdateTestITCase extends AbstractTestITCase {
protected EntityContainerFactory<EdmEnabledODataClient> getContainerFactory() {
protected Service<EdmEnabledODataClient> getContainerFactory() {
return containerFactory;
}
@ -62,14 +62,14 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
@Test
public void update() {
Person person = getContainer().getPeople().get(1).load();
Person person = getContainer().getPeople().getByKey(1).load();
final Address address = person.getHomeAddress();
address.setCity("XXX");
getContainer().flush();
person = getContainer().getPeople().get(1).load();
person = getContainer().getPeople().getByKey(1).load();
assertEquals("XXX", person.getHomeAddress().getCity());
}
@ -79,7 +79,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
orderDetailKey.setOrderID(7);
orderDetailKey.setProductID(5);
OrderDetail orderDetail = getContainer().getOrderDetails().get(orderDetailKey).load();
OrderDetail orderDetail = getContainer().getOrderDetails().getByKey(orderDetailKey).load();
assertNotNull(orderDetail);
assertEquals(7, orderDetail.getOrderID(), 0);
assertEquals(5, orderDetail.getProductID(), 0);
@ -88,7 +88,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
getContainer().flush();
orderDetail = getContainer().getOrderDetails().get(orderDetailKey).load();
orderDetail = getContainer().getOrderDetails().getByKey(orderDetailKey).load();
assertEquals(5, orderDetail.getQuantity(), 0);
}
@ -132,10 +132,10 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
getContainer().flush();
// 3. check everything after flush
order = getContainer().getOrders().get(orderId).load();
order = getContainer().getOrders().getByKey(orderId).load();
assertEquals(orderId, order.getOrderID(), 0);
customer = getContainer().getCustomers().get(977);
customer = getContainer().getCustomers().getByKey(977);
// assertEquals(1, customer.getOrders().size());
@ -157,7 +157,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
@Test
public void concurrentModification() {
Order order = getContainer().getOrders().get(8).load();
Order order = getContainer().getOrders().getByKey(8).load();
final String etag = ((EntityInvocationHandler) Proxy.getInvocationHandler(order)).getETag();
assertTrue(StringUtils.isNotBlank(etag));
@ -165,20 +165,21 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
getContainer().flush();
order = getContainer().getOrders().get(8).load();
order = getContainer().getOrders().getByKey(8).load();
assertEquals(BigDecimal.TEN, order.getShelfLife());
}
@Test
public void contained() {
PaymentInstrument instrument = getContainer().getAccounts().get(101).getMyPaymentInstruments().get(101901);
PaymentInstrument instrument =
getContainer().getAccounts().getByKey(101).getMyPaymentInstruments().getByKey(101901);
final String newName = UUID.randomUUID().toString();
instrument.setFriendlyName(newName);
getContainer().flush();
instrument = getContainer().getAccounts().get(101).getMyPaymentInstruments().get(101901).load();
instrument = getContainer().getAccounts().getByKey(101).getMyPaymentInstruments().getByKey(101901).load();
assertEquals(newName, instrument.getFriendlyName());
}
}

View File

@ -18,17 +18,20 @@
*/
package org.apache.olingo.fit.proxy.v4;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.olingo.ext.proxy.api.Filter;
import org.apache.olingo.ext.proxy.api.Search;
import org.apache.olingo.ext.proxy.api.Sort;
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.People;
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Customer;
//CHECKSTYLE:OFF (Maven checkstyle)
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Person;
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.PersonCollection;
@ -39,11 +42,12 @@ public class FilterTestITCase extends AbstractTestITCase {
@Test
public void filterOrderby() {
final Filter<Person, PersonCollection> filter = container.getPeople().createFilter().setFilter(
containerFactory.getClient().getFilterFactory().lt("PersonID", 3));
final People people = container.getPeople();
PersonCollection result =
people.filter(containerFactory.getClient().getFilterFactory().lt("PersonID", 3)).execute();
// 1. check that result looks as expected
PersonCollection result = filter.getResult();
assertEquals(2, result.size());
// 2. extract PersonID values - sorted ASC by default
@ -55,7 +59,7 @@ public class FilterTestITCase extends AbstractTestITCase {
}
// 3. add orderby clause to filter above
result = filter.setOrderBy(new Sort("PersonID", Sort.Direction.DESC)).getResult();
result = people.orderBy(new Sort("PersonID", Sort.Direction.DESC)).execute();
assertEquals(2, result.size());
// 4. extract again VIN value - now they were required to be sorted DESC
@ -74,11 +78,41 @@ public class FilterTestITCase extends AbstractTestITCase {
@Test
public void search() {
final Search<Person, PersonCollection> search = container.getPeople().createSearch().setSearch(
containerFactory.getClient().getSearchFactory().or(
containerFactory.getClient().getSearchFactory().or(
containerFactory.getClient().getSearchFactory().literal("Bob"),
containerFactory.getClient().getSearchFactory().literal("Jill")));
final PersonCollection result = search.getResult();
assertFalse(result.isEmpty());
}
@Test
public void loadWithSelect() {
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Order order =
container.getOrders().getByKey(8);
assertNull(order.getOrderID());
assertNull(order.getOrderDate());
order.select("OrderID");
order.load();
assertNull(order.getOrderDate());
assertNotNull(order.getOrderID());
order.clear();
order.load();
assertNotNull(order.getOrderDate());
assertNotNull(order.getOrderID());
}
@Test
public void loadWithSelectAndExpand() {
final Customer customer = container.getCustomers().getByKey(1);
// customer.expand("Orders");
customer.select("Orders", "PersonID");
customer.load();
assertEquals(1, customer.getOrders().size());
}
}

View File

@ -23,20 +23,20 @@ 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.ext.proxy.Service;
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.Person;
import org.junit.Test;
public class KeyAsSegmentTestITCase extends AbstractTestITCase {
private EntityContainerFactory<EdmEnabledODataClient> ecf;
private Service<EdmEnabledODataClient> ecf;
private InMemoryEntities ime;
protected EntityContainerFactory<EdmEnabledODataClient> getContainerFactory() {
protected Service<EdmEnabledODataClient> getContainerFactory() {
if (ecf == null) {
ecf = EntityContainerFactory.getV4(testKeyAsSegmentServiceRootURL);
ecf = Service.getV4(testKeyAsSegmentServiceRootURL);
ecf.getClient().getConfiguration().setKeyAsSegment(true);
ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
}
@ -52,7 +52,7 @@ public class KeyAsSegmentTestITCase extends AbstractTestITCase {
@Test
public void read() {
assertNotNull(getContainer().getAccounts().get(101));
assertNotNull(getContainer().getAccounts().getByKey(101));
}
@Test
@ -62,12 +62,12 @@ public class KeyAsSegmentTestITCase extends AbstractTestITCase {
@Test
public void update() {
Person person = getContainer().getPeople().get(5);
Person person = getContainer().getPeople().getByKey(5);
person.setMiddleName("middleN");
container.flush();
person = getContainer().getPeople().get(5);
person = getContainer().getPeople().getByKey(5);
assertEquals("middleN", person.getMiddleName());
}
}

View File

@ -32,7 +32,7 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils;
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.Service;
import org.apache.olingo.fit.proxy.v4.demo.odatademo.DemoService;
import org.apache.olingo.fit.proxy.v4.demo.odatademo.types.Advertisement;
import org.junit.Test;
@ -42,13 +42,13 @@ import org.junit.Test;
*/
public class MediaEntityTestITCase extends AbstractTestITCase {
private EntityContainerFactory<EdmEnabledODataClient> ecf;
private Service<EdmEnabledODataClient> ecf;
private DemoService ime;
protected EntityContainerFactory<EdmEnabledODataClient> getContainerFactory() {
protected Service<EdmEnabledODataClient> getContainerFactory() {
if (ecf == null) {
ecf = EntityContainerFactory.getV4(testDemoServiceRootURL);
ecf = Service.getV4(testDemoServiceRootURL);
ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
}
return ecf;
@ -65,7 +65,7 @@ public class MediaEntityTestITCase extends AbstractTestITCase {
public void read() throws IOException {
final UUID uuid = UUID.fromString("f89dee73-af9f-4cd4-b330-db93c25ff3c7");
final Advertisement adv = getContainer().getAdvertisements().get(uuid).load();
final Advertisement adv = getContainer().getAdvertisements().getByKey(uuid).load();
assertNotNull(adv.getAirDate());
final InputStream is = adv.getStream();
@ -77,7 +77,7 @@ public class MediaEntityTestITCase extends AbstractTestITCase {
public void update() throws IOException {
final UUID uuid = UUID.fromString("f89dee73-af9f-4cd4-b330-db93c25ff3c7");
final Advertisement adv = getContainer().getAdvertisements().get(uuid).load();
final Advertisement adv = getContainer().getAdvertisements().getByKey(uuid).load();
final String random = RandomStringUtils.random(124, "abcdefghijklmnopqrstuvwxyz");
@ -85,7 +85,7 @@ public class MediaEntityTestITCase extends AbstractTestITCase {
getContainer().flush();
assertEquals(random, IOUtils.toString(getContainer().getAdvertisements().get(uuid).load().getStream()));
assertEquals(random, IOUtils.toString(getContainer().getAdvertisements().getByKey(uuid).load().getStream()));
}
@Test
@ -101,7 +101,7 @@ public class MediaEntityTestITCase extends AbstractTestITCase {
final UUID uuid = adv.getID();
getContainerFactory().getContext().detachAll();
assertEquals(random, IOUtils.toString(getContainer().getAdvertisements().get(uuid).load().getStream()));
assertEquals(random, IOUtils.toString(getContainer().getAdvertisements().getByKey(uuid).load().getStream()));
getContainerFactory().getContext().detachAll();
@ -109,7 +109,7 @@ public class MediaEntityTestITCase extends AbstractTestITCase {
getContainer().flush();
try {
getContainer().getAdvertisements().get(uuid).load();
getContainer().getAdvertisements().getByKey(uuid).load();
fail();
} catch (IllegalArgumentException e) {
}

View File

@ -21,19 +21,19 @@ package org.apache.olingo.fit.proxy.v4;
import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.ext.proxy.EntityContainerFactory;
import org.apache.olingo.ext.proxy.Service;
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities;
public class NonTransactionalAuthEntityCreateTestITCase extends EntityCreateTestITCase {
private EntityContainerFactory<EdmEnabledODataClient> ecf;
private Service<EdmEnabledODataClient> ecf;
private InMemoryEntities ime;
@Override
protected EntityContainerFactory<EdmEnabledODataClient> getContainerFactory() {
protected Service<EdmEnabledODataClient> getContainerFactory() {
if (ecf == null) {
ecf = EntityContainerFactory.getV4(testAuthServiceRootURL, false);
ecf = Service.getV4(testAuthServiceRootURL, false);
ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
ecf.getClient().getConfiguration().
setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient"));

View File

@ -20,19 +20,19 @@ package org.apache.olingo.fit.proxy.v4;
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.Service;
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities;
public class NonTransactionalEntityCreateTestITCase extends EntityCreateTestITCase {
private EntityContainerFactory<EdmEnabledODataClient> ecf;
private Service<EdmEnabledODataClient> ecf;
private InMemoryEntities ime;
@Override
protected EntityContainerFactory<EdmEnabledODataClient> getContainerFactory() {
protected Service<EdmEnabledODataClient> getContainerFactory() {
if (ecf == null) {
ecf = EntityContainerFactory.getV4(testStaticServiceRootURL, false);
ecf = Service.getV4(testStaticServiceRootURL, false);
ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
}
return ecf;

View File

@ -20,19 +20,19 @@ package org.apache.olingo.fit.proxy.v4;
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.Service;
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities;
public class NonTransactionalEntityUpdateTestITCase extends EntityUpdateTestITCase {
private EntityContainerFactory<EdmEnabledODataClient> ecf;
private Service<EdmEnabledODataClient> ecf;
private InMemoryEntities ime;
@Override
protected EntityContainerFactory<EdmEnabledODataClient> getContainerFactory() {
protected Service<EdmEnabledODataClient> getContainerFactory() {
if (ecf == null) {
ecf = EntityContainerFactory.getV4(testStaticServiceRootURL, false);
ecf = Service.getV4(testStaticServiceRootURL, false);
ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
}
return ecf;

View File

@ -20,19 +20,19 @@ package org.apache.olingo.fit.proxy.v4;
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.Service;
import org.apache.olingo.fit.proxy.v4.demo.odatademo.DemoService;
public class NonTransactionalMediaEntityTestITCase extends MediaEntityTestITCase {
private EntityContainerFactory<EdmEnabledODataClient> ecf;
private Service<EdmEnabledODataClient> ecf;
private DemoService ime;
@Override
protected EntityContainerFactory<EdmEnabledODataClient> getContainerFactory() {
protected Service<EdmEnabledODataClient> getContainerFactory() {
if (ecf == null) {
ecf = EntityContainerFactory.getV4(testDemoServiceRootURL, false);
ecf = Service.getV4(testDemoServiceRootURL, false);
ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
}
return ecf;

View File

@ -32,7 +32,7 @@ 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.Service;
import org.apache.olingo.ext.proxy.api.annotations.EntityType;
import org.apache.olingo.fit.proxy.v4.opentype.microsoft.test.odata.services.opentypesservicev4.DefaultContainer;
import org.apache.olingo.fit.proxy.v4.opentype.microsoft.test.odata.services.opentypesservicev4.types.AccountInfo;
@ -48,13 +48,13 @@ import org.junit.Test;
*/
public class OpenTypeTestITCase extends AbstractTestITCase {
private static EntityContainerFactory<EdmEnabledODataClient> otcontainerFactory;
private static Service<EdmEnabledODataClient> otcontainerFactory;
private static DefaultContainer otcontainer;
@BeforeClass
public static void initContainer() {
otcontainerFactory = EntityContainerFactory.getV4(testOpenTypeServiceRootURL);
otcontainerFactory = Service.getV4(testOpenTypeServiceRootURL);
otcontainerFactory.getClient().getConfiguration().
setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
otcontainer = otcontainerFactory.getEntityContainer(DefaultContainer.class);
@ -74,11 +74,11 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
@Test
public void read() {
Row row = otcontainer.getRow().get(UUID.fromString("71f7d0dc-ede4-45eb-b421-555a2aa1e58f")).load();
Row row = otcontainer.getRow().getByKey(UUID.fromString("71f7d0dc-ede4-45eb-b421-555a2aa1e58f")).load();
assertEquals(Double.class, row.getAdditionalProperty("Double").getClass());
assertEquals("71f7d0dc-ede4-45eb-b421-555a2aa1e58f", row.getId().toString());
row = otcontainer.getRow().get(UUID.fromString("672b8250-1e6e-4785-80cf-b94b572e42b3")).load();
row = otcontainer.getRow().getByKey(UUID.fromString("672b8250-1e6e-4785-80cf-b94b572e42b3")).load();
assertEquals(BigDecimal.class, row.getAdditionalProperty("Decimal").getClass());
}
@ -127,7 +127,7 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
otcontainer.flush();
rowIndex = otcontainer.getRowIndex().get(id).load();
rowIndex = otcontainer.getRowIndex().getByKey(id).load();
assertEquals(String.class, rowIndex.getAdditionalProperty("aString").getClass());
assertEquals(Boolean.class, rowIndex.getAdditionalProperty("aBoolean").getClass());
assertEquals(Double.class, rowIndex.getAdditionalProperty("aDouble").getClass());
@ -148,7 +148,7 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
otcontainer.flush();
try {
otcontainer.getRowIndex().get(id).load();
otcontainer.getRowIndex().getByKey(id).load();
fail();
} catch (IllegalArgumentException e) {
}

View File

@ -32,16 +32,16 @@ public class PropertyTestITCase extends AbstractTestITCase {
@Test
public void nullNullableProperty() {
final Customer customer = container.getCustomers().get(1);
final Customer customer = container.getCustomers().getByKey(1);
customer.setFirstName(null);
container.flush();
assertNull(container.getCustomers().get(1).getFirstName());
assertNull(container.getCustomers().getByKey(1).getFirstName());
}
@Test
public void nullNonNullableProperty() {
final StoredPI storedPI = container.getStoredPIs().get(1000);
final StoredPI storedPI = container.getStoredPIs().getByKey(1000);
storedPI.setPIName(null);
try {

View File

@ -33,27 +33,27 @@ public class SingletonTestITCase extends AbstractTestITCase {
@Test
public void read() {
final Company company = container.getCompany().get();
final Company company = container.getCompany().load();
assertEquals(0, company.getCompanyID(), 0);
assertEquals(CompanyCategory.IT, company.getCompanyCategory());
}
@Test
public void update() {
final Company company = container.getCompany().get();
final Company company = container.getCompany().load();
company.setRevenue(132520L);
container.flush();
assertEquals(132520L, container.getCompany().get().getRevenue(), 0);
assertEquals(132520L, container.getCompany().load().getRevenue(), 0);
}
@Test
public void readWithAnnotations() {
final Company company = container.getCompany().get();
final Company company = container.getCompany().load();
assertTrue(company.getAnnotationTerms().isEmpty());
final Person boss = container.getBoss().get();
final Person boss = container.getBoss().load();
assertEquals(2, boss.getPersonID(), 0);
assertEquals(1, boss.getAnnotationTerms().size());

View File

@ -22,19 +22,19 @@ import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.ext.proxy.EntityContainerFactory;
import org.apache.olingo.ext.proxy.Service;
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities;
import org.junit.Test;
public class UnauthorizedEntityCreateTestITCase extends AbstractTestITCase {
private EntityContainerFactory<EdmEnabledODataClient> ecf;
private Service<EdmEnabledODataClient> ecf;
private InMemoryEntities ime;
public EntityContainerFactory<EdmEnabledODataClient> getContainerFactory() {
public Service<EdmEnabledODataClient> getContainerFactory() {
if (ecf == null) {
ecf = EntityContainerFactory.getV4(testAuthServiceRootURL);
ecf = Service.getV4(testAuthServiceRootURL);
ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
ecf.getClient().getConfiguration().
setHttpClientFactory(new BasicAuthHttpClientFactory("not_auth", "not_auth"));

View File

@ -234,9 +234,10 @@ public interface Account
void setMyPaymentInstruments(org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Account.MyPaymentInstruments _myPaymentInstruments);
@org.apache.olingo.ext.proxy.api.annotations.EntitySet(name = "MyPaymentInstruments", contained = true)
interface MyPaymentInstruments
extends AbstractEntitySet<org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.PaymentInstrument, java.lang.Integer, org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.PaymentInstrumentCollection> {
extends org.apache.olingo.ext.proxy.api.CollectionQuery<org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.PaymentInstrument, org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.PaymentInstrumentCollection>, AbstractEntitySet<org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.PaymentInstrument, java.lang.Integer, org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.PaymentInstrumentCollection> {
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.PaymentInstrument newPaymentInstrument();
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.PaymentInstrumentCollection newPaymentInstrumentCollection();
@ -254,9 +255,10 @@ public interface Account
void setActiveSubscriptions(org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Account.ActiveSubscriptions _activeSubscriptions);
@org.apache.olingo.ext.proxy.api.annotations.EntitySet(name = "ActiveSubscriptions", contained = true)
interface ActiveSubscriptions
extends AbstractEntitySet<org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Subscription, java.lang.Integer, org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.SubscriptionCollection> {
extends org.apache.olingo.ext.proxy.api.CollectionQuery<org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Subscription, org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.SubscriptionCollection>, AbstractEntitySet<org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Subscription, java.lang.Integer, org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.SubscriptionCollection> {
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Subscription newSubscription();
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.SubscriptionCollection newSubscriptionCollection();

View File

@ -342,9 +342,10 @@ public interface CreditCardPI
void setCreditRecords(org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.CreditCardPI.CreditRecords _creditRecords);
@org.apache.olingo.ext.proxy.api.annotations.EntitySet(name = "CreditRecords", contained = true)
interface CreditRecords
extends AbstractEntitySet<org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.CreditRecord, java.lang.Integer, org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.CreditRecordCollection> {
extends org.apache.olingo.ext.proxy.api.CollectionQuery<org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.CreditRecord, org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.CreditRecordCollection>, AbstractEntitySet<org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.CreditRecord, java.lang.Integer, org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.CreditRecordCollection> {
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.CreditRecord newCreditRecord();
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.CreditRecordCollection newCreditRecordCollection();

View File

@ -199,9 +199,10 @@ public interface PaymentInstrument
void setBillingStatements(org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.PaymentInstrument.BillingStatements _billingStatements);
@org.apache.olingo.ext.proxy.api.annotations.EntitySet(name = "BillingStatements", contained = true)
interface BillingStatements
extends AbstractEntitySet<org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Statement, java.lang.Integer, org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.StatementCollection> {
extends org.apache.olingo.ext.proxy.api.CollectionQuery<org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Statement, org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.StatementCollection>, AbstractEntitySet<org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Statement, java.lang.Integer, org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.StatementCollection> {
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Statement newStatement();
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.StatementCollection newStatementCollection();

View File

@ -349,9 +349,10 @@ public interface PublicCompany
void setAssets(org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.PublicCompany.Assets _assets);
@org.apache.olingo.ext.proxy.api.annotations.EntitySet(name = "Assets", contained = true)
interface Assets
extends AbstractEntitySet<org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Asset, java.lang.Integer, org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.AssetCollection> {
extends org.apache.olingo.ext.proxy.api.CollectionQuery<org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Asset, org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.AssetCollection>, AbstractEntitySet<org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Asset, java.lang.Integer, org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.AssetCollection> {
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Asset newAsset();
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.AssetCollection newAssetCollection();