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);
}
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);
}
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;
}
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");
}
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);
}
Aggregations