use of org.apache.atlas.model.typedef.AtlasTypesDef in project incubator-atlas by apache.
the class AtlasEntityStoreV1Test method testTagAssociationAfterRedefinition.
@Test
public void testTagAssociationAfterRedefinition() {
AtlasClassificationDef aTag = new AtlasClassificationDef("testTag");
AtlasAttributeDef attributeDef = new AtlasAttributeDef("testAttribute", "int", true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, true, Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
aTag.addAttribute(attributeDef);
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.setClassificationDefs(Arrays.asList(aTag));
try {
typeDefStore.createTypesDef(typesDef);
} catch (AtlasBaseException e) {
fail("Tag creation should've succeeded");
}
try {
typeDefStore.deleteTypesDef(typesDef);
} catch (AtlasBaseException e) {
fail("Tag deletion should've succeeded");
}
aTag = new AtlasClassificationDef("testTag");
attributeDef = new AtlasAttributeDef("testAttribute", "string", true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, true, Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
aTag.addAttribute(attributeDef);
typesDef.setClassificationDefs(Arrays.asList(aTag));
try {
typeDefStore.createTypesDef(typesDef);
} catch (AtlasBaseException e) {
fail("Tag re-creation should've succeeded");
}
final AtlasEntity dbEntity = TestUtilsV2.createDBEntity();
try {
EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);
List<AtlasEntityHeader> createdEntity = response.getCreatedEntities();
assertTrue(CollectionUtils.isNotEmpty(createdEntity));
String guid = createdEntity.get(0).getGuid();
entityStore.addClassification(Arrays.asList(guid), new AtlasClassification(aTag.getName(), "testAttribute", "test-string"));
} catch (AtlasBaseException e) {
fail("DB entity creation should've succeeded");
}
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project incubator-atlas by apache.
the class AtlasEntityStoreV1Test method setUp.
@BeforeClass
public void setUp() throws Exception {
metadataService = TestUtils.addSessionCleanupWrapper(metadataService);
new GraphBackedSearchIndexer(typeRegistry);
AtlasTypesDef[] testTypesDefs = new AtlasTypesDef[] { TestUtilsV2.defineDeptEmployeeTypes(), TestUtilsV2.defineHiveTypes() };
for (AtlasTypesDef typesDef : testTypesDefs) {
AtlasTypesDef typesToCreate = AtlasTypeDefStoreInitializer.getTypesToCreate(typesDef, typeRegistry);
if (!typesToCreate.isEmpty()) {
typeDefStore.createTypesDef(typesToCreate);
}
}
deptEntity = TestUtilsV2.createDeptEg2();
dbEntity = TestUtilsV2.createDBEntityV2();
tblEntity = TestUtilsV2.createTableEntityV2(dbEntity.getEntity());
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project incubator-atlas by apache.
the class AtlasEntityStoreV1Test method testSpecialCharacters.
@Test(enabled = false)
public //TODO : Failing in typedef creation
void testSpecialCharacters() throws Exception {
//Verify that type can be created with reserved characters in typename, attribute name
final String typeName = "test_type_" + RandomStringUtils.randomAlphanumeric(10);
String strAttrName = randomStrWithReservedChars();
String arrayAttrName = randomStrWithReservedChars();
String mapAttrName = randomStrWithReservedChars();
AtlasEntityDef typeDefinition = AtlasTypeUtil.createClassTypeDef(typeName, "Special chars test type", ImmutableSet.<String>of(), AtlasTypeUtil.createOptionalAttrDef(strAttrName, "string"), AtlasTypeUtil.createOptionalAttrDef(arrayAttrName, "array<string>"), AtlasTypeUtil.createOptionalAttrDef(mapAttrName, "map<string,string>"));
AtlasTypesDef atlasTypesDef = new AtlasTypesDef(null, null, null, Arrays.asList(typeDefinition));
typeDefStore.createTypesDef(atlasTypesDef);
//verify that entity can be created with reserved characters in string value, array value and map key and value
AtlasEntity entity = new AtlasEntity();
entity.setAttribute(strAttrName, randomStrWithReservedChars());
entity.setAttribute(arrayAttrName, new String[] { randomStrWithReservedChars() });
entity.setAttribute(mapAttrName, new HashMap<String, String>() {
{
put(randomStrWithReservedChars(), randomStrWithReservedChars());
}
});
AtlasEntityWithExtInfo entityWithExtInfo = new AtlasEntityWithExtInfo(entity);
final EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entityWithExtInfo), false);
final AtlasEntityHeader firstEntityCreated = response.getFirstEntityCreated();
validateEntity(entityWithExtInfo, getEntityFromStore(firstEntityCreated));
//Verify that search with reserved characters works - for string attribute
// String query =
// String.format("`%s` where `%s` = '%s'", typeName, strAttrName, entity.getAttribute(strAttrName));
// String responseJson = discoveryService.searchByDSL(query, new QueryParams(1, 0));
// JSONObject response = new JSONObject(responseJson);
// assertEquals(response.getJSONArray("rows").length(), 1);
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project incubator-atlas by apache.
the class AtlasTypeDefGraphStoreTest method allCreatedTypes.
@DataProvider
public Object[][] allCreatedTypes() {
// Capture all the types that are getting created or updated here.
AtlasTypesDef updatedTypeDefs = TestUtilsV2.defineValidUpdatedDeptEmployeeTypes();
AtlasTypesDef allTypeDefs = new AtlasTypesDef();
allTypeDefs.getEnumDefs().addAll(updatedTypeDefs.getEnumDefs());
allTypeDefs.getStructDefs().addAll(updatedTypeDefs.getStructDefs());
allTypeDefs.getClassificationDefs().addAll(updatedTypeDefs.getClassificationDefs());
allTypeDefs.getEntityDefs().addAll(updatedTypeDefs.getEntityDefs());
allTypeDefs.getEntityDefs().addAll(TestUtilsV2.getEntityWithValidSuperType());
return new Object[][] { { allTypeDefs } };
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project incubator-atlas by apache.
the class AtlasTypeDefGraphStoreTest method testCreateWithValidSuperTypes.
@Test(dependsOnMethods = "testGet")
public void testCreateWithValidSuperTypes() {
// Test Classification with supertype
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");
}
// Test Entity with supertype
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");
}
}
Aggregations