You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2013/09/24 14:43:07 UTC
[40/51] [partial] Refactored project structure
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmMappingModelServiceTest.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmMappingModelServiceTest.java b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmMappingModelServiceTest.java
deleted file mode 100644
index 76ea726..0000000
--- a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmMappingModelServiceTest.java
+++ /dev/null
@@ -1,213 +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.access.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 java.io.InputStream;
-
-import org.apache.olingo.odata2.processor.core.jpa.mock.ODataJPAContextMock;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class JPAEdmMappingModelServiceTest extends JPAEdmMappingModelService {
-
- private static JPAEdmMappingModelServiceTest objJPAEdmMappingModelServiceTest;
-
- private static final String MAPPING_FILE_CORRECT = "SalesOrderProcessingMappingModels.xml";
- private static final String MAPPING_FILE_INCORRECT = "TEST.xml";
-
- private static int VARIANT_MAPPING_FILE; // 0 FOR INCORRECT, 1 FOR CORRECT
-
- private static String PERSISTENCE_UNIT_NAME_JPA = "salesorderprocessing";
- private static String PERSISTENCE_UNIT_NAME_EDM = "SalesOrderProcessing";
-
- private static String ENTITY_TYPE_NAME_JPA = "SalesOrderHeader";
- private static String ENTITY_TYPE_NAME_EDM = "SalesOrder";
- private static String ENTITY_SET_NAME_EDM = "SalesOrders";
- private static String RELATIONSHIP_NAME_JPA = "salesOrderItems";
- private static String RELATIONSHIP_NAME_EDM = "SalesOrderItemDetails";
- private static String ATTRIBUTE_NAME_JPA = "netAmount";
- private static String ATTRIBUTE_NAME_EDM = "NetAmount";
- private static String EMBEDDABLE_TYPE_NAME_JPA = "SalesOrderItemKey";
- private static String EMBEDDABLE_ATTRIBUTE_NAME_JPA = "liId";
- private static String EMBEDDABLE_ATTRIBUTE_NAME_EDM = "ID";
- private static String EMBEDDABLE_TYPE_2_NAME_JPA = "SalesOrderItemKey";
-
- private static String ENTITY_TYPE_NAME_JPA_WRONG = "SalesOrderHeaders";
- private static String RELATIONSHIP_NAME_JPA_WRONG = "value";
- private static String EMBEDDABLE_TYPE_NAME_JPA_WRONG = "SalesOrderItemKeys";
-
- public JPAEdmMappingModelServiceTest() {
- super(ODataJPAContextMock.mockODataJPAContext());
- }
-
- @BeforeClass
- public static void setup() {
- objJPAEdmMappingModelServiceTest = new JPAEdmMappingModelServiceTest();
- VARIANT_MAPPING_FILE = 1;
- objJPAEdmMappingModelServiceTest.loadMappingModel();
- }
-
- @Test
- public void testLoadMappingModel() {
- VARIANT_MAPPING_FILE = 1;
- loadMappingModel();
- assertTrue(isMappingModelExists());
- }
-
- @Test
- public void testLoadMappingModelNegative() {
- VARIANT_MAPPING_FILE = 0;
- loadMappingModel();
- assertFalse(isMappingModelExists());
- // reset it for other JUnits
- VARIANT_MAPPING_FILE = 1;
- loadMappingModel();
- }
-
- @Test
- public void testIsMappingModelExists() {
- assertTrue(objJPAEdmMappingModelServiceTest.isMappingModelExists());
- }
-
- @Test
- public void testGetJPAEdmMappingModel() {
- assertNotNull(objJPAEdmMappingModelServiceTest.getJPAEdmMappingModel());
- }
-
- @Test
- public void testMapJPAPersistenceUnit() {
- assertEquals(PERSISTENCE_UNIT_NAME_EDM, objJPAEdmMappingModelServiceTest
- .mapJPAPersistenceUnit(PERSISTENCE_UNIT_NAME_JPA));
- }
-
- @Test
- public void testMapJPAPersistenceUnitNegative() {
- assertNull(objJPAEdmMappingModelServiceTest.mapJPAPersistenceUnit(PERSISTENCE_UNIT_NAME_EDM));// Wrong value to
- // bring null
- }
-
- @Test
- public void testMapJPAEntityType() {
- assertEquals(ENTITY_TYPE_NAME_EDM, objJPAEdmMappingModelServiceTest.mapJPAEntityType(ENTITY_TYPE_NAME_JPA));
- }
-
- @Test
- public void testMapJPAEntityTypeNegative() {
- assertNull(objJPAEdmMappingModelServiceTest.mapJPAEntityType(ENTITY_TYPE_NAME_JPA_WRONG));// Wrong value to bring
- // null
- }
-
- @Test
- public void testMapJPAEntitySet() {
- assertEquals(ENTITY_SET_NAME_EDM, objJPAEdmMappingModelServiceTest.mapJPAEntitySet(ENTITY_TYPE_NAME_JPA));
- }
-
- @Test
- public void testMapJPAEntitySetNegative() {
- assertNull(objJPAEdmMappingModelServiceTest.mapJPAEntitySet(ENTITY_TYPE_NAME_JPA_WRONG));// Wrong value to bring
- // null
- }
-
- @Test
- public void testMapJPAAttribute() {
- assertEquals(ATTRIBUTE_NAME_EDM, objJPAEdmMappingModelServiceTest.mapJPAAttribute(ENTITY_TYPE_NAME_JPA,
- ATTRIBUTE_NAME_JPA));
- }
-
- @Test
- public void testMapJPAAttributeNegative() {
- // Wrong value to bring null
- assertNull(objJPAEdmMappingModelServiceTest.mapJPAAttribute(ENTITY_TYPE_NAME_JPA, ATTRIBUTE_NAME_JPA + "AA"));
- }
-
- @Test
- public void testMapJPARelationship() {
- assertEquals(RELATIONSHIP_NAME_EDM, objJPAEdmMappingModelServiceTest.mapJPARelationship(ENTITY_TYPE_NAME_JPA,
- RELATIONSHIP_NAME_JPA));
- }
-
- @Test
- public void testMapJPARelationshipNegative() {
- // Wrong value to bring null
- assertNull(objJPAEdmMappingModelServiceTest.mapJPARelationship(ENTITY_TYPE_NAME_JPA, RELATIONSHIP_NAME_JPA_WRONG));
- }
-
- @Test
- public void testMapJPAEmbeddableType() {
- assertEquals("SalesOrderLineItemKey", objJPAEdmMappingModelServiceTest.mapJPAEmbeddableType("SalesOrderItemKey"));
- }
-
- @Test
- public void testMapJPAEmbeddableTypeNegative() {
- assertNull(objJPAEdmMappingModelServiceTest.mapJPAEmbeddableType(EMBEDDABLE_TYPE_NAME_JPA_WRONG));// Wrong value to
- // bring null
- }
-
- @Test
- public void testMapJPAEmbeddableTypeAttribute() {
- assertEquals(EMBEDDABLE_ATTRIBUTE_NAME_EDM, objJPAEdmMappingModelServiceTest.mapJPAEmbeddableTypeAttribute(
- EMBEDDABLE_TYPE_NAME_JPA, EMBEDDABLE_ATTRIBUTE_NAME_JPA));
- }
-
- @Test
- public void testMapJPAEmbeddableTypeAttributeNegative() {
- assertNull(objJPAEdmMappingModelServiceTest.mapJPAEmbeddableTypeAttribute(EMBEDDABLE_TYPE_NAME_JPA_WRONG,
- EMBEDDABLE_ATTRIBUTE_NAME_JPA));
- }
-
- @Test
- public void testCheckExclusionOfJPAEntityType() {
- assertTrue(!objJPAEdmMappingModelServiceTest.checkExclusionOfJPAEntityType(ENTITY_TYPE_NAME_JPA));
- }
-
- @Test
- public void testCheckExclusionOfJPAAttributeType() {
- assertTrue(!objJPAEdmMappingModelServiceTest.checkExclusionOfJPAAttributeType(ENTITY_TYPE_NAME_JPA,
- ATTRIBUTE_NAME_JPA));
- }
-
- @Test
- public void testCheckExclusionOfJPAEmbeddableType() {
- assertTrue(!objJPAEdmMappingModelServiceTest.checkExclusionOfJPAEmbeddableType(EMBEDDABLE_TYPE_2_NAME_JPA));
- }
-
- @Test
- public void testCheckExclusionOfJPAEmbeddableAttributeType() {
- assertTrue(!objJPAEdmMappingModelServiceTest.checkExclusionOfJPAEmbeddableAttributeType(EMBEDDABLE_TYPE_NAME_JPA,
- EMBEDDABLE_ATTRIBUTE_NAME_JPA));
- }
-
- /**
- * This method is for loading the xml file for testing.
- */
- @Override
- protected InputStream loadMappingModelInputStream() {
- if (VARIANT_MAPPING_FILE == 1) {
- return ClassLoader.getSystemResourceAsStream(MAPPING_FILE_CORRECT);
- } else {
- return ClassLoader.getSystemResourceAsStream(MAPPING_FILE_INCORRECT);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmNameBuilderTest.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmNameBuilderTest.java b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmNameBuilderTest.java
deleted file mode 100644
index f1e55e3..0000000
--- a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmNameBuilderTest.java
+++ /dev/null
@@ -1,90 +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.access.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmPropertyView;
-import org.apache.olingo.odata2.processor.core.jpa.ODataJPAContextImpl;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAAttributeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEntityTypeMock;
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-public class JPAEdmNameBuilderTest {
-
- @SuppressWarnings("rawtypes")
- @Test
- public void testBuildJPAEdmComplexPropertyViewJPAEdmPropertyView() {
- JPAEdmComplexPropertyView complexPropertyView = EasyMock.createMock(JPAEdmComplexPropertyView.class);
- ComplexProperty complexProperty = new ComplexProperty();
- EasyMock.expect(complexPropertyView.getEdmComplexProperty()).andStubReturn(complexProperty);
- ODataJPAContextImpl oDataJPAContext = new ODataJPAContextImpl();
- JPAEdmMappingModelService mappingModelService = new JPAEdmMappingModelService(oDataJPAContext);
- EasyMock.expect(complexPropertyView.getJPAEdmMappingModelAccess()).andStubReturn(mappingModelService);
-
- // Mocking EDMProperty
- JPAEdmPropertyView propertyView = EasyMock.createMock(JPAEdmPropertyView.class);
- JPAEdmEntityTypeView entityTypeView = EasyMock.createMock(JPAEdmEntityTypeView.class);
- EasyMock.expect(entityTypeView.getJPAEntityType()).andStubReturn(new JEntityType());
- EasyMock.replay(entityTypeView);
- EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JAttribute());
- EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
- EasyMock.replay(complexPropertyView);
- EasyMock.replay(propertyView);
-
- JPAEdmNameBuilder.build(complexPropertyView, propertyView);
- assertEquals("Id", complexPropertyView.getEdmComplexProperty().getName());
-
- }
-
- @SuppressWarnings("hiding")
- class JAttribute<Object, String> extends JPAAttributeMock<Object, java.lang.String> {
-
- @Override
- public java.lang.String getName() {
- return "id";
- }
-
- @Override
- public Class<java.lang.String> getJavaType() {
- return java.lang.String.class;
- }
-
- }
-
- class JEntityType<Object> extends JPAEntityTypeMock<Object> {
-
- @Override
- public java.lang.String getName() {
- return "SalesOrderHeader";
- }
-
- }
-
- @Test
- public void testBuildJPAEdmComplexPropertyViewString() {
- assertTrue(true);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertorTest.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertorTest.java b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertorTest.java
deleted file mode 100644
index 3a4057f..0000000
--- a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertorTest.java
+++ /dev/null
@@ -1,94 +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.access.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.math.BigDecimal;
-import java.util.UUID;
-
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.junit.Test;
-
-public class JPATypeConvertorTest {
-
- private EdmSimpleTypeKind edmSimpleKindTypeString;
- private EdmSimpleTypeKind edmSimpleKindTypeByteArr;
- private EdmSimpleTypeKind edmSimpleKindTypeLong;
- private EdmSimpleTypeKind edmSimpleKindTypeShort;
- private EdmSimpleTypeKind edmSimpleKindTypeInteger;
- private EdmSimpleTypeKind edmSimpleKindTypeDouble;
- private EdmSimpleTypeKind edmSimpleKindTypeFloat;
- private EdmSimpleTypeKind edmSimpleKindTypeBigDecimal;
- private EdmSimpleTypeKind edmSimpleKindTypeByte;
- private EdmSimpleTypeKind edmSimpleKindTypeBoolean;
- private EdmSimpleTypeKind edmSimpleKindTypeUUID;
-
- @Test
- public void testConvertToEdmSimpleType() {
- String str = "entity";
- byte[] byteArr = new byte[3];
- Long longObj = new Long(0);
- Short shortObj = new Short((short) 0);
- Integer integerObj = new Integer(0);
- Double doubleObj = new Double(0);
- Float floatObj = new Float(0);
- BigDecimal bigDecimalObj = new BigDecimal(0);
- Byte byteObj = new Byte((byte) 0);
- Boolean booleanObj = Boolean.TRUE;
- UUID uUID = new UUID(0, 0);
-
- try {
- edmSimpleKindTypeString = JPATypeConvertor.convertToEdmSimpleType(str.getClass(), null);
- edmSimpleKindTypeByteArr = JPATypeConvertor.convertToEdmSimpleType(byteArr.getClass(), null);
- edmSimpleKindTypeLong = JPATypeConvertor.convertToEdmSimpleType(longObj.getClass(), null);
- edmSimpleKindTypeShort = JPATypeConvertor.convertToEdmSimpleType(shortObj.getClass(), null);
- edmSimpleKindTypeInteger = JPATypeConvertor.convertToEdmSimpleType(integerObj.getClass(), null);
- edmSimpleKindTypeDouble = JPATypeConvertor.convertToEdmSimpleType(doubleObj.getClass(), null);
- edmSimpleKindTypeFloat = JPATypeConvertor.convertToEdmSimpleType(floatObj.getClass(), null);
- edmSimpleKindTypeBigDecimal = JPATypeConvertor.convertToEdmSimpleType(bigDecimalObj.getClass(), null);
- edmSimpleKindTypeByte = JPATypeConvertor.convertToEdmSimpleType(byteObj.getClass(), null);
- edmSimpleKindTypeBoolean = JPATypeConvertor.convertToEdmSimpleType(booleanObj.getClass(), null);
- /*
- * edmSimpleKindTypeDate = JPATypeConvertor
- * .convertToEdmSimpleType(dateObj.getClass(),null);
- */
- edmSimpleKindTypeUUID = JPATypeConvertor.convertToEdmSimpleType(uUID.getClass(), null);
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- assertEquals(EdmSimpleTypeKind.String, edmSimpleKindTypeString);
- assertEquals(EdmSimpleTypeKind.Binary, edmSimpleKindTypeByteArr);
- assertEquals(EdmSimpleTypeKind.Int64, edmSimpleKindTypeLong);
- assertEquals(EdmSimpleTypeKind.Int16, edmSimpleKindTypeShort);
- assertEquals(EdmSimpleTypeKind.Int32, edmSimpleKindTypeInteger);
- assertEquals(EdmSimpleTypeKind.Double, edmSimpleKindTypeDouble);
- assertEquals(EdmSimpleTypeKind.Single, edmSimpleKindTypeFloat);
- assertEquals(EdmSimpleTypeKind.Decimal, edmSimpleKindTypeBigDecimal);
- assertEquals(EdmSimpleTypeKind.Byte, edmSimpleKindTypeByte);
- assertEquals(EdmSimpleTypeKind.Boolean, edmSimpleKindTypeBoolean);
- // assertEquals(EdmSimpleTypeKind.DateTime, edmSimpleKindTypeDate);
- assertEquals(EdmSimpleTypeKind.Guid, edmSimpleKindTypeUUID);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/common/ODataJPATestConstants.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/common/ODataJPATestConstants.java b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/common/ODataJPATestConstants.java
deleted file mode 100644
index cd6caee..0000000
--- a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/common/ODataJPATestConstants.java
+++ /dev/null
@@ -1,27 +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.common;
-
-public final class ODataJPATestConstants {
-
- public static final String EXCEPTION_MSG_PART_1 = "Exception [ ";
- public static final String EXCEPTION_MSG_PART_2 = " ] not expected";
- public static final String EMPTY_STRING = "gwt1";
- public static final String EXCEPTION_EXPECTED = "Exception expected";
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProviderNegativeTest.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProviderNegativeTest.java b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProviderNegativeTest.java
deleted file mode 100644
index f00cc61..0000000
--- a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProviderNegativeTest.java
+++ /dev/null
@@ -1,191 +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.edm;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-
-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.EntityContainer;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.ODataJPAContextMock;
-import org.apache.olingo.odata2.processor.core.jpa.model.JPAEdmModel;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class ODataJPAEdmProviderNegativeTest {
-
- private static ODataJPAEdmProvider edmProvider;
-
- @BeforeClass
- public static void setup() {
-
- edmProvider = new ODataJPAEdmProvider();
- try {
- Class<? extends ODataJPAEdmProvider> clazz = edmProvider.getClass();
- Field field = clazz.getDeclaredField("schemas");
- field.setAccessible(true);
- List<Schema> schemas = new ArrayList<Schema>();
- schemas.add(new Schema().setNamespace("salesorderprocessing")); // Empty Schema
- field.set(edmProvider, schemas);
- field = clazz.getDeclaredField("oDataJPAContext");
- field.setAccessible(true);
- field.set(edmProvider, ODataJPAContextMock.mockODataJPAContext());
- field = clazz.getDeclaredField("jpaEdmModel");
- field.setAccessible(true);
- field.set(edmProvider, new JPAEdmModel(null, null));
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @Test
- public void testNullGetEntityContainerInfo() {
- EntityContainerInfo entityContainer = null;
- try {
- entityContainer = edmProvider.getEntityContainerInfo("salesorderprocessingContainer");
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertNull(entityContainer);
- }
-
- @Test
- public void testNullGetEntityType() {
- FullQualifiedName entityTypeName = new FullQualifiedName("salesorderprocessing", "SalesOrderHeader");
- try {
- assertNull(edmProvider.getEntityType(entityTypeName));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testNullGetComplexType() {
- FullQualifiedName complexTypeName = new FullQualifiedName("salesorderprocessing", "Address");
- try {
- assertNull(edmProvider.getComplexType(complexTypeName));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetAssociationFullQualifiedName() {
- Association association = null;
- try {
- association =
- edmProvider.getAssociation(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader_SalesOrderItem"));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertNull(association);
- }
-
- @Test
- public void testGetEntitySet() {
- try {
- assertNull(edmProvider.getEntitySet("salesorderprocessingContainer", "SalesOrderHeaders"));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetAssociationSet() {
- try {
- assertNull(edmProvider.getAssociationSet("salesorderprocessingContainer", new FullQualifiedName(
- "salesorderprocessing", "SalesOrderHeader_SalesOrderItem"), "SalesOrderHeaders", "SalesOrderHeader"));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @Test
- public void testNullGetFunctionImport() {
-
- try {
- assertNull(edmProvider.getFunctionImport("salesorderprocessingContainer", "SalesOrder_FunctionImport1"));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @Test
- public void testNullGetFunctionImport2() {
-
- try {
- ODataJPAEdmProvider provider = new ODataJPAEdmProvider();
- try {
- Class<? extends ODataJPAEdmProvider> clazz = provider.getClass();
- Field field = clazz.getDeclaredField("schemas");
- field.setAccessible(true);
- List<Schema> schemas = new ArrayList<Schema>();
- Schema schema = new Schema().setNamespace("salesorderprocessing");
- EntityContainer container = new EntityContainer().setName("salesorderprocessingContainer");
- List<EntityContainer> containerList = new ArrayList<EntityContainer>();
- containerList.add(container); // Empty Container
- schema.setEntityContainers(containerList);
- schemas.add(schema); // Empty Schema
- field.set(provider, schemas);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- assertNull(provider.getFunctionImport("salesorderprocessingContainer", "SalesOrder_FunctionImport1"));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @Test
- public void testGetSchemas() {
- try {
- assertNotNull(edmProvider.getSchemas());
- } catch (ODataException 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/57599da6/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProviderTest.java b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProviderTest.java
deleted file mode 100644
index 8dbd9da..0000000
--- a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProviderTest.java
+++ /dev/null
@@ -1,385 +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.edm;
-
-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.reflect.Field;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-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.AssociationSet;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.ODataJPAContextMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.EdmSchemaMock;
-import org.apache.olingo.odata2.processor.core.jpa.model.JPAEdmModel;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class ODataJPAEdmProviderTest {
-
- private static ODataJPAEdmProvider edmProvider;
-
- @BeforeClass
- public static void setup() {
-
- edmProvider = new ODataJPAEdmProvider();
- try {
- Class<? extends ODataJPAEdmProvider> clazz = edmProvider.getClass();
- Field field = clazz.getDeclaredField("schemas");
- field.setAccessible(true);
- List<Schema> schemas = new ArrayList<Schema>();
- schemas.add(EdmSchemaMock.createMockEdmSchema());
- field.set(edmProvider, schemas);
- field = clazz.getDeclaredField("oDataJPAContext");
- field.setAccessible(true);
- field.set(edmProvider, ODataJPAContextMock.mockODataJPAContext());
- field = clazz.getDeclaredField("jpaEdmModel");
- field.setAccessible(true);
- field.set(edmProvider, new JPAEdmModel(null, null));
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @Test
- public void testConstructor() {
- try {
- ODataJPAEdmProvider edmProv = new ODataJPAEdmProvider(ODataJPAContextMock.mockODataJPAContext());
- edmProv.getClass();
- } catch (Exception e) {
- e.printStackTrace();
- assertTrue(true);
- }
- }
-
- @Test
- public void testGetODataJPAContext() {
- String pUnitName = edmProvider.getODataJPAContext().getPersistenceUnitName();
- assertEquals("salesorderprocessing", pUnitName);
- }
-
- @Test
- public void testGetEntityContainerInfo() {
- String entityContainerName = null;
- EntityContainerInfo entityContainer = null;
- try {
- entityContainer = edmProvider.getEntityContainerInfo("salesorderprocessingContainer");
- entityContainerName = entityContainer.getName();
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- assertEquals("salesorderprocessingContainer", entityContainerName);
- assertNotNull(entityContainer);
- }
-
- @Test
- public void testDefaultGetEntityContainerInfo() {
- String entityContainerName = null;
- EntityContainerInfo entityContainer = null;
- try {
- entityContainer = edmProvider.getEntityContainerInfo(null);
- entityContainerName = entityContainer.getName();
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- assertEquals("salesorderprocessingContainer", entityContainerName);
- assertNotNull(entityContainer);
- }
-
- @Test
- public void testGetEntityType() {
- FullQualifiedName entityTypeName = new FullQualifiedName("salesorderprocessing", "SalesOrderHeader");
- String entityName = null;
- try {
- entityName = edmProvider.getEntityType(entityTypeName).getName();
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertEquals("SalesOrderHeader", entityName);
- try {
- edmProvider.getEntityType(new FullQualifiedName("salesorder", "abc"));
- } catch (ODataException e) {
- assertTrue(true);
- }
-
- }
-
- @Test
- public void testGetComplexType() {
- FullQualifiedName complexTypeName = new FullQualifiedName("salesorderprocessing", "Address");
- String nameStr = null;
- try {
- nameStr = edmProvider.getComplexType(complexTypeName).getName();
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertEquals("Address", nameStr);
- }
-
- @Test
- public void testGetAssociationFullQualifiedName() {
- Association association = null;
- try {
- association =
- edmProvider.getAssociation(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader_SalesOrderItem"));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertNotNull(association);
- assertEquals("SalesOrderHeader_SalesOrderItem", association.getName());
- }
-
- @Test
- public void testGetEntitySet() {
- String entitySetName = null;
- try {
- entitySetName = edmProvider.getEntitySet("salesorderprocessingContainer", "SalesOrderHeaders").getName();
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertEquals("SalesOrderHeaders", entitySetName);
- try {
- assertNull(edmProvider.getEntitySet("salesorderprocessing", "SalesOrderHeaders"));
- } catch (ODataException e) {
- assertTrue(true);
- }
- }
-
- @Test
- public void testGetAssociationSet() {
- AssociationSet associationSet = null;
-
- try {
- associationSet =
- edmProvider.getAssociationSet("salesorderprocessingContainer", new FullQualifiedName("salesorderprocessing",
- "SalesOrderHeader_SalesOrderItem"), "SalesOrderHeaders", "SalesOrderHeader");
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertNotNull(associationSet);
- assertEquals("SalesOrderHeader_SalesOrderItemSet", associationSet.getName());
- try {
- associationSet =
- edmProvider.getAssociationSet("salesorderprocessingContainer", new FullQualifiedName("salesorderprocessing",
- "SalesOrderHeader_SalesOrderItem"), "SalesOrderItems", "SalesOrderItem");
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertNotNull(associationSet);
- try {
- associationSet =
- edmProvider.getAssociationSet("salesorderproceContainer", new FullQualifiedName("salesorderprocessing",
- "SalesOrderHeader_SalesOrderItem"), "SalesOrderItems", "SalesOrderItem");
- } catch (ODataException e) {
- assertTrue(true);
- }
- }
-
- @Test
- public void testGetFunctionImport() {
- String functionImportName = null;
- try {
- functionImportName =
- edmProvider.getFunctionImport("salesorderprocessingContainer", "SalesOrder_FunctionImport1").getName();
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertEquals("SalesOrder_FunctionImport1", functionImportName);
- try {
- functionImportName =
- edmProvider.getFunctionImport("salesorderprocessingContainer", "SalesOrder_FunctionImport1").getName();
- } catch (ODataException e) {
- assertTrue(true);
- }
- try {
- assertNotNull(edmProvider.getFunctionImport("salesorderprocessingContainer", "SalesOrder_FunctionImport1"));
- } catch (ODataException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void testGetSchemas() {
- try {
- assertNotNull(edmProvider.getSchemas());
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testgetComplexTypeWithBuffer() {
- HashMap<String, ComplexType> compTypes = new HashMap<String, ComplexType>();
- ComplexType comp = new ComplexType();
- comp.setName("Address");
- compTypes.put("salesorderprocessing" + "." + "Address", comp);
- ODataJPAEdmProvider jpaEdmProv = new ODataJPAEdmProvider();
- Class<?> claz = jpaEdmProv.getClass();
- Field f;
- try {
- f = claz.getDeclaredField("complexTypes");
- f.setAccessible(true);
- f.set(jpaEdmProv, compTypes);
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- try {
- assertEquals(comp, jpaEdmProv.getComplexType(new FullQualifiedName("salesorderprocessing", "Address")));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- try {
- jpaEdmProv.getComplexType(new FullQualifiedName("salesorderessing", "abc"));
- } catch (ODataJPAModelException e) {
- assertTrue(true);
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetEntityContainerInfoWithBuffer() {
- HashMap<String, EntityContainerInfo> entityContainerInfos = new HashMap<String, EntityContainerInfo>();
- EntityContainerInfo entityContainer = new EntityContainerInfo();
- entityContainer.setName("salesorderprocessingContainer");
- entityContainerInfos.put("salesorderprocessingContainer", entityContainer);
- ODataJPAEdmProvider jpaEdmProv = new ODataJPAEdmProvider();
- Class<?> claz = jpaEdmProv.getClass();
- try {
- Field f = claz.getDeclaredField("entityContainerInfos");
- f.setAccessible(true);
- f.set(jpaEdmProv, entityContainerInfos);
- assertEquals(entityContainer, jpaEdmProv.getEntityContainerInfo("salesorderprocessingContainer"));
- jpaEdmProv.getEntityContainerInfo("abc");
- } catch (ODataJPAModelException e) {
- assertTrue(true);
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException 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 testGetEntityTypeWithBuffer() {
- HashMap<String, org.apache.olingo.odata2.api.edm.provider.EntityType> entityTypes =
- new HashMap<String, org.apache.olingo.odata2.api.edm.provider.EntityType>();
- org.apache.olingo.odata2.api.edm.provider.EntityType entity =
- new org.apache.olingo.odata2.api.edm.provider.EntityType();
- entity.setName("SalesOrderHeader");
- entityTypes.put("salesorderprocessing" + "." + "SalesorderHeader", entity);
- ODataJPAEdmProvider jpaEdmProv = new ODataJPAEdmProvider();
- Class<?> claz = jpaEdmProv.getClass();
- Field f;
- try {
- f = claz.getDeclaredField("entityTypes");
- f.setAccessible(true);
- f.set(jpaEdmProv, entityTypes);
- assertEquals(entity, jpaEdmProv.getEntityType(new FullQualifiedName("salesorderprocessing", "SalesorderHeader")));
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException 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);
- }
- try {
- jpaEdmProv.getEntityType(new FullQualifiedName("salesoprocessing", "abc"));
- } catch (ODataJPAModelException e) {
- assertTrue(true);
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetAssociationWithBuffer() {
- HashMap<String, Association> associations = new HashMap<String, Association>();
- Association association = new Association();
- association.setName("SalesOrderHeader_SalesOrderItem");
- associations.put("salesorderprocessing" + "." + "SalesOrderHeader_SalesOrderItem", association);
- ODataJPAEdmProvider jpaEdmProv = new ODataJPAEdmProvider();
- Class<?> claz = jpaEdmProv.getClass();
- Field f;
- try {
- f = claz.getDeclaredField("associations");
- f.setAccessible(true);
- f.set(jpaEdmProv, associations);
- assertEquals(association, jpaEdmProv.getAssociation(new FullQualifiedName("salesorderprocessing",
- "SalesOrderHeader_SalesOrderItem")));
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException 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);
- }
- try {
- jpaEdmProv.getAssociation(new FullQualifiedName("salesorderprocessing", "abc"));
- } catch (ODataJPAModelException e) {
- assertTrue(true);
- } catch (ODataException 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/57599da6/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLBuilderFactoryTest.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLBuilderFactoryTest.java b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLBuilderFactoryTest.java
deleted file mode 100644
index 7da02d8..0000000
--- a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLBuilderFactoryTest.java
+++ /dev/null
@@ -1,377 +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.jpql;
-
-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.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import javax.persistence.Cache;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceUnitUtil;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.metamodel.Metamodel;
-
-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.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.NavigationSegment;
-import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.factory.JPAAccessFactory;
-import org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAAccessFactory;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext.JPQLContextBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement.JPQLStatementBuilder;
-import org.apache.olingo.odata2.processor.core.jpa.ODataJPAContextImpl;
-import org.apache.olingo.odata2.processor.core.jpa.access.data.JPAProcessorImplTest;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.factory.ODataJPAFactoryImpl;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLSelectContext.JPQLSelectContextBuilder;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLSelectSingleContext.JPQLSelectSingleContextBuilder;
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-public class JPQLBuilderFactoryTest {
-
- @Test
- public void testGetStatementBuilderFactoryforSelect() throws ODataException {
-
- GetEntitySetUriInfo getEntitySetView = getUriInfo();
-
- // Build JPQL Context
- JPQLContext selectContext = JPQLContext.createBuilder(JPQLContextType.SELECT, getEntitySetView).build();
- JPQLStatementBuilder statementBuilder =
- new ODataJPAFactoryImpl().getJPQLBuilderFactory().getStatementBuilder(selectContext);
-
- assertTrue(statementBuilder instanceof JPQLSelectStatementBuilder);
-
- }
-
- @Test
- public void testGetStatementBuilderFactoryforSelectSingle() throws ODataException {
-
- GetEntityUriInfo getEntityView = getEntityUriInfo();
-
- // Build JPQL Context
- JPQLContext selectContext = JPQLContext.createBuilder(JPQLContextType.SELECT_SINGLE, getEntityView).build();
- JPQLStatementBuilder statementBuilder =
- new ODataJPAFactoryImpl().getJPQLBuilderFactory().getStatementBuilder(selectContext);
-
- assertTrue(statementBuilder instanceof JPQLSelectSingleStatementBuilder);
-
- }
-
- @Test
- public void testGetStatementBuilderFactoryforJoinSelect() throws ODataException {
-
- GetEntitySetUriInfo getEntitySetView = getUriInfo();
-
- // Build JPQL Context
- JPQLContext selectContext = JPQLContext.createBuilder(JPQLContextType.JOIN, getEntitySetView).build();
- JPQLStatementBuilder statementBuilder =
- new ODataJPAFactoryImpl().getJPQLBuilderFactory().getStatementBuilder(selectContext);
-
- assertTrue(statementBuilder instanceof JPQLJoinStatementBuilder);
-
- }
-
- @Test
- public void testGetStatementBuilderFactoryforJoinSelectSingle() throws ODataException {
-
- GetEntityUriInfo getEntityView = getEntityUriInfo();
-
- // Build JPQL Context
- JPQLContext selectContext = JPQLContext.createBuilder(JPQLContextType.JOIN_SINGLE, getEntityView).build();
- JPQLStatementBuilder statementBuilder =
- new ODataJPAFactoryImpl().getJPQLBuilderFactory().getStatementBuilder(selectContext);
-
- assertTrue(statementBuilder instanceof JPQLJoinSelectSingleStatementBuilder);
-
- }
-
- @Test
- public void testGetContextBuilderforDelete() throws ODataException {
-
- // Build JPQL ContextBuilder
- JPQLContextBuilder contextBuilder =
- new ODataJPAFactoryImpl().getJPQLBuilderFactory().getContextBuilder(JPQLContextType.DELETE);
-
- assertNull(contextBuilder);
-
- }
-
- @Test
- public void testGetContextBuilderforSelect() throws ODataException {
-
- // Build JPQL ContextBuilder
- JPQLContextBuilder contextBuilder =
- new ODataJPAFactoryImpl().getJPQLBuilderFactory().getContextBuilder(JPQLContextType.SELECT);
-
- assertNotNull(contextBuilder);
- assertTrue(contextBuilder instanceof JPQLSelectContextBuilder);
-
- }
-
- @Test
- public void testGetContextBuilderforSelectSingle() throws ODataException {
-
- // Build JPQL ContextBuilder
- JPQLContextBuilder contextBuilder =
- new ODataJPAFactoryImpl().getJPQLBuilderFactory().getContextBuilder(JPQLContextType.SELECT_SINGLE);
-
- assertNotNull(contextBuilder);
- assertTrue(contextBuilder instanceof JPQLSelectSingleContextBuilder);
-
- }
-
- private GetEntitySetUriInfo getUriInfo() throws EdmException {
- GetEntitySetUriInfo getEntitySetView = EasyMock.createMock(GetEntitySetUriInfo.class);
- EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(edmEntityType.getName()).andStubReturn("SOItem");
- EasyMock.replay(edmEntityType);
- OrderByExpression orderByExpression = EasyMock.createMock(OrderByExpression.class);
- EasyMock.expect(getEntitySetView.getTargetEntitySet()).andStubReturn(edmEntitySet);
- EdmEntitySet startEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType startEdmEntityType = EasyMock.createMock(EdmEntityType.class);
- EasyMock.expect(startEdmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(startEdmEntityType.getName()).andStubReturn("SOHeader");
- EasyMock.expect(startEdmEntitySet.getEntityType()).andStubReturn(startEdmEntityType);
- EasyMock.expect(getEntitySetView.getStartEntitySet()).andStubReturn(startEdmEntitySet);
- EasyMock.replay(startEdmEntityType, startEdmEntitySet);
- EasyMock.expect(getEntitySetView.getOrderBy()).andStubReturn(orderByExpression);
- EasyMock.expect(getEntitySetView.getSelect()).andStubReturn(null);
- EasyMock.expect(getEntitySetView.getFilter()).andStubReturn(null);
- List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
- EasyMock.expect(getEntitySetView.getNavigationSegments()).andStubReturn(navigationSegments);
- KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
- EdmProperty kpProperty = EasyMock.createMock(EdmProperty.class);
- EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("Field1");
- EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
- try {
- EasyMock.expect(kpProperty.getName()).andStubReturn("Field1");
- EasyMock.expect(kpProperty.getType()).andStubReturn(edmType);
-
- EasyMock.expect(kpProperty.getMapping()).andStubReturn(edmMapping);
-
- } catch (EdmException e2) {
- fail("this should not happen");
- }
- EasyMock.expect(keyPredicate.getProperty()).andStubReturn(kpProperty);
- EasyMock.replay(edmMapping, edmType, kpProperty, keyPredicate);
- List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
- keyPredicates.add(keyPredicate);
- EasyMock.expect(getEntitySetView.getKeyPredicates()).andStubReturn(keyPredicates);
- EasyMock.replay(getEntitySetView);
- EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
- EasyMock.replay(edmEntitySet);
- return getEntitySetView;
- }
-
- private GetEntityUriInfo getEntityUriInfo() throws EdmException {
- GetEntityUriInfo getEntityView = EasyMock.createMock(GetEntityUriInfo.class);
- EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>());
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(edmEntityType.getName()).andStubReturn("");
- EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
- EasyMock.expect(getEntityView.getSelect()).andStubReturn(null);
- EasyMock.expect(getEntityView.getTargetEntitySet()).andStubReturn(edmEntitySet);
- EdmEntitySet startEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType startEdmEntityType = EasyMock.createMock(EdmEntityType.class);
- EasyMock.expect(startEdmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(startEdmEntityType.getName()).andStubReturn("SOHeader");
- EasyMock.expect(startEdmEntitySet.getEntityType()).andStubReturn(startEdmEntityType);
- EasyMock.expect(getEntityView.getStartEntitySet()).andStubReturn(startEdmEntitySet);
- EasyMock.replay(startEdmEntityType, startEdmEntitySet);
- EasyMock.replay(edmEntityType, edmEntitySet);
- EasyMock.expect(getEntityView.getKeyPredicates()).andStubReturn(new ArrayList<KeyPredicate>());
- List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
- EasyMock.expect(getEntityView.getNavigationSegments()).andStubReturn(navigationSegments);
- EasyMock.replay(getEntityView);
- return getEntityView;
- }
-
- @Test
- public void testJPAAccessFactory() {
- ODataJPAFactoryImpl oDataJPAFactoryImpl = new ODataJPAFactoryImpl();
- JPAAccessFactory jpaAccessFactory = oDataJPAFactoryImpl.getJPAAccessFactory();
- ODataJPAContextImpl oDataJPAContextImpl = new ODataJPAContextImpl();
- Class<?> clazz = oDataJPAContextImpl.getClass();
- try {
- Field field = clazz.getDeclaredField("em");
- field.setAccessible(true);
- field.set(oDataJPAContextImpl, new JPAProcessorImplTest().getLocalEntityManager());
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EntityManagerFactory emf = new EntityManagerFactory() {
-
- @Override
- public boolean isOpen() {
- return false;
- }
-
- @Override
- public Map<String, Object> getProperties() {
- return null;
- }
-
- @Override
- public PersistenceUnitUtil getPersistenceUnitUtil() {
- return null;
- }
-
- @Override
- public Metamodel getMetamodel() {
- return null;
- }
-
- @Override
- public CriteriaBuilder getCriteriaBuilder() {
- return null;
- }
-
- @Override
- public Cache getCache() {
- return null;
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public EntityManager createEntityManager(final Map arg0) {
- return null;
- }
-
- @Override
- public EntityManager createEntityManager() {
- return null;
- }
-
- @Override
- public void close() {}
- };
- oDataJPAContextImpl.setEntityManagerFactory(emf);
- oDataJPAContextImpl.setPersistenceUnitName("pUnit");
-
- assertNotNull(jpaAccessFactory.getJPAProcessor(oDataJPAContextImpl));
- assertNotNull(jpaAccessFactory.getJPAEdmModelView(oDataJPAContextImpl));
-
- }
-
- @Test
- public void testOdataJpaAccessFactory() {
-
- ODataJPAFactoryImpl oDataJPAFactoryImpl = new ODataJPAFactoryImpl();
- ODataJPAAccessFactory jpaAccessFactory = oDataJPAFactoryImpl.getODataJPAAccessFactory();
- ODataJPAContextImpl oDataJPAContextImpl = new ODataJPAContextImpl();
-
- EntityManagerFactory emf = new EntityManagerFactory() {
-
- @Override
- public boolean isOpen() {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public Map<String, Object> getProperties() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public PersistenceUnitUtil getPersistenceUnitUtil() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Metamodel getMetamodel() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public CriteriaBuilder getCriteriaBuilder() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Cache getCache() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public EntityManager createEntityManager(final Map arg0) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public EntityManager createEntityManager() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void close() {
- // TODO Auto-generated method stub
-
- }
- };
- oDataJPAContextImpl.setEntityManagerFactory(emf);
- oDataJPAContextImpl.setPersistenceUnitName("pUnit");
-
- assertNotNull(jpaAccessFactory.getODataJPAMessageService(new Locale("en")));
- assertNotNull(jpaAccessFactory.createODataJPAContext());
- assertNotNull(jpaAccessFactory.createJPAEdmProvider(oDataJPAContextImpl));
- assertNotNull(jpaAccessFactory.createODataProcessor(oDataJPAContextImpl));
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinContextTest.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinContextTest.java b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinContextTest.java
deleted file mode 100644
index 509591f..0000000
--- a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinContextTest.java
+++ /dev/null
@@ -1,198 +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.jpql;
-
-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.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmAssociation;
-import org.apache.olingo.odata2.api.edm.EdmAssociationEnd;
-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.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.NavigationSegment;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAJoinClause;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLJoinSelectContext.JPQLJoinContextBuilder;
-import org.easymock.EasyMock;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class JPQLJoinContextTest {
-
- GetEntitySetUriInfo entitySetUriInfo;
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {}
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {}
-
- @Before
- public void setUp() throws Exception {
- entitySetUriInfo = EasyMock.createMock(GetEntitySetUriInfo.class);
- EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
- final EdmNavigationProperty navigationProperty = createNavigationProperty("a");
- final EdmNavigationProperty navigationProperty1 = createNavigationProperty("b");
- final List<KeyPredicate> keyPredicates = createKeyPredicates();
- NavigationSegment navigationSegment = new NavigationSegment() {
-
- @Override
- public EdmNavigationProperty getNavigationProperty() {
- return navigationProperty;
- }
-
- @Override
- public List<KeyPredicate> getKeyPredicates() {
- return keyPredicates;
- }
-
- @Override
- public EdmEntitySet getEntitySet() {
- // TODO Auto-generated method stub
- return null;
- }
- };
- NavigationSegment navigationSegment1 = new NavigationSegment() {
-
- @Override
- public EdmNavigationProperty getNavigationProperty() {
- return navigationProperty1;
- }
-
- @Override
- public List<KeyPredicate> getKeyPredicates() {
- return keyPredicates;
- }
-
- @Override
- public EdmEntitySet getEntitySet() {
- // TODO Auto-generated method stub
- return null;
- }
- };
- navigationSegments.add(navigationSegment);
- navigationSegments.add(navigationSegment1);
- EasyMock.expect(entitySetUriInfo.getNavigationSegments()).andStubReturn(navigationSegments);
- EasyMock.expect(entitySetUriInfo.getOrderBy()).andStubReturn(null);
- EasyMock.expect(entitySetUriInfo.getTop()).andStubReturn(null);
- EasyMock.expect(entitySetUriInfo.getSkip()).andStubReturn(null);
- EasyMock.expect(entitySetUriInfo.getSelect()).andStubReturn(null);
- EasyMock.expect(entitySetUriInfo.getFilter()).andStubReturn(null);
- EasyMock.expect(entitySetUriInfo.getKeyPredicates()).andStubReturn(keyPredicates);
- EasyMock.expect(entitySetUriInfo.getTargetEntitySet()).andStubReturn(edmEntitySet);
- EdmEntitySet startEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType startEdmEntityType = EasyMock.createMock(EdmEntityType.class);
- EasyMock.expect(startEdmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(startEdmEntityType.getName()).andStubReturn("SOHeader");
- EasyMock.expect(startEdmEntitySet.getEntityType()).andStubReturn(startEdmEntityType);
- EasyMock.expect(entitySetUriInfo.getStartEntitySet()).andStubReturn(startEdmEntitySet);
- EasyMock.replay(startEdmEntityType, startEdmEntitySet);
- EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(edmEntityType.getName()).andStubReturn("SOHeader");
- EasyMock.replay(edmEntityType, edmEntitySet, entitySetUriInfo);
-
- }
-
- @After
- public void tearDown() throws Exception {}
-
- @Test
- public void testGetJPAOuterJoinClauses() {
- JPQLJoinSelectContext joinContext = new JPQLJoinSelectContext(false);
- JPQLJoinContextBuilder joinContextBuilder = joinContext.new JPQLJoinContextBuilder();
- try {
- joinContextBuilder.entitySetView = entitySetUriInfo;
- joinContextBuilder.build();
- } catch (ODataJPAModelException e) {
- fail("Should not come here");
- } catch (ODataJPARuntimeException e) {
- fail("Should not come here");
- }
- List<JPAJoinClause> joinClauses = joinContext.getJPAJoinClauses();
- assertNotNull(joinClauses);
- assertTrue(joinClauses.size() > 0);
- assertEquals("E1", joinClauses.get(0).getEntityAlias());
- assertEquals("SOHeader", joinClauses.get(0).getEntityName());
- assertEquals("s_Itema", joinClauses.get(1).getEntityRelationShip());
- assertEquals("R1", joinClauses.get(1).getEntityRelationShipAlias());
- }
-
- private EdmNavigationProperty createNavigationProperty(final String z) throws EdmException {
- EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
- EdmAssociation association = EasyMock.createMock(EdmAssociation.class);
- EdmAssociationEnd associationEnd = EasyMock.createMock(EdmAssociationEnd.class);
- EasyMock.expect(navigationProperty.getFromRole()).andStubReturn("roleA" + z);
- EasyMock.expect(navigationProperty.getToRole()).andStubReturn("roleB" + z);
- EasyMock.expect(navigationProperty.getName()).andStubReturn("navP" + z);
- EasyMock.expect(navigationProperty.getName()).andStubReturn("navP" + z);
- EasyMock.expect(navigationProperty.getMultiplicity()).andStubReturn(EdmMultiplicity.ONE);
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("sItem" + z);
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(edmMapping);
- EasyMock.expect(edmEntityType.getName()).andStubReturn("soItem" + z);
- EasyMock.expect(associationEnd.getEntityType()).andStubReturn(edmEntityType);
- EasyMock.expect(association.getEnd("roleA" + z)).andStubReturn(associationEnd);
- EasyMock.expect(navigationProperty.getRelationship()).andStubReturn(association);
- EdmMapping edmMapping1 = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping1.getInternalName()).andStubReturn("s_Item" + z);
- EasyMock.expect(navigationProperty.getMapping()).andStubReturn(edmMapping1);
- EasyMock.replay(edmMapping, edmMapping1, edmEntityType, associationEnd, association, navigationProperty);
- return navigationProperty;
- }
-
- private List<KeyPredicate> createKeyPredicates() throws EdmException {
- KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
- EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
- EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soid");
- EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
- EasyMock.expect(edmProperty.getName()).andStubReturn("soid");
- EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
- EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
- EasyMock.expect(keyPredicate.getProperty()).andStubReturn(edmProperty);
-
- EasyMock.replay(edmType, edmMapping, edmProperty, keyPredicate);
- List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
- keyPredicates.add(keyPredicate);
- return keyPredicates;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleContextTest.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleContextTest.java b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleContextTest.java
deleted file mode 100644
index b7c9c7d..0000000
--- a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleContextTest.java
+++ /dev/null
@@ -1,215 +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.jpql;
-
-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.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmAssociation;
-import org.apache.olingo.odata2.api.edm.EdmAssociationEnd;
-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.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.NavigationSegment;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAJoinClause;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLJoinSelectSingleContext.JPQLJoinSelectSingleContextBuilder;
-import org.easymock.EasyMock;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class JPQLJoinSelectSingleContextTest {
-
- GetEntityUriInfo entityUriInfo;
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {}
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {}
-
- public void setUp(final boolean toThrowException) throws Exception {
- entityUriInfo = EasyMock.createMock(GetEntityUriInfo.class);
- EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
- final EdmNavigationProperty navigationProperty = createNavigationProperty("a");
- final EdmNavigationProperty navigationProperty1 = createNavigationProperty("b");
- final List<KeyPredicate> keyPredicates = createKeyPredicates(toThrowException);
- NavigationSegment navigationSegment = new NavigationSegment() {
-
- @Override
- public EdmNavigationProperty getNavigationProperty() {
- return navigationProperty;
- }
-
- @Override
- public List<KeyPredicate> getKeyPredicates() {
- return keyPredicates;
- }
-
- @Override
- public EdmEntitySet getEntitySet() {
- // TODO Auto-generated method stub
- return null;
- }
- };
- NavigationSegment navigationSegment1 = new NavigationSegment() {
-
- @Override
- public EdmNavigationProperty getNavigationProperty() {
- return navigationProperty1;
- }
-
- @Override
- public List<KeyPredicate> getKeyPredicates() {
- return keyPredicates;
- }
-
- @Override
- public EdmEntitySet getEntitySet() {
- // TODO Auto-generated method stub
- return null;
- }
- };
- navigationSegments.add(navigationSegment);
- navigationSegments.add(navigationSegment1);
- EasyMock.expect(entityUriInfo.getNavigationSegments()).andStubReturn(navigationSegments);
- EasyMock.expect(entityUriInfo.getSelect()).andStubReturn(null);
- EasyMock.expect(entityUriInfo.getFilter()).andStubReturn(null);
- EasyMock.expect(entityUriInfo.getKeyPredicates()).andStubReturn(createKeyPredicates(toThrowException));
- EasyMock.expect(entityUriInfo.getTargetEntitySet()).andStubReturn(edmEntitySet);
- EdmEntitySet startEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType startEdmEntityType = EasyMock.createMock(EdmEntityType.class);
- EasyMock.expect(startEdmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(startEdmEntityType.getName()).andStubReturn("SOHeader");
- EasyMock.expect(startEdmEntitySet.getEntityType()).andStubReturn(startEdmEntityType);
- EasyMock.expect(entityUriInfo.getStartEntitySet()).andStubReturn(startEdmEntitySet);
- EasyMock.replay(startEdmEntityType, startEdmEntitySet);
- EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(edmEntityType.getName()).andStubReturn("SOHeader");
- EasyMock.replay(edmEntityType, edmEntitySet, entityUriInfo);
-
- }
-
- @After
- public void tearDown() throws Exception {}
-
- @Test
- public void testGetJPAOuterJoinClauses() throws Exception {
- setUp(false);
-
- JPQLJoinSelectSingleContext joinContext = new JPQLJoinSelectSingleContext();
- JPQLJoinSelectSingleContextBuilder joinContextBuilder = joinContext.new JPQLJoinSelectSingleContextBuilder();
- try {
- joinContextBuilder.entityView = entityUriInfo;
- joinContextBuilder.build();
- } catch (ODataJPAModelException e) {
- fail("Should not come here");
- } catch (ODataJPARuntimeException e) {
- fail("Should not come here");
- }
- List<JPAJoinClause> joinClauses = joinContext.getJPAJoinClauses();
- assertNotNull(joinClauses);
- assertTrue(joinClauses.size() > 0);
- assertEquals("E1", joinClauses.get(0).getEntityAlias());
- assertEquals("SOHeader", joinClauses.get(0).getEntityName());
- assertEquals("s_Itema", joinClauses.get(1).getEntityRelationShip());
- assertEquals("R1", joinClauses.get(1).getEntityRelationShipAlias());
- }
-
- @Test
- public void testExceptionThrown() throws Exception {
- setUp(true);
- JPQLJoinSelectSingleContext joinContext = new JPQLJoinSelectSingleContext();
- JPQLJoinSelectSingleContextBuilder joinContextBuilder = joinContext.new JPQLJoinSelectSingleContextBuilder();
- try {
- joinContextBuilder.entityView = entityUriInfo;
- joinContextBuilder.build();
- fail("Should not come here");
- } catch (ODataJPAModelException e) {
- fail("Should not come here");
- } catch (ODataJPARuntimeException e) {
- assertTrue(true);
- }
- }
-
- private EdmNavigationProperty createNavigationProperty(final String z) throws EdmException {
- EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
- EdmAssociation association = EasyMock.createMock(EdmAssociation.class);
- EdmAssociationEnd associationEnd = EasyMock.createMock(EdmAssociationEnd.class);
- EasyMock.expect(navigationProperty.getFromRole()).andStubReturn("roleA" + z);
- EasyMock.expect(navigationProperty.getToRole()).andStubReturn("roleB" + z);
- EasyMock.expect(navigationProperty.getName()).andStubReturn("navP" + z);
- EasyMock.expect(navigationProperty.getName()).andStubReturn("navP" + z);
- EasyMock.expect(navigationProperty.getMultiplicity()).andStubReturn(EdmMultiplicity.ONE);
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("sItem" + z);
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(edmMapping);
- EasyMock.expect(edmEntityType.getName()).andStubReturn("soItem" + z);
- EasyMock.expect(associationEnd.getEntityType()).andStubReturn(edmEntityType);
- EasyMock.expect(association.getEnd("roleA" + z)).andStubReturn(associationEnd);
- EasyMock.expect(navigationProperty.getRelationship()).andStubReturn(association);
- EdmMapping edmMapping1 = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping1.getInternalName()).andStubReturn("s_Item" + z);
- EasyMock.expect(navigationProperty.getMapping()).andStubReturn(edmMapping1);
- EasyMock.replay(edmMapping, edmMapping1, edmEntityType, associationEnd, association, navigationProperty);
- return navigationProperty;
- }
-
- private List<KeyPredicate> createKeyPredicates(final boolean toThrowException) throws EdmException {
- KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
- EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
- EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soid");
- EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
- EasyMock.expect(edmProperty.getName()).andStubReturn("soid");
- EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
- if (toThrowException) {
- EasyMock.expect(edmProperty.getType()).andStubThrow(new EdmException(null));
- } else {
- EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
- }
- EasyMock.expect(keyPredicate.getProperty()).andStubReturn(edmProperty);
-
- EasyMock.replay(edmType, edmMapping, edmProperty, keyPredicate);
- List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
- keyPredicates.add(keyPredicate);
- return keyPredicates;
- }
-
-}