Repository: olingo-odata2
Updated Branches:
  refs/heads/master b0376ca3f -> ecd02e87b


[OLINGO-974] Additional unit tests for Dynamic Entity Support

Signed-off-by: Christian Amend <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/ecd02e87
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/ecd02e87
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/ecd02e87

Branch: refs/heads/master
Commit: ecd02e87b9dfe2d26e472934eca495a2c5c89bae
Parents: b0376ca
Author: Shankara G <[email protected]>
Authored: Wed Jun 22 09:19:05 2016 +0530
Committer: Christian Amend <[email protected]>
Committed: Thu Jan 26 11:54:53 2017 +0100

----------------------------------------------------------------------
 .../core/access/data/JPAEntityParserTest.java   | 113 +++++++++++++++++--
 1 file changed, 106 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ecd02e87/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 8035f2b..c0b3cf6 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
@@ -34,6 +34,7 @@ import org.apache.olingo.odata2.api.edm.EdmException;
 import org.apache.olingo.odata2.api.edm.EdmMapping;
 import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
 import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
 import org.apache.olingo.odata2.api.edm.EdmStructuralType;
 import org.apache.olingo.odata2.api.edm.EdmType;
 import org.apache.olingo.odata2.api.edm.EdmTypeKind;
@@ -177,7 +178,7 @@ public class JPAEntityParserTest {
     }
 
   }
-
+  
   @Test
   public void testparse2EdmPropertyListMap() {
     JPAEntityParser resultParser = new JPAEntityParser();
@@ -200,6 +201,39 @@ public class JPAEntityParserTest {
     } catch (EdmException e) {
       fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + 
ODataJPATestConstants.EXCEPTION_MSG_PART_2);
     }
+    
+    navigationPropertyList.add(navigationProperty);
+    try {
+      HashMap<String, Object> result = 
resultParser.parse2EdmNavigationValueMap(jpaEntity, navigationPropertyList);
+      assertEquals(relatedEntity, result.get("RelatedEntities"));
+      
+    } catch (ODataJPARuntimeException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + 
ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    }
+  }
+
+  @Test
+  public void testparse2EdmPropertyListMapWithVirtualAccess() {
+    JPAEntityParser resultParser = new JPAEntityParser();
+    Map<String, Object> edmEntity = new HashMap<String, Object>();
+    edmEntity.put("SoId", 1);
+    DemoRelatedEntity relatedEntity = new DemoRelatedEntity("NewOrder");
+    demoItem jpaEntity = new demoItem("laptop", 1);
+    jpaEntity.setRelatedEntity(relatedEntity);
+    List<EdmNavigationProperty> navigationPropertyList = new 
ArrayList<EdmNavigationProperty>();
+    // Mocking a navigation property and its mapping object
+    EdmNavigationProperty navigationProperty = 
EasyMock.createMock(EdmNavigationProperty.class);
+    JPAEdmMappingImpl edmMapping = 
EasyMock.createMock(JPAEdmMappingImpl.class);
+    try {
+      
EasyMock.expect(edmMapping.getInternalName()).andStubReturn("relatedEntity");
+      
EasyMock.expect(((JPAEdmMappingImpl)edmMapping).isVirtualAccess()).andStubReturn(true);
      
+      EasyMock.replay(edmMapping);
+      
EasyMock.expect(navigationProperty.getName()).andStubReturn("RelatedEntities");
+      
EasyMock.expect(navigationProperty.getMapping()).andStubReturn(edmMapping);
+      EasyMock.replay(navigationProperty);
+    } catch (EdmException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + 
ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    }
 
     navigationPropertyList.add(navigationProperty);
     try {
@@ -401,7 +435,7 @@ public class JPAEntityParserTest {
 
     }
   }
-
+  
   @Test
   public void testParse2EdmPropertyValueMap() {
     JPAEntityParser resultParser = new JPAEntityParser();
@@ -414,6 +448,17 @@ public class JPAEntityParserTest {
   }
 
   @Test
+  public void testParse2EdmPropertyValueMapWithVirtualAccess() {
+    JPAEntityParser resultParser = new JPAEntityParser();
+    Object jpaEntity = new DemoItem2("abc");
+    try {
+      resultParser.parse2EdmPropertyValueMap(jpaEntity, 
getEdmPropertyListWithVirtualAccess());
+    } catch (ODataJPARuntimeException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + 
ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    }
+  }
+
+  @Test
   public void testGetGetterEdmException() {
     JPAEntityParser resultParser = new JPAEntityParser();
     Object jpaEntity = new demoItem("abc", 10);
@@ -478,10 +523,21 @@ public class JPAEntityParserTest {
     public void setRelatedEntity(final DemoRelatedEntity relatedEntity) {
       this.relatedEntity = relatedEntity;
     }
-
+    
     public int getValue() {
       return value;
     }
+    
+    public void set(String property, Object value)
+        throws IllegalArgumentException, IllegalAccessException,
+        NoSuchFieldException, SecurityException {
+      this.getClass().getDeclaredField(property).set(this, value);
+    }
+
+    public Object get(String property) throws IllegalArgumentException,
+        IllegalAccessException, NoSuchFieldException, SecurityException {
+      return this.getClass().getDeclaredField(property).get(this);
+    }
 
     public void setValue(final int value) {
       this.value = value;
@@ -511,24 +567,40 @@ public class JPAEntityParserTest {
     }
 
   }
-
+  
   private List<EdmProperty> getEdmPropertyList() {
     List<EdmProperty> properties = new ArrayList<EdmProperty>();
     properties.add(getEdmProperty());
     return properties;
   }
 
+  private List<EdmProperty> getEdmPropertyListWithVirtualAccess() {
+    List<EdmProperty> properties = new ArrayList<EdmProperty>();
+    properties.add(getEdmPropertyWithVirtualAccess());
+    return properties;
+  }
+
   class DemoItem2 {
     private String field1;
-
+    
     public String getField1() {
       return field1;
     }
-
+    
     public void setField1(final String field) {
       field1 = field;
     }
 
+    //Getter for Dynamic Entity
+    public String get(String fieldName) {
+      return field1;
+    }
+
+    //Setter for Dynamic Entity
+    public void set(final String fieldName, Object fieldValue) {
+      field1 = (String) fieldValue;
+    }
+
     public DemoItem2(final String field) {
       field1 = field;
     }
@@ -561,4 +633,31 @@ public class JPAEntityParserTest {
     EasyMock.replay(edmTyped);
     return edmTyped;
   }
-}
+
+  private EdmProperty getEdmPropertyWithVirtualAccess() {
+    EdmProperty edmTyped = EasyMock.createMock(EdmProperty.class);
+  
+    JPAEdmMappingImpl edmMapping = 
EasyMock.createMock(JPAEdmMappingImpl.class);
+    EasyMock.expect(edmMapping.getInternalName()).andStubReturn("Field1");
+    EasyMock.expect(((JPAEdmMappingImpl) 
edmMapping).isVirtualAccess()).andStubReturn(true);
+    EasyMock.replay(edmMapping);
+  
+    EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
+  
+    try {
+      EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+      EasyMock.expect(edmType.getName()).andStubReturn("identifier");
+      EasyMock.expect(edmTyped.getName()).andStubReturn("SalesOrderHeader");
+      EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);
+  
+      EasyMock.expect(edmTyped.getType()).andStubReturn(edmType);
+      EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);
+  
+    } catch (EdmException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + 
ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    }
+    EasyMock.replay(edmType);
+    EasyMock.replay(edmTyped);
+    return edmTyped;
+  }
+}
\ No newline at end of file

Reply via email to