Search in sources :

Example 21 with IReferenceableInstance

use of org.apache.atlas.typesystem.IReferenceableInstance in project incubator-atlas by apache.

the class DefaultMetadataServiceTest method testDeleteEntityByUniqueAttribute.

@Test
public void testDeleteEntityByUniqueAttribute() throws Exception {
    // Create a table entity, with 3 composite column entities
    Referenceable dbEntity = createDBEntity();
    String dbGuid = TestUtils.createInstance(metadataService, dbEntity);
    Referenceable table1Entity = createTableEntity(dbGuid);
    Referenceable col1 = createColumnEntity();
    Referenceable col2 = createColumnEntity();
    Referenceable col3 = createColumnEntity();
    table1Entity.set(COLUMNS_ATTR_NAME, ImmutableList.of(col1, col2, col3));
    TestUtils.createInstance(metadataService, table1Entity);
    // to get their guids and the composite column guids.
    String entityJson = metadataService.getEntityDefinition(TestUtils.TABLE_TYPE, NAME, (String) table1Entity.get(NAME));
    Assert.assertNotNull(entityJson);
    table1Entity = InstanceSerialization.fromJsonReferenceable(entityJson, true);
    List<IReferenceableInstance> table1Columns = (List<IReferenceableInstance>) table1Entity.get(COLUMNS_ATTR_NAME);
    // Register an EntityChangeListener to verify the notification mechanism
    // is working for deleteEntityByUniqueAttribute().
    EntitiesChangeListener listener = new EntitiesChangeListener();
    metadataService.registerListener(listener);
    // Delete the table entities.  The deletion should cascade
    // to their composite columns.
    List<String> deletedGuids = metadataService.deleteEntityByUniqueAttribute(TestUtils.TABLE_TYPE, NAME, (String) table1Entity.get(NAME)).getDeletedEntities();
    // Verify that deleteEntities() response has guids for tables and their composite columns.
    Assert.assertTrue(deletedGuids.contains(table1Entity.getId()._getId()));
    for (IReferenceableInstance column : table1Columns) {
        Assert.assertTrue(deletedGuids.contains(column.getId()._getId()));
    }
    // Verify that tables and their composite columns have been deleted from the repository.
    // Verify that tables and their composite columns have been deleted from the repository.
    assertEntityDeleted(TABLE_TYPE, NAME, table1Entity.get(NAME));
    assertEntityDeleted(COLUMN_TYPE, NAME, col1.get(NAME));
    assertEntityDeleted(COLUMN_TYPE, NAME, col2.get(NAME));
    assertEntityDeleted(COLUMN_TYPE, NAME, col3.get(NAME));
    // Verify that the listener was notified about the deleted entities.
    List<String> deletedEntitiesFromListener = listener.getDeletedEntities();
    Assert.assertNotNull(deletedEntitiesFromListener);
    assertEquals(deletedEntitiesFromListener.size(), deletedGuids.size());
    Assert.assertTrue(deletedEntitiesFromListener.containsAll(deletedGuids));
}
Also used : IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) Referenceable(org.apache.atlas.typesystem.Referenceable) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)21 ArrayList (java.util.ArrayList)11 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)9 List (java.util.List)7 Id (org.apache.atlas.typesystem.persistence.Id)7 Test (org.testng.annotations.Test)7 ImmutableList (com.google.common.collect.ImmutableList)5 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)5 BeforeTest (org.testng.annotations.BeforeTest)5 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)4 Referenceable (org.apache.atlas.typesystem.Referenceable)4 HashMap (java.util.HashMap)3 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)3 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 AtlasException (org.apache.atlas.AtlasException)2 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)2 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)2 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)2