Commit 03684a05 by Madhan Neethiraj

ATLAS-1540: fix for unit test failures in TestEntityREST

parent 7ed6b02c
...@@ -94,7 +94,14 @@ public class RequestContext { ...@@ -94,7 +94,14 @@ public class RequestContext {
} }
public static void clear() { public static void clear() {
CURRENT_CONTEXT.get().entityCache.clear(); RequestContext instance = CURRENT_CONTEXT.get();
if (instance != null) {
if (instance.entityCache != null) {
instance.entityCache.clear();
}
}
CURRENT_CONTEXT.remove(); CURRENT_CONTEXT.remove();
} }
......
...@@ -58,16 +58,12 @@ public class TestEntityREST { ...@@ -58,16 +58,12 @@ public class TestEntityREST {
private AtlasEntity dbEntity; private AtlasEntity dbEntity;
private String dbGuid;
private AtlasClassification testClassification; private AtlasClassification testClassification;
@BeforeClass @BeforeClass
public void setUp() throws Exception { public void setUp() throws Exception {
AtlasTypesDef typesDef = TestUtilsV2.defineHiveTypes(); AtlasTypesDef typesDef = TestUtilsV2.defineHiveTypes();
typeStore.createTypesDef(typesDef); typeStore.createTypesDef(typesDef);
Map<String, AtlasEntity> dbEntityMap = TestUtilsV2.createDBEntity();
dbEntity = dbEntityMap.values().iterator().next();
} }
@AfterClass @AfterClass
...@@ -80,9 +76,12 @@ public class TestEntityREST { ...@@ -80,9 +76,12 @@ public class TestEntityREST {
RequestContext.clear(); RequestContext.clear();
} }
public void createOrUpdateEntity() throws Exception { private void createTestEntity() throws Exception {
Map<String, AtlasEntity> dbEntityMap = new HashMap<>(); Map<String, AtlasEntity> dbEntityMap = TestUtilsV2.createDBEntity();
AtlasEntity dbEntity = dbEntityMap.values().iterator().next();
dbEntityMap.put(dbEntity.getGuid(), dbEntity); dbEntityMap.put(dbEntity.getGuid(), dbEntity);
final EntityMutationResponse response = entitiesREST.createOrUpdate(dbEntityMap); final EntityMutationResponse response = entitiesREST.createOrUpdate(dbEntityMap);
Assert.assertNotNull(response); Assert.assertNotNull(response);
...@@ -91,37 +90,37 @@ public class TestEntityREST { ...@@ -91,37 +90,37 @@ public class TestEntityREST {
Assert.assertNotNull(entitiesMutated); Assert.assertNotNull(entitiesMutated);
Assert.assertEquals(entitiesMutated.size(), 1); Assert.assertEquals(entitiesMutated.size(), 1);
Assert.assertNotNull(entitiesMutated.get(0)); Assert.assertNotNull(entitiesMutated.get(0));
dbGuid = entitiesMutated.get(0).getGuid(); dbEntity.setGuid(entitiesMutated.get(0).getGuid());
Assert.assertEquals(entitiesMutated.size(), 1);
this.dbEntity = dbEntity;
} }
@Test @Test
public void testGetEntityById() throws Exception { public void testGetEntityById() throws Exception {
createOrUpdateEntity(); createTestEntity();
AtlasEntityWithExtInfo response = entityREST.getById(dbGuid); AtlasEntityWithExtInfo response = entityREST.getById(dbEntity.getGuid());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertNotNull(response.getEntity()); Assert.assertNotNull(response.getEntity());
TestEntitiesREST.verifyAttributes(response.getEntity().getAttributes(), dbEntity.getAttributes()); TestEntitiesREST.verifyAttributes(response.getEntity().getAttributes(), dbEntity.getAttributes());
} }
@Test @Test(dependsOnMethods = "testGetEntityById")
public void testAddAndGetClassification() throws Exception { public void testAddAndGetClassification() throws Exception {
createOrUpdateEntity();
List<AtlasClassification> classifications = new ArrayList<>(); List<AtlasClassification> classifications = new ArrayList<>();
testClassification = new AtlasClassification(TestUtilsV2.CLASSIFICATION, new HashMap<String, Object>() {{ put("tag", "tagName"); }}); testClassification = new AtlasClassification(TestUtilsV2.CLASSIFICATION, new HashMap<String, Object>() {{ put("tag", "tagName"); }});
classifications.add(testClassification); classifications.add(testClassification);
entityREST.addClassifications(dbGuid, classifications); entityREST.addClassifications(dbEntity.getGuid(), classifications);
final AtlasClassification.AtlasClassifications retrievedClassifications = entityREST.getClassifications(dbGuid); final AtlasClassification.AtlasClassifications retrievedClassifications = entityREST.getClassifications(dbEntity.getGuid());
Assert.assertNotNull(retrievedClassifications); Assert.assertNotNull(retrievedClassifications);
final List<AtlasClassification> retrievedClassificationsList = retrievedClassifications.getList(); final List<AtlasClassification> retrievedClassificationsList = retrievedClassifications.getList();
Assert.assertNotNull(retrievedClassificationsList); Assert.assertNotNull(retrievedClassificationsList);
Assert.assertEquals(classifications, retrievedClassificationsList); Assert.assertEquals(classifications, retrievedClassificationsList);
final AtlasClassification retrievedClassification = entityREST.getClassification(dbGuid, TestUtilsV2.CLASSIFICATION); final AtlasClassification retrievedClassification = entityREST.getClassification(dbEntity.getGuid(), TestUtilsV2.CLASSIFICATION);
Assert.assertNotNull(retrievedClassification); Assert.assertNotNull(retrievedClassification);
Assert.assertEquals(retrievedClassification, testClassification); Assert.assertEquals(retrievedClassification, testClassification);
...@@ -131,7 +130,7 @@ public class TestEntityREST { ...@@ -131,7 +130,7 @@ public class TestEntityREST {
@Test(dependsOnMethods = "testAddAndGetClassification") @Test(dependsOnMethods = "testAddAndGetClassification")
public void testGetEntityWithAssociations() throws Exception { public void testGetEntityWithAssociations() throws Exception {
AtlasEntityWithExtInfo entity = entityREST.getById(dbGuid); AtlasEntityWithExtInfo entity = entityREST.getById(dbEntity.getGuid());
final List<AtlasClassification> retrievedClassifications = entity.getEntity().getClassifications(); final List<AtlasClassification> retrievedClassifications = entity.getEntity().getClassifications();
Assert.assertNotNull(retrievedClassifications); Assert.assertNotNull(retrievedClassifications);
...@@ -141,8 +140,8 @@ public class TestEntityREST { ...@@ -141,8 +140,8 @@ public class TestEntityREST {
@Test(dependsOnMethods = "testGetEntityWithAssociations") @Test(dependsOnMethods = "testGetEntityWithAssociations")
public void testDeleteClassification() throws Exception { public void testDeleteClassification() throws Exception {
entityREST.deleteClassification(dbGuid, TestUtilsV2.CLASSIFICATION); entityREST.deleteClassification(dbEntity.getGuid(), TestUtilsV2.CLASSIFICATION);
final AtlasClassification.AtlasClassifications retrievedClassifications = entityREST.getClassifications(dbGuid); final AtlasClassification.AtlasClassifications retrievedClassifications = entityREST.getClassifications(dbEntity.getGuid());
Assert.assertNotNull(retrievedClassifications); Assert.assertNotNull(retrievedClassifications);
Assert.assertEquals(retrievedClassifications.getList().size(), 0); Assert.assertEquals(retrievedClassifications.getList().size(), 0);
...@@ -151,26 +150,28 @@ public class TestEntityREST { ...@@ -151,26 +150,28 @@ public class TestEntityREST {
@Test(dependsOnMethods = "testDeleteClassification") @Test(dependsOnMethods = "testDeleteClassification")
public void testDeleteEntityById() throws Exception { public void testDeleteEntityById() throws Exception {
EntityMutationResponse response = entityREST.deleteByGuid(dbGuid); EntityMutationResponse response = entityREST.deleteByGuid(dbEntity.getGuid());
List<AtlasEntityHeader> entitiesMutated = response.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE); List<AtlasEntityHeader> entitiesMutated = response.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE);
Assert.assertNotNull(entitiesMutated); Assert.assertNotNull(entitiesMutated);
Assert.assertEquals(entitiesMutated.get(0).getGuid(), dbGuid); Assert.assertEquals(entitiesMutated.get(0).getGuid(), dbEntity.getGuid());
} }
@Test @Test
public void testUpdateGetDeleteEntityByUniqueAttribute() throws Exception { public void testUpdateGetDeleteEntityByUniqueAttribute() throws Exception {
Map<String, AtlasEntity> dbEntityMap = TestUtilsV2.createDBEntity(); Map<String, AtlasEntity> dbEntityMap = TestUtilsV2.createDBEntity();
entitiesREST.createOrUpdate(dbEntityMap); AtlasEntity dbEntity = dbEntityMap.values().iterator().next();
EntityMutationResponse response = entitiesREST.createOrUpdate(dbEntityMap);
String dbGuid = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0).getGuid();
Assert.assertTrue(AtlasEntity.isAssigned(dbGuid));
final String prevDBName = (String) dbEntity.getAttribute(TestUtilsV2.NAME); final String prevDBName = (String) dbEntity.getAttribute(TestUtilsV2.NAME);
final String updatedDBName = "updatedDBName"; final String updatedDBName = prevDBName + ":updated";
dbEntity.setAttribute(TestUtilsV2.NAME, updatedDBName); dbEntity.setAttribute(TestUtilsV2.NAME, updatedDBName);
final EntityMutationResponse response = entityREST.partialUpdateByUniqueAttribute(TestUtilsV2.DATABASE_TYPE, TestUtilsV2.NAME, prevDBName, dbEntity); response = entityREST.partialUpdateByUniqueAttribute(TestUtilsV2.DATABASE_TYPE, TestUtilsV2.NAME, prevDBName, dbEntity);
String dbGuid = response.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).get(0).getGuid(); Assert.assertEquals(response.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).get(0).getGuid(), dbGuid);
Assert.assertTrue(AtlasEntity.isAssigned(dbGuid));
//Get By unique attribute //Get By unique attribute
List<AtlasEntity> entities = entityREST.getByUniqueAttribute(TestUtilsV2.DATABASE_TYPE, TestUtilsV2.NAME, updatedDBName); List<AtlasEntity> entities = entityREST.getByUniqueAttribute(TestUtilsV2.DATABASE_TYPE, TestUtilsV2.NAME, updatedDBName);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment