List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphanumeric
public static String randomAlphanumeric(int count)
Creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of alpha-numeric characters.
From source file:com.google.code.ssm.aop.ReadThroughMultiCacheTest.java
@Test public void testConvertIdObject() throws Exception { final AnnotationData data = new AnnotationData(); data.setNamespace(RandomStringUtils.randomAlphanumeric(6)); final Map<String, Object> expectedString2Object = new HashMap<String, Object>(); final Map<Object, String> expectedObject2String = new HashMap<Object, String>(); final List<Object> idObjects = new ArrayList<Object>(); final int length = 10; for (int ix = 0; ix < length; ix++) { final String object = RandomStringUtils.randomAlphanumeric(2 + ix); final String key = cut.getCacheBase().getCacheKeyBuilder().getCacheKey(object, data.getNamespace()); idObjects.add(object);/*from ww w .j a va 2 s . com*/ expectedObject2String.put(object, key); expectedString2Object.put(key, object); } /* * final List<Object> exceptionObjects = new ArrayList<Object>(idObjects); Object[] objs = new Object[] { * exceptionObjects }; exceptionObjects.add(null); try { cut.convertIdObjectsToKeyMap(exceptionObjects, objs, 0, * data); fail("Expected Exception"); } catch (InvalidParameterException ex) { } * * for (int ix = 0; ix < length; ix++) { if (ix % 2 == 0) { idObjects.add(idObjects.get(ix)); } } * assertTrue(idObjects.size() > length); * * final ReadThroughMultiCacheAdvice.MapHolder holder = cut.convertIdObjectsToKeyMap(idObjects, new Object[] { * idObjects }, 0, data); * * assertEquals(length, holder.getKey2Obj().size()); assertEquals(length, holder.getObj2Key().size()); * * assertEquals(expectedObject2String, holder.getObj2Key()); assertEquals(expectedString2Object, * holder.getKey2Obj()); * * coord.setHolder(holder); * * assertEquals(expectedObject2String, coord.getObj2Key()); assertEquals(expectedString2Object, * coord.getKey2Obj()); */ }
From source file:de.thorstenberger.examServer.webapp.action.userimport.AbstractImportMembersAction.java
/** * Add imported members as users into our own user management system. * * @param members/*from w w w . ja v a 2 s.c o m*/ * opal members * @return all successfully imported users */ protected List<Member> storeImportedUsers(final List<Member> members) { final UserManager um = (UserManager) getBean("userManager"); final RoleManager rm = (RoleManager) getBean("roleManager"); final List<Member> importedMembers = new ArrayList<Member>(); for (final Member member : members) { try { um.getUserByUsername(member.getMemberId()); } catch (final UsernameNotFoundException e) { final User user = new User(); user.addRole(rm.getRole("student")); user.setUsername(member.getMemberId()); user.setFirstName(member.getFirstname()); user.setLastName(member.getLastname()); // use random password, needs to be changed manually // or not used at all (i.e. use remote authentication) user.setPassword(RandomStringUtils.randomAlphanumeric(10)); user.setAccountExpired(false); user.setAccountLocked(false); user.setCredentialsExpired(false); user.setEnabled(true); try { um.saveUser(user); importedMembers.add(member); } catch (final UserExistsException e1) { log.error("User exists, this error should never occur!", e1); } } } return importedMembers; }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.servlet.MMXTopicResourceTest.java
private static void setupMocks() { new MockUp<TopicResource>() { @Mock//w w w .j a va2 s. c o m protected List<TopicSubscription> getTopicSubscriptions(String appId, String topicName) { LOGGER.trace("MOCKED getTopicSubscriptions : appid={}, topicName={}", appId, topicName); String topicId = TopicHelper.makeTopic(appId, null, topicName); List<TopicSubscription> list = new ArrayList<TopicSubscription>(10); for (int i = 0; i < 100; i++) { StubTopicSubscription subscription = new StubTopicSubscription(); subscription.setTopic(topicName); subscription.setUsername(RandomStringUtils.randomAlphanumeric(3)); subscription.setSubscriptionId(RandomStringUtils.randomAlphanumeric(10)); if (i % 3 == 0) { subscription.setDeviceId(RandomStringUtils.randomNumeric(10)); } list.add(subscription); } return list; } }; //for allowing auth new MockUp<AuthUtil>() { @Mock public boolean isAuthorized(HttpServletRequest headers) throws IOException { return true; } }; /** * For using the db unit datasource */ new MockUp<TopicResource>() { @Mock public ConnectionProvider getConnectionProvider() { return new BasicDataSourceConnectionProvider(ds); } }; }
From source file:com.highcharts.export.util.SVGCreator.java
public File createUniqueFile(String content, String extension) throws IOException { File file = File.createTempFile(RandomStringUtils.randomAlphanumeric(8), extension); writeFile(file, content);/*from w w w .j a v a2 s . com*/ return file; }
From source file:com.google.code.ssm.aop.UpdateMultiCacheAdviceTest.java
@Test public void testGetCacheKeys() throws Exception { final int size = 10; final List<Object> sources = new ArrayList<Object>(); for (int ix = 0; ix < size; ix++) { sources.add(RandomStringUtils.randomAlphanumeric(3 + ix)); }//w w w. j a v a2 s. c o m final String namespace = RandomStringUtils.randomAlphabetic(20); final AnnotationData annotationData = new AnnotationData(); annotationData.setNamespace(namespace); final List<String> results = cut.getCacheBase().getCacheKeyBuilder().getCacheKeys(sources, annotationData.getNamespace()); assertEquals(size, results.size()); for (int ix = 0; ix < size; ix++) { final String result = results.get(ix); assertTrue(result.indexOf(namespace) != -1); final String source = (String) sources.get(ix); assertTrue(result.indexOf(source) != -1); } }
From source file:alluxio.master.meta.checkconf.ServerConfigurationCheckerTest.java
@Test public void checkConf() { // Prepare data PropertyKey keyMasterEnforce = new PropertyKey.Builder("TestKey1") .setConsistencyCheckLevel(PropertyKey.ConsistencyCheckLevel.ENFORCE).setScope(Scope.MASTER).build(); ConfigProperty masterEnforceProp = new ConfigProperty().setName(keyMasterEnforce.getName()) .setSource("Test").setValue("Value"); PropertyKey keyWorkerWarn = new PropertyKey.Builder("TestKey2") .setConsistencyCheckLevel(PropertyKey.ConsistencyCheckLevel.WARN).setScope(Scope.WORKER).build(); ConfigProperty workerWarnProp = new ConfigProperty().setName(keyWorkerWarn.getName()).setSource("Test") .setValue("Value"); PropertyKey keyServerEnforce = new PropertyKey.Builder("TestKey3") .setConsistencyCheckLevel(PropertyKey.ConsistencyCheckLevel.ENFORCE).setScope(Scope.SERVER).build(); ConfigProperty serverEnforceProp = new ConfigProperty().setName(keyServerEnforce.getName()) .setSource("Test").setValue("Value"); Random random = new Random(); Address addressOne = new Address(RandomStringUtils.randomAlphanumeric(10), random.nextInt()); Address addressTwo = new Address(RandomStringUtils.randomAlphanumeric(10), random.nextInt()); // When records have nothing different, no errors or warns will be found mRecordOne.registerNewConf(addressOne, Arrays.asList(masterEnforceProp, workerWarnProp)); mRecordTwo.registerNewConf(addressTwo, Arrays.asList(masterEnforceProp, workerWarnProp)); checkResults(0, 0, ConfigStatus.PASSED); // When records have a wrong warn property, checker should be able to find config warns ConfigProperty wrongWorkerWarnProp = new ConfigProperty().setName(workerWarnProp.getName()) .setSource(workerWarnProp.getSource()).setValue("WrongValue"); mRecordOne.registerNewConf(addressOne, Arrays.asList(masterEnforceProp, wrongWorkerWarnProp)); checkResults(0, 1, ConfigStatus.WARN); // When records have a wrong enforce property, checker should be able to find config errors ConfigProperty wrongMasterEnforceProp = new ConfigProperty().setName(masterEnforceProp.getName()) .setSource(masterEnforceProp.getSource()).setValue("WrongValue"); mRecordTwo.registerNewConf(addressTwo, Arrays.asList(wrongMasterEnforceProp, workerWarnProp)); checkResults(1, 1, ConfigStatus.FAILED); ConfigProperty wrongServerEnforceProp = new ConfigProperty().setName(serverEnforceProp.getName()) .setSource(serverEnforceProp.getSource()).setValue("WrongValue"); mRecordOne.registerNewConf(addressOne, Arrays.asList(masterEnforceProp, workerWarnProp, serverEnforceProp)); mRecordTwo.registerNewConf(addressTwo, Arrays.asList(masterEnforceProp, workerWarnProp, wrongServerEnforceProp)); checkResults(1, 0, ConfigCheckReport.ConfigStatus.FAILED); }
From source file:com.xtructure.xutil.valid.strategy.UTestTestValidationStrategy.java
public void processFailureBehavesAsExpected() { Condition predicate = isNotNull(); Object object = null;/* w w w . jav a 2 s. c om*/ String msg = RandomStringUtils.randomAlphanumeric(10); TestValidationStrategy<Object> vs = new TestValidationStrategy<Object>(predicate); try { vs.validate(object); } catch (AssertionError e) { if (!String.format("%s (%s): %s", TestValidationStrategy.DEFAULT_MSG, object, predicate) .equals(e.getMessage())) { throw new AssertionError(); } } try { vs.validate(object, msg); } catch (AssertionError e) { if (!String.format("%s (%s): %s", msg, object, predicate).equals(e.getMessage())) { throw new AssertionError(); } } }
From source file:com.xtructure.xutil.valid.strategy.UTestStateValidationStrategy.java
public void processFailureBehavesAsExpected() { Condition predicate = isNotNull(); Object object = null;/* ww w . j a v a2 s. c o m*/ String msg = RandomStringUtils.randomAlphanumeric(10); StateValidationStrategy<Object> vs = new StateValidationStrategy<Object>(predicate); try { vs.validate(object); } catch (IllegalStateException e) { if (!String.format("%s (%s): %s", StateValidationStrategy.DEFAULT_MSG, object, predicate) .equals(e.getMessage())) { throw new AssertionError(); } } try { vs.validate(object, msg); } catch (IllegalStateException e) { if (!String.format("%s (%s): %s", msg, object, predicate).equals(e.getMessage())) { throw new AssertionError(); } } }
From source file:com.openkm.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;//from w w w . jav a 2s . co m if (Config.USER_PASSWORD_RESET) { 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); } } else { sc.getRequestDispatcher("/login.jsp").forward(request, response); } }
From source file:net.przemkovv.sphinx.executor.SimpleExecutorNGTest.java
@Test(expectedExceptions = IOException.class) public void testExecuteExecutableNonExists() throws Exception { SimpleExecutor instance = new SimpleExecutor(new File(RandomStringUtils.randomAlphanumeric(8))); instance.execute(null);/* www.j a v a2s . c om*/ }