mneethiraj commented on a change in pull request #29: ATLAS-2933:Empty array 
attributes are returned as null instead of an empty list
URL: https://github.com/apache/atlas/pull/29#discussion_r265381766
 
 

 ##########
 File path: 
repository/src/test/java/org/apache/atlas/repository/store/graph/v2/AtlasComplexAttributesTest.java
 ##########
 @@ -195,6 +202,39 @@ private void updateEntityMapAttributes(AtlasEntity 
attrEntity, Map<String, Strin
         attrEntity.setAttribute("mapAttr5", map5);
     }
 
+    @Test
+    public void testEmptyArrayAttribute() throws Exception {
+        init();
+        AtlasEntity nestedEntity = nestedCollectionAttrEntity.getEntity();
+
+        // set the attribute - arrayOfArrayOfStrings of the nestedEntity to
+        // an empty list. Expected behavior is that retrieved entity will
+        // have the value of this field as an empty list instead of null.
+        nestedEntity.setAttribute("arrayOfArrayOfStrings", 
Collections.emptyList());
+        AtlasEntitiesWithExtInfo nestedEntitiesInfo = new 
AtlasEntitiesWithExtInfo(nestedEntity);
+
+        EntityMutationResponse response       = entityStore.createOrUpdate(new 
AtlasEntityStream(nestedEntitiesInfo), false);
+        AtlasEntityHeader updatedNestedEntity = 
response.getFirstCreatedEntityByTypeName(ENTITY_TYPE_WITH_NESTED_COLLECTION_ATTR);
+        validateEntity(nestedEntitiesInfo, 
getEntityFromStore(updatedNestedEntity));
+    }
+
+    @Test(dependsOnMethods = "testCreateComplexAttributeEntity")
+    public void testNullArrayAttribute() throws Exception {
+        init();
+
+        // set the attribute - listOfStructs of the complexEntity to null.
+        // Expected behavior is that the retrieved entity will
+        // not have the attribute of listOfStructs.
+        AtlasEntity complexEntity = 
getEntityFromStore(complexCollectionAttrEntity.getEntity().getGuid());
+        assertTrue(complexEntity.getAttributes().containsKey("listOfStructs"));
+
+        complexEntity.setAttribute("listOfStructs", null);
+        AtlasEntitiesWithExtInfo complexEntityInfo = new 
AtlasEntitiesWithExtInfo(complexEntity);
+        EntityMutationResponse responseUpdated     = 
entityStore.createOrUpdate(new AtlasEntityStream(complexEntityInfo), false);
+        AtlasEntityHeader updatedComplexEntity     = 
responseUpdated.getFirstUpdatedEntityByTypeName(ENTITY_TYPE_WITH_COMPLEX_COLLECTION_ATTR);
 
 Review comment:
   updatedComplexEntity is a AtlasEntityHeader - which will not have all 
attributes of an entity, hence the asset at line #235 passes. Please get an 
entire entity and use that in assert:
   
   ```
     AtlasEntityHeader      updatedEntityHeader  = 
responseUpdated.getFirstUpdatedEntityByTypeName(ENTITY_TYPE_WITH_COMPLEX_COLLECTION_ATTR);
     AtlasEntity            updatedComplexEntity = 
getEntityFromStore(updatedEntityHeader);
     Object                 updatedAttrValue     = 
updatedComplexEntity.getAttribute("listOfStructs");
   
     assertNull(updatedAttrValue, "listOfStructs");
   
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to