Search in sources :

Example 56 with EntityMutationResponse

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

the class TestEntitiesREST method testCreateOrUpdateEntities.

@Test
public void testCreateOrUpdateEntities() throws Exception {
    AtlasEntitiesWithExtInfo entities = new AtlasEntitiesWithExtInfo();
    entities.addEntity(dbEntity);
    entities.addEntity(tableEntity);
    for (AtlasEntity column : columns) {
        entities.addReferredEntity(column);
    }
    EntityMutationResponse response = entityREST.createOrUpdate(entities);
    List<AtlasEntityHeader> guids = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE);
    Assert.assertNotNull(guids);
    Assert.assertEquals(guids.size(), 3);
    for (AtlasEntityHeader header : guids) {
        createdGuids.add(header.getGuid());
    }
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test)

Example 57 with EntityMutationResponse

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

the class TestEntityREST method testUpdateGetDeleteEntityByUniqueAttribute.

@Test
public void testUpdateGetDeleteEntityByUniqueAttribute() 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";
    dbEntity.setAttribute(TestUtilsV2.NAME, updatedDBName);
    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(), dbEntity.getAttributes());
    final EntityMutationResponse deleteResponse = entityREST.deleteByUniqueAttribute(TestUtilsV2.DATABASE_TYPE, toHttpServletRequest(TestUtilsV2.NAME, (String) dbEntity.getAttribute(TestUtilsV2.NAME)));
    Assert.assertNotNull(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE));
    Assert.assertEquals(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).size(), 1);
    Assert.assertEquals(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).get(0).getGuid(), dbGuid);
}
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)

Example 58 with EntityMutationResponse

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

the class NotificationHookConsumerTest method setup.

@BeforeMethod
public void setup() throws AtlasBaseException {
    MockitoAnnotations.initMocks(this);
    AtlasType mockType = mock(AtlasType.class);
    when(typeRegistry.getType(anyString())).thenReturn(mockType);
    AtlasEntity.AtlasEntitiesWithExtInfo mockEntity = mock(AtlasEntity.AtlasEntitiesWithExtInfo.class);
    when(instanceConverter.toAtlasEntities(anyList())).thenReturn(mockEntity);
    EntityMutationResponse mutationResponse = mock(EntityMutationResponse.class);
    when(atlasEntityStore.createOrUpdate(any(EntityStream.class), anyBoolean())).thenReturn(mutationResponse);
}
Also used : EntityStream(org.apache.atlas.repository.store.graph.v1.EntityStream) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasType(org.apache.atlas.type.AtlasType) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 59 with EntityMutationResponse

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

the class TestEntityREST method testDeleteEntityById.

@Test(dependsOnMethods = "testDeleteClassification")
public void testDeleteEntityById() throws Exception {
    EntityMutationResponse response = entityREST.deleteByGuid(dbEntity.getGuid());
    List<AtlasEntityHeader> entitiesMutated = response.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE);
    Assert.assertNotNull(entitiesMutated);
    Assert.assertEquals(entitiesMutated.get(0).getGuid(), dbEntity.getGuid());
}
Also used : EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test)

Example 60 with EntityMutationResponse

use of org.apache.atlas.model.instance.EntityMutationResponse 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

EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)60 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)44 Test (org.testng.annotations.Test)40 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)34 BeforeTest (org.testng.annotations.BeforeTest)22 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)21 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)17 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)17 ArrayList (java.util.ArrayList)16 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)13 HashMap (java.util.HashMap)12 List (java.util.List)8 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)7 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)7 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)7 ImmutableList (com.google.common.collect.ImmutableList)6 AtlasException (org.apache.atlas.AtlasException)6 TestUtils.randomString (org.apache.atlas.TestUtils.randomString)6 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)6 Map (java.util.Map)5