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

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

Introduction

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

Prototype

public static String randomAscii(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 characters whose ASCII value is between 32 and 126 (inclusive).

Usage

From source file:org.apache.sling.settings.impl.SlingSettingsServiceImplTest.java

@Test
public void testGetSlingIdFromTooShortData() throws IOException {
    final String data = RandomStringUtils.randomAscii(8); // 8 byte long random String
    SlingIdUtil.writeSlingId(slingIdFile, data);
    final SlingSettingsService slingSettingsService = createSlingSettingsService(slingIdFile, optionsFile);

    final String slingId = slingSettingsService.getSlingId();
    assertNotNull(slingId);/*from  ww w .j a  v a2  s. co m*/
}

From source file:org.apache.tez.runtime.library.output.TestOnFileUnorderedKVOutput.java

@Test(timeout = 30000)
@SuppressWarnings("unchecked")
public void testWithPipelinedShuffle() throws Exception {
    Configuration conf = new Configuration();
    conf.set(TezRuntimeConfiguration.TEZ_RUNTIME_KEY_CLASS, Text.class.getName());
    conf.set(TezRuntimeConfiguration.TEZ_RUNTIME_VALUE_CLASS, IntWritable.class.getName());
    conf.setBoolean(TezRuntimeConfiguration.TEZ_RUNTIME_PIPELINED_SHUFFLE_ENABLED, true);
    conf.setBoolean(TezRuntimeConfiguration.TEZ_RUNTIME_ENABLE_FINAL_MERGE_IN_OUTPUT, false);

    conf.setInt(TezRuntimeConfiguration.TEZ_RUNTIME_UNORDERED_OUTPUT_BUFFER_SIZE_MB, 1);

    TezSharedExecutor sharedExecutor = new TezSharedExecutor(conf);
    OutputContext outputContext = createOutputContext(conf, sharedExecutor);

    UnorderedKVOutput kvOutput = new UnorderedKVOutput(outputContext, 1);

    List<Event> events = null;
    events = kvOutput.initialize();/*from  w  w  w  .ja v  a 2 s.  c om*/
    kvOutput.start();
    assertTrue(events != null && events.size() == 0);

    KeyValueWriter kvWriter = kvOutput.getWriter();
    for (int i = 0; i < 500; i++) {
        kvWriter.write(new Text(RandomStringUtils.randomAscii(10000)), new IntWritable(i));
    }

    events = kvOutput.close();
    //When pipelining is on, all events are sent out within writer itself.
    assertTrue(events != null && events.size() == 0);

    //ensure that data is sent via outputContext.
    ArgumentCaptor<List> eventsCaptor = ArgumentCaptor.forClass(List.class);
    verify(outputContext, atLeast(1)).sendEvents(eventsCaptor.capture());
    events = eventsCaptor.getValue();

    CompositeDataMovementEvent dmEvent = (CompositeDataMovementEvent) events.get(1);
    assertEquals("Invalid source index", 0, dmEvent.getSourceIndexStart());

    DataMovementEventPayloadProto shufflePayload = DataMovementEventPayloadProto
            .parseFrom(ByteString.copyFrom(dmEvent.getUserPayload()));

    assertTrue(shufflePayload.hasLastEvent());

    assertFalse(shufflePayload.hasEmptyPartitions());
    assertEquals(shufflePort, shufflePayload.getPort());
    assertEquals("localhost", shufflePayload.getHost());
    sharedExecutor.shutdownNow();
}

From source file:org.artifactory.storage.db.fs.itest.dao.PropertiesDaoTest.java

public void trimLongPropertyValue() throws SQLException {
    if (storageProperties.getDbType() == DbType.MSSQL) {
        return; // RTFACT-5768
    }/*ww w .j  a  v  a 2  s .  c o m*/
    String longValue = RandomStringUtils.randomAscii(4020);
    propsDao.create(new NodeProperty(876, 15, "trimeme", longValue));
    List<NodeProperty> nodeProperties = propsDao.getNodeProperties(15);
    assertThat(nodeProperties.size()).isEqualTo(1);
    String trimmedValue = nodeProperties.get(0).getPropValue();
    assertThat(trimmedValue).hasSize(4000);
    assertThat(longValue).startsWith(trimmedValue);
}

From source file:org.encuestame.business.service.AbstractSurveyService.java

/**
 * Public Tweet Poll (OAuth method).//from w w w  . jav a 2s.co  m
 * @param tweetText tweet text
 * @return status of tweet
 * @throws EnMeException exception
 */
public TweetPublishedMetadata publicTweetPoll(final String tweetText, final SocialAccount socialAccount,
        final Set<HashTag> hashtags) throws EnMeException {
    TweetPublishedMetadata published = new TweetPublishedMetadata();
    log.debug("publicTweetPoll:{ " + tweetText);
    if (socialAccount.getAccounType().equals(SocialProvider.TWITTER)) {
        log.debug("Publish on TWITTER");
        final TwitterAPIOperations twitterAPIOperations = new TwitterAPITemplate(
                EnMePlaceHolderConfigurer.getProperty("twitter.oauth.consumerSecret"),
                EnMePlaceHolderConfigurer.getProperty("twitter.oauth.consumerKey"), socialAccount);
        try {
            published = twitterAPIOperations.updateStatus(tweetText);
        } catch (Exception e) {
            log.error(e);
            //e.printStackTrace();
        }
    } else if (socialAccount.getAccounType().equals(SocialProvider.IDENTICA)) {
        log.debug("Publish on IDENTICA");
        final IdenticaAPIOperations identicaAPIOperations = new IdenticaAPITemplate(
                EnMePlaceHolderConfigurer.getProperty("identica.consumer.key"),
                EnMePlaceHolderConfigurer.getProperty("identica.consumer.secret"),
                socialAccount.getAccessToken(), socialAccount.getSecretToken());
        try {
            log.debug("Publish on Identica............>");
            published = identicaAPIOperations.updateStatus(tweetText);
            log.debug("Publish on Identica...... " + published);
        } catch (Exception e) {
            published.setDatePublished(Calendar.getInstance().getTime());
            log.error(e);
            ///e.printStackTrace();
        }
    } else if (socialAccount.getAccounType().equals(SocialProvider.PLURK)) {
        log.debug("Publish on PLURK");
        final PlurkAPIOperations tumblrAPIOperations = new PlurkAPITemplate(
                EnMePlaceHolderConfigurer.getProperty("plurk.consumer.key"),
                EnMePlaceHolderConfigurer.getProperty("plurk.consumer.secret"), socialAccount.getAccessToken(),
                socialAccount.getSecretToken());
        try {
            log.debug("Publish on Identica............>");
            published = tumblrAPIOperations.updateStatus(tweetText);
            log.debug("Publish on Identica...... " + published);
        } catch (Exception e) {
            published.setDatePublished(Calendar.getInstance().getTime());
            log.error(e);
            //e.printStackTrace();
        }
    } else if (socialAccount.getAccounType().equals(SocialProvider.TUMBLR)) {
        log.debug("Publish on TUMBLR");
        final TumblrAPIOperations tumblrAPIOperations = new TumblrAPITemplate(
                EnMePlaceHolderConfigurer.getProperty("tumblr.consumer.key"),
                EnMePlaceHolderConfigurer.getProperty("tumblr.consumer.secret"), socialAccount.getAccessToken(),
                socialAccount.getSecretToken());
        try {
            log.debug("Publish on TUMBLR............>");
            published = tumblrAPIOperations.updateStatus(tweetText, socialAccount, hashtags);
            log.debug("Publish on TUMBLR...... " + published);
        } catch (Exception e) {
            published.setDatePublished(Calendar.getInstance().getTime());
            log.error(e);
            //e.printStackTrace();
        }
    } else if (socialAccount.getAccounType().equals(SocialProvider.FACEBOOK)) {
        log.debug("Publish on FACEBOOK");
        FacebookAPIOperations facebookAPIOperations = new FacebookAPITemplate(socialAccount.getAccessToken());
        try {
            log.debug("Publish on FACEBOOK............>");
            published = facebookAPIOperations.updateStatus(tweetText);
            log.debug("Publish on FACEBOOK...... " + published);
            published.setDatePublished(Calendar.getInstance().getTime());
        } catch (HttpClientErrorException e) {
            log.error("-----------------------FACEBOOK EXPIRED TOKEN----------------------- 1");
            log.error(e.getStatusCode());
            log.error(e.getResponseBodyAsString());
            log.error(e.getStatusText());
            published.setDatePublished(Calendar.getInstance().getTime());
            // refresh token point.
            //offline_access scope permission is enabled by default . In this case
            //https://developers.facebook.com/docs/authentication/permissions/
            log.error("-----------------------FACEBOOK EXPIRED TOKEN----------------------- 2");
            //e.printStackTrace();
        } catch (Exception e) {
            published.setDatePublished(Calendar.getInstance().getTime());
            log.error(e);
            //e.printStackTrace();
        }
    } else if (socialAccount.getAccounType().equals(SocialProvider.LINKEDIN)) {
        log.debug("Publish on LinkedIn");
        LinkedInAPIOperations linkedInAPIOperations = new LinkedInAPITemplate(
                EnMePlaceHolderConfigurer.getProperty("linkedIn.oauth.api.key"),
                EnMePlaceHolderConfigurer.getProperty("linkedIn.oauth.api.secret"),
                socialAccount.getAccessToken(), socialAccount.getSecretToken());
        try {
            log.debug("Publish on LinkedIn 1............>");
            published = linkedInAPIOperations.updateStatus(tweetText);
            published.setTextTweeted(tweetText);
            published.setDatePublished(Calendar.getInstance().getTime());
            published.setTweetId(RandomStringUtils.randomAscii(15));
            log.debug("Publish on LinkedIn 2...... " + published);
        } catch (Exception e) {
            published.setDatePublished(Calendar.getInstance().getTime());
            log.error(e);
            //e.printStackTrace();
        }
    }
    if (published != null) {
        log.debug("publicTweetPoll:s " + published.toString());
    }
    return published;
}

From source file:org.encuestame.mvc.controller.AbstractBaseOperations.java

/**
 * Create question with answers.//from w  w  w.  j  a va2  s .co m
 * @param questionName question description
 * @param user {@link UserAccount} owner.
 * @return {@link Question}
 * @throws EnMeException exception
 */
public Question createQuestion(final String questionName, final String[] answers, final UserAccount user)
        throws EnMeException {
    final QuestionBean questionBean = new QuestionBean();
    questionBean.setQuestionName(questionName);
    questionBean.setUserId(user.getUid());
    // setting Answers.
    for (int row = 0; row < answers.length; row++) {
        final QuestionAnswerBean answer = new QuestionAnswerBean();
        answer.setAnswers(answers[row].trim());
        answer.setAnswerHash(RandomStringUtils.randomAscii(5));
        questionBean.getListAnswers().add(answer);
    }
    final Question questionDomain = getSurveyService().createQuestion(questionBean);
    return questionDomain;
}

From source file:org.encuestame.test.config.AbstractBase.java

/**
 * Create project./* w  w w. java2 s.c o m*/
 * @param name Project's name
 * @param descProject Project Description
 * @param infoProject Informations's Project
 * @param user user
 * @return {@link Project}
 */
public Project createProject(final String name, final String descProject, final String infoProject,
        final Account user) {
    final Project project = new Project();
    final Calendar start = Calendar.getInstance();
    final Calendar end = Calendar.getInstance();
    end.add(Calendar.MONTH, 4);
    project.setProjectDateFinish(end.getTime());
    project.setProjectDateStart(start.getTime());
    project.setProjectInfo(infoProject);
    project.setProjectName(RandomStringUtils.randomAscii(4) + "_name");
    project.setLead(createUserAccount("tes-" + RandomStringUtils.randomAscii(4), createAccount()));
    project.setProjectDescription(descProject);
    project.setProjectStatus(Status.ACTIVE);
    project.setPriority(Priority.MEDIUM);
    project.setHideProject(Boolean.FALSE);
    project.setPublished(Boolean.TRUE);
    project.setUsers(user);
    getProjectDaoImp().saveOrUpdate(project);
    return project;
}

From source file:org.encuestame.test.config.AbstractBase.java

/**
 * Create Fast TweetPoll Votes.//from  w  ww.j  a v  a 2  s .c  o m
 * @return tweet poll
 */
public TweetPoll createFastTweetPollVotes() {
    final UserAccount secondary = createUserAccount("jhon-" + RandomStringUtils.randomAscii(4),
            createAccount());
    final Question question = createQuestion("who I am?", "");
    final QuestionAnswer questionsAnswers1 = createQuestionAnswer("yes", question, "12345");
    final QuestionAnswer questionsAnswers2 = createQuestionAnswer("no", question, "12346");
    final TweetPoll tweetPoll = createPublishedTweetPoll(secondary.getAccount(), question);
    final TweetPollSwitch pollSwitch1 = createTweetPollSwitch(questionsAnswers1, tweetPoll);
    final TweetPollSwitch pollSwitch2 = createTweetPollSwitch(questionsAnswers2, tweetPoll);
    createTweetPollResult(pollSwitch1, "192.168.0.1");
    createTweetPollResult(pollSwitch1, "192.168.0.2");
    createTweetPollResult(pollSwitch2, "192.168.0.3");
    createTweetPollResult(pollSwitch2, "192.168.0.4");
    //log.info("tw "+tweetPoll);
    return tweetPoll;
}

From source file:org.encuestame.test.persistence.config.AbstractBase.java

/**
 * Create Fast TweetPoll Votes.// ww  w  .ja v a 2  s . co m
 * @return tweet poll
 */
public TweetPoll createFastTweetPollVotes() {
    final UserAccount secondary = createUserAccount("jhon-" + RandomStringUtils.randomAscii(4),
            createAccount());
    final Question question = createQuestion("who I am?", "");
    final QuestionAnswer questionsAnswers1 = createQuestionAnswer("yes", question, "12345");
    final QuestionAnswer questionsAnswers2 = createQuestionAnswer("no", question, "12346");
    final TweetPoll tweetPoll = createPublishedTweetPoll(secondary, question);
    final TweetPollSwitch pollSwitch1 = createTweetPollSwitch(questionsAnswers1, tweetPoll);
    final TweetPollSwitch pollSwitch2 = createTweetPollSwitch(questionsAnswers2, tweetPoll);
    createTweetPollResult(pollSwitch1, "192.168.0.1");
    createTweetPollResult(pollSwitch1, "192.168.0.2");
    createTweetPollResult(pollSwitch2, "192.168.0.3");
    createTweetPollResult(pollSwitch2, "192.168.0.4");
    //log.info("tw "+tweetPoll);
    return tweetPoll;
}

From source file:org.encuestame.test.persistence.dao.TestNotificationDao.java

/**
 * Before start.//from   w  w w.  j  a v  a  2  s  .c  om
 */
@Before
public void initService() {
    this.account = createAccount();
    this.userAccount = createUserAccount("user 1", this.account);
    for (int i = 0; i < 10; i++) {
        createNotification(RandomStringUtils.randomAscii(100), account, NotificationEnum.TWEETPOL_CREATED,
                false, calDate.getTime());
    }
    calDate.add(Calendar.HOUR, 3);
    for (int i = 0; i < 10; i++) {
        createNotification(RandomStringUtils.randomAscii(100), account, NotificationEnum.TWEETPOL_CREATED, true,
                calDate.getTime());
    }
}

From source file:org.encuestame.test.persistence.domain.TestHibernateDomains.java

/**
* Test Questions Domain.//from   w  w w .  ja va  2  s .  c  om
**/
@Test
public void testQuestions() {
    final Question questions = new Question();
    questions.setQuestion("What is your Name");
    questions.setQidKey("2");
    questions.setHits(0L);
    questions.setSharedQuestion(Boolean.FALSE);
    questions.setSlugQuestion(" " + RandomStringUtils.randomAscii(10));
    questions.getQuestionColettions().add(createQuestionCollect("options"));
    questions.setAccountQuestion(createAccount());
    getQuestionDaoImp().saveOrUpdate(questions);
    assertNotNull(questions.getQid());

}