You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2016/04/12 16:28:58 UTC
[2/3] olingo-odata2 git commit: [OLINGO-895] test case fixes for
virtual access changes
[OLINGO-895] test case fixes for virtual access changes
Signed-off-by: Christian Amend <ch...@sap.com>
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/599991e1
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/599991e1
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/599991e1
Branch: refs/heads/OLINGO-895
Commit: 599991e170d6a636eb7d5a39f279a75908616024
Parents: 32689c1
Author: Shankara G <sh...@sap.com>
Authored: Thu Feb 25 10:55:07 2016 +0530
Committer: Christian Amend <ch...@sap.com>
Committed: Tue Apr 12 16:10:07 2016 +0200
----------------------------------------------------------------------
.../processor/core/access/data/JPAEntity.java | 210 +++++++++++--------
.../core/access/data/JPAEntityParser.java | 6 +-
.../core/ODataJPAResponseBuilderTest.java | 4 +-
.../JPAEntityParserForStaticMethodTest.java | 72 ++++++-
.../core/access/data/JPAEntityParserTest.java | 29 ++-
.../processor/core/mock/data/EdmMockUtil.java | 4 +-
6 files changed, 218 insertions(+), 107 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/599991e1/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java
index e8bcbeb..793e151 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java
@@ -49,6 +49,7 @@ import org.apache.olingo.odata2.jpa.processor.api.OnJPAWriteContent;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
public class JPAEntity {
@@ -204,91 +205,19 @@ public class JPAEntity {
this.jpaEntity = jpaEntity;
}
- @SuppressWarnings("unchecked")
protected void setComplexProperty(Method accessModifier, final Object jpaEntity,
- final EdmStructuralType edmComplexType, final HashMap<String, Object> propertyValue, String propertyName)
+ final EdmStructuralType edmComplexType, final HashMap<String, Object> propertyValue)
throws EdmException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
InstantiationException, ODataJPARuntimeException, NoSuchMethodException, SecurityException, SQLException {
- JPAEdmMapping mapping = (JPAEdmMapping) edmComplexType.getMapping();
- Object embeddableObject = mapping.getJPAType().newInstance();
- accessModifier.invoke(jpaEntity, embeddableObject);
-
- HashMap<String, Method> accessModifiers =
- jpaEntityParser.getAccessModifiers(embeddableObject, edmComplexType, JPAEntityParser.ACCESS_MODIFIER_SET);
-
- for (String edmPropertyName : edmComplexType.getPropertyNames()) {
- EdmTyped edmTyped = (EdmTyped) edmComplexType.getProperty(edmPropertyName);
- accessModifier = accessModifiers.get(edmPropertyName);
- if (edmTyped.getType().getKind().toString().equals(EdmTypeKind.COMPLEX.toString())) {
- EdmStructuralType structualType = (EdmStructuralType) edmTyped.getType();
- setComplexProperty(accessModifier, embeddableObject, structualType, (HashMap<String, Object>) propertyValue
- .get(edmPropertyName),propertyName);
- } else {
- setProperty(accessModifier, embeddableObject, propertyValue.get(edmPropertyName), (EdmSimpleType) edmTyped
- .getType(),propertyName);
- }
- }
+ setComplexProperty(accessModifier, jpaEntity, edmComplexType, propertyValue, null);
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
protected void setProperty(final Method method, final Object entity, final Object entityPropertyValue,
- final EdmSimpleType type, String propertyName) throws
+ final EdmSimpleType type) throws
IllegalAccessException, IllegalArgumentException, InvocationTargetException, ODataJPARuntimeException {
- if (entityPropertyValue != null) {
- if(method.getParameterTypes().length>1) {
- method.invoke(entity, propertyName,entityPropertyValue);
- return;
- }
- Class<?> parameterType = method.getParameterTypes()[0];
- if (type != null && type.getDefaultType().equals(String.class)) {
- if (parameterType.equals(String.class)) {
- method.invoke(entity, entityPropertyValue);
- } else if (parameterType.equals(char[].class)) {
- char[] characters = ((String) entityPropertyValue).toCharArray();
- method.invoke(entity, characters);
- } else if (parameterType.equals(char.class)) {
- char c = ((String) entityPropertyValue).charAt(0);
- method.invoke(entity, c);
- } else if (parameterType.equals(Character[].class)) {
- Character[] characters = JPAEntityParser.toCharacterArray((String) entityPropertyValue);
- method.invoke(entity, (Object) characters);
- } else if (parameterType.equals(Character.class)) {
- Character c = Character.valueOf(((String) entityPropertyValue).charAt(0));
- method.invoke(entity, c);
- } else if (parameterType.isEnum()) {
- Enum e = Enum.valueOf((Class<Enum>) parameterType, (String) entityPropertyValue);
- method.invoke(entity, e);
- }
- } else if (parameterType.equals(Blob.class)) {
- if (onJPAWriteContent == null) {
- throw ODataJPARuntimeException
- .throwException(ODataJPARuntimeException.ERROR_JPA_BLOB_NULL, null);
- } else {
- method.invoke(entity, onJPAWriteContent.getJPABlob((byte[]) entityPropertyValue));
- }
- } else if (parameterType.equals(Clob.class)) {
- if (onJPAWriteContent == null) {
- throw ODataJPARuntimeException
- .throwException(ODataJPARuntimeException.ERROR_JPA_CLOB_NULL, null);
- } else {
- method.invoke(entity, onJPAWriteContent.getJPAClob(((String) entityPropertyValue).toCharArray()));
- }
- } else if (parameterType.equals(Timestamp.class)) {
- Timestamp ts = new Timestamp(((Calendar) entityPropertyValue).getTimeInMillis());
- method.invoke(entity, ts);
- } else if (parameterType.equals(java.util.Date.class)) {
- method.invoke(entity, ((Calendar) entityPropertyValue).getTime());
- } else if (parameterType.equals(java.sql.Date.class)) {
- long timeInMs = ((Calendar) entityPropertyValue).getTimeInMillis();
- method.invoke(entity, new java.sql.Date(timeInMs));
- } else if (parameterType.equals(java.sql.Time.class)) {
- long timeInMs = ((Calendar) entityPropertyValue).getTimeInMillis();
- method.invoke(entity, new java.sql.Time(timeInMs));
- } else {
- method.invoke(entity, entityPropertyValue);
- }
- }
+
+ setProperty(method, entity, entityPropertyValue, type, null);
}
protected void setEmbeddableKeyProperty(final HashMap<String, String> embeddableKeys,
@@ -412,9 +341,14 @@ public class JPAEntity {
propertyNames = oDataEntryProperties.keySet();
}
+ boolean isVirtual = false;
for (String propertyName : propertyNames) {
EdmTyped edmTyped = (EdmTyped) oDataEntityType.getProperty(propertyName);
-
+ if (edmTyped instanceof EdmProperty) {
+ isVirtual = ((JPAEdmMappingImpl)((EdmProperty) edmTyped).getMapping()).isVirtualAccess();
+ } else {
+ isVirtual = false;
+ }
Method accessModifier = null;
switch (edmTyped.getType().getKind()) {
@@ -425,16 +359,26 @@ public class JPAEntity {
}
}
accessModifier = accessModifiersWrite.get(propertyName);
- setProperty(accessModifier, jpaEntity, oDataEntryProperties.get(propertyName), (EdmSimpleType) edmTyped
- .getType(),propertyName);
-
+ if (isVirtual) {
+ setProperty(accessModifier, jpaEntity, oDataEntryProperties.get(propertyName), (EdmSimpleType) edmTyped
+ .getType(), propertyName);
+ } else {
+ setProperty(accessModifier, jpaEntity, oDataEntryProperties.get(propertyName), (EdmSimpleType) edmTyped
+ .getType());
+ }
break;
case COMPLEX:
structuralType = (EdmStructuralType) edmTyped.getType();
accessModifier = accessModifiersWrite.get(propertyName);
- setComplexProperty(accessModifier, jpaEntity,
- structuralType,
- (HashMap<String, Object>) oDataEntryProperties.get(propertyName),propertyName);
+ if (isVirtual) {
+ setComplexProperty(accessModifier, jpaEntity,
+ structuralType,
+ (HashMap<String, Object>) oDataEntryProperties.get(propertyName), propertyName);
+ } else {
+ setComplexProperty(accessModifier, jpaEntity,
+ structuralType,
+ (HashMap<String, Object>) oDataEntryProperties.get(propertyName));
+ }
break;
case NAVIGATION:
case ENTITY:
@@ -479,4 +423,102 @@ public class JPAEntity {
.addContent(e.getMessage()), e);
}
}
+
+ @SuppressWarnings("unchecked")
+ protected void setComplexProperty(Method accessModifier, final Object jpaEntity,
+ final EdmStructuralType edmComplexType, final HashMap<String, Object> propertyValue, String propertyName)
+ throws EdmException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
+ InstantiationException, ODataJPARuntimeException, NoSuchMethodException, SecurityException, SQLException {
+
+ JPAEdmMapping mapping = (JPAEdmMapping) edmComplexType.getMapping();
+ Object embeddableObject = mapping.getJPAType().newInstance();
+ accessModifier.invoke(jpaEntity, embeddableObject);
+
+ HashMap<String, Method> accessModifiers =
+ jpaEntityParser.getAccessModifiers(embeddableObject, edmComplexType,
+ JPAEntityParser.ACCESS_MODIFIER_SET);
+
+ for (String edmPropertyName : edmComplexType.getPropertyNames()) {
+ EdmTyped edmTyped = (EdmTyped) edmComplexType.getProperty(edmPropertyName);
+ accessModifier = accessModifiers.get(edmPropertyName);
+ if (edmTyped.getType().getKind().toString().equals(EdmTypeKind.COMPLEX.toString())) {
+ EdmStructuralType structualType = (EdmStructuralType) edmTyped.getType();
+ if (propertyName != null) {
+ setComplexProperty(accessModifier, embeddableObject, structualType,
+ (HashMap<String, Object>) propertyValue.get(edmPropertyName), propertyName);
+ } else {
+ setComplexProperty(accessModifier, embeddableObject, structualType,
+ (HashMap<String, Object>) propertyValue.get(edmPropertyName));
+ }
+ } else {
+ if (propertyName != null) {
+ setProperty(accessModifier, embeddableObject, propertyValue.get(edmPropertyName),
+ (EdmSimpleType) edmTyped.getType(), propertyName);
+ } else {
+ setProperty(accessModifier, embeddableObject, propertyValue.get(edmPropertyName),
+ (EdmSimpleType) edmTyped.getType());
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ protected void setProperty(final Method method, final Object entity, final Object entityPropertyValue,
+ final EdmSimpleType type, String propertyName) throws
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException, ODataJPARuntimeException {
+ if (entityPropertyValue != null) {
+ if (propertyName != null) {
+ method.invoke(entity, propertyName, entityPropertyValue);
+ return;
+ }
+ Class<?> parameterType = method.getParameterTypes()[0];
+ if (type != null && type.getDefaultType().equals(String.class)) {
+ if (parameterType.equals(String.class)) {
+ method.invoke(entity, entityPropertyValue);
+ } else if (parameterType.equals(char[].class)) {
+ char[] characters = ((String) entityPropertyValue).toCharArray();
+ method.invoke(entity, characters);
+ } else if (parameterType.equals(char.class)) {
+ char c = ((String) entityPropertyValue).charAt(0);
+ method.invoke(entity, c);
+ } else if (parameterType.equals(Character[].class)) {
+ Character[] characters = JPAEntityParser.toCharacterArray((String) entityPropertyValue);
+ method.invoke(entity, (Object) characters);
+ } else if (parameterType.equals(Character.class)) {
+ Character c = Character.valueOf(((String) entityPropertyValue).charAt(0));
+ method.invoke(entity, c);
+ } else if (parameterType.isEnum()) {
+ Enum e = Enum.valueOf((Class<Enum>) parameterType, (String) entityPropertyValue);
+ method.invoke(entity, e);
+ }
+ } else if (parameterType.equals(Blob.class)) {
+ if (onJPAWriteContent == null) {
+ throw ODataJPARuntimeException
+ .throwException(ODataJPARuntimeException.ERROR_JPA_BLOB_NULL, null);
+ } else {
+ method.invoke(entity, onJPAWriteContent.getJPABlob((byte[]) entityPropertyValue));
+ }
+ } else if (parameterType.equals(Clob.class)) {
+ if (onJPAWriteContent == null) {
+ throw ODataJPARuntimeException
+ .throwException(ODataJPARuntimeException.ERROR_JPA_CLOB_NULL, null);
+ } else {
+ method.invoke(entity, onJPAWriteContent.getJPAClob(((String) entityPropertyValue).toCharArray()));
+ }
+ } else if (parameterType.equals(Timestamp.class)) {
+ Timestamp ts = new Timestamp(((Calendar) entityPropertyValue).getTimeInMillis());
+ method.invoke(entity, ts);
+ } else if (parameterType.equals(java.util.Date.class)) {
+ method.invoke(entity, ((Calendar) entityPropertyValue).getTime());
+ } else if (parameterType.equals(java.sql.Date.class)) {
+ long timeInMs = ((Calendar) entityPropertyValue).getTimeInMillis();
+ method.invoke(entity, new java.sql.Date(timeInMs));
+ } else if (parameterType.equals(java.sql.Time.class)) {
+ long timeInMs = ((Calendar) entityPropertyValue).getTimeInMillis();
+ method.invoke(entity, new java.sql.Time(timeInMs));
+ } else {
+ method.invoke(entity, entityPropertyValue);
+ }
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/599991e1/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
index c8e3c8e..4c1d439 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
@@ -175,7 +175,7 @@ public final class JPAEntityParser {
navigationProperty.getMapping(), ACCESS_MODIFIER_GET);
Method getterMethod = null;
if(((JPAEdmMapping)navigationProperty.getMapping()).isVirtualAccess()) {
- getterMethod = jpaEntity.getClass().getMethod("get", String.class);
+ getterMethod = jpaEntity.getClass().getMethod(ACCESS_MODIFIER_GET, String.class);
}else{
getterMethod = jpaEntity.getClass()
.getMethod(methodName, (Class<?>[]) null);
@@ -556,7 +556,7 @@ public final class JPAEntityParser {
if (accessModifier.equals(ACCESS_MODIFIER_SET)) {
JPAEdmMapping jpaEdmMapping = (JPAEdmMapping) property.getMapping();
if(jpaEdmMapping.isVirtualAccess()) {
- accessModifierMap.put(propertyName, jpaEntityType.getMethod("set",
+ accessModifierMap.put(propertyName, jpaEntityType.getMethod(ACCESS_MODIFIER_SET,
new Class<?>[] { String.class,Object.class }));
}else {
accessModifierMap.put(propertyName, jpaEntityType.getMethod(methodName,
@@ -565,7 +565,7 @@ public final class JPAEntityParser {
} else {
JPAEdmMapping jpaEdmMapping = (JPAEdmMapping) property.getMapping();
if(jpaEdmMapping.isVirtualAccess()) {
- method = jpaEntityType.getMethod("get", String.class);
+ method = jpaEntityType.getMethod(ACCESS_MODIFIER_GET, String.class);
}else{
method = jpaEntityType.getMethod(methodName, (Class<?>[]) null);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/599991e1/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java
index 049b365..ebf268f 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java
@@ -62,6 +62,7 @@ import org.apache.olingo.odata2.jpa.processor.api.ODataJPAResponseBuilder;
import org.apache.olingo.odata2.jpa.processor.api.access.JPAPaging;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmTestModelView;
import org.easymock.EasyMock;
import org.junit.Before;
@@ -384,9 +385,10 @@ public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
}
EasyMock.replay(edmType);
EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ JPAEdmMappingImpl edmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soId");
EasyMock.expect(edmMapping.getMediaResourceMimeTypeKey()).andReturn(null);
+ EasyMock.expect(((JPAEdmMappingImpl) edmMapping).isVirtualAccess()).andStubReturn(false);
EasyMock.replay(edmMapping);
try {
EasyMock.expect(edmProperty.getName()).andStubReturn("ID");
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/599991e1/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserForStaticMethodTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserForStaticMethodTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserForStaticMethodTest.java
index 9a18f41..7a277fc 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserForStaticMethodTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserForStaticMethodTest.java
@@ -84,7 +84,7 @@ public class JPAEntityParserForStaticMethodTest {
public void testGetPropertyCharacter() {
try {
Method method = JPAEntityParserForStaticMethodTest.class.getMethod("getCharacter", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getPropertyValue(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this, "");
assertEquals("A", output);
} catch (NoSuchMethodException e) {
@@ -100,7 +100,7 @@ public class JPAEntityParserForStaticMethodTest {
public void testGetPropertyCharacterNull() {
try {
Method method = JPAEntityParserForStaticMethodTest.class.getMethod("getCharacterNull", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getPropertyValue(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this, "");
assertNull(output);
} catch (NoSuchMethodException e) {
@@ -116,7 +116,7 @@ public class JPAEntityParserForStaticMethodTest {
public void testGetPropertyCharacterArray() {
try {
Method method = JPAEntityParserForStaticMethodTest.class.getMethod("getCharacterArray", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getPropertyValue(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this, "");
assertEquals("AB", output);
} catch (NoSuchMethodException e) {
@@ -132,7 +132,7 @@ public class JPAEntityParserForStaticMethodTest {
public void testGetPropertyCharacterArrayNull() {
try {
Method method = JPAEntityParserForStaticMethodTest.class.getMethod("getCharacterArrayNull", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getPropertyValue(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this, "");
assertNull(output);
} catch (NoSuchMethodException e) {
@@ -148,7 +148,7 @@ public class JPAEntityParserForStaticMethodTest {
public void testGetPropertyChar() {
try {
Method method = JPAEntityParserForStaticMethodTest.class.getMethod("getChar", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getPropertyValue(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this, "");
assertEquals("A", output);
} catch (NoSuchMethodException e) {
@@ -164,7 +164,7 @@ public class JPAEntityParserForStaticMethodTest {
public void testGetPropertyCharNull() {
try {
Method method = JPAEntityParserForStaticMethodTest.class.getMethod("getCharNull", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getPropertyValue(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this, "");
assertNull(output);
} catch (NoSuchMethodException e) {
@@ -180,7 +180,7 @@ public class JPAEntityParserForStaticMethodTest {
public void testGetPropertyCharArray() {
try {
Method method = JPAEntityParserForStaticMethodTest.class.getMethod("getCharArray", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getPropertyValue(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this, "");
assertEquals("AB", output);
} catch (NoSuchMethodException e) {
@@ -196,7 +196,7 @@ public class JPAEntityParserForStaticMethodTest {
public void testGetPropertyCharArrayNull() {
try {
Method method = JPAEntityParserForStaticMethodTest.class.getMethod("getCharArrayNull", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getPropertyValue(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this, "");
assertNull(output);
} catch (NoSuchMethodException e) {
@@ -212,7 +212,7 @@ public class JPAEntityParserForStaticMethodTest {
public void testGetPropertyCharArrayValueNull() {
try {
Method method = JPAEntityParserForStaticMethodTest.class.getMethod("getCharArrayValueNull", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getPropertyValue(method, this);
+ String output = (String) JPAEntityParser.getPropertyValue(method, this, "");
assertEquals("A\u0000", output);
} catch (NoSuchMethodException e) {
@@ -225,6 +225,41 @@ public class JPAEntityParserForStaticMethodTest {
}
@Test
+ public void testGetPropertyObject() {
+
+ try {
+ Method method = JPAEntityParserForStaticMethodTest.class.getMethod("getObject", (Class<?>[]) null);
+ Object output = (Object) JPAEntityParser.getPropertyValue(method, this, "");
+ assertTrue(output != null);
+
+ } catch (NoSuchMethodException 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 (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+@Test
+ public void testGetPropertyObjectWithParameters() {
+
+ try {
+ Method method = JPAEntityParserForStaticMethodTest.class.
+ getMethod("getObjectWithParameters", getParameterTypeForMethod("getObjectWithParameters"));
+ Object output = (Object) JPAEntityParser.getPropertyValue(method, this, "obj1");
+ assertTrue(output != null);
+
+ } catch (NoSuchMethodException 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 (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+@Test
public void testGetString() {
char[] expectedChar = new char[] { 'a', 'b', 'c' };
try {
@@ -315,4 +350,23 @@ public class JPAEntityParserForStaticMethodTest {
public char[] getCharArrayValueNull() {
return new char[] { 'A', '\u0000' };
}
+
+ public Object getObject() {
+ return new Object();
+ }
+
+ public Object getObjectWithParameters(Object ob1) {
+ return new Object();
+ }
+
+ private Class<?>[] getParameterTypeForMethod(String methodName) {
+
+ Method[] methods = JPAEntityParserForStaticMethodTest.class.getMethods();
+ for (Method method: methods) {
+ if (method.getName().equals(methodName)) {
+ return method.getParameterTypes();
+ }
+ }
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/599991e1/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTest.java
index 01bf774..8035f2b 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTest.java
@@ -39,6 +39,7 @@ import org.apache.olingo.odata2.api.edm.EdmType;
import org.apache.olingo.odata2.api.edm.EdmTypeKind;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
import org.easymock.EasyMock;
import org.junit.Test;
@@ -66,14 +67,15 @@ public class JPAEntityParserTest {
EdmType edmType = EasyMock.createMock(EdmType.class);
EdmProperty edmTyped01 = EasyMock.createMock(EdmProperty.class);
EdmType edmType01 = EasyMock.createMock(EdmType.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EdmMapping edmMapping01 = EasyMock.createMock(EdmMapping.class);
+ EdmMapping edmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
+ EdmMapping edmMapping01 = EasyMock.createMock(JPAEdmMappingImpl.class);
try {
EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
EasyMock.expect(edmTyped.getName()).andStubReturn("identifier");
EasyMock.replay(edmType);
EasyMock.expect(edmMapping.getInternalName()).andStubReturn("id");
+ EasyMock.expect(((JPAEdmMappingImpl) edmMapping).isVirtualAccess()).andStubReturn(false);
EasyMock.replay(edmMapping);
EasyMock.expect(edmTyped.getType()).andStubReturn(edmType);
EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);
@@ -84,6 +86,7 @@ public class JPAEntityParserTest {
EasyMock.expect(edmTyped01.getName()).andStubReturn("Value");
EasyMock.replay(edmType01);
EasyMock.expect(edmMapping01.getInternalName()).andStubReturn("value");
+ EasyMock.expect(((JPAEdmMappingImpl) edmMapping01).isVirtualAccess()).andStubReturn(false);
EasyMock.replay(edmMapping01);
EasyMock.expect(edmTyped01.getType()).andStubReturn(edmType01);
EasyMock.expect(edmTyped01.getMapping()).andStubReturn(edmMapping01);
@@ -119,8 +122,8 @@ public class JPAEntityParserTest {
EdmType edmType = EasyMock.createMock(EdmType.class);
EdmProperty edmTyped01 = EasyMock.createMock(EdmProperty.class);
EdmType edmType01 = EasyMock.createMock(EdmType.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EdmMapping edmMapping01 = EasyMock.createMock(EdmMapping.class);
+ EdmMapping edmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
+ EdmMapping edmMapping01 = EasyMock.createMock(JPAEdmMappingImpl.class);
try {
EasyMock.expect(edmType.getKind())
@@ -128,6 +131,7 @@ public class JPAEntityParserTest {
EasyMock.expect(edmType.getName()).andReturn("identifier");
EasyMock.replay(edmType);
EasyMock.expect(edmMapping.getInternalName()).andStubReturn("id");
+ EasyMock.expect(((JPAEdmMappingImpl)edmMapping).isVirtualAccess()).andStubReturn(false);
EasyMock.replay(edmMapping);
EasyMock.expect(edmTyped.getType()).andStubThrow(
new EdmException(null));
@@ -143,6 +147,8 @@ public class JPAEntityParserTest {
EasyMock.replay(edmType01);
EasyMock.expect(edmMapping01.getInternalName()).andStubReturn(
"value");
+ EasyMock.expect(((JPAEdmMappingImpl)edmMapping01).isVirtualAccess())
+ .andStubReturn(false);
EasyMock.replay(edmMapping01);
EasyMock.expect(edmTyped01.getName()).andReturn("value").anyTimes();
EasyMock.expect(edmTyped01.getType()).andStubReturn(edmType01);
@@ -183,9 +189,10 @@ public class JPAEntityParserTest {
List<EdmNavigationProperty> navigationPropertyList = new ArrayList<EdmNavigationProperty>();
// Mocking a navigation property and its mapping object
EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ JPAEdmMappingImpl edmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
try {
EasyMock.expect(edmMapping.getInternalName()).andStubReturn("relatedEntity");
+ EasyMock.expect(((JPAEdmMappingImpl)edmMapping).isVirtualAccess()).andStubReturn(false);
EasyMock.replay(edmMapping);
EasyMock.expect(navigationProperty.getName()).andStubReturn("RelatedEntities");
EasyMock.expect(navigationProperty.getMapping()).andStubReturn(edmMapping);
@@ -220,13 +227,14 @@ public class JPAEntityParserTest {
EdmType edmType1 = EasyMock.createMock(EdmType.class);
EdmStructuralType edmType2 = EasyMock.createMock(EdmStructuralType.class);
EdmType edmComplexType = EasyMock.createMock(EdmType.class);
- EdmMapping mapping1 = EasyMock.createMock(EdmMapping.class);
- EdmMapping mapping2 = EasyMock.createMock(EdmMapping.class);
- EdmMapping complexMapping = EasyMock.createMock(EdmMapping.class);
+ JPAEdmMappingImpl mapping1 = EasyMock.createMock(JPAEdmMappingImpl.class);
+ JPAEdmMappingImpl mapping2 = EasyMock.createMock(JPAEdmMappingImpl.class);
+ JPAEdmMappingImpl complexMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
try {
EasyMock.expect(edmType1.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
EasyMock.replay(edmType1);
EasyMock.expect(mapping1.getInternalName()).andStubReturn("id");
+ EasyMock.expect(((JPAEdmMappingImpl) mapping1).isVirtualAccess()).andStubReturn(false);
EasyMock.replay(mapping1);
EasyMock.expect(edmProperty1.getName()).andStubReturn("Id");
EasyMock.expect(edmProperty1.getMapping()).andStubReturn(mapping1);
@@ -236,6 +244,7 @@ public class JPAEntityParserTest {
EasyMock.expect(edmComplexType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
EasyMock.replay(edmComplexType);
EasyMock.expect(complexMapping.getInternalName()).andStubReturn("order");
+ EasyMock.expect(((JPAEdmMappingImpl) complexMapping).isVirtualAccess()).andStubReturn(false);
EasyMock.replay(complexMapping);
EasyMock.expect(edmComplexProperty.getName()).andStubReturn("OrderName");
EasyMock.expect(edmComplexProperty.getMapping()).andStubReturn(complexMapping);
@@ -248,6 +257,7 @@ public class JPAEntityParserTest {
EasyMock.expect(edmType2.getPropertyNames()).andStubReturn(propertyNames);
EasyMock.replay(edmType2);
EasyMock.expect(mapping2.getInternalName()).andStubReturn("relatedEntity");
+ EasyMock.expect(((JPAEdmMappingImpl) mapping2).isVirtualAccess()).andStubReturn(false);
EasyMock.replay(mapping2);
EasyMock.expect(edmProperty2.getName()).andStubReturn("Order");
EasyMock.expect(edmProperty2.getMapping()).andStubReturn(mapping2);
@@ -528,8 +538,9 @@ public class JPAEntityParserTest {
private EdmProperty getEdmProperty() {
EdmProperty edmTyped = EasyMock.createMock(EdmProperty.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ JPAEdmMappingImpl edmMapping = EasyMock.createMock(JPAEdmMappingImpl.class);
EasyMock.expect(edmMapping.getInternalName()).andStubReturn("Field1");
+ EasyMock.expect(((JPAEdmMappingImpl) edmMapping).isVirtualAccess()).andStubReturn(false);
EasyMock.replay(edmMapping);
EdmType edmType = EasyMock.createMock(EdmType.class);
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/599991e1/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtil.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtil.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtil.java
index 7bd7bcf..b0e713e 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtil.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtil.java
@@ -42,6 +42,7 @@ import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackContext;
import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
import org.easymock.EasyMock;
public class EdmMockUtil {
@@ -320,8 +321,9 @@ public class EdmMockUtil {
EdmType type = EasyMock.createMock(EdmType.class);
EasyMock.expect(type.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
EasyMock.replay(type);
- EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
+ JPAEdmMappingImpl mapping = EasyMock.createMock(JPAEdmMappingImpl.class);
EasyMock.expect(mapping.getInternalName()).andStubReturn("price");
+ EasyMock.expect(((JPAEdmMappingImpl) mapping).isVirtualAccess()).andStubReturn(false);
EasyMock.replay(mapping);
try {
EasyMock.expect(edmProperty.getName()).andStubReturn("price");