Search in sources :

Example 26 with AtlasEntitiesWithExtInfo

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

the class TestEntityREST method testPartialUpdateByUniqueAttribute.

@Test
public void testPartialUpdateByUniqueAttribute() throws Exception {
    AtlasEntity dbEntity = TestUtilsV2.createDBEntity();
    EntityMutationResponse response = entityREST.createOrUpdate(new AtlasEntitiesWithExtInfo(dbEntity));
    String dbGuid = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0).getGuid();
    Assert.assertTrue(AtlasTypeUtil.isAssignedGuid(dbGuid));
    final String prevDBName = (String) dbEntity.getAttribute(TestUtilsV2.NAME);
    final String updatedDBName = prevDBName + ":updated";
    Map<String, Object> dbAttrs = dbEntity.getAttributes();
    // partial update only db name
    dbEntity = new AtlasEntity(TestUtilsV2.DATABASE_TYPE);
    dbEntity.setGuid(dbGuid);
    dbEntity.setAttribute(TestUtilsV2.NAME, updatedDBName);
    dbAttrs.putAll(dbEntity.getAttributes());
    response = entityREST.partialUpdateEntityByUniqueAttrs(TestUtilsV2.DATABASE_TYPE, toHttpServletRequest(TestUtilsV2.NAME, prevDBName), new AtlasEntityWithExtInfo(dbEntity));
    Assert.assertEquals(response.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE).get(0).getGuid(), dbGuid);
    //Get By unique attribute
    AtlasEntityWithExtInfo entity = entityREST.getByUniqueAttributes(TestUtilsV2.DATABASE_TYPE, toHttpServletRequest(TestUtilsV2.NAME, updatedDBName));
    Assert.assertNotNull(entity);
    Assert.assertNotNull(entity.getEntity().getGuid());
    Assert.assertEquals(entity.getEntity().getGuid(), dbGuid);
    TestEntitiesREST.verifyAttributes(entity.getEntity().getAttributes(), dbAttrs);
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) Test(org.testng.annotations.Test)

Aggregations

AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)26 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)21 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)21 Test (org.testng.annotations.Test)17 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)15 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)8 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)7 BeforeTest (org.testng.annotations.BeforeTest)7 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)6 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 AtlasException (org.apache.atlas.AtlasException)4 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)4 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)4 JSONObject (org.codehaus.jettison.json.JSONObject)4 Map (java.util.Map)3 EntityExistsException (org.apache.atlas.typesystem.exception.EntityExistsException)3 ValueConversionException (org.apache.atlas.typesystem.types.ValueConversionException)3 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)3