AtlasTypeDefGraphStore implements AtlasTypeDefStore, ActiveStateChangeHandler { @Override @GraphTransaction public AtlasTypesDef createTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classifications={}, entities={}, relationships={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), CollectionUtils.size(typesDef.getEntityDefs()), CollectionUtils.size(typesDef.getRelationshipDefs())); } AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); tryTypeCreation(typesDef, ttr); AtlasTypesDef ret = addToGraphStore(typesDef, ttr); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), CollectionUtils.size(typesDef.getEntityDefs()), CollectionUtils.size(typesDef.getRelationshipDefs())); } return ret; } protected  AtlasTypeDefGraphStore(AtlasTypeRegistry typeRegistry,
                                     Set<TypeDefChangeListener> typeDefChangeListeners); @Override void init(); @Override AtlasEnumDef getEnumDefByName(String name); @Override AtlasEnumDef getEnumDefByGuid(String guid); @Override @GraphTransaction AtlasEnumDef updateEnumDefByName(String name, AtlasEnumDef enumDef); @Override @GraphTransaction AtlasEnumDef updateEnumDefByGuid(String guid, AtlasEnumDef enumDef); @Override AtlasStructDef getStructDefByName(String name); @Override AtlasStructDef getStructDefByGuid(String guid); @Override AtlasRelationshipDef getRelationshipDefByName(String name); @Override AtlasRelationshipDef getRelationshipDefByGuid(String guid); @Override @GraphTransaction AtlasStructDef updateStructDefByName(String name, AtlasStructDef structDef); @Override @GraphTransaction AtlasStructDef updateStructDefByGuid(String guid, AtlasStructDef structDef); @Override AtlasClassificationDef getClassificationDefByName(String name); @Override AtlasClassificationDef getClassificationDefByGuid(String guid); @Override @GraphTransaction AtlasClassificationDef updateClassificationDefByName(String name, AtlasClassificationDef classificationDef); @Override @GraphTransaction AtlasClassificationDef updateClassificationDefByGuid(String guid, AtlasClassificationDef classificationDef); @Override AtlasEntityDef getEntityDefByName(String name); @Override AtlasEntityDef getEntityDefByGuid(String guid); @Override @GraphTransaction AtlasEntityDef updateEntityDefByName(String name, AtlasEntityDef entityDef); @Override @GraphTransaction AtlasEntityDef updateEntityDefByGuid(String guid, AtlasEntityDef entityDef); @Override @GraphTransaction AtlasRelationshipDef updateRelationshipDefByName(String name, AtlasRelationshipDef relationshipDef); @Override @GraphTransaction AtlasRelationshipDef updateRelationshipDefByGuid(String guid, AtlasRelationshipDef relationshipDef); @Override @GraphTransaction AtlasTypesDef createTypesDef(AtlasTypesDef typesDef); @Override @GraphTransaction AtlasTypesDef createUpdateTypesDef(AtlasTypesDef typesToCreate, AtlasTypesDef typesToUpdate); @Override @GraphTransaction AtlasTypesDef updateTypesDef(AtlasTypesDef typesDef); @Override @GraphTransaction void deleteTypesDef(AtlasTypesDef typesDef); @Override AtlasTypesDef searchTypesDef(SearchFilter searchFilter); @Override AtlasBaseTypeDef getByName(String name); @Override AtlasBaseTypeDef getByGuid(String guid); @Override void instanceIsActive(); @Override void instanceIsPassive();  }
@Test(dependsOnMethods = "testGet") public void testCreateWithValidAttributes(){ AtlasTypesDef hiveTypes = TestUtilsV2.defineHiveTypes(); try { AtlasTypesDef createdTypes = typeDefStore.createTypesDef(hiveTypes); assertEquals(hiveTypes.getEnumDefs(), createdTypes.getEnumDefs(), "Data integrity issue while persisting"); assertEquals(hiveTypes.getStructDefs(), createdTypes.getStructDefs(), "Data integrity issue while persisting"); assertEquals(hiveTypes.getClassificationDefs(), createdTypes.getClassificationDefs(), "Data integrity issue while persisting"); assertEquals(hiveTypes.getEntityDefs(), createdTypes.getEntityDefs(), "Data integrity issue while persisting"); } catch (AtlasBaseException e) { fail("Hive Type creation should've succeeded"); } }
@Test(dependsOnMethods = "testGet") public void testCreateWithValidSuperTypes(){ List<AtlasClassificationDef> classificationDefs = TestUtilsV2.getClassificationWithValidSuperType(); AtlasTypesDef toCreate = new AtlasTypesDef(Collections.<AtlasEnumDef>emptyList(), Collections.<AtlasStructDef>emptyList(), classificationDefs, Collections.<AtlasEntityDef>emptyList()); try { AtlasTypesDef created = typeDefStore.createTypesDef(toCreate); assertEquals(created.getClassificationDefs(), toCreate.getClassificationDefs(), "Classification creation with valid supertype should've succeeded"); } catch (AtlasBaseException e) { fail("Classification creation with valid supertype should've succeeded"); } List<AtlasEntityDef> entityDefs = TestUtilsV2.getEntityWithValidSuperType(); toCreate = new AtlasTypesDef(Collections.<AtlasEnumDef>emptyList(), Collections.<AtlasStructDef>emptyList(), Collections.<AtlasClassificationDef>emptyList(), entityDefs); try { AtlasTypesDef created = typeDefStore.createTypesDef(toCreate); assertEquals(created.getEntityDefs(), toCreate.getEntityDefs(), "Entity creation with valid supertype should've succeeded"); } catch (AtlasBaseException e) { fail("Entity creation with valid supertype should've succeeded"); } }
@Test(dependsOnMethods = "testGet") public void testCreateWithInvalidSuperTypes(){ AtlasTypesDef typesDef; AtlasClassificationDef classificationDef = TestUtilsV2.getClassificationWithInvalidSuperType(); typesDef = new AtlasTypesDef(); typesDef.getClassificationDefs().add(classificationDef); try { AtlasTypesDef created = typeDefStore.createTypesDef(typesDef); fail("Classification creation with invalid supertype should've failed"); } catch (AtlasBaseException e) { typesDef = null; } AtlasEntityDef entityDef = TestUtilsV2.getEntityWithInvalidSuperType(); typesDef = new AtlasTypesDef(); typesDef.getEntityDefs().add(entityDef); try { AtlasTypesDef created = typeDefStore.createTypesDef(typesDef); fail("Entity creation with invalid supertype should've failed"); } catch (AtlasBaseException e) {} }