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.tasktop.c2c.server.tasks.tests.service.TaskServiceTest.java

License:asdf

@Test
public void testUpdateProduct() throws Exception {
    Product mockProduct = MockProductFactory.create(entityManager);
    entityManager.flush();/*from ww w .j  a  v  a2 s . c  o  m*/
    entityManager.refresh(mockProduct);
    com.tasktop.c2c.server.tasks.domain.Product product = taskService
            .retrieveProduct(mockProduct.getId().intValue());

    product.setName(RandomStringUtils.randomAlphanumeric(24));
    product.setDescription(RandomStringUtils.randomAlphanumeric(1024));
    product.setIsActive(false);
    com.tasktop.c2c.server.tasks.domain.Product updatedProduct = taskService.updateProduct(product);

    assertEquals(product.getName(), updatedProduct.getName());
    assertEquals(updatedProduct.getDescription(), product.getDescription());
    assertEquals(updatedProduct.getIsActive(), product.getIsActive());
    assertEquals(updatedProduct.getDefaultMilestone(), product.getDefaultMilestone());
}

From source file:com.tasktop.c2c.server.tasks.tests.service.TaskServiceTest.java

License:asdf

@Test
public void testCreateComponentWithInitialOwner() throws Exception {
    com.tasktop.c2c.server.tasks.domain.Component testComponent = new com.tasktop.c2c.server.tasks.domain.Component();
    testComponent.setName(RandomStringUtils.randomAlphanumeric(24));
    testComponent.setDescription(RandomStringUtils.randomAlphanumeric(1024));
    testComponent.setInitialOwner(getCreatedMockTaskUserProfile());
    testComponent.setProduct(getCreatedMockDomainProduct());

    com.tasktop.c2c.server.tasks.domain.Component createdComponent = taskService.createComponent(testComponent);
    assertNotNull(createdComponent.getId());
    assertEquals(testComponent.getName(), createdComponent.getName());
    assertEquals(testComponent.getDescription(), createdComponent.getDescription());
    assertEquals(testComponent.getInitialOwner().getId(), createdComponent.getInitialOwner().getId());
    assertEquals(testComponent.getProduct().getId(), createdComponent.getProduct().getId());
}

From source file:com.tasktop.c2c.server.tasks.tests.service.TaskServiceTest.java

License:asdf

/**
 * Should successfully create a component with no intitial owner (task 1727)
 *//*from w w  w . j a v  a 2  s.  co  m*/
@Test
public void testCreateComponentNoInitialOwner() throws Throwable {
    com.tasktop.c2c.server.tasks.domain.Component testComponent = new com.tasktop.c2c.server.tasks.domain.Component();
    testComponent.setName(RandomStringUtils.randomAlphanumeric(24));
    testComponent.setDescription(RandomStringUtils.randomAlphanumeric(1024));
    testComponent.setProduct(getCreatedMockDomainProduct());

    com.tasktop.c2c.server.tasks.domain.Component createComponent = taskService.createComponent(testComponent);
    assertNull(createComponent.getInitialOwner());
}

From source file:com.tasktop.c2c.server.tasks.tests.service.TaskServiceTest.java

License:asdf

@Test
public void testUpdateComponent() throws Exception {

    // Save a random component before we start our test.
    Component mockComponent = MockComponentFactory.create(entityManager);
    entityManager.flush();/*from w w w.j  av  a2s . c o  m*/

    // Grab our domain object through the task service.
    com.tasktop.c2c.server.tasks.domain.Component origComponent = taskService
            .retrieveComponent(Integer.valueOf(mockComponent.getId()));

    // Sanity check, to make sure we had a component to start with.
    assertNotNull(origComponent);

    // Perform a couple of updates, and push them to the Task Service
    origComponent.setName(RandomStringUtils.randomAlphanumeric(24));
    origComponent.setDescription(RandomStringUtils.randomAlphanumeric(1024));
    com.tasktop.c2c.server.tasks.domain.Component updatedComponent = taskService.updateComponent(origComponent);

    assertEquals(origComponent.getName(), updatedComponent.getName());
    assertEquals(updatedComponent.getDescription(), origComponent.getDescription());
}

From source file:com.tasktop.c2c.server.tasks.tests.service.TaskServiceTest.java

License:asdf

@Test(expected = ValidationException.class)
public void testUpdateComponentNoName() throws Throwable {

    // Save a random component before we start our test.
    Component mockComponent = MockComponentFactory.create(entityManager);
    entityManager.flush();/* w w  w .j ava 2  s  . c  o m*/

    // Grab our domain object through the task service.
    com.tasktop.c2c.server.tasks.domain.Component origComponent = taskService
            .retrieveComponent(Integer.valueOf(mockComponent.getId()));

    // Sanity check, to make sure we had a component to start with.
    assertNotNull(origComponent);

    // Perform a couple of updates, and push them to the Task Service
    origComponent.setName(null);
    origComponent.setDescription(RandomStringUtils.randomAlphanumeric(1024));

    // This should blow up.
    taskService.updateComponent(origComponent);
}

From source file:com.tasktop.c2c.server.tasks.tests.service.TaskServiceTest.java

License:asdf

@Test
public void testUpdateProductTree_ValidationErrors() throws Exception {
    Product mockProduct = MockProductFactory.create(entityManager);
    entityManager.flush();/*from ww w.  j a v a  2  s.  c  o m*/
    entityManager.refresh(mockProduct);
    com.tasktop.c2c.server.tasks.domain.Product product = taskService
            .retrieveProduct(mockProduct.getId().intValue());

    product.setName(RandomStringUtils.randomAlphanumeric(24));
    product.setDescription(RandomStringUtils.randomAlphanumeric(1024));
    product.setIsActive(false);

    // Now, make some invalid data.
    product.setName(null);

    for (com.tasktop.c2c.server.tasks.domain.Component curComponent : product.getComponents()) {
        curComponent.setName(null);
    }

    try {
        // This should blow up with an exception.
        taskService.updateProductTree(product);
    } catch (ValidationException ve) {

        // We should have an error for every product, and 2 for every component
        assertEquals(1 + product.getComponents().size(), ve.getMessages().size());
    }
}

From source file:com.tasktop.c2c.server.tasks.tests.service.TaskServiceTest.java

License:asdf

@Test
public void testUpdateProductTree() throws Exception {
    Product mockProduct = MockProductFactory.create(entityManager);
    entityManager.flush();/*  w  w  w  .  j a v a2 s .co  m*/
    entityManager.refresh(mockProduct);
    com.tasktop.c2c.server.tasks.domain.Product product = taskService
            .retrieveProduct(mockProduct.getId().intValue());
    String appender = RandomStringUtils.randomAlphanumeric(12);

    product.setName(RandomStringUtils.randomAlphanumeric(24));
    product.setDescription(RandomStringUtils.randomAlphanumeric(1024));
    product.setIsActive(false);

    for (com.tasktop.c2c.server.tasks.domain.Component curComponent : product.getComponents()) {
        curComponent.setName(curComponent.getName() + appender);
    }

    com.tasktop.c2c.server.tasks.domain.Product updatedProduct = taskService.updateProductTree(product);

    assertEquals(product.getName(), updatedProduct.getName());
    assertEquals(updatedProduct.getDescription(), product.getDescription());
    assertEquals(updatedProduct.getIsActive(), product.getIsActive());
    assertEquals(updatedProduct.getDefaultMilestone(), product.getDefaultMilestone());

    for (com.tasktop.c2c.server.tasks.domain.Component curComponent : product.getComponents()) {
        assertTrue(curComponent.getName().endsWith(appender));
    }
}

From source file:com.tasktop.c2c.server.tasks.tests.service.TaskServiceTest.java

License:asdf

@Ignore
@Test/*from ww  w  .ja v  a 2 s  .c  o m*/
public void testUpdateProductTree_task2891() throws Exception {
    Product mockProduct = MockProductFactory.create(entityManager);
    entityManager.flush();
    entityManager.refresh(mockProduct);
    com.tasktop.c2c.server.tasks.domain.Product product = taskService
            .retrieveProduct(mockProduct.getId().intValue());

    product.setName(RandomStringUtils.randomAlphanumeric(24));
    product.setDescription(RandomStringUtils.randomAlphanumeric(1024));
    product.setIsActive(false);

    String lastComponentName = null;
    for (com.tasktop.c2c.server.tasks.domain.Component curComponent : product.getComponents()) {
        String thisName = curComponent.getName();
        if (lastComponentName != null) {
            curComponent.setName(lastComponentName);
        }
        lastComponentName = thisName;
    }
    product.getComponents().get(0).setName(lastComponentName);

    com.tasktop.c2c.server.tasks.domain.Product updatedProduct = taskService.updateProductTree(product);
    Assert.assertEquals(lastComponentName, updatedProduct.getComponents().get(0).getName());
}

From source file:net.sourceforge.subsonic.controller.ExternalPlayerController.java

private Player getPlayer(HttpServletRequest request) {

    // Create guest user if necessary.
    User user = securityService.getUserByName(GUEST_USERNAME);
    if (user == null) {
        user = new User(GUEST_USERNAME, RandomStringUtils.randomAlphanumeric(30), null);
        user.setStreamRole(true);/*from w w w .j a  v  a 2s  .  c o  m*/
        securityService.createUser(user);
    }

    // Look for existing player.
    List<Player> players = playerService.getPlayersForUserAndClientId(GUEST_USERNAME, null);
    if (!players.isEmpty()) {
        return players.get(0);
    }

    // Create player if necessary.
    Player player = new Player();
    player.setIpAddress(request.getRemoteAddr());
    player.setUsername(GUEST_USERNAME);
    playerService.createPlayer(player);

    return player;
}

From source file:net.sourceforge.subsonic.controller.MultiController.java

public ModelAndView recover(HttpServletRequest request, HttpServletResponse response) throws Exception {

    Map<String, Object> map = new HashMap<String, Object>();
    String usernameOrEmail = StringUtils.trimToNull(request.getParameter("usernameOrEmail"));

    if (usernameOrEmail != null) {
        User user = getUserByUsernameOrEmail(usernameOrEmail);
        if (user == null) {
            map.put("error", "recover.error.usernotfound");
        } else if (user.getEmail() == null) {
            map.put("error", "recover.error.noemail");
        } else {/*from ww  w.j a va2  s .  co  m*/
            String password = RandomStringUtils.randomAlphanumeric(8);
            if (emailPassword(password, user.getUsername(), user.getEmail())) {
                map.put("sentTo", user.getEmail());
                user.setLdapAuthenticated(false);
                user.setPassword(password);
                securityService.updateUser(user);
            } else {
                map.put("error", "recover.error.sendfailed");
            }
        }
    }

    return new ModelAndView("recover", "model", map);
}