You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by fm...@apache.org on 2013/07/26 13:22:46 UTC
[41/51] [partial] initial commit
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ff2b0a0e/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAResponseBuilderTest.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAResponseBuilderTest.java b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAResponseBuilderTest.java
new file mode 100644
index 0000000..3684790
--- /dev/null
+++ b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAResponseBuilderTest.java
@@ -0,0 +1,675 @@
+/*******************************************************************************
+ * 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.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+import org.apache.olingo.odata2.api.commons.InlineCount;
+import org.apache.olingo.odata2.api.edm.EdmEntityContainer;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+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.edm.EdmSimpleTypeException;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.Facets;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
+import org.apache.olingo.odata2.api.uri.PathInfo;
+import org.apache.olingo.odata2.api.uri.SelectItem;
+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.ODataJPAContext;
+import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.processor.core.jpa.model.JPAEdmTestModelView;
+
+public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
+
+ /*
+ * This Unit is supposed to test the building of Entity Provider Properties for query with $expand
+ */
+ @Test
+ public void testGetEntityProviderPropertiesQuery() {
+ GetEntitySetUriInfo getEntitySetUriInfo = mockEntitySetUriInfoForExpand();
+ ODataJPAContext oDataJPAContext = getODataJPAContext();
+ // Building the edm entity
+ List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
+ Map<String, Object> edmEntity = new HashMap<String, Object>();
+ edmEntity.put("ID", 1);
+ edmEntityList.add(edmEntity);
+ // Invoking the private static method using reflection
+ Class<?> clazz = ODataJPAResponseBuilder.class;
+ Object[] actualParameters = { oDataJPAContext, getEntitySetUriInfo, edmEntityList };
+ Class<?>[] formalParameters = { ODataJPAContext.class,
+ GetEntitySetUriInfo.class, List.class };
+ EntityProviderWriteProperties providerProperties = null;
+ try {
+ ODataJPAResponseBuilder responseBuilder = (ODataJPAResponseBuilder) clazz
+ .newInstance();
+ Method method = clazz.getDeclaredMethod(
+ "getEntityProviderProperties", formalParameters);
+ method.setAccessible(true);
+ providerProperties = (EntityProviderWriteProperties) method.invoke(
+ responseBuilder, actualParameters);
+ assertEquals(1, providerProperties.getExpandSelectTree().getLinks()
+ .size());
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchMethodException 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 (InvocationTargetException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (InstantiationException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ /*
+ * This Unit is supposed to test the building of Entity Provider Properties for read with $expand
+ */
+ @Test
+ public void testGetEntityProviderPropertiesRead() {
+
+ // Getting the EntityUriInfo
+ GetEntityUriInfo getEntityUriInfo = mockEntityUriInfoForExpand();
+ ODataJPAContext oDataJPAContext = getODataJPAContext();
+ Class<?> clazz = ODataJPAResponseBuilder.class;
+ Object[] actualParameters = { oDataJPAContext, getEntityUriInfo };
+ Class<?>[] formalParameters = { ODataJPAContext.class,
+ GetEntityUriInfo.class };
+ EntityProviderWriteProperties providerProperties = null;
+ try {
+ ODataJPAResponseBuilder responseBuilder = (ODataJPAResponseBuilder) clazz
+ .newInstance();
+ Method method = clazz.getDeclaredMethod(
+ "getEntityProviderProperties", formalParameters);
+ method.setAccessible(true);
+ providerProperties = (EntityProviderWriteProperties) method.invoke(
+ responseBuilder, actualParameters);
+ assertEquals(1, providerProperties.getExpandSelectTree().getLinks()
+ .size());
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchMethodException 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 (InvocationTargetException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (InstantiationException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testConstructListofNavProperty()
+ {
+ List<ArrayList<NavigationPropertySegment>> expand = new ArrayList<ArrayList<NavigationPropertySegment>>();
+ ArrayList<NavigationPropertySegment> navPropList1 = new ArrayList<NavigationPropertySegment>();
+ navPropList1.add(getNavigationPropertySegment("DemoNavigationProperties11"));
+ navPropList1.add(getNavigationPropertySegment("DemoNavigationProperties12"));
+ expand.add(navPropList1);
+ ArrayList<NavigationPropertySegment> navPropList2 = new ArrayList<NavigationPropertySegment>();
+ navPropList2.add(getNavigationPropertySegment("DemoNavigationProperties21"));
+ navPropList2.add(getNavigationPropertySegment("DemoNavigationProperties22"));
+ expand.add(navPropList2);
+ Class<?> clazz = ODataJPAResponseBuilder.class;
+ Object[] actualParameters = { expand };
+ Class<?>[] formalParameters = { List.class };
+ List<EdmNavigationProperty> navigationProperties = null;
+ try {
+ ODataJPAResponseBuilder responseBuilder = (ODataJPAResponseBuilder) clazz
+ .newInstance();
+ Method method = clazz.getDeclaredMethod(
+ "constructListofNavProperty", formalParameters);
+ method.setAccessible(true);
+ navigationProperties = (List<EdmNavigationProperty>) method.invoke(
+ responseBuilder, actualParameters);
+ assertEquals("DemoNavigationProperties21", navigationProperties.get(1).getName());
+ assertEquals("DemoNavigationProperties11", navigationProperties.get(0).getName());
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchMethodException 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 (InvocationTargetException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (InstantiationException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ @Test
+ public void testBuildListOfTGetEntitySetUriInfoStringODataJPAContext() {
+ try {
+ assertNotNull(ODataJPAResponseBuilder.build(getJPAEntities(),
+ getResultsView(), "application/xml", getODataJPAContext()));
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ @Test
+ public void testBuildNegatives() {// Bad content type
+ try {
+ EntityType entity = new EntityType();
+ entity.setName("SalesOrderHeader");
+ try {
+ assertNotNull(ODataJPAResponseBuilder.build(getEntity(),
+ getLocalGetURIInfo(), "xml", getODataJPAContext()));
+ } catch (ODataNotFoundException e) {
+ assertTrue(true);
+ }
+ } catch (ODataJPARuntimeException e) {
+ assertTrue(true);// Nothing to do, Expected.
+ }
+ try {// Bad content type
+ assertNotNull(ODataJPAResponseBuilder.build(getJPAEntities(),
+ getResultsView(), "xml", getODataJPAContext()));
+ } catch (ODataJPARuntimeException e) {
+ assertTrue(true);// Nothing to do, Expected.
+ }
+
+ }
+
+ @Test
+ public void testBuildObjectGetEntityUriInfoStringODataJPAContext()
+ throws ODataNotFoundException {
+ try {
+ assertNotNull(ODataJPAResponseBuilder.build(new SalesOrderHeader(2,
+ 10), getLocalGetURIInfo(), "application/xml",
+ getODataJPAContext()));
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testBuildNullSelects() {// Bad content type
+ try {
+ ODataJPAResponseBuilder.build(getJPAEntities(),
+ getResultsViewWithNullSelects(), "xml",
+ getODataJPAContext());
+ } catch (ODataJPARuntimeException e) {
+ assertTrue(true);// Nothing to do, Expected.
+ } catch (Exception e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testBuildGetCount() {
+ ODataResponse objODataResponse = null;
+ try {
+ objODataResponse = ODataJPAResponseBuilder.build(1,
+ getODataJPAContext());
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertNotNull(objODataResponse);
+ }
+
+ private ODataJPAContext getODataJPAContext() {
+ ODataJPAContext objODataJPAContext = EasyMock
+ .createMock(ODataJPAContext.class);
+ EasyMock.expect(objODataJPAContext.getODataContext()).andStubReturn(
+ getLocalODataContext());
+ EasyMock.replay(objODataJPAContext);
+ return objODataJPAContext;
+ }
+
+ private ODataContext getLocalODataContext() {
+ ODataContext objODataContext = EasyMock.createMock(ODataContext.class);
+ try {
+ EasyMock.expect(objODataContext.getPathInfo()).andStubReturn(
+ getLocalPathInfo());
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(objODataContext);
+ return objODataContext;
+ }
+
+ private PathInfo getLocalPathInfo() {
+ PathInfo pathInfo = EasyMock.createMock(PathInfo.class);
+ EasyMock.expect(pathInfo.getServiceRoot()).andStubReturn(getLocalURI());
+ EasyMock.replay(pathInfo);
+ return pathInfo;
+ }
+
+ private URI getLocalURI() {
+ URI uri = null;
+ try {
+ uri = new URI(
+ "http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/");
+ } catch (URISyntaxException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return uri;
+ }
+
+ private GetEntitySetUriInfo getResultsView() {
+ GetEntitySetUriInfo objGetEntitySetUriInfo = EasyMock
+ .createMock(GetEntitySetUriInfo.class);
+ EasyMock.expect(objGetEntitySetUriInfo.getInlineCount()).andStubReturn(
+ getLocalInlineCount());
+ EasyMock.expect(objGetEntitySetUriInfo.getTargetEntitySet())
+ .andStubReturn(getLocalTargetEntitySet());
+ EasyMock.expect(objGetEntitySetUriInfo.getSelect()).andStubReturn(
+ getSelectItemList());
+ EasyMock.expect(objGetEntitySetUriInfo.getExpand()).andStubReturn(
+ getExpandList());
+ EasyMock.expect(objGetEntitySetUriInfo.getSkip()).andStubReturn(new Integer(1));
+ EasyMock.replay(objGetEntitySetUriInfo);
+ return objGetEntitySetUriInfo;
+ }
+
+ private List<ArrayList<NavigationPropertySegment>> getExpandList() {
+ List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
+ return expandList;
+ }
+
+ private GetEntitySetUriInfo getResultsViewWithNullSelects() {
+ GetEntitySetUriInfo objGetEntitySetUriInfo = EasyMock
+ .createMock(GetEntitySetUriInfo.class);
+ EasyMock.expect(objGetEntitySetUriInfo.getInlineCount()).andStubReturn(
+ getLocalInlineCount());
+ EasyMock.expect(objGetEntitySetUriInfo.getTargetEntitySet())
+ .andStubReturn(getLocalTargetEntitySet());
+ EasyMock.expect(objGetEntitySetUriInfo.getSelect()).andStubReturn(null);
+ EasyMock.expect(objGetEntitySetUriInfo.getExpand()).andStubReturn(null);
+ EasyMock.expect(objGetEntitySetUriInfo.getSkip()).andStubReturn(new Integer(1));
+
+ EasyMock.replay(objGetEntitySetUriInfo);
+ return objGetEntitySetUriInfo;
+ }
+
+ private GetEntityUriInfo getLocalGetURIInfo() {
+ GetEntityUriInfo objGetEntityUriInfo = EasyMock
+ .createMock(GetEntityUriInfo.class);
+ EasyMock.expect(objGetEntityUriInfo.getSelect()).andStubReturn(
+ getSelectItemList());
+ EasyMock.expect(objGetEntityUriInfo.getTargetEntitySet())
+ .andStubReturn(getLocalTargetEntitySet());
+ EasyMock.expect(objGetEntityUriInfo.getExpand()).andStubReturn(
+ getExpandList());
+ EasyMock.replay(objGetEntityUriInfo);
+ return objGetEntityUriInfo;
+ }
+
+ private List<SelectItem> getSelectItemList() {
+ List<SelectItem> selectItems = new ArrayList<SelectItem>();
+ selectItems.add(getSelectItem());
+ return selectItems;
+ }
+
+ private SelectItem getSelectItem() {
+ SelectItem selectItem = EasyMock.createMock(SelectItem.class);
+ EasyMock.expect(selectItem.getProperty()).andStubReturn(
+ getEdmPropertyForSelect());
+ List<NavigationPropertySegment> navigationSegmentList = new ArrayList<NavigationPropertySegment>();
+ EasyMock.expect(selectItem.getNavigationPropertySegments())
+ .andStubReturn(navigationSegmentList);
+ EasyMock.replay(selectItem);
+ return selectItem;
+ }
+
+ private EdmProperty getEdmPropertyForSelect() {
+ EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
+ EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ Facets facets = new Facets().setNullable(false);
+ try {
+ EasyMock.expect(
+ edmType.valueToString(new Integer(2), EdmLiteralKind.URI,
+ facets)).andStubReturn("2");
+ EasyMock.expect(
+ edmType.valueToString(new Integer(2),
+ EdmLiteralKind.DEFAULT, facets)).andStubReturn("2");
+ } catch (EdmSimpleTypeException e1) {
+ fail("There is an exception in mocking EdmType object "
+ + e1.getMessage());
+ }
+ EasyMock.replay(edmType);
+ EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soId");
+ EasyMock.expect(edmMapping.getMimeType()).andReturn(null);
+ EasyMock.replay(edmMapping);
+ try {
+ EasyMock.expect(edmProperty.getName()).andStubReturn("ID");
+ EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
+ EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
+ EasyMock.expect(edmProperty.getFacets()).andStubReturn(facets);
+ EasyMock.expect(edmProperty.getCustomizableFeedMappings())
+ .andStubReturn(null);
+ EasyMock.expect(edmProperty.getMimeType()).andStubReturn(null);
+ EasyMock.replay(edmProperty);
+
+ } catch (EdmException e) {
+ fail("There is an exception in mocking some object "
+ + e.getMessage());
+ }
+
+ return edmProperty;
+
+ }
+
+ private EdmEntitySet getLocalTargetEntitySet() {
+ EdmEntitySet objEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+ try {
+ EasyMock.expect(objEdmEntitySet.getEntityType()).andStubReturn(
+ getLocalEdmEntityType());
+ EasyMock.expect(objEdmEntitySet.getName()).andStubReturn(
+ "SalesOderHeaders");
+ EasyMock.expect(objEdmEntitySet.getEntityContainer())
+ .andStubReturn(getLocalEdmEntityContainer());
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ EasyMock.replay(objEdmEntitySet);
+ return objEdmEntitySet;
+ }
+
+ private EdmEntityContainer getLocalEdmEntityContainer() {
+ EdmEntityContainer edmEntityContainer = EasyMock
+ .createMock(EdmEntityContainer.class);
+ EasyMock.expect(edmEntityContainer.isDefaultEntityContainer())
+ .andStubReturn(true);
+ try {
+ EasyMock.expect(edmEntityContainer.getName()).andStubReturn(
+ "salesorderprocessingContainer");
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ EasyMock.replay(edmEntityContainer);
+ return edmEntityContainer;
+ }
+
+ private EdmEntityType getLocalEdmEntityType() {
+ EdmEntityType objEdmEntityType = EasyMock
+ .createMock(EdmEntityType.class);
+ try {
+ EasyMock.expect(objEdmEntityType.getName()).andStubReturn(
+ "SalesOderHeaders");
+ EasyMock.expect(objEdmEntityType.getNamespace()).andStubReturn(
+ "SalesOderHeaders");
+ EasyMock.expect(objEdmEntityType.hasStream()).andStubReturn(false);
+ EasyMock.expect(objEdmEntityType.hasStream()).andStubReturn(false);
+ ArrayList<String> propertyNames = new ArrayList<String>();
+ propertyNames.add("ID");
+ EasyMock.expect(objEdmEntityType.getProperty("ID")).andStubReturn(
+ getEdmPropertyForSelect());
+ EasyMock.expect(objEdmEntityType.getPropertyNames()).andStubReturn(
+ propertyNames);
+ EasyMock.expect(objEdmEntityType.getNavigationPropertyNames())
+ .andStubReturn(new ArrayList<String>());
+ EasyMock.expect(objEdmEntityType.getKeyPropertyNames())
+ .andStubReturn(propertyNames);
+ EasyMock.expect(objEdmEntityType.getKeyProperties()).andStubReturn(
+ getKeyProperties());
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(objEdmEntityType);
+ return objEdmEntityType;
+ }
+
+ private List<EdmProperty> getKeyProperties() {
+ List<EdmProperty> edmProperties = new ArrayList<EdmProperty>();
+ EdmType edmType = EasyMock.createMock(EdmType.class);
+ EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.replay(edmType);
+ EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soId");
+ EasyMock.replay(edmMapping);
+ try {
+ EasyMock.expect(edmProperty.getName()).andStubReturn("ID");
+ EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
+ EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
+ EasyMock.replay(edmProperty);
+ } catch (EdmException e) {
+ fail("There is an exception is mocking some object "
+ + e.getMessage());
+ }
+
+ edmProperties.add(edmProperty);
+ return edmProperties;
+ }
+
+ private InlineCount getLocalInlineCount() {
+ return InlineCount.NONE;
+ }
+
+ class SalesOrderHeader {
+ private int soId;
+ private int Field1;
+
+ public SalesOrderHeader(final int soId, final int field) {
+ this.soId = soId;
+ Field1 = field;
+ }
+
+ public int getField1() {
+ return Field1;
+ }
+
+ public void setField1(final int field1) {
+ Field1 = field1;
+ }
+
+ public int getSoId() {
+ return soId;
+ }
+
+ public void setSoId(final int soId) {
+ this.soId = soId;
+ }
+
+ }
+
+ private List<Object> getJPAEntities() {
+ List<Object> listJPAEntities = new ArrayList<Object>();
+ SalesOrderHeader entity;
+ entity = new SalesOrderHeader(2, 10);
+ listJPAEntities.add(entity);
+ return listJPAEntities;
+ }
+
+ private Object getEntity() {
+ SalesOrderHeader sHeader = new SalesOrderHeader(10, 34);
+ return sHeader;
+ }
+
+ private GetEntityUriInfo mockEntityUriInfoForExpand() {
+
+ List<SelectItem> selectItemList = new ArrayList<SelectItem>();
+ List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
+ ArrayList<NavigationPropertySegment> navigationPropertyList = new ArrayList<NavigationPropertySegment>();
+ // Mocking the navigation property
+ EdmNavigationProperty navigationProperty = EasyMock
+ .createMock(EdmNavigationProperty.class);
+ try {
+ EasyMock.expect(navigationProperty.getName()).andStubReturn(
+ "SalesOrderItemDetails");
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(navigationProperty);
+ // Mocking the navigation property segments and adding to expand list
+ NavigationPropertySegment navigationPropertySegment = EasyMock
+ .createMock(NavigationPropertySegment.class);
+ EasyMock.expect(navigationPropertySegment.getNavigationProperty())
+ .andStubReturn(navigationProperty);
+ EasyMock.expect(navigationPropertySegment.getTargetEntitySet())
+ .andStubReturn(getTargetEntitySetForExpand());
+ EasyMock.replay(navigationPropertySegment);
+ navigationPropertyList.add(navigationPropertySegment);
+ expandList.add(navigationPropertyList);
+ // Mocking EntityUriInfo
+ GetEntityUriInfo entityUriInfo = EasyMock
+ .createMock(GetEntityUriInfo.class);
+ EasyMock.expect(entityUriInfo.getSelect())
+ .andStubReturn(selectItemList);
+ EasyMock.expect(entityUriInfo.getExpand()).andStubReturn(expandList);
+ EasyMock.replay(entityUriInfo);
+ return entityUriInfo;
+ }
+
+ private GetEntitySetUriInfo mockEntitySetUriInfoForExpand() {
+
+ List<SelectItem> selectItemList = new ArrayList<SelectItem>();
+ List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
+ ArrayList<NavigationPropertySegment> navigationPropertyList = new ArrayList<NavigationPropertySegment>();
+ // Mocking the navigation property
+ EdmNavigationProperty navigationProperty = EasyMock
+ .createMock(EdmNavigationProperty.class);
+ try {
+ EasyMock.expect(navigationProperty.getName()).andStubReturn(
+ "SalesOrderItemDetails");
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(navigationProperty);
+ // Mocking the navigation property segments and adding to expand list
+ NavigationPropertySegment navigationPropertySegment = EasyMock
+ .createMock(NavigationPropertySegment.class);
+ EasyMock.expect(navigationPropertySegment.getNavigationProperty())
+ .andStubReturn(navigationProperty);
+ EasyMock.expect(navigationPropertySegment.getTargetEntitySet())
+ .andStubReturn(getTargetEntitySetForExpand());
+ EasyMock.replay(navigationPropertySegment);
+ navigationPropertyList.add(navigationPropertySegment);
+ expandList.add(navigationPropertyList);
+ // Mocking EntityUriInfo
+ GetEntitySetUriInfo entitySetUriInfo = EasyMock
+ .createMock(GetEntitySetUriInfo.class);
+ EasyMock.expect(entitySetUriInfo.getSelect())
+ .andStubReturn(selectItemList);
+ EasyMock.expect(entitySetUriInfo.getExpand()).andStubReturn(expandList);
+ EasyMock.expect(entitySetUriInfo.getInlineCount()).andStubReturn(InlineCount.ALLPAGES);
+ EasyMock.expect(entitySetUriInfo.getSkip()).andStubReturn(new Integer(1));
+ EasyMock.expect(entitySetUriInfo.getTop()).andStubReturn(new Integer(2));
+ EasyMock.replay(entitySetUriInfo);
+ return entitySetUriInfo;
+ }
+
+ private EdmEntitySet getTargetEntitySetForExpand() {
+ EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
+ try {
+ EasyMock.expect(entitySet.getName()).andStubReturn(
+ "SalesOrderHeaders");
+ EasyMock.expect(entitySet.getEntityType()).andStubReturn(null);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(entitySet);
+ return entitySet;
+ }
+
+ private NavigationPropertySegment getNavigationPropertySegment(final String navPropertyName)
+ {
+ EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
+ try {
+ EasyMock.expect(navigationProperty.getName()).andStubReturn(navPropertyName);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(navigationProperty);
+ NavigationPropertySegment navPropertySegment = EasyMock.createMock(NavigationPropertySegment.class);
+ EasyMock.expect(navPropertySegment.getNavigationProperty()).andStubReturn(navigationProperty);
+ EasyMock.replay(navPropertySegment);
+ return navPropertySegment;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ff2b0a0e/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAExpandCallBackTest.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAExpandCallBackTest.java b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAExpandCallBackTest.java
new file mode 100644
index 0000000..232d75e
--- /dev/null
+++ b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAExpandCallBackTest.java
@@ -0,0 +1,179 @@
+/*******************************************************************************
+ * 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.data;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+
+import org.apache.olingo.odata2.api.ODataCallback;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackContext;
+import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackResult;
+import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackContext;
+import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackResult;
+import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
+import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
+import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
+
+public class JPAExpandCallBackTest {
+
+ @Test
+ public void testRetrieveEntryResult() {
+ JPAExpandCallBack callBack = getJPAExpandCallBackObject();
+ WriteEntryCallbackContext writeFeedContext = TestUtil.getWriteEntryCallBackContext();
+ try {
+ Field field = callBack.getClass().getDeclaredField("nextEntitySet");
+ field.setAccessible(true);
+ field.set(callBack, TestUtil.mockTargetEntitySet());
+ WriteEntryCallbackResult result = callBack.retrieveEntryResult(writeFeedContext);
+ assertEquals(1, result.getEntryData().size());
+ } 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);
+ }
+ }
+
+ @Test
+ public void testRetrieveFeedResult() {
+ JPAExpandCallBack callBack = getJPAExpandCallBackObject();
+ WriteFeedCallbackContext writeFeedContext = TestUtil.getWriteFeedCallBackContext();
+ try {
+ Field field = callBack.getClass().getDeclaredField("nextEntitySet");
+ field.setAccessible(true);
+ field.set(callBack, TestUtil.mockTargetEntitySet());
+ WriteFeedCallbackResult result = callBack.retrieveFeedResult(writeFeedContext);
+ assertEquals(2, result.getFeedData().size());
+ } 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);
+ }
+ }
+
+ @Test
+ public void testGetCallbacks() {
+ Map<String, ODataCallback> callBacks = null;
+ try {
+ URI baseUri = new URI("http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/SalesOrderProcessing.svc/");
+ ExpandSelectTreeNode expandSelectTreeNode = TestUtil.mockExpandSelectTreeNode();
+ List<ArrayList<NavigationPropertySegment>> expandList = TestUtil.getExpandList();
+ callBacks = JPAExpandCallBack.getCallbacks(baseUri, expandSelectTreeNode, expandList);
+ } catch (URISyntaxException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertEquals(1, callBacks.size());
+
+ }
+
+ @Test
+ public void testGetNextNavigationProperty()
+ {
+ JPAExpandCallBack callBack = getJPAExpandCallBackObject();
+ List<ArrayList<NavigationPropertySegment>> expandList = TestUtil.getExpandList();
+ ArrayList<NavigationPropertySegment> expands = expandList.get(0);
+ expands.add(TestUtil.mockThirdNavigationPropertySegment());
+ EdmNavigationProperty result = null;
+ try {
+ Field field = callBack.getClass().getDeclaredField("expandList");
+ field.setAccessible(true);
+ field.set(callBack, expandList);
+ Class<?>[] formalParams = { EdmEntityType.class, EdmNavigationProperty.class };
+ Object[] actualParams = { TestUtil.mockSourceEdmEntityType(), TestUtil.mockNavigationProperty() };
+ Method method = callBack.getClass().getDeclaredMethod("getNextNavigationProperty", formalParams);
+ method.setAccessible(true);
+ result = (EdmNavigationProperty) method.invoke(callBack, actualParams);
+ assertEquals("MaterialDetails", result.getName());
+
+ } 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);
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (InvocationTargetException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ private JPAExpandCallBack getJPAExpandCallBackObject()
+ {
+ Map<String, ODataCallback> callBacks = null;
+ try {
+ URI baseUri = new URI("http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/SalesOrderProcessing.svc/");
+ ExpandSelectTreeNode expandSelectTreeNode = TestUtil.mockExpandSelectTreeNode();
+ List<ArrayList<NavigationPropertySegment>> expandList = TestUtil.getExpandList();
+ callBacks = JPAExpandCallBack.getCallbacks(baseUri, expandSelectTreeNode, expandList);
+ } catch (URISyntaxException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return (JPAExpandCallBack) callBacks.get("SalesOrderLineItemDetails");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ff2b0a0e/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAFunctionContextTest.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAFunctionContextTest.java b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAFunctionContextTest.java
new file mode 100644
index 0000000..fd70433
--- /dev/null
+++ b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAFunctionContextTest.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * 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.data;
+
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.edm.EdmLiteral;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmParameter;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
+import org.apache.olingo.odata2.processor.api.jpa.access.JPAMethodContext;
+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.api.jpa.jpql.JPQLContextType;
+import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.processor.core.jpa.model.JPAEdmMappingImpl;
+
+public class JPAFunctionContextTest {
+
+ private int VARIANT = 0;
+
+ public JPAFunctionContext build() {
+ JPAFunctionContext functionContext = null;
+ try {
+ if (VARIANT == 0) {
+ functionContext = (JPAFunctionContext) JPAMethodContext
+ .createBuilder(JPQLContextType.FUNCTION, getView())
+ .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);
+ }
+
+ return functionContext;
+ }
+
+ @Test
+ public void testGetEnclosingObject() {
+
+ VARIANT = 0;
+
+ Assert.assertNotNull(build());
+
+ }
+
+ private GetFunctionImportUriInfo getView() {
+ GetFunctionImportUriInfo functiontView = EasyMock
+ .createMock(GetFunctionImportUriInfo.class);
+ EasyMock.expect(functiontView.getFunctionImport()).andStubReturn(
+ getEdmFunctionImport());
+ EasyMock.expect(functiontView.getFunctionImportParameters())
+ .andStubReturn(getFunctionImportParameters());
+
+ EasyMock.replay(functiontView);
+ return functiontView;
+ }
+
+ private Map<String, EdmLiteral> getFunctionImportParameters() {
+ return null;
+ }
+
+ private EdmFunctionImport getEdmFunctionImport() {
+ EdmFunctionImport edmFunctionImport = EasyMock
+ .createMock(EdmFunctionImport.class);
+ try {
+ EasyMock.expect(edmFunctionImport.getMapping()).andStubReturn(
+ getMapping());
+ EasyMock.expect(edmFunctionImport.getParameterNames())
+ .andStubReturn(getParameterNames());
+ EasyMock.expect(edmFunctionImport.getParameter("Gentleman"))
+ .andStubReturn(getParameter("Gentleman"));
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ EasyMock.replay(edmFunctionImport);
+ return edmFunctionImport;
+ }
+
+ private EdmParameter getParameter(final String string) {
+ EdmParameter edmParameter = EasyMock.createMock(EdmParameter.class);
+ try {
+ EasyMock.expect(edmParameter.getMapping()).andStubReturn(
+ getEdmMapping());
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(edmParameter);
+ return edmParameter;
+ }
+
+ private EdmMapping getEdmMapping() {
+ JPAEdmMappingImpl mapping = new JPAEdmMappingImpl();
+ mapping.setJPAType(String.class);
+ ((Mapping) mapping).setInternalName("Gentleman");
+ return mapping;
+ }
+
+ private JPAEdmMappingImpl getMapping() {
+ JPAEdmMappingImpl mapping = new JPAEdmMappingImpl();
+ mapping.setJPAType(FunctionImportTestClass.class);
+ ((Mapping) mapping).setInternalName("testMethod");
+ return mapping;
+ }
+
+ private Collection<String> getParameterNames() {
+ Collection<String> parametersList = new ArrayList<String>();
+ parametersList.add("Gentleman");
+ return parametersList;
+ }
+
+ public static class FunctionImportTestClass {
+
+ public FunctionImportTestClass() {
+
+ }
+
+ public String testMethod(final String message) {
+ return "Hello " + message + "!!";
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ff2b0a0e/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImplTest.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImplTest.java b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImplTest.java
new file mode 100644
index 0000000..169a13f
--- /dev/null
+++ b/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImplTest.java
@@ -0,0 +1,464 @@
+/*******************************************************************************
+ * 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.data;
+
+import static org.junit.Assert.fail;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Query;
+import javax.persistence.metamodel.Metamodel;
+
+import junit.framework.Assert;
+
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.olingo.odata2.api.commons.InlineCount;
+import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
+import org.apache.olingo.odata2.api.edm.EdmEntityContainer;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFacets;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTyped;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.PathInfo;
+import org.apache.olingo.odata2.api.uri.UriInfo;
+import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
+import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
+import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
+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.common.ODataJPATestConstants;
+
+public class JPAProcessorImplTest {
+
+ // -------------------------------- Common Start ------------------------------------common in ODataJPAProcessorDefaultTest as well
+ private static final String STR_LOCAL_URI = "http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/";
+ private static final String SALESORDERPROCESSING_CONTAINER = "salesorderprocessingContainer";
+ private static final String SO_ID = "SoId";
+ private static final String SALES_ORDER = "SalesOrder";
+ private static final String SALES_ORDER_HEADERS = "SalesOrderHeaders";
+ //-------------------------------- Common End ------------------------------------
+
+ JPAProcessorImpl objJPAProcessorImpl;
+
+ @Before
+ public void setUp() throws Exception {
+ objJPAProcessorImpl = new JPAProcessorImpl(getLocalmockODataJPAContext());
+ }
+
+ @Test
+ public void testProcessGetEntitySetCountUriInfo() {
+ try {
+ Assert.assertEquals(11, objJPAProcessorImpl.process(getEntitySetCountUriInfo()));
+ } 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 testProcessGetEntityCountUriInfo() {
+ try {
+ Assert.assertEquals(11, objJPAProcessorImpl.process(getEntityCountUriInfo()));
+ } 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 testProcessGetEntitySetUriInfo() {
+ try {
+ Assert.assertNotNull(objJPAProcessorImpl.process(getEntitySetUriInfo()));
+ } 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 testProcessDeleteUriInfo() {
+ try {
+ Assert.assertNotNull(objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml"));
+ Assert.assertEquals(new Address(), objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml"));
+ } 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 testProcessDeleteUriInfoNegative() {
+ try {
+ Assert.assertNotNull(objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml"));
+ Assert.assertNotSame(new Object(), objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml"));
+ } 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);
+ }
+ }
+
+ // ---------------------------- Common Code Start ---------------- TODO - common in ODataJPAProcessorDefaultTest as well
+
+ private DeleteUriInfo getDeletetUriInfo() {
+ UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
+ EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
+ EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
+ EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
+ EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
+ EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
+ EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
+ EasyMock.expect(objUriInfo.getKeyPredicates()).andStubReturn(getKeyPredicates());
+ EasyMock.replay(objUriInfo);
+ return objUriInfo;
+ }
+
+ private List<KeyPredicate> getKeyPredicates() {
+ List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
+ return keyPredicates;
+ }
+
+ private GetEntitySetCountUriInfo getEntitySetCountUriInfo() {
+ return getLocalUriInfo();
+ }
+
+ private GetEntityCountUriInfo getEntityCountUriInfo() {
+ return getLocalUriInfo();
+ }
+
+ private GetEntitySetUriInfo getEntitySetUriInfo() {
+
+ UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
+ EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
+ EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
+ EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
+ EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
+ EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
+ EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
+ //EasyMock.expect(objUriInfo.getFunctionImport()).andStubReturn(getFunctionImport());
+ EasyMock.expect(objUriInfo.getFunctionImport()).andStubReturn(null);
+ EasyMock.replay(objUriInfo);
+ return objUriInfo;
+ }
+
+ /**
+ * @return
+ */
+ private UriInfo getLocalUriInfo() {
+ UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
+ EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
+ EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
+ EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
+ EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
+ EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
+ EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
+ EasyMock.replay(objUriInfo);
+ return objUriInfo;
+ }
+
+ /**
+ * @return
+ * @throws EdmException
+ */
+ private EdmEntitySet getLocalEdmEntitySet() {
+ EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+ try {
+ EasyMock.expect(edmEntitySet.getName()).andStubReturn(SALES_ORDER_HEADERS);
+ EasyMock.expect(edmEntitySet.getEntityContainer()).andStubReturn(getLocalEdmEntityContainer());
+ EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(getLocalEdmEntityType());
+ EasyMock.replay(edmEntitySet);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return edmEntitySet;
+ }
+
+ /**
+ * @return
+ * @throws EdmException
+ */
+ private EdmEntityType getLocalEdmEntityType() {
+ EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
+ try {
+ EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>());
+ EasyMock.expect(edmEntityType.getPropertyNames()).andStubReturn(getLocalPropertyNames());
+ EasyMock.expect(edmEntityType.getProperty(SO_ID)).andStubReturn(getEdmTypedMockedObj(SALES_ORDER));
+ EasyMock.expect(edmEntityType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.expect(edmEntityType.getNamespace()).andStubReturn(SALES_ORDER_HEADERS);
+ EasyMock.expect(edmEntityType.getName()).andStubReturn(SALES_ORDER_HEADERS);
+ EasyMock.expect(edmEntityType.hasStream()).andStubReturn(false);
+ EasyMock.expect(edmEntityType.getNavigationPropertyNames()).andStubReturn(new ArrayList<String>());
+ EasyMock.expect(edmEntityType.getKeyPropertyNames()).andStubReturn(new ArrayList<String>());
+ EasyMock.expect(edmEntityType.getMapping()).andStubReturn(getEdmMappingMockedObj(SALES_ORDER));// ID vs Salesorder ID
+ EasyMock.replay(edmEntityType);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return edmEntityType;
+ }
+
+ private InlineCount getInlineCount() {
+ return InlineCount.NONE;
+ }
+
+ private FilterExpression getFilter() {
+ return null;
+ }
+
+ private Integer getSkip() {
+ return null;
+ }
+
+ private Integer getTop() {
+ return null;
+ }
+
+ private OrderByExpression getOrderByExpression() {
+ return null;
+ }
+
+ private ODataJPAContext getLocalmockODataJPAContext() {
+ ODataJPAContext odataJPAContext = EasyMock.createMock(ODataJPAContext.class);
+ EasyMock.expect(odataJPAContext.getPersistenceUnitName()).andStubReturn("salesorderprocessing");
+ EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andStubReturn(mockEntityManagerFactory());
+ EasyMock.expect(odataJPAContext.getODataContext()).andStubReturn(getLocalODataContext());
+ EasyMock.expect(odataJPAContext.getEntityManager()).andStubReturn(getLocalEntityManager());
+ EasyMock.replay(odataJPAContext);
+ return odataJPAContext;
+ }
+
+ private EntityManagerFactory mockEntityManagerFactory() {
+ EntityManagerFactory emf = EasyMock.createMock(EntityManagerFactory.class);
+ EasyMock.expect(emf.getMetamodel()).andStubReturn(mockMetaModel());
+ EasyMock.expect(emf.createEntityManager()).andStubReturn(getLocalEntityManager());
+ EasyMock.replay(emf);
+ return emf;
+ }
+
+ public EntityManager getLocalEntityManager() {
+ EntityManager em = EasyMock.createMock(EntityManager.class);
+ EasyMock.expect(em.createQuery("SELECT E1 FROM SalesOrderHeaders E1")).andStubReturn(getQuery());
+ EasyMock.expect(em.createQuery("SELECT COUNT ( E1 ) FROM SalesOrderHeaders E1")).andStubReturn(getQueryForSelectCount());
+ EasyMock.expect(em.getTransaction()).andStubReturn(getLocalTransaction()); //For Delete
+ em.flush();
+ em.flush();
+ Address obj = new Address();
+ em.remove(obj);// testing void method
+ em.remove(obj);// testing void method
+ EasyMock.replay(em);
+ return em;
+ }
+
+ private EntityTransaction getLocalTransaction() {
+ EntityTransaction entityTransaction = EasyMock.createMock(EntityTransaction.class);
+ entityTransaction.begin(); // testing void method
+ entityTransaction.begin(); // testing void method
+ entityTransaction.commit();// testing void method
+ entityTransaction.commit();// testing void method
+ EasyMock.replay(entityTransaction);
+ return entityTransaction;
+ }
+
+ private Query getQuery() {
+ Query query = EasyMock.createMock(Query.class);
+ EasyMock.expect(query.getResultList()).andStubReturn(getResultList());
+ EasyMock.replay(query);
+ return query;
+ }
+
+ private Query getQueryForSelectCount() {
+ Query query = EasyMock.createMock(Query.class);
+ EasyMock.expect(query.getResultList()).andStubReturn(getResultListForSelectCount());
+ EasyMock.replay(query);
+ return query;
+ }
+
+ private List<?> getResultList() {
+ List<Object> list = new ArrayList<Object>();
+ list.add(new Address());
+ return list;
+ }
+
+ private List<?> getResultListForSelectCount() {
+ List<Object> list = new ArrayList<Object>();
+ list.add(new Long(11));
+ return list;
+ }
+
+ private class Address {
+ private String soId = "12";
+
+ public String getSoId() {
+ return soId;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ boolean isEqual = false;
+ if (obj instanceof Address)
+ {
+ isEqual = getSoId().equalsIgnoreCase(((Address) obj).getSoId());//
+ }
+ return isEqual;
+ }
+ }
+
+ private Metamodel mockMetaModel() {
+ Metamodel metaModel = EasyMock.createMock(Metamodel.class);
+ EasyMock.replay(metaModel);
+ return metaModel;
+ }
+
+ private EdmEntityContainer getLocalEdmEntityContainer() {
+ EdmEntityContainer edmEntityContainer = EasyMock.createMock(EdmEntityContainer.class);
+ EasyMock.expect(edmEntityContainer.isDefaultEntityContainer()).andStubReturn(true);
+ try {
+ EasyMock.expect(edmEntityContainer.getName()).andStubReturn(SALESORDERPROCESSING_CONTAINER);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ EasyMock.replay(edmEntityContainer);
+ return edmEntityContainer;
+ }
+
+ private EdmTyped getEdmTypedMockedObj(final String propertyName) {
+ EdmProperty mockedEdmProperty = EasyMock.createMock(EdmProperty.class);
+ try {
+ EasyMock.expect(mockedEdmProperty.getMapping())
+ .andStubReturn(getEdmMappingMockedObj(propertyName));
+ EdmType edmType = EasyMock.createMock(EdmType.class);
+ EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.replay(edmType);
+ EasyMock.expect(mockedEdmProperty.getName()).andStubReturn("identifier");
+ EasyMock.expect(mockedEdmProperty.getType()).andStubReturn(edmType);
+ EasyMock.expect(mockedEdmProperty.getFacets()).andStubReturn(getEdmFacetsMockedObj());
+
+ EasyMock.replay(mockedEdmProperty);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return mockedEdmProperty;
+ }
+
+ private EdmFacets getEdmFacetsMockedObj() {
+ EdmFacets facets = EasyMock.createMock(EdmFacets.class);
+ EasyMock.expect(facets.getConcurrencyMode()).andStubReturn(EdmConcurrencyMode.Fixed);
+
+ EasyMock.replay(facets);
+ return facets;
+ }
+
+ private EdmMapping getEdmMappingMockedObj(final String propertyName) {
+ EdmMapping mockedEdmMapping = EasyMock.createMock(EdmMapping.class);
+ if (propertyName.equalsIgnoreCase(SALES_ORDER)) {
+ EasyMock.expect(mockedEdmMapping.getInternalName())
+ .andStubReturn(SALES_ORDER_HEADERS);
+ } else {
+ EasyMock.expect(mockedEdmMapping.getInternalName())
+ .andStubReturn(propertyName);
+ }
+ EasyMock.replay(mockedEdmMapping);
+ return mockedEdmMapping;
+ }
+
+ private List<String> getLocalPropertyNames() {
+ List<String> list = new ArrayList<String>();
+ list.add(SO_ID);
+ return list;
+ }
+
+ private ODataContext getLocalODataContext() {
+ ODataContext objODataContext = EasyMock.createMock(ODataContext.class);
+ try {
+ EasyMock.expect(objODataContext.getPathInfo()).andStubReturn(getLocalPathInfo());
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(objODataContext);
+ return objODataContext;
+ }
+
+ private PathInfo getLocalPathInfo() {
+ PathInfo pathInfo = EasyMock.createMock(PathInfo.class);
+ EasyMock.expect(pathInfo.getServiceRoot()).andStubReturn(getLocalURI());
+ EasyMock.replay(pathInfo);
+ return pathInfo;
+ }
+
+ private URI getLocalURI() {
+ URI uri = null;
+ try {
+ uri = new URI(STR_LOCAL_URI);
+ } catch (URISyntaxException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return uri;
+ }
+
+ //-------------------------------- Common End ------------------------------------
+
+}