use of org.apache.atlas.type.AtlasTypeRegistry in project incubator-atlas by apache.
the class TestAtlasEntity method testEntitySerDe.
@Test
public void testEntitySerDe() throws AtlasBaseException {
AtlasEntityDef entityDef = ModelTestUtil.getEntityDef();
AtlasTypeRegistry typeRegistry = ModelTestUtil.getTypesRegistry();
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityDef.getName());
assertNotNull(entityType);
AtlasEntity ent1 = entityType.createDefaultValue();
String jsonString = AtlasType.toJson(ent1);
AtlasEntity ent2 = AtlasType.fromJson(jsonString, AtlasEntity.class);
entityType.normalizeAttributeValues(ent2);
assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasEntity");
}
use of org.apache.atlas.type.AtlasTypeRegistry in project incubator-atlas by apache.
the class BaseRepositoryTest method setUp.
protected void setUp() throws Exception {
//force graph initialization / built in type registration
TestUtils.getGraph();
setUpDefaultTypes();
setUpTypes();
TestUtils.getGraph().commit();
new GraphBackedSearchIndexer(new AtlasTypeRegistry());
TestUtils.resetRequestContext();
setupInstances();
TestUtils.getGraph().commit();
TestUtils.dumpGraph(TestUtils.getGraph());
}
use of org.apache.atlas.type.AtlasTypeRegistry in project incubator-atlas by apache.
the class RestUtilsTest method convertV1toV2.
private List<AtlasEntityDef> convertV1toV2(List<HierarchicalTypeDefinition<ClassType>> types) throws AtlasBaseException {
ImmutableList<HierarchicalTypeDefinition<ClassType>> classTypeList = ImmutableList.<HierarchicalTypeDefinition<ClassType>>builder().addAll(types).build();
TypesDef toConvert = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), classTypeList);
String json = TypesSerialization.toJson(toConvert);
AtlasTypeRegistry emptyRegistry = new AtlasTypeRegistry();
AtlasTypesDef converted = TypeConverterUtil.toAtlasTypesDef(json, emptyRegistry);
List<AtlasEntityDef> convertedEntityDefs = converted.getEntityDefs();
return convertedEntityDefs;
}
use of org.apache.atlas.type.AtlasTypeRegistry in project incubator-atlas by apache.
the class RestUtilsTest method createRegistry.
private AtlasTypeRegistry createRegistry(List<AtlasEntityDef> toConvert) throws AtlasBaseException {
AtlasTypeRegistry reg = new AtlasTypeRegistry();
AtlasTransientTypeRegistry tmp = reg.lockTypeRegistryForUpdate();
tmp.addTypes(toConvert);
reg.releaseTypeRegistryForUpdate(tmp, true);
return reg;
}
use of org.apache.atlas.type.AtlasTypeRegistry in project incubator-atlas by apache.
the class RestUtilsTest method testV1toV2toV1Conversion.
private void testV1toV2toV1Conversion(List<HierarchicalTypeDefinition<ClassType>> typesToTest, boolean[] compositeExpected) throws AtlasBaseException {
List<AtlasEntityDef> convertedEntityDefs = convertV1toV2(typesToTest);
AtlasTypeRegistry registry = createRegistry(convertedEntityDefs);
for (int i = 0; i < convertedEntityDefs.size(); i++) {
AtlasEntityDef def = convertedEntityDefs.get(i);
for (AtlasAttributeDef attrDef : def.getAttributeDefs()) {
AtlasAttributeDef converted = convertToJsonAndBack(registry, def, attrDef, compositeExpected[i]);
Assert.assertEquals(converted, attrDef);
}
}
List<HierarchicalTypeDefinition<ClassType>> convertedBackTypeDefs = convertV2toV1(convertedEntityDefs);
for (int i = 0; i < typesToTest.size(); i++) {
HierarchicalTypeDefinition<ClassType> convertedBack = convertedBackTypeDefs.get(i);
Assert.assertEquals(convertedBack, typesToTest.get(i));
AttributeDefinition[] attributeDefinitions = convertedBack.attributeDefinitions;
if (attributeDefinitions.length > 0) {
Assert.assertEquals(attributeDefinitions[0].isComposite, compositeExpected[i]);
}
}
}
Aggregations