List of usage examples for org.apache.commons.lang RandomStringUtils randomNumeric
public static String randomNumeric(int count)
Creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of numeric characters.
From source file:org.alfresco.repo.security.authentication.RandomUserNameGenerator.java
/** * Returns a generated user name//w ww . j ava 2s .c o m * * @return the generated user name */ public String generateUserName(String firstName, String lastName, String emailAddress, int seed) { String userName = RandomStringUtils.randomNumeric(getUserNameLength()); return userName; }
From source file:org.alfresco.repo.web.scripts.invite.InviteServiceTest.java
public void testStartInviteWhenInviteeIsAlreadyMemberOfSite() throws Exception { ////from w w w .j a v a2 s. c o m // add invitee as member of site: SITE_SHORT_NAME_INVITE // String randomStr = RandomStringUtils.randomNumeric(6); final String inviteeUserName = "inviteeUserName" + randomStr; final String inviteeEmailAddr = INVITEE_EMAIL_PREFIX + randomStr + "@" + INVITEE_EMAIL_DOMAIN; // create person with invitee user name and invitee email address AuthenticationUtil.runAs(new RunAsWork<Object>() { public Object doWork() throws Exception { createPerson(INVITEE_FIRSTNAME, INVITEE_LASTNAME, inviteeUserName, inviteeEmailAddr); return null; } }, AuthenticationUtil.getSystemUserName()); // add invitee person to site: SITE_SHORT_NAME_INVITE AuthenticationUtil.runAs(new RunAsWork<Object>() { public Object doWork() throws Exception { InviteServiceTest.this.siteService.setMembership(SITE_SHORT_NAME_INVITE_1, inviteeUserName, INVITEE_SITE_ROLE); return null; } }, USER_INVITER); /** * Should conflict */ startInvite(INVITEE_FIRSTNAME, INVITEE_LASTNAME, inviteeEmailAddr, INVITEE_SITE_ROLE, SITE_SHORT_NAME_INVITE_1, Status.STATUS_CONFLICT); // Should go through startInvite(INVITEE_FIRSTNAME, "Belzebub", inviteeEmailAddr, INVITEE_SITE_ROLE, SITE_SHORT_NAME_INVITE_1, Status.STATUS_OK); // Should go through startInvite("Lucifer", INVITEE_LASTNAME, inviteeEmailAddr, INVITEE_SITE_ROLE, SITE_SHORT_NAME_INVITE_1, Status.STATUS_OK); }
From source file:org.alfresco.repo.web.scripts.person.PersonServiceTest.java
public void testJobWithSpace() throws Exception { String userName = RandomStringUtils.randomNumeric(6); String userJob = "myJob" + RandomStringUtils.randomNumeric(2) + " myJob" + RandomStringUtils.randomNumeric(3); //we need to ecape a spaces for search String jobSearchString = userJob.replace(" ", "\\ "); createPerson(userName, "myTitle", "myFirstName", "myLastName", "myOrganisation", userJob, "firstName.lastName@email.com", "myBio", "images/avatar.jpg", Status.STATUS_OK); // Get a person Response response = sendRequest( new GetRequest(URL_PEOPLE + "?filter=" + URLEncoder.encode("jobtitle:" + jobSearchString)), 200); JSONObject res = new JSONObject(response.getContentAsString()); assertEquals(1, res.getJSONArray("people").length()); response = sendRequest(new GetRequest(URL_PEOPLE + "?filter=" + URLEncoder.encode("jobtitle:" + userJob)), 200);/* www . j ava 2 s. c om*/ res = new JSONObject(response.getContentAsString()); assertEquals(0, res.getJSONArray("people").length()); }
From source file:org.alfresco.repo.web.scripts.person.PersonServiceTest.java
@SuppressWarnings("unused") public void testGetPerson() throws Exception { // Get a person that doesn't exist Response response = sendRequest(new GetRequest(URL_PEOPLE + "/" + "nonExistantUser"), 404); // Create a person and get him/her String userName = RandomStringUtils.randomNumeric(6); JSONObject result = createPerson(userName, "myTitle", "myFirstName", "myLastName", "myOrganisation", "myJobTitle", "myEmailAddress", "myBio", "images/avatar.jpg", 200); response = sendRequest(new GetRequest(URL_PEOPLE + "/" + userName), 200); }
From source file:org.alfresco.repo.web.scripts.person.PersonServiceTest.java
public void testUpdatePerson() throws Exception { // Create a new person String userName = RandomStringUtils.randomNumeric(6); createPerson(userName, "myTitle", "myFirstName", "myLastName", "myOrganisation", "myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", Status.STATUS_OK); // Update the person's details JSONObject result = updatePerson(userName, "updatedTitle", "updatedFirstName", "updatedLastName", "updatedOrganisation", "updatedJobTitle", "updatedFN.updatedLN@email.com", "updatedBio", "images/updatedAvatar.jpg", Status.STATUS_OK); assertEquals(userName, result.get("userName")); assertEquals("updatedFirstName", result.get("firstName")); assertEquals("updatedLastName", result.get("lastName")); assertEquals("updatedOrganisation", result.get("organization")); assertEquals("updatedJobTitle", result.get("jobtitle")); assertEquals("updatedFN.updatedLN@email.com", result.get("email")); }
From source file:org.alfresco.repo.web.scripts.person.PersonServiceTest.java
public void testDeletePerson() throws Exception { // Create a new person String userName = RandomStringUtils.randomNumeric(6); createPerson(userName, "myTitle", "myFirstName", "myLastName", "myOrganisation", "myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", Status.STATUS_OK); // Delete the person deletePerson(userName, Status.STATUS_OK); // Make sure that the person has been deleted and no longer exists deletePerson(userName, Status.STATUS_NOT_FOUND); }
From source file:org.alfresco.repo.web.scripts.person.PersonServiceTest.java
public void testCreatePerson() throws Exception { String userName = RandomStringUtils.randomNumeric(6); // Create a new person JSONObject result = createPerson(userName, "myTitle", "myFirstName", "myLastName", "myOrganisation", "myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", Status.STATUS_OK); assertEquals(userName, result.get("userName")); assertEquals("myFirstName", result.get("firstName")); assertEquals("myLastName", result.get("lastName")); assertEquals("myOrganisation", result.get("organization")); assertEquals("myJobTitle", result.get("jobtitle")); assertEquals("firstName.lastName@email.com", result.get("email")); // Check for duplicate names createPerson(userName, "myTitle", "myFirstName", "mylastName", "myOrganisation", "myJobTitle", "myEmail", "myBio", "images/avatar.jpg", 409); }
From source file:org.alfresco.repo.web.scripts.person.PersonServiceTest.java
public void testCreatePersonMissingFirstName() throws Exception { String userName = RandomStringUtils.randomNumeric(6); // Create a new person with firstName == null (first name missing) createPerson(userName, "myTitle", null, "myLastName", "myOrganisation", "myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", Status.STATUS_BAD_REQUEST); // Create a new person with firstName == "" (first name is blank) createPerson(userName, "myTitle", "", "myLastName", "myOrganisation", "myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", Status.STATUS_BAD_REQUEST); }
From source file:org.alfresco.repo.web.scripts.person.PersonServiceTest.java
public void testDisableEnablePerson() throws Exception { String userName = RandomStringUtils.randomNumeric(6); // Create a new person createPerson(userName, "myTitle", "myFirstName", "myLastName", "myOrganisation", "myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", Status.STATUS_OK); String currentUser = this.authenticationComponent.getCurrentUserName(); String adminUser = this.authenticationComponent.getSystemUserName(); this.authenticationComponent.setCurrentUser(adminUser); // Check if user is enabled assertTrue("User isn't enabled", personService.isEnabled(userName)); this.authenticationComponent.setCurrentUser(adminUser); // Disable user authenticationService.setAuthenticationEnabled(userName, false); this.authenticationComponent.setCurrentUser(adminUser); // Check user status assertFalse("User must be disabled", personService.isEnabled(userName)); // Delete the person deletePerson(userName, Status.STATUS_OK); this.authenticationComponent.setCurrentUser(currentUser); }
From source file:org.apache.activemq.web.RestTest.java
@Test(timeout = 15 * 1000) public void testCorrelation() throws Exception { int port = getPort(); HttpClient httpClient = new HttpClient(); httpClient.start();/*from w ww . ja v a 2 s. co m*/ for (int i = 0; i < 200; i++) { String correlId = "RESTY" + RandomStringUtils.randomNumeric(10); TextMessage message = session.createTextMessage(correlId); message.setStringProperty("correlationId", correlId); message.setJMSCorrelationID(correlId); LOG.info("Sending: " + correlId); producer.send(message); final StringBuffer buf = new StringBuffer(); final CountDownLatch latch = asyncRequest(httpClient, "http://localhost:" + port + "/message/test?readTimeout=1000&type=queue&clientId=test", buf); latch.await(); LOG.info("Received: " + buf.toString()); // assertEquals(200, contentExchange.getResponseStatus()); assertEquals(correlId, buf.toString()); } httpClient.stop(); }