From baf2cd10984cdd7b036bb1df1ab8f4bcef76e3a1 Mon Sep 17 00:00:00 2001 From: fmartelli Date: Sun, 13 Jul 2014 18:08:58 +0200 Subject: [PATCH] provided the possibility to specify query options at proxy layer --- ...tityContainerFactory.java => Service.java} | 22 +- .../ext/proxy/api/AbstractEntitySet.java | 40 +--- .../ext/proxy/api/AbstractSingleton.java | 7 - .../olingo/ext/proxy/api/CollectionQuery.java | 71 ++++++- .../olingo/ext/proxy/api/CommonQuery.java | 45 +++++ .../apache/olingo/ext/proxy/api/Filter.java | 131 ------------ .../olingo/ext/proxy/api/SingleQuery.java | 4 +- .../commons/AbstractInvocationHandler.java | 6 +- .../commons/AbstractPersistenceManager.java | 6 +- .../AbstractStructuredInvocationHandler.java | 5 +- .../EntityContainerInvocationHandler.java | 8 +- .../commons/EntityInvocationHandler.java | 44 +++- .../commons/EntitySetInvocationHandler.java | 130 ++++++++---- .../ext/proxy/commons/EntitySetIterator.java | 3 +- .../olingo/ext/proxy/commons/FilterImpl.java | 174 ---------------- ...onTransactionalPersistenceManagerImpl.java | 4 +- .../olingo/ext/proxy/commons/SearchImpl.java | 4 +- .../commons/SingletonInvocationHandler.java | 6 +- .../TransactionalPersistenceManagerImpl.java | 4 +- .../ext/pojogen/AbstractPOJOGenMojo.java | 13 ++ .../src/main/resources/complexCreator.vm | 32 +++ .../src/main/resources/entityCreator.vm | 37 ++++ .../src/main/resources/entityType.vm | 4 +- .../fit/proxy/v3/AbstractTestITCase.java | 14 +- .../proxy/v3/ActionOverloadingTestITCase.java | 26 +-- .../olingo/fit/proxy/v3/AsyncTestITCase.java | 65 +++--- .../fit/proxy/v3/ContextTestITCase.java | 188 +++++++++--------- .../fit/proxy/v3/EntityCreateTestITCase.java | 40 ++-- .../proxy/v3/EntityRetrieveTestITCase.java | 18 +- .../fit/proxy/v3/EntitySetTestITCase.java | 6 +- .../fit/proxy/v3/EntityUpdateTestITCase.java | 18 +- .../olingo/fit/proxy/v3/FilterTestITCase.java | 79 +++++--- .../olingo/fit/proxy/v3/InvokeTestITCase.java | 16 +- .../fit/proxy/v3/MediaEntityTestITCase.java | 16 +- .../fit/proxy/v3/OpenTypeTestITCase.java | 14 +- .../fit/proxy/v3/PrimitiveKeysTestITCase.java | 26 +-- .../fit/proxy/v3/PropertyTestITCase.java | 8 +- .../fit/proxy/v4/AbstractTestITCase.java | 20 +- .../olingo/fit/proxy/v4/AsyncTestITCase.java | 6 +- .../proxy/v4/AuthEntityCreateTestITCase.java | 8 +- .../v4/AuthEntityRetrieveTestITCase.java | 4 +- .../v4/BoundOperationInvokeTestITCase.java | 23 ++- .../fit/proxy/v4/DerivedTypeTestITCase.java | 8 +- .../fit/proxy/v4/EntityCreateTestITCase.java | 39 ++-- .../proxy/v4/EntityRetrieveTestITCase.java | 18 +- .../fit/proxy/v4/EntitySetTestITCase.java | 4 +- .../fit/proxy/v4/EntityUpdateTestITCase.java | 25 +-- .../olingo/fit/proxy/v4/FilterTestITCase.java | 48 ++++- .../fit/proxy/v4/KeyAsSegmentTestITCase.java | 14 +- .../fit/proxy/v4/MediaEntityTestITCase.java | 18 +- ...ansactionalAuthEntityCreateTestITCase.java | 8 +- ...onTransactionalEntityCreateTestITCase.java | 8 +- ...onTransactionalEntityUpdateTestITCase.java | 8 +- ...NonTransactionalMediaEntityTestITCase.java | 8 +- .../fit/proxy/v4/OpenTypeTestITCase.java | 14 +- .../fit/proxy/v4/PropertyTestITCase.java | 6 +- .../fit/proxy/v4/SingletonTestITCase.java | 10 +- .../UnauthorizedEntityCreateTestITCase.java | 8 +- .../odatawcfservice/types/Account.java | 6 +- .../odatawcfservice/types/CreditCardPI.java | 3 +- .../types/PaymentInstrument.java | 3 +- .../odatawcfservice/types/PublicCompany.java | 3 +- 62 files changed, 808 insertions(+), 846 deletions(-) rename ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/{EntityContainerFactory.java => Service.java} (83%) create mode 100644 ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CommonQuery.java delete mode 100644 ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Filter.java delete mode 100644 ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/FilterImpl.java create mode 100644 ext/pojogen-maven-plugin/src/main/resources/complexCreator.vm create mode 100644 ext/pojogen-maven-plugin/src/main/resources/entityCreator.vm diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/Service.java similarity index 83% rename from ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java rename to ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/Service.java index 84b49956b..361109075 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/Service.java @@ -36,24 +36,24 @@ import org.apache.olingo.ext.proxy.context.Context; * * @param actual client class */ -public final class EntityContainerFactory> { +public final class Service> { - private static final Map> FACTORY_PER_SERVICEROOT = - new ConcurrentHashMap>(); + private static final Map> FACTORY_PER_SERVICEROOT = + new ConcurrentHashMap>(); private final Map, Object> ENTITY_CONTAINERS = new ConcurrentHashMap, Object>(); @SuppressWarnings("unchecked") - private static > EntityContainerFactory getInstance( + private static > Service getInstance( final C client, final boolean transactional) { if (!FACTORY_PER_SERVICEROOT.containsKey(client.getServiceRoot())) { client.getConfiguration().setDefaultPubFormat(ODataFormat.JSON_FULL_METADATA); - final EntityContainerFactory instance = new EntityContainerFactory(client, transactional); + final Service instance = new Service(client, transactional); FACTORY_PER_SERVICEROOT.put(client.getServiceRoot(), instance); } - return (EntityContainerFactory) FACTORY_PER_SERVICEROOT.get(client.getServiceRoot()); + return (Service) FACTORY_PER_SERVICEROOT.get(client.getServiceRoot()); } /** @@ -62,7 +62,7 @@ public final class EntityContainerFactory getV3( + public static Service getV3( final String serviceRoot) { return getV3(serviceRoot, true); @@ -75,7 +75,7 @@ public final class EntityContainerFactory getV3( + public static Service getV3( final String serviceRoot, final boolean transactional) { return getInstance(ODataClientFactory.getEdmEnabledV3(serviceRoot), transactional); @@ -87,7 +87,7 @@ public final class EntityContainerFactory getV4( + public static Service getV4( final String serviceRoot) { return getV4(serviceRoot, true); @@ -100,7 +100,7 @@ public final class EntityContainerFactory getV4( + public static Service getV4( final String serviceRoot, final boolean transactional) { return getInstance(ODataClientFactory.getEdmEnabledV4(serviceRoot), transactional); @@ -114,7 +114,7 @@ public final class EntityContainerFactory client, final boolean transactional) { + private Service(final CommonEdmEnabledODataClient client, final boolean transactional) { this.client = client; this.context = new Context(); this.transactional = transactional; diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.java index 71a739205..302096e46 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.java @@ -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 extends StructuredType, KEY extends Serializable, EC extends AbstractEntityCollection> extends Iterable, 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 get(KEY key, Class reference) throws IllegalArgumentException; + S getByKey(KEY key, Class 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 - * @param - * @param reference entity collection class to be returned - * @return all entities of the given subtype - */ - > SEC getAll(Class reference); - /** * Deletes the entity with the given key. * @@ -96,23 +79,6 @@ public interface AbstractEntitySet< */ void delete(Iterable entities); - /** - * Create an instance of Filter. - * - * @return the new filter instance - */ - Filter createFilter(); - - /** - * Create an instance of Filter. - * - * @param - * @param - * @param reference - * @return the new filter instance - */ - > Filter createFilter(Class reference); - /** * Create an instance of Search. * diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractSingleton.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractSingleton.java index fb2feca66..4468653d8 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractSingleton.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractSingleton.java @@ -23,11 +23,4 @@ import java.io.Serializable; public interface AbstractSingleton< T extends Serializable, KEY extends Serializable, EC extends AbstractEntityCollection> extends Serializable { - - /** - * Retrieves a singleton. - * - * @return the singleton - */ - T get(); } diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CollectionQuery.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CollectionQuery.java index 2acd0f1b0..9be70209f 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CollectionQuery.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CollectionQuery.java @@ -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> { +public interface CollectionQuery> + extends CommonQuery> { /** + * Returns all instances. * - * @return structured type. + * @return all entities */ EC execute(); + + /** + * Returns all instances of the given subtype. + * + * @param + * @param + * @param reference entity collection class to be returned + * @return all entities of the given subtype + */ + > SEC execute(Class reference); + + /** + * Sets the $filter expression. + *
+ * Any of available operators and functions can be embodied here. + * + * @param filter the $filter expression. + * @return the same query instance. + */ + CollectionQuery filter(String filter); + + /** + * Sets the filter generating the $filter expression. + * + * @param filter filter instance (to be obtained via factory): note that build() method will be immediately + * invoked. + * @return the same query instance. + */ + CollectionQuery filter(URIFilter filter); + + /** + * Sets the $orderBy expression. + * + * @param sort sort options. + * @return the same query instance. + */ + CollectionQuery orderBy(Sort... sort); + + /** + * Sets the $orderBy expression. + * + * @param orderBy the $orderBy expression. + * @return the same query instance. + */ + CollectionQuery orderBy(String orderBy); + + /** + * Sets the maximum number of results to retrieve ($top). + * + * @param top maximum number of results to retrieve + * @return the same query instance. + * @throws IllegalArgumentException if the argument is negative + */ + CollectionQuery top(int top) throws IllegalArgumentException; + + /** + * Sets the position of the first result to retrieve ($skip). + * + * @param skip position of the first result, numbered from 0 + * @return the same query instance. + * @throws IllegalArgumentException if the argument is negative + */ + CollectionQuery skip(int skip) throws IllegalArgumentException; } diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CommonQuery.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CommonQuery.java new file mode 100644 index 000000000..4c24bc45e --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CommonQuery.java @@ -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 { + + /** + * Sets $expand expression. + * + * @param expand $expand expression items. + * @return the same query instance. + */ + T expand(String... expand); + + /** + * Sets $select expression. + * + * @param select $select expression items. + * @return the same query instance. + */ + T select(String... select); + + /** + * Remove all query options. + * + * @return the same query instance. + */ + T clear(); +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Filter.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Filter.java deleted file mode 100644 index 11b3e836e..000000000 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Filter.java +++ /dev/null @@ -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 filter result type - * @param - */ -public interface Filter> extends Serializable { - - /** - * Sets the $filter expression for this filter. - *
- * Any of available operators and functions can be embodied here. - * - * @param filter the $filter expression for this filter - * @return the same filter instance - */ - Filter setFilter(String filter); - - /** - * Sets the filter generating the $filter expression for this filter. - * - * @param filter filter instance (to be obtained via factory): note that build() method - * will be immediately invoked. - * @return the same filter instance - */ - Filter setFilter(URIFilter filter); - - /** - * The $filter expression for this filter. - * - * @return the $filter expression for this filter - */ - String getFilter(); - - /** - * Sets the $orderBy expression for this filter via sort options. - * - * @param sort sort options - * @return the same filter instance - */ - Filter setOrderBy(Sort... sort); - - /** - * Sets the $orderBy expression for this filter. - * - * @param orderBy the $orderBy expression for this filter - * @return the same filter instance - */ - Filter setOrderBy(String orderBy); - - /** - * The $orderBy expression for this filter. - * - * @return the $orderBy expression for this filter - */ - String getOrderBy(); - - /** - * Sets the maximum number of results to retrieve ($top). - * - * @param maxResults maximum number of results to retrieve - * @return the same filter instance - * @throws IllegalArgumentException if the argument is negative - */ - Filter setMaxResults(int maxResults) throws IllegalArgumentException; - - /** - * The maximum number of results the filter object was set to retrieve ($top). Returns - * Integer.MAX_VALUE 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 ($skip). - * - * @param firstResult position of the first result, numbered from 0 - * @return the same filter instance - * @throws IllegalArgumentException if the argument is negative - */ - Filter setFirstResult(int firstResult) throws IllegalArgumentException; - - /** - * The position of the first result the filter object was set to retrieve ($skip). - * - * Returns 0 if setFirstResult was not applied to the filter object. - * - * @return position of the first result - */ - int getFirstResult(); - - /** - * Executes a $filter 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 $filter filter and return the filter results as collection. - * - * @return an iterable view of the results - */ - EC getResult(); -} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/SingleQuery.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/SingleQuery.java index 66c7b7424..9a43d8be9 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/SingleQuery.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/SingleQuery.java @@ -18,10 +18,10 @@ */ package org.apache.olingo.ext.proxy.api; -public interface SingleQuery { +public interface SingleQuery extends CommonQuery { /** - * + * * @return structured type. */ T load(); diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java index a35712a47..52e356ad9 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java @@ -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; } diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java index d53e68ea2..e68bfc173 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java @@ -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; } diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java index 0d12d7330..b5204cf0e 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java @@ -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(); diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java index 56bcc6d76..80d3ac37a 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java @@ -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; } diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java index a5b68c054..cd9c9360a 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java @@ -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 propertyChanges = new HashMap(); @@ -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 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(); diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java index 28b22cace..b969c0344 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java @@ -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 extends StructuredType, KEY extends Serializable, EC extends AbstractEntityCollection> extends AbstractInvocationHandler implements AbstractEntitySet { @@ -75,7 +77,9 @@ class EntitySetInvocationHandler< private Class 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) entitySetParams[0]; this.collTypeRef = (Class) entitySetParams[2]; - - this.uri = uri; } protected Class 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 get(final KEY key, final Class typeRef) throws IllegalArgumentException { + public S getByKey(final KEY key, final Class 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 > SEC getAll(final Class collTypeRef) { + public > SEC execute(final Class collTypeRef) { final Class ref = (Class) ClassUtils.extractTypeArg(collTypeRef, AbstractEntitySet.class, AbstractSingleton.class, AbstractEntityCollection.class); final Class oref = (Class) 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 createFilter() { - return new FilterImpl(getClient(), this.collTypeRef, this.uri, this); - } - - @Override - @SuppressWarnings("unchecked") - public > Filter createFilter( - final Class reference) { - - return new FilterImpl(getClient(), reference, this.uri, (EntitySetInvocationHandler) this); - } - @Override public Search createSearch() { if (getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) { throw new UnsupportedInV3Exception(); } - return new SearchImpl((EdmEnabledODataClient) getClient(), this.collTypeRef, this.uri, this); + return new SearchImpl((EdmEnabledODataClient) getClient(), this.collTypeRef, this.baseURI, this); } @Override @@ -350,7 +349,10 @@ class EntitySetInvocationHandler< throw new UnsupportedInV3Exception(); } return new SearchImpl( - (EdmEnabledODataClient) getClient(), reference, this.uri, (EntitySetInvocationHandler) this); + (EdmEnabledODataClient) getClient(), + reference, + baseURI, + (EntitySetInvocationHandler) 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 iterator() { - return new EntitySetIterator(getClient().newURIBuilder(this.uri.toASCIIString()).build(), this); + return new EntitySetIterator(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()); } } diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetIterator.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetIterator.java index 48405e860..79655599e 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetIterator.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetIterator.java @@ -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> +class EntitySetIterator> implements Iterator { private final EntitySetInvocationHandler esi; diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/FilterImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/FilterImpl.java deleted file mode 100644 index f328ac718..000000000 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/FilterImpl.java +++ /dev/null @@ -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> implements Filter { - - private static final long serialVersionUID = -300830736753191114L; - - private final CommonODataClient client; - - private final Class typeRef; - - private final Class collTypeRef; - - private final EntitySetInvocationHandler 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 collTypeRef, final URI baseURI, final EntitySetInvocationHandler handler) { - - this.client = client; - this.typeRef = (Class) ClassUtils.extractTypeArg(collTypeRef); - this.collTypeRef = collTypeRef; - this.baseURI = baseURI; - this.handler = handler; - } - - @Override - public Filter setFilter(final String filter) { - this.filter = filter; - return this; - } - - @Override - public Filter setFilter(final URIFilter filter) { - this.filter = filter.build(); - return this; - } - - @Override - public String getFilter() { - return filter; - } - - @Override - public Filter 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 setOrderBy(final String orderBy) { - this.orderBy = orderBy; - return this; - } - - @Override - public String getOrderBy() { - return orderBy; - } - - @Override - public Filter 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 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); - } -} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java index 6f3614812..6a0127c1d 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java @@ -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); } diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SearchImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SearchImpl.java index fb65c6eac..b36e4d179 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SearchImpl.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SearchImpl.java @@ -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> implements Search { +public class SearchImpl> implements Search { private static final long serialVersionUID = 4383858176507769973L; diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java index bbae0c80f..4e6d78bc4 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java @@ -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(); } } diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java index 1165830f8..b64dbfb59 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java @@ -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); } diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java index ea2976709..95bee13c8 100644 --- a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java +++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java @@ -282,7 +282,10 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo { parseObj(typesBaseDir, typesPkg, "complexType", className + ".java", objs); } + final List entities = new ArrayList(); + 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"); diff --git a/ext/pojogen-maven-plugin/src/main/resources/complexCreator.vm b/ext/pojogen-maven-plugin/src/main/resources/complexCreator.vm new file mode 100644 index 000000000..af2388480 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/complexCreator.vm @@ -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 +} diff --git a/ext/pojogen-maven-plugin/src/main/resources/entityCreator.vm b/ext/pojogen-maven-plugin/src/main/resources/entityCreator.vm new file mode 100644 index 000000000..bbb462847 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/entityCreator.vm @@ -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 +} diff --git a/ext/pojogen-maven-plugin/src/main/resources/entityType.vm b/ext/pojogen-maven-plugin/src/main/resources/entityType.vm index 73e1e639b..70d7cbd06 100644 --- a/ext/pojogen-maven-plugin/src/main/resources/entityType.vm +++ b/ext/pojogen-maven-plugin/src/main/resources/entityType.vm @@ -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) ) diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java index bbf077f98..a80e1f534 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java @@ -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 containerFactory; + protected static Service 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()); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java index b43c84250..b3a85ae03 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java @@ -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 ecf = - EntityContainerFactory.getV3(testActionOverloadingServiceRootURL); + final Service 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); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AsyncTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AsyncTestITCase.java index bd593e146..67ca58113 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AsyncTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AsyncTestITCase.java @@ -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 futureProds = - new AsyncCall(containerFactory.getClient().getConfiguration()) { - - @Override - public ProductCollection call() { - return container.getProduct().getAll(); - } - }; + new AsyncCall(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 futureFlush = new AsyncCall(containerFactory.getClient().getConfiguration()) { - + final Future futureFlush = new AsyncCall(service.getClient().getConfiguration()) { @Override public Void call() { container.flush(); @@ -86,11 +82,10 @@ public class AsyncTestITCase extends AbstractTestITCase { Thread.sleep(1000L); } - final Future futureProd = new AsyncCall(containerFactory.getClient().getConfiguration()) { - + final Future futureProd = new AsyncCall(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> queryEmployee = - new AsyncCall>(containerFactory.getClient().getConfiguration()) { + final Future queryEmployee = new AsyncCall(service.getClient().getConfiguration()) { + @Override + public Person call() { + return container.getPerson(); + } + }; + assertFalse(queryEmployee.get().execute(EmployeeCollection.class).isEmpty()); - @Override - public Filter call() { - return container.getPerson().createFilter(EmployeeCollection.class); - } - }; - assertFalse(queryEmployee.get().getResult().isEmpty()); + final Future querySpecialEmployee = new AsyncCall(service.getClient().getConfiguration()) { + @Override + public Person call() { + return container.getPerson(); + } + }; + assertFalse(querySpecialEmployee.get().execute(SpecialEmployeeCollection.class).isEmpty()); - final Future> querySpecialEmployee = - new AsyncCall>( - containerFactory.getClient().getConfiguration()) { - - @Override - public Filter 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()); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java index 405e74114..b3e0806cb 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java @@ -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.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))); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityCreateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityCreateTestITCase.java index 211ced366..59006f4d5 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityCreateTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityCreateTestITCase.java @@ -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) { } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityRetrieveTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityRetrieveTestITCase.java index eb75c796e..bc9b1790e 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityRetrieveTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityRetrieveTestITCase.java @@ -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())); } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntitySetTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntitySetTestITCase.java index a86f7ba15..c31d6efbf 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntitySetTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntitySetTestITCase.java @@ -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 = container.getCar().getAll(); + final Iterable car = container.getCar().execute(); assertNotNull(car); final Iterator itor = car.iterator(); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityUpdateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityUpdateTestITCase.java index 5cef4d795..a7af5819d 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityUpdateTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityUpdateTestITCase.java @@ -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()); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/FilterTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/FilterTestITCase.java index d01514124..98c2f6f73 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/FilterTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/FilterTestITCase.java @@ -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 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 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 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 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); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/InvokeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/InvokeTestITCase.java index 7caa8ac6a..09145e1d7 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/InvokeTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/InvokeTestITCase.java @@ -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 preSalaries = new HashMap(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()); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/MediaEntityTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/MediaEntityTestITCase.java index c478ac66b..365021fc5 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/MediaEntityTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/MediaEntityTestITCase.java @@ -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) { } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java index f2a74632f..80bd207b6 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java @@ -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 otcontainerFactory; + private static Service 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) { } } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/PrimitiveKeysTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/PrimitiveKeysTestITCase.java index c04198362..bf6f349de 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/PrimitiveKeysTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/PrimitiveKeysTestITCase.java @@ -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 testContainerFactory = - EntityContainerFactory.getV3(testPrimitiveKeysServiceRootURL); + final Service 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()); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/PropertyTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/PropertyTestITCase.java index 9d94d2c1f..4bcd4b770 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/PropertyTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/PropertyTestITCase.java @@ -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(); } } } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AbstractTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AbstractTestITCase.java index b72610a18..ad489ab3d 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AbstractTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AbstractTestITCase.java @@ -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 containerFactory; + protected static Service 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 containerFactory) { + final InMemoryEntities container, final Service 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) { } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AsyncTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AsyncTestITCase.java index ea1179fc7..28c4987e6 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AsyncTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AsyncTestITCase.java @@ -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 futureFlush = new AsyncCall(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); } }; diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityCreateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityCreateTestITCase.java index 429329225..21937d0fa 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityCreateTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityCreateTestITCase.java @@ -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 ecf; + private Service ecf; private InMemoryEntities ime; @Override - protected EntityContainerFactory getContainerFactory() { + protected Service 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")); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java index 15ebfed60..3e8fa6ebc 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java @@ -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 ecf = EntityContainerFactory.getV4(testAuthServiceRootURL); + final Service ecf = Service.getV4(testAuthServiceRootURL); ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); ecf.getClient().getConfiguration(). setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient")); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/BoundOperationInvokeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/BoundOperationInvokeTestITCase.java index 54fd70afe..76abd061d 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/BoundOperationInvokeTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/BoundOperationInvokeTestITCase.java @@ -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); } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/DerivedTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/DerivedTypeTestITCase.java index fd43a8504..3f9a51072 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/DerivedTypeTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/DerivedTypeTestITCase.java @@ -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); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java index 325059476..966eee783 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java @@ -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 getContainerFactory() { + protected Service 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); } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityRetrieveTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityRetrieveTestITCase.java index 2007b8101..7ebed37af 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityRetrieveTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityRetrieveTestITCase.java @@ -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()); } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntitySetTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntitySetTestITCase.java index ef537eefc..141a3ac59 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntitySetTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntitySetTestITCase.java @@ -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++; } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityUpdateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityUpdateTestITCase.java index b156d3145..cb7ed463f 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityUpdateTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityUpdateTestITCase.java @@ -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 getContainerFactory() { + protected Service 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()); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/FilterTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/FilterTestITCase.java index 3b2d0b331..78763150c 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/FilterTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/FilterTestITCase.java @@ -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 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 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()); + } } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/KeyAsSegmentTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/KeyAsSegmentTestITCase.java index b5bd7d213..c1c5da4e0 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/KeyAsSegmentTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/KeyAsSegmentTestITCase.java @@ -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 ecf; + private Service ecf; private InMemoryEntities ime; - protected EntityContainerFactory getContainerFactory() { + protected Service 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()); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/MediaEntityTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/MediaEntityTestITCase.java index bacdb5728..cdfe5ff9c 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/MediaEntityTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/MediaEntityTestITCase.java @@ -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 ecf; + private Service ecf; private DemoService ime; - protected EntityContainerFactory getContainerFactory() { + protected Service 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) { } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalAuthEntityCreateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalAuthEntityCreateTestITCase.java index 4a56853c3..65c53ae0a 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalAuthEntityCreateTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalAuthEntityCreateTestITCase.java @@ -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 ecf; + private Service ecf; private InMemoryEntities ime; @Override - protected EntityContainerFactory getContainerFactory() { + protected Service 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")); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalEntityCreateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalEntityCreateTestITCase.java index 804148611..091adefdb 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalEntityCreateTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalEntityCreateTestITCase.java @@ -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 ecf; + private Service ecf; private InMemoryEntities ime; @Override - protected EntityContainerFactory getContainerFactory() { + protected Service getContainerFactory() { if (ecf == null) { - ecf = EntityContainerFactory.getV4(testStaticServiceRootURL, false); + ecf = Service.getV4(testStaticServiceRootURL, false); ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); } return ecf; diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalEntityUpdateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalEntityUpdateTestITCase.java index cfc3a4f3c..e789f902c 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalEntityUpdateTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalEntityUpdateTestITCase.java @@ -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 ecf; + private Service ecf; private InMemoryEntities ime; @Override - protected EntityContainerFactory getContainerFactory() { + protected Service getContainerFactory() { if (ecf == null) { - ecf = EntityContainerFactory.getV4(testStaticServiceRootURL, false); + ecf = Service.getV4(testStaticServiceRootURL, false); ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); } return ecf; diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalMediaEntityTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalMediaEntityTestITCase.java index 53d1c89cc..487763397 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalMediaEntityTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalMediaEntityTestITCase.java @@ -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 ecf; + private Service ecf; private DemoService ime; @Override - protected EntityContainerFactory getContainerFactory() { + protected Service getContainerFactory() { if (ecf == null) { - ecf = EntityContainerFactory.getV4(testDemoServiceRootURL, false); + ecf = Service.getV4(testDemoServiceRootURL, false); ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); } return ecf; diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/OpenTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/OpenTypeTestITCase.java index b88de4926..6c3bdec6d 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/OpenTypeTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/OpenTypeTestITCase.java @@ -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 otcontainerFactory; + private static Service 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) { } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/PropertyTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/PropertyTestITCase.java index 3c39b6891..b15f9855a 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/PropertyTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/PropertyTestITCase.java @@ -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 { diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java index 91b32f306..2388ff5ec 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java @@ -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()); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/UnauthorizedEntityCreateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/UnauthorizedEntityCreateTestITCase.java index ef47e0275..b4ca6579c 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/UnauthorizedEntityCreateTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/UnauthorizedEntityCreateTestITCase.java @@ -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 ecf; + private Service ecf; private InMemoryEntities ime; - public EntityContainerFactory getContainerFactory() { + public Service 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")); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/Account.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/Account.java index ad433df6d..bd50a2a43 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/Account.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/Account.java @@ -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 { + extends org.apache.olingo.ext.proxy.api.CollectionQuery, AbstractEntitySet { 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 { + extends org.apache.olingo.ext.proxy.api.CollectionQuery, AbstractEntitySet { 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(); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/CreditCardPI.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/CreditCardPI.java index 06a6b6c3f..985e61467 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/CreditCardPI.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/CreditCardPI.java @@ -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 { + extends org.apache.olingo.ext.proxy.api.CollectionQuery, AbstractEntitySet { 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(); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/PaymentInstrument.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/PaymentInstrument.java index 42d474afe..5d9ae4cfa 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/PaymentInstrument.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/PaymentInstrument.java @@ -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 { + extends org.apache.olingo.ext.proxy.api.CollectionQuery, AbstractEntitySet { 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(); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/PublicCompany.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/PublicCompany.java index 1c8c6d46d..fb6eeed9b 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/PublicCompany.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/PublicCompany.java @@ -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 { + extends org.apache.olingo.ext.proxy.api.CollectionQuery, AbstractEntitySet { 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();