use of org.apache.atlas.typesystem.IStruct in project incubator-atlas by apache.
the class EntityNotificationImplTest 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);
EntityNotificationImpl entityNotification = new EntityNotificationImpl(entity, EntityNotification.OperationType.TRAIT_ADD, typeSystem);
List<IStruct> allTraits = entityNotification.getAllTraits();
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.IStruct in project incubator-atlas by apache.
the class EntityNotificationImplTest method getEntity.
public static Referenceable getEntity(String id, IStruct... traits) {
String typeName = "typeName";
Map<String, Object> values = new HashMap<>();
List<String> traitNames = new LinkedList<>();
Map<String, IStruct> traitMap = new HashMap<>();
for (IStruct trait : traits) {
String traitName = trait.getTypeName();
traitNames.add(traitName);
traitMap.put(traitName, trait);
}
return new Referenceable(id, typeName, values, traitNames, traitMap);
}
use of org.apache.atlas.typesystem.IStruct in project incubator-atlas by apache.
the class NotificationEntityChangeListener method getSuperTraits.
private static List<IStruct> getSuperTraits(String typeName, Map<String, Object> values, TypeSystem typeSystem) throws AtlasException {
List<IStruct> superTypes = new LinkedList<>();
TraitType traitDef = typeSystem.getDataType(TraitType.class, typeName);
Set<String> superTypeNames = traitDef.getAllSuperTypeNames();
for (String superTypeName : superTypeNames) {
TraitType superTraitDef = typeSystem.getDataType(TraitType.class, superTypeName);
Map<String, Object> superTypeValues = new HashMap<>();
FieldMapping fieldMapping = superTraitDef.fieldMapping();
if (fieldMapping != null) {
Set<String> superTypeAttributeNames = fieldMapping.fields.keySet();
for (String superTypeAttributeName : superTypeAttributeNames) {
if (values.containsKey(superTypeAttributeName)) {
superTypeValues.put(superTypeAttributeName, values.get(superTypeAttributeName));
}
}
}
IStruct superTrait = new Struct(superTypeName, superTypeValues);
superTypes.add(superTrait);
superTypes.addAll(getSuperTraits(superTypeName, values, typeSystem));
}
return superTypes;
}
use of org.apache.atlas.typesystem.IStruct in project incubator-atlas by apache.
the class KafkaConsumerTest method getEntity.
private Referenceable getEntity(String traitName) {
Referenceable entity = EntityNotificationImplTest.getEntity("id");
List<IStruct> traitInfo = new LinkedList<>();
IStruct trait = new Struct(traitName, Collections.<String, Object>emptyMap());
traitInfo.add(trait);
return entity;
}
use of org.apache.atlas.typesystem.IStruct in project incubator-atlas by apache.
the class DefaultMetadataServiceTest method testAddDeleteTrait.
@Test
public void testAddDeleteTrait() throws Exception {
Referenceable entity = createDBEntity();
String id = TestUtils.createInstance(metadataService, entity);
//add trait
Struct tag = new Struct(TestUtils.PII);
metadataService.addTrait(id, InstanceSerialization.toJson(tag, true));
List<String> traits = metadataService.getTraitNames(id);
assertEquals(traits.size(), 1);
assertEquals(traits.get(0), PII);
//getTrait
IStruct traitDefinition = metadataService.getTraitDefinition(id, PII);
Assert.assertNotNull(traitDefinition);
assertEquals(traitDefinition.getValuesMap().size(), 0);
//delete trait
metadataService.deleteTrait(id, PII);
traits = metadataService.getTraitNames(id);
assertEquals(traits.size(), 0);
//add trait again
metadataService.addTrait(id, InstanceSerialization.toJson(tag, true));
traits = metadataService.getTraitNames(id);
assertEquals(traits.size(), 1);
assertEquals(traits.get(0), PII);
}
Aggregations