List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphabetic
public static String randomAlphabetic(int count)
Creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of alphabetic characters.
From source file:com.haulmont.cuba.gui.relatedentities.RelatedEntitiesBean.java
@Nullable protected AbstractCondition getManyToOneCondition(List<Object> parentIds, CollectionDatasource datasource, String filterComponentName, String relatedPrimaryKey, MetaDataDescriptor descriptor) { MetaClass metaClass = descriptor.getMetaClass(); String parentPrimaryKey = metadataTools.getPrimaryKeyName(metaClass); CustomCondition customCondition = getParentEntitiesCondition(parentIds, parentPrimaryKey, datasource, filterComponentName, metaClass); String entityAlias = RandomStringUtils.randomAlphabetic(6); String subQuery = String.format("select %s.%s.%s from %s %s where %s.%s in :%s", entityAlias, descriptor.getMetaProperty().getName(), relatedPrimaryKey, metaClass.getName(), entityAlias, entityAlias, parentPrimaryKey, customCondition.getParam().getName()); String whereString = String.format("{E}.%s in (%s)", relatedPrimaryKey, subQuery); customCondition.setWhere(whereString); return customCondition; }
From source file:com.ironiacorp.statistics.r.AbstractRClient.java
@Override public LinearModelSummary linearModel(double[] data, ObjectMatrix<String, String, Object> d) { String datName = RandomStringUtils.randomAlphabetic(10); assign(datName, data);//from w w w. j a v a 2 s . c o m String df = dataFrame(d); String varNames = StringUtils.join(d.getColNames(), "+"); String lmName = RandomStringUtils.randomAlphabetic(10); String command = lmName + "<-lm(" + datName + " ~ " + varNames + ", data=" + df + ", na.action=na.exclude)"; voidEval(command); REXP lmsum = eval("summary(" + lmName + ")"); REXP anova = eval("anova(" + lmName + ")"); return new LinearModelSummary(lmsum, anova, d.getColNames().toArray(new String[] {})); }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.api.tags.MMXDeviceTagsResourceTest.java
@Test public void testInvalidTagChars() { List<String> tagList1 = Arrays.asList(RandomStringUtils.randomAlphabetic(1000), "tag2", "tag3", "tag4", "tag5", "tag6"); List<String> tagList2 = Arrays.asList("tag1", "", "tag3", "tag4", "tag5", "tag6"); List<String> tagList3 = Arrays.asList("tag1", null, "tag3", "tag4", "tag5", "tag6"); String deviceId = deviceEntityList.get(0).getDeviceId(); //set tags/*from ww w .j av a2 s. com*/ { Response response = setTags(deviceId, tagList1); assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode()); response.close(); } //set tags { Response response = setTags(deviceId, tagList2); assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode()); response.close(); } { Response response = setTags(deviceId, tagList3); assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode()); response.close(); } }
From source file:com.ironiacorp.statistics.r.AbstractRClient.java
@Override @SuppressWarnings({ "unchecked", "cast" }) public LinearModelSummary linearModel(double[] data, Map<String, List<?>> factors) { String datName = RandomStringUtils.randomAlphabetic(10); assign(datName, data);//from www . j a v a 2 s . c o m for (String factorName : factors.keySet()) { List<?> list = factors.get(factorName); if (list.iterator().next() instanceof String) { assignFactor(factorName, (List<String>) list); } else { // treat is as a numeric covariate List<Double> d = new ArrayList<Double>(); for (Object object : list) { d.add((Double) object); } assign(factorName, ArrayUtils.toPrimitive(d.toArray(new Double[] {}))); } } String modelDeclaration = datName + " ~ " + StringUtils.join(factors.keySet(), "+"); String lmName = RandomStringUtils.randomAlphabetic(10); String command = lmName + "<-lm(" + modelDeclaration + ", na.action=na.exclude)"; voidEval(command); REXP lmsum = eval("summary(" + lmName + ")"); REXP anova = eval("anova(" + lmName + ")"); return new LinearModelSummary(lmsum, anova, factors.keySet().toArray(new String[] {})); }
From source file:com.haulmont.cuba.gui.relatedentities.RelatedEntitiesBean.java
protected CustomCondition getParentEntitiesCondition(List<Object> parentIds, String parentPrimaryKey, CollectionDatasource datasource, String filterComponentName, MetaClass parentMetaClass) { String conditionName = String.format("related_%s", RandomStringUtils.randomAlphabetic(6)); CustomCondition condition = new CustomCondition(getConditionXmlElement(conditionName, parentMetaClass), AppConfig.getMessagesPack(), filterComponentName, datasource); Class<?> parentPrimaryKeyClass = parentMetaClass.getPropertyNN(parentPrimaryKey).getJavaType(); condition.setJavaClass(parentPrimaryKeyClass); condition.setHidden(true);/*from w ww . j a v a 2 s . c om*/ condition.setInExpr(true); int randInt = new Random().nextInt((99999 - 11111) + 1) + 11111; String paramName = String.format("component$%s.%s%s", filterComponentName, conditionName, randInt); condition.setParam(getParentEntitiesParam(parentIds, parentPrimaryKey, datasource, parentPrimaryKeyClass, paramName, parentMetaClass)); return condition; }
From source file:com.kixeye.chassis.transport.HttpTransportTest.java
@Test public void testHttpServiceWithJsonWithHTTPS() throws Exception { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("https.enabled", "true"); properties.put("https.port", "" + SocketUtils.findAvailableTcpPort()); properties.put("https.hostname", "localhost"); properties.put("https.selfSigned", "true"); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addFirst(new MapPropertySource("default", properties)); context.setEnvironment(environment); context.register(PropertySourcesPlaceholderConfigurer.class); context.register(TransportConfiguration.class); context.register(TestRestService.class); try {/* w w w. ja v a 2s . c o m*/ context.refresh(); final MessageSerDe serDe = context.getBean(JsonJacksonMessageSerDe.class); SSLContextBuilder builder = SSLContexts.custom(); builder.loadTrustMaterial(null, new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }); SSLContext sslContext = builder.build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new X509HostnameVerifier() { @Override public void verify(String host, SSLSocket ssl) throws IOException { } @Override public void verify(String host, X509Certificate cert) throws SSLException { } @Override public void verify(String host, String[] cns, String[] subjectAlts) throws SSLException { } @Override public boolean verify(String s, SSLSession sslSession) { return true; } }); Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder .<ConnectionSocketFactory>create().register("https", sslsf).build(); PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(socketFactoryRegistry); HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); requestFactory.setHttpClient(HttpClients.custom().setConnectionManager(cm).build()); RestTemplate httpClient = new RestTemplate(requestFactory); httpClient.setErrorHandler(new ResponseErrorHandler() { public boolean hasError(ClientHttpResponse response) throws IOException { return response.getRawStatusCode() == HttpStatus.OK.value(); } public void handleError(ClientHttpResponse response) throws IOException { } }); httpClient.setInterceptors(Lists.newArrayList(LOGGING_INTERCEPTOR)); httpClient.setMessageConverters(new ArrayList<HttpMessageConverter<?>>( Lists.newArrayList(new SerDeHttpMessageConverter(serDe)))); TestObject response = httpClient.getForObject( new URI("https://localhost:" + properties.get("https.port") + "/stuff/"), TestObject.class); Assert.assertNotNull(response); Assert.assertEquals("stuff", response.value); response = httpClient.postForObject( new URI("https://localhost:" + properties.get("https.port") + "/stuff/"), new TestObject("more stuff"), TestObject.class); Assert.assertNotNull(response); Assert.assertEquals("stuff", response.value); response = httpClient.getForObject( new URI("https://localhost:" + properties.get("https.port") + "/stuff/"), TestObject.class); Assert.assertNotNull(response); Assert.assertEquals("more stuff", response.value); response = httpClient.getForObject( new URI("https://localhost:" + properties.get("https.port") + "/stuff/getFuture"), TestObject.class); Assert.assertNotNull(response); Assert.assertEquals("more stuff", response.value); response = httpClient.getForObject( new URI("https://localhost:" + properties.get("https.port") + "/stuff/getObservable"), TestObject.class); Assert.assertNotNull(response); Assert.assertEquals("more stuff", response.value); ResponseEntity<ServiceError> error = httpClient.postForEntity( new URI("https://localhost:" + properties.get("https.port") + "/stuff/"), new TestObject(RandomStringUtils.randomAlphabetic(100)), ServiceError.class); Assert.assertNotNull(response); Assert.assertEquals(HttpStatus.BAD_REQUEST, error.getStatusCode()); Assert.assertEquals(ExceptionServiceErrorMapper.VALIDATION_ERROR_CODE, error.getBody().code); error = httpClient.getForEntity( new URI("https://localhost:" + properties.get("https.port") + "/stuff/expectedError"), ServiceError.class); Assert.assertNotNull(response); Assert.assertEquals(TestRestService.EXPECTED_EXCEPTION_HTTP_CODE, error.getStatusCode()); Assert.assertEquals(TestRestService.EXPECTED_EXCEPTION.code, error.getBody().code); Assert.assertEquals(TestRestService.EXPECTED_EXCEPTION.description, error.getBody().description); error = httpClient.getForEntity( new URI("https://localhost:" + properties.get("https.port") + "/stuff/unexpectedError"), ServiceError.class); Assert.assertNotNull(response); Assert.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, error.getStatusCode()); Assert.assertEquals(ExceptionServiceErrorMapper.UNKNOWN_ERROR_CODE, error.getBody().code); } finally { context.close(); } }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.api.topics.MMXTopicsItemsResourceTest.java
public static String getRandomPublishedItemPayload(Date creationDate) { String base = "<mmx xmlns=\"com.magnet:msg:payload\">" + "<meta>%s</meta>" + "<payload mtype=\"text/plain\" chunk=\"0/7/7\" stamp=\"%s\">%s</payload></mmx>"; int numKeys = RandomUtils.nextInt(1, 10); String keySuffix = RandomStringUtils.randomAlphabetic(3); Map<String, String> map = new HashMap<String, String>(); for (int i = 0; i < numKeys; i++) { map.put("key" + keySuffix + i, RandomStringUtils.randomAlphabetic(10)); }/*www . ja va 2 s .c om*/ Gson gson = new Gson(); String mapStr = gson.toJson(map); return String.format(base, mapStr, new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ").format(creationDate), RandomStringUtils.randomAlphabetic(25)); }
From source file:com.gs.collections.impl.parallel.SerialParallelLazyPerformanceTest.java
public UnifiedSet<String> generateWordsList(int count) { UnifiedSet<String> words = UnifiedSet.newSet(); while (words.size() < count) { words.add(RandomStringUtils.randomAlphabetic(5)); }// ww w . j a va 2s . com return words; }
From source file:com.google.cloud.bigtable.hbase.TestFilters.java
/** * Requirement 9.5 - RowFilter - filter by rowkey against a given Comparable * * Test the BinaryComparator against EQUAL, GREATER, GREATER_OR_EQUAL, LESS, LESS_OR_EQUAL, * NOT_EQUAL, and NO_OP. BinaryComparator compares two byte arrays lexicographically using * Bytes.compareTo(byte[], byte[]).//from w ww. j av a 2 s .com */ @Test @Category(KnownGap.class) public void testRowFilterBinaryComparator() throws Exception { // Initialize data Table table = getTable(); String rowKeyPrefix = "testRowFilter-" + RandomStringUtils.randomAlphabetic(10); byte[] rowKey1 = Bytes.toBytes(rowKeyPrefix + "A"); byte[] rowKey2 = Bytes.toBytes(rowKeyPrefix + "AA"); byte[] rowKey3 = Bytes.toBytes(rowKeyPrefix + "B"); byte[] rowKey4 = Bytes.toBytes(rowKeyPrefix + "BB"); byte[] qual = Bytes.toBytes("testqual"); byte[] value = Bytes.toBytes("testvalue"); for (byte[] rowKey : new byte[][] { rowKey1, rowKey2, rowKey3, rowKey4 }) { Put put = new Put(rowKey).addColumn(COLUMN_FAMILY, qual, value); table.put(put); } // Test BinaryComparator - EQUAL ByteArrayComparable rowKey2Comparable = new BinaryComparator(rowKey2); Filter filter = new RowFilter(CompareFilter.CompareOp.EQUAL, rowKey2Comparable); Result[] results = scanWithFilter(table, rowKey1, rowKey4, qual, filter); Assert.assertEquals("# results", 1, results.length); Assert.assertArrayEquals(rowKey2, results[0].getRow()); // Test BinaryComparator - GREATER filter = new RowFilter(CompareFilter.CompareOp.GREATER, rowKey2Comparable); results = scanWithFilter(table, rowKey1, rowKey4, qual, filter); Assert.assertEquals("# results", 1, results.length); Assert.assertArrayEquals(rowKey3, results[0].getRow()); // Test BinaryComparator - GREATER_OR_EQUAL filter = new RowFilter(CompareFilter.CompareOp.GREATER_OR_EQUAL, rowKey2Comparable); results = scanWithFilter(table, rowKey1, rowKey4, qual, filter); Assert.assertEquals("# results", 2, results.length); Assert.assertArrayEquals(rowKey2, results[0].getRow()); Assert.assertArrayEquals(rowKey3, results[1].getRow()); // Test BinaryComparator - LESS filter = new RowFilter(CompareFilter.CompareOp.LESS, rowKey2Comparable); results = scanWithFilter(table, rowKey1, rowKey4, qual, filter); Assert.assertEquals("# results", 1, results.length); Assert.assertArrayEquals(rowKey1, results[0].getRow()); // Test BinaryComparator - LESS_OR_EQUAL filter = new RowFilter(CompareFilter.CompareOp.LESS_OR_EQUAL, rowKey2Comparable); results = scanWithFilter(table, rowKey1, rowKey4, qual, filter); Assert.assertEquals("# results", 2, results.length); Assert.assertArrayEquals(rowKey1, results[0].getRow()); Assert.assertArrayEquals(rowKey2, results[1].getRow()); // Test BinaryComparator - NOT_EQUAL filter = new RowFilter(CompareFilter.CompareOp.NOT_EQUAL, rowKey2Comparable); results = scanWithFilter(table, rowKey1, rowKey4, qual, filter); Assert.assertEquals("# results", 2, results.length); Assert.assertArrayEquals(rowKey1, results[0].getRow()); Assert.assertArrayEquals(rowKey3, results[1].getRow()); // Test BinaryComparator - NO_OP filter = new RowFilter(CompareFilter.CompareOp.NO_OP, rowKey2Comparable); results = scanWithFilter(table, rowKey1, rowKey4, qual, filter); Assert.assertEquals("# results", 0, results.length); table.close(); }
From source file:com.zimbra.cs.mime.MimeTest.java
@Test @Ignore("expensive test") public void bigMime() throws Exception { String content = baseMpMixedContent + "\r\n"; StringBuilder sb = new StringBuilder(content); long total = 0; int count = 10; int partCount = 100; int textcount = 1000000; int lineSize = 200; for (int i = 0; i < partCount; i++) { sb.append("------------1111971890AC3BB91\r\n") .append("Content-Type: text/plain; charset=windows-1250\r\n") .append("Content-Transfer-Encoding: quoted-printable\r\n\r\n"); for (int j = 0; j < textcount; j += lineSize) { String text = RandomStringUtils.randomAlphabetic(lineSize); sb.append(text).append("\r\n"); }/*from ww w . j av a2 s. c o m*/ sb.append("\r\n"); } for (int i = 0; i < count; i++) { long start = System.currentTimeMillis(); MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(sb.toString().getBytes())); List<MPartInfo> parts = Mime.getParts(mm); long end = System.currentTimeMillis(); total += (end - start); ZimbraLog.test.info("took %dms", end - start); Assert.assertNotNull(parts); Assert.assertEquals(partCount + 1, parts.size()); MPartInfo body = Mime.getTextBody(parts, false); Assert.assertNotNull(body); } ZimbraLog.test.info("Avg %dms", total / count); }