Search in sources :

Example 31 with ITypedReferenceableInstance

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

the class GraphBackedMetadataRepositoryTest method testGetEntityDefinitionForDepartment.

@Test(dependsOnMethods = "testSubmitEntity")
public void testGetEntityDefinitionForDepartment() throws Exception {
    ITypedReferenceableInstance entity = repositoryService.getEntityDefinition(guid);
    Assert.assertNotNull(entity);
    // entity state should be active by default
    Assert.assertEquals(entity.getId().getState(), Id.EntityState.ACTIVE);
    // System attributes created time and modified time should not be null
    AtlasSystemAttributes systemAttributes = entity.getSystemAttributes();
    Assert.assertNotNull(systemAttributes.createdTime);
    Assert.assertNotNull(systemAttributes.modifiedTime);
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AtlasSystemAttributes(org.apache.atlas.typesystem.persistence.AtlasSystemAttributes) Test(org.testng.annotations.Test)

Example 32 with ITypedReferenceableInstance

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

the class GraphBackedMetadataRepositoryTest method testCreateEntityWithTwoNestingLevels.

@Test
public void testCreateEntityWithTwoNestingLevels() throws AtlasException {
    List<Referenceable> toVerify = new ArrayList<>();
    Referenceable dept = new Referenceable(TestUtils.DEPARTMENT_TYPE);
    toVerify.add(dept);
    dept.set(TestUtils.NAME, "test2");
    Referenceable wallace = new Referenceable(TestUtils.PERSON_TYPE);
    toVerify.add(wallace);
    wallace.set(TestUtils.NAME, "Wallace");
    wallace.set(TestUtils.DEPARTMENT_ATTR, dept);
    Referenceable wallaceComputer = new Referenceable(TestUtils.ASSET_TYPE);
    toVerify.add(wallaceComputer);
    wallaceComputer.set("name", "wallaceComputer");
    wallace.set(TestUtils.ASSETS_ATTR, ImmutableList.of(wallaceComputer));
    Referenceable jordan = new Referenceable(TestUtils.PERSON_TYPE);
    toVerify.add(jordan);
    jordan.set(TestUtils.NAME, "Jordan");
    jordan.set(TestUtils.DEPARTMENT_ATTR, dept);
    Referenceable jordanComputer = new Referenceable(TestUtils.ASSET_TYPE);
    toVerify.add(jordanComputer);
    jordanComputer.set("name", "jordanComputer");
    jordan.set(TestUtils.ASSETS_ATTR, ImmutableList.of(jordanComputer));
    dept.set(TestUtils.EMPLOYEES_ATTR, ImmutableList.of(wallace, jordan));
    Map<String, Referenceable> positions = new HashMap<>();
    final String JANITOR = "janitor";
    final String RECEPTIONIST = "receptionist";
    positions.put(JANITOR, wallace);
    positions.put(RECEPTIONIST, jordan);
    dept.set(TestUtils.POSITIONS_ATTR, positions);
    ClassType deptType = TypeSystem.getInstance().getDataType(ClassType.class, TestUtils.DEPARTMENT_TYPE);
    ITypedReferenceableInstance deptInstance = deptType.convert(dept, Multiplicity.REQUIRED);
    CreateUpdateEntitiesResult result = repositoryService.createEntities(deptInstance);
    validateGuidMapping(toVerify, result);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) HashMap(java.util.HashMap) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) ArrayList(java.util.ArrayList) ClassType(org.apache.atlas.typesystem.types.ClassType) Test(org.testng.annotations.Test)

Example 33 with ITypedReferenceableInstance

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

the class GraphBackedMetadataRepositoryTest method assertEdge.

private boolean assertEdge(String id, String typeName) throws Exception {
    AtlasGraph graph = TestUtils.getGraph();
    Iterable<AtlasVertex> vertices = graph.query().has(Constants.GUID_PROPERTY_KEY, id).vertices();
    AtlasVertex AtlasVertex = vertices.iterator().next();
    Iterable<AtlasEdge> edges = AtlasVertex.getEdges(AtlasEdgeDirection.OUT, Constants.INTERNAL_PROPERTY_KEY_PREFIX + typeName + ".ref");
    if (!edges.iterator().hasNext()) {
        ITypedReferenceableInstance entity = repositoryService.getEntityDefinition(id);
        assertNotNull(entity.get("ref"));
        return true;
    }
    return false;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 34 with ITypedReferenceableInstance

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

the class GraphBackedMetadataRepositoryTest method testAddTraitWithAttribute.

@Test(dependsOnMethods = "testAddTrait")
public void testAddTraitWithAttribute() throws Exception {
    final String aGUID = getGUID();
    final String traitName = "P_I_I";
    HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE));
    TraitType traitType = typeSystem.defineTraitType(piiTrait);
    ITypedStruct traitInstance = traitType.createInstance();
    traitInstance.set("type", "SSN");
    repositoryService.addTrait(aGUID, traitInstance);
    TestUtils.dumpGraph(TestUtils.getGraph());
    // refresh trait names
    List<String> traitNames = repositoryService.getTraitNames(aGUID);
    Assert.assertEquals(traitNames.size(), 3);
    Assert.assertTrue(traitNames.contains(traitName));
    ITypedReferenceableInstance instance = repositoryService.getEntityDefinition(aGUID);
    IStruct traitInstanceRef = instance.getTrait(traitName);
    String type = (String) traitInstanceRef.get("type");
    Assert.assertEquals(type, "SSN");
}
Also used : TraitType(org.apache.atlas.typesystem.types.TraitType) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct) Test(org.testng.annotations.Test)

Example 35 with ITypedReferenceableInstance

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

the class GraphBackedMetadataRepositoryTest method createEntity.

private List<String> createEntity(Referenceable entity) throws Exception {
    ClassType type = typeSystem.getDataType(ClassType.class, entity.getTypeName());
    ITypedReferenceableInstance instance = type.convert(entity, Multiplicity.REQUIRED);
    return createEntities(instance);
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ClassType(org.apache.atlas.typesystem.types.ClassType)

Aggregations

ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)142 Test (org.testng.annotations.Test)54 List (java.util.List)34 ArrayList (java.util.ArrayList)30 Id (org.apache.atlas.typesystem.persistence.Id)28 Referenceable (org.apache.atlas.typesystem.Referenceable)22 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)21 ImmutableList (com.google.common.collect.ImmutableList)20 ClassType (org.apache.atlas.typesystem.types.ClassType)19 HashMap (java.util.HashMap)16 AtlasException (org.apache.atlas.AtlasException)16 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)16 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)14 EntityResult (org.apache.atlas.model.legacy.EntityResult)12 IStruct (org.apache.atlas.typesystem.IStruct)10 Map (java.util.Map)9 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)9 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)9 RepositoryException (org.apache.atlas.repository.RepositoryException)9 BeforeTest (org.testng.annotations.BeforeTest)9