List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphanumeric
public static String randomAlphanumeric(int count)
Creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of alpha-numeric characters.
From source file:org.apache.atlas.service.DefaultMetadataServiceTest.java
@Test(expectedExceptions = TypeNotFoundException.class) public void testCreateEntityWithUnknownDatatype() throws Exception { Referenceable entity = new Referenceable("Unknown datatype"); String dbName = RandomStringUtils.randomAlphanumeric(10); entity.set(NAME, dbName);/* w w w. j ava2s.co m*/ entity.set("description", "us db"); TestUtils.createInstance(metadataService, entity); Assert.fail(TypeNotFoundException.class.getSimpleName() + " was expected but none thrown."); }
From source file:org.apache.atlas.service.DefaultMetadataServiceTest.java
@Test //Titan doesn't allow some reserved chars in property keys. Verify that atlas encodes these //See GraphHelper.encodePropertyKey() public void testSpecialCharacters() throws Exception { //Verify that type can be created with reserved characters in typename, attribute name String strAttrName = randomStrWithReservedChars(); String arrayAttrName = randomStrWithReservedChars(); String mapAttrName = randomStrWithReservedChars(); HierarchicalTypeDefinition<ClassType> typeDefinition = createClassTypeDef( "test_type_" + RandomStringUtils.randomAlphanumeric(10), ImmutableSet.<String>of(), createOptionalAttrDef(strAttrName, DataTypes.STRING_TYPE), new AttributeDefinition(arrayAttrName, DataTypes.arrayTypeName(DataTypes.STRING_TYPE.getName()), Multiplicity.OPTIONAL, false, null), new AttributeDefinition(mapAttrName, DataTypes.mapTypeName(DataTypes.STRING_TYPE.getName(), DataTypes.STRING_TYPE.getName()), Multiplicity.OPTIONAL, false, null)); metadataService.createType(TypesSerialization.toJson(typeDefinition, false)); //verify that entity can be created with reserved characters in string value, array value and map key and value Referenceable entity = new Referenceable(typeDefinition.typeName); entity.set(strAttrName, randomStrWithReservedChars()); entity.set(arrayAttrName, new ArrayList<String>() { {/*from w ww. j a va 2 s .c o m*/ add(randomStrWithReservedChars()); } }); entity.set(mapAttrName, new HashMap<String, String>() { { put(randomStrWithReservedChars(), randomStrWithReservedChars()); } }); String id = createInstance(metadataService, entity); //Verify that get entity definition returns actual values with reserved characters Referenceable instance = InstanceSerialization .fromJsonReferenceable(metadataService.getEntityDefinitionJson(id), true); assertReferenceableEquals(instance, entity); //Verify that search with reserved characters works - for string attribute String query = String.format("`%s` where `%s` = '%s'", typeDefinition.typeName, strAttrName, entity.get(strAttrName)); String responseJson = discoveryService.searchByDSL(query, new QueryParams(1, 0)); JSONObject response = new JSONObject(responseJson); assertEquals(response.getJSONArray("rows").length(), 1); }
From source file:org.apache.atlas.service.DefaultMetadataServiceTest.java
@Test public void testTypeUpdateFailureShouldRollBack() throws AtlasException, JSONException { String typeName = "test_type_" + RandomStringUtils.randomAlphanumeric(10); HierarchicalTypeDefinition<ClassType> typeDef = TypesUtil.createClassTypeDef(typeName, ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef("test_type_attribute", DataTypes.STRING_TYPE)); TypesDef typesDef = new TypesDef(typeDef, false); JSONObject type = metadataService.createType(TypesSerialization.toJson(typesDef)); Assert.assertNotNull(type.get(AtlasClient.TYPES)); HierarchicalTypeDefinition<ClassType> updatedTypeDef = TypesUtil.createClassTypeDef(typeName, ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef("test_type_attribute", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("test_type_invalid_attribute$", DataTypes.STRING_TYPE)); TypesDef updatedTypesDef = new TypesDef(updatedTypeDef, false); try {/*from ww w .j a v a 2 s. c o m*/ metadataService.updateType(TypesSerialization.toJson(updatedTypesDef)); fail("Expected AtlasException"); } catch (AtlasException e) { //expected } //type definition should reflect old type String typeDefinition = metadataService.getTypeDefinition(typeName); typesDef = TypesSerialization.fromJson(typeDefinition); assertEquals(typesDef.classTypes().head().attributeDefinitions.length, 1); }
From source file:org.apache.atlas.TestUtils.java
public static final String randomString() { return RandomStringUtils.randomAlphanumeric(10); }
From source file:org.apache.atlas.TestUtils.java
public static Referenceable createDBEntity() { Referenceable entity = new Referenceable(DATABASE_TYPE); String dbName = RandomStringUtils.randomAlphanumeric(10); entity.set(NAME, dbName);/*from w ww .jav a2 s . com*/ entity.set("description", "us db"); return entity; }
From source file:org.apache.atlas.TestUtils.java
public static Referenceable createTableEntity(String dbId) { Referenceable entity = new Referenceable(TABLE_TYPE); String tableName = RandomStringUtils.randomAlphanumeric(10); entity.set(NAME, tableName);//from www. j a va2 s. co m entity.set("description", "random table"); entity.set("type", "type"); entity.set("tableType", "MANAGED"); entity.set("database", new Id(dbId, 0, DATABASE_TYPE)); entity.set("created", new Date()); return entity; }
From source file:org.apache.atlas.TestUtils.java
public static Referenceable createColumnEntity() { Referenceable entity = new Referenceable(COLUMN_TYPE); entity.set(NAME, RandomStringUtils.randomAlphanumeric(10)); entity.set("type", "VARCHAR(32)"); return entity; }
From source file:org.apache.atlas.TestUtilsV2.java
public static AtlasEntity createDBEntity() { String dbName = RandomStringUtils.randomAlphanumeric(10); return createDBEntity(dbName); }
From source file:org.apache.atlas.TestUtilsV2.java
public static AtlasEntityWithExtInfo createDBEntityV2() { AtlasEntity dbEntity = new AtlasEntity(DATABASE_TYPE); dbEntity.setAttribute(NAME, RandomStringUtils.randomAlphanumeric(10)); dbEntity.setAttribute("description", "us db"); return new AtlasEntityWithExtInfo(dbEntity); }
From source file:org.apache.atlas.TestUtilsV2.java
public static AtlasEntity createTableEntity(AtlasEntity dbEntity) { String tableName = RandomStringUtils.randomAlphanumeric(10); return createTableEntity(dbEntity, tableName); }