Java Code Examples for org.apache.commons.lang3.RandomStringUtils#randomAlphabetic()
The following examples show how to use
org.apache.commons.lang3.RandomStringUtils#randomAlphabetic() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CertificateGenerationRequestParametersTest.java From credhub with Apache License 2.0 | 6 votes |
@Test public void validate_rejectsAlternativeNamesThatAreTooLong() { final String maxLengthAlternativeName = RandomStringUtils.randomAlphabetic(57) + "." + RandomStringUtils.randomNumeric(63) + "." + RandomStringUtils.randomAlphabetic(63) + "." + RandomStringUtils.randomAlphabetic(63) + ".com"; subject.setAlternativeNames(new String[]{"abc.com", maxLengthAlternativeName}); subject.validate(); final String overlyLongAlternativeName = "." + RandomStringUtils.randomAlphabetic(58) + "." + RandomStringUtils.randomNumeric(63) + "." + RandomStringUtils.randomAlphabetic(63) + "." + RandomStringUtils.randomAlphabetic(63) + ".co"; subject.setAlternativeNames(new String[]{"abc.com", overlyLongAlternativeName}); try { subject.validate(); fail("should throw"); } catch (final ParameterizedValidationException e) { assertThat(e.getMessage(), equalTo(ErrorMessages.Credential.INVALID_CERTIFICATE_PARAMETER)); assertThat(e.getParameters(), equalTo(new Object[]{"alternative name", 253})); } }
Example 2
Source File: ConversationUpdateSampler.java From BotServiceStressToolkit with MIT License | 6 votes |
private String ensureFromUser() { JMeterContext context = getThreadContext(); JMeterVariables vars = context.getVariables(); String fromUserId = ""; if (getGenRandomUserIdPerThread()) { if (vars.get(Constants.USER) == null) { fromUserId = "user-" + RandomStringUtils.randomAlphabetic(3, 7); vars.put(Constants.USER, fromUserId); } else { fromUserId = vars.get(Constants.USER); } } else { fromUserId = getFromMemberId(); } return fromUserId; }
Example 3
Source File: TestDefaultCAServer.java From hadoop-ozone with Apache License 2.0 | 6 votes |
@Test public void testInit() throws SCMSecurityException, CertificateException, IOException { SecurityConfig securityConfig = new SecurityConfig(conf); CertificateServer testCA = new DefaultCAServer("testCA", RandomStringUtils.randomAlphabetic(4), RandomStringUtils.randomAlphabetic(4), caStore); testCA.init(securityConfig, CertificateServer.CAType.SELF_SIGNED_CA); X509CertificateHolder first = testCA.getCACertificate(); assertNotNull(first); //Init is idempotent. testCA.init(securityConfig, CertificateServer.CAType.SELF_SIGNED_CA); X509CertificateHolder second = testCA.getCACertificate(); assertEquals(first, second); // we only support Self Signed CA for now. try { testCA.init(securityConfig, CertificateServer.CAType.INTERMEDIARY_CA); fail("code should not reach here, exception should have been thrown."); } catch (IllegalStateException e) { // This is a run time exception, hence it is not caught by the junit // expected Exception. assertTrue(e.toString().contains("Not implemented")); } }
Example 4
Source File: TestOzoneManagerHAWithACL.java From hadoop-ozone with Apache License 2.0 | 6 votes |
@Test public void testAddPrefixAcl() throws Exception { OzoneBucket ozoneBucket = setupBucket(); String remoteUserName = "remoteUser"; String prefixName = RandomStringUtils.randomAlphabetic(5) +"/"; OzoneAcl defaultUserAcl = new OzoneAcl(USER, remoteUserName, READ, DEFAULT); OzoneObj ozoneObj = OzoneObjInfo.Builder.newBuilder() .setResType(OzoneObj.ResourceType.PREFIX) .setStoreType(OzoneObj.StoreType.OZONE) .setVolumeName(ozoneBucket.getVolumeName()) .setBucketName(ozoneBucket.getName()) .setPrefixName(prefixName).build(); testAddAcl(remoteUserName, ozoneObj, defaultUserAcl); }
Example 5
Source File: UserSetHelper.java From cuba with Apache License 2.0 | 6 votes |
public static String generateSetFilter(Set ids, String entityClass, String componentId, String entityAlias) { Document document = DocumentHelper.createDocument(); Element root = DocumentHelper.createElement("filter"); Element or = root.addElement("and"); Element condition = or.addElement("c"); condition.addAttribute("name", "set"); condition.addAttribute("inExpr", "true"); condition.addAttribute("hidden", "true"); condition.addAttribute("locCaption", "Set filter"); condition.addAttribute("entityAlias", entityAlias); condition.addAttribute("class", entityClass); condition.addAttribute("type", ConditionType.CUSTOM.name()); String listOfId = createIdsString(ids); String randomName = RandomStringUtils.randomAlphabetic(10); condition.addText(entityAlias + ".id in :component$" + componentId + "." + randomName); Element param = condition.addElement("param"); param.addAttribute("name", "component$" + componentId + "." + randomName); param.addAttribute("isFoldersFilterEntitiesSet", "true"); param.addText(listOfId); document.add(root); return Dom4j.writeDocument(document, true); }
Example 6
Source File: AggregateLookupTest.java From mongodb-aggregate-query-support with Apache License 2.0 | 6 votes |
@BeforeClass private void setup() { String primaryKey = RandomStringUtils.randomAlphabetic(10); // create a single primarykey record TestPrimaryKeyBean primaryKeyBean = new TestPrimaryKeyBean(); primaryKeyBean.setRandomPrimaryKey(primaryKey); testPrimaryKeyRepository.save(primaryKeyBean); // generate a random number of foreign key items foreignKeyItemsCount = RandomUtils.nextInt(10, 40); List<TestForeignKeyBean> foreignKeyBeans = new ArrayList<>(foreignKeyItemsCount); for (int i = 0; i < foreignKeyItemsCount; i++) { TestForeignKeyBean testForeignKeyBean = new TestForeignKeyBean(); String fkey = RandomStringUtils.randomAlphabetic(15); foreignKeys.add(fkey); testForeignKeyBean.setRandomAttribute(fkey); testForeignKeyBean.setForeignKey(primaryKey); foreignKeyBeans.add(testForeignKeyBean); } testForeignKeyRepository.saveAll(foreignKeyBeans); }
Example 7
Source File: TestOMDirectoryCreateRequest.java From hadoop-ozone with Apache License 2.0 | 5 votes |
@Test public void testCreateDirectoryOMMetric() throws Exception { String volumeName = "vol1"; String bucketName = "bucket1"; String keyName = RandomStringUtils.randomAlphabetic(5); for (int i =0; i< 3; i++) { keyName += "/" + RandomStringUtils.randomAlphabetic(5); } // Add volume and bucket entries to DB. TestOMRequestUtils.addVolumeAndBucketToDB(volumeName, bucketName, omMetadataManager); OMRequest omRequest = createDirectoryRequest(volumeName, bucketName, OzoneFSUtils.addTrailingSlashIfNeeded(keyName)); OMDirectoryCreateRequest omDirectoryCreateRequest = new OMDirectoryCreateRequest(omRequest); OMRequest modifiedOmRequest = omDirectoryCreateRequest.preExecute(ozoneManager); omDirectoryCreateRequest = new OMDirectoryCreateRequest(modifiedOmRequest); Assert.assertEquals(0L, omMetrics.getNumKeys()); OMClientResponse omClientResponse = omDirectoryCreateRequest.validateAndUpdateCache(ozoneManager, 100L, ozoneManagerDoubleBufferHelper); Assert.assertEquals(OzoneManagerProtocolProtos.Status.OK, omClientResponse.getOMResponse().getStatus()); Assert.assertNotNull(omMetadataManager.getKeyTable().get( omMetadataManager.getOzoneDirKey(volumeName, bucketName, keyName))); Assert.assertEquals(1L, omMetrics.getNumKeys()); }
Example 8
Source File: CollectionNameAnnotationTest.java From mongodb-aggregate-query-support with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = IllegalArgumentException.class) public void mustThrowExceptionIfMultipleCollectionNameAnnotationsPresentOnMethod2() { String collName = RandomStringUtils.randomAlphabetic(10); List<Score> scores = getScoresDocuments(); // insert scores into a random collection mongoTemplate.insert(scores, collName); validateRepository(collName); Integer passingScores = countRepository.invalidGetPassingScores2FromSpecifiedCollection2(collName, new Object(), collName); assertNotNull(passingScores); assertEquals((int) passingScores, 4); }
Example 9
Source File: AMQPObservableQueueTest.java From conductor with Apache License 2.0 | 5 votes |
private void testPublishMessagesToQueueAndDefaultConfiguration(Channel channel, Connection connection, boolean queueExists, boolean useWorkingChannel) throws IOException, TimeoutException { final Random random = new Random(); final String queueName = RandomStringUtils.randomAlphabetic(30); final AMQPSettings settings = new AMQPSettings(configuration) .fromURI("amqp_queue:" + queueName +"?deliveryMode=2&durable=true&exclusive=false&autoDelete=true"); assertEquals(true, settings.isDurable()); assertEquals(false, settings.isExclusive()); assertEquals(true, settings.autoDelete()); assertEquals(2, settings.getDeliveryMode()); List<GetResponse> queue = buildQueue(random, batchSize); channel = mockChannelForQueue(channel, useWorkingChannel, queueExists, queueName, queue); AMQPObservableQueue observableQueue = new AMQPObservableQueue( mockConnectionFactory(connection), addresses, false, settings, batchSize, pollTimeMs); assertArrayEquals(addresses, observableQueue.getAddresses()); assertEquals(AMQPConstants.AMQP_QUEUE_TYPE, observableQueue.getType()); assertEquals(AMQPConstants.AMQP_QUEUE_TYPE+":"+queueName+"?deliveryMode=2&durable=true&exclusive=false&autoDelete=true", observableQueue.getName()); assertEquals(queueName, observableQueue.getURI()); assertEquals(batchSize, observableQueue.getBatchSize()); assertEquals(pollTimeMs, observableQueue.getPollTimeInMS()); assertEquals(queue.size(), observableQueue.size()); List<Message> messages = new LinkedList<>(); Observable.range(0, batchSize).forEach((Integer x) -> messages.add(new Message("" + x, "payload: " + x, null))); assertEquals(batchSize, messages.size()); observableQueue.publish(messages); if (useWorkingChannel) { verify(channel, times(batchSize)).basicPublish(eq(StringUtils.EMPTY), eq(queueName), any(AMQP.BasicProperties.class), any(byte[].class)); } }
Example 10
Source File: CollectionNameAnnotationTest.java From mongodb-aggregate-query-support with Apache License 2.0 | 5 votes |
@Test public void mustReturnScoresFromDynamicallyCreatedScoresCollection() { String collName = RandomStringUtils.randomAlphabetic(10); List<Score> scores = getScoresDocuments(); // insert scores into a random collection mongoTemplate.insert(scores, collName); validateRepository(collName); Integer passingScores = countRepository.getPassingScores2FromSpecifiedCollection(collName); assertNotNull(passingScores); assertEquals((int) passingScores, 4); }
Example 11
Source File: UnbindableParametersTest.java From mongodb-aggregate-query-support with Apache License 2.0 | 5 votes |
@Test public void mustBeAbleToUseConditionalPipelineStageAsWellAsPageable() { String tag = RandomStringUtils.randomAlphabetic(10); Possessions expectedCarPossessions = FixtureUtils.createPossessions(true, false, tag); Possessions expectedHomePossessions = FixtureUtils.createPossessions(false, true, tag); possessionsRepository.saveAll(Arrays.asList(expectedCarPossessions, expectedHomePossessions)); List<Possessions> carsOnlyPossessions = possessionsRepository.mutuallyExclusiveStagesPageable( tag, true, null, PageRequest.of(0, 10)); //this query must not throw error when accessing pageable in AggregateQueryProvider::getParameterValues assertNotNull(carsOnlyPossessions); }
Example 12
Source File: TestOzoneManagerBlockToken.java From hadoop-ozone with Apache License 2.0 | 4 votes |
OzoneBlockTokenIdentifier generateTestToken() { return new OzoneBlockTokenIdentifier(RandomStringUtils.randomAlphabetic(6), RandomStringUtils.randomAlphabetic(5), EnumSet.allOf(HddsProtos.BlockTokenSecretProto.AccessModeProto.class), expiryTime, cert.getSerialNumber().toString(), MAX_LEN); }
Example 13
Source File: NotSoHungryDevelopersGenerator.java From MaxibonKataJava with Apache License 2.0 | 4 votes |
@Override public Developer generate(SourceOfRandomness random, GenerationStatus status) { String name = RandomStringUtils.randomAlphabetic(random.nextInt(16)); int numberOfMaxibons = random.nextInt(0, 7); return new Developer(name, numberOfMaxibons); }
Example 14
Source File: PartialScannerResultsDisabledIT.java From phoenix with Apache License 2.0 | 4 votes |
private static String randString(int length, Random random) { return RandomStringUtils.randomAlphabetic(length); }
Example 15
Source File: AggregateTestConfiguration.java From mongodb-aggregate-query-support with Apache License 2.0 | 4 votes |
@Bean public String dbName() { return RandomStringUtils.randomAlphabetic(7); }
Example 16
Source File: FlinkPravegaInputFormatITCase.java From flink-connectors with Apache License 2.0 | 4 votes |
/** * Verifies that the input format reads all records exactly-once in the presence of job failures. */ @Test public void testBatchInputWithFailure() throws Exception { final int numElements = 100; // set up the stream final String streamName = RandomStringUtils.randomAlphabetic(20); SETUP_UTILS.createTestStream(streamName, 3); try ( final EventStreamWriter<Integer> eventWriter = SETUP_UTILS.getIntegerWriter(streamName); // create the producer that writes to the stream final ThrottledIntegerWriter producer = new ThrottledIntegerWriter( eventWriter, numElements, numElements + 1, // no need to block writer for a batch test 0, false ) ) { // write batch input producer.start(); producer.sync(); final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setRestartStrategy(RestartStrategies.fixedDelayRestart(1, 1000L)); env.setParallelism(3); // simple pipeline that reads from Pravega and collects the events List<Integer> integers = env.createInput( FlinkPravegaInputFormat.<Integer>builder() .forStream(streamName) .withPravegaConfig(SETUP_UTILS.getPravegaConfig()) .withDeserializationSchema(new IntegerDeserializationSchema()) .build(), BasicTypeInfo.INT_TYPE_INFO ).map(new FailOnceMapper(numElements / 2)).collect(); // verify that the job did fail, and all events were still read Assert.assertTrue(FailOnceMapper.hasFailed()); Assert.assertEquals(numElements, integers.size()); FailOnceMapper.reset(); } }
Example 17
Source File: FlinkPravegaInputFormatITCase.java From flink-connectors with Apache License 2.0 | 4 votes |
/** * Verifies that the input format: * - correctly reads all records in a given set of multiple Pravega streams * - allows multiple executions */ @Test public void testBatchInput() throws Exception { final int numElements1 = 100; final int numElements2 = 300; // set up the stream final String streamName1 = RandomStringUtils.randomAlphabetic(20); final String streamName2 = RandomStringUtils.randomAlphabetic(20); final Set<String> streams = new HashSet<>(); streams.add(streamName1); streams.add(streamName2); SETUP_UTILS.createTestStream(streamName1, 3); SETUP_UTILS.createTestStream(streamName2, 5); try ( final EventStreamWriter<Integer> eventWriter1 = SETUP_UTILS.getIntegerWriter(streamName1); final EventStreamWriter<Integer> eventWriter2 = SETUP_UTILS.getIntegerWriter(streamName2); // create the producer that writes to the stream final ThrottledIntegerWriter producer1 = new ThrottledIntegerWriter( eventWriter1, numElements1, numElements1 + 1, // no need to block writer for a batch test 0, false ); final ThrottledIntegerWriter producer2 = new ThrottledIntegerWriter( eventWriter2, numElements2, numElements2 + 1, // no need to block writer for a batch test 0, false ) ) { // write batch input producer1.start(); producer2.start(); producer1.sync(); producer2.sync(); final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(3); // simple pipeline that reads from Pravega and collects the events DataSet<Integer> integers = env.createInput( FlinkPravegaInputFormat.<Integer>builder() .forStream(streamName1) .forStream(streamName2) .withPravegaConfig(SETUP_UTILS.getPravegaConfig()) .withDeserializationSchema(new IntegerDeserializationSchema()) .build(), BasicTypeInfo.INT_TYPE_INFO ); // verify that all events were read Assert.assertEquals(numElements1 + numElements2, integers.collect().size()); // this verifies that the input format allows multiple passes Assert.assertEquals(numElements1 + numElements2, integers.collect().size()); } }
Example 18
Source File: CustomHashAggDataGeneratorLargeAccum.java From dremio-oss with Apache License 2.0 | 4 votes |
private void buildInputTableDataAndResultset() { intKeyValues = new Integer[numRows]; bigintKeyValues = new Long[numRows]; varKeyValues = new String[numRows]; floatKeyValues = new Float[numRows]; doubleKeyValues = new Double[numRows]; booleanKeyValues = new Boolean[numRows]; decimalKeyValues = new BigDecimal[numRows]; intMeasureValues = new Integer[numRows]; int batch = 0; /* build batch by batch */ while (batch != batches) { int startPoint = batch * BATCH_SIZE; int pos = startPoint; for (int i = startPoint; i < (startPoint + BATCH_SIZE); i++) { if (i == 0) { /* key columns */ intKeyValues[0] = INT_BASEVALUE; bigintKeyValues[0] = BIGINT_BASEVALUE; varKeyValues[0] = VARCHAR_BASEVALUE; floatKeyValues[0] = FLOAT_BASEVALUE; doubleKeyValues[0] = DOUBLE_BASEVALUE; booleanKeyValues[0] = BOOLEAN_BASEVALUE; decimalKeyValues[0] = DECIMAL_BASEVALUE; /* measure columns */ intMeasureValues[0] = INT_BASEVALUE; } else { if (i == pos + (GROUP_INTERVAL_PER_BATCH * GROUP_REPEAT_PER_BATCH)) { pos = i; } /* key columns */ if (i < pos + GROUP_INTERVAL_PER_BATCH) { /* generate unique key column values */ intKeyValues[i] = intKeyValues[i-1] + 1; bigintKeyValues[i] = bigintKeyValues[i-1] + 1L; varKeyValues[i] = VARCHAR_BASEVALUE + RandomStringUtils.randomAlphabetic(10); floatKeyValues[i] = floatKeyValues[i - 1] + 1.0f; doubleKeyValues[i] = doubleKeyValues[i - 1] + 1.0D; booleanKeyValues[i] = !booleanKeyValues[i - 1]; decimalKeyValues[i] = decimalKeyValues[i - 1].add(DECIMAL_INCREMENT); } else { /* generate duplicate key column values */ intKeyValues[i] = intKeyValues[i - GROUP_INTERVAL_PER_BATCH]; bigintKeyValues[i] = bigintKeyValues[i - GROUP_INTERVAL_PER_BATCH]; varKeyValues[i] = varKeyValues[i - GROUP_INTERVAL_PER_BATCH]; floatKeyValues[i] = floatKeyValues[i - GROUP_INTERVAL_PER_BATCH]; doubleKeyValues[i] = doubleKeyValues[i - GROUP_INTERVAL_PER_BATCH]; booleanKeyValues[i] = booleanKeyValues[i - GROUP_INTERVAL_PER_BATCH]; decimalKeyValues[i] = decimalKeyValues[i - GROUP_INTERVAL_PER_BATCH]; } /* measure columns */ intMeasureValues[i] = intMeasureValues[i-1] + INT_INCREMENT; } /* compute the hashagg results as we build the data */ final CustomHashAggDataGeneratorLargeAccum.Key k = new CustomHashAggDataGeneratorLargeAccum.Key(intKeyValues[i], bigintKeyValues[i], varKeyValues[i], Float.floatToIntBits(floatKeyValues[i]), Double.doubleToLongBits(doubleKeyValues[i]), booleanKeyValues[i], decimalKeyValues[i]); CustomHashAggDataGeneratorLargeAccum.Value v = aggregatedResults.get(k); if (v == null) { v = new CustomHashAggDataGeneratorLargeAccum.Value(intMeasureValues[i]); aggregatedResults.put(k, v); } else { v.sumInt += intMeasureValues[i]; } } batch++; } Preconditions.checkArgument(aggregatedResults.size() == (GROUPS_PER_BATCH * batches), "result table built incorrectly"); }
Example 19
Source File: FooController.java From spring-security-oauth with MIT License | 4 votes |
@PreAuthorize("#oauth2.hasScope('read')") @GetMapping("/{id}") public Foo retrieveFoo(@PathVariable("id") Long id) { return new Foo(id, RandomStringUtils.randomAlphabetic(6)); }
Example 20
Source File: ResourceModelClassesTest.java From sling-org-apache-sling-models-impl with Apache License 2.0 | 4 votes |
@Test public void testChildModel() { Object firstValue = RandomStringUtils.randomAlphabetic(10); ValueMap firstMap = new ValueMapDecorator(Collections.singletonMap("property", firstValue)); final Resource firstChild = mock(Resource.class); when(firstChild.adaptTo(ValueMap.class)).thenReturn(firstMap); when(firstChild.adaptTo(ChildModel.class)).thenAnswer(new AdaptToChildModel()); Object firstGrandChildValue = RandomStringUtils.randomAlphabetic(10); ValueMap firstGrandChildMap = new ValueMapDecorator(Collections.singletonMap("property", firstGrandChildValue)); Object secondGrandChildValue = RandomStringUtils.randomAlphabetic(10); ValueMap secondGrandChildMap = new ValueMapDecorator(Collections.singletonMap("property", secondGrandChildValue)); final Resource firstGrandChild = mock(Resource.class); when(firstGrandChild.adaptTo(ValueMap.class)).thenReturn(firstGrandChildMap); when(firstGrandChild.adaptTo(ChildModel.class)).thenAnswer(new AdaptToChildModel()); final Resource secondGrandChild = mock(Resource.class); when(secondGrandChild.adaptTo(ValueMap.class)).thenReturn(secondGrandChildMap); when(secondGrandChild.adaptTo(ChildModel.class)).thenAnswer(new AdaptToChildModel()); Resource secondChild = mock(Resource.class); when(secondChild.listChildren()).thenReturn(Arrays.asList(firstGrandChild, secondGrandChild).iterator()); Resource emptyChild = mock(Resource.class); when(emptyChild.listChildren()).thenReturn(Collections.<Resource>emptySet().iterator()); Resource res = mock(Resource.class); when(res.getChild("firstChild")).thenReturn(firstChild); when(res.getChild("secondChild")).thenReturn(secondChild); when(res.getChild("emptyChild")).thenReturn(emptyChild); ParentModel model = factory.getAdapter(res, ParentModel.class); assertNotNull(model); ChildModel childModel = model.getFirstChild(); assertNotNull(childModel); assertEquals(firstValue, childModel.getProperty()); assertEquals(2, model.getGrandChildren().size()); assertEquals(firstGrandChildValue, model.getGrandChildren().get(0).getProperty()); assertEquals(secondGrandChildValue, model.getGrandChildren().get(1).getProperty()); assertEquals(0, model.getEmptyGrandChildren().size()); }