Search in sources :

Example 81 with AtlasEntity

use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.

the class EntityV2JerseyResourceIT method testEntityDeduping.

@Test
public void testEntityDeduping() throws Exception {
    JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
    assertEquals(results.length(), 1);
    final AtlasEntity hiveDBInstanceV2 = createHiveDB();
    // Do the notification thing here
    waitForNotification(notificationConsumer, MAX_WAIT_TIME, new NotificationPredicate() {

        @Override
        public boolean evaluate(EntityNotification notification) throws Exception {
            return notification != null && notification.getEntity().getId()._getId().equals(hiveDBInstanceV2.getGuid());
        }
    });
    results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
    assertEquals(results.length(), 1);
    //Test the same across references
    final String tableName = randomString();
    AtlasEntity hiveTableInstanceV2 = createHiveTableInstanceV2(hiveDBInstanceV2, tableName);
    hiveTableInstanceV2.setAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
    EntityMutationResponse entity = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(hiveTableInstanceV2));
    assertNotNull(entity);
    assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
    results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
    assertEquals(results.length(), 1);
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityNotification(org.apache.atlas.notification.entity.EntityNotification) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) JSONArray(org.codehaus.jettison.json.JSONArray) AtlasServiceException(org.apache.atlas.AtlasServiceException) Test(org.testng.annotations.Test)

Example 82 with AtlasEntity

use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.

the class EntityV2JerseyResourceIT method testEntityInvalidValue.

@Test
public void testEntityInvalidValue() throws Exception {
    AtlasEntity databaseInstance = new AtlasEntity(DATABASE_TYPE_V2);
    String dbName = randomString();
    String nullString = null;
    String emptyString = "";
    databaseInstance.setAttribute("name", dbName);
    databaseInstance.setAttribute("description", nullString);
    AtlasEntityHeader created = createEntity(databaseInstance);
    // null valid value for required attr - description
    assertNull(created);
    databaseInstance.setAttribute("description", emptyString);
    created = createEntity(databaseInstance);
    // empty string valid value for required attr
    assertNotNull(created);
    databaseInstance.setGuid(created.getGuid());
    databaseInstance.setAttribute("owner", nullString);
    databaseInstance.setAttribute("locationUri", emptyString);
    created = updateEntity(databaseInstance);
    // null/empty string valid value for optional attr
    assertNotNull(created);
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test)

Example 83 with AtlasEntity

use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.

the class EntityV2JerseyResourceIT method addProperty.

private void addProperty(String guid, String property, Object value) throws AtlasServiceException {
    AtlasEntity entityByGuid = getEntityByGuid(guid);
    entityByGuid.setAttribute(property, value);
    EntityMutationResponse response = atlasClientV2.updateEntity(new AtlasEntityWithExtInfo(entityByGuid));
    assertNotNull(response);
    assertNotNull(response.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse)

Example 84 with AtlasEntity

use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.

the class EntityV2JerseyResourceIT method testGetEntityByAttribute.

@Test
public void testGetEntityByAttribute() throws Exception {
    AtlasEntity hiveDB = createHiveDB();
    String qualifiedName = (String) hiveDB.getAttribute(NAME);
    //get entity by attribute
    AtlasEntity byAttribute = atlasClientV2.getEntityByAttribute(DATABASE_TYPE_V2, toMap(NAME, qualifiedName)).getEntity();
    assertEquals(byAttribute.getTypeName(), DATABASE_TYPE_V2);
    assertEquals(byAttribute.getAttribute(NAME), qualifiedName);
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) Test(org.testng.annotations.Test)

Example 85 with AtlasEntity

use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.

the class EntityV2JerseyResourceIT method testDeleteEntityByUniqAttribute.

@Test
public void testDeleteEntityByUniqAttribute() throws Exception {
    // Create database entity
    AtlasEntity hiveDB = createHiveDB(DATABASE_NAME + random());
    // Delete the database entity
    EntityMutationResponse deleteResponse = atlasClientV2.deleteEntityByAttribute(DATABASE_TYPE_V2, toMap(NAME, (String) hiveDB.getAttribute(NAME)));
    // Verify that deleteEntities() response has database entity guids
    assertNotNull(deleteResponse);
    assertNotNull(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE));
    assertEquals(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).size(), 1);
// Verify entities were deleted from the repository.
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) Test(org.testng.annotations.Test)

Aggregations

AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)124 Test (org.testng.annotations.Test)58 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)43 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)36 HashMap (java.util.HashMap)25 BeforeTest (org.testng.annotations.BeforeTest)25 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)24 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)24 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)21 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)17 ArrayList (java.util.ArrayList)16 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)14 Map (java.util.Map)12 List (java.util.List)11 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)11 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)9 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)9 TestUtils.randomString (org.apache.atlas.TestUtils.randomString)7 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)7 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)7