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

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

Introduction

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

Prototype

public static String randomAlphabetic(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 alphabetic characters.

Usage

From source file:org.elasticstore.server.integration.fixtures.Fixtures.java

public static String randomName() {
    return RandomStringUtils.randomAlphabetic(16);
}

From source file:org.encuestame.core.test.integration.GatewayTestCase.java

@Test
@Repeat(2)//  w  w  w  .  j a v  a 2s.c om
public void testTransformation() {
    Assert.assertNotNull(this.twitterAdapter);

    this.twitterChannel.send(new Message<String>() {
        public MessageHeaders getHeaders() {
            return new MessageHeaders(new HashMap<String, Object>());
        }

        public String getPayload() {
            return "original www.xebia.com message http://www.xebia.com "
                    + RandomStringUtils.randomAlphabetic(3);
        }
    });
    log.debug(errorChannel.getQueueSize());

    this.twitterAdapter
            .publishTweet("text http://blog.jotadeveloper.com " + RandomStringUtils.randomAlphabetic(3));
}

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

/**
 * Validate items based on context.//from   www .  j av  a2  s  .com
 * @param context could be signup, update profile or another one.
 * @param type
 * @param value
 * @return
 */
protected Map<String, Object> validate(final String context, final String type, String value,
        final HttpServletRequest request) {
    value = value == null ? "" : value;
    final Map<String, Object> jsonResponse = new HashMap<String, Object>();
    final ValidateOperations validateOperations = new ValidateOperations(getSecurityService());
    boolean valid = false;
    if ("email".equals(type)) {
        if (value.isEmpty() || value.length() < ValidateOperations.MIN_EMAIL_LENGTH) {
            log.debug("validate email emtpy");
            jsonResponse.put("msg", getMessage("secure.email.emtpy", request, null));
        } else {
            valid = validateOperations.validateUserEmail(value, null);
            log.debug("validate EMAIL" + valid);
            if (valid) {
                jsonResponse.put("msg", getMessage("secure.email.valid", request, null));
            } else {
                jsonResponse.put("msg", getMessage("secure.email.notvalid", request, null));
            }
        }
    } else if ("username".equals(type)) {
        valid = validateOperations.validateUsername(value, null);
        if (value.isEmpty() || value.length() < ValidateOperations.MIN_USERNAME_LENGTH) {
            log.debug("validate username emtpy");
            jsonResponse.put("msg", getMessage("secure.username.empty", request, null));
        } else {
            log.debug("validate username NO emtpy");
            if (!valid) {
                jsonResponse.put("msg", getMessage("secure.user.notvalid", request, null));
                final List<String> suggestions = new ArrayList<String>();
                for (int i = 0; i < 5; i++) {
                    suggestions.add(
                            value + RandomStringUtils.randomAlphabetic(ValidateOperations.LENGTH_RANDOM_VALUE));
                }
                jsonResponse.put("suggestions", suggestions);
            } else {
                jsonResponse.put("msg", getMessage("secure.username.valid", request, null));
            }
            jsonResponse.put("valid", valid);
        }
    } else if ("realName".equals(type)) {
        if (value.isEmpty()) {
            valid = false;
            jsonResponse.put("msg", getMessage("secure.realName.empty", request, null));
        } else {
            valid = true;
            jsonResponse.put("msg", getMessage("secure.realName.valid", request, null));
        }
    } else {
        jsonResponse.put("msg", getMessage("secure.type.not.valid", request, null));
    }
    jsonResponse.put("valid", valid);
    jsonResponse.put("color", "#RRR");
    return jsonResponse;
}

From source file:org.encuestame.mvc.test.json.JsonUsersControllerTestCase.java

/**
 *
 * @throws ServletException//from   w w w. j  a  v  a 2s  .co  m
 * @throws IOException
 */
@Category(InternetTest.class)
@Test
public void testCreateUser() throws ServletException, IOException {
    initService("/api/admon/create-user.json", MethodJson.POST);
    setParameter("newUsername", RandomStringUtils.randomAlphabetic(10));
    setParameter("newEmailUser", RandomStringUtils.randomAlphabetic(10) + "@demo.org");
    final JSONObject response = callJsonService();
    //System.out.println(response);
    final JSONObject success = getSucess(response);
    final String ok = (String) success.get("userAdded");
    Assert.assertNotNull(ok);
    //Assert.assertEquals(1, polls.size());
}

From source file:org.encuestame.rest.api.test.json.TweetPollJsonControllerTestCase.java

/**
 * Test publish tweetpoll.//from   w ww  .  j a va 2 s .  c  o  m
 * @throws ServletException
 * @throws IOException
 */
@Test
public void testPublishTweetPoll() throws ServletException, IOException {
    String questionString = "Real Madrid VS Barcelona? _ " + RandomStringUtils.randomAlphabetic(7);
    final Question question = createQuestion(questionString, userAccount.getAccount());
    final TweetPoll tp1 = createTweetPollPublicated(Boolean.TRUE, Boolean.TRUE, new Date(), userAccount,
            question);

    final Long tPollId = tp1.getTweetPollId();
    final SocialAccount social1 = createDefaultSettedSocialAccount(getSpringSecurityLoggedUserAccount());
    this.tp1.setPublishTweetPoll(Boolean.FALSE);
    getTweetPoll().saveOrUpdate(tp1);
    initService("/api/survey/tweetpoll/publish", MethodJson.POST);
    setParameter("id", tPollId.toString());
    setParameter("twitterAccounts", social1.getId().toString());
    final JSONObject response = callJsonService();
    final JSONObject sucess = getSucess(response);
    final JSONArray items = (JSONArray) sucess.get("socialPublish");
    Assert.assertNotNull(items);
    Assert.assertEquals(items.size(), 1);
    final JSONObject itemsAnswer = (JSONObject) items.get(0);
    Assert.assertEquals(itemsAnswer.get("textTweeted").toString(), questionString);
}

From source file:org.encuestame.rest.api.test.json.TweetPollJsonControllerTestCase.java

/**
 *
 * @throws ServletException/*  w  w w .  j ava2s . c  om*/
 * @throws IOException
 */
@Test
public void testTweetPollAutosave() throws ServletException, IOException {
    // step - 1: create tweetpoll
    String questionString = "Real Madrid VS Barcelona? _ " + RandomStringUtils.randomAlphabetic(7);
    tp1.setPublishTweetPoll(Boolean.FALSE);
    getTweetPoll().saveOrUpdate(tp1);
    initService("/api/survey/tweetpoll/autosave", MethodJson.POST);
    //setParameter("tweetPollId", tp1.getTweetPollId().toString());
    setParameter("question", questionString);
    setParameter("scheduled", "false");
    setParameter("liveResults", "false");
    setParameter("captcha", "false");
    setParameter("limitVotes", "false");
    setParameter("repeatedVotes", "false");
    setParameter("maxLimitVotes", "100");
    setParameter("maxRepeatedVotes", "10");
    setParameter("resumeLiveResults", "false");
    final JSONObject response = callJsonService();
    final JSONObject sucess = getSucess(response);
    final JSONObject tweetpoll = (JSONObject) sucess.get("tweetPoll");
    Assert.assertNotNull(tweetpoll);
    final Long id = (Long) tweetpoll.get("id");
    Assert.assertNotNull(id);
    final JSONObject question = (JSONObject) tweetpoll.get("question");
    Assert.assertEquals(question.get("question_name"), questionString);
    // step 2 : update the question
    initService("/api/survey/tweetpoll/autosave", MethodJson.POST);
    setParameter("tweetPollId", id.toString());
    setParameter("question", questionString + "_change");
    final JSONObject response2 = callJsonService();
    final JSONObject sucess2 = getSucess(response2);
    final JSONObject tweetpoll2 = (JSONObject) sucess2.get("tweetPoll");
    Assert.assertNotNull(tweetpoll2);
    final JSONObject question2 = (JSONObject) tweetpoll2.get("question");
    Assert.assertEquals(question2.get("question_name"), questionString + "_change");
    // step 3: change some properties
    initService("/api/survey/tweetpoll/autosave", MethodJson.POST);
    setParameter("tweetPollId", id.toString());
    setParameter("question", questionString);
    setParameter("repeatedVotes", "true");
    setParameter("maxLimitVotes", "100");
    setParameter("maxRepeatedVotes", "1000");
    final JSONObject response3 = callJsonService();
    final JSONObject sucess3 = getSucess(response3);
    final JSONObject tweetpoll3 = (JSONObject) sucess3.get("tweetPoll");
    Assert.assertNotNull(tweetpoll3);
    final JSONObject question3 = (JSONObject) tweetpoll3.get("question");
    Assert.assertEquals(question3.get("question_name"), questionString);
    final Long maxRepeatedVotes = (Long) tweetpoll3.get("maxRepeatedVotes");
    final Long limitVotes = (Long) tweetpoll3.get("limitVotes");
    Assert.assertEquals(maxRepeatedVotes.longValue(), 1000);
    Assert.assertEquals(limitVotes.longValue(), 100);

}

From source file:org.encuestame.test.business.config.AbstractSpringSecurityContext.java

/**
 *
 */
public UserAccount quickLogin() {
    return this.quickLogin("quick_user_" + RandomStringUtils.randomAlphabetic(3));
}

From source file:org.encuestame.test.business.service.TestTweetPollService.java

/**
 * Before.//  w  ww.j ava2 s.c o  m
 */
@Before
public void serviceInit() {
    this.user = createUser("testEncuesta", "testEncuesta123");
    this.userAccount = getSpringSecurityLoggedUserAccount();
    this.question = createQuestion("Why the sky is blue?", "html");
    createQuestionAnswer("Yes", this.question, "SSSA");
    // this.questionBean = createUnitQuestionBean("", 1L, 1L, listAnswers,
    // pattern)
    answers = new ArrayList<QuestionAnswerBean>();
    answers.add(createAnswersBean("2DFAAS", "Yes", question.getQid()));
    answers.add(createAnswersBean("4DSWGK", "No", question.getQid()));
    questionBean = createUnitQuestionBean("questionName", 1L, this.user.getUid(), this.answers);
    this.tweetText = RandomStringUtils.randomAlphabetic(5);
    this.socialBeans = this.createSocialAccounts();
    this.creationDate = new DateTime();
    request = new MockHttpServletRequest();
    request.addPreferredLocale(Locale.ENGLISH);

    this.folder = createTweetPollFolder("Folder 1", getSpringSecurityLoggedUserAccount());
}

From source file:org.encuestame.test.business.service.TestTweetPollService.java

/**
 * Test Public TweetPoll on multiples social networks.
 */// w w w . j a  va 2  s  .c  o  m
@Category(DefaultTest.class)
@Test
public void testPublicMultiplesTweetAccounts() {

    final TweetPoll tweetPoll = createTweetPollPublicated(true, true, new Date(), this.userAccount, question);
    tweetPollService.publishMultiplesOnSocialAccounts(this.socialBeans, tweetPoll,
            RandomStringUtils.randomAlphabetic(7), TypeSearchResult.TWEETPOLL, null, null);
    final TweetPoll tweet = getTweetPoll().getTweetPollById(tweetPoll.getTweetPollId());
    assertNotNull(tweet);
    final List<LinksSocialBean> linksPublished = getTweetPollService().getTweetPollLinks(tweetPoll, null, null,
            TypeSearchResult.TWEETPOLL);
    assertEquals("Should be equals", 1, linksPublished.size());
}

From source file:org.wso2.appmanager.integration.restapi.utils.RESTAPITestUtil.java

/**
 * This method is used to register OAuth Application
 *
 * @param keyMangerUrl url of the key manger
 * @return map which contains the consumer key and secret
 * @throws AppManagerIntegrationTestException if it fails to register OAuth Application
 */// w  ww.  j a  v  a 2s.  c  o  m
private Map<String, String> registerOAuthApplication(String keyMangerUrl)
        throws AppManagerIntegrationTestException {

    String dcrEndpointURL = keyMangerUrl + RESTAPITestConstants.CLIENT_REGISTRATION_URL;

    //use a random name for client to avoid conflicts in application(s)
    String randomClientName = RandomStringUtils.randomAlphabetic(5);
    String applicationRequestBody = "{\n" + "\"callbackUrl\": \"www.google.lk\",\n" + "\"clientName\": \""
            + randomClientName + "\",\n" + "\"tokenScope\": \"Production\",\n" + "\"owner\": \"admin\",\n"
            + "\"grantType\": \"password refresh_token\",\n" + "\"saasApp\": true\n" + "}";

    Map<String, String> dcrRequestHeaders = new HashMap<String, String>();
    Map<String, String> dataMap = new HashMap<String, String>();

    try {

        //Basic Auth header is used for only to get token
        byte[] encodedBytes = Base64.encodeBase64(RESTAPITestConstants.BASIC_AUTH_HEADER.getBytes("UTF-8"));
        dcrRequestHeaders.put(RESTAPITestConstants.AUTHORIZATION_KEY,
                "Basic " + new String(encodedBytes, "UTF-8"));

        //Set content type as its mandatory
        dcrRequestHeaders.put(RESTAPITestConstants.CONTENT_TYPE, RESTAPITestConstants.APPLICATION_JSON_CONTENT);
        JSONObject clientRegistrationResponse = new JSONObject(
                HttpRequestUtil.doPost(new URL(dcrEndpointURL), applicationRequestBody, dcrRequestHeaders));
        String consumerKey = new JSONObject(
                clientRegistrationResponse.getString(RESTAPITestConstants.DATA_SECTION))
                        .get(RESTAPITestConstants.CLIENT_ID).toString();
        String consumerSecret = new JSONObject(
                clientRegistrationResponse.getString(RESTAPITestConstants.DATA_SECTION))
                        .get(RESTAPITestConstants.CLIENT_SECRET).toString();

        //give 2 second duration to create consumer key and consumer secret
        Thread.sleep(2000);
        dataMap.put(RESTAPITestConstants.CONSUMER_KEY, consumerKey);
        dataMap.put(RESTAPITestConstants.CONSUMER_SECRET, consumerSecret);

    } catch (UnsupportedEncodingException unsupportedEncodingException) {
        log.error("Header encoding was unsuccessful while registering application.",
                unsupportedEncodingException);
        throw new AppManagerIntegrationTestException(
                "Header encoding was unsuccessful while registering application.",
                unsupportedEncodingException);
    } catch (MalformedURLException malformedURLException) {
        log.error("Error in getting the DCR endpoint URL.", malformedURLException);
        throw new AppManagerIntegrationTestException("Error in getting the DCR endpoint URL.",
                malformedURLException);
    } catch (AutomationFrameworkException automationFrameworkException) {
        log.error("Error in sending request to the DCR endpoint.", automationFrameworkException);
        throw new AppManagerIntegrationTestException("Error in sending request to the DCR endpoint.",
                automationFrameworkException);
    } catch (JSONException e) {
        log.error("Error in parsing JSON to get consumer key/secret.", e);
        throw new AppManagerIntegrationTestException("Error in parsing JSON to get consumer key/secret.", e);
    } catch (InterruptedException interruptedException) {
        log.error("Thread interrupted while waiting to get consumer key/secret.", interruptedException);
        throw new AppManagerIntegrationTestException(
                "Thread interrupted while waiting to get consumer key/secret.", interruptedException);
    }
    return dataMap;
}