You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2013/12/28 15:18:06 UTC
[08/31] [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/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRoleTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRoleTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRoleTest.java
new file mode 100644
index 0000000..a453984
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRoleTest.java
@@ -0,0 +1,235 @@
+/*******************************************************************************
+ * 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.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.JoinColumn;
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.ManagedType;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+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.JPAEdmReferentialConstraintRoleView.RoleType;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAJavaMemberMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAManagedTypeMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmReferentialConstraintRole;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPAEdmReferentialConstraintRoleTest extends JPAEdmTestModelView {
+
+ private static JPAEdmReferentialConstraintRole objJPAEdmReferentialConstraintRole = null;
+ private static JPAEdmReferentialConstraintRoleTest objJPAEdmReferentialConstraintRoleTest = null;
+
+ @Before
+ public void setUp() {
+ objJPAEdmReferentialConstraintRoleTest = new JPAEdmReferentialConstraintRoleTest();
+
+ objJPAEdmReferentialConstraintRole =
+ new JPAEdmReferentialConstraintRole(RoleType.PRINCIPAL, objJPAEdmReferentialConstraintRoleTest,
+ objJPAEdmReferentialConstraintRoleTest, objJPAEdmReferentialConstraintRoleTest);
+
+ try {
+ objJPAEdmReferentialConstraintRole.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testIsExists() {
+ assertTrue(objJPAEdmReferentialConstraintRole.isExists());// Default
+ }
+
+ @Test
+ public void testGetBuilder() {
+ assertNotNull(objJPAEdmReferentialConstraintRole.getBuilder());
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmBuilder builder1 = objJPAEdmReferentialConstraintRole.getBuilder();
+ JPAEdmBuilder builder2 = objJPAEdmReferentialConstraintRole.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Test
+ public void testGetRoleTypePrincipal() {
+ assertEquals(objJPAEdmReferentialConstraintRole.getRoleType(), RoleType.PRINCIPAL);
+ }
+
+ @Test
+ public void testGetRoleTypeDependent() {
+ objJPAEdmReferentialConstraintRoleTest = new JPAEdmReferentialConstraintRoleTest();
+ objJPAEdmReferentialConstraintRole =
+ new JPAEdmReferentialConstraintRole(RoleType.DEPENDENT, objJPAEdmReferentialConstraintRoleTest,
+ objJPAEdmReferentialConstraintRoleTest, objJPAEdmReferentialConstraintRoleTest);
+
+ try {
+ objJPAEdmReferentialConstraintRole.getBuilder().build();
+ objJPAEdmReferentialConstraintRole.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertEquals(objJPAEdmReferentialConstraintRole.getRoleType(), RoleType.DEPENDENT);
+ }
+
+ @Test
+ public void testGetEdmReferentialConstraintRole() {
+ try {
+ objJPAEdmReferentialConstraintRole.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertNotNull(objJPAEdmReferentialConstraintRole.getEdmReferentialConstraintRole());
+ }
+
+ @Test
+ public void testGetJPAColumnName() {
+ assertNull(objJPAEdmReferentialConstraintRole.getJPAColumnName());
+ }
+
+ @Test
+ public void testGetEdmEntityTypeName() {
+ assertNull(objJPAEdmReferentialConstraintRole.getEdmEntityTypeName());
+ }
+
+ @Test
+ public void testGetEdmAssociationName() {
+ assertNull(objJPAEdmReferentialConstraintRole.getEdmAssociationName());
+ }
+
+ @Override
+ public Attribute<?, ?> getJPAAttribute() {
+ return getJPAAttributeLocal();
+ }
+
+ @Override
+ public Association getEdmAssociation() {
+ Association association = new Association();
+ association.setName("Assoc_SalesOrderHeader_SalesOrderItem");
+ association.setEnd1(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "String")).setRole(
+ "SalesOrderHeader"));
+ association.setEnd2(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "SalesOrderItem"))
+ .setRole("SalesOrderItem"));
+ return association;
+ }
+
+ @Override
+ public EntityType searchEdmEntityType(final String arg0) {
+
+ EntityType entityType = new EntityType();
+
+ JPAEdmMappingImpl mapping = new JPAEdmMappingImpl();
+ mapping.setJPAColumnName("SOID");
+
+ List<Property> propList = new ArrayList<Property>();
+
+ Property property = new Property() {};
+ property.setMapping((Mapping) mapping);
+ property.setName("SOID");
+ propList.add(property);
+
+ entityType.setProperties(propList);
+
+ return entityType;
+ }
+
+ private Attribute<?, ?> getJPAAttributeLocal() {
+ AttributeMock<Object, String> attr = new AttributeMock<Object, String>();
+ return attr;
+ }
+
+ @SuppressWarnings("hiding")
+ private class AttributeMock<Object, String> extends JPAAttributeMock<Object, String> {
+
+ @Override
+ public Member getJavaMember() {
+ return new JavaMemberMock();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<String> getJavaType() {
+ return (Class<String>) java.lang.String.class;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public ManagedType<Object> getDeclaringType() {
+ return (ManagedType<Object>) getManagedTypeLocal();
+ }
+
+ private ManagedType<?> getManagedTypeLocal() {
+ ManagedTypeMock<String> managedTypeMock = new ManagedTypeMock<String>();
+ return managedTypeMock;
+ }
+ }
+
+ @SuppressWarnings("hiding")
+ private class ManagedTypeMock<String> extends JPAManagedTypeMock<String> {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<String> getJavaType() {
+ return (Class<String>) java.lang.String.class;
+ }
+ }
+
+ private class JavaMemberMock extends JPAJavaMemberMock {
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends Annotation> T getAnnotation(final Class<T> annotationClass) {
+ JoinColumn joinColumn = EasyMock.createMock(JoinColumn.class);
+ EasyMock.expect(joinColumn.referencedColumnName()).andReturn("SOID");
+ EasyMock.expect(joinColumn.name()).andReturn("SOID");
+
+ EasyMock.replay(joinColumn);
+ return (T) joinColumn;
+ }
+ }
+}
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/model/JPAEdmReferentialConstraintTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintTest.java
new file mode 100644
index 0000000..885ff86
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintTest.java
@@ -0,0 +1,178 @@
+/*******************************************************************************
+ * 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.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+
+import javax.persistence.JoinColumn;
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.ManagedType;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+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.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAJavaMemberMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAManagedTypeMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmReferentialConstraint;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPAEdmReferentialConstraintTest extends JPAEdmTestModelView {
+
+ private static JPAEdmReferentialConstraint objJPAEdmReferentialConstraint = null;
+ private static JPAEdmReferentialConstraintTest objJPAEdmReferentialConstraintTest = null;
+
+ @Before
+ public void setUp() {
+ objJPAEdmReferentialConstraintTest = new JPAEdmReferentialConstraintTest();
+ objJPAEdmReferentialConstraint =
+ new JPAEdmReferentialConstraint(objJPAEdmReferentialConstraintTest, objJPAEdmReferentialConstraintTest,
+ objJPAEdmReferentialConstraintTest);
+ try {
+ objJPAEdmReferentialConstraint.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetBuilder() {
+ assertNotNull(objJPAEdmReferentialConstraint.getBuilder());
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmBuilder builder1 = objJPAEdmReferentialConstraint.getBuilder();
+ JPAEdmBuilder builder2 = objJPAEdmReferentialConstraint.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Test
+ public void testGetEdmReferentialConstraint() {
+ assertNotNull(objJPAEdmReferentialConstraint.getEdmReferentialConstraint());
+ }
+
+ @Test
+ public void testIsExistsTrue() {
+ objJPAEdmReferentialConstraintTest = new JPAEdmReferentialConstraintTest();
+ objJPAEdmReferentialConstraint =
+ new JPAEdmReferentialConstraint(objJPAEdmReferentialConstraintTest, objJPAEdmReferentialConstraintTest,
+ objJPAEdmReferentialConstraintTest);
+ try {
+ objJPAEdmReferentialConstraint.getBuilder().build();
+ objJPAEdmReferentialConstraint.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertTrue(objJPAEdmReferentialConstraint.isExists());
+ }
+
+ @Test
+ public void testGetRelationShipName() {
+ assertEquals("Assoc_SalesOrderHeader_SalesOrderItem", objJPAEdmReferentialConstraint.getEdmRelationShipName());
+ }
+
+ @Override
+ public Association getEdmAssociation() {
+ Association association = new Association();
+ association.setName("Assoc_SalesOrderHeader_SalesOrderItem");
+ association.setEnd1(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "String")).setRole(
+ "SalesOrderHeader"));
+ association.setEnd2(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "SalesOrderItem"))
+ .setRole("SalesOrderItem"));
+ return association;
+ }
+
+ private Attribute<?, ?> getJPAAttributeLocal() {
+ AttributeMock<Object, String> attr = new AttributeMock<Object, String>();
+ return attr;
+ }
+
+ @Override
+ public Attribute<?, ?> getJPAAttribute() {
+ return getJPAAttributeLocal();
+ }
+
+ @SuppressWarnings("hiding")
+ private class AttributeMock<Object, String> extends JPAAttributeMock<Object, String> {
+
+ @Override
+ public Member getJavaMember() {
+ return new JavaMemberMock();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<String> getJavaType() {
+ return (Class<String>) java.lang.String.class;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public ManagedType<Object> getDeclaringType() {
+ return (ManagedType<Object>) getManagedTypeLocal();
+ }
+
+ private ManagedType<?> getManagedTypeLocal() {
+ ManagedTypeMock<String> managedTypeMock = new ManagedTypeMock<String>();
+ return managedTypeMock;
+ }
+ }
+
+ @SuppressWarnings("hiding")
+ private class ManagedTypeMock<String> extends JPAManagedTypeMock<String> {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<String> getJavaType() {
+ return (Class<String>) java.lang.String.class;
+ }
+ }
+
+ private class JavaMemberMock extends JPAJavaMemberMock {
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends Annotation> T getAnnotation(final Class<T> annotationClass) {
+ JoinColumn joinColumn = EasyMock.createMock(JoinColumn.class);
+ EasyMock.expect(joinColumn.referencedColumnName()).andReturn("SOID");
+ EasyMock.expect(joinColumn.name()).andReturn("SOID");
+
+ EasyMock.replay(joinColumn);
+ return (T) joinColumn;
+ }
+ }
+
+}
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/model/JPAEdmSchemaTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmSchemaTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmSchemaTest.java
new file mode 100644
index 0000000..b366191
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmSchemaTest.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * 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.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAMetaModelMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmSchema;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPAEdmSchemaTest extends JPAEdmTestModelView {
+ private JPAEdmSchemaTest objJPAEdmSchemaTest;
+ private JPAEdmSchema objJPAEdmSchema;
+
+ @Before
+ public void setUp() {
+ objJPAEdmSchemaTest = new JPAEdmSchemaTest();
+ objJPAEdmSchema = new JPAEdmSchema(objJPAEdmSchemaTest);
+ // building schema is not required as downstream structure already tested
+
+ }
+
+ @Test
+ public void testClean() {
+ assertTrue(objJPAEdmSchema.isConsistent());
+ objJPAEdmSchema.clean();
+ assertFalse(objJPAEdmSchema.isConsistent());
+ }
+
+ @Test
+ public void testGetEdmSchema() {
+ assertNull(objJPAEdmSchema.getEdmSchema());
+ }
+
+ @Test
+ public void testGetJPAEdmEntityContainerView() {
+ assertNull(objJPAEdmSchema.getJPAEdmEntityContainerView());
+ }
+
+ @Test
+ public void testGetJPAEdmComplexTypeView() {
+ assertNull(objJPAEdmSchema.getJPAEdmComplexTypeView());
+ }
+
+ @Test
+ public void testGetBuilder() {
+ assertNotNull(objJPAEdmSchema.getBuilder());
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmBuilder builder1 = objJPAEdmSchema.getBuilder();
+ JPAEdmBuilder builder2 = objJPAEdmSchema.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Test
+ public void testGetJPAEdmAssociationView() {
+ assertNull(objJPAEdmSchema.getJPAEdmAssociationView());
+ }
+
+ @Test
+ public void testIsConsistent() {
+ assertTrue(objJPAEdmSchema.isConsistent());
+ objJPAEdmSchema.clean();
+ assertFalse(objJPAEdmSchema.isConsistent());
+ }
+
+ @Override
+ public Metamodel getJPAMetaModel() {
+ return new JPAMetaModelMock();
+ }
+
+ @Override
+ public String getpUnitName() {
+ return "salesorderprocessing";
+ }
+
+}
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/model/JPAEdmTestModelView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmTestModelView.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmTestModelView.java
new file mode 100644
index 0000000..d145239
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmTestModelView.java
@@ -0,0 +1,400 @@
+/*******************************************************************************
+ * 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.model;
+
+import java.util.HashMap;
+import java.util.List;
+
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.EmbeddableType;
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.Key;
+import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.ReferentialConstraint;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationEndView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationSetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmBaseView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmExtension;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmKeyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmModelView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmNavigationPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
+
+public class JPAEdmTestModelView implements JPAEdmAssociationEndView, JPAEdmAssociationSetView, JPAEdmAssociationView,
+ JPAEdmBaseView, JPAEdmComplexPropertyView, JPAEdmComplexTypeView, JPAEdmEntityContainerView, JPAEdmEntitySetView,
+ JPAEdmEntityTypeView, JPAEdmKeyView, JPAEdmModelView, JPAEdmNavigationPropertyView, JPAEdmPropertyView,
+ JPAEdmReferentialConstraintView, JPAEdmSchemaView {
+
+ protected JPAEdmMappingModelAccess mappingModelAccess;
+
+ @Override
+ public Schema getEdmSchema() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmAssociationView getJPAEdmAssociationView() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmComplexTypeView getJPAEdmComplexTypeView() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
+ return null;
+ }
+
+ @Override
+ public Attribute<?, ?> getJPAAttribute() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmKeyView getJPAEdmKeyView() {
+ return null;
+ }
+
+ @Override
+ public List<Property> getEdmPropertyList() {
+ return null;
+ }
+
+ @Override
+ public SimpleProperty getEdmSimpleProperty() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmSchemaView getEdmSchemaView() {
+ return null;
+ }
+
+ @Override
+ public Key getEdmKey() {
+ return null;
+ }
+
+ @Override
+ public List<EntityType> getConsistentEdmEntityTypes() {
+ return null;
+ }
+
+ @Override
+ public EntityType getEdmEntityType() {
+ return null;
+ }
+
+ @Override
+ public javax.persistence.metamodel.EntityType<?> getJPAEntityType() {
+ return null;
+ }
+
+ @Override
+ public List<EntitySet> getConsistentEdmEntitySetList() {
+ return null;
+ }
+
+ @Override
+ public EntitySet getEdmEntitySet() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
+ return null;
+ }
+
+ @Override
+ public List<EntityContainer> getConsistentEdmEntityContainerList() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmAssociationSetView getEdmAssociationSetView() {
+ return null;
+ }
+
+ @Override
+ public EntityContainer getEdmEntityContainer() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmEntitySetView getJPAEdmEntitySetView() {
+ return null;
+ }
+
+ @Override
+ public void addJPAEdmCompleTypeView(final JPAEdmComplexTypeView arg0) {
+
+ }
+
+ @Override
+ public List<ComplexType> getConsistentEdmComplexTypes() {
+ return null;
+ }
+
+ @Override
+ public ComplexType getEdmComplexType() {
+ return null;
+ }
+
+ @Override
+ public EmbeddableType<?> getJPAEmbeddableType() {
+ return null;
+ }
+
+ @Override
+ public ComplexType searchEdmComplexType(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public ComplexType searchEdmComplexType(final FullQualifiedName arg0) {
+ return null;
+ }
+
+ @Override
+ public ComplexProperty getEdmComplexProperty() {
+ return null;
+ }
+
+ @Override
+ public void clean() {
+
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ return null;
+ }
+
+ @Override
+ public Metamodel getJPAMetaModel() {
+ return null;
+ }
+
+ @Override
+ public String getpUnitName() {
+ return null;
+ }
+
+ @Override
+ public boolean isConsistent() {
+ return false;
+ }
+
+ @Override
+ public void addJPAEdmRefConstraintView(final JPAEdmReferentialConstraintView arg0) {
+
+ }
+
+ @Override
+ public ReferentialConstraint getEdmReferentialConstraint() {
+ return null;
+ }
+
+ @Override
+ public String getEdmRelationShipName() {
+ return null;
+ }
+
+ @Override
+ public boolean isExists() {
+ return false;
+ }
+
+ @Override
+ public EntityType searchEdmEntityType(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView() {
+ return null;
+ }
+
+ @Override
+ public List<Association> getConsistentEdmAssociationList() {
+ return null;
+ }
+
+ @Override
+ public Association searchAssociation(final JPAEdmAssociationEndView arg0) {
+ return null;
+ }
+
+ @Override
+ public List<AssociationSet> getConsistentEdmAssociationSetList() {
+ return null;
+ }
+
+ @Override
+ public Association getEdmAssociation() {
+ return null;
+ }
+
+ @Override
+ public AssociationSet getEdmAssociationSet() {
+ return null;
+ }
+
+ @Override
+ public boolean compare(final AssociationEnd arg0, final AssociationEnd arg1) {
+ return false;
+ }
+
+ @Override
+ public AssociationEnd getEdmAssociationEnd1() {
+ return null;
+ }
+
+ @Override
+ public AssociationEnd getEdmAssociationEnd2() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView() {
+ return null;
+ }
+
+ @Override
+ public void addJPAEdmNavigationPropertyView(final JPAEdmNavigationPropertyView view) {
+
+ }
+
+ @Override
+ public List<NavigationProperty> getConsistentEdmNavigationProperties() {
+ return null;
+ }
+
+ @Override
+ public NavigationProperty getEdmNavigationProperty() {
+ return null;
+ }
+
+ @Override
+ public void expandEdmComplexType(final ComplexType complexType, final List<Property> expandedPropertyList,
+ final String embeddablePropertyName) {
+
+ }
+
+ @Override
+ public JPAEdmMappingModelAccess getJPAEdmMappingModelAccess() {
+ return null;
+ }
+
+ @Override
+ public void registerOperations(final Class<?> customClass, final String[] methodNames) {
+ // Do nothing
+ }
+
+ @Override
+ public HashMap<Class<?>, String[]> getRegisteredOperations() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmExtension getJPAEdmExtension() {
+ return null;
+ }
+
+ @Override
+ public void addJPAEdmAssociationView(final JPAEdmAssociationView associationView,
+ final JPAEdmAssociationEndView associationEndView) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public int getNumberOfAssociationsWithSimilarEndPoints(final JPAEdmAssociationEndView view) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public String getJoinColumnName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getJoinColumnReferenceColumnName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getMappedByName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getOwningPropertyName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean isDefaultNamingSkipped() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isReferencedInKey(String complexTypeName) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void setReferencedInKey(String complexTypeName) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
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/model/_JPAEdmFunctionImportTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportTest.java
new file mode 100644
index 0000000..02b6c9f
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportTest.java
@@ -0,0 +1,571 @@
+/*******************************************************************************
+ * 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.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.Parameter.Mode;
+import org.apache.olingo.odata2.api.edm.EdmFacets;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImportParameter;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.api.edm.provider.ReturnType;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+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.JPAEdmComplexTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+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.ODataJPAContextMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model._JPACustomProcessorMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model._JPACustomProcessorNegativeMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmFunctionImport;
+import org.junit.Before;
+import org.junit.Test;
+
+@Deprecated
+public class _JPAEdmFunctionImportTest extends JPAEdmTestModelView {
+ private static final int METHOD_COUNT = 6;
+ private static int VARIANT = 0;
+ private JPAEdmFunctionImport jpaEdmfunctionImport;
+
+ @Before
+ public void setup() {
+ jpaEdmfunctionImport = new JPAEdmFunctionImport(this);
+ }
+
+ /**
+ * Test Case - Function Import Basic test - Positive Case
+ */
+ @Test
+ public void testFunctionImportBasic() {
+ VARIANT = 0;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+ for (FunctionImport functionImport : functionImportList) {
+ assertEquals(functionImport.getName(), "Method1");
+ assertNotNull(functionImport.getMapping());
+ Mapping mapping = new Mapping();
+ mapping.setInternalName("method1");
+
+ assertEquals(mapping.getInternalName(), functionImport.getMapping().getInternalName());
+
+ ReturnType returnType = functionImport.getReturnType();
+ assertNotNull(returnType);
+ assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity());
+
+ List<FunctionImportParameter> funcImpList = functionImport.getParameters();
+ assertEquals(2, funcImpList.size());
+ assertEquals("Param1", funcImpList.get(0).getName());
+ assertEquals(EdmSimpleTypeKind.String, funcImpList.get(0).getType());
+ assertEquals(Mode.IN.toString(), funcImpList.get(0).getMode());
+
+ assertEquals("Param3", funcImpList.get(1).getName());
+ assertEquals(EdmSimpleTypeKind.Double, funcImpList.get(1).getType());
+ assertEquals(Mode.IN.toString(), funcImpList.get(1).getMode());
+
+ }
+
+ }
+
+ /**
+ * Test Case - Enable a method that does not exists
+ */
+ @Test
+ public void testFunctionImportNoSuchMethod() {
+ VARIANT = 1;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 0);
+
+ }
+
+ /**
+ * Test Case - Enable all annotated methods in a class as function imports
+ */
+ @Test
+ public void testFunctionImportAllMethods() {
+ VARIANT = 2;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(METHOD_COUNT, functionImportList.size());
+
+ }
+
+ /**
+ * Test Case - Function Import with no names. Default name is Java method
+ * name.
+ */
+ @Test
+ public void testFunctionImportNoName() {
+ VARIANT = 3;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ FunctionImport functionImport = functionImportList.get(0);
+ assertEquals(functionImport.getName(), "method3");
+ assertNotNull(functionImport.getMapping());
+
+ ReturnType returnType = functionImport.getReturnType();
+ assertNotNull(returnType);
+ assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
+ assertEquals(returnType.getTypeName().toString(), EdmSimpleTypeKind.Int32.getFullQualifiedName().toString());
+ }
+
+ /**
+ * Test Case - Function Import with No return type defined - Negative case
+ */
+ @Test
+ public void testNoReturnType() {
+ VARIANT = 4;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 0);
+
+ }
+
+ /**
+ * Test Case - Function Import with return type as Entity and Multiplicity
+ * as Many but no Entity set defined. --> Negative Case
+ */
+ @Test
+ public void testNoEntitySet() {
+ VARIANT = 5;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_ENTITYSET_EXP.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+ }
+
+ /**
+ * Test Case - Function Import with return type as Entity Type but method
+ * has returns void. --> Negative Case
+ */
+ @Test
+ public void testNoReturnTypeButAnnotated() {
+ VARIANT = 6;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+ }
+
+ /**
+ * Test Case - Function Import that returns an Entity Type with Multiplicity
+ * as ONE. -->Positive Case
+ */
+ @Test
+ public void testFunctionImportEntityTypeSingleReturn() {
+ VARIANT = 7;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ FunctionImport functionImport = functionImportList.get(0);
+ assertEquals(functionImport.getName(), "method7");
+ assertNotNull(functionImport.getMapping());
+ JPAEdmMapping mapping = (JPAEdmMapping) functionImport.getMapping();
+ assertEquals(_JPACustomProcessorMock.class, mapping.getJPAType());
+
+ ReturnType returnType = functionImport.getReturnType();
+ assertNotNull(returnType);
+ assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
+ assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
+ + _JPACustomProcessorMock.edmName);
+ }
+
+ /**
+ * Test Case - Function Import that returns an Entity Type that is not found
+ * in JPA Model
+ */
+ @Test
+ public void testFunctionImportEntityTypeInvalid() {
+ VARIANT = 8;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ /**
+ * Test Case - Function Import that returns a complex Type
+ */
+ @Test
+ public void testFunctionImportComplexType() {
+ VARIANT = 9;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ FunctionImport functionImport = functionImportList.get(0);
+ assertEquals(functionImport.getName(), "method9");
+ assertNotNull(functionImport.getMapping());
+
+ ReturnType returnType = functionImport.getReturnType();
+ assertNotNull(returnType);
+ assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
+ assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
+ + _JPACustomProcessorMock.edmName);
+
+ }
+
+ /**
+ * Test Case - Function Import that returns a complex Type with multiplicity
+ * Many
+ */
+ @Test
+ public void testFunctionImportComplexTypeMany() {
+ VARIANT = 10;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ FunctionImport functionImport = functionImportList.get(0);
+ assertEquals(functionImport.getName(), "method10");
+ assertNotNull(functionImport.getMapping());
+
+ ReturnType returnType = functionImport.getReturnType();
+ assertNotNull(returnType);
+ assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity());
+ assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
+ + _JPACustomProcessorMock.edmName);
+
+ }
+
+ /**
+ * Test Case - Function Import that returns an Complex Type that is not
+ * found in JPA Model
+ */
+ @Test
+ public void testFunctionImportComplexTypeInvalid() {
+ VARIANT = 11;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ /**
+ * Test Case - Function Import that returns an scalar Type that is not valid
+ */
+ @Test
+ public void testFunctionImportScalarTypeInvalid() {
+ VARIANT = 12;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.TYPE_NOT_SUPPORTED.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ /**
+ * Test Case - Function Import that takes a parameter with no name
+ */
+ @Test
+ public void testFunctionImportParamNoName() {
+ VARIANT = 13;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_PARAM_NAME_EXP.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ /**
+ * Test Case - Function Import test for facets
+ */
+ @Test
+ public void testFunctionImportParamFacets() {
+ VARIANT = 14;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ List<FunctionImportParameter> funcImpParamList = functionImportList.get(0).getParameters();
+ EdmFacets facets = funcImpParamList.get(0).getFacets();
+ assertNotNull(facets);
+ assertEquals(2, facets.getMaxLength().intValue());
+ assertEquals(true, facets.isNullable());
+
+ facets = funcImpParamList.get(1).getFacets();
+ assertNotNull(facets);
+ assertEquals(false, facets.isNullable());
+ assertEquals(10, facets.getPrecision().intValue());
+ assertEquals(2, facets.getScale().intValue());
+
+ }
+
+ /**
+ * Test Case - Function Import test for default facets
+ */
+ @Test
+ public void testFunctionImportParamFacetsDefault() {
+ VARIANT = 15;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ List<FunctionImportParameter> funcImpParamList = functionImportList.get(0).getParameters();
+ EdmFacets facets = funcImpParamList.get(0).getFacets();
+ assertNotNull(facets);
+ assertNull(facets.getMaxLength());
+ assertEquals(false, facets.isNullable());
+ assertNull(facets.getPrecision());
+ assertNull(facets.getScale());
+
+ }
+
+ /**
+ * Test Case - Function Import test for ReturnType.SCALAR but method returns
+ * void
+ */
+ @Test
+ public void testWrongReturnTypeScalar() {
+ VARIANT = 16;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ /**
+ * Test Case - Function Import test for ReturnType.COMPLEX but method returns
+ * void
+ */
+ @Test
+ public void testWrongReturnTypeComplex() {
+ VARIANT = 17;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ @Test
+ public void testNoFunctionImport() {
+ VARIANT = 99;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 0);
+
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmFunctionImport jpaEdmfunctionImport = new JPAEdmFunctionImport(this);
+
+ JPAEdmBuilder builder1 = jpaEdmfunctionImport.getBuilder();
+ JPAEdmBuilder builder2 = jpaEdmfunctionImport.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Override
+ public HashMap<Class<?>, String[]> getRegisteredOperations() {
+
+ HashMap<Class<?>, String[]> customOperations = new HashMap<Class<?>, String[]>();
+
+ if (VARIANT == 0) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "method1" });
+ } else if (VARIANT == 1) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "XYX" });
+ } else if (VARIANT == 2) {
+ customOperations.put(_JPACustomProcessorMock.class, null);
+ } else if (VARIANT == 3) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "method3" });
+ } else if (VARIANT == 4) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "method4" });
+ } else if (VARIANT == 5) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method5" });
+ } else if (VARIANT == 6) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method6" });
+ } else if (VARIANT == 7) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "method7" });
+ } else if (VARIANT == 8) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method8" });
+ } else if (VARIANT == 9) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "method9" });
+ } else if (VARIANT == 10) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "method10" });
+ } else if (VARIANT == 11) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method11" });
+ } else if (VARIANT == 12) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method12" });
+ } else if (VARIANT == 13) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method13" });
+ } else if (VARIANT == 14) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "method1" });
+ } else if (VARIANT == 15) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "method3" });
+ } else if (VARIANT == 16) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method16" });
+ } else if (VARIANT == 17) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method17" });
+ } else {
+ return null;
+ }
+
+ return customOperations;
+ }
+
+ @Override
+ public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmEntitySetView getJPAEdmEntitySetView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmComplexTypeView getJPAEdmComplexTypeView() {
+ return this;
+ }
+
+ @Override
+ public EntityType searchEdmEntityType(final String arg0) {
+ if (arg0.equals(_JPACustomProcessorMock.class.getSimpleName())) {
+ return new EntityType().setName(_JPACustomProcessorMock.edmName);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public ComplexType searchEdmComplexType(final String arg0) {
+ if (arg0.equals(_JPACustomProcessorMock.class.getName())) {
+ return new ComplexType().setName(_JPACustomProcessorMock.edmName);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public String getpUnitName() {
+ return ODataJPAContextMock.PERSISTENCE_UNIT_NAME;
+ }
+
+ private void build() {
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+}
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/processor/core/jpa/ODataExpressionParserTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataExpressionParserTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataExpressionParserTest.java
deleted file mode 100644
index 390c7fe..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataExpressionParserTest.java
+++ /dev/null
@@ -1,515 +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.processor.core.jpa;
-
-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.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.core.jpa.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/processor/core/jpa/ODataJPAContextImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAContextImplTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAContextImplTest.java
deleted file mode 100644
index 10e65c0..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAContextImplTest.java
+++ /dev/null
@@ -1,98 +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.processor.core.jpa;
-
-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.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.core.jpa.edm.ODataJPAEdmProvider;
-import org.apache.olingo.odata2.processor.core.jpa.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());
- }
-
- }
-
-}