Search in sources :

Example 1 with HierarchicalType

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

the class DefaultPropertyMapperTest method testToQualifiedName_specifiedMappings.

@Test
public void testToQualifiedName_specifiedMappings() throws Exception {
    String typeName = "testType";
    HierarchicalType dataType = createNiceMock(HierarchicalType.class);
    // currently only use key in map
    Map<String, AttributeInfo> fields = new HashMap<>();
    fields.put("foo", null);
    fields.put("prop", null);
    // can't mock FieldMapping due to direct access to final instance var 'fields'
    FieldMapping fieldMapping = new FieldMapping(fields, null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    // mock expectations
    expect(dataType.fieldMapping()).andReturn(fieldMapping).anyTimes();
    expect(dataType.getQualifiedName("foo")).andReturn("foo");
    expect(dataType.getQualifiedName("prop")).andReturn("Prefix.prop");
    replay(dataType);
    Map<String, String> cleanToQualifiedMap = new HashMap<>();
    cleanToQualifiedMap.put("prop1", "property_1");
    Map<String, String> qualifiedToCleanMap = new HashMap<>();
    qualifiedToCleanMap.put("property_1", "prop1");
    PropertyMapper propertyMapper = new TestDefaultPropertyMapper(typeName, qualifiedToCleanMap, cleanToQualifiedMap, dataType);
    assertEquals(propertyMapper.toFullyQualifiedName("prop1", typeName), "property_1");
    assertEquals(propertyMapper.toFullyQualifiedName("foo", typeName), "foo");
    assertEquals(propertyMapper.toFullyQualifiedName("prop", typeName), "Prefix.prop");
    assertEquals(propertyMapper.toFullyQualifiedName("other", typeName), "other");
    assertEquals(propertyMapper.toFullyQualifiedName("Prefix.other", typeName), "Prefix.other");
    verify(dataType);
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) HashMap(java.util.HashMap) FieldMapping(org.apache.atlas.typesystem.types.FieldMapping) HierarchicalType(org.apache.atlas.typesystem.types.HierarchicalType) Test(org.testng.annotations.Test)

Example 2 with HierarchicalType

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

the class DefaultPropertyMapperTest method testToQualifiedName_defaultMappings.

@Test
public void testToQualifiedName_defaultMappings() throws Exception {
    String typeName = "testType";
    HierarchicalType dataType = createNiceMock(HierarchicalType.class);
    // currently only use key in map
    Map<String, AttributeInfo> fields = new HashMap<>();
    fields.put("foo", null);
    fields.put("prop", null);
    // can't mock FieldMapping due to direct access to final instance var 'fields'
    FieldMapping fieldMapping = new FieldMapping(fields, null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    // mock expectations
    expect(dataType.fieldMapping()).andReturn(fieldMapping).anyTimes();
    expect(dataType.getQualifiedName("foo")).andReturn("foo");
    expect(dataType.getQualifiedName("prop")).andReturn("Prefix.prop");
    replay(dataType);
    PropertyMapper propertyMapper = new TestDefaultPropertyMapper(dataType);
    assertEquals(propertyMapper.toFullyQualifiedName("foo", typeName), "foo");
    assertEquals(propertyMapper.toFullyQualifiedName("prop", typeName), "Prefix.prop");
    assertEquals(propertyMapper.toFullyQualifiedName("other", typeName), "other");
    assertEquals(propertyMapper.toFullyQualifiedName("Prefix.other", typeName), "Prefix.other");
    verify(dataType);
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) HashMap(java.util.HashMap) FieldMapping(org.apache.atlas.typesystem.types.FieldMapping) HierarchicalType(org.apache.atlas.typesystem.types.HierarchicalType) Test(org.testng.annotations.Test)

Example 3 with HierarchicalType

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

the class DefaultPropertyMapperTest method testToCleanName_defaultMappings.

@Test
public void testToCleanName_defaultMappings() {
    String typeName = "testType";
    HierarchicalType dataType = createNiceMock(HierarchicalType.class);
    // currently only use key in map
    Map<String, AttributeInfo> fields = new HashMap<>();
    fields.put("foo", null);
    fields.put("prop", null);
    // can't mock FieldMapping due to direct access to final instance var 'fields'
    FieldMapping fieldMapping = new FieldMapping(fields, null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    // mock expectations
    expect(dataType.fieldMapping()).andReturn(fieldMapping).anyTimes();
    replay(dataType);
    PropertyMapper propertyMapper = new TestDefaultPropertyMapper(dataType);
    assertEquals(propertyMapper.toCleanName("Prefix.prop", typeName), "prop");
    assertEquals(propertyMapper.toCleanName("foo", typeName), "foo");
    assertEquals(propertyMapper.toCleanName("other", typeName), "other");
    assertEquals(propertyMapper.toCleanName("Prefix.other", typeName), "Prefix.other");
    verify(dataType);
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) HashMap(java.util.HashMap) FieldMapping(org.apache.atlas.typesystem.types.FieldMapping) HierarchicalType(org.apache.atlas.typesystem.types.HierarchicalType) Test(org.testng.annotations.Test)

Example 4 with HierarchicalType

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

the class TypeVertexFinder method visitSuperType.

@Override
public void visitSuperType(String typeName, String superTypeName) throws AtlasException {
    HierarchicalType superType = typeSystem.getDataType(HierarchicalType.class, superTypeName);
    visitDataType(superType);
}
Also used : HierarchicalType(org.apache.atlas.typesystem.types.HierarchicalType)

Example 5 with HierarchicalType

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

the class MemRepository method defineTypes.

public void defineTypes(List<HierarchicalType> types) throws RepositoryException {
    List<TraitType> tTypes = new ArrayList<>();
    List<ClassType> cTypes = new ArrayList<>();
    for (HierarchicalType h : types) {
        if (h.getTypeCategory() == DataTypes.TypeCategory.TRAIT) {
            tTypes.add((TraitType) h);
        } else {
            cTypes.add((ClassType) h);
        }
    }
    tTypes = HierarchicalTypeDependencySorter.sortTypes(tTypes);
    cTypes = HierarchicalTypeDependencySorter.sortTypes(cTypes);
    for (TraitType tT : tTypes) {
        defineTrait(tT);
    }
    for (ClassType cT : cTypes) {
        defineClass(cT);
    }
}
Also used : TraitType(org.apache.atlas.typesystem.types.TraitType) ArrayList(java.util.ArrayList) ClassType(org.apache.atlas.typesystem.types.ClassType) HierarchicalType(org.apache.atlas.typesystem.types.HierarchicalType)

Aggregations

HierarchicalType (org.apache.atlas.typesystem.types.HierarchicalType)10 FieldMapping (org.apache.atlas.typesystem.types.FieldMapping)6 HashMap (java.util.HashMap)4 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)4 Test (org.testng.annotations.Test)4 ArrayList (java.util.ArrayList)1 AtlasException (org.apache.atlas.AtlasException)1 CatalogRuntimeException (org.apache.atlas.catalog.exception.CatalogRuntimeException)1 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)1 ClassType (org.apache.atlas.typesystem.types.ClassType)1 TraitType (org.apache.atlas.typesystem.types.TraitType)1