[OLINGO-260] provided v4 integration test for entity creation

Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/2e06947b
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/2e06947b
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/2e06947b

Branch: refs/heads/master
Commit: 2e06947bfc07b2ada48c3755f212bb281512323b
Parents: 15eb587
Author: fmartelli <[email protected]>
Authored: Tue May 13 13:39:28 2014 +0200
Committer: Stephan Klevenz <[email protected]>
Committed: Mon May 19 14:28:51 2014 +0200

----------------------------------------------------------------------
 .../ext/proxy/EntityContainerFactory.java       |  33 ++--
 .../olingo/ext/proxy/commons/ContainerImpl.java | 150 +++++++-------
 .../commons/EntitySetInvocationHandler.java     | 195 +++++++++----------
 .../java/org/apache/olingo/fit/V4Services.java  |   2 +-
 .../olingo/fit/proxy/v3/AbstractTestITCase.java |  22 +--
 .../olingo/fit/proxy/v4/AbstractTestITCase.java |  56 +-----
 .../fit/proxy/v4/EntityCreateTestITCase.java    | 122 +++++-------
 .../odatawcfservice/types/OrderDetail.java      |   2 -
 8 files changed, 241 insertions(+), 341 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2e06947b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
----------------------------------------------------------------------
diff --git 
a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
 
b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
index c378a7a..3e8606e 100644
--- 
a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
+++ 
b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
@@ -22,6 +22,7 @@ import java.lang.reflect.Proxy;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.olingo.client.api.CommonConfiguration;
 import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
 import org.apache.olingo.client.core.ODataClientFactory;
 import org.apache.olingo.commons.api.format.ODataPubFormat;
@@ -29,18 +30,16 @@ import 
org.apache.olingo.ext.proxy.commons.EntityContainerInvocationHandler;
 import org.apache.olingo.ext.proxy.context.Context;
 
 /**
- * Entry point for proxy mode, gives access to entity container instances.
- *
- * @param <C> actual client class
+ * Entry point for ODataJClient proxy mode, gives access to entity container 
instances.
  */
-public final class EntityContainerFactory<C extends 
CommonEdmEnabledODataClient<?>> {
+public final class EntityContainerFactory {
 
   private static final Object MONITOR = new Object();
 
   private static Context context = null;
 
-  private static final Map<String, EntityContainerFactory<?>> 
FACTORY_PER_SERVICEROOT =
-          new ConcurrentHashMap<String, EntityContainerFactory<?>>();
+  private static final Map<String, EntityContainerFactory> 
FACTORY_PER_SERVICEROOT =
+          new ConcurrentHashMap<String, EntityContainerFactory>();
 
   private static final Map<Class<?>, Object> ENTITY_CONTAINERS = new 
ConcurrentHashMap<Class<?>, Object>();
 
@@ -58,28 +57,23 @@ public final class EntityContainerFactory<C extends 
CommonEdmEnabledODataClient<
     return context;
   }
 
-  @SuppressWarnings("unchecked")
-  private static <C extends CommonEdmEnabledODataClient<?>> 
EntityContainerFactory<C> getInstance(
+  private static <C extends CommonEdmEnabledODataClient<?>> 
EntityContainerFactory getInstance(
           final C client, final String serviceRoot) {
 
     if (!FACTORY_PER_SERVICEROOT.containsKey(serviceRoot)) {
-      final EntityContainerFactory<C> instance = new 
EntityContainerFactory<C>(client, serviceRoot);
+      final EntityContainerFactory instance = new 
EntityContainerFactory(client, serviceRoot);
       FACTORY_PER_SERVICEROOT.put(serviceRoot, instance);
     }
     
client.getConfiguration().setDefaultPubFormat(ODataPubFormat.JSON_FULL_METADATA);
-
-    return (EntityContainerFactory<C>) 
FACTORY_PER_SERVICEROOT.get(serviceRoot);
+    
+    return FACTORY_PER_SERVICEROOT.get(serviceRoot);
   }
 
-  public static 
EntityContainerFactory<org.apache.olingo.client.api.v3.EdmEnabledODataClient> 
getV3(
-          final String serviceRoot) {
-
+  public static EntityContainerFactory getV3(final String serviceRoot) {
     return getInstance(ODataClientFactory.getEdmEnabledV3(serviceRoot), 
serviceRoot);
   }
 
-  public static 
EntityContainerFactory<org.apache.olingo.client.api.v4.EdmEnabledODataClient> 
getV4(
-          final String serviceRoot) {
-
+  public static EntityContainerFactory getV4(final String serviceRoot) {
     return getInstance(ODataClientFactory.getEdmEnabledV4(serviceRoot), 
serviceRoot);
   }
 
@@ -88,9 +82,8 @@ public final class EntityContainerFactory<C extends 
CommonEdmEnabledODataClient<
     this.serviceRoot = serviceRoot;
   }
 
-  @SuppressWarnings("unchecked")
-  public C getClient() {
-    return (C) client;
+  public CommonConfiguration getConfiguration() {
+    return client.getConfiguration();
   }
 
   public String getServiceRoot() {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2e06947b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java
----------------------------------------------------------------------
diff --git 
a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java
 
b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java
index da9329d..3d30497 100644
--- 
a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java
+++ 
b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java
@@ -46,6 +46,7 @@ import 
org.apache.olingo.client.api.communication.response.ODataBatchResponse;
 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.client.api.uri.CommonURIBuilder;
 import 
org.apache.olingo.client.core.communication.request.batch.ODataChangesetResponseItem;
 import org.apache.olingo.client.core.uri.URIUtils;
 import org.apache.olingo.commons.api.domain.CommonODataEntity;
@@ -74,9 +75,9 @@ class ContainerImpl implements Container {
 
   private final CommonEdmEnabledODataClient<?> client;
 
-  private final EntityContainerFactory<?> factory;
+  private final EntityContainerFactory factory;
 
-  ContainerImpl(final CommonEdmEnabledODataClient<?> client, final 
EntityContainerFactory<?> factory) {
+  ContainerImpl(final CommonEdmEnabledODataClient<?> client, final 
EntityContainerFactory factory) {
     this.client = client;
     this.factory = factory;
   }
@@ -87,7 +88,7 @@ class ContainerImpl implements Container {
   @Override
   public void flush() {
     final CommonODataBatchRequest request = 
client.getBatchRequestFactory().getBatchRequest(client.getServiceRoot());
-    ((ODataRequest) 
request).setAccept(client.getConfiguration().getDefaultBatchAcceptFormat());
+    
((ODataRequest)request).setAccept(client.getConfiguration().getDefaultBatchAcceptFormat());
 
     final BatchStreamManager streamManager = (BatchStreamManager) 
((ODataStreamedRequest) request).execute();
 
@@ -137,13 +138,13 @@ class ContainerImpl implements Container {
           throw new IllegalStateException("Transaction failed: " + 
res.getStatusMessage());
         }
 
-        final EntityInvocationHandler handler = items.get(changesetItemId);
+        final EntityTypeInvocationHandler<?> handler = 
items.get(changesetItemId);
 
         if (handler != null) {
-          if (res instanceof ODataEntityCreateResponse && res.getStatusCode() 
== 201) {
+          if (res instanceof ODataEntityCreateResponse) {
             handler.setEntity(((ODataEntityCreateResponse) res).getBody());
             LOG.debug("Upgrade created object '{}'", handler);
-          } else if (res instanceof ODataEntityUpdateResponse && 
res.getStatusCode() == 200) {
+          } else if (res instanceof ODataEntityUpdateResponse) {
             handler.setEntity(((ODataEntityUpdateResponse) res).getBody());
             LOG.debug("Upgrade updated object '{}'", handler);
           }
@@ -154,44 +155,45 @@ class ContainerImpl implements Container {
     EntityContainerFactory.getContext().detachAll();
   }
 
-  private AttachedEntityStatus batch(
-          final EntityInvocationHandler handler,
+  private void batch(
+          final EntityTypeInvocationHandler<?> handler,
           final CommonODataEntity entity,
           final ODataChangeset changeset) {
 
     switch 
(EntityContainerFactory.getContext().entityContext().getStatus(handler)) {
       case NEW:
         batchCreate(handler, entity, changeset);
-        return AttachedEntityStatus.NEW;
+        break;
 
       case CHANGED:
         batchUpdate(handler, entity, changeset);
-        return AttachedEntityStatus.CHANGED;
+        break;
 
       case DELETED:
         batchDelete(handler, entity, changeset);
-        return AttachedEntityStatus.DELETED;
+        break;
 
       default:
         if (handler.isChanged()) {
           batchUpdate(handler, entity, changeset);
         }
-        return AttachedEntityStatus.CHANGED;
     }
   }
 
   private void batchCreate(
-          final EntityInvocationHandler handler,
+          final EntityTypeInvocationHandler<?> handler,
           final CommonODataEntity entity,
           final ODataChangeset changeset) {
 
     LOG.debug("Create '{}'", handler);
 
-    
changeset.addRequest(client.getCUDRequestFactory().getEntityCreateRequest(handler.getEntitySetURI(),
 entity));
+    final CommonURIBuilder<?> uriBuilder = 
client.getURIBuilder(factory.getServiceRoot()).
+            appendEntitySetSegment(handler.getEntitySetName());
+    
changeset.addRequest(client.getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(),
 entity));
   }
 
   private void batchUpdateMediaEntity(
-          final EntityInvocationHandler handler,
+          final EntityTypeInvocationHandler<?> handler,
           final URI uri,
           final InputStream input,
           final ODataChangeset changeset) {
@@ -213,7 +215,7 @@ class ContainerImpl implements Container {
   }
 
   private void batchUpdateMediaResource(
-          final EntityInvocationHandler handler,
+          final EntityTypeInvocationHandler<?> handler,
           final URI uri,
           final InputStream input,
           final ODataChangeset changeset) {
@@ -230,20 +232,18 @@ class ContainerImpl implements Container {
   }
 
   private void batchUpdate(
-          final EntityInvocationHandler handler,
+          final EntityTypeInvocationHandler<?> handler,
           final CommonODataEntity changes,
           final ODataChangeset changeset) {
 
-    LOG.debug("Update '{}'", handler.getEntityURI());
+    LOG.debug("Update '{}'", changes.getEditLink());
 
     final ODataEntityUpdateRequest<CommonODataEntity> req =
             client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0
             ? ((org.apache.olingo.client.api.v3.EdmEnabledODataClient) 
client).getCUDRequestFactory().
-            getEntityUpdateRequest(handler.getEntityURI(),
-            
org.apache.olingo.client.api.communication.request.cud.v3.UpdateType.PATCH, 
changes)
+            
getEntityUpdateRequest(org.apache.olingo.client.api.communication.request.cud.v3.UpdateType.PATCH,
 changes)
             : ((org.apache.olingo.client.api.v4.EdmEnabledODataClient) 
client).getCUDRequestFactory().
-            getEntityUpdateRequest(handler.getEntityURI(),
-            
org.apache.olingo.client.api.communication.request.cud.v4.UpdateType.PATCH, 
changes);
+            
getEntityUpdateRequest(org.apache.olingo.client.api.communication.request.cud.v4.UpdateType.PATCH,
 changes);
 
     req.setPrefer(new 
ODataPreferences(client.getServiceVersion()).returnContent());
 
@@ -255,7 +255,7 @@ class ContainerImpl implements Container {
   }
 
   private void batchUpdate(
-          final EntityInvocationHandler handler,
+          final EntityTypeInvocationHandler<?> handler,
           final URI uri,
           final CommonODataEntity changes,
           final ODataChangeset changeset) {
@@ -265,11 +265,11 @@ class ContainerImpl implements Container {
     final ODataEntityUpdateRequest<CommonODataEntity> req =
             client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0
             ? ((org.apache.olingo.client.api.v3.EdmEnabledODataClient) 
client).getCUDRequestFactory().
-            getEntityUpdateRequest(uri,
-            
org.apache.olingo.client.api.communication.request.cud.v3.UpdateType.PATCH, 
changes)
+            getEntityUpdateRequest(
+            uri, 
org.apache.olingo.client.api.communication.request.cud.v3.UpdateType.PATCH, 
changes)
             : ((org.apache.olingo.client.api.v4.EdmEnabledODataClient) 
client).getCUDRequestFactory().
-            getEntityUpdateRequest(uri,
-            
org.apache.olingo.client.api.communication.request.cud.v4.UpdateType.PATCH, 
changes);
+            getEntityUpdateRequest(
+            uri, 
org.apache.olingo.client.api.communication.request.cud.v4.UpdateType.PATCH, 
changes);
 
     req.setPrefer(new 
ODataPreferences(client.getServiceVersion()).returnContent());
 
@@ -281,14 +281,14 @@ class ContainerImpl implements Container {
   }
 
   private void batchDelete(
-          final EntityInvocationHandler handler,
+          final EntityTypeInvocationHandler<?> handler,
           final CommonODataEntity entity,
           final ODataChangeset changeset) {
 
-    final URI deleteURI = handler.getEntityURI() == null ? 
entity.getEditLink() : handler.getEntityURI();
-    LOG.debug("Delete '{}'", deleteURI);
+    LOG.debug("Delete '{}'", entity.getEditLink());
 
-    final ODataDeleteRequest req = 
client.getCUDRequestFactory().getDeleteRequest(deleteURI);
+    final ODataDeleteRequest req = 
client.getCUDRequestFactory().getDeleteRequest(URIUtils.getURI(
+            factory.getServiceRoot(), entity.getEditLink().toASCIIString()));
 
     if (StringUtils.isNotBlank(handler.getETag())) {
       req.setIfMatch(handler.getETag());
@@ -298,7 +298,7 @@ class ContainerImpl implements Container {
   }
 
   private int processEntityContext(
-          final EntityInvocationHandler handler,
+          final EntityTypeInvocationHandler<?> handler,
           int pos,
           final TransactionItems items,
           final List<EntityLinkDesc> delayedUpdates,
@@ -323,14 +323,14 @@ class ContainerImpl implements Container {
               ? ODataLinkType.ENTITY_SET_NAVIGATION
               : ODataLinkType.ENTITY_NAVIGATION;
 
-      final Set<EntityInvocationHandler> toBeLinked = new 
HashSet<EntityInvocationHandler>();
+      final Set<EntityTypeInvocationHandler<?>> toBeLinked = new 
HashSet<EntityTypeInvocationHandler<?>>();
       final String serviceRoot = factory.getServiceRoot();
 
       for (Object proxy : type == ODataLinkType.ENTITY_SET_NAVIGATION
               ? (Collection) property.getValue() : 
Collections.singleton(property.getValue())) {
 
-        final EntityInvocationHandler target =
-                (EntityInvocationHandler) Proxy.getInvocationHandler(proxy);
+        final EntityTypeInvocationHandler<?> target =
+                (EntityTypeInvocationHandler) 
Proxy.getInvocationHandler(proxy);
 
         final AttachedEntityStatus status =
                 
EntityContainerFactory.getContext().entityContext().getStatus(target);
@@ -360,7 +360,8 @@ class ContainerImpl implements Container {
             // create the link for the current object
             LOG.debug("'{}' from '{}' to (${}) '{}'", type.name(), handler, 
targetPos, target);
 
-            entity.addLink(buildNavigationLink(property.getKey().name(), 
URI.create("$" + targetPos), type));
+            entity.addLink(
+                    buildNavigationLink(property.getKey().name(), 
URI.create("$" + targetPos), type));
           }
         }
       }
@@ -372,53 +373,52 @@ class ContainerImpl implements Container {
 
     // insert into the batch
     LOG.debug("{}: Insert '{}' into the batch", pos, handler);
-    final AttachedEntityStatus processedStatus = batch(handler, entity, 
changeset);
+    batch(handler, entity, changeset);
 
     items.put(handler, pos);
 
-    if (processedStatus != AttachedEntityStatus.DELETED) {
-      int startingPos = pos;
-
-      if (handler.getEntity().isMediaEntity() && handler.isChanged()) {
-        // update media properties
-        if (!handler.getPropertyChanges().isEmpty()) {
-          final URI targetURI = currentStatus == AttachedEntityStatus.NEW
-                  ? URI.create("$" + startingPos)
-                  : URIUtils.getURI(factory.getServiceRoot(), 
handler.getEntity().getEditLink().toASCIIString());
-          batchUpdate(handler, targetURI, entity, changeset);
-          pos++;
-          items.put(handler, pos);
-        }
-
-        // update media content
-        if (handler.getStreamChanges() != null) {
-          final URI targetURI = currentStatus == AttachedEntityStatus.NEW
-                  ? URI.create("$" + startingPos + "/$value")
-                  : URIUtils.getURI(
-                  factory.getServiceRoot(), 
handler.getEntity().getEditLink().toASCIIString() + "/$value");
+    int startingPos = pos;
 
-          batchUpdateMediaEntity(handler, targetURI, 
handler.getStreamChanges(), changeset);
+    if (handler.getEntity().isMediaEntity()) {
 
-          // update media info (use null key)
-          pos++;
-          items.put(null, pos);
-        }
+      // update media properties
+      if (!handler.getPropertyChanges().isEmpty()) {
+        final URI targetURI = currentStatus == AttachedEntityStatus.NEW
+                ? URI.create("$" + startingPos)
+                : URIUtils.getURI(factory.getServiceRoot(), 
handler.getEntity().getEditLink().toASCIIString());
+        batchUpdate(handler, targetURI, entity, changeset);
+        pos++;
+        items.put(handler, pos);
       }
 
-      for (Map.Entry<String, InputStream> streamedChanges : 
handler.getStreamedPropertyChanges().entrySet()) {
+      // update media content
+      if (handler.getStreamChanges() != null) {
         final URI targetURI = currentStatus == AttachedEntityStatus.NEW
-                ? URI.create("$" + startingPos) : URIUtils.getURI(
-                factory.getServiceRoot(),
-                CoreUtils.getMediaEditLink(streamedChanges.getKey(), 
entity).toASCIIString());
+                ? URI.create("$" + startingPos + "/$value")
+                : URIUtils.getURI(
+                factory.getServiceRoot(), 
handler.getEntity().getEditLink().toASCIIString() + "/$value");
 
-        batchUpdateMediaResource(handler, targetURI, 
streamedChanges.getValue(), changeset);
+        batchUpdateMediaEntity(handler, targetURI, handler.getStreamChanges(), 
changeset);
 
         // update media info (use null key)
         pos++;
-        items.put(handler, pos);
+        items.put(null, pos);
       }
     }
 
+    for (Map.Entry<String, InputStream> streamedChanges : 
handler.getStreamedPropertyChanges().entrySet()) {
+      final URI targetURI = currentStatus == AttachedEntityStatus.NEW
+              ? URI.create("$" + startingPos) : URIUtils.getURI(
+              factory.getServiceRoot(),
+              CoreUtils.getEditMediaLink(streamedChanges.getKey(), 
entity).toASCIIString());
+
+      batchUpdateMediaResource(handler, targetURI, streamedChanges.getValue(), 
changeset);
+
+      // update media info (use null key)
+      pos++;
+      items.put(handler, pos);
+    }
+
     return pos;
   }
 
@@ -467,7 +467,7 @@ class ContainerImpl implements Container {
         sourceURI = URI.create("$" + sourcePos);
       }
 
-      for (EntityInvocationHandler target : delayedUpdate.getTargets()) {
+      for (EntityTypeInvocationHandler<?> target : delayedUpdate.getTargets()) 
{
         status = 
EntityContainerFactory.getContext().entityContext().getStatus(target);
 
         final URI targetURI;
@@ -492,11 +492,11 @@ class ContainerImpl implements Container {
 
   private class TransactionItems {
 
-    private final List<EntityInvocationHandler> keys = new 
ArrayList<EntityInvocationHandler>();
+    private final List<EntityTypeInvocationHandler<?>> keys = new 
ArrayList<EntityTypeInvocationHandler<?>>();
 
     private final List<Integer> values = new ArrayList<Integer>();
 
-    public EntityInvocationHandler get(final Integer value) {
+    public EntityTypeInvocationHandler<?> get(final Integer value) {
       if (value != null && values.contains(value)) {
         return keys.get(values.indexOf(value));
       } else {
@@ -504,7 +504,7 @@ class ContainerImpl implements Container {
       }
     }
 
-    public Integer get(final EntityInvocationHandler key) {
+    public Integer get(final EntityTypeInvocationHandler<?> key) {
       if (key != null && keys.contains(key)) {
         return values.get(keys.indexOf(key));
       } else {
@@ -512,14 +512,14 @@ class ContainerImpl implements Container {
       }
     }
 
-    public void remove(final EntityInvocationHandler key) {
+    public void remove(final EntityTypeInvocationHandler<?> key) {
       if (keys.contains(key)) {
         values.remove(keys.indexOf(key));
         keys.remove(key);
       }
     }
 
-    public void put(final EntityInvocationHandler key, final Integer value) {
+    public void put(final EntityTypeInvocationHandler<?> key, final Integer 
value) {
       // replace just in case of null current value; otherwise add the new 
entry
       if (key != null && keys.contains(key) && values.get(keys.indexOf(key)) 
== null) {
         remove(key);
@@ -534,7 +534,7 @@ class ContainerImpl implements Container {
       return sortedValues;
     }
 
-    public boolean contains(final EntityInvocationHandler key) {
+    public boolean contains(final EntityTypeInvocationHandler<?> key) {
       return keys.contains(key);
     }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2e06947b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
----------------------------------------------------------------------
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 6e70a0e..10c68f2 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,37 +33,34 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
 import 
org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest;
 import 
org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
 import org.apache.olingo.client.api.uri.CommonURIBuilder;
-import org.apache.olingo.client.api.v3.UnsupportedInV3Exception;
-import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
 import org.apache.olingo.client.api.v4.ODataClient;
 import org.apache.olingo.commons.api.domain.CommonODataEntity;
 import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
 import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
 import org.apache.olingo.commons.api.format.ODataValueFormat;
 import org.apache.olingo.ext.proxy.EntityContainerFactory;
 import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
 import org.apache.olingo.ext.proxy.api.AbstractEntitySet;
-import org.apache.olingo.ext.proxy.api.AbstractSingleton;
-import org.apache.olingo.ext.proxy.api.Filter;
-import org.apache.olingo.ext.proxy.api.Search;
+import org.apache.olingo.ext.proxy.api.Query;
 import org.apache.olingo.ext.proxy.api.annotations.CompoundKey;
 import org.apache.olingo.ext.proxy.api.annotations.CompoundKeyElement;
 import org.apache.olingo.ext.proxy.api.annotations.EntitySet;
+import org.apache.olingo.ext.proxy.api.annotations.EntityType;
+import org.apache.olingo.ext.proxy.api.annotations.Singleton;
 import org.apache.olingo.ext.proxy.context.AttachedEntityStatus;
 import org.apache.olingo.ext.proxy.context.EntityContext;
 import org.apache.olingo.ext.proxy.context.EntityUUID;
 import org.apache.olingo.ext.proxy.utils.ClassUtils;
-import org.apache.olingo.ext.proxy.utils.CoreUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-class EntitySetInvocationHandler<
-        T extends Serializable, KEY extends Serializable, EC extends 
AbstractEntityCollection<T>>
-        extends AbstractInvocationHandler
+class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T 
extends Serializable, 
+        KEY extends Serializable, EC extends AbstractEntityCollection<T>>
+        extends AbstractInvocationHandler<C>
         implements AbstractEntitySet<T, KEY, EC> {
 
   private static final long serialVersionUID = 2629912294765040027L;
@@ -73,67 +70,79 @@ class EntitySetInvocationHandler<
    */
   private static final Logger LOG = 
LoggerFactory.getLogger(EntitySetInvocationHandler.class);
 
-  private final boolean isSingleton;
-
   private final Class<T> typeRef;
 
   private final Class<EC> collTypeRef;
 
-  private final URI uri;
+  private final String entitySetName;
 
-  @SuppressWarnings({"rawtypes", "unchecked"})
-  static EntitySetInvocationHandler getInstance(
-          final Class<?> ref, final EntityContainerInvocationHandler 
containerHandler, final String entitySetName) {
-
-    final CommonURIBuilder<?> uriBuilder = containerHandler.getClient().
-            getURIBuilder(containerHandler.getFactory().getServiceRoot());
-
-    final StringBuilder entitySetSegment = new StringBuilder();
-    if (!containerHandler.isDefaultEntityContainer()) {
-      
entitySetSegment.append(containerHandler.getEntityContainerName()).append('.');
-    }
-    entitySetSegment.append(entitySetName);
+  private final URI uri;
 
-    uriBuilder.appendEntitySetSegment(entitySetSegment.toString());
-
-    return new EntitySetInvocationHandler(ref, containerHandler, 
entitySetName, uriBuilder.build());
-  }
+  private boolean isSingleton = false;
 
   @SuppressWarnings({"rawtypes", "unchecked"})
   static EntitySetInvocationHandler getInstance(
-          final Class<?> ref, final EntityContainerInvocationHandler 
containerHandler, final URI uri) {
+          final Class<?> ref, final EntityContainerInvocationHandler 
containerHandler) {
 
-    return new EntitySetInvocationHandler(ref, containerHandler, 
(ref.getAnnotation(EntitySet.class)).name(), uri);
+    return new EntitySetInvocationHandler(ref, containerHandler);
   }
 
   @SuppressWarnings("unchecked")
-  protected EntitySetInvocationHandler(
+  private EntitySetInvocationHandler(
           final Class<?> ref,
-          final EntityContainerInvocationHandler containerHandler,
-          final String entitySetName,
-          final URI uri) {
+          final EntityContainerInvocationHandler<C> containerHandler) {
 
     super(containerHandler.getClient(), containerHandler);
 
-    this.isSingleton = AbstractSingleton.class.isAssignableFrom(ref);
+    Annotation annotation = ref.getAnnotation(EntitySet.class);
+    if (annotation == null) {
+      annotation = ref.getAnnotation(Singleton.class);
 
-    final Type[] entitySetParams = ((ParameterizedType) 
ref.getGenericInterfaces()[0]).getActualTypeArguments();
+      if (annotation == null) {
+        throw new IllegalArgumentException("Return type " + ref.getName()
+                + " is not annotated as @" + EntitySet.class.getSimpleName());
+      }
 
-    this.typeRef = (Class<T>) entitySetParams[0];
-    this.collTypeRef = (Class<EC>) entitySetParams[2];
+      this.entitySetName = ((Singleton) annotation).name();
+      isSingleton = true;
+    } else {
+      this.entitySetName = ((EntitySet) annotation).name();
+    }
+
+    final Type[] abstractEntitySetParams =
+            ((ParameterizedType) 
ref.getGenericInterfaces()[0]).getActualTypeArguments();
+
+    this.typeRef = (Class<T>) abstractEntitySetParams[0];
+    if (typeRef.getAnnotation(EntityType.class) == null) {
+      throw new IllegalArgumentException("Invalid entity '" + 
typeRef.getSimpleName() + "'");
+    }
+    this.collTypeRef = (Class<EC>) abstractEntitySetParams[2];
+
+    final CommonURIBuilder<?> uriBuilder = 
client.getURIBuilder(containerHandler.getFactory().getServiceRoot());
+
+    final StringBuilder entitySetSegment = new StringBuilder();
+    if (!containerHandler.isDefaultEntityContainer()) {
+      
entitySetSegment.append(containerHandler.getEntityContainerName()).append('.');
+    }
+    entitySetSegment.append(entitySetName);
 
-    this.uri = uri;
+    uriBuilder.appendEntitySetSegment(entitySetSegment.toString());
+    this.uri = uriBuilder.build();
   }
 
-  protected Class<T> getTypeRef() {
+  Class<T> getTypeRef() {
     return typeRef;
   }
 
-  protected Class<EC> getCollTypeRef() {
+  Class<EC> getCollTypeRef() {
     return collTypeRef;
   }
 
-  protected URI getEntitySetURI() {
+  String getEntitySetName() {
+    return entitySetName;
+  }
+
+  URI getUri() {
     return uri;
   }
 
@@ -149,7 +158,7 @@ class EntitySetInvocationHandler<
         return newEntity(method.getReturnType());
       }
     } else {
-      throw new NoSuchMethodException(method.getName());
+      throw new UnsupportedOperationException("Method not found: " + method);
     }
   }
 
@@ -158,8 +167,8 @@ class EntitySetInvocationHandler<
     final CommonODataEntity entity = client.getObjectFactory().newEntity(
             new FullQualifiedName(containerHandler.getSchemaName(), 
ClassUtils.getEntityTypeName(reference)));
 
-    final EntityInvocationHandler handler =
-            EntityInvocationHandler.getInstance(null, entity, uri, reference, 
containerHandler);
+    final EntityTypeInvocationHandler<?> handler =
+            EntityTypeInvocationHandler.getInstance(entity, entitySetName, 
reference, containerHandler);
     EntityContainerFactory.getContext().entityContext().attachNew(handler);
 
     return (NE) Proxy.newProxyInstance(
@@ -173,15 +182,27 @@ class EntitySetInvocationHandler<
     return (NEC) Proxy.newProxyInstance(
             Thread.currentThread().getContextClassLoader(),
             new Class<?>[] {reference},
-            new EntityCollectionInvocationHandler<T>(containerHandler, new 
ArrayList<T>(), typeRef));
+            new EntityCollectionInvocationHandler<T, C>(
+            containerHandler, new ArrayList<T>(), typeRef, 
containerHandler.getEntityContainerName()));
   }
 
   @Override
   public Long count() {
-    final ODataValueRequest req = client.getRetrieveRequestFactory().
-            
getValueRequest(client.getURIBuilder(this.uri.toASCIIString()).count().build());
-    req.setFormat(ODataValueFormat.TEXT);
-    return Long.valueOf(req.execute().getBody().asPrimitive().toString());
+    if (isSingleton) {
+      final 
ODataRetrieveResponse<org.apache.olingo.commons.api.domain.v4.Singleton> res =
+              ((ODataClient) 
client).getRetrieveRequestFactory().getSingletonRequest(uri).execute();
+
+      if (res.getBody() == null) {
+        return 0l;
+      } else {
+        return 1l;
+      }
+    } else {
+      final ODataValueRequest req = client.getRetrieveRequestFactory().
+              
getValueRequest(client.getURIBuilder(this.uri.toASCIIString()).count().build());
+      req.setFormat(ODataValueFormat.TEXT);
+      return Long.valueOf(req.execute().getBody().asPrimitive().toString());
+    }
   }
 
   @Override
@@ -191,13 +212,13 @@ class EntitySetInvocationHandler<
     try {
       result = get(key) != null;
     } catch (Exception e) {
-      LOG.error("Could not check existence of {}({})", this.uri, key, e);
+      LOG.error("Could not check existence of {}({})", this.entitySetName, 
key, e);
     }
 
     return result;
   }
 
-  private Map<String, Object> getCompoundKey(final Object key) {
+  private LinkedHashMap<String, Object> getCompoundKey(final Object key) {
     final Set<CompoundKeyElementWrapper> elements = new 
TreeSet<CompoundKeyElementWrapper>();
 
     for (Method method : key.getClass().getMethods()) {
@@ -233,10 +254,11 @@ class EntitySetInvocationHandler<
       throw new IllegalArgumentException("Null key");
     }
 
-    final EntityUUID uuid = new 
EntityUUID(containerHandler.getEntityContainerName(), uri, typeRef, key);
+    final EntityUUID uuid = new 
EntityUUID(containerHandler.getEntityContainerName(), entitySetName, typeRef, 
key);
     LOG.debug("Ask for '{}({})'", typeRef.getSimpleName(), key);
 
-    EntityInvocationHandler handler = 
EntityContainerFactory.getContext().entityContext().getEntity(uuid);
+    EntityTypeInvocationHandler<?> handler =
+            
EntityContainerFactory.getContext().entityContext().getEntity(uuid);
 
     if (handler == null) {
       // not yet attached: search against the service
@@ -252,26 +274,19 @@ class EntitySetInvocationHandler<
           uriBuilder.appendKeySegment(getCompoundKey(key));
         }
 
-        LOG.debug("GET {}", uriBuilder.toString());
+        LOG.debug("Execute query '{}'", uriBuilder.toString());
 
         final ODataRetrieveResponse<CommonODataEntity> res =
                 
client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()).execute();
 
-        final String etag = res.getETag();
-        final CommonODataEntity entity = res.getBody();
-
-        if (entity == null || !key.equals(CoreUtils.getKey(client, typeRef, 
entity))) {
-          throw new IllegalArgumentException("Invalid " + 
typeRef.getSimpleName() + "(" + key + ")");
-        }
-
-        handler = EntityInvocationHandler.getInstance(uriBuilder.build(), 
entity, this, typeRef);
-        handler.setETag(etag);
+        handler = EntityTypeInvocationHandler.getInstance(res.getBody(), this, 
typeRef);
+        handler.setETag(res.getETag());
       } catch (Exception e) {
         LOG.info("Entity '" + uuid + "' not found", e);
       }
     } else if (isDeleted(handler)) {
       // object deleted
-      LOG.debug("Object '{}({})' has been deleted", typeRef.getSimpleName(), 
uuid);
+      LOG.debug("Object '{}({})' has been delete", typeRef.getSimpleName(), 
uuid);
       handler = null;
     }
 
@@ -304,10 +319,9 @@ class EntitySetInvocationHandler<
     final List<S> items = new ArrayList<S>(entities.size());
 
     for (CommonODataEntity entity : entities) {
-      final EntityInvocationHandler handler =
-              EntityInvocationHandler.getInstance(entity.getEditLink(), 
entity, this, typeRef);
+      final EntityTypeInvocationHandler<?> handler = 
EntityTypeInvocationHandler.getInstance(entity, this, typeRef);
 
-      final EntityInvocationHandler handlerInTheContext =
+      final EntityTypeInvocationHandler<?> handlerInTheContext =
               
EntityContainerFactory.getContext().entityContext().getEntity(handler.getUUID());
 
       items.add((S) Proxy.newProxyInstance(
@@ -335,7 +349,8 @@ class EntitySetInvocationHandler<
     return (SEC) Proxy.newProxyInstance(
             Thread.currentThread().getContextClassLoader(),
             new Class<?>[] {collTypeRef},
-            new EntityCollectionInvocationHandler<S>(containerHandler, items, 
typeRef, entitySetURI));
+            new EntityCollectionInvocationHandler<S, C>(
+            containerHandler, items, typeRef, 
containerHandler.getEntityContainerName(), entitySetURI));
   }
 
   @Override
@@ -363,53 +378,31 @@ class EntitySetInvocationHandler<
   }
 
   @Override
-  public Filter<T, EC> createFilter() {
-    return new FilterImpl<T, EC>(this.client, this.collTypeRef, this.uri, 
this);
+  public Query<T, EC> createQuery() {
+    return new QueryImpl<T, EC>(this.client, this.collTypeRef, this.uri, this);
   }
 
   @Override
-  @SuppressWarnings("unchecked")
-  public <S extends T, SEC extends AbstractEntityCollection<S>> Filter<S, SEC> 
createFilter(
+  public <S extends T, SEC extends AbstractEntityCollection<S>> Query<S, SEC> 
createQuery(
           final Class<SEC> reference) {
 
-    return new FilterImpl<S, SEC>(
-            this.client, reference, this.uri, (EntitySetInvocationHandler<S, 
?, SEC>) this);
-  }
-
-  @Override
-  public Search<T, EC> createSearch() {
-    if (client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) {
-      throw new UnsupportedInV3Exception();
-    }
-    return new SearchImpl<T, EC>((EdmEnabledODataClient) this.client, 
this.collTypeRef, this.uri, this);
-  }
-
-  @Override
-  @SuppressWarnings("unchecked")
-  public <S extends T, SEC extends AbstractEntityCollection<S>> Search<S, SEC> 
createSearch(
-          final Class<SEC> reference) {
-
-    if (client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) {
-      throw new UnsupportedInV3Exception();
-    }
-    return new SearchImpl<S, SEC>(
-            (EdmEnabledODataClient) this.client, reference, this.uri, 
(EntitySetInvocationHandler<S, ?, SEC>) this);
+    return new QueryImpl<S, SEC>(this.client, reference, this.uri, this);
   }
 
   @Override
   public void delete(final KEY key) throws IllegalArgumentException {
     final EntityContext entityContext = 
EntityContainerFactory.getContext().entityContext();
 
-    EntityInvocationHandler entity = entityContext.getEntity(new EntityUUID(
+    EntityTypeInvocationHandler<?> entity = entityContext.getEntity(new 
EntityUUID(
             containerHandler.getEntityContainerName(),
-            uri,
+            entitySetName,
             typeRef,
             key));
 
     if (entity == null) {
       // search for entity
       final T searched = get(key);
-      entity = (EntityInvocationHandler) Proxy.getInvocationHandler(searched);
+      entity = (EntityTypeInvocationHandler<?>) 
Proxy.getInvocationHandler(searched);
       entityContext.attach(entity, AttachedEntityStatus.DELETED);
     } else {
       entityContext.setStatus(entity, AttachedEntityStatus.DELETED);
@@ -421,7 +414,7 @@ class EntitySetInvocationHandler<
     final EntityContext entityContext = 
EntityContainerFactory.getContext().entityContext();
 
     for (T en : entities) {
-      final EntityInvocationHandler entity = (EntityInvocationHandler) 
Proxy.getInvocationHandler(en);
+      final EntityTypeInvocationHandler<?> entity = 
(EntityTypeInvocationHandler<?>) Proxy.getInvocationHandler(en);
       if (entityContext.isAttached(entity)) {
         entityContext.setStatus(entity, AttachedEntityStatus.DELETED);
       } else {
@@ -430,7 +423,7 @@ class EntitySetInvocationHandler<
     }
   }
 
-  private boolean isDeleted(final EntityInvocationHandler handler) {
+  private boolean isDeleted(final EntityTypeInvocationHandler<?> handler) {
     return 
EntityContainerFactory.getContext().entityContext().getStatus(handler) == 
AttachedEntityStatus.DELETED;
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2e06947b/fit/src/main/java/org/apache/olingo/fit/V4Services.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V4Services.java 
b/fit/src/main/java/org/apache/olingo/fit/V4Services.java
index 9487d1e..0bd689d 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V4Services.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V4Services.java
@@ -112,7 +112,7 @@ public class V4Services extends AbstractServices {
   protected V4Services(final Metadata metadata) throws Exception {
     super(ODataServiceVersion.V40, metadata);
   }
-
+  
   @GET
   @Path("/$crossjoin({elements:.*})")
   public Response crossjoin(

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2e06947b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
----------------------------------------------------------------------
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 de9cdc3..e9afca9 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
@@ -26,17 +26,19 @@ import static org.junit.Assert.assertNotNull;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
-import org.apache.olingo.client.api.v3.EdmEnabledODataClient;
 import org.apache.olingo.commons.api.format.ContentType;
 import org.apache.olingo.ext.proxy.EntityContainerFactory;
 import org.apache.olingo.ext.proxy.context.EntityContext;
 import 
org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.
         DefaultContainer;
-import 
org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.
-        ContactDetails;
-import 
org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Customer;
-import 
org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Aliases;
-import 
org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Phone;
+import 
org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.
+        types.ContactDetails;
+import 
org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.
+        types.Customer;
+import 
org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.
+        types.Aliases;
+import 
org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.
+        types.Phone;
 
 import org.junit.BeforeClass;
 import org.slf4j.Logger;
@@ -53,8 +55,6 @@ public abstract class AbstractTestITCase {
 
   protected static String testStaticServiceRootURL;
 
-  protected static String testPrimitiveKeysServiceRootURL;
-
   protected static String testKeyAsSegmentServiceRootURL;
 
   protected static String testActionOverloadingServiceRootURL;
@@ -67,14 +67,13 @@ public abstract class AbstractTestITCase {
 
   protected final EntityContext entityContext = 
EntityContainerFactory.getContext().entityContext();
 
-  protected static EntityContainerFactory<EdmEnabledODataClient> 
containerFactory;
+  protected static EntityContainerFactory containerFactory;
 
   protected static DefaultContainer container;
 
   @BeforeClass
   public static void setUpODataServiceRoot() throws IOException {
     testStaticServiceRootURL = 
"http://localhost:9080/stub/StaticService/V30/Static.svc";;
-    testPrimitiveKeysServiceRootURL = 
"http://localhost:9080/stub/StaticService/V30/PrimitiveKeys.svc";;
     testKeyAsSegmentServiceRootURL = 
"http://localhost:9080/stub/StaticService/V30/KeyAsSegment.svc";;
     testActionOverloadingServiceRootURL = 
"http://localhost:9080/stub/StaticService/V30/ActionOverloading.svc";;
     testOpenTypeServiceRootURL = 
"http://localhost:9080/stub/StaticService/V30/OpenType.svc";;
@@ -82,10 +81,9 @@ public abstract class AbstractTestITCase {
     testAuthServiceRootURL = "http://localhost:9080/stub/DefaultService.svc";;
 
     containerFactory = EntityContainerFactory.getV3(testStaticServiceRootURL);
-    
containerFactory.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
+    
containerFactory.getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
     container = containerFactory.getEntityContainer(DefaultContainer.class);
     assertNotNull(container);
-    EntityContainerFactory.getContext().detachAll();
   }
 
   protected Customer getSampleCustomerProfile(

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2e06947b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AbstractTestITCase.java
----------------------------------------------------------------------
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 4efc7d0..cdf503f 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
@@ -18,22 +18,15 @@
  */
 package org.apache.olingo.fit.proxy.v4;
 
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertEquals;
 
 import java.io.IOException;
-import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.TimeZone;
-import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
 import org.apache.olingo.commons.api.format.ContentType;
 import org.apache.olingo.ext.proxy.EntityContainerFactory;
 import org.apache.olingo.ext.proxy.context.EntityContext;
 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;
 import org.junit.BeforeClass;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,8 +42,6 @@ public abstract class AbstractTestITCase {
 
   protected static String testStaticServiceRootURL;
 
-  protected static String testDemoServiceRootURL;
-
   protected static String testKeyAsSegmentServiceRootURL;
 
   protected static String testActionOverloadingServiceRootURL;
@@ -63,14 +54,13 @@ public abstract class AbstractTestITCase {
 
   protected final EntityContext entityContext = 
EntityContainerFactory.getContext().entityContext();
 
-  protected static EntityContainerFactory<EdmEnabledODataClient> 
containerFactory;
+  protected static EntityContainerFactory containerFactory;
 
   protected static InMemoryEntities container;
 
   @BeforeClass
   public static void setUpODataServiceRoot() throws IOException {
     testStaticServiceRootURL = 
"http://localhost:9080/stub/StaticService/V40/Static.svc";;
-    testDemoServiceRootURL = 
"http://localhost:9080/stub/StaticService/V40/Demo.svc";;
     testKeyAsSegmentServiceRootURL = 
"http://localhost:9080/stub/StaticService/V40/KeyAsSegment.svc";;
     testActionOverloadingServiceRootURL = 
"http://localhost:9080/stub/StaticService/V40/ActionOverloading.svc";;
     testOpenTypeServiceRootURL = 
"http://localhost:9080/stub/StaticService/V40/OpenType.svc";;
@@ -78,10 +68,9 @@ public abstract class AbstractTestITCase {
     testAuthServiceRootURL = "http://localhost:9080/stub/DefaultService.svc";;
 
     containerFactory = EntityContainerFactory.getV4(testStaticServiceRootURL);
-    
containerFactory.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
+    
containerFactory.getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
     container = containerFactory.getEntityContainer(InMemoryEntities.class);
     assertNotNull(container);
-    EntityContainerFactory.getContext().detachAll();
   }
 
   protected Customer readCustomer(final InMemoryEntities container, int id) {
@@ -91,43 +80,4 @@ public abstract class AbstractTestITCase {
 
     return customer;
   }
-
-  protected void createAndDeleteOrder(final InMemoryEntities container) {
-    final Order order = container.getOrders().newOrder();
-    order.setOrderID(105);
-
-    final Calendar orderDate = 
Calendar.getInstance(TimeZone.getTimeZone("GMT"));
-    orderDate.clear();
-    orderDate.set(2011, 3, 4, 16, 3, 57);
-    order.setOrderDate(orderDate);
-
-    order.setShelfLife(BigDecimal.TEN);
-    order.setOrderShelfLifes(Arrays.asList(new BigDecimal[] 
{BigDecimal.TEN.negate(), BigDecimal.TEN}));
-
-    container.flush();
-
-    Order actual = container.getOrders().get(105);
-    assertEquals(105, actual.getOrderID(), 0);
-    assertEquals(orderDate.getTimeInMillis(), 
actual.getOrderDate().getTimeInMillis());
-    assertEquals(BigDecimal.TEN, actual.getShelfLife());
-    assertEquals(2, actual.getOrderShelfLifes().size());
-
-    container.getOrders().delete(105);
-    actual = container.getOrders().get(105);
-    assertNull(actual);
-
-    entityContext.detachAll();
-    actual = container.getOrders().get(105);
-    assertNotNull(actual);
-
-    container.getOrders().delete(105);
-    actual = container.getOrders().get(105);
-    assertNull(actual);
-
-    container.flush();
-
-    entityContext.detachAll();
-    actual = container.getOrders().get(105);
-    assertNull(actual);
-  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2e06947b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java
----------------------------------------------------------------------
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 aee3127..cbacd6e 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
@@ -18,34 +18,25 @@
  */
 package org.apache.olingo.fit.proxy.v4;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
 import java.math.BigDecimal;
 import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Collections;
 import java.util.TimeZone;
-import org.apache.commons.lang3.RandomUtils;
-import 
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.AccessLevel;
+import org.apache.olingo.commons.api.edm.geo.Geospatial;
+import org.apache.olingo.commons.api.edm.geo.Point;
 import 
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Address;
-import 
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Color;
 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.Employee;
 import 
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Order;
 import 
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.OrderCollection;
 import 
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.OrderDetail;
 import 
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.OrderDetailKey;
-import 
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.
-        PaymentInstrument;
-import 
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.
-        PaymentInstrumentCollection;
-import 
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Product;
-import 
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.ProductDetail;
-import 
org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.
-        ProductDetailCollection;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
 import org.junit.Test;
 
 /**
@@ -54,8 +45,43 @@ import org.junit.Test;
 public class EntityCreateTestITCase extends AbstractTestITCase {
 
   @Test
-  public void createAndDelete() {
-    createAndDeleteOrder(container);
+  public void create() {
+    final Order order = container.getOrders().newOrder();
+    order.setOrderID(105);
+
+    final Calendar orderDate = 
Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+    orderDate.clear();
+    orderDate.set(2011, 3, 4, 16, 3, 57);
+    order.setOrderDate(orderDate);
+
+    order.setShelfLife(BigDecimal.TEN);
+    order.setOrderShelfLifes(Arrays.asList(new BigDecimal[] 
{BigDecimal.TEN.negate(), BigDecimal.TEN}));
+
+    container.flush();
+
+    Order actual = container.getOrders().get(105);
+    assertEquals(105, actual.getOrderID(), 0);
+    assertEquals(orderDate.getTimeInMillis(), 
actual.getOrderDate().getTimeInMillis());
+    assertEquals(BigDecimal.TEN, actual.getShelfLife());
+    assertEquals(2, actual.getOrderShelfLifes().size());
+
+    container.getOrders().delete(105);
+    actual = container.getOrders().get(105);
+    assertNull(actual);
+
+    entityContext.detachAll();
+    actual = container.getOrders().get(105);
+    assertNotNull(actual);
+
+    container.getOrders().delete(105);
+    actual = container.getOrders().get(105);
+    assertNull(actual);
+
+    container.flush();
+
+    entityContext.detachAll();
+    actual = container.getOrders().get(105);
+    assertNull(actual);
   }
 
   @Test
@@ -157,6 +183,7 @@ public class EntityCreateTestITCase extends 
AbstractTestITCase {
     order.setOrderShelfLifes(Arrays.asList(new BigDecimal[] 
{BigDecimal.TEN.negate(), BigDecimal.TEN}));
     // -------------------------------
 
+
     // -------------------------------
     // Create a new customer
     // -------------------------------
@@ -241,63 +268,4 @@ public class EntityCreateTestITCase extends 
AbstractTestITCase {
 
     assertNull(container.getOrderDetails().get(key));
   }
-
-  @Test
-  public void deepInsert() {
-    Product product = container.getProducts().newProduct();
-    product.setProductID(12);
-    product.setName("Latte");
-    product.setQuantityPerUnit("100g Bag");
-    product.setUnitPrice(3.24f);
-    product.setQuantityInStock(100);
-    product.setDiscontinued(false);
-    product.setUserAccess(AccessLevel.Execute);
-    product.setSkinColor(Color.Blue);
-    product.setCoverColors(Arrays.asList(new Color[] {Color.Red, 
Color.Green}));
-
-    final ProductDetail detail = 
container.getProductDetails().newProductDetail();
-    detail.setProductID(product.getProductID());
-    detail.setProductDetailID(12);
-    detail.setProductName("LatteHQ");
-    detail.setDescription("High-Quality Milk");
-
-    final ProductDetailCollection detailCollection = 
container.getProductDetails().newProductDetailCollection();
-    detailCollection.add(detail);
-
-    product.setDetails(detailCollection);
-
-    container.flush();
-
-    product = container.getProducts().get(12);
-    assertEquals("Latte", product.getName());
-    assertEquals(12, 
product.getDetails().iterator().next().getProductDetailID(), 0);
-  }
-
-  @Test
-  public void contained() {
-    PaymentInstrumentCollection instruments = 
container.getAccounts().get(101).getMyPaymentInstruments().getAll();
-    final int sizeBefore = instruments.size();
-
-    final PaymentInstrument instrument = container.getAccounts().get(101).
-            getMyPaymentInstruments().newPaymentInstrument();
-
-    final int id = RandomUtils.nextInt(101999, 105000);
-    instrument.setPaymentInstrumentID(id);
-    instrument.setFriendlyName("New one");
-    instrument.setCreatedDate(Calendar.getInstance());
-
-    container.flush();
-
-    instruments = 
container.getAccounts().get(101).getMyPaymentInstruments().getAll();
-    final int sizeAfter = instruments.size();
-    assertEquals(sizeBefore + 1, sizeAfter);
-
-    container.getAccounts().get(101).getMyPaymentInstruments().delete(id);
-
-    container.flush();
-
-    instruments = 
container.getAccounts().get(101).getMyPaymentInstruments().getAll();
-    final int sizeEnd = instruments.size();
-    assertEquals(sizeBefore, sizeEnd);
-  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2e06947b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/OrderDetail.java
----------------------------------------------------------------------
diff --git 
a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/OrderDetail.java
 
b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/OrderDetail.java
index 15a0b9b..ce4fa9c 100644
--- 
a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/OrderDetail.java
+++ 
b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/staticservice/microsoft/test/odata/services/odatawcfservice/types/OrderDetail.java
@@ -59,8 +59,6 @@ import javax.xml.datatype.Duration;
 public interface OrderDetail 
   extends Serializable {
 
-        
-    @Key
     @Property(name = "OrderID", 
                 type = "Edm.Int32", 
                 nullable = false,

Reply via email to