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.jslsolucoes.tagria.lib.util.TagUtil.java
public static String getId(String name, String id, SimpleTagSupport simpleTagSupport) { String idForComponent = "par_" + RandomStringUtils.randomAlphanumeric(20); if (!StringUtils.isEmpty(id)) { idForComponent = id;/*from ww w. j a v a2s . c om*/ } else if (!StringUtils.isEmpty(name)) { idForComponent = "par_" + name.replaceAll("\\.", "_").replaceAll("\\[([0-9]{1,}|)\\]", ""); } return idForComponent + complementForDetailTable(simpleTagSupport); }
From source file:fm.last.moji.integration.AbstractMojiIT.java
String newKey() {
return newKey(RandomStringUtils.randomAlphanumeric(16));
}
From source file:com.xtructure.xutil.xml.UTestXmlUnit.java
public void toStringReturnsExpectedString() { String name = RandomStringUtils.randomAlphanumeric(10); String expectedAttribute = String.format("%s{%s}", Attribute.class.getSimpleName(), name); String expectedElement = String.format("%s{%s}", Element.class.getSimpleName(), name); assertThat("", // XmlUnit.newAttribute(name).toString(), isEqualTo(expectedAttribute)); assertThat("", // XmlUnit.newAttribute(name, Double.class).toString(), isEqualTo(expectedAttribute)); assertThat("", // XmlUnit.newElement(name).toString(), isEqualTo(expectedElement)); assertThat("", // XmlUnit.newElement(name, Double.class).toString(), isEqualTo(expectedElement)); }
From source file:com.linkedin.pinot.index.readerwriter.FixedByteSingleValueMultiColumnReaderWriterTest.java
private void testSequentialReadWrite(int startOffset) { int[] intValues = new int[NUM_ROWS]; long[] longValues = new long[NUM_ROWS]; float[] floatValues = new float[NUM_ROWS]; double[] doubleValues = new double[NUM_ROWS]; String[] stringValues = new String[NUM_ROWS]; for (int i = 0; i < NUM_ROWS; i++) { int row = i + startOffset; intValues[i] = _random.nextInt(); _readerWriter.setInt(row, 0, intValues[i]); longValues[i] = _random.nextLong(); _readerWriter.setLong(row, 1, longValues[i]); floatValues[i] = _random.nextFloat(); _readerWriter.setFloat(row, 2, floatValues[i]); doubleValues[i] = _random.nextDouble(); _readerWriter.setDouble(row, 3, doubleValues[i]); stringValues[i] = RandomStringUtils.randomAlphanumeric(STRING_LENGTH); _readerWriter.setString(row, 4, stringValues[i]); }/* w ww.ja va 2 s . c om*/ for (int i = 0; i < NUM_ROWS; i++) { int row = i + startOffset; Assert.assertEquals(_readerWriter.getInt(row, 0), intValues[i]); Assert.assertEquals(_readerWriter.getLong(row, 1), longValues[i]); Assert.assertEquals(_readerWriter.getFloat(row, 2), floatValues[i]); Assert.assertEquals(_readerWriter.getDouble(row, 3), doubleValues[i]); Assert.assertEquals(_readerWriter.getString(row, 4), stringValues[i]); } }
From source file:Highcharts.SVGConverter.java
public String createUniqueFileName(String extension) throws IOException { return System.getProperty("java.io.tmpdir") + "/" + RandomStringUtils.randomAlphanumeric(8) + extension; }
From source file:com.xwiki.authentication.sts.XWikiSTSAuthenticator.java
/** * showLogin - Makes appropriate url and sends request to the STS (Security Token Service) * and gets response with xwiki methods. * //from w ww.java2s .com * @param context XWikiContext - context - to make request and show login * @throws XWikiException java.lang.Object extended by java.lang.Throwable </br> extended by java.lang.Exception extended by com.xpn.xwiki.XWikiException */ @Override public void showLogin(XWikiContext context) throws XWikiException { log.trace("showLogin()"); XWikiRequest request = context.getRequest(); try { DefaultBootstrap.bootstrap(); } catch (ConfigurationException e) { log.error("Failed to bootstrap sts module" + e); errorCollector.addError(new Throwable("Failed to bootstrap sts module: ", e)); } // STS provider URL String url = props.getAuthURL(context) + "?wa=wsignin1.0"; // Request realm String wtrealm = props.getWtrealm(context); if (wtrealm != null && wtrealm != "") url += "&wtrealm=" + escapeHtml(wtrealm); // Request ID String wctx = props.getWctx(context); if (wctx != null && "1".equals(wctx)) { String randId = RandomStringUtils.randomAlphanumeric(42); log.debug("Request ID: " + randId); request.getSession().setAttribute("saml_id", randId); url += "&wctx=" + randId; } // Host is set manually, because XWiki is behind proxy server // and simple XWiki.getRequestURL(request) returns localhost String wreplyHost = props.getWreplyHost(context); String wreplyPage = props.getWreplyPage(context); String page = "/"; if (wreplyHost != null && !"0".equals(wreplyHost)) { if ("1".equals(wreplyPage) || "shorten".equals(wreplyPage)) { page = request.getParameter("xredirect"); if (page != null) log.trace("Got xrecdirect to: " + page); else page = XWiki.getRequestURL(request).getFile(); if ("shorten".equals(wreplyPage)) { // change reply address if URL shortening is used page = page.replace("/xwiki/bin/view/", "/"); page = page.replace("/WebHome", "/"); } log.trace("Reply page: " + page); } url += "&wreply=" + escapeHtml(wreplyHost + page); } request.getSession().setAttribute("saml_url", wreplyHost + page); // Auth request time String wct = props.getWct(context); if (wct != null && "1".equals(wct)) { SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT")); wct = dateFormatGmt.format(new Date()); url += "&wct=" + wct; } // maximum age of authentication String wfresh = props.getWfresh(context); if (wfresh != null && wfresh != "" && Integer.parseInt(wfresh) > 0) { url += "&wfresh=" + wfresh; } // Send request to the STS service log.info("SAML STS request sent to " + url); try { context.getResponse().sendRedirect(url); context.setFinished(true); } catch (Exception e) { log.debug("Cannot call sendRedirect() after the response has been committed: " + e); } }
From source file:com.openkm.util.SecureStore.java
/** * Password generator./* w ww .ja v a 2 s . c o m*/ */ public static String generatePassword(int lenght) { return RandomStringUtils.randomAlphanumeric(lenght); }
From source file:info.bluefoot.winter.controller.PlaylistController.java
@RequestMapping(value = { "/playlist/delete" }, method = RequestMethod.POST, produces = "application/json") public @ResponseBody ResponseEntity<Map<String, String>> removePlaylist(Integer playlistId, HttpServletResponse response) {/*from w w w.ja v a 2 s . co m*/ try { playlistService.removePlaylistAndVideos(playlistId); } catch (Exception e) { String errorId = RandomStringUtils.randomAlphanumeric(6).toUpperCase(); logger.error("[" + errorId + "] Can't delete playlist", e); return new ResponseEntity<Map<String, String>>( Collections.singletonMap("error", "Can't delete playlist. Try again later. Error id: " + errorId + "."), HttpStatus.INTERNAL_SERVER_ERROR); } return new ResponseEntity<Map<String, String>>(Collections.singletonMap("sucess", "true"), HttpStatus.OK); }
From source file:com.xtructure.xutil.coll.UTestListBuilder.java
public void getImmutableCollectionReturnsExpectedObject() { List<String> list = new ArrayList<String>(); for (int i = 0; i < 10; i++) { list.add(RandomStringUtils.randomAlphanumeric(10)); }//from www. j a v a 2 s .c o m List<String> newList = new ListBuilder<String>(list).newImmutableInstance(); assertThat("", // list, isNotSameAs(newList)); assertThat("", // list, isEqualTo(newList)); }
From source file:io.pravega.test.integration.ControllerRestApiTest.java
@Test public void restApiTests() { Invocation.Builder builder;//from www .jav a2 s . c o m Response response; restServerURI = SETUP_UTILS.getControllerRestUri().toString(); log.info("REST Server URI: {}", restServerURI); // TEST REST server status, ping test resourceURl = new StringBuilder(restServerURI).append("/ping").toString(); webTarget = client.target(resourceURl); builder = webTarget.request(); response = builder.get(); assertEquals("Ping test", OK.getStatusCode(), response.getStatus()); log.info("REST Server is running. Ping successful."); final String scope1 = RandomStringUtils.randomAlphanumeric(10); final String stream1 = RandomStringUtils.randomAlphanumeric(10); // TEST CreateScope POST http://controllerURI:Port/v1/scopes resourceURl = new StringBuilder(restServerURI).append("/v1/scopes").toString(); webTarget = client.target(resourceURl); final CreateScopeRequest createScopeRequest = new CreateScopeRequest(); createScopeRequest.setScopeName(scope1); builder = webTarget.request(MediaType.APPLICATION_JSON_TYPE); response = builder.post(Entity.json(createScopeRequest)); assertEquals("Create scope status", CREATED.getStatusCode(), response.getStatus()); Assert.assertEquals("Create scope response", scope1, response.readEntity(ScopeProperty.class).getScopeName()); log.info("Create scope: {} successful ", scope1); // TEST CreateStream POST http://controllerURI:Port/v1/scopes/{scopeName}/streams resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + scope1 + "/streams").toString(); webTarget = client.target(resourceURl); CreateStreamRequest createStreamRequest = new CreateStreamRequest(); ScalingConfig scalingConfig = new ScalingConfig(); scalingConfig.setType(ScalingConfig.TypeEnum.FIXED_NUM_SEGMENTS); scalingConfig.setTargetRate(2); scalingConfig.scaleFactor(2); scalingConfig.minSegments(2); RetentionConfig retentionConfig = new RetentionConfig(); retentionConfig.setType(RetentionConfig.TypeEnum.LIMITED_DAYS); retentionConfig.setValue(123L); createStreamRequest.setStreamName(stream1); createStreamRequest.setScalingPolicy(scalingConfig); createStreamRequest.setRetentionPolicy(retentionConfig); builder = webTarget.request(MediaType.APPLICATION_JSON_TYPE); response = builder.post(Entity.json(createStreamRequest)); assertEquals("Create stream status", CREATED.getStatusCode(), response.getStatus()); final StreamProperty streamPropertyResponse = response.readEntity(StreamProperty.class); assertEquals("Scope name in response", scope1, streamPropertyResponse.getScopeName()); assertEquals("Stream name in response", stream1, streamPropertyResponse.getStreamName()); log.info("Create stream: {} successful", stream1); // Test listScopes GET http://controllerURI:Port/v1/scopes/{scopeName}/streams resourceURl = new StringBuilder(restServerURI).append("/v1/scopes").toString(); webTarget = client.target(resourceURl); builder = webTarget.request(); response = builder.get(); assertEquals("List scopes", OK.getStatusCode(), response.getStatus()); log.info("List scopes successful"); // Test listStream GET /v1/scopes/scope1/streams resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + scope1 + "/streams").toString(); webTarget = client.target(resourceURl); builder = webTarget.request(); response = builder.get(); assertEquals("List streams", OK.getStatusCode(), response.getStatus()); Assert.assertEquals("List streams size", 1, response.readEntity(StreamsList.class).getStreams().size()); log.info("List streams successful"); // Test getScope resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + scope1).toString(); response = client.target(resourceURl).request().get(); assertEquals("Get scope status", OK.getStatusCode(), response.getStatus()); assertEquals("Get scope scope1 response", scope1, response.readEntity(ScopeProperty.class).getScopeName()); log.info("Get scope successful"); // Test updateStream resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + scope1 + "/streams/" + stream1) .toString(); UpdateStreamRequest updateStreamRequest = new UpdateStreamRequest(); ScalingConfig scalingConfig1 = new ScalingConfig(); scalingConfig1.setType(ScalingConfig.TypeEnum.FIXED_NUM_SEGMENTS); scalingConfig1.setTargetRate(2); scalingConfig1.scaleFactor(3); // update existing scaleFactor from 2 to 3 scalingConfig1.minSegments(4); // update existing minSegments from 2 to 4 updateStreamRequest.setScalingPolicy(scalingConfig1); updateStreamRequest.setRetentionPolicy(retentionConfig); response = client.target(resourceURl).request(MediaType.APPLICATION_JSON_TYPE) .put(Entity.json(updateStreamRequest)); assertEquals("Update stream status", OK.getStatusCode(), response.getStatus()); assertEquals("Verify updated property", 4, response.readEntity(StreamProperty.class).getScalingPolicy().getMinSegments().intValue()); log.info("Update stream successful"); // Test getStream resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + scope1 + "/streams/" + stream1) .toString(); response = client.target(resourceURl).request().get(); assertEquals("Get stream status", OK.getStatusCode(), response.getStatus()); assertEquals("Get stream stream1 response", stream1, response.readEntity(StreamProperty.class).getStreamName()); log.info("Get stream successful"); // Test updateStreamState resourceURl = new StringBuilder(restServerURI) .append("/v1/scopes/" + scope1 + "/streams/" + stream1 + "/state").toString(); StreamState streamState = new StreamState(); streamState.setStreamState(StreamState.StreamStateEnum.SEALED); response = client.target(resourceURl).request(MediaType.APPLICATION_JSON_TYPE) .put(Entity.json(streamState)); assertEquals("UpdateStreamState status", OK.getStatusCode(), response.getStatus()); assertEquals("UpdateStreamState status in response", streamState.getStreamState(), response.readEntity(StreamState.class).getStreamState()); log.info("Update stream state successful"); // Test deleteStream resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + scope1 + "/streams/" + stream1) .toString(); response = client.target(resourceURl).request().delete(); assertEquals("DeleteStream status", NO_CONTENT.getStatusCode(), response.getStatus()); log.info("Delete stream successful"); // Test deleteScope resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + scope1).toString(); response = client.target(resourceURl).request().delete(); assertEquals("Get scope status", NO_CONTENT.getStatusCode(), response.getStatus()); log.info("Delete Scope successful"); // Test reader groups APIs. // Prepare the streams and readers using the admin client. final String testScope = RandomStringUtils.randomAlphanumeric(10); final String testStream1 = RandomStringUtils.randomAlphanumeric(10); final String testStream2 = RandomStringUtils.randomAlphanumeric(10); URI controllerUri = SETUP_UTILS.getControllerUri(); try (StreamManager streamManager = new StreamManagerImpl(controllerUri)) { log.info("Creating scope: {}", testScope); streamManager.createScope(testScope); log.info("Creating stream: {}", testStream1); StreamConfiguration streamConf1 = StreamConfiguration.builder().scope(testScope).streamName(testStream1) .scalingPolicy(ScalingPolicy.fixed(1)).build(); streamManager.createStream(testScope, testStream1, streamConf1); log.info("Creating stream: {}", testStream2); StreamConfiguration streamConf2 = StreamConfiguration.builder().scope(testScope).streamName(testStream2) .scalingPolicy(ScalingPolicy.fixed(1)).build(); streamManager.createStream(testScope, testStream2, streamConf2); } final String readerGroupName1 = RandomStringUtils.randomAlphanumeric(10); final String readerGroupName2 = RandomStringUtils.randomAlphanumeric(10); final String reader1 = RandomStringUtils.randomAlphanumeric(10); final String reader2 = RandomStringUtils.randomAlphanumeric(10); Controller controller = new ControllerImpl(controllerUri); try (ClientFactory clientFactory = new ClientFactoryImpl(testScope, controller); ReaderGroupManager readerGroupManager = ReaderGroupManager.withScope(testScope, controllerUri)) { readerGroupManager.createReaderGroup(readerGroupName1, ReaderGroupConfig.builder().startingTime(0).build(), new HashSet<>(Arrays.asList(testStream1, testStream2))); readerGroupManager.createReaderGroup(readerGroupName2, ReaderGroupConfig.builder().startingTime(0).build(), new HashSet<>(Arrays.asList(testStream1, testStream2))); clientFactory.createReader(reader1, readerGroupName1, new JavaSerializer<Long>(), ReaderConfig.builder().build()); clientFactory.createReader(reader2, readerGroupName1, new JavaSerializer<Long>(), ReaderConfig.builder().build()); } // Test fetching readergroups. resourceURl = new StringBuilder(restServerURI).append("/v1/scopes/" + testScope + "/readergroups") .toString(); response = client.target(resourceURl).request().get(); assertEquals("Get readergroups status", OK.getStatusCode(), response.getStatus()); ReaderGroupsList readerGroupsList = response.readEntity(ReaderGroupsList.class); assertEquals("Get readergroups size", 2, readerGroupsList.getReaderGroups().size()); assertTrue(readerGroupsList.getReaderGroups() .contains(new ReaderGroupsListReaderGroups().readerGroupName(readerGroupName1))); assertTrue(readerGroupsList.getReaderGroups() .contains(new ReaderGroupsListReaderGroups().readerGroupName(readerGroupName2))); log.info("Get readergroups successful"); // Test fetching readergroup info. resourceURl = new StringBuilder(restServerURI) .append("/v1/scopes/" + testScope + "/readergroups/" + readerGroupName1).toString(); response = client.target(resourceURl).request().get(); assertEquals("Get readergroup properties status", OK.getStatusCode(), response.getStatus()); ReaderGroupProperty readerGroupProperty = response.readEntity(ReaderGroupProperty.class); assertEquals("Get readergroup name", readerGroupName1, readerGroupProperty.getReaderGroupName()); assertEquals("Get readergroup scope name", testScope, readerGroupProperty.getScopeName()); assertEquals("Get readergroup streams size", 2, readerGroupProperty.getStreamList().size()); assertTrue(readerGroupProperty.getStreamList().contains(testStream1)); assertTrue(readerGroupProperty.getStreamList().contains(testStream2)); assertEquals("Get readergroup onlinereaders size", 2, readerGroupProperty.getOnlineReaderIds().size()); assertTrue(readerGroupProperty.getOnlineReaderIds().contains(reader1)); assertTrue(readerGroupProperty.getOnlineReaderIds().contains(reader2)); // Test readergroup or scope not found. resourceURl = new StringBuilder(restServerURI) .append("/v1/scopes/" + testScope + "/readergroups/" + "unknownreadergroup").toString(); response = client.target(resourceURl).request().get(); assertEquals("Get readergroup properties status", NOT_FOUND.getStatusCode(), response.getStatus()); resourceURl = new StringBuilder(restServerURI) .append("/v1/scopes/" + "unknownscope" + "/readergroups/" + readerGroupName1).toString(); response = client.target(resourceURl).request().get(); assertEquals("Get readergroup properties status", NOT_FOUND.getStatusCode(), response.getStatus()); log.info("Get readergroup properties successful"); log.info("Test restApiTests passed successfully!"); }