Search in sources :

Example 26 with AtlasEntity

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

the class EntityV2JerseyResourceIT method testUTF8.

@Test
public void testUTF8() throws Exception {
    String classType = randomString();
    String attrName = random();
    String attrValue = random();
    AtlasEntityDef classTypeDef = AtlasTypeUtil.createClassTypeDef(classType, ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef(attrName, "string"));
    AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
    atlasTypesDef.getEntityDefs().add(classTypeDef);
    createType(atlasTypesDef);
    AtlasEntity instance = new AtlasEntity(classType);
    instance.setAttribute(attrName, attrValue);
    AtlasEntityHeader entity = createEntity(instance);
    assertNotNull(entity);
    assertNotNull(entity.getGuid());
    AtlasEntity entityByGuid = getEntityByGuid(entity.getGuid());
    assertEquals(entityByGuid.getAttribute(attrName), attrValue);
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 27 with AtlasEntity

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

the class EntityV2JerseyResourceIT method testDeleteEntities.

@Test
public void testDeleteEntities() throws Exception {
    // Create 2 database entities
    AtlasEntity db1 = new AtlasEntity(DATABASE_TYPE_V2);
    String dbName1 = randomString();
    db1.setAttribute("name", dbName1);
    db1.setAttribute(NAME, dbName1);
    db1.setAttribute("clusterName", randomString());
    db1.setAttribute("description", randomString());
    AtlasEntityHeader entity1Header = createEntity(db1);
    AtlasEntity db2 = new AtlasEntity(DATABASE_TYPE_V2);
    String dbName2 = randomString();
    db2.setAttribute("name", dbName2);
    db2.setAttribute(NAME, dbName2);
    db2.setAttribute("clusterName", randomString());
    db2.setAttribute("description", randomString());
    AtlasEntityHeader entity2Header = createEntity(db2);
    // Delete the database entities
    EntityMutationResponse deleteResponse = atlasClientV2.deleteEntitiesByGuids(ImmutableList.of(entity1Header.getGuid(), entity2Header.getGuid()));
    // Verify that deleteEntities() response has database entity guids
    assertNotNull(deleteResponse);
    assertNotNull(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE));
    assertEquals(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).size(), 2);
// Verify entities were deleted from the repository.
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test)

Example 28 with AtlasEntity

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

the class ZipSourceTest method useCreationOrderToFetchEntities.

private void useCreationOrderToFetchEntities(ZipSource zipSource, List<String> creationOrder) {
    for (String guid : creationOrder) {
        AtlasEntity e = zipSource.getByGuid(guid);
        assertNotNull(e);
    }
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity)

Example 29 with AtlasEntity

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

the class ZipSourceTest method iteratorBehavor_WorksAsExpected.

@Test(dataProvider = "zipFileStocks")
public void iteratorBehavor_WorksAsExpected(ZipSource zipSource) throws IOException, AtlasBaseException {
    Assert.assertTrue(zipSource.hasNext());
    List<String> creationOrder = zipSource.getCreationOrder();
    for (int i = 0; i < creationOrder.size(); i++) {
        AtlasEntity e = zipSource.next();
        assertNotNull(e);
        assertEquals(e.getGuid(), creationOrder.get(i));
    }
    Assert.assertFalse(zipSource.hasNext());
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) Test(org.testng.annotations.Test)

Example 30 with AtlasEntity

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

the class AtlasDeleteHandlerV1Test method testDeleteTargetOfRequiredMapReference.

@Test
public void testDeleteTargetOfRequiredMapReference() throws Exception {
    // Define type for map value.
    AtlasEntityDef mapValueDef = new AtlasEntityDef("RequiredMapValue", "RequiredMapValue_description", "1.0", Collections.<AtlasStructDef.AtlasAttributeDef>emptyList(), Collections.<String>emptySet());
    AtlasStructDef.AtlasAttributeDef[] mapOwnerAttributes = new AtlasStructDef.AtlasAttributeDef[] { new AtlasStructDef.AtlasAttributeDef("map", "map<string,RequiredMapValue>", false, AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE, 1, 1, false, false, Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()) };
    AtlasEntityDef mapOwnerDef = new AtlasEntityDef("RequiredMapOwner", "RequiredMapOwner_description", "1.0", Arrays.asList(mapOwnerAttributes), Collections.<String>emptySet());
    AtlasTypesDef typesDef = AtlasTypeUtil.getTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), ImmutableList.<AtlasClassificationDef>of(), ImmutableList.<AtlasEntityDef>of(mapValueDef, mapOwnerDef));
    typeDefStore.createTypesDef(typesDef);
    AtlasEntityType mapOwnerType = typeRegistry.getEntityTypeByName("RequiredMapOwner");
    AtlasEntityType mapValueType = typeRegistry.getEntityTypeByName("RequiredMapValue");
    // Create instances of RequiredMapOwner and RequiredMapValue.
    // Set RequiredMapOwner.map with one entry that references RequiredMapValue instance.
    AtlasEntity mapOwnerInstance = new AtlasEntity(mapOwnerType.getTypeName());
    AtlasEntity mapValueInstance = new AtlasEntity(mapValueType.getTypeName());
    mapOwnerInstance.setAttribute("map", Collections.singletonMap("value1", AtlasTypeUtil.getAtlasObjectId(mapValueInstance)));
    AtlasEntity.AtlasEntitiesWithExtInfo entities = new AtlasEntity.AtlasEntitiesWithExtInfo();
    entities.addReferredEntity(mapValueInstance);
    entities.addEntity(mapOwnerInstance);
    List<AtlasEntityHeader> createEntitiesResult = entityStore.createOrUpdate(new AtlasEntityStream(entities), false).getCreatedEntities();
    Assert.assertEquals(createEntitiesResult.size(), 2);
    List<String> guids = metadataService.getEntityList("RequiredMapOwner");
    Assert.assertEquals(guids.size(), 1);
    String mapOwnerGuid = guids.get(0);
    guids = metadataService.getEntityList("RequiredMapValue");
    Assert.assertEquals(guids.size(), 1);
    String mapValueGuid = guids.get(0);
    // Verify MapOwner.map attribute has expected value.
    final AtlasEntity.AtlasEntityWithExtInfo mapOwnerInstance1 = entityStore.getById(mapOwnerGuid);
    Object object = mapOwnerInstance1.getEntity().getAttribute("map");
    Assert.assertNotNull(object);
    Assert.assertTrue(object instanceof Map);
    Map<String, AtlasObjectId> map = (Map<String, AtlasObjectId>) object;
    Assert.assertEquals(map.size(), 1);
    AtlasObjectId mapValueInstance1 = map.get("value1");
    Assert.assertNotNull(mapValueInstance1);
    Assert.assertEquals(mapValueInstance1.getGuid(), mapValueGuid);
    String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(mapOwnerType, "map");
    String mapEntryLabel = edgeLabel + "." + "value1";
    AtlasEdgeLabel atlasEdgeLabel = new AtlasEdgeLabel(mapEntryLabel);
    AtlasVertex mapOwnerVertex = GraphHelper.getInstance().getVertexForGUID(mapOwnerGuid);
    object = mapOwnerVertex.getProperty(atlasEdgeLabel.getQualifiedMapKey(), Object.class);
    Assert.assertNotNull(object);
    // Verify deleting the target of required map attribute throws a AtlasBaseException.
    try {
        entityStore.deleteById(mapValueGuid);
        Assert.fail(AtlasBaseException.class.getSimpleName() + " was expected but none thrown.");
    } catch (Exception e) {
        verifyExceptionThrown(e, AtlasBaseException.class);
    }
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEdgeLabel(org.apache.atlas.repository.graph.AtlasEdgeLabel) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasException(org.apache.atlas.AtlasException) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Map(java.util.Map) HashMap(java.util.HashMap) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

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