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:com.cws.esolutions.core.dao.impl.ServerDataDAOImplTest.java

@Test
public void addNewServer() {
    List<Object> data = new ArrayList<Object>(Arrays.asList(this.guid, "CentOS", ServiceStatus.ACTIVE.name(),
            ServiceRegion.DEV.name(), ServerType.APPSERVER.name(), "caspersbox.com", "AMD Athlon 1.0 GHz", 1,
            "VPS", RandomStringUtils.randomAlphanumeric(8).toUpperCase(), 512, "127.0.0.1",
            RandomStringUtils.randomAlphanumeric(8).toLowerCase(), "127.0.0.1",
            RandomStringUtils.randomAlphanumeric(8).toLowerCase(), "127.0.0.1",
            RandomStringUtils.randomAlphanumeric(8).toLowerCase(), "127.0.0.1",
            RandomStringUtils.randomAlphanumeric(8).toLowerCase(), "Unconfigured", "JUnit test", "khuntly",
            "Unconfigured", 0, "Unconfigured", "Unconfigured", "Unconfigured"));

    try {/*from  w  ww.j av a  2  s .c  o m*/
        Assert.assertTrue(dao.addServer(data));
    } catch (SQLException sqx) {
        Assert.fail(sqx.getMessage());
    }
}

From source file:edu.htwm.vsp.phone.services.XmlMappingTest.java

/**
 * Testet ob eine XML-Datei korrekt angelegt wird
 *///from   w w w. j  a  v  a2 s .  c  o  m
@Test
public void createValidXmlFile() throws IOException, JAXBException {

    // Lsche Datei falls schon vorhanden
    if (testfileSave.exists()) {
        testfileSave.delete();
    }

    /*
     * Erzeugt einen Nutzer mit einem zuflligen Namen und einer zuflligen Telefonnummer.
     */
    PhoneUser newUser = createRandomUser(phoneService);
    String phoneNumberCaption = RandomStringUtils.randomAlphanumeric(10);
    String phoneNumber = RandomStringUtils.randomAlphanumeric(8);
    PhoneNumber newNumber = new PhoneNumber(phoneNumberCaption, phoneNumber);
    newUser.getPhoneNumbers().add(newNumber);

    // XML-Datei schreiben
    marshaller.marshal(newUser, new FileWriter(testfileSave));
    // Teste ob Datei existiert und lesbar ist
    assertThat(testfileSave.exists(), is(true));
    assertThat(testfileSave.isFile(), is(true));

    // deserialize
    PhoneUser deserializedUser = (PhoneUser) unmarshaller.unmarshal(testfileSave);

    // check deserialization creates new object
    assertThat(deserializedUser, is(not(sameInstance(newUser))));
    assertThat(deserializedUser, is(newUser));
}

From source file:business.model.CaptchaModel.java

/**
 *
 * @return//  w  ww .java2 s  . c  o m
 */
public static String CreateCaptchaText() {
    try {
        return RandomStringUtils.random(CaptchaModel.numOfText, CaptchaModel.chars);
    } catch (Exception e) {
        log.warn(e.getMessage(), e);
    }
    return RandomStringUtils.randomAlphanumeric(CaptchaModel.numOfText);
}

From source file:com.adobe.acs.commons.xss.XSSFunctionsTest.java

@Test
public void testGetValidDimension() {
    final String dimension = RandomStringUtils.randomAlphanumeric(10);
    final String defaultValue = RandomStringUtils.randomAlphanumeric(10);
    XSSFunctions.getValidDimension(xssAPI, dimension, defaultValue);
    verify(xssAPI, only()).getValidDimension(dimension, defaultValue);
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.db.TopicItemDAOImplTest.java

public static void generatePubsubItems() {
    for (int i = 1; i <= 10; i++) {
        TopicItemEntity entity = new TopicItemEntity();
        entity.setServiceId(SERVICE_ID);
        entity.setNodeId(NODE_ID);//from  www  .j a  v a 2  s.  c o m
        entity.setId(RandomStringUtils.randomAlphanumeric(10));
        entity.setJid(JID);
        entity.setPayload(String.format("%03d", 11 - i));
        DateTime dt = new DateTime(testStartTime);
        dt = dt.minusDays(i);
        Date d = dt.toDate();
        String dateStr = StringUtils.dateToMillis(d);
        entity.setCreationDate(dateStr);
        DBTestUtil.getTopicItemDAO().persist(entity);
    }
}

From source file:io.fabric8.kubernetes.PodIT.java

@Before
public void init() {
    currentNamespace = session.getNamespace();
    client.pods().inNamespace(currentNamespace).delete();

    pod1 = new PodBuilder().withNewMetadata()
            .withName("pod1-" + RandomStringUtils.randomAlphanumeric(6).toLowerCase()).endMetadata()
            .withNewSpec().addNewContainer().withName("busybox").withImage("busybox")
            .withCommand("sleep", "36000").endContainer().endSpec().build();

    client.pods().inNamespace(currentNamespace).createOrReplace(pod1);
}

From source file:com.thoughtworks.go.server.service.AccessTokenServiceTest.java

@Test
void shouldMakeACallToSQLDaoForAccessTokenCreation() throws Exception {
    String longerDescription = RandomStringUtils.randomAlphanumeric(1024).toUpperCase();
    accessTokenService.create(longerDescription, username, authConfigId);

    assertThat(result.isSuccessful()).isTrue();

    verify(accessTokenDao, times(1)).saveOrUpdate(any(AccessToken.class));
}

From source file:com.kixeye.chassis.scala.transport.serde.ScalaCaseClassTest.java

@Test
@Ignore("Maybe fix this?")
public void testXmlSerDe() throws Exception {
    final XmlMessageSerDe serDe = new XmlMessageSerDe();

    final TestObject obj = new TestObject(RandomStringUtils.randomAlphanumeric(64),
            new SomeOtherObject(RandomStringUtils.randomAlphanumeric(64)));

    final byte[] serializedObj = serDe.serialize(obj);

    dumpToLog(serDe, serializedObj);/*from w  w w .  ja va  2s .co m*/

    final TestObject deserializedObj = serDe.deserialize(serializedObj, 0, serializedObj.length,
            TestObject.class);

    Assert.assertEquals(obj, deserializedObj);
}

From source file:com.ikon.servlet.PasswordResetServlet.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String username = WebUtils.getString(request, "username");
    ServletContext sc = getServletContext();
    User usr = null;/*ww  w.ja  v a2 s .  co m*/

    try {
        usr = AuthDAO.findUserByPk(username);
    } catch (DatabaseException e) {
        log.error(getServletName() + " User '" + username + "' not found");
    }

    if (usr != null) {
        try {
            String password = RandomStringUtils.randomAlphanumeric(8);
            AuthDAO.updateUserPassword(username, password);
            MailUtils.sendMessage(usr.getEmail(), usr.getEmail(), "Password reset", "Your new password is: "
                    + password + "<br/>"
                    + "To change it log in and then go to 'Tools' > 'Preferences' > 'User Configuration'.");
            sc.setAttribute("resetOk", usr.getEmail());
            response.sendRedirect("password_reset.jsp");
        } catch (MessagingException e) {
            log.error(e.getMessage(), e);
            sc.setAttribute("resetFailed", "Failed to send the new password by email");
            response.sendRedirect("password_reset.jsp");
        } catch (DatabaseException e) {
            log.error(e.getMessage(), e);
            sc.setAttribute("resetFailed", "Failed reset the user password");
            response.sendRedirect("password_reset.jsp");
        }
    } else {
        sc.setAttribute("resetFailed", "Invalid user name provided");
        sc.getRequestDispatcher("/password_reset.jsp").forward(request, response);
    }
}

From source file:com.redhat.rhn.domain.common.CommonFactory.java

/**
 * Create a TinyUrl//from  ww  w  . j a v  a2s  .c o  m
 * @param urlIn to tinyfy
 * @param expires the date we *ADD* 6 hours to to set the expiration on the URL
 * @return TinyUrl instance
 */
public static TinyUrl createTinyUrl(String urlIn, Date expires) {
    String token = RandomStringUtils.randomAlphanumeric(8);
    TinyUrl existing = lookupTinyUrl(token);
    while (existing != null) {
        log.warn("Had collision with: " + token);
        token = RandomStringUtils.randomAlphanumeric(8);
        existing = lookupTinyUrl(token);
    }

    TinyUrl url = new TinyUrl();
    Config c = new Config();
    url.setUrl(urlIn);
    url.setEnabled(true);
    url.setToken(token);
    Calendar pcal = Calendar.getInstance();
    pcal.setTime(expires);
    pcal.add(Calendar.HOUR, c.getInt("server.satellite.tiny_url_timeout", 4));
    url.setExpires(new Date(pcal.getTimeInMillis()));
    return url;
}