use of org.apache.atlas.typesystem.types.TypeSystem in project incubator-atlas by apache.
the class GraphHelperTest method testGetInstancesByUniqueAttributes.
@Test
public void testGetInstancesByUniqueAttributes() throws Exception {
GraphHelper helper = GraphHelper.getInstance();
List<ITypedReferenceableInstance> instances = new ArrayList<>();
List<String> guids = new ArrayList<>();
TypeSystem ts = TypeSystem.getInstance();
ClassType dbType = ts.getDataType(ClassType.class, TestUtils.DATABASE_TYPE);
for (int i = 0; i < 10; i++) {
Referenceable db = TestUtils.createDBEntity();
String guid = createInstance(db);
ITypedReferenceableInstance instance = convert(db, dbType);
instances.add(instance);
guids.add(guid);
}
//lookup vertices via getVertexForInstanceByUniqueAttributes
List<AtlasVertex> vertices = helper.getVerticesForInstancesByUniqueAttribute(dbType, instances);
assertEquals(instances.size(), vertices.size());
//assert vertex matches the vertex we get through getVertexForGUID
for (int i = 0; i < instances.size(); i++) {
String guid = guids.get(i);
AtlasVertex foundVertex = vertices.get(i);
AtlasVertex expectedVertex = helper.getVertexForGUID(guid);
assertEquals(foundVertex, expectedVertex);
}
}
use of org.apache.atlas.typesystem.types.TypeSystem in project incubator-atlas by apache.
the class GraphBackedSearchIndexerTest method verifyUserDefinedTypeIndex.
@Test
public void verifyUserDefinedTypeIndex() throws AtlasException {
AtlasGraph graph = TestUtils.getGraph();
AtlasGraphManagement managementSystem = graph.getManagementSystem();
try {
TypeSystem typeSystem = TypeSystem.getInstance();
String enumName = "randomEnum" + RandomStringUtils.randomAlphanumeric(10);
EnumType managedType = typeSystem.defineEnumType(enumName, new EnumValue("randomEnumValue", 0));
HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = createClassTypeDef("Database", "Database type description", null, TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("managedType", managedType));
ClassType databaseType = typeSystem.defineClassType(databaseTypeDefinition);
graphBackedSearchIndexer.onAdd(Arrays.asList(databaseType));
verifySystemCompositeIndex(managementSystem, "Database.name" + Constants.ENTITY_TYPE_PROPERTY_KEY, false);
verifyVertexIndexContains(managementSystem, "Database.name" + Constants.ENTITY_TYPE_PROPERTY_KEY);
verifySystemCompositeIndex(managementSystem, "Database.name" + Constants.SUPER_TYPES_PROPERTY_KEY, false);
verifyVertexIndexContains(managementSystem, "Database.managedType");
} finally {
//search indexer uses its own titan management transaction
managementSystem.rollback();
}
}
use of org.apache.atlas.typesystem.types.TypeSystem in project incubator-atlas by apache.
the class NotificationEntityChangeListenerTest method testGetAllTraitsSuperTraits.
@Test
public void testGetAllTraitsSuperTraits() throws Exception {
TypeSystem typeSystem = mock(TypeSystem.class);
String traitName = "MyTrait";
IStruct myTrait = new Struct(traitName);
String superTraitName = "MySuperTrait";
TraitType traitDef = mock(TraitType.class);
Set<String> superTypeNames = Collections.singleton(superTraitName);
TraitType superTraitDef = mock(TraitType.class);
Set<String> superSuperTypeNames = Collections.emptySet();
Referenceable entity = getEntity("id", myTrait);
when(typeSystem.getDataType(TraitType.class, traitName)).thenReturn(traitDef);
when(typeSystem.getDataType(TraitType.class, superTraitName)).thenReturn(superTraitDef);
when(traitDef.getAllSuperTypeNames()).thenReturn(superTypeNames);
when(superTraitDef.getAllSuperTypeNames()).thenReturn(superSuperTypeNames);
List<IStruct> allTraits = NotificationEntityChangeListener.getAllTraits(entity, typeSystem);
assertEquals(2, allTraits.size());
for (IStruct trait : allTraits) {
String typeName = trait.getTypeName();
assertTrue(typeName.equals(traitName) || typeName.equals(superTraitName));
}
}
use of org.apache.atlas.typesystem.types.TypeSystem in project incubator-atlas by apache.
the class DefaultTypeCacheTest method testGetTypesByFilter.
@Test
public void testGetTypesByFilter() throws Exception {
// init TypeSystem
TypeSystem ts = TypeSystem.getInstance().reset();
ts.defineClassType(TypesUtil.createClassTypeDef("A", ImmutableSet.<String>of()));
ts.defineClassType(TypesUtil.createClassTypeDef("A1", ImmutableSet.of("A")));
ts.defineClassType(TypesUtil.createClassTypeDef("B", ImmutableSet.<String>of()));
ts.defineClassType(TypesUtil.createClassTypeDef("C", ImmutableSet.of("B", "A")));
//supertype ~ A
ImmutableList<String> results = ts.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>() {
{
put(TypeCache.TYPE_FILTER.SUPERTYPE, "A");
}
});
assertTrue(results.containsAll(Arrays.asList("A1", "C")), "Results: " + results);
//!supertype doesn't return the type itself
results = ts.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>() {
{
put(TypeCache.TYPE_FILTER.NOT_SUPERTYPE, "A");
}
});
assertTrue(results.containsAll(Arrays.asList("B")), "Results: " + results);
//supertype ~ A && supertype !~ B
results = ts.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>() {
{
put(TypeCache.TYPE_FILTER.SUPERTYPE, "A");
put(TypeCache.TYPE_FILTER.NOT_SUPERTYPE, "B");
}
});
assertTrue(results.containsAll(Arrays.asList("A1")), "Results: " + results);
//none of category trait
results = ts.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>() {
{
put(TypeCache.TYPE_FILTER.CATEGORY, TypeCategory.TRAIT.name());
put(TypeCache.TYPE_FILTER.SUPERTYPE, "A");
}
});
assertTrue(results.isEmpty(), "Results: " + results);
//no filter returns all types
results = ts.getTypeNames(null);
assertTrue(results.containsAll(Arrays.asList("A", "A1", "B", "C")), "Results: " + results);
results = ts.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>());
assertTrue(results.containsAll(Arrays.asList("A", "A1", "B", "C")), "Results: " + results);
//invalid category
try {
ts.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>() {
{
put(TypeCache.TYPE_FILTER.CATEGORY, "A");
}
});
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
//expected
}
//invalid supertype
results = ts.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>() {
{
put(TypeCache.TYPE_FILTER.SUPERTYPE, "X");
}
});
assertTrue(results.isEmpty(), "Expected empty result for non-existent type 'X'. Found: " + results);
//invalid supertype
results = ts.getTypeNames(new HashMap<TypeCache.TYPE_FILTER, String>() {
{
put(TypeCache.TYPE_FILTER.NOT_SUPERTYPE, "X");
}
});
assertTrue(results.containsAll(Arrays.asList("A", "A1", "B", "C")), "Results: " + results);
}
use of org.apache.atlas.typesystem.types.TypeSystem in project incubator-atlas by apache.
the class DefaultTypeCacheTest method onetimeSetup.
@BeforeClass
public void onetimeSetup() throws Exception {
// init TypeSystem
TypeSystem ts = TypeSystem.getInstance().reset();
// Customer ClassType
customerType = ts.defineClassType(TypesUtil.createClassTypeDef(CLASSTYPE_CUSTOMER, ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("id", DataTypes.LONG_TYPE)));
// Address StructType
addressType = ts.defineStructType(STRUCTTYPE_ADDRESS, true, TypesUtil.createRequiredAttrDef("first line", DataTypes.STRING_TYPE), TypesUtil.createOptionalAttrDef("second line", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("city", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("pincode", DataTypes.INT_TYPE));
// Privileged TraitType
privilegedTrait = ts.defineTraitType(TypesUtil.createTraitTypeDef(TRAITTYPE_PRIVILEGED, ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("category", DataTypes.INT_TYPE)));
// Shipping EnumType
shippingEnum = ts.defineEnumType(TypesUtil.createEnumTypeDef(ENUMTYPE_SHIPPING, new EnumValue("Domestic", 1), new EnumValue("International", 2)));
}
Aggregations