Repository: incubator-atlas Updated Branches: refs/heads/master 88ca02c62 -> 214c1572a
ATLAS-1603: fix to handle null value for object_id type attributes (#2 - fix unit test failure) Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/214c1572 Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/214c1572 Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/214c1572 Branch: refs/heads/master Commit: 214c1572adf71ec5565db29036d7ec3d0dd6354b Parents: 88ca02c Author: Madhan Neethiraj <[email protected]> Authored: Wed Mar 1 00:43:30 2017 -0800 Committer: Madhan Neethiraj <[email protected]> Committed: Wed Mar 1 02:37:58 2017 -0800 ---------------------------------------------------------------------- .../test/java/org/apache/atlas/TestUtilsV2.java | 6 ++++- .../store/graph/v1/AtlasEntityStoreV1Test.java | 25 ++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/214c1572/intg/src/test/java/org/apache/atlas/TestUtilsV2.java ---------------------------------------------------------------------- diff --git a/intg/src/test/java/org/apache/atlas/TestUtilsV2.java b/intg/src/test/java/org/apache/atlas/TestUtilsV2.java index 1fbf10e..0b28bcf 100755 --- a/intg/src/test/java/org/apache/atlas/TestUtilsV2.java +++ b/intg/src/test/java/org/apache/atlas/TestUtilsV2.java @@ -743,7 +743,11 @@ public final class TestUtilsV2 { new AtlasAttributeDef("databaseComposite", DATABASE_TYPE, true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, false, - Collections.<AtlasConstraintDef>emptyList())); + new ArrayList<AtlasStructDef.AtlasConstraintDef>() {{ + add(new AtlasStructDef.AtlasConstraintDef( + AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF)); + }} + )); AtlasClassificationDef piiTypeDefinition = AtlasTypeUtil.createTraitTypeDef(PII, PII + _description, ImmutableSet.<String>of()); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/214c1572/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java ---------------------------------------------------------------------- diff --git a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java index 47c9fc9..acb8075 100644 --- a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java +++ b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java @@ -75,7 +75,6 @@ import static org.apache.atlas.TestUtils.randomString; import static org.apache.atlas.TestUtilsV2.TABLE_TYPE; import static org.mockito.Mockito.mock; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; @Guice(modules = RepositoryMetadataModule.class) @@ -814,22 +813,30 @@ public class AtlasEntityStoreV1Test { @Test public void testSetObjectIdAttrToNull() throws Exception { - final AtlasEntity dbEntity = TestUtilsV2.createDBEntity(); - EntityMutationResponse dbCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false); - final AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity); + final AtlasEntity dbEntity = TestUtilsV2.createDBEntity(); + final AtlasEntity db2Entity = TestUtilsV2.createDBEntity(); + + entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false); + entityStore.createOrUpdate(new AtlasEntityStream(db2Entity), false); + + final AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity); + + tableEntity.setAttribute("databaseComposite", AtlasTypeUtil.getAtlasObjectId(db2Entity)); + final EntityMutationResponse tblCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(tableEntity), false); final AtlasEntityHeader createdTblHeader = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(TABLE_TYPE, NAME, (String) tableEntity.getAttribute(NAME)); final AtlasEntity createdTblEntity = getEntityFromStore(createdTblHeader); init(); - createdTblEntity.setAttribute("database", null); + createdTblEntity.setAttribute("databaseComposite", null); final EntityMutationResponse tblUpdateResponse = entityStore.createOrUpdate(new AtlasEntityStream(createdTblEntity), true); final AtlasEntityHeader updatedTblHeader = tblUpdateResponse.getFirstEntityPartialUpdated(); final AtlasEntity updatedTblEntity = getEntityFromStore(updatedTblHeader); + final AtlasEntity deletedDb2Entity = getEntityFromStore(db2Entity.getGuid()); - assertNull(updatedTblEntity.getAttribute("database")); + assertEquals(deletedDb2Entity.getStatus(), AtlasEntity.Status.DELETED); } private String randomStrWithReservedChars() { @@ -925,7 +932,11 @@ public class AtlasEntityStoreV1Test { } private AtlasEntity getEntityFromStore(AtlasEntityHeader header) throws AtlasBaseException { - AtlasEntityWithExtInfo entity = header != null ? entityStore.getById(header.getGuid()) : null; + return header != null ? getEntityFromStore(header.getGuid()) : null; + } + + private AtlasEntity getEntityFromStore(String guid) throws AtlasBaseException { + AtlasEntityWithExtInfo entity = guid != null ? entityStore.getById(guid) : null; return entity != null ? entity.getEntity() : null; }
