You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by tb...@apache.org on 2014/01/02 13:47:10 UTC
[23/47] [OLINGO-99] Re-factor Package Names. Following are the changes
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAFunctionContextTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAFunctionContextTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAFunctionContextTest.java
new file mode 100644
index 0000000..359ddfa
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAFunctionContextTest.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.jpa.processor.core.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.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.jpa.processor.api.access.JPAMethodContext;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAFunctionContext;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+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/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java
new file mode 100644
index 0000000..915a7d3
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java
@@ -0,0 +1,448 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.jpa.processor.core.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.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.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAProcessorImpl;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+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 ------------------------------------
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelServiceTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelServiceTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelServiceTest.java
new file mode 100644
index 0000000..073cd1f
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelServiceTest.java
@@ -0,0 +1,214 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.jpa.processor.core.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.jpa.processor.core.access.model.JPAEdmMappingModelService;
+import org.apache.olingo.odata2.jpa.processor.core.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/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilderTest.java
new file mode 100644
index 0000000..73af3e9
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilderTest.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.jpa.processor.core.access.model;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView;
+import org.apache.olingo.odata2.jpa.processor.core.ODataJPAContextImpl;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmMappingModelService;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmNameBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEntityTypeMock;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+public class JPAEdmNameBuilderTest {
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Test
+ public void testBuildJPAEdmPropertyView() {
+
+ SimpleProperty simpleProperty = new SimpleProperty();
+
+ // Mocking EDMProperty
+ JPAEdmPropertyView propertyView = EasyMock.createMock(JPAEdmPropertyView.class);
+ JPAEdmEntityTypeView entityTypeView = EasyMock.createMock(JPAEdmEntityTypeView.class);
+
+ EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JPAAttribute());
+ EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
+ EasyMock.expect(propertyView.getJPAEdmMappingModelAccess()).andStubReturn(null);
+ EasyMock.expect(propertyView.getEdmSimpleProperty()).andStubReturn(simpleProperty);
+ EasyMock.replay(propertyView);
+
+ JPAEdmNameBuilder.build(propertyView, false, false);
+ assertEquals("Id", simpleProperty.getName());
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Test
+ public void testBuildJPAEdmPropertyViewWithNoDefaultNaming() {
+
+ SimpleProperty simpleProperty = new SimpleProperty();
+
+ // Mocking EDMProperty
+ JPAEdmPropertyView propertyView = EasyMock.createMock(JPAEdmPropertyView.class);
+ JPAEdmEntityTypeView entityTypeView = EasyMock.createMock(JPAEdmEntityTypeView.class);
+
+ EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JPAAttribute());
+ EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
+ EasyMock.expect(propertyView.getJPAEdmMappingModelAccess()).andStubReturn(null);
+ EasyMock.expect(propertyView.getEdmSimpleProperty()).andStubReturn(simpleProperty);
+ EasyMock.replay(propertyView);
+
+ JPAEdmNameBuilder.build(propertyView, false, true);
+ assertEquals("id", simpleProperty.getName());
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Test
+ public void testBuildJPAEdmComplexPropertyView() {
+ 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 JPAEntityType());
+ EasyMock.replay(entityTypeView);
+ EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JPAAttribute());
+ EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
+ EasyMock.replay(complexPropertyView);
+ EasyMock.replay(propertyView);
+
+ JPAEdmNameBuilder.build(complexPropertyView, propertyView, false);
+ assertEquals("Id", complexPropertyView.getEdmComplexProperty().getName());
+
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Test
+ public void testBuildJPAEdmComplexPropertyViewWithNoDefaultNaming() {
+ 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 JPAEntityType());
+ EasyMock.replay(entityTypeView);
+ EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JPAAttribute());
+ EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
+ EasyMock.replay(complexPropertyView);
+ EasyMock.replay(propertyView);
+
+ JPAEdmNameBuilder.build(complexPropertyView, propertyView, true);
+ assertEquals("id", complexPropertyView.getEdmComplexProperty().getName());
+
+ }
+
+ @SuppressWarnings("hiding")
+ class JPAAttribute<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;
+ }
+
+ }
+
+ @SuppressWarnings("hiding")
+ class JPAEntityType<Object> extends JPAEntityTypeMock<Object> {
+
+ @Override
+ public java.lang.String getName() {
+ return "SalesOrderHeader";
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertorTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertorTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertorTest.java
new file mode 100644
index 0000000..cdcf3b1
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertorTest.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.jpa.processor.core.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.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPATypeConvertor;
+import org.apache.olingo.odata2.jpa.processor.core.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/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/common/ODataJPATestConstants.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/common/ODataJPATestConstants.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/common/ODataJPATestConstants.java
new file mode 100644
index 0000000..c25af73
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/common/ODataJPATestConstants.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.jpa.processor.core.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/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProviderNegativeTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProviderNegativeTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProviderNegativeTest.java
new file mode 100644
index 0000000..3e680f2
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProviderNegativeTest.java
@@ -0,0 +1,192 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.jpa.processor.core.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.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.edm.ODataJPAEdmProvider;
+import org.apache.olingo.odata2.jpa.processor.core.mock.ODataJPAContextMock;
+import org.apache.olingo.odata2.jpa.processor.core.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/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProviderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProviderTest.java
new file mode 100644
index 0000000..44d0448
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProviderTest.java
@@ -0,0 +1,386 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.jpa.processor.core.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.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.edm.ODataJPAEdmProvider;
+import org.apache.olingo.odata2.jpa.processor.core.mock.ODataJPAContextMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.EdmSchemaMock;
+import org.apache.olingo.odata2.jpa.processor.core.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);
+ }
+ }
+
+}