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:com.google.cloud.bigtable.hbase.TestFilters.java

/**
 * Requirement 9.5/*from   ww  w  .j a  v a 2s.  c  o  m*/
 *
 * Test the NullComparator against EQUAL, GREATER, GREATER_OR_EQUAL, LESS, LESS_OR_EQUAL,
 * NOT_EQUAL, and NO_OP.  It behaves the same as constructing a BinaryComparator with an empty
 * byte array.
 */
@Test
@Category(KnownGap.class)
public void testRowFilterNullComparator() throws Exception {
    // Initialize data
    Table table = getTable();
    String rowKeyPrefix = "testRowFilter-" + RandomStringUtils.randomAlphabetic(10);
    byte[] rowKeyA = Bytes.toBytes(rowKeyPrefix + "A");
    byte[] rowKeyB = Bytes.toBytes(rowKeyPrefix + "B");
    byte[] qual = dataHelper.randomData("testqual");
    byte[] value = Bytes.toBytes("testvalue");
    Put put = new Put(rowKeyA).addColumn(COLUMN_FAMILY, qual, value);
    table.put(put);

    // Test BinaryComparator - EQUAL
    ByteArrayComparable nullComparator = new NullComparator();
    Filter filter = new RowFilter(CompareFilter.CompareOp.EQUAL, nullComparator);
    Result[] results = scanWithFilter(table, rowKeyA, rowKeyB, qual, filter);
    Assert.assertEquals("# results", 0, results.length);

    // Test BinaryComparator - GREATER
    filter = new RowFilter(CompareFilter.CompareOp.GREATER, nullComparator);
    results = scanWithFilter(table, rowKeyA, rowKeyB, qual, filter);
    Assert.assertEquals("# results", 0, results.length);

    // Test BinaryComparator - GREATER_OR_EQUAL
    filter = new RowFilter(CompareFilter.CompareOp.GREATER_OR_EQUAL, nullComparator);
    results = scanWithFilter(table, rowKeyA, rowKeyB, qual, filter);
    Assert.assertEquals("# results", 0, results.length);

    // Test BinaryComparator - LESS
    filter = new RowFilter(CompareFilter.CompareOp.LESS, nullComparator);
    results = scanWithFilter(table, rowKeyA, rowKeyB, qual, filter);
    Assert.assertEquals("# results", 1, results.length);
    Assert.assertArrayEquals(rowKeyA, results[0].getRow());

    // Test BinaryComparator - LESS_OR_EQUAL
    filter = new RowFilter(CompareFilter.CompareOp.LESS_OR_EQUAL, nullComparator);
    results = scanWithFilter(table, rowKeyA, rowKeyB, qual, filter);
    Assert.assertEquals("# results", 1, results.length);
    Assert.assertArrayEquals(rowKeyA, results[0].getRow());

    // Test BinaryComparator - NOT_EQUAL
    filter = new RowFilter(CompareFilter.CompareOp.NOT_EQUAL, nullComparator);
    results = scanWithFilter(table, rowKeyA, rowKeyB, qual, filter);
    Assert.assertEquals("# results", 1, results.length);
    Assert.assertArrayEquals(rowKeyA, results[0].getRow());

    // Test BinaryComparator - NO_OP
    filter = new RowFilter(CompareFilter.CompareOp.NO_OP, nullComparator);
    results = scanWithFilter(table, rowKeyA, rowKeyB, qual, filter);
    Assert.assertEquals("# results", 0, results.length);

    table.close();
}

From source file:com.edgenius.wiki.gwt.server.SecurityControllerImpl.java

public int sendForgetPassword(String email) {
    User user = userReadingService.getUserByEmail(email);
    if (user == null) {
        //email does not exist
        return SharedConstants.RET_NO_EMAIL;
    }/*from w  ww  . ja  v  a 2  s .c o  m*/
    //reset this user password and send out
    String newPass = RandomStringUtils.randomAlphabetic(8);
    //so far, it is plain text - just for email body. It will be encrypted in UserSerivce.resetPassword()

    String plainPass = newPass;
    user.setPassword(newPass);
    //TODO: Does it need warranty only email send out, the password can be reset?
    //if so, I need change 2 things. Use mailEngine instead of mailService, change mailEngine throw exception 
    //rather than catch all Exception
    userService.resetPassword(user, newPass);
    //after above method, the password is encrypted one, so need keep plain one and send email

    //send email
    try {
        // Send create account email
        SimpleMailMessage msg = new SimpleMailMessage();
        msg.setFrom(Global.DefaultNotifyMail);
        msg.setTo(user.getContact().getEmail());

        Map<String, Object> map = new HashMap<String, Object>();
        map.put(WikiConstants.ATTR_PASSWORD, plainPass);
        map.put(WikiConstants.ATTR_USER, user);
        mailService.sendPlainMail(msg, WikiConstants.MAIL_TEMPL_FORGET_PASSWORD_NOTIFICATION, map);
        log.info("Email sent to " + user.getFullname() + " for password reset.");
    } catch (Exception e) {
        log.error("Failed to send reset passowrd email:" + user.getContact().getEmail(), e);
        return SharedConstants.RET_SEND_MAIL_FAILED;
    }

    return 0;
}

From source file:it.cineca.iris.restclient.main.Command.java

private void createNewItem(String authorityName, String localName) throws Exception {
    ObjectMapper mapper = new ObjectMapper();

    CollectionRestDTO targetCollection = null;
    Integer targetInputFormId = null;
    Response response = null;//from w  w  w.jav  a 2 s .  c o m

    if (authorityName == null || localName == null) {

        response = cl.collections();

        String result = response.readEntity(String.class);

        CollectionRestPageDTO collection = mapper.readValue(result, CollectionRestPageDTO.class);

        if (collection != null && !collection.getRestResourseDTOList().isEmpty()) {

            int index = randInt(0, collection.getRestResourseDTOList().size() - 1);

            targetCollection = collection.getRestResourseDTOList().get(index);
            targetInputFormId = collection.getRestResourseDTOList().get(index).getInputformActiveId();
            System.out.println("Collections handle: " + targetCollection.getHandle());
            System.out.println("Collections inputform: " + targetInputFormId);

        } else {
            System.out.println("\nNo collection found...");
            return;
        }

    } else {

        response = cl.collection(authorityName, localName);

        String result = response.readEntity(String.class);

        targetCollection = mapper.readValue(result, CollectionRestDTO.class);
        targetInputFormId = targetCollection.getInputformActiveId();
    }

    if (targetCollection != null && targetCollection.getHandle() != null
            && !targetCollection.getHandle().isEmpty() && targetInputFormId != null && targetInputFormId > -1) {
        response = cl.inputFormAll(String.valueOf(targetInputFormId));
        String test = response.readEntity(String.class);
        System.out.println(test);

        DCInputSetRestDTO inputform = mapper.readValue(test, DCInputSetRestDTO.class);

        List<DCInputSetRowRestDTO> inputformRow = inputform.getRows();

        ItemRestWriteDTO itemToCreate = new ItemRestWriteDTO();
        itemToCreate.setCollection(targetCollection.getContainerDTO());

        String dcSchema = null, dcElement = null, dcQualifier = null, dcValue = null, dcAuthority = null;

        ChoiceAuthorityManager manager = ChoiceAuthorityManager.getManager();

        for (DCInputSetRowRestDTO dcInputSetRowRestDTO : inputformRow) {
            dcSchema = dcInputSetRowRestDTO.getDcSchema();
            dcElement = dcInputSetRowRestDTO.getDcElement();
            dcQualifier = dcInputSetRowRestDTO.getDcQualifier();

            //Only required!!!
            if (dcInputSetRowRestDTO.isRequired()) {

                if (manager.isAuthorityManaged(dcSchema, dcElement, dcQualifier, null, null)) {
                    AbstractAuthorityResolver resolver = (AbstractAuthorityResolver) manager
                            .getAuthorityResolver(dcSchema, dcElement, dcQualifier);
                    resolver.setRestIRClient(this.cl);
                    dcAuthority = resolver.resolve(this.authorCF);
                } else {
                    dcValue = RandomStringUtils.randomAlphabetic(randInt(1, 40));
                }

                System.out.println("Type: " + dcInputSetRowRestDTO.getInputType());

                IInputformType typeEnum = AbstractInputformType
                        .getInstance(dcInputSetRowRestDTO.getInputType());
                itemToCreate
                        .addMetadata(typeEnum.build(dcSchema, dcElement, dcQualifier, dcValue, dcAuthority));
            } else if ("year".equals(dcInputSetRowRestDTO.getInputType())) {
                IInputformType typeEnum = AbstractInputformType
                        .getInstance(dcInputSetRowRestDTO.getInputType());
                itemToCreate.addMetadata(typeEnum.build(dcSchema, dcElement, dcQualifier, "2015", null));
            }
        }

        MultivaluedMap<String, Object> headers = new MultivaluedHashMap<String, Object>();
        headers.add(HeaderScopeEnum.getHeaderTag(), HeaderScopeEnum.ROLE_ADMIN.getHeaderValue());
        headers.add(HeaderTagNameEnum.ON_BEHALF_OF.getHeaderTag(), this.username);
        headers.add(HeaderTargetStateEnum.getHeaderTag(), HeaderTargetStateEnum.PUBLISH.getHeaderValue());
        headers.add(HeaderDisseminationOptionsEnum.getHeaderTag(),
                HeaderDisseminationOptionsEnum.VISIBLE.getHeaderValue());
        headers.add(HeaderActAsBatchUserEnum.getHeaderTag(), HeaderActAsBatchUserEnum.TRUE.getHeaderValue());

        response = cl.createItem(itemToCreate, headers);

        this.locationItem = response.getHeaderString("Location");

        System.out.println("Location item: " + locationItem);
    }
}

From source file:com.xpn.xwiki.plugin.invitationmanager.impl.InvitationManagerImpl.java

/**
 * @return a new random code for an invitation
 */
private String generateInvitationCode() {
    return RandomStringUtils.randomAlphabetic(8).toLowerCase();
}

From source file:edu.samplu.common.WebDriverLegacyITBase.java

protected List<String> testCreateNewParameterType(String docId, String parameterType, String parameterCode)
        throws Exception {
    waitForPageToLoad();//w w w  . j  av a 2 s.  c  o  m
    docId = waitForDocId();

    //Enter details for Parameter.
    waitAndTypeByName("document.documentHeader.documentDescription", "Adding Test Parameter Type");
    parameterCode = RandomStringUtils.randomAlphabetic(4).toLowerCase();
    waitAndTypeByName("document.newMaintainableObject.code", parameterCode);
    parameterType = "testing " + ITUtil.createUniqueDtsPlusTwoRandomChars();
    waitAndTypeByName("document.newMaintainableObject.name", parameterType);
    waitAndClickSave();
    waitAndClickSubmit();
    waitForPageToLoad();
    assertElementPresentByXpath(DOC_SUBMIT_SUCCESS_MSG_XPATH, "Document is not submitted successfully");
    selectTopFrame();
    waitAndClickDocSearchTitle();
    waitForPageToLoad();
    selectFrameIframePortlet();
    waitAndClickSearch();
    Thread.sleep(2000);
    SeleneseTestBase.assertEquals(docId, getTextByXpath(DOC_ID_XPATH_3));
    SeleneseTestBase.assertEquals(DOC_STATUS_FINAL, getTextByXpath(DOC_STATUS_XPATH_2));
    selectTopFrame();
    List<String> params = new ArrayList<String>();
    params.add(docId);
    params.add(parameterType);
    params.add(parameterCode);

    return params;
}

From source file:edu.samplu.common.WebDriverLegacyITBase.java

protected List<String> testCopyParameterType(String docId, String parameterType, String parameterCode)
        throws Exception {
    selectFrameIframePortlet();//from   ww  w . j  av  a  2 s.c  o  m
    waitAndClickCopy();
    waitForPageToLoad();
    docId = waitForDocId();
    waitAndTypeByName("document.documentHeader.documentDescription", "Copying Test Parameter");
    parameterCode = RandomStringUtils.randomAlphabetic(4).toLowerCase();
    waitAndTypeByName("document.newMaintainableObject.code", parameterCode);
    clearTextByName("document.newMaintainableObject.name");
    parameterType = "testing " + ITUtil.createUniqueDtsPlusTwoRandomChars();
    waitAndTypeByName("document.newMaintainableObject.name", parameterType);
    waitAndClickSave();
    waitAndClickSubmit();
    waitForPageToLoad();
    assertElementPresentByXpath(DOC_SUBMIT_SUCCESS_MSG_XPATH, "Document is not submitted successfully");
    selectTopFrame();
    waitAndClickDocSearchTitle();
    waitForPageToLoad();
    selectFrameIframePortlet();
    waitAndClickSearch();
    Thread.sleep(2000);
    SeleneseTestBase.assertEquals(docId, getTextByXpath(DOC_ID_XPATH_3));
    SeleneseTestBase.assertEquals(DOC_STATUS_FINAL, getTextByXpath(DOC_STATUS_XPATH_2));
    selectTopFrame();
    List<String> params = new ArrayList<String>();
    params.add(docId);
    params.add(parameterType);
    params.add(parameterCode);

    return params;
}

From source file:edu.samplu.common.WebDriverLegacyITBase.java

protected void testIdentityPersonBlanketApprove() throws Exception {
    selectFrameIframePortlet();/*from   www.  j a  v a 2 s. c om*/
    waitAndCreateNew();
    String docId = waitForDocId();
    waitAndTypeByXpath(DOC_DESCRIPTION_XPATH, "Validation Test Person");
    assertBlanketApproveButtonsPresent();
    waitAndTypeByXpath("//input[@id='document.principalName']",
            "principal" + RandomStringUtils.randomAlphabetic(3).toLowerCase());
    selectByName("newAffln.affiliationTypeCode", "Affiliate");
    selectByName("newAffln.campusCode", "BX - BLGTN OFF CAMPUS");
    selectByName("newAffln.campusCode", "BL - BLOOMINGTON");
    assertElementPresentByName("newAffln.dflt");
    waitAndClickByName("newAffln.dflt");
    waitAndClickByName("methodToCall.addAffln.anchor");
    waitAndClickByName("methodToCall.toggleTab.tabContact");
    selectByName("newName.namePrefix", "Mr");
    waitAndTypeByName("newName.firstName", "First");
    waitAndTypeByName("newName.lastName", "Last");
    selectByName("newName.nameSuffix", "Mr");
    waitAndClickByName("newName.dflt");
    waitAndClickByName("methodToCall.addName.anchor");
    waitForPageToLoad();
    blanketApproveTest();
    assertDocFinal(docId);
}

From source file:edu.samplu.common.WebDriverLegacyITBase.java

protected void testLocationCampusBlanketApprove() throws Exception {
    selectFrameIframePortlet();/*from  ww w. j av a 2s  .  c  o  m*/
    waitAndCreateNew();
    String docId = waitForDocId();
    String twoLetters = RandomStringUtils.randomAlphabetic(2);
    waitAndTypeByName("document.documentHeader.documentDescription", "Validation Test Campus " + twoLetters);
    assertBlanketApproveButtonsPresent();
    waitAndTypeByName("document.newMaintainableObject.code", RandomStringUtils.randomAlphabetic(2));
    waitAndTypeByName("document.newMaintainableObject.name",
            "Validation Test Campus" + ITUtil.createUniqueDtsPlusTwoRandomChars());
    waitAndTypeByName("document.newMaintainableObject.shortName", "VTC " + twoLetters);
    selectByName("document.newMaintainableObject.campusTypeCode", "B - BOTH");
    blanketApproveTest();
    assertDocFinal(docId);
}

From source file:edu.samplu.common.WebDriverLegacyITBase.java

protected void testLocationCountryBlanketApprove() throws InterruptedException {
    selectFrameIframePortlet();/*from w  w w  .  j av a  2s.c  o  m*/
    waitAndCreateNew();
    String docId = waitForDocId();
    assertBlanketApproveButtonsPresent();
    String twoUpperCaseLetters = RandomStringUtils.randomAlphabetic(2).toUpperCase();
    String countryName = "Validation Test Country " + ITUtil.createUniqueDtsPlusTwoRandomCharsNot9Digits();
    waitAndTypeByXpath(DOC_DESCRIPTION_XPATH, countryName);
    waitAndTypeByXpath(DOC_CODE_XPATH, twoUpperCaseLetters);
    waitAndTypeByXpath("//input[@id='document.newMaintainableObject.name']", countryName);
    waitAndTypeByXpath("//input[@id='document.newMaintainableObject.alternateCode']",
            "V" + twoUpperCaseLetters);
    int attemptCount = 0;
    blanketApproveCheck();
    while (hasDocError("same primary key already exists") && attemptCount < 25) {
        clearTextByXpath(DOC_CODE_XPATH);
        waitAndTypeByXpath(DOC_CODE_XPATH,
                twoUpperCaseLetters.substring(0, 1) + Character.toString((char) ('A' + attemptCount++)));
        blanketApproveCheck();
    }
    blanketApproveAssert();
    assertDocFinal(docId);
}

From source file:edu.samplu.common.WebDriverLegacyITBase.java

protected void testLocationCountyBlanketApprove() throws Exception {
    selectFrameIframePortlet();//from   w w  w. ja  v a2  s.  co  m
    waitAndCreateNew();
    String docId = waitForDocId();
    waitAndTypeByXpath(DOC_DESCRIPTION_XPATH, "Validation Test County");
    assertBlanketApproveButtonsPresent();
    String countryLookUp = "//input[@name='methodToCall.performLookup.(!!org.kuali.rice.location.impl.country.CountryBo!!).(((code:document.newMaintainableObject.countryCode,))).((`document.newMaintainableObject.countryCode:code,`)).((<>)).(([])).((**)).((^^)).((&&)).((//)).((~~)).(::::;"
            + getBaseUrlString() + "/kr/lookup.do;::::).anchor4']";
    waitAndClickByXpath(countryLookUp);
    waitAndTypeByName("code", "US");
    waitAndClickSearch();
    waitAndClickReturnValue();
    waitAndTypeByXpath(DOC_CODE_XPATH, RandomStringUtils.randomAlphabetic(2).toUpperCase());
    String stateLookUp = "//input[@name='methodToCall.performLookup.(!!org.kuali.rice.location.impl.state.StateBo!!).(((countryCode:document.newMaintainableObject.countryCode,code:document.newMaintainableObject.stateCode,))).((`document.newMaintainableObject.countryCode:countryCode,document.newMaintainableObject.stateCode:code,`)).((<>)).(([])).((**)).((^^)).((&&)).((//)).((~~)).(::::;"
            + getBaseUrlString() + "/kr/lookup.do;::::).anchor4']";
    waitAndClickByXpath(stateLookUp);
    waitAndTypeByName("code", "IN");
    waitAndClickSearch();
    waitAndClickReturnValue();
    String countyName = "Validation Test County" + ITUtil.createUniqueDtsPlusTwoRandomChars();
    waitAndTypeByXpath("//input[@id='document.newMaintainableObject.name']", countyName);
    waitAndClickByXpath("//input[@id='document.newMaintainableObject.active']");
    blanketApproveTest();
    assertDocFinal(docId);
}