You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by tb...@apache.org on 2014/01/02 13:47:12 UTC
[25/47] [OLINGO-99] Re-factor Package Names. Following are the changes
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/resources/jpaprocessor_msg.properties
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/resources/jpaprocessor_msg.properties b/odata2-jpa-processor/jpa-core/src/main/resources/jpaprocessor_msg.properties
index 5eb96fb..db8d857 100644
--- a/odata2-jpa-processor/jpa-core/src/main/resources/jpaprocessor_msg.properties
+++ b/odata2-jpa-processor/jpa-core/src/main/resources/jpaprocessor_msg.properties
@@ -20,42 +20,42 @@
#
#JPA EDM Provider Errors
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.GENERAL="OData - JPA Metadata: Internal error [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.INNER_EXCEPTION="%1$s: %2$s.\n"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.INVALID_ENTITY_TYPE="OData - JPA Model Processor: Invalid Entity Type [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.INVALID_COMPLEX_TYPE="OData - JPA Model Processor: Invalid Complex Type [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.INVALID_ASSOCIATION ="OData - JPA Model Processor: Invalid Association [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.INVALID_ENTITYSET="OData - JPA Model Processor: Invalid Entity set [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.INVALID_ENTITYCONTAINER="OData - JPA Model Processor: Invalid Entity Container [%1$s]"
-org.apache.olingo.odata2.processor.jap.exception.ODataJPAModelException.INVALID_ASSOCIATION_SET="OData - JPA Model Processor: Invalid Association Set [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.INVALID_FUNC_IMPORT="OData - JPA Model Processor: Invalid Function Import [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.BUILDER_NULL="OData - JPA Model Processor: JPA Builder not initialized"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.FUNC_ENTITYSET_EXP="OData - JPA Model Processor: Entity Set expected for Function Import with return type as Entity Type with Multiplicity Many"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.FUNC_RETURN_TYPE_EXP="OData - JPA Model Processor: Return type expected. Class: [%1$s], Method: [%2$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND="OData - JPA Model Processor: Return type not found. Class: [%1$s], Method: [%2$s], Type: [%3$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.FUNC_PARAM_NAME_EXP="OData - JPA Model Processor: Parameter Name for function import expected. Class: [%1$s]", Method: [%2$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.GENERAL="OData - JPA Metadata: Internal error [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.INNER_EXCEPTION="%1$s: %2$s.\n"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.INVALID_ENTITY_TYPE="OData - JPA Model Processor: Invalid Entity Type [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.INVALID_COMPLEX_TYPE="OData - JPA Model Processor: Invalid Complex Type [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.INVALID_ASSOCIATION ="OData - JPA Model Processor: Invalid Association [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.INVALID_ENTITYSET="OData - JPA Model Processor: Invalid Entity set [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.INVALID_ENTITYCONTAINER="OData - JPA Model Processor: Invalid Entity Container [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.INVALID_ASSOCIATION_SET="OData - JPA Model Processor: Invalid Association Set [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.INVALID_FUNC_IMPORT="OData - JPA Model Processor: Invalid Function Import [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.BUILDER_NULL="OData - JPA Model Processor: JPA Builder not initialized"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.FUNC_ENTITYSET_EXP="OData - JPA Model Processor: Entity Set expected for Function Import with return type as Entity Type with Multiplicity Many"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.FUNC_RETURN_TYPE_EXP="OData - JPA Model Processor: Return type expected. Class: [%1$s], Method: [%2$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND="OData - JPA Model Processor: Return type not found. Class: [%1$s], Method: [%2$s], Type: [%3$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.FUNC_PARAM_NAME_EXP="OData - JPA Model Processor: Parameter Name for function import expected. Class: [%1$s]", Method: [%2$s]"
#JPA Type converter Errors
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.TYPE_NOT_SUPPORTED="OData - JPA Type Converter: Type [%1$s] not supported"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.TYPE_NOT_SUPPORTED="OData - JPA Type Converter: Type [%1$s] not supported"
#JPA Runtime Errors
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ENTITY_MANAGER_NOT_INITIALIZED="OData - JPA Service Factory: Java Persistence Entity Manager not initialized"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.GENERAL="OData - JPA Runtime: Internal error [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.INNER_EXCEPTION="%1$s: %2$s.\n"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.JOIN_CLAUSE_EXPECTED="OData - JPA Runtime: Join Clause expected"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.RESOURCE_NOT_FOUND="OData - JPA Runtime: Resource not found"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_ODATA_FILTER_CONDITION="OData - JPA Runtime: Filter condition not correct"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE="OData - JPA Runtime: JPA query syntax is not correct"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQL_CREATE_REQUEST="OData - JPA Runtime: JPA create request is not correct"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQL_UPDATE_REQUEST="OData - JPA Runtime: JPA update request is not correct"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQL_DELETE_REQUEST="OData - JPA Runtime: JPA delete URL is not correct"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQL_KEY_VALUE="Key parameter value is not correct for [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQL_PARAM_VALUE="Parameter value is not correct for [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQL_UNIQUE_CONSTRAINT="Violation of unique constraint"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQL_INTEGRITY_CONSTRAINT="Integrity constraint violation"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.RELATIONSHIP_INVALID="OData - JPA Runtime: Invalid link"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.RESOURCE_X_NOT_FOUND="OData - JPA Runtime: Resource [%1$s] not found"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ENTITY_MANAGER_NOT_INITIALIZED="OData - JPA Service Factory: Java Persistence Entity Manager not initialized"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.GENERAL="OData - JPA Runtime: Internal error [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.INNER_EXCEPTION="%1$s: %2$s.\n"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.JOIN_CLAUSE_EXPECTED="OData - JPA Runtime: Join Clause expected"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.RESOURCE_NOT_FOUND="OData - JPA Runtime: Resource not found"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_ODATA_FILTER_CONDITION="OData - JPA Runtime: Filter condition not correct"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE="OData - JPA Runtime: JPA query syntax is not correct"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQL_CREATE_REQUEST="OData - JPA Runtime: JPA create request is not correct"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQL_UPDATE_REQUEST="OData - JPA Runtime: JPA update request is not correct"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQL_DELETE_REQUEST="OData - JPA Runtime: JPA delete URL is not correct"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQL_KEY_VALUE="Key parameter value is not correct for [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQL_PARAM_VALUE="Parameter value is not correct for [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQL_UNIQUE_CONSTRAINT="Violation of unique constraint"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQL_INTEGRITY_CONSTRAINT="Integrity constraint violation"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.RELATIONSHIP_INVALID="OData - JPA Runtime: Invalid link"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.RESOURCE_X_NOT_FOUND="OData - JPA Runtime: Resource [%1$s] not found"
#JPA Common Errors
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAException.ODATA_JPACTX_NULL="OData JPA: OData JPA Context cannot be null"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQLCTXBLDR_CREATE="OData JPA: Error creating JPQL Context Builder"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAException.ODATA_JPACTX_NULL="OData JPA: OData JPA Context cannot be null"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQLCTXBLDR_CREATE="OData JPA: Error creating JPQL Context Builder"
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParserTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParserTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParserTest.java
new file mode 100644
index 0000000..c0d364c
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParserTest.java
@@ -0,0 +1,516 @@
+/*******************************************************************************
+ * 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.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFacets;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+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.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.expression.BinaryExpression;
+import org.apache.olingo.odata2.api.uri.expression.BinaryOperator;
+import org.apache.olingo.odata2.api.uri.expression.CommonExpression;
+import org.apache.olingo.odata2.api.uri.expression.ExpressionKind;
+import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
+import org.apache.olingo.odata2.api.uri.expression.LiteralExpression;
+import org.apache.olingo.odata2.api.uri.expression.MemberExpression;
+import org.apache.olingo.odata2.api.uri.expression.MethodExpression;
+import org.apache.olingo.odata2.api.uri.expression.MethodOperator;
+import org.apache.olingo.odata2.api.uri.expression.PropertyExpression;
+import org.apache.olingo.odata2.api.uri.expression.UnaryExpression;
+import org.apache.olingo.odata2.api.uri.expression.UnaryOperator;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.ODataExpressionParser;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+public class ODataExpressionParserTest {
+
+ private static final String EXPECTED_STR_1 = "gwt1.SalesOrder = 1234";
+ private static final String EXPECTED_STR_2 = "gwt1.SalesOrder >= 1234 AND gwt1.SalesABC <> XYZ";
+ private static final String EXPECTED_STR_3 = "gwt1.SalesOrder >= 1234 OR gwt1.SalesABC <> XYZ";
+ private static final String EXPECTED_STR_4 = "gwt1.SalesOrder < 1234 AND gwt1.SalesABC <= XYZ";
+ private static final String EXPECTED_STR_5 = "gwt1.LineItems > 2345 AND gwt1.SalesOrder >= Amazon";
+ private static final String EXPECTED_STR_6 = "gwt1.Address.city = \'City_3\'";
+ private static final String EXPECTED_STR_7 = "gwt1.Address.city.area = \'BTM\'";
+ private static final String EXPECTED_STR_8 = "gwt1.field1 = 1 AND gwt1.field2 = 'abc'";
+ private static final String EXPECTED_STR_9 = "gwt1.BuyerAddress, gwt1.BuyerName, gwt1.BuyerId";
+ private static final String EXPECTED_STR_10 = "gwt1.SalesOrder";
+ private static final String EXPECTED_STR_11 = "NOT(gwt1.deliveryStatus)";
+ private static final String EXPECTED_STR_12 =
+ "(CASE WHEN (gwt1.currencyCode LIKE '%Ru%') THEN TRUE ELSE FALSE END) = true";
+ private static final String EXPECTED_STR_13 = "SUBSTRING(gwt1.currencyCode, 1 + 1 , 2) = 'NR'";
+ private static final String EXPECTED_STR_14 = "LOWER(gwt1.currencyCode) = 'inr rupees'";
+ private static final String EXPECTED_STR_15 =
+ "(CASE WHEN (LOWER(gwt1.currencyCode) LIKE '%nr rupees%') THEN TRUE ELSE FALSE END) = true";
+ private static final String EXPECTED_STR_16 =
+ "(CASE WHEN (gwt1.currencyCode LIKE '%INR%') THEN TRUE ELSE FALSE END) = true";
+ private static final String EXPECTED_STR_17 =
+ "(CASE WHEN (LOWER(gwt1.currencyCode) LIKE '%nr rupees%') THEN TRUE ELSE FALSE END) = true";
+
+ private static final String ADDRESS = "Address";
+ private static final String CITY = "city";
+ private static final String AREA = "area";
+ private static final String SALES_ORDER = "SalesOrder";
+ private static final String SALES_ABC = "SalesABC";
+ private static final String SAMPLE_DATA_1 = "1234";
+ private static final String SAMPLE_DATA_2 = "2345";
+ private static final String SAMPLE_DATA_XYZ = "XYZ";
+ private static final String SAMPLE_DATA_BTM = "\'BTM\'";
+ private static final String SAMPLE_DATA_CITY_3 = "\'City_3\'";
+ private static final String SAMPLE_DATA_LINE_ITEMS = "LineItems";
+ private static final String SAMPLE_DATA_AMAZON = "Amazon";
+ private static final String SAMPLE_DATA_FIELD1 = "field1";
+ private static final String SAMPLE_DATA_FIELD2 = "field2";
+
+ private static final String TABLE_ALIAS = "gwt1"; //$NON-NLS-1$
+
+ @Test
+ public void testParseWhereExpression() {
+ try {
+ String parsedStr = ODataJPATestConstants.EMPTY_STRING;
+ // Simple Binary query -
+ parsedStr =
+ ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpressionMockedObj(BinaryOperator.EQ,
+ ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1), TABLE_ALIAS);
+
+ assertEquals(EXPECTED_STR_1, parsedStr);
+ // complex query -
+ parsedStr = ODataJPATestConstants.EMPTY_STRING;
+
+ CommonExpression exp1 =
+ getBinaryExpressionMockedObj(BinaryOperator.GE, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1);
+ CommonExpression exp2 =
+ getBinaryExpressionMockedObj(BinaryOperator.NE, ExpressionKind.PROPERTY, SALES_ABC, SAMPLE_DATA_XYZ);
+ parsedStr =
+ ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(exp1, BinaryOperator.AND, exp2),
+ TABLE_ALIAS);
+ assertEquals(EXPECTED_STR_2, parsedStr);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testMoreThanOneBinaryExpression() {
+ // complex query -
+ String parsedStr = ODataJPATestConstants.EMPTY_STRING;
+ CommonExpression exp1 =
+ getBinaryExpressionMockedObj(BinaryOperator.GE, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1);
+ CommonExpression exp2 =
+ getBinaryExpressionMockedObj(BinaryOperator.NE, ExpressionKind.PROPERTY, SALES_ABC, SAMPLE_DATA_XYZ);
+ try {
+ parsedStr =
+ ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(exp1, BinaryOperator.AND, exp2),
+ TABLE_ALIAS);
+ assertEquals(EXPECTED_STR_2, parsedStr);
+ parsedStr =
+ ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(exp1, BinaryOperator.OR, exp2),
+ TABLE_ALIAS);
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertEquals(EXPECTED_STR_3, parsedStr);
+ }
+
+ @Test
+ public void testParseFilterExpression() {
+ try {
+ assertEquals(EXPECTED_STR_10, ODataExpressionParser.parseToJPAWhereExpression(getFilterExpressionMockedObj(
+ ExpressionKind.PROPERTY, SALES_ORDER), TABLE_ALIAS));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testAllBinaryOperators() { // Test for all Binary Operators
+ // complex query -
+ String parsedStr1 = ODataJPATestConstants.EMPTY_STRING;
+ String parsedStr2 = ODataJPATestConstants.EMPTY_STRING;
+
+ CommonExpression exp1 =
+ getBinaryExpressionMockedObj(BinaryOperator.LT, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1);
+ CommonExpression exp2 =
+ getBinaryExpressionMockedObj(BinaryOperator.LE, ExpressionKind.PROPERTY, SALES_ABC, SAMPLE_DATA_XYZ);
+
+ try {
+ parsedStr1 =
+ ODataExpressionParser.parseToJPAWhereExpression((BinaryExpression) getBinaryExpression(exp1,
+ BinaryOperator.AND, exp2), TABLE_ALIAS);
+ assertEquals(EXPECTED_STR_4, parsedStr1);
+
+ CommonExpression exp3 =
+ getBinaryExpressionMockedObj(BinaryOperator.GT, ExpressionKind.PROPERTY, SAMPLE_DATA_LINE_ITEMS,
+ SAMPLE_DATA_2);
+ CommonExpression exp4 =
+ getBinaryExpressionMockedObj(BinaryOperator.GE, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_AMAZON);
+
+ parsedStr2 =
+ ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(exp3, BinaryOperator.AND, exp4),
+ TABLE_ALIAS);
+
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertEquals(EXPECTED_STR_5, parsedStr2);
+ }
+
+ @Test
+ public void testParseMemberExpression() {
+ try {
+ assertEquals(EXPECTED_STR_6, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
+ getMemberExpressionMockedObj(ADDRESS, CITY), BinaryOperator.EQ,
+ getLiteralExpressionMockedObj(SAMPLE_DATA_CITY_3)), TABLE_ALIAS));
+ assertEquals(EXPECTED_STR_7, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
+ getMultipleMemberExpressionMockedObj(ADDRESS, CITY, AREA), BinaryOperator.EQ,
+ getLiteralExpressionMockedObj(SAMPLE_DATA_BTM)), TABLE_ALIAS));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testParseMethodExpression() {
+ try {
+ assertEquals(EXPECTED_STR_12, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
+ getMethodExpressionMockedObj(MethodOperator.SUBSTRINGOF, "'Ru'", "currencyCode", null, 2), BinaryOperator.EQ,
+ getLiteralExpressionMockedObj("true")), TABLE_ALIAS));
+ assertEquals(EXPECTED_STR_13, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
+ getMethodExpressionMockedObj(MethodOperator.SUBSTRING, "currencyCode", "1", "2", 3), BinaryOperator.EQ,
+ getLiteralExpressionMockedObj("'NR'")), TABLE_ALIAS));
+ assertEquals(EXPECTED_STR_14, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
+ getMethodExpressionMockedObj(MethodOperator.TOLOWER, "currencyCode", null, null, 1), BinaryOperator.EQ,
+ getLiteralExpressionMockedObj("'inr rupees'")), TABLE_ALIAS));
+ assertEquals(EXPECTED_STR_15, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
+ getMultipleMethodExpressionMockedObj(MethodOperator.SUBSTRINGOF, "'nr rupees'", MethodOperator.TOLOWER,
+ "currencyCode", 2, 1), BinaryOperator.EQ, getLiteralExpressionMockedObj("true")), TABLE_ALIAS));
+ assertEquals(EXPECTED_STR_16, ODataExpressionParser.parseToJPAWhereExpression(
+ getFilterExpressionForFunctionsMockedObj(MethodOperator.SUBSTRINGOF, "'INR'", null, "currencyCode", 2, null)
+ /*
+ * getBinaryExpression(
+ * getMemberExpressionMockedObj(ADDRESS,
+ * CITY),
+ * BinaryOperator.EQ,
+ * getLiteralExpressionMockedObj(SAMPLE_DATA_CITY_3))
+ */, TABLE_ALIAS));
+ assertEquals(EXPECTED_STR_17, ODataExpressionParser.parseToJPAWhereExpression(
+ getFilterExpressionForFunctionsMockedObj(MethodOperator.SUBSTRINGOF, "'nr rupees'", MethodOperator.TOLOWER,
+ "currencyCode", 2, 1)
+ /*
+ * getBinaryExpression(
+ * getMemberExpressionMockedObj(ADDRESS,
+ * CITY),
+ * BinaryOperator.EQ,
+ * getLiteralExpressionMockedObj(SAMPLE_DATA_CITY_3))
+ */, TABLE_ALIAS));
+
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ private CommonExpression getMethodExpressionMockedObj(final MethodOperator methodOperator, final String firstName,
+ final String secondName, final String thirdName, final Integer parameterCount) {
+
+ List<CommonExpression> parameters = new ArrayList<CommonExpression>();
+
+ if (methodOperator == MethodOperator.SUBSTRINGOF) {
+ parameters.add(getLiteralExpressionMockedObj(firstName));
+ parameters.add(getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, secondName));
+ } else if (methodOperator == MethodOperator.SUBSTRING) {
+ parameters.add(getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, firstName));
+ parameters.add(getLiteralExpressionMockedObj(secondName));
+ parameters.add(getLiteralExpressionMockedObj(thirdName));
+ } else if (methodOperator == MethodOperator.TOLOWER) {
+ parameters.add(getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, firstName));
+ }
+
+ MethodExpression methodExpression = EasyMock.createMock(MethodExpression.class);
+
+ EasyMock.expect(methodExpression.getKind()).andStubReturn(ExpressionKind.METHOD);
+ EasyMock.expect(methodExpression.getMethod()).andStubReturn(methodOperator);
+ EasyMock.expect(methodExpression.getParameterCount()).andStubReturn(parameterCount);
+ EasyMock.expect(methodExpression.getParameters()).andStubReturn(parameters);
+ EasyMock.replay(methodExpression);
+
+ return methodExpression;
+ }
+
+ private CommonExpression getMultipleMethodExpressionMockedObj(final MethodOperator methodOperator1,
+ final String firstName, final MethodOperator methodOperator2, final String secondName,
+ final Integer parameterCount1, final Integer parameterCount2) {
+
+ // complex query
+ List<CommonExpression> parameters = new ArrayList<CommonExpression>();
+
+ parameters.add(getLiteralExpressionMockedObj(firstName));
+ parameters.add(getMethodExpressionMockedObj(methodOperator2, secondName, null, null, 1));
+
+ MethodExpression methodExpression = EasyMock.createMock(MethodExpression.class);
+
+ EasyMock.expect(methodExpression.getKind()).andStubReturn(ExpressionKind.METHOD);
+ EasyMock.expect(methodExpression.getMethod()).andStubReturn(methodOperator1);
+ EasyMock.expect(methodExpression.getParameterCount()).andStubReturn(parameterCount1);
+ EasyMock.expect(methodExpression.getParameters()).andStubReturn(parameters);
+ EasyMock.replay(methodExpression);
+
+ return methodExpression;
+ }
+
+ private CommonExpression getMultipleMemberExpressionMockedObj(final String string1, final String string2,
+ final String string3) {
+
+ MemberExpression memberExpression = EasyMock.createMock(MemberExpression.class);
+
+ EasyMock.expect(memberExpression.getPath()).andStubReturn(getMemberExpressionMockedObj(string1, string2));
+ EasyMock.expect(memberExpression.getProperty()).andStubReturn(
+ getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, string3));
+ EasyMock.expect(memberExpression.getKind()).andStubReturn(ExpressionKind.MEMBER);
+ EasyMock.replay(memberExpression);
+
+ return memberExpression;
+ }
+
+ @Test
+ public void testParseUnaryExpression() {
+
+ UnaryExpression unaryExpression =
+ getUnaryExpressionMockedObj(getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, "deliveryStatus"),
+ org.apache.olingo.odata2.api.uri.expression.UnaryOperator.NOT);
+ try {
+ assertEquals(EXPECTED_STR_11, ODataExpressionParser.parseToJPAWhereExpression(unaryExpression, TABLE_ALIAS));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ private UnaryExpression
+ getUnaryExpressionMockedObj(final CommonExpression operand, final UnaryOperator unaryOperator) {
+ UnaryExpression unaryExpression = EasyMock.createMock(UnaryExpression.class);
+ EasyMock.expect(unaryExpression.getKind()).andStubReturn(ExpressionKind.UNARY);
+ EasyMock.expect(unaryExpression.getOperand()).andStubReturn(operand);
+ EasyMock.expect(unaryExpression.getOperator()).andStubReturn(unaryOperator);
+
+ EasyMock.replay(unaryExpression);
+ return unaryExpression;
+ }
+
+ private CommonExpression getMemberExpressionMockedObj(final String pathUriLiteral, final String propertyUriLiteral) {
+ MemberExpression memberExpression = EasyMock.createMock(MemberExpression.class);
+ EasyMock.expect(memberExpression.getPath()).andStubReturn(
+ getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, pathUriLiteral));
+ EasyMock.expect(memberExpression.getProperty()).andStubReturn(
+ getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, propertyUriLiteral));
+ EasyMock.expect(memberExpression.getKind()).andStubReturn(ExpressionKind.MEMBER);
+
+ EasyMock.replay(memberExpression);
+ return memberExpression;
+ }
+
+ private LiteralExpression getLiteralExpressionMockedObj(final String uriLiteral) {
+ LiteralExpression rightOperandLiteralExpresion = EasyMock.createMock(LiteralExpression.class);
+ EasyMock.expect(rightOperandLiteralExpresion.getKind()).andStubReturn(ExpressionKind.LITERAL);
+ EasyMock.expect(rightOperandLiteralExpresion.getUriLiteral()).andStubReturn(uriLiteral);// SAMPLE_DATA
+ EasyMock.expect(rightOperandLiteralExpresion.getEdmType()).andStubReturn(getEdmSimpleTypeMockedObj(uriLiteral));
+ EasyMock.replay(rightOperandLiteralExpresion);
+ return rightOperandLiteralExpresion;
+
+ }
+
+ private EdmSimpleType getEdmSimpleTypeMockedObj(final String value) {
+ EdmSimpleType edmSimpleType = EasyMock.createMock(EdmSimpleType.class);
+ try {
+ EasyMock.expect(edmSimpleType.getName()).andReturn(value);
+ EasyMock.expect(edmSimpleType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.expect(edmSimpleType.valueOfString(value, EdmLiteralKind.URI, getEdmFacetsMockedObj(), null))
+ .andStubReturn(value);
+ EasyMock.expect(edmSimpleType.valueOfString(value, EdmLiteralKind.URI, null, null)).andStubReturn(value);
+ EasyMock.expect(edmSimpleType.valueToString(value, EdmLiteralKind.DEFAULT, getEdmFacetsMockedObj()))
+ .andStubReturn(value);
+ EasyMock.expect(edmSimpleType.valueToString(value, EdmLiteralKind.DEFAULT, null)).andStubReturn(value);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.expect(edmSimpleType.getDefaultType()).andStubReturn(null);
+ EasyMock.replay(edmSimpleType);
+ return edmSimpleType;
+ }
+
+ private EdmFacets getEdmFacetsMockedObj() {
+ EdmFacets facets = EasyMock.createMock(EdmFacets.class);
+
+ EasyMock.replay(facets);
+ return facets;
+ }
+
+ private PropertyExpression getPropertyExpressionMockedObj(final ExpressionKind expKind, final String propertyName) {
+ PropertyExpression leftOperandPropertyExpresion = EasyMock.createMock(PropertyExpression.class);
+ EasyMock.expect(leftOperandPropertyExpresion.getKind()).andStubReturn(ExpressionKind.PROPERTY);
+ EasyMock.expect(leftOperandPropertyExpresion.getPropertyName()).andStubReturn(propertyName);
+ EasyMock.expect(leftOperandPropertyExpresion.getEdmProperty()).andStubReturn(getEdmTypedMockedObj(propertyName));
+ EasyMock.replay(leftOperandPropertyExpresion);
+ return leftOperandPropertyExpresion;
+ }
+
+ private EdmTyped getEdmTypedMockedObj(final String propertyName) {
+ EdmProperty mockedEdmProperty = EasyMock.createMock(EdmProperty.class);
+ try {
+ EasyMock.expect(mockedEdmProperty.getMapping()).andStubReturn(getEdmMappingMockedObj(propertyName));
+ EasyMock.replay(mockedEdmProperty);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return mockedEdmProperty;
+ }
+
+ private EdmMapping getEdmMappingMockedObj(final String propertyName) {
+ EdmMapping mockedEdmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(mockedEdmMapping.getInternalName()).andStubReturn(propertyName);
+ EasyMock.replay(mockedEdmMapping);
+ return mockedEdmMapping;
+ }
+
+ private BinaryExpression getBinaryExpressionMockedObj(final BinaryOperator operator,
+ final ExpressionKind leftOperandExpKind, final String propertyName, final String literalStr) {
+ BinaryExpression binaryExpression = EasyMock.createMock(BinaryExpression.class);
+ EasyMock.expect(binaryExpression.getKind()).andStubReturn(ExpressionKind.BINARY);
+ EasyMock.expect(binaryExpression.getLeftOperand()).andStubReturn(
+ getPropertyExpressionMockedObj(leftOperandExpKind, propertyName));
+ EasyMock.expect(binaryExpression.getOperator()).andStubReturn(operator);
+ EasyMock.expect(binaryExpression.getRightOperand()).andStubReturn(getLiteralExpressionMockedObj(literalStr));
+
+ EasyMock.replay(binaryExpression);
+ return binaryExpression;
+ }
+
+ private FilterExpression getFilterExpressionMockedObj(final ExpressionKind leftOperandExpKind,
+ final String propertyName) {
+ FilterExpression filterExpression = EasyMock.createMock(FilterExpression.class);
+ EasyMock.expect(filterExpression.getKind()).andStubReturn(ExpressionKind.FILTER);
+ EasyMock.expect(filterExpression.getExpression()).andStubReturn(
+ getPropertyExpressionMockedObj(leftOperandExpKind, propertyName));
+
+ EasyMock.replay(filterExpression);
+ return filterExpression;
+ }
+
+ private FilterExpression getFilterExpressionForFunctionsMockedObj(final MethodOperator methodOperator1,
+ final String firstName, final MethodOperator methodOperator2, final String secondName,
+ final Integer parameterCount1, final Integer parameterCount2) {
+ // default value handling of SUBSTRINGOF
+ FilterExpression filterExpression = EasyMock.createMock(FilterExpression.class);
+ EasyMock.expect(filterExpression.getKind()).andStubReturn(ExpressionKind.FILTER);
+ if ((methodOperator2 != null) && (parameterCount2 != null)) {
+ EasyMock.expect(filterExpression.getExpression()).andStubReturn(
+ getMultipleMethodExpressionMockedObj(methodOperator1, firstName, methodOperator2, secondName,
+ parameterCount1, parameterCount2));
+ } else {
+ EasyMock.expect(filterExpression.getExpression()).andStubReturn(
+ getMethodExpressionMockedObj(methodOperator1, firstName, secondName, null, parameterCount1));
+ }
+
+ EasyMock.replay(filterExpression);
+ return filterExpression;
+ }
+
+ private CommonExpression getBinaryExpression(final CommonExpression leftOperand, final BinaryOperator operator,
+ final CommonExpression rightOperand) {
+ BinaryExpression binaryExpression = EasyMock.createMock(BinaryExpression.class);
+ EasyMock.expect(binaryExpression.getKind()).andStubReturn(ExpressionKind.BINARY);
+ EasyMock.expect(binaryExpression.getLeftOperand()).andStubReturn(leftOperand);
+ EasyMock.expect(binaryExpression.getRightOperand()).andStubReturn(rightOperand);
+ EasyMock.expect(binaryExpression.getOperator()).andStubReturn(operator);
+
+ EasyMock.replay(binaryExpression);
+ return binaryExpression;
+ }
+
+ @Test
+ public void testParseKeyPredicates() {
+ // Setting up the expected value
+ KeyPredicate keyPredicate1 = EasyMock.createMock(KeyPredicate.class);
+ EdmProperty kpProperty1 = EasyMock.createMock(EdmProperty.class);
+ EasyMock.expect(keyPredicate1.getLiteral()).andStubReturn("1");
+ KeyPredicate keyPredicate2 = EasyMock.createMock(KeyPredicate.class);
+ EdmProperty kpProperty2 = EasyMock.createMock(EdmProperty.class);
+ EasyMock.expect(keyPredicate2.getLiteral()).andStubReturn("abc");
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ try {
+ EasyMock.expect(kpProperty1.getName()).andStubReturn(SAMPLE_DATA_FIELD1);
+ EasyMock.expect(kpProperty1.getType()).andStubReturn(EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance());
+ EasyMock.expect(kpProperty2.getName()).andStubReturn(SAMPLE_DATA_FIELD2);
+ EasyMock.expect(kpProperty2.getType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance());
+ EasyMock.expect(keyPredicate1.getProperty()).andStubReturn(kpProperty1);
+ EasyMock.expect(kpProperty1.getMapping()).andReturn(edmMapping);
+ EasyMock.expect(edmMapping.getInternalName()).andReturn(SAMPLE_DATA_FIELD1);
+ EasyMock.expect(keyPredicate2.getProperty()).andStubReturn(kpProperty2);
+ EasyMock.expect(kpProperty2.getMapping()).andReturn(edmMapping);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.expect(edmMapping.getInternalName()).andReturn(SAMPLE_DATA_FIELD2);
+ EasyMock.replay(edmMapping);
+ EasyMock.replay(kpProperty1, keyPredicate1, kpProperty2, keyPredicate2);
+
+ ArrayList<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
+ keyPredicates.add(keyPredicate1);
+ keyPredicates.add(keyPredicate2);
+ String str = null;
+
+ try {
+ str = ODataExpressionParser.parseKeyPredicates(keyPredicates, TABLE_ALIAS);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ assertEquals(EXPECTED_STR_8, str);
+ }
+
+ @Test
+ public void testParseToJPASelectExpression() {
+
+ ArrayList<String> selectedFields = new ArrayList<String>();
+ selectedFields.add("BuyerAddress");
+ selectedFields.add("BuyerName");
+ selectedFields.add("BuyerId");
+
+ assertEquals(EXPECTED_STR_9, ODataExpressionParser.parseToJPASelectExpression(TABLE_ALIAS, selectedFields));
+ assertEquals(TABLE_ALIAS, ODataExpressionParser.parseToJPASelectExpression(TABLE_ALIAS, null));
+
+ selectedFields.clear();
+ assertEquals(TABLE_ALIAS, ODataExpressionParser.parseToJPASelectExpression(TABLE_ALIAS, selectedFields));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImplTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImplTest.java
new file mode 100644
index 0000000..fe981fc
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImplTest.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * 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.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataProcessor;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.core.ODataJPAContextImpl;
+import org.apache.olingo.odata2.jpa.processor.core.edm.ODataJPAEdmProvider;
+import org.apache.olingo.odata2.jpa.processor.core.mock.ODataJPAContextMock;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ODataJPAContextImplTest {
+
+ private ODataContext odataContext = null;
+ private ODataJPAContext odataJPAContext = null;
+ private EdmProvider edmProvider = null;
+ private EntityManagerFactory emf = null;
+ private EntityManager em = null;
+ private ODataProcessor processor = null;
+
+ @Before
+ public void setup() {
+
+ edmProvider = new ODataJPAEdmProvider();
+ emf = EasyMock.createMock(EntityManagerFactory.class);
+ em = EasyMock.createMock(EntityManager.class);
+ EasyMock.replay(em);
+
+ EasyMock.expect(emf.createEntityManager()).andStubReturn(em);
+ EasyMock.replay(emf);
+
+ odataContext = EasyMock.createMock(ODataContext.class);
+ List<Locale> listLocale = new ArrayList<Locale>();
+ listLocale.add(Locale.ENGLISH);
+ listLocale.add(Locale.GERMAN);
+
+ EasyMock.expect(odataContext.getAcceptableLanguages()).andStubReturn(listLocale);
+ EasyMock.replay(odataContext);
+
+ processor = EasyMock.createMock(ODataProcessor.class);
+ EasyMock.replay(processor);
+
+ odataJPAContext = new ODataJPAContextImpl();
+ odataJPAContext.setEdmProvider(edmProvider);
+ odataJPAContext.setEntityManagerFactory(emf);
+ odataJPAContext.setODataContext(odataContext);
+ odataJPAContext.setODataProcessor(processor);
+ odataJPAContext.setPersistenceUnitName(ODataJPAContextMock.PERSISTENCE_UNIT_NAME);
+ odataJPAContext.setJPAEdmMappingModel(ODataJPAContextMock.MAPPING_MODEL);
+ }
+
+ @Test
+ public void testgetMethodsOfODataJPAContext() {
+
+ assertEquals(odataJPAContext.getEdmProvider().hashCode(), edmProvider.hashCode());
+ assertEquals(odataJPAContext.getEntityManagerFactory().hashCode(), emf.hashCode());
+ assertEquals(odataJPAContext.getODataContext().hashCode(), odataContext.hashCode());
+ assertEquals(odataJPAContext.getODataProcessor().hashCode(), processor.hashCode());
+ assertEquals(odataJPAContext.getPersistenceUnitName(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME);
+ assertEquals(odataJPAContext.getJPAEdmMappingModel(), ODataJPAContextMock.MAPPING_MODEL);
+
+ EntityManager em1 = odataJPAContext.getEntityManager();
+ EntityManager em2 = odataJPAContext.getEntityManager();
+ if (em1 != null && em2 != null) {
+ assertEquals(em1.hashCode(), em2.hashCode());
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/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
new file mode 100644
index 0000000..ced012e
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java
@@ -0,0 +1,555 @@
+/*******************************************************************************
+ * 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.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.ODataJPAProcessorDefault;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+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;
+ ODataJPAProcessorDefaultTest objODataJPAProcessorDefaultTest;
+
+ 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() {
+ objODataJPAProcessorDefaultTest = new ODataJPAProcessorDefaultTest();
+ 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(getEntityCountCountUriInfo(),
+ HttpContentType.APPLICATION_XML));
+ Assert.assertNull("ContentType MUST NOT set by entity provider", objODataJPAProcessorDefault.existsEntity(
+ getEntityCountCountUriInfo(), 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 getEntityCountCountUriInfo() {
+ return getLocalUriInfo();
+ }
+
+ private DeleteUriInfo getDeletetUriInfo() {
+ UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
+ EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ 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.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());
+ 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(getEdmMappingMockedObj(SALES_ORDER));// ID vs Salesorder
+ // ID
+ 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.getPersistenceUnitName()).andStubReturn("salesorderprocessing");
+ EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andStubReturn(mockEntityManagerFactory());
+ EasyMock.expect(odataJPAContext.getODataContext()).andStubReturn(getLocalODataContext());
+ EasyMock.expect(odataJPAContext.getEntityManager()).andStubReturn(getLocalEntityManager());
+ EasyMock.replay(odataJPAContext);
+ return odataJPAContext;
+ }
+
+ 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
+ Address obj = new Address();
+ em.remove(obj);// testing void method
+ em.flush();
+ 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.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(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(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 EdmMapping getEdmMappingMockedObj(final String propertyName) {
+ EdmMapping mockedEdmMapping = EasyMock.createMock(EdmMapping.class);
+ if (propertyName.equalsIgnoreCase(SALES_ORDER)) {
+ EasyMock.expect(mockedEdmMapping.getInternalName()).andStubReturn(SALES_ORDER_HEADERS);
+ } else {
+ EasyMock.expect(mockedEdmMapping.getInternalName()).andStubReturn(propertyName);
+ }
+ 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 = EasyMock.createMock(ODataContext.class);
+ try {
+ EasyMock.expect(objODataContext.getPathInfo()).andStubReturn(getLocalPathInfo());
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(objODataContext);
+ 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;
+ }
+
+}