Example usage for org.apache.commons.lang RandomStringUtils randomAlphanumeric

List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphanumeric

Introduction

In this page you can find the example usage for org.apache.commons.lang RandomStringUtils randomAlphanumeric.

Prototype

public static String randomAlphanumeric(int count) 

Source Link

Document

Creates a random string whose length is the number of characters specified.

Characters will be chosen from the set of alpha-numeric characters.

Usage

From source file:org.apache.atlas.discovery.DataSetLineageServiceTest.java

private String random() {
    return RandomStringUtils.randomAlphanumeric(5);
}

From source file:org.apache.atlas.falcon.hook.FalconHookIT.java

private String random() {
    return RandomStringUtils.randomAlphanumeric(10);
}

From source file:org.apache.atlas.hive.HiveITBase.java

protected String random() {
    return RandomStringUtils.randomAlphanumeric(10);
}

From source file:org.apache.atlas.kafka.KafkaNotificationTest.java

@BeforeClass
public void setup() throws Exception {
    Configuration properties = ApplicationProperties.get();
    properties.setProperty("atlas.kafka.data", "target/" + RandomStringUtils.randomAlphanumeric(5));

    kafkaNotification = new KafkaNotification(properties);
    kafkaNotification.start();/*from w  ww .  ja  v a2  s  . co m*/
}

From source file:org.apache.atlas.notification.NotificationHookConsumerKafkaTest.java

protected String randomString() {
    return RandomStringUtils.randomAlphanumeric(10);
}

From source file:org.apache.atlas.repository.audit.AuditRepositoryTestBase.java

private String rand() {
    return RandomStringUtils.randomAlphanumeric(10);
}

From source file:org.apache.atlas.repository.graph.GraphBackedMetadataRepositoryTest.java

private String randomString() {
    return RandomStringUtils.randomAlphanumeric(10);
}

From source file:org.apache.atlas.repository.graph.GraphBackedSearchIndexerTest.java

@Test
public void verifyUserDefinedTypeIndex() throws AtlasException {
    AtlasGraph graph = TestUtils.getGraph();
    AtlasGraphManagement managementSystem = graph.getManagementSystem();
    try {//from  ww  w . ja  v  a2s  .  c o  m
        TypeSystem typeSystem = TypeSystem.getInstance();

        String enumName = "randomEnum" + RandomStringUtils.randomAlphanumeric(10);
        EnumType managedType = typeSystem.defineEnumType(enumName, new EnumValue("randomEnumValue", 0));

        HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = createClassTypeDef("Database",
                "Database type description", null,
                TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE),
                TypesUtil.createRequiredAttrDef("managedType", managedType));

        ClassType databaseType = typeSystem.defineClassType(databaseTypeDefinition);
        graphBackedSearchIndexer.onAdd(Arrays.asList(databaseType));

        verifySystemCompositeIndex(managementSystem, "Database.name" + Constants.ENTITY_TYPE_PROPERTY_KEY,
                false);
        verifyVertexIndexContains(managementSystem, "Database.name" + Constants.ENTITY_TYPE_PROPERTY_KEY);
        verifySystemCompositeIndex(managementSystem, "Database.name" + Constants.SUPER_TYPES_PROPERTY_KEY,
                false);

        verifyVertexIndexContains(managementSystem, "Database.managedType");
    } finally {
        //search indexer uses its own titan management transaction
        managementSystem.rollback();
    }
}

From source file:org.apache.atlas.repository.store.graph.v1.AtlasEntityStoreV1Test.java

@Test(enabled = false)
//Titan doesn't allow some reserved chars in property keys. Verify that atlas encodes these
//See GraphHelper.encodePropertyKey()
//TODO : Failing in typedef creation
public 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>() {
        {//from  w  w w .  j  a v  a2 s  .c om
            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);
}

From source file:org.apache.atlas.repository.store.graph.v1.AtlasEntityStoreV1Test.java

@Test
public void testPartialUpdateAttr() throws Exception {
    //Update optional attribute

    init();/*from   w w w .j  av  a2  s. c om*/

    AtlasEntity dbEntity = new AtlasEntity(TestUtilsV2.DATABASE_TYPE);
    dbEntity.setAttribute("name", RandomStringUtils.randomAlphanumeric(10));
    dbEntity.setAttribute("description", "us db");
    dbEntity.setAttribute("isReplicated", false);
    dbEntity.setAttribute("created", "09081988");
    dbEntity.setAttribute("namespace", "db namespace");
    dbEntity.setAttribute("cluster", "Fenton_Cluster");
    dbEntity.setAttribute("colo", "10001");

    EntityStream dbStream = new AtlasEntityStream(new AtlasEntitiesWithExtInfo(dbEntity));
    EntityMutationResponse response = entityStore.createOrUpdate(dbStream, false);
    AtlasEntityHeader dbHeader = response.getFirstEntityCreated();
    AtlasEntity createdDbEntity = getEntityFromStore(dbHeader);

    // update the db entity
    dbEntity = new AtlasEntity(TestUtilsV2.DATABASE_TYPE);
    dbEntity.setGuid(createdDbEntity.getGuid());
    // dbEntity.setAttribute("name", createdDbEntity.getAttribute("name"));
    // dbEntity.setAttribute("description", "another db"); // required attr
    dbEntity.setAttribute("created", "08151947"); // optional attr
    dbEntity.setAttribute("isReplicated", true); // optional attr

    dbStream = new AtlasEntityStream(new AtlasEntitiesWithExtInfo(dbEntity));

    // fail full update if required attributes are not specified.
    try {
        entityStore.createOrUpdate(dbStream, false);
    } catch (AtlasBaseException ex) {
        Assert.assertEquals(ex.getAtlasErrorCode(), AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS);
    }

    // do partial update without providing required attributes
    dbStream.reset();
    response = entityStore.createOrUpdate(dbStream, true);
    dbHeader = response.getFirstEntityPartialUpdated();
    AtlasEntity updatedDbEntity = getEntityFromStore(dbHeader);

    assertEquals(updatedDbEntity.getAttribute("name"), createdDbEntity.getAttribute("name"));
    assertEquals(updatedDbEntity.getAttribute("description"), createdDbEntity.getAttribute("description"));
    assertEquals(updatedDbEntity.getAttribute("isReplicated"), true);
    assertEquals(updatedDbEntity.getAttribute("created"), "08151947");
    assertEquals(updatedDbEntity.getAttribute("namespace"), createdDbEntity.getAttribute("namespace"));
    assertEquals(updatedDbEntity.getAttribute("cluster"), createdDbEntity.getAttribute("cluster"));
    assertEquals(updatedDbEntity.getAttribute("colo"), createdDbEntity.getAttribute("colo"));

    // create a new table type
    AtlasEntity tblEntity = new AtlasEntity(TABLE_TYPE);
    tblEntity.setAttribute("name", RandomStringUtils.randomAlphanumeric(10));
    tblEntity.setAttribute("type", "type");
    tblEntity.setAttribute("tableType", "MANAGED");
    tblEntity.setAttribute("database", AtlasTypeUtil.getAtlasObjectId(updatedDbEntity));

    // create new column entity
    AtlasEntity col1 = TestUtilsV2.createColumnEntity(tblEntity);
    AtlasEntity col2 = TestUtilsV2.createColumnEntity(tblEntity);
    col1.setAttribute(TestUtilsV2.NAME, "col1");
    col2.setAttribute(TestUtilsV2.NAME, "col2");

    List<AtlasObjectId> columns = new ArrayList<>();
    columns.add(AtlasTypeUtil.getAtlasObjectId(col1));
    columns.add(AtlasTypeUtil.getAtlasObjectId(col2));

    tblEntity.setAttribute(TestUtilsV2.COLUMNS_ATTR_NAME, columns);

    AtlasEntitiesWithExtInfo tableEntityInfo = new AtlasEntitiesWithExtInfo(tblEntity);
    tableEntityInfo.addReferredEntity(col1.getGuid(), col1);
    tableEntityInfo.addReferredEntity(col2.getGuid(), col2);

    EntityStream tblStream = new AtlasEntityStream(tableEntityInfo);
    response = entityStore.createOrUpdate(tblStream, false);
    AtlasEntityHeader tblHeader = response.getFirstEntityCreated();
    AtlasEntity createdTblEntity = getEntityFromStore(tblHeader);

    columns = (List<AtlasObjectId>) createdTblEntity.getAttribute(TestUtilsV2.COLUMNS_ATTR_NAME);
    assertEquals(columns.size(), 2);

    // update - add 2 more columns to table
    AtlasEntity col3 = TestUtilsV2.createColumnEntity(createdTblEntity);
    col3.setAttribute(TestUtilsV2.NAME, "col3");
    col3.setAttribute("description", "description col3");

    AtlasEntity col4 = TestUtilsV2.createColumnEntity(createdTblEntity);
    col4.setAttribute(TestUtilsV2.NAME, "col4");
    col4.setAttribute("description", "description col4");

    columns.clear();
    columns.add(AtlasTypeUtil.getAtlasObjectId(col3));
    columns.add(AtlasTypeUtil.getAtlasObjectId(col4));

    tblEntity = new AtlasEntity(TABLE_TYPE);
    tblEntity.setGuid(createdTblEntity.getGuid());
    tblEntity.setAttribute(TestUtilsV2.COLUMNS_ATTR_NAME, columns);

    tableEntityInfo = new AtlasEntitiesWithExtInfo(tblEntity);
    tableEntityInfo.addReferredEntity(col3.getGuid(), col3);
    tableEntityInfo.addReferredEntity(col4.getGuid(), col4);

    tblStream = new AtlasEntityStream(tableEntityInfo);
    response = entityStore.createOrUpdate(tblStream, true);
    tblHeader = response.getFirstEntityPartialUpdated();
    AtlasEntity updatedTblEntity = getEntityFromStore(tblHeader);

    columns = (List<AtlasObjectId>) updatedTblEntity.getAttribute(TestUtilsV2.COLUMNS_ATTR_NAME);
    // deleted columns are included in the attribute; hence use >=
    assertTrue(columns.size() >= 2);
}