You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2016/10/24 20:39:15 UTC

[1/3] olingo-odata2 git commit: [OLINGO-1018] Introduced ODataJPADefaultProcessor

Repository: olingo-odata2
Updated Branches:
  refs/heads/master c1b1a60ab -> ed07b2dea


[OLINGO-1018] Introduced ODataJPADefaultProcessor


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/571a10eb
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/571a10eb
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/571a10eb

Branch: refs/heads/master
Commit: 571a10ebeacfa6116f9632533d37b47356f8a3ec
Parents: 0689384
Author: mibo <mi...@apache.org>
Authored: Tue Sep 6 20:28:36 2016 +0200
Committer: mibo <mi...@apache.org>
Committed: Tue Sep 6 20:28:36 2016 +0200

----------------------------------------------------------------------
 .../processor/api/ODataJPADefaultProcessor.java | 297 +++++++++++++++++++
 .../processor/api/ODataJPAServiceFactory.java   |  10 +-
 .../core/ODataJPAProcessorDefault.java          | 283 +-----------------
 .../ref/util/CustomODataJPAProcessor.java       |  57 ++++
 .../ref/web/JPAReferenceServiceFactory.java     |   8 +
 5 files changed, 372 insertions(+), 283 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/571a10eb/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPADefaultProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPADefaultProcessor.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPADefaultProcessor.java
new file mode 100644
index 0000000..ca89e13
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPADefaultProcessor.java
@@ -0,0 +1,297 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api;
+
+import org.apache.olingo.odata2.api.batch.BatchHandler;
+import org.apache.olingo.odata2.api.batch.BatchRequestPart;
+import org.apache.olingo.odata2.api.batch.BatchResponsePart;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.ep.EntityProvider;
+import org.apache.olingo.odata2.api.ep.EntityProviderBatchProperties;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataRequest;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.uri.PathInfo;
+import org.apache.olingo.odata2.api.uri.info.*;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAException;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ODataJPADefaultProcessor extends ODataJPAProcessor {
+
+  public ODataJPADefaultProcessor(final ODataJPAContext oDataJPAContext) {
+    super(oDataJPAContext);
+    if (oDataJPAContext == null) {
+      throw new IllegalArgumentException(ODataJPAException.ODATA_JPACTX_NULL);
+    }
+  }
+
+  @Override
+  public ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType)
+      throws ODataException {
+    ODataResponse oDataResponse = null;
+    try {
+      oDataJPAContext.setODataContext(getContext());
+      List<Object> jpaEntities = jpaProcessor.process(uriParserResultView);
+      oDataResponse =
+          responseBuilder.build(uriParserResultView, jpaEntities, contentType);
+    } finally {
+      close();
+    }
+    return oDataResponse;
+  }
+
+  @Override
+  public ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType)
+      throws ODataException {
+    ODataResponse oDataResponse = null;
+    try {
+      oDataJPAContext.setODataContext(getContext());
+      Object jpaEntity = jpaProcessor.process(uriParserResultView);
+      oDataResponse =
+          responseBuilder.build(uriParserResultView, jpaEntity, contentType);
+    } finally {
+      close();
+    }
+    return oDataResponse;
+  }
+
+  @Override
+  public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType)
+      throws ODataException {
+    ODataResponse oDataResponse = null;
+    try {
+      oDataJPAContext.setODataContext(getContext());
+      long jpaEntityCount = jpaProcessor.process(uriParserResultView);
+      oDataResponse = responseBuilder.build(jpaEntityCount);
+    } finally {
+      close();
+    }
+    return oDataResponse;
+  }
+
+  @Override
+  public ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType)
+      throws ODataException {
+    ODataResponse oDataResponse = null;
+    try {
+      oDataJPAContext.setODataContext(getContext());
+      long jpaEntityCount = jpaProcessor.process(uriInfo);
+      oDataResponse = responseBuilder.build(jpaEntityCount);
+    } finally {
+      close();
+    }
+    return oDataResponse;
+  }
+
+  @Override
+  public ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content,
+      final String requestContentType, final String contentType) throws ODataException {
+    ODataResponse oDataResponse = null;
+    try {
+      oDataJPAContext.setODataContext(getContext());
+      Object createdJpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType);
+      oDataResponse =
+          responseBuilder.build(uriParserResultView, createdJpaEntity, contentType);
+    } finally {
+      close();
+    }
+    return oDataResponse;
+  }
+
+  @Override
+  public ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content,
+      final String requestContentType, final boolean merge, final String contentType) throws ODataException {
+    ODataResponse oDataResponse = null;
+    try {
+      oDataJPAContext.setODataContext(getContext());
+      Object jpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType);
+      oDataResponse = responseBuilder.build(uriParserResultView, jpaEntity);
+    } finally {
+      close();
+    }
+    return oDataResponse;
+  }
+
+  @Override
+  public ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType)
+      throws ODataException {
+    ODataResponse oDataResponse = null;
+    try {
+      oDataJPAContext.setODataContext(getContext());
+      Object deletedObj = jpaProcessor.process(uriParserResultView, contentType);
+      oDataResponse = responseBuilder.build(uriParserResultView, deletedObj);
+    } finally {
+      close();
+    }
+    return oDataResponse;
+  }
+
+  @Override
+  public ODataResponse executeFunctionImport(final GetFunctionImportUriInfo uriParserResultView,
+      final String contentType) throws ODataException {
+    ODataResponse oDataResponse = null;
+    try {
+      oDataJPAContext.setODataContext(getContext());
+      List<Object> resultEntity = jpaProcessor.process(uriParserResultView);
+      oDataResponse =
+          responseBuilder.build(uriParserResultView, resultEntity, contentType);
+    } finally {
+      close();
+    }
+    return oDataResponse;
+  }
+
+  @Override
+  public ODataResponse executeFunctionImportValue(final GetFunctionImportUriInfo uriParserResultView,
+      final String contentType) throws ODataException {
+    ODataResponse oDataResponse = null;
+    try {
+      oDataJPAContext.setODataContext(getContext());
+      List<Object> result = jpaProcessor.process(uriParserResultView);
+      oDataResponse =
+          responseBuilder.build(uriParserResultView, result.get(0));
+    } finally {
+      close();
+    }
+    return oDataResponse;
+  }
+
+  @Override
+  public ODataResponse readEntityLink(final GetEntityLinkUriInfo uriParserResultView, final String contentType)
+      throws ODataException {
+    ODataResponse oDataResponse = null;
+    try {
+      oDataJPAContext.setODataContext(getContext());
+      Object jpaEntity = jpaProcessor.process(uriParserResultView);
+      oDataResponse =
+          responseBuilder.build(uriParserResultView, jpaEntity, contentType);
+    } finally {
+      close();
+    }
+    return oDataResponse;
+  }
+
+  @Override
+  public ODataResponse readEntityLinks(final GetEntitySetLinksUriInfo uriParserResultView, final String contentType)
+      throws ODataException {
+    ODataResponse oDataResponse = null;
+    try {
+      oDataJPAContext.setODataContext(getContext());
+      List<Object> jpaEntity = jpaProcessor.process(uriParserResultView);
+      oDataResponse =
+          responseBuilder.build(uriParserResultView, jpaEntity, contentType);
+    } finally {
+      close();
+    }
+    return oDataResponse;
+  }
+
+  @Override
+  public ODataResponse createEntityLink(final PostUriInfo uriParserResultView, final InputStream content,
+      final String requestContentType, final String contentType) throws ODataException {
+    try {
+      oDataJPAContext.setODataContext(getContext());
+      jpaProcessor.process(uriParserResultView, content, requestContentType, contentType);
+      return ODataResponse.newBuilder().build();
+    } finally {
+      close();
+    }
+  }
+
+  @Override
+  public ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content,
+      final String requestContentType, final String contentType) throws ODataException {
+    try {
+      oDataJPAContext.setODataContext(getContext());
+      jpaProcessor.process(uriParserResultView, content, requestContentType, contentType);
+      return ODataResponse.newBuilder().build();
+    } finally {
+      close();
+    }
+  }
+
+  @Override
+  public ODataResponse deleteEntityLink(final DeleteUriInfo uriParserResultView, final String contentType)
+      throws ODataException {
+    try {
+      oDataJPAContext.setODataContext(getContext());
+      jpaProcessor.process(uriParserResultView, contentType);
+      return ODataResponse.newBuilder().build();
+    } finally {
+      close();
+    }
+  }
+
+  @Override
+  public ODataResponse executeBatch(final BatchHandler handler, final String contentType, final InputStream content)
+      throws ODataException {
+    try {
+      oDataJPAContext.setODataContext(getContext());
+
+      ODataResponse batchResponse;
+      List<BatchResponsePart> batchResponseParts = new ArrayList<BatchResponsePart>();
+      PathInfo pathInfo = getContext().getPathInfo();
+      EntityProviderBatchProperties batchProperties = EntityProviderBatchProperties.init().pathInfo(pathInfo).build();
+      List<BatchRequestPart> batchParts = EntityProvider.parseBatchRequest(contentType, content, batchProperties);
+
+      for (BatchRequestPart batchPart : batchParts) {
+        batchResponseParts.add(handler.handleBatchPart(batchPart));
+      }
+      batchResponse = EntityProvider.writeBatchResponse(batchResponseParts);
+      return batchResponse;
+    } finally {
+      close(true);
+    }
+  }
+
+  @Override
+  public BatchResponsePart executeChangeSet(final BatchHandler handler, final List<ODataRequest> requests)
+      throws ODataException {
+    List<ODataResponse> responses = new ArrayList<ODataResponse>();
+    try {
+      oDataJPAContext.getODataJPATransaction().begin();
+
+      for (ODataRequest request : requests) {
+        oDataJPAContext.setODataContext(getContext());
+        ODataResponse response = handler.handleRequest(request);
+        if (response.getStatus().getStatusCode() >= HttpStatusCodes.BAD_REQUEST.getStatusCode()) {
+          // Rollback
+          oDataJPAContext.getODataJPATransaction().rollback();
+          List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1);
+          errorResponses.add(response);
+          return BatchResponsePart.responses(errorResponses).changeSet(false).build();
+        }
+        responses.add(response);
+      }
+      oDataJPAContext.getODataJPATransaction().commit();
+
+      return BatchResponsePart.responses(responses).changeSet(true).build();
+    } catch (Exception e) {
+
+      List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1);
+      errorResponses.add(ODataResponse.entity(e).status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build());
+      return BatchResponsePart.responses(errorResponses).changeSet(false).build();
+    } finally {
+      close(true);
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/571a10eb/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java
index 5566ada..64444b5 100644
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java
@@ -134,14 +134,20 @@ public abstract class ODataJPAServiceFactory extends ODataServiceFactory {
       oDataJPAContext.setODataContext(ctx);
     }
 
-    ODataSingleProcessor odataJPAProcessor = accessFactory.createODataProcessor(oDataJPAContext);
-
+    ODataSingleProcessor odataJPAProcessor = createCustomODataProcessor(oDataJPAContext);
+    if(odataJPAProcessor == null) {
+      odataJPAProcessor = accessFactory.createODataProcessor(oDataJPAContext);
+    }
     // OData Entity Data Model Provider based on JPA
     EdmProvider edmProvider = accessFactory.createJPAEdmProvider(oDataJPAContext);
 
     return createODataSingleProcessorService(edmProvider, odataJPAProcessor);
   }
 
+  public ODataSingleProcessor createCustomODataProcessor(ODataJPAContext oDataJPAContext) {
+    return null;
+  }
+
   /**
    * @return an instance of type {@link ODataJPAContext}
    * @throws ODataJPARuntimeException

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/571a10eb/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
index c09864e..8daf88e 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
@@ -18,291 +18,12 @@
  ******************************************************************************/
 package org.apache.olingo.odata2.jpa.processor.core;
 
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.batch.BatchHandler;
-import org.apache.olingo.odata2.api.batch.BatchRequestPart;
-import org.apache.olingo.odata2.api.batch.BatchResponsePart;
-import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
-import org.apache.olingo.odata2.api.ep.EntityProvider;
-import org.apache.olingo.odata2.api.ep.EntityProviderBatchProperties;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.processor.ODataRequest;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.uri.PathInfo;
-import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
 import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
-import org.apache.olingo.odata2.jpa.processor.api.ODataJPAProcessor;
-import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAException;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPADefaultProcessor;
 
-public class ODataJPAProcessorDefault extends ODataJPAProcessor {
+public class ODataJPAProcessorDefault extends ODataJPADefaultProcessor {
 
   public ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext) {
     super(oDataJPAContext);
-    if (oDataJPAContext == null) {
-      throw new IllegalArgumentException(ODataJPAException.ODATA_JPACTX_NULL);
-    }
-  }
-
-  @Override
-  public ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType)
-      throws ODataException {
-    ODataResponse oDataResponse = null;
-    try {
-      oDataJPAContext.setODataContext(getContext());
-      List<Object> jpaEntities = jpaProcessor.process(uriParserResultView);
-      oDataResponse =
-          responseBuilder.build(uriParserResultView, jpaEntities, contentType);
-    } finally {
-      close();
-    }
-    return oDataResponse;
-  }
-
-  @Override
-  public ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType)
-      throws ODataException {
-    ODataResponse oDataResponse = null;
-    try {
-      oDataJPAContext.setODataContext(getContext());
-      Object jpaEntity = jpaProcessor.process(uriParserResultView);
-      oDataResponse =
-          responseBuilder.build(uriParserResultView, jpaEntity, contentType);
-    } finally {
-      close();
-    }
-    return oDataResponse;
-  }
-
-  @Override
-  public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType)
-      throws ODataException {
-    ODataResponse oDataResponse = null;
-    try {
-      oDataJPAContext.setODataContext(getContext());
-      long jpaEntityCount = jpaProcessor.process(uriParserResultView);
-      oDataResponse = responseBuilder.build(jpaEntityCount);
-    } finally {
-      close();
-    }
-    return oDataResponse;
-  }
-
-  @Override
-  public ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType)
-      throws ODataException {
-    ODataResponse oDataResponse = null;
-    try {
-      oDataJPAContext.setODataContext(getContext());
-      long jpaEntityCount = jpaProcessor.process(uriInfo);
-      oDataResponse = responseBuilder.build(jpaEntityCount);
-    } finally {
-      close();
-    }
-    return oDataResponse;
-  }
-
-  @Override
-  public ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content,
-      final String requestContentType, final String contentType) throws ODataException {
-    ODataResponse oDataResponse = null;
-    try {
-      oDataJPAContext.setODataContext(getContext());
-      Object createdJpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType);
-      oDataResponse =
-          responseBuilder.build(uriParserResultView, createdJpaEntity, contentType);
-    } finally {
-      close();
-    }
-    return oDataResponse;
-  }
-
-  @Override
-  public ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content,
-      final String requestContentType, final boolean merge, final String contentType) throws ODataException {
-    ODataResponse oDataResponse = null;
-    try {
-      oDataJPAContext.setODataContext(getContext());
-      Object jpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType);
-      oDataResponse = responseBuilder.build(uriParserResultView, jpaEntity);
-    } finally {
-      close();
-    }
-    return oDataResponse;
-  }
-
-  @Override
-  public ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType)
-      throws ODataException {
-    ODataResponse oDataResponse = null;
-    try {
-      oDataJPAContext.setODataContext(getContext());
-      Object deletedObj = jpaProcessor.process(uriParserResultView, contentType);
-      oDataResponse = responseBuilder.build(uriParserResultView, deletedObj);
-    } finally {
-      close();
-    }
-    return oDataResponse;
-  }
-
-  @Override
-  public ODataResponse executeFunctionImport(final GetFunctionImportUriInfo uriParserResultView,
-      final String contentType) throws ODataException {
-    ODataResponse oDataResponse = null;
-    try {
-      oDataJPAContext.setODataContext(getContext());
-      List<Object> resultEntity = jpaProcessor.process(uriParserResultView);
-      oDataResponse =
-          responseBuilder.build(uriParserResultView, resultEntity, contentType);
-    } finally {
-      close();
-    }
-    return oDataResponse;
-  }
-
-  @Override
-  public ODataResponse executeFunctionImportValue(final GetFunctionImportUriInfo uriParserResultView,
-      final String contentType) throws ODataException {
-    ODataResponse oDataResponse = null;
-    try {
-      oDataJPAContext.setODataContext(getContext());
-      List<Object> result = jpaProcessor.process(uriParserResultView);
-      oDataResponse =
-          responseBuilder.build(uriParserResultView, result.get(0));
-    } finally {
-      close();
-    }
-    return oDataResponse;
-  }
-
-  @Override
-  public ODataResponse readEntityLink(final GetEntityLinkUriInfo uriParserResultView, final String contentType)
-      throws ODataException {
-    ODataResponse oDataResponse = null;
-    try {
-      oDataJPAContext.setODataContext(getContext());
-      Object jpaEntity = jpaProcessor.process(uriParserResultView);
-      oDataResponse =
-          responseBuilder.build(uriParserResultView, jpaEntity, contentType);
-    } finally {
-      close();
-    }
-    return oDataResponse;
-  }
-
-  @Override
-  public ODataResponse readEntityLinks(final GetEntitySetLinksUriInfo uriParserResultView, final String contentType)
-      throws ODataException {
-    ODataResponse oDataResponse = null;
-    try {
-      oDataJPAContext.setODataContext(getContext());
-      List<Object> jpaEntity = jpaProcessor.process(uriParserResultView);
-      oDataResponse =
-          responseBuilder.build(uriParserResultView, jpaEntity, contentType);
-    } finally {
-      close();
-    }
-    return oDataResponse;
-  }
-
-  @Override
-  public ODataResponse createEntityLink(final PostUriInfo uriParserResultView, final InputStream content,
-      final String requestContentType, final String contentType) throws ODataException {
-    try {
-      oDataJPAContext.setODataContext(getContext());
-      jpaProcessor.process(uriParserResultView, content, requestContentType, contentType);
-      return ODataResponse.newBuilder().build();
-    } finally {
-      close();
-    }
-  }
-
-  @Override
-  public ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content,
-      final String requestContentType, final String contentType) throws ODataException {
-    try {
-      oDataJPAContext.setODataContext(getContext());
-      jpaProcessor.process(uriParserResultView, content, requestContentType, contentType);
-      return ODataResponse.newBuilder().build();
-    } finally {
-      close();
-    }
-  }
-
-  @Override
-  public ODataResponse deleteEntityLink(final DeleteUriInfo uriParserResultView, final String contentType)
-      throws ODataException {
-    try {
-      oDataJPAContext.setODataContext(getContext());
-      jpaProcessor.process(uriParserResultView, contentType);
-      return ODataResponse.newBuilder().build();
-    } finally {
-      close();
-    }
-  }
-
-  @Override
-  public ODataResponse executeBatch(final BatchHandler handler, final String contentType, final InputStream content)
-      throws ODataException {
-    try {
-      oDataJPAContext.setODataContext(getContext());
-
-      ODataResponse batchResponse;
-      List<BatchResponsePart> batchResponseParts = new ArrayList<BatchResponsePart>();
-      PathInfo pathInfo = getContext().getPathInfo();
-      EntityProviderBatchProperties batchProperties = EntityProviderBatchProperties.init().pathInfo(pathInfo).build();
-      List<BatchRequestPart> batchParts = EntityProvider.parseBatchRequest(contentType, content, batchProperties);
-
-      for (BatchRequestPart batchPart : batchParts) {
-        batchResponseParts.add(handler.handleBatchPart(batchPart));
-      }
-      batchResponse = EntityProvider.writeBatchResponse(batchResponseParts);
-      return batchResponse;
-    } finally {
-      close(true);
-    }
-  }
-
-  @Override
-  public BatchResponsePart executeChangeSet(final BatchHandler handler, final List<ODataRequest> requests)
-      throws ODataException {
-    List<ODataResponse> responses = new ArrayList<ODataResponse>();
-    try {
-      oDataJPAContext.getODataJPATransaction().begin();
-
-      for (ODataRequest request : requests) {
-        oDataJPAContext.setODataContext(getContext());
-        ODataResponse response = handler.handleRequest(request);
-        if (response.getStatus().getStatusCode() >= HttpStatusCodes.BAD_REQUEST.getStatusCode()) {
-          // Rollback
-          oDataJPAContext.getODataJPATransaction().rollback();
-          List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1);
-          errorResponses.add(response);
-          return BatchResponsePart.responses(errorResponses).changeSet(false).build();
-        }
-        responses.add(response);
-      }
-      oDataJPAContext.getODataJPATransaction().commit();
-
-      return BatchResponsePart.responses(responses).changeSet(true).build();
-    } catch (Exception e) {
-
-      List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1);
-      errorResponses.add(ODataResponse.entity(e).status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build());
-      return BatchResponsePart.responses(errorResponses).changeSet(false).build();
-    } finally {
-      close(true);
-    }
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/571a10eb/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/CustomODataJPAProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/CustomODataJPAProcessor.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/CustomODataJPAProcessor.java
new file mode 100644
index 0000000..385bb50
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/CustomODataJPAProcessor.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.ref.util;
+
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPADefaultProcessor;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class CustomODataJPAProcessor extends ODataJPADefaultProcessor {
+
+  private static final Logger LOG = Logger.getLogger(CustomODataJPAProcessor.class.getName());
+  private static final AtomicInteger READ_COUNT = new AtomicInteger(0);
+
+  public CustomODataJPAProcessor(ODataJPAContext oDataJPAContext) {
+    super(oDataJPAContext);
+  }
+
+  @Override
+  public ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType)
+      throws ODataException {
+
+    int readCount = READ_COUNT.incrementAndGet();
+    LOG.log(Level.INFO, "Start read access number '" + readCount + "' for '" +
+        uriParserResultView.getTargetEntitySet().getName() + "'.");
+    long start = System.currentTimeMillis();
+    List<Object> jpaEntities = jpaProcessor.process(uriParserResultView);
+    ODataResponse oDataResponse = responseBuilder.build(uriParserResultView, jpaEntities, contentType);
+    long duration = System.currentTimeMillis() - start;
+    LOG.log(Level.INFO, "Finished read access number '" + readCount + "' after '" + duration + "'ms.");
+
+    return oDataResponse;
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/571a10eb/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java
index 6e59903..845875b 100644
--- a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java
@@ -22,13 +22,16 @@ import java.util.ResourceBundle;
 
 import org.apache.olingo.odata2.api.ODataCallback;
 import org.apache.olingo.odata2.api.ODataDebugCallback;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
 import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
 import org.apache.olingo.odata2.jpa.processor.api.ODataJPAServiceFactory;
 import org.apache.olingo.odata2.jpa.processor.api.OnJPAWriteContent;
 import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAAccessFactory;
 import org.apache.olingo.odata2.jpa.processor.ref.extension.OnDBWriteContent;
 import org.apache.olingo.odata2.jpa.processor.ref.extension.SalesOrderProcessingExtension;
 import org.apache.olingo.odata2.jpa.processor.ref.factory.JPAEntityManagerFactory;
+import org.apache.olingo.odata2.jpa.processor.ref.util.CustomODataJPAProcessor;
 
 public class JPAReferenceServiceFactory extends ODataJPAServiceFactory {
   private static final String PUNIT_NAME = "salesorderprocessing";
@@ -54,6 +57,11 @@ public class JPAReferenceServiceFactory extends ODataJPAServiceFactory {
     return oDataJPAContext;
   }
 
+  @Override
+  public ODataSingleProcessor createCustomODataProcessor(ODataJPAContext context) {
+    return new CustomODataJPAProcessor(context);
+  }
+
   private void setErrorLevel() {
     ResourceBundle config = ResourceBundle.getBundle(CONFIG);
     boolean error = Boolean.parseBoolean(config.getString(SHOW_DETAIL_ERROR));


[2/3] olingo-odata2 git commit: [OLINGO-1018] Removed obsolete ODataJPAProcessorDefault

Posted by mi...@apache.org.
[OLINGO-1018] Removed obsolete ODataJPAProcessorDefault


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

Branch: refs/heads/master
Commit: 03457349196c8788f7865e4478071c14d77c9ea3
Parents: 571a10e
Author: mibo <mi...@apache.org>
Authored: Thu Sep 8 20:43:41 2016 +0200
Committer: mibo <mi...@apache.org>
Committed: Thu Sep 8 20:43:41 2016 +0200

----------------------------------------------------------------------
 .../processor/api/ODataJPADefaultProcessor.java |   6 +-
 .../core/ODataJPAProcessorDefault.java          |  29 -
 .../core/factory/ODataJPAFactoryImpl.java       |   4 +-
 .../core/ODataJPADefaultProcessorTest.java      | 588 +++++++++++++++++++
 .../core/ODataJPAProcessorDefaultTest.java      | 587 ------------------
 .../core/access/data/JPAProcessorImplTest.java  |   4 +-
 6 files changed, 593 insertions(+), 625 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/03457349/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPADefaultProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPADefaultProcessor.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPADefaultProcessor.java
index ca89e13..e562dc7 100644
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPADefaultProcessor.java
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPADefaultProcessor.java
@@ -29,19 +29,15 @@ import org.apache.olingo.odata2.api.processor.ODataRequest;
 import org.apache.olingo.odata2.api.processor.ODataResponse;
 import org.apache.olingo.odata2.api.uri.PathInfo;
 import org.apache.olingo.odata2.api.uri.info.*;
-import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAException;
 
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
-public class ODataJPADefaultProcessor extends ODataJPAProcessor {
+public abstract class ODataJPADefaultProcessor extends ODataJPAProcessor {
 
   public ODataJPADefaultProcessor(final ODataJPAContext oDataJPAContext) {
     super(oDataJPAContext);
-    if (oDataJPAContext == null) {
-      throw new IllegalArgumentException(ODataJPAException.ODATA_JPACTX_NULL);
-    }
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/03457349/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
deleted file mode 100644
index 8daf88e..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
+++ /dev/null
@@ -1,29 +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.odata2.jpa.processor.core;
-
-import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
-import org.apache.olingo.odata2.jpa.processor.api.ODataJPADefaultProcessor;
-
-public class ODataJPAProcessorDefault extends ODataJPADefaultProcessor {
-
-  public ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext) {
-    super(oDataJPAContext);
-  }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/03457349/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java
index ce08757..6ef809f 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java
@@ -23,6 +23,7 @@ import java.util.Locale;
 import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
 import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
 import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPADefaultProcessor;
 import org.apache.olingo.odata2.jpa.processor.api.ODataJPAResponseBuilder;
 import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess;
 import org.apache.olingo.odata2.jpa.processor.api.access.JPAMethodContext.JPAMethodContextBuilder;
@@ -39,7 +40,6 @@ import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement.JPQLStateme
 import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
 import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmModelView;
 import org.apache.olingo.odata2.jpa.processor.core.ODataJPAContextImpl;
-import org.apache.olingo.odata2.jpa.processor.core.ODataJPAProcessorDefault;
 import org.apache.olingo.odata2.jpa.processor.core.ODataJPAResponseBuilderDefault;
 import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAFunctionContext;
 import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAProcessorImpl;
@@ -173,7 +173,7 @@ public class ODataJPAFactoryImpl extends ODataJPAFactory {
 
     @Override
     public ODataSingleProcessor createODataProcessor(final ODataJPAContext oDataJPAContext) {
-      return new ODataJPAProcessorDefault(oDataJPAContext);
+      return new ODataJPADefaultProcessor(oDataJPAContext) { };
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/03457349/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPADefaultProcessorTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPADefaultProcessorTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPADefaultProcessorTest.java
new file mode 100644
index 0000000..71e790f
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPADefaultProcessorTest.java
@@ -0,0 +1,588 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Query;
+import javax.persistence.metamodel.EntityType;
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.api.commons.HttpContentType;
+import org.apache.olingo.odata2.api.commons.InlineCount;
+import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
+import org.apache.olingo.odata2.api.edm.EdmEntityContainer;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFacets;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTyped;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.NavigationSegment;
+import org.apache.olingo.odata2.api.uri.PathInfo;
+import org.apache.olingo.odata2.api.uri.UriInfo;
+import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
+import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
+import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPADefaultProcessor;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPATransaction;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.ODataContextMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.ODataServiceMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.data.SalesOrderHeader;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmTestModelView;
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ODataJPADefaultProcessorTest extends JPAEdmTestModelView {
+
+  private ODataJPADefaultProcessor objODataJPAProcessorDefault;
+
+  private static final String STR_LOCAL_URI = "http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/";
+  private static final String SALESORDERPROCESSING_CONTAINER = "salesorderprocessingContainer";
+  private static final String SO_ID = "SoId";
+  private static final String SALES_ORDER = "SalesOrder";
+  private static final String SALES_ORDER_HEADERS = "SalesOrderHeaders";
+  private static final String STR_CONTENT_TYPE = "Content-Type";
+
+  @Before
+  public void setUp() {
+    objODataJPAProcessorDefault = new ODataJPADefaultProcessor(getLocalmockODataJPAContext()) { };
+  }
+
+  @Test
+  public void testReadEntitySetGetEntitySetUriInfoString() {
+    try {
+      GetEntityUriInfo getEntityView = getEntityUriInfo();
+      Assert.assertNotNull(objODataJPAProcessorDefault.readEntity(getEntityView, HttpContentType.APPLICATION_XML));
+    } catch (ODataJPAModelException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    } catch (ODataJPARuntimeException e1) {// Expected
+      assertTrue(true);
+    } catch (ODataException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    }
+
+  }
+
+  @Test
+  public void testcountEntitySet() {
+    try {
+      ODataResponse countEntitySet =
+          objODataJPAProcessorDefault.countEntitySet(getEntitySetCountUriInfo(), HttpContentType.APPLICATION_XML);
+      Assert.assertNotNull(countEntitySet);
+      Object entity = countEntitySet.getEntity();
+      Assert.assertNotNull(entity);
+
+      byte[] b = new byte[2];
+      ((ByteArrayInputStream) entity).read(b);
+      Assert.assertEquals("11", new String(b, Charset.forName("utf-8")));
+    } catch (ODataException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    } catch (Exception e) {
+      assertTrue(true);
+    }
+  }
+
+  @Test
+  public void testExistsEntity() {
+    try {
+      Assert.assertNotNull(objODataJPAProcessorDefault.existsEntity(getEntityCountUriInfo(),
+          HttpContentType.APPLICATION_XML));
+      Assert.assertNull("ContentType MUST NOT set by entity provider", objODataJPAProcessorDefault.existsEntity(
+          getEntityCountUriInfo(), HttpContentType.APPLICATION_XML).getHeader(STR_CONTENT_TYPE));
+    } catch (ODataException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    } catch (Exception e) {
+      assertTrue(true);
+    }
+  }
+
+  @Test
+  public void testDeleteEntity() {
+    try {
+      Assert.assertNotNull(objODataJPAProcessorDefault.deleteEntity(getDeletetUriInfo(),
+          HttpContentType.APPLICATION_XML));
+    } catch (ODataException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    }
+  }
+
+  @Test
+  public void testCreateEntity() {
+    try {
+      Assert.assertNotNull(objODataJPAProcessorDefault.createEntity(getPostUriInfo(), getMockedInputStreamContent(),
+          HttpContentType.APPLICATION_XML, HttpContentType.APPLICATION_XML));
+    } catch (ODataException e) {
+      Assert.assertTrue(true); // Expected TODO - need to revisit
+    }
+  }
+
+  @Test
+  public void testUpdateEntity() {
+    try {
+      Assert.assertNotNull(objODataJPAProcessorDefault.updateEntity(getPutUriInfo(), getMockedInputStreamContent(),
+          HttpContentType.APPLICATION_XML, false, HttpContentType.APPLICATION_XML));
+    } catch (ODataException e) {
+      Assert.assertTrue(true); // Expected TODO - need to revisit
+    }
+  }
+
+  private PutMergePatchUriInfo getPutUriInfo() {
+    return (PutMergePatchUriInfo) getDeletetUriInfo();
+  }
+
+  private PostUriInfo getPostUriInfo() {
+    return (PostUriInfo) getDeletetUriInfo();
+  }
+
+  private InputStream getMockedInputStreamContent() {
+    return new ByteArrayInputStream(getEntityBody().getBytes());
+  }
+
+  private String getEntityBody() {
+    return "<entry xmlns=\"http://www.w3.org/2005/Atom\" " +
+        "xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\" " +
+        "xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\" " +
+        "xml:base=\"http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/SalesOrderProcessing.svc/\">"
+        + "<content type=\"application/xml\">"
+        + "<m:properties>"
+        + "<d:ID>2</d:ID>"
+        + "<d:CreationDate>2013-01-02T00:00:00</d:CreationDate>"
+        + "<d:CurrencyCode>Code_555</d:CurrencyCode>"
+        + "<d:BuyerAddressInfo m:type=\"SalesOrderProcessing.AddressInfo\">"
+        + "<d:Street>Test_Street_Name_055</d:Street>"
+        + "<d:Number>2</d:Number>"
+        + "<d:Country>Test_Country_2</d:Country>"
+        + "<d:City>Test_City_2</d:City>"
+        + "</d:BuyerAddressInfo>"
+        + "<d:GrossAmount>0.0</d:GrossAmount>"
+        + "<d:BuyerId>2</d:BuyerId>"
+        + "<d:DeliveryStatus>true</d:DeliveryStatus>"
+        + "<d:BuyerName>buyerName_2</d:BuyerName>"
+        + "<d:NetAmount>0.0</d:NetAmount>" + "</m:properties>" + "</content>" + "</entry>";
+  }
+
+  private GetEntitySetCountUriInfo getEntitySetCountUriInfo() {
+    return getLocalUriInfo();
+  }
+
+  private GetEntityCountUriInfo getEntityCountUriInfo() {
+    return getLocalUriInfo();
+  }
+
+  private DeleteUriInfo getDeletetUriInfo() {
+    UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
+    EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
+    List<NavigationSegment> navSegments = new ArrayList<NavigationSegment>();
+    EasyMock.expect(objUriInfo.getNavigationSegments()).andReturn(navSegments).anyTimes();
+    EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
+    EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
+    EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
+    EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
+    EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
+    EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
+    EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
+    EasyMock.expect(objUriInfo.getKeyPredicates()).andStubReturn(getKeyPredicates());
+    EasyMock.expect(objUriInfo.isLinks()).andStubReturn(false);
+    EasyMock.replay(objUriInfo);
+    return objUriInfo;
+  }
+
+  private List<KeyPredicate> getKeyPredicates() {
+    List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
+    return keyPredicates;
+  }
+
+  /**
+   * @return
+   */
+  private UriInfo getLocalUriInfo() {
+    UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
+    EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
+    List<NavigationSegment> navSegments = new ArrayList<NavigationSegment>();
+    EasyMock.expect(objUriInfo.getNavigationSegments()).andReturn(navSegments).anyTimes();
+    EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
+    EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
+    EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
+    EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
+    EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
+    EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
+    EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
+    EasyMock.expect(objUriInfo.getFunctionImport()).andStubReturn(null);
+    EasyMock.replay(objUriInfo);
+    return objUriInfo;
+  }
+
+  /**
+   * @return
+   * @throws EdmException
+   */
+  private EdmEntitySet getLocalEdmEntitySet() {
+    EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+    try {
+      EasyMock.expect(edmEntitySet.getName()).andStubReturn(SALES_ORDER_HEADERS);
+      EasyMock.expect(edmEntitySet.getEntityContainer()).andStubReturn(getLocalEdmEntityContainer());
+      EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(getLocalEdmEntityType());
+      EasyMock.replay(edmEntitySet);
+    } catch (EdmException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    }
+    return edmEntitySet;
+  }
+
+  /**
+   * @return
+   * @throws EdmException
+   */
+  private EdmEntityType getLocalEdmEntityType() {
+    EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
+    try {
+      EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>());
+      EasyMock.expect(edmEntityType.getPropertyNames()).andStubReturn(getLocalPropertyNames());
+      EasyMock.expect(edmEntityType.getProperty(SO_ID)).andStubReturn(getEdmTypedMockedObj(SALES_ORDER));
+      EasyMock.expect(edmEntityType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+      EasyMock.expect(edmEntityType.getNamespace()).andStubReturn(SALES_ORDER_HEADERS);
+      EasyMock.expect(edmEntityType.getName()).andStubReturn(SALES_ORDER_HEADERS);
+      EasyMock.expect(edmEntityType.hasStream()).andStubReturn(false);
+      EasyMock.expect(edmEntityType.getNavigationPropertyNames()).andStubReturn(new ArrayList<String>());
+      EasyMock.expect(edmEntityType.getKeyPropertyNames()).andStubReturn(new ArrayList<String>());
+      EasyMock.expect(edmEntityType.getMapping()).andStubReturn((EdmMapping) getEdmMappingMockedObj(SALES_ORDER));
+      EasyMock.replay(edmEntityType);
+    } catch (EdmException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    }
+    return edmEntityType;
+  }
+
+  private InlineCount getInlineCount() {
+    return InlineCount.NONE;
+  }
+
+  private FilterExpression getFilter() {
+    return null;
+  }
+
+  private Integer getSkip() {
+    return null;
+  }
+
+  private Integer getTop() {
+    return null;
+  }
+
+  private OrderByExpression getOrderByExpression() {
+    return null;
+  }
+
+  private ODataJPAContext getLocalmockODataJPAContext() {
+    ODataJPAContext odataJPAContext = EasyMock.createMock(ODataJPAContext.class);
+    EasyMock.expect(odataJPAContext.getPageSize()).andReturn(0).anyTimes();
+    EasyMock.expect(odataJPAContext.getPersistenceUnitName()).andStubReturn("salesorderprocessing");
+    EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andStubReturn(mockEntityManagerFactory());
+    EasyMock.expect(odataJPAContext.getODataJPATransaction()).andStubReturn(getLocalJpaTransaction());
+    EasyMock.expect(odataJPAContext.getODataContext()).andStubReturn(getLocalODataContext());
+    odataJPAContext.setODataContext((ODataContext) EasyMock.anyObject());
+    EasyMock.expectLastCall().anyTimes();
+    EasyMock.expect(odataJPAContext.getEntityManager()).andStubReturn(getLocalEntityManager());
+    EasyMock.expect(odataJPAContext.isContainerManaged()).andReturn(false);
+    EasyMock.expectLastCall().anyTimes();
+    EasyMock.replay(odataJPAContext);
+    return odataJPAContext;
+  }
+
+  private ODataJPATransaction getLocalJpaTransaction() {
+    ODataJPATransaction tx = EasyMock.createMock(ODataJPATransaction.class);
+    tx.begin(); // testing void method
+    tx.commit();// testing void method
+    tx.rollback();// testing void method
+    EasyMock.expect(tx.isActive()).andReturn(false);
+    EasyMock.replay(tx);
+    return tx;
+  }
+
+  private EntityManagerFactory mockEntityManagerFactory() {
+    EntityManagerFactory emf = EasyMock.createMock(EntityManagerFactory.class);
+    EasyMock.expect(emf.getMetamodel()).andStubReturn(mockMetaModel());
+    EasyMock.expect(emf.createEntityManager()).andStubReturn(getLocalEntityManager());
+    EasyMock.replay(emf);
+    return emf;
+  }
+
+  private EntityManagerFactory mockEntityManagerFactory2() {// For create, to avoid stackoverflow
+    EntityManagerFactory emf = EasyMock.createMock(EntityManagerFactory.class);
+    EasyMock.expect(emf.getMetamodel()).andStubReturn(mockMetaModel());
+    EasyMock.replay(emf);
+    return emf;
+  }
+
+  private EntityManager getLocalEntityManager() {
+    EntityManager em = EasyMock.createMock(EntityManager.class);
+    EasyMock.expect(em.createQuery("SELECT E1 FROM SalesOrderHeaders E1")).andStubReturn(getQuery());
+    EasyMock.expect(em.createQuery("SELECT COUNT ( E1 ) FROM SalesOrderHeaders E1")).andStubReturn(
+        getQueryForSelectCount());
+    EasyMock.expect(em.getEntityManagerFactory()).andStubReturn(mockEntityManagerFactory2());// For create
+    EasyMock.expect(em.getTransaction()).andStubReturn(getLocalTransaction()); // For Delete
+    EasyMock.expect(em.isOpen()).andReturn(true).anyTimes();
+    Address obj = new Address();
+    em.remove(obj);// testing void method
+    em.flush();
+    em.close();
+    EasyMock.expectLastCall().anyTimes();
+    EasyMock.replay(em);
+    return em;
+  }
+
+  private EntityTransaction getLocalTransaction() {
+    EntityTransaction entityTransaction = EasyMock.createMock(EntityTransaction.class);
+    entityTransaction.begin(); // testing void method
+    entityTransaction.commit();// testing void method
+    entityTransaction.rollback();// testing void method
+    EasyMock.expect(entityTransaction.isActive()).andReturn(false);
+    EasyMock.replay(entityTransaction);
+    return entityTransaction;
+  }
+
+  private Query getQuery() {
+    Query query = EasyMock.createMock(Query.class);
+    EasyMock.expect(query.getResultList()).andStubReturn(getResultList());
+    EasyMock.replay(query);
+    return query;
+  }
+
+  private Query getQueryForSelectCount() {
+    Query query = EasyMock.createMock(Query.class);
+    EasyMock.expect(query.getResultList()).andStubReturn(getResultListForSelectCount());
+    EasyMock.replay(query);
+    return query;
+  }
+
+  private List<?> getResultList() {
+    List<Object> list = new ArrayList<Object>();
+    list.add(new Address());
+    return list;
+  }
+
+  private List<?> getResultListForSelectCount() {
+    List<Object> list = new ArrayList<Object>();
+    list.add(new Long(11));
+    return list;
+  }
+
+  class Address {
+    private String soId = "12";
+
+    public String getSoId() {
+      return soId;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+      boolean isEqual = false;
+      if (obj instanceof Address) {
+        isEqual = getSoId().equalsIgnoreCase(((Address) obj).getSoId());//
+      }
+      return isEqual;
+    }
+  }
+
+  private Metamodel mockMetaModel() {
+    Metamodel metaModel = EasyMock.createMock(Metamodel.class);
+    EasyMock.expect(metaModel.getEntities()).andStubReturn(getLocalEntities());
+    EasyMock.replay(metaModel);
+    return metaModel;
+  }
+
+  private Set<EntityType<?>> getLocalEntities() {
+    Set<EntityType<?>> entityTypeSet = new HashSet<EntityType<?>>();
+    entityTypeSet.add(getLocalJPAEntityType());
+    return entityTypeSet;
+  }
+
+  @SuppressWarnings("rawtypes")
+  private EntityType<EntityType> getLocalJPAEntityType() {
+    @SuppressWarnings("unchecked")
+    EntityType<EntityType> entityType = EasyMock.createMock(EntityType.class);
+    EasyMock.expect(entityType.getJavaType()).andStubReturn(EntityType.class);
+    EasyMock.replay(entityType);
+    return entityType;
+  }
+
+  private GetEntityUriInfo getEntityUriInfo() {
+    GetEntityUriInfo getEntityView = EasyMock.createMock(GetEntityUriInfo.class);
+    EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+    EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
+    try {
+      EasyMock.expect(getEntityView.getExpand()).andStubReturn(null);
+      EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>());
+      EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
+      EasyMock.expect(edmEntitySet.getName()).andStubReturn(SALES_ORDER_HEADERS);
+
+      EasyMock.expect(getEntityView.getSelect()).andStubReturn(null);
+      EasyMock.expect(getEntityView.getTargetEntitySet()).andStubReturn(edmEntitySet);
+      EasyMock.expect(edmEntityType.getPropertyNames()).andStubReturn(getLocalPropertyNames());
+      EasyMock.expect(edmEntityType.getProperty(SO_ID)).andStubReturn(getEdmTypedMockedObj(SO_ID));
+
+      EasyMock.expect(edmEntityType.getMapping()).andStubReturn((EdmMapping) getEdmMappingMockedObj(SALES_ORDER));
+
+      EasyMock.expect(edmEntityType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+      EasyMock.expect(edmEntityType.getNamespace()).andStubReturn(SALES_ORDER_HEADERS);
+      EasyMock.expect(edmEntityType.getName()).andStubReturn(SALES_ORDER_HEADERS);
+      EasyMock.expect(edmEntityType.hasStream()).andStubReturn(false);
+      EasyMock.expect(edmEntityType.getNavigationPropertyNames()).andStubReturn(new ArrayList<String>());
+      EasyMock.expect(edmEntityType.getKeyPropertyNames()).andStubReturn(new ArrayList<String>());
+
+      EasyMock.expect(edmEntitySet.getEntityContainer()).andStubReturn(getLocalEdmEntityContainer());
+
+      EasyMock.replay(edmEntityType, edmEntitySet);
+      EasyMock.expect(getEntityView.getKeyPredicates()).andStubReturn(new ArrayList<KeyPredicate>());
+      List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
+      EasyMock.expect(getEntityView.getNavigationSegments()).andReturn(navigationSegments);
+      EasyMock.expect(getEntityView.getStartEntitySet()).andReturn(edmEntitySet);
+
+      EasyMock.replay(getEntityView);
+    } catch (EdmException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    }
+    return getEntityView;
+  }
+
+  private EdmEntityContainer getLocalEdmEntityContainer() {
+    EdmEntityContainer edmEntityContainer = EasyMock.createMock(EdmEntityContainer.class);
+    EasyMock.expect(edmEntityContainer.isDefaultEntityContainer()).andStubReturn(true);
+    try {
+      EasyMock.expect(edmEntityContainer.getName()).andStubReturn(SALESORDERPROCESSING_CONTAINER);
+    } catch (EdmException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    }
+
+    EasyMock.replay(edmEntityContainer);
+    return edmEntityContainer;
+  }
+
+  private EdmTyped getEdmTypedMockedObj(final String propertyName) {
+    EdmProperty mockedEdmProperty = EasyMock.createMock(EdmProperty.class);
+    try {
+      EasyMock.expect(mockedEdmProperty.getMapping()).andStubReturn((EdmMapping) getEdmMappingMockedObj(propertyName));
+      EdmType edmType = EasyMock.createMock(EdmType.class);
+      EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+      EasyMock.replay(edmType);
+      EasyMock.expect(mockedEdmProperty.getName()).andStubReturn("identifier");
+      EasyMock.expect(mockedEdmProperty.getType()).andStubReturn(edmType);
+      EasyMock.expect(mockedEdmProperty.getFacets()).andStubReturn(getEdmFacetsMockedObj());
+
+      EasyMock.replay(mockedEdmProperty);
+    } catch (EdmException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    }
+    return mockedEdmProperty;
+  }
+
+  private EdmFacets getEdmFacetsMockedObj() {
+    EdmFacets facets = EasyMock.createMock(EdmFacets.class);
+    EasyMock.expect(facets.getConcurrencyMode()).andStubReturn(EdmConcurrencyMode.Fixed);
+
+    EasyMock.replay(facets);
+    return facets;
+  }
+
+  private JPAEdmMapping getEdmMappingMockedObj(final String propertyName) {
+    JPAEdmMappingImpl mockedEdmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
+    if (propertyName.equalsIgnoreCase(SALES_ORDER)) {
+      EasyMock.expect(((EdmMapping) mockedEdmMapping).getInternalName()).andStubReturn(SALES_ORDER_HEADERS);
+    } else {
+      EasyMock.expect(((EdmMapping) mockedEdmMapping).getInternalName()).andStubReturn(propertyName);
+    }
+    EasyMock.expect(mockedEdmMapping.getODataJPATombstoneEntityListener()).andReturn(null);
+    EasyMock.<Class<?>> expect(mockedEdmMapping.getJPAType()).andReturn(SalesOrderHeader.class);
+    EasyMock.replay(mockedEdmMapping);
+    return mockedEdmMapping;
+  }
+
+  private List<String> getLocalPropertyNames() {
+    List<String> list = new ArrayList<String>();
+    list.add(SO_ID);
+    return list;
+  }
+
+  private ODataContext getLocalODataContext() {
+    ODataContext objODataContext = null;
+    try {
+      ODataContextMock contextMock = new ODataContextMock();
+      contextMock.setODataService(new ODataServiceMock().mock());
+      contextMock.setPathInfo(getLocalPathInfo());
+      objODataContext = contextMock.mock();
+
+    } catch (ODataException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    }
+    return objODataContext;
+  }
+
+  private PathInfo getLocalPathInfo() {
+    PathInfo pathInfo = EasyMock.createMock(PathInfo.class);
+    EasyMock.expect(pathInfo.getServiceRoot()).andStubReturn(getLocalURI());
+    EasyMock.replay(pathInfo);
+    return pathInfo;
+  }
+
+  private URI getLocalURI() {
+    URI uri = null;
+    try {
+      uri = new URI(STR_LOCAL_URI);
+    } catch (URISyntaxException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    }
+    return uri;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/03457349/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java
deleted file mode 100644
index 14cb5d3..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java
+++ /dev/null
@@ -1,587 +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.odata2.jpa.processor.core;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.EntityTransaction;
-import javax.persistence.Query;
-import javax.persistence.metamodel.EntityType;
-import javax.persistence.metamodel.Metamodel;
-
-import org.apache.olingo.odata2.api.commons.HttpContentType;
-import org.apache.olingo.odata2.api.commons.InlineCount;
-import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
-import org.apache.olingo.odata2.api.edm.EdmEntityContainer;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmTypeKind;
-import org.apache.olingo.odata2.api.edm.EdmTyped;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.NavigationSegment;
-import org.apache.olingo.odata2.api.uri.PathInfo;
-import org.apache.olingo.odata2.api.uri.UriInfo;
-import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
-import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
-import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
-import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
-import org.apache.olingo.odata2.jpa.processor.api.ODataJPATransaction;
-import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
-import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.jpa.processor.core.mock.ODataContextMock;
-import org.apache.olingo.odata2.jpa.processor.core.mock.ODataServiceMock;
-import org.apache.olingo.odata2.jpa.processor.core.mock.data.SalesOrderHeader;
-import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
-import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmTestModelView;
-import org.easymock.EasyMock;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ODataJPAProcessorDefaultTest extends JPAEdmTestModelView {
-
-  ODataJPAProcessorDefault objODataJPAProcessorDefault;
-
-  private static final String STR_LOCAL_URI = "http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/";
-  private static final String SALESORDERPROCESSING_CONTAINER = "salesorderprocessingContainer";
-  private static final String SO_ID = "SoId";
-  private static final String SALES_ORDER = "SalesOrder";
-  private static final String SALES_ORDER_HEADERS = "SalesOrderHeaders";
-  private static final String STR_CONTENT_TYPE = "Content-Type";
-
-  @Before
-  public void setUp() {
-    objODataJPAProcessorDefault = new ODataJPAProcessorDefault(getLocalmockODataJPAContext());
-  }
-
-  @Test
-  public void testReadEntitySetGetEntitySetUriInfoString() {
-    try {
-      GetEntityUriInfo getEntityView = getEntityUriInfo();
-      Assert.assertNotNull(objODataJPAProcessorDefault.readEntity(getEntityView, HttpContentType.APPLICATION_XML));
-    } catch (ODataJPAModelException e) {
-      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
-    } catch (ODataJPARuntimeException e1) {// Expected
-      assertTrue(true);
-    } catch (ODataException e) {
-      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
-    }
-
-  }
-
-  @Test
-  public void testcountEntitySet() {
-    try {
-      ODataResponse countEntitySet =
-          objODataJPAProcessorDefault.countEntitySet(getEntitySetCountUriInfo(), HttpContentType.APPLICATION_XML);
-      Assert.assertNotNull(countEntitySet);
-      Object entity = countEntitySet.getEntity();
-      Assert.assertNotNull(entity);
-
-      byte[] b = new byte[2];
-      ((ByteArrayInputStream) entity).read(b);
-      Assert.assertEquals("11", new String(b, Charset.forName("utf-8")));
-    } catch (ODataException e) {
-      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
-    } catch (Exception e) {
-      assertTrue(true);
-    }
-  }
-
-  @Test
-  public void testExistsEntity() {
-    try {
-      Assert.assertNotNull(objODataJPAProcessorDefault.existsEntity(getEntityCountUriInfo(),
-          HttpContentType.APPLICATION_XML));
-      Assert.assertNull("ContentType MUST NOT set by entity provider", objODataJPAProcessorDefault.existsEntity(
-          getEntityCountUriInfo(), HttpContentType.APPLICATION_XML).getHeader(STR_CONTENT_TYPE));
-    } catch (ODataException e) {
-      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
-    } catch (Exception e) {
-      assertTrue(true);
-    }
-  }
-
-  @Test
-  public void testDeleteEntity() {
-    try {
-      Assert.assertNotNull(objODataJPAProcessorDefault.deleteEntity(getDeletetUriInfo(),
-          HttpContentType.APPLICATION_XML));
-    } catch (ODataException e) {
-      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
-    }
-  }
-
-  @Test
-  public void testCreateEntity() {
-    try {
-      Assert.assertNotNull(objODataJPAProcessorDefault.createEntity(getPostUriInfo(), getMockedInputStreamContent(),
-          HttpContentType.APPLICATION_XML, HttpContentType.APPLICATION_XML));
-    } catch (ODataException e) {
-      Assert.assertTrue(true); // Expected TODO - need to revisit
-    }
-  }
-
-  @Test
-  public void testUpdateEntity() {
-    try {
-      Assert.assertNotNull(objODataJPAProcessorDefault.updateEntity(getPutUriInfo(), getMockedInputStreamContent(),
-          HttpContentType.APPLICATION_XML, false, HttpContentType.APPLICATION_XML));
-    } catch (ODataException e) {
-      Assert.assertTrue(true); // Expected TODO - need to revisit
-    }
-  }
-
-  private PutMergePatchUriInfo getPutUriInfo() {
-    return (PutMergePatchUriInfo) getDeletetUriInfo();
-  }
-
-  private PostUriInfo getPostUriInfo() {
-    return (PostUriInfo) getDeletetUriInfo();
-  }
-
-  private InputStream getMockedInputStreamContent() {
-    return new ByteArrayInputStream(getEntityBody().getBytes());
-  }
-
-  private String getEntityBody() {
-    return "<entry xmlns=\"http://www.w3.org/2005/Atom\" " +
-        "xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\" " +
-        "xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\" " +
-        "xml:base=\"http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/SalesOrderProcessing.svc/\">"
-        + "<content type=\"application/xml\">"
-        + "<m:properties>"
-        + "<d:ID>2</d:ID>"
-        + "<d:CreationDate>2013-01-02T00:00:00</d:CreationDate>"
-        + "<d:CurrencyCode>Code_555</d:CurrencyCode>"
-        + "<d:BuyerAddressInfo m:type=\"SalesOrderProcessing.AddressInfo\">"
-        + "<d:Street>Test_Street_Name_055</d:Street>"
-        + "<d:Number>2</d:Number>"
-        + "<d:Country>Test_Country_2</d:Country>"
-        + "<d:City>Test_City_2</d:City>"
-        + "</d:BuyerAddressInfo>"
-        + "<d:GrossAmount>0.0</d:GrossAmount>"
-        + "<d:BuyerId>2</d:BuyerId>"
-        + "<d:DeliveryStatus>true</d:DeliveryStatus>"
-        + "<d:BuyerName>buyerName_2</d:BuyerName>"
-        + "<d:NetAmount>0.0</d:NetAmount>" + "</m:properties>" + "</content>" + "</entry>";
-  }
-
-  private GetEntitySetCountUriInfo getEntitySetCountUriInfo() {
-    return getLocalUriInfo();
-  }
-
-  private GetEntityCountUriInfo getEntityCountUriInfo() {
-    return getLocalUriInfo();
-  }
-
-  private DeleteUriInfo getDeletetUriInfo() {
-    UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
-    EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
-    List<NavigationSegment> navSegments = new ArrayList<NavigationSegment>();
-    EasyMock.expect(objUriInfo.getNavigationSegments()).andReturn(navSegments).anyTimes();
-    EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
-    EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
-    EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
-    EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
-    EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
-    EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
-    EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
-    EasyMock.expect(objUriInfo.getKeyPredicates()).andStubReturn(getKeyPredicates());
-    EasyMock.expect(objUriInfo.isLinks()).andStubReturn(false);
-    EasyMock.replay(objUriInfo);
-    return objUriInfo;
-  }
-
-  private List<KeyPredicate> getKeyPredicates() {
-    List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
-    return keyPredicates;
-  }
-
-  /**
-   * @return
-   */
-  private UriInfo getLocalUriInfo() {
-    UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
-    EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
-    List<NavigationSegment> navSegments = new ArrayList<NavigationSegment>();
-    EasyMock.expect(objUriInfo.getNavigationSegments()).andReturn(navSegments).anyTimes();
-    EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
-    EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
-    EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
-    EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
-    EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
-    EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
-    EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
-    EasyMock.expect(objUriInfo.getFunctionImport()).andStubReturn(null);
-    EasyMock.replay(objUriInfo);
-    return objUriInfo;
-  }
-
-  /**
-   * @return
-   * @throws EdmException
-   */
-  private EdmEntitySet getLocalEdmEntitySet() {
-    EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
-    try {
-      EasyMock.expect(edmEntitySet.getName()).andStubReturn(SALES_ORDER_HEADERS);
-      EasyMock.expect(edmEntitySet.getEntityContainer()).andStubReturn(getLocalEdmEntityContainer());
-      EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(getLocalEdmEntityType());
-      EasyMock.replay(edmEntitySet);
-    } catch (EdmException e) {
-      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
-    }
-    return edmEntitySet;
-  }
-
-  /**
-   * @return
-   * @throws EdmException
-   */
-  private EdmEntityType getLocalEdmEntityType() {
-    EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
-    try {
-      EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>());
-      EasyMock.expect(edmEntityType.getPropertyNames()).andStubReturn(getLocalPropertyNames());
-      EasyMock.expect(edmEntityType.getProperty(SO_ID)).andStubReturn(getEdmTypedMockedObj(SALES_ORDER));
-      EasyMock.expect(edmEntityType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
-      EasyMock.expect(edmEntityType.getNamespace()).andStubReturn(SALES_ORDER_HEADERS);
-      EasyMock.expect(edmEntityType.getName()).andStubReturn(SALES_ORDER_HEADERS);
-      EasyMock.expect(edmEntityType.hasStream()).andStubReturn(false);
-      EasyMock.expect(edmEntityType.getNavigationPropertyNames()).andStubReturn(new ArrayList<String>());
-      EasyMock.expect(edmEntityType.getKeyPropertyNames()).andStubReturn(new ArrayList<String>());
-      EasyMock.expect(edmEntityType.getMapping()).andStubReturn((EdmMapping) getEdmMappingMockedObj(SALES_ORDER));
-      EasyMock.replay(edmEntityType);
-    } catch (EdmException e) {
-      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
-    }
-    return edmEntityType;
-  }
-
-  private InlineCount getInlineCount() {
-    return InlineCount.NONE;
-  }
-
-  private FilterExpression getFilter() {
-    return null;
-  }
-
-  private Integer getSkip() {
-    return null;
-  }
-
-  private Integer getTop() {
-    return null;
-  }
-
-  private OrderByExpression getOrderByExpression() {
-    return null;
-  }
-
-  private ODataJPAContext getLocalmockODataJPAContext() {
-    ODataJPAContext odataJPAContext = EasyMock.createMock(ODataJPAContext.class);
-    EasyMock.expect(odataJPAContext.getPageSize()).andReturn(0).anyTimes();
-    EasyMock.expect(odataJPAContext.getPersistenceUnitName()).andStubReturn("salesorderprocessing");
-    EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andStubReturn(mockEntityManagerFactory());
-    EasyMock.expect(odataJPAContext.getODataJPATransaction()).andStubReturn(getLocalJpaTransaction());
-    EasyMock.expect(odataJPAContext.getODataContext()).andStubReturn(getLocalODataContext());
-    odataJPAContext.setODataContext((ODataContext) EasyMock.anyObject());
-    EasyMock.expectLastCall().anyTimes();
-    EasyMock.expect(odataJPAContext.getEntityManager()).andStubReturn(getLocalEntityManager());
-    EasyMock.expect(odataJPAContext.isContainerManaged()).andReturn(false);
-    EasyMock.expectLastCall().anyTimes();
-    EasyMock.replay(odataJPAContext);
-    return odataJPAContext;
-  }
-
-  private ODataJPATransaction getLocalJpaTransaction() {
-    ODataJPATransaction tx = EasyMock.createMock(ODataJPATransaction.class);
-    tx.begin(); // testing void method
-    tx.commit();// testing void method
-    tx.rollback();// testing void method
-    EasyMock.expect(tx.isActive()).andReturn(false);
-    EasyMock.replay(tx);
-    return tx;
-  }
-
-  private EntityManagerFactory mockEntityManagerFactory() {
-    EntityManagerFactory emf = EasyMock.createMock(EntityManagerFactory.class);
-    EasyMock.expect(emf.getMetamodel()).andStubReturn(mockMetaModel());
-    EasyMock.expect(emf.createEntityManager()).andStubReturn(getLocalEntityManager());
-    EasyMock.replay(emf);
-    return emf;
-  }
-
-  private EntityManagerFactory mockEntityManagerFactory2() {// For create, to avoid stackoverflow
-    EntityManagerFactory emf = EasyMock.createMock(EntityManagerFactory.class);
-    EasyMock.expect(emf.getMetamodel()).andStubReturn(mockMetaModel());
-    EasyMock.replay(emf);
-    return emf;
-  }
-
-  private EntityManager getLocalEntityManager() {
-    EntityManager em = EasyMock.createMock(EntityManager.class);
-    EasyMock.expect(em.createQuery("SELECT E1 FROM SalesOrderHeaders E1")).andStubReturn(getQuery());
-    EasyMock.expect(em.createQuery("SELECT COUNT ( E1 ) FROM SalesOrderHeaders E1")).andStubReturn(
-        getQueryForSelectCount());
-    EasyMock.expect(em.getEntityManagerFactory()).andStubReturn(mockEntityManagerFactory2());// For create
-    EasyMock.expect(em.getTransaction()).andStubReturn(getLocalTransaction()); // For Delete
-    EasyMock.expect(em.isOpen()).andReturn(true).anyTimes();
-    Address obj = new Address();
-    em.remove(obj);// testing void method
-    em.flush();
-    em.close();
-    EasyMock.expectLastCall().anyTimes();
-    EasyMock.replay(em);
-    return em;
-  }
-
-  private EntityTransaction getLocalTransaction() {
-    EntityTransaction entityTransaction = EasyMock.createMock(EntityTransaction.class);
-    entityTransaction.begin(); // testing void method
-    entityTransaction.commit();// testing void method
-    entityTransaction.rollback();// testing void method
-    EasyMock.expect(entityTransaction.isActive()).andReturn(false);
-    EasyMock.replay(entityTransaction);
-    return entityTransaction;
-  }
-
-  private Query getQuery() {
-    Query query = EasyMock.createMock(Query.class);
-    EasyMock.expect(query.getResultList()).andStubReturn(getResultList());
-    EasyMock.replay(query);
-    return query;
-  }
-
-  private Query getQueryForSelectCount() {
-    Query query = EasyMock.createMock(Query.class);
-    EasyMock.expect(query.getResultList()).andStubReturn(getResultListForSelectCount());
-    EasyMock.replay(query);
-    return query;
-  }
-
-  private List<?> getResultList() {
-    List<Object> list = new ArrayList<Object>();
-    list.add(new Address());
-    return list;
-  }
-
-  private List<?> getResultListForSelectCount() {
-    List<Object> list = new ArrayList<Object>();
-    list.add(new Long(11));
-    return list;
-  }
-
-  class Address {
-    private String soId = "12";
-
-    public String getSoId() {
-      return soId;
-    }
-
-    @Override
-    public boolean equals(final Object obj) {
-      boolean isEqual = false;
-      if (obj instanceof Address) {
-        isEqual = getSoId().equalsIgnoreCase(((Address) obj).getSoId());//
-      }
-      return isEqual;
-    }
-  }
-
-  private Metamodel mockMetaModel() {
-    Metamodel metaModel = EasyMock.createMock(Metamodel.class);
-    EasyMock.expect(metaModel.getEntities()).andStubReturn(getLocalEntities());
-    EasyMock.replay(metaModel);
-    return metaModel;
-  }
-
-  private Set<EntityType<?>> getLocalEntities() {
-    Set<EntityType<?>> entityTypeSet = new HashSet<EntityType<?>>();
-    entityTypeSet.add(getLocalJPAEntityType());
-    return entityTypeSet;
-  }
-
-  @SuppressWarnings("rawtypes")
-  private EntityType<EntityType> getLocalJPAEntityType() {
-    @SuppressWarnings("unchecked")
-    EntityType<EntityType> entityType = EasyMock.createMock(EntityType.class);
-    EasyMock.expect(entityType.getJavaType()).andStubReturn(EntityType.class);
-    EasyMock.replay(entityType);
-    return entityType;
-  }
-
-  private GetEntityUriInfo getEntityUriInfo() {
-    GetEntityUriInfo getEntityView = EasyMock.createMock(GetEntityUriInfo.class);
-    EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
-    EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
-    try {
-      EasyMock.expect(getEntityView.getExpand()).andStubReturn(null);
-      EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>());
-      EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
-      EasyMock.expect(edmEntitySet.getName()).andStubReturn(SALES_ORDER_HEADERS);
-
-      EasyMock.expect(getEntityView.getSelect()).andStubReturn(null);
-      EasyMock.expect(getEntityView.getTargetEntitySet()).andStubReturn(edmEntitySet);
-      EasyMock.expect(edmEntityType.getPropertyNames()).andStubReturn(getLocalPropertyNames());
-      EasyMock.expect(edmEntityType.getProperty(SO_ID)).andStubReturn(getEdmTypedMockedObj(SO_ID));
-
-      EasyMock.expect(edmEntityType.getMapping()).andStubReturn((EdmMapping) getEdmMappingMockedObj(SALES_ORDER));
-
-      EasyMock.expect(edmEntityType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
-      EasyMock.expect(edmEntityType.getNamespace()).andStubReturn(SALES_ORDER_HEADERS);
-      EasyMock.expect(edmEntityType.getName()).andStubReturn(SALES_ORDER_HEADERS);
-      EasyMock.expect(edmEntityType.hasStream()).andStubReturn(false);
-      EasyMock.expect(edmEntityType.getNavigationPropertyNames()).andStubReturn(new ArrayList<String>());
-      EasyMock.expect(edmEntityType.getKeyPropertyNames()).andStubReturn(new ArrayList<String>());
-
-      EasyMock.expect(edmEntitySet.getEntityContainer()).andStubReturn(getLocalEdmEntityContainer());
-
-      EasyMock.replay(edmEntityType, edmEntitySet);
-      EasyMock.expect(getEntityView.getKeyPredicates()).andStubReturn(new ArrayList<KeyPredicate>());
-      List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
-      EasyMock.expect(getEntityView.getNavigationSegments()).andReturn(navigationSegments);
-      EasyMock.expect(getEntityView.getStartEntitySet()).andReturn(edmEntitySet);
-
-      EasyMock.replay(getEntityView);
-    } catch (EdmException e) {
-      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
-    }
-    return getEntityView;
-  }
-
-  private EdmEntityContainer getLocalEdmEntityContainer() {
-    EdmEntityContainer edmEntityContainer = EasyMock.createMock(EdmEntityContainer.class);
-    EasyMock.expect(edmEntityContainer.isDefaultEntityContainer()).andStubReturn(true);
-    try {
-      EasyMock.expect(edmEntityContainer.getName()).andStubReturn(SALESORDERPROCESSING_CONTAINER);
-    } catch (EdmException e) {
-      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
-    }
-
-    EasyMock.replay(edmEntityContainer);
-    return edmEntityContainer;
-  }
-
-  private EdmTyped getEdmTypedMockedObj(final String propertyName) {
-    EdmProperty mockedEdmProperty = EasyMock.createMock(EdmProperty.class);
-    try {
-      EasyMock.expect(mockedEdmProperty.getMapping()).andStubReturn((EdmMapping) getEdmMappingMockedObj(propertyName));
-      EdmType edmType = EasyMock.createMock(EdmType.class);
-      EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
-      EasyMock.replay(edmType);
-      EasyMock.expect(mockedEdmProperty.getName()).andStubReturn("identifier");
-      EasyMock.expect(mockedEdmProperty.getType()).andStubReturn(edmType);
-      EasyMock.expect(mockedEdmProperty.getFacets()).andStubReturn(getEdmFacetsMockedObj());
-
-      EasyMock.replay(mockedEdmProperty);
-    } catch (EdmException e) {
-      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
-    }
-    return mockedEdmProperty;
-  }
-
-  private EdmFacets getEdmFacetsMockedObj() {
-    EdmFacets facets = EasyMock.createMock(EdmFacets.class);
-    EasyMock.expect(facets.getConcurrencyMode()).andStubReturn(EdmConcurrencyMode.Fixed);
-
-    EasyMock.replay(facets);
-    return facets;
-  }
-
-  private JPAEdmMapping getEdmMappingMockedObj(final String propertyName) {
-    JPAEdmMappingImpl mockedEdmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
-    if (propertyName.equalsIgnoreCase(SALES_ORDER)) {
-      EasyMock.expect(((EdmMapping) mockedEdmMapping).getInternalName()).andStubReturn(SALES_ORDER_HEADERS);
-    } else {
-      EasyMock.expect(((EdmMapping) mockedEdmMapping).getInternalName()).andStubReturn(propertyName);
-    }
-    EasyMock.expect(mockedEdmMapping.getODataJPATombstoneEntityListener()).andReturn(null);
-    EasyMock.<Class<?>> expect(mockedEdmMapping.getJPAType()).andReturn(SalesOrderHeader.class);
-    EasyMock.replay(mockedEdmMapping);
-    return mockedEdmMapping;
-  }
-
-  private List<String> getLocalPropertyNames() {
-    List<String> list = new ArrayList<String>();
-    list.add(SO_ID);
-    return list;
-  }
-
-  private ODataContext getLocalODataContext() {
-    ODataContext objODataContext = null;
-    try {
-      ODataContextMock contextMock = new ODataContextMock();
-      contextMock.setODataService(new ODataServiceMock().mock());
-      contextMock.setPathInfo(getLocalPathInfo());
-      objODataContext = contextMock.mock();
-
-    } catch (ODataException e) {
-      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
-    }
-    return objODataContext;
-  }
-
-  private PathInfo getLocalPathInfo() {
-    PathInfo pathInfo = EasyMock.createMock(PathInfo.class);
-    EasyMock.expect(pathInfo.getServiceRoot()).andStubReturn(getLocalURI());
-    EasyMock.replay(pathInfo);
-    return pathInfo;
-  }
-
-  private URI getLocalURI() {
-    URI uri = null;
-    try {
-      uri = new URI(STR_LOCAL_URI);
-    } catch (URISyntaxException e) {
-      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
-    }
-    return uri;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/03457349/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java
index 4a00340..6422a97 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java
@@ -80,7 +80,7 @@ import org.junit.Test;
 public class JPAProcessorImplTest {
 
   // -------------------------------- Common Start ------------------------------------common in
-  // ODataJPAProcessorDefaultTest as well
+  // ODataJPADefaultProcessorTest as well
   private static final String STR_LOCAL_URI = "http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/";
   private static final String SALESORDERPROCESSING_CONTAINER = "salesorderprocessingContainer";
   private static final String SO_ID = "SoId";
@@ -152,7 +152,7 @@ public class JPAProcessorImplTest {
     }
   }
 
-  // ---------------------------- Common Code Start ---------------- TODO - common in ODataJPAProcessorDefaultTest as
+  // ---------------------------- Common Code Start ---------------- TODO - common in ODataJPADefaultProcessorTest as
   // well
 
   private DeleteUriInfo getDeletetUriInfo() {


[3/3] olingo-odata2 git commit: [OLINGO-1018] Merge branch 'OLINGO-1018-JPA_API_DefaultProcessor'

Posted by mi...@apache.org.
[OLINGO-1018] Merge branch 'OLINGO-1018-JPA_API_DefaultProcessor'


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

Branch: refs/heads/master
Commit: ed07b2deae24f4275bdc138039dcf95ef54084f7
Parents: c1b1a60 0345734
Author: mibo <mi...@apache.org>
Authored: Mon Oct 24 22:27:46 2016 +0200
Committer: mibo <mi...@apache.org>
Committed: Mon Oct 24 22:35:06 2016 +0200

----------------------------------------------------------------------
 .../processor/api/ODataJPADefaultProcessor.java | 301 ++++++++++
 .../processor/api/ODataJPAServiceFactory.java   |  10 +-
 .../core/ODataJPAProcessorDefault.java          | 308 ----------
 .../core/factory/ODataJPAFactoryImpl.java       |   4 +-
 .../core/ODataJPADefaultProcessorTest.java      | 588 +++++++++++++++++++
 .../core/ODataJPAProcessorDefaultTest.java      | 587 ------------------
 .../core/access/data/JPAProcessorImplTest.java  |   4 +-
 .../ref/util/CustomODataJPAProcessor.java       |  57 ++
 .../ref/web/JPAReferenceServiceFactory.java     |   8 +
 9 files changed, 966 insertions(+), 901 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ed07b2de/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPADefaultProcessor.java
----------------------------------------------------------------------
diff --cc odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPADefaultProcessor.java
index 0000000,e562dc7..848293e
mode 000000,100644..100644
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPADefaultProcessor.java
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPADefaultProcessor.java
@@@ -1,0 -1,293 +1,301 @@@
+ /*******************************************************************************
+  * 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.odata2.jpa.processor.api;
+ 
+ import org.apache.olingo.odata2.api.batch.BatchHandler;
+ import org.apache.olingo.odata2.api.batch.BatchRequestPart;
+ import org.apache.olingo.odata2.api.batch.BatchResponsePart;
+ import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+ import org.apache.olingo.odata2.api.ep.EntityProvider;
+ import org.apache.olingo.odata2.api.ep.EntityProviderBatchProperties;
+ import org.apache.olingo.odata2.api.exception.ODataException;
+ import org.apache.olingo.odata2.api.processor.ODataRequest;
+ import org.apache.olingo.odata2.api.processor.ODataResponse;
+ import org.apache.olingo.odata2.api.uri.PathInfo;
 -import org.apache.olingo.odata2.api.uri.info.*;
 -
++import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
++import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
++import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
++import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
++import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
++import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
++import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
++import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
++import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
++import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
+ import java.io.InputStream;
+ import java.util.ArrayList;
+ import java.util.List;
+ 
+ public abstract class ODataJPADefaultProcessor extends ODataJPAProcessor {
+ 
+   public ODataJPADefaultProcessor(final ODataJPAContext oDataJPAContext) {
+     super(oDataJPAContext);
+   }
+ 
+   @Override
+   public ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType)
+       throws ODataException {
+     ODataResponse oDataResponse = null;
+     try {
+       oDataJPAContext.setODataContext(getContext());
+       List<Object> jpaEntities = jpaProcessor.process(uriParserResultView);
+       oDataResponse =
+           responseBuilder.build(uriParserResultView, jpaEntities, contentType);
+     } finally {
+       close();
+     }
+     return oDataResponse;
+   }
+ 
+   @Override
+   public ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType)
+       throws ODataException {
+     ODataResponse oDataResponse = null;
+     try {
+       oDataJPAContext.setODataContext(getContext());
+       Object jpaEntity = jpaProcessor.process(uriParserResultView);
+       oDataResponse =
+           responseBuilder.build(uriParserResultView, jpaEntity, contentType);
+     } finally {
+       close();
+     }
+     return oDataResponse;
+   }
+ 
+   @Override
+   public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType)
+       throws ODataException {
+     ODataResponse oDataResponse = null;
+     try {
+       oDataJPAContext.setODataContext(getContext());
+       long jpaEntityCount = jpaProcessor.process(uriParserResultView);
+       oDataResponse = responseBuilder.build(jpaEntityCount);
+     } finally {
+       close();
+     }
+     return oDataResponse;
+   }
+ 
+   @Override
+   public ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType)
+       throws ODataException {
+     ODataResponse oDataResponse = null;
+     try {
+       oDataJPAContext.setODataContext(getContext());
+       long jpaEntityCount = jpaProcessor.process(uriInfo);
+       oDataResponse = responseBuilder.build(jpaEntityCount);
+     } finally {
+       close();
+     }
+     return oDataResponse;
+   }
+ 
+   @Override
+   public ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content,
+       final String requestContentType, final String contentType) throws ODataException {
+     ODataResponse oDataResponse = null;
+     try {
+       oDataJPAContext.setODataContext(getContext());
+       Object createdJpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType);
+       oDataResponse =
+           responseBuilder.build(uriParserResultView, createdJpaEntity, contentType);
+     } finally {
+       close();
+     }
+     return oDataResponse;
+   }
+ 
+   @Override
+   public ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content,
+       final String requestContentType, final boolean merge, final String contentType) throws ODataException {
+     ODataResponse oDataResponse = null;
+     try {
+       oDataJPAContext.setODataContext(getContext());
+       Object jpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType);
+       oDataResponse = responseBuilder.build(uriParserResultView, jpaEntity);
+     } finally {
+       close();
+     }
+     return oDataResponse;
+   }
+ 
+   @Override
+   public ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType)
+       throws ODataException {
+     ODataResponse oDataResponse = null;
+     try {
+       oDataJPAContext.setODataContext(getContext());
+       Object deletedObj = jpaProcessor.process(uriParserResultView, contentType);
+       oDataResponse = responseBuilder.build(uriParserResultView, deletedObj);
+     } finally {
+       close();
+     }
+     return oDataResponse;
+   }
+ 
+   @Override
+   public ODataResponse executeFunctionImport(final GetFunctionImportUriInfo uriParserResultView,
+       final String contentType) throws ODataException {
+     ODataResponse oDataResponse = null;
+     try {
+       oDataJPAContext.setODataContext(getContext());
+       List<Object> resultEntity = jpaProcessor.process(uriParserResultView);
+       oDataResponse =
+           responseBuilder.build(uriParserResultView, resultEntity, contentType);
+     } finally {
+       close();
+     }
+     return oDataResponse;
+   }
+ 
+   @Override
+   public ODataResponse executeFunctionImportValue(final GetFunctionImportUriInfo uriParserResultView,
+       final String contentType) throws ODataException {
+     ODataResponse oDataResponse = null;
+     try {
+       oDataJPAContext.setODataContext(getContext());
+       List<Object> result = jpaProcessor.process(uriParserResultView);
+       oDataResponse =
+           responseBuilder.build(uriParserResultView, result.get(0));
+     } finally {
+       close();
+     }
+     return oDataResponse;
+   }
+ 
+   @Override
+   public ODataResponse readEntityLink(final GetEntityLinkUriInfo uriParserResultView, final String contentType)
+       throws ODataException {
+     ODataResponse oDataResponse = null;
+     try {
+       oDataJPAContext.setODataContext(getContext());
+       Object jpaEntity = jpaProcessor.process(uriParserResultView);
+       oDataResponse =
+           responseBuilder.build(uriParserResultView, jpaEntity, contentType);
+     } finally {
+       close();
+     }
+     return oDataResponse;
+   }
+ 
+   @Override
+   public ODataResponse readEntityLinks(final GetEntitySetLinksUriInfo uriParserResultView, final String contentType)
+       throws ODataException {
+     ODataResponse oDataResponse = null;
+     try {
+       oDataJPAContext.setODataContext(getContext());
+       List<Object> jpaEntity = jpaProcessor.process(uriParserResultView);
+       oDataResponse =
+           responseBuilder.build(uriParserResultView, jpaEntity, contentType);
+     } finally {
+       close();
+     }
+     return oDataResponse;
+   }
+ 
+   @Override
+   public ODataResponse createEntityLink(final PostUriInfo uriParserResultView, final InputStream content,
+       final String requestContentType, final String contentType) throws ODataException {
+     try {
+       oDataJPAContext.setODataContext(getContext());
+       jpaProcessor.process(uriParserResultView, content, requestContentType, contentType);
+       return ODataResponse.newBuilder().build();
+     } finally {
+       close();
+     }
+   }
+ 
+   @Override
+   public ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content,
+       final String requestContentType, final String contentType) throws ODataException {
+     try {
+       oDataJPAContext.setODataContext(getContext());
+       jpaProcessor.process(uriParserResultView, content, requestContentType, contentType);
+       return ODataResponse.newBuilder().build();
+     } finally {
+       close();
+     }
+   }
+ 
+   @Override
+   public ODataResponse deleteEntityLink(final DeleteUriInfo uriParserResultView, final String contentType)
+       throws ODataException {
+     try {
+       oDataJPAContext.setODataContext(getContext());
+       jpaProcessor.process(uriParserResultView, contentType);
+       return ODataResponse.newBuilder().build();
+     } finally {
+       close();
+     }
+   }
+ 
+   @Override
+   public ODataResponse executeBatch(final BatchHandler handler, final String contentType, final InputStream content)
+       throws ODataException {
+     try {
+       oDataJPAContext.setODataContext(getContext());
+ 
+       ODataResponse batchResponse;
+       List<BatchResponsePart> batchResponseParts = new ArrayList<BatchResponsePart>();
+       PathInfo pathInfo = getContext().getPathInfo();
+       EntityProviderBatchProperties batchProperties = EntityProviderBatchProperties.init().pathInfo(pathInfo).build();
+       List<BatchRequestPart> batchParts = EntityProvider.parseBatchRequest(contentType, content, batchProperties);
+ 
+       for (BatchRequestPart batchPart : batchParts) {
+         batchResponseParts.add(handler.handleBatchPart(batchPart));
+       }
+       batchResponse = EntityProvider.writeBatchResponse(batchResponseParts);
+       return batchResponse;
+     } finally {
+       close(true);
+     }
+   }
+ 
+   @Override
+   public BatchResponsePart executeChangeSet(final BatchHandler handler, final List<ODataRequest> requests)
+       throws ODataException {
+     List<ODataResponse> responses = new ArrayList<ODataResponse>();
+     try {
+       oDataJPAContext.getODataJPATransaction().begin();
+ 
+       for (ODataRequest request : requests) {
+         oDataJPAContext.setODataContext(getContext());
+         ODataResponse response = handler.handleRequest(request);
+         if (response.getStatus().getStatusCode() >= HttpStatusCodes.BAD_REQUEST.getStatusCode()) {
+           // Rollback
+           oDataJPAContext.getODataJPATransaction().rollback();
+           List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1);
+           errorResponses.add(response);
+           return BatchResponsePart.responses(errorResponses).changeSet(false).build();
+         }
+         responses.add(response);
+       }
+       oDataJPAContext.getODataJPATransaction().commit();
+ 
+       return BatchResponsePart.responses(responses).changeSet(true).build();
+     } catch (Exception e) {
+ 
+       List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1);
+       errorResponses.add(ODataResponse.entity(e).status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build());
+       return BatchResponsePart.responses(errorResponses).changeSet(false).build();
+     } finally {
+       close(true);
+     }
+   }
+ }