org.apache.commons.lang.RandomStringUtils#randomAlphabetic ( )源码实例Demo

下面列出了org.apache.commons.lang.RandomStringUtils#randomAlphabetic ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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));
    }

    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);
    }
}
 
源代码2 项目: chassis   文件: ConfigurationBuilderTest.java
@Test
public void buildConfigurationInAws(){
    String az = "testaz";
    String instanceId = RandomStringUtils.randomAlphabetic(10);
    String region = Regions.DEFAULT_REGION.getName();

    ServerInstanceContext serverInstanceContext = EasyMock.createMock(ServerInstanceContext.class);
    EasyMock.expect(serverInstanceContext.getAvailabilityZone()).andReturn(az);
    EasyMock.expect(serverInstanceContext.getInstanceId()).andReturn(instanceId);
    EasyMock.expect(serverInstanceContext.getRegion()).andReturn(region);
    EasyMock.expect(serverInstanceContext.getPrivateIp()).andReturn("127.0.0.1");
    EasyMock.expect(serverInstanceContext.getPublicIp()).andReturn(null);

    EasyMock.replay(serverInstanceContext);

    Configuration configuration = configurationBuilder.withServerInstanceContext(serverInstanceContext).build();

    Assert.assertEquals(az, configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_AVAILABILITY_ZONE.getPropertyName()));
    Assert.assertEquals(instanceId, configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_ID.getPropertyName()));
    Assert.assertEquals(region, configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_REGION.getPropertyName()));
    Assert.assertEquals("127.0.0.1", configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_PRIVATE_IP.getPropertyName()));
    Assert.assertEquals(null, configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_PUBLIC_IP.getPropertyName()));

    EasyMock.verify(serverInstanceContext);
}
 
源代码3 项目: smarthome   文件: SampleExtensionService.java
@Activate
protected void activate() {
    types.add(new ExtensionType("binding", "Bindings"));
    types.add(new ExtensionType("ui", "User Interfaces"));
    types.add(new ExtensionType("persistence", "Persistence Services"));

    for (ExtensionType type : types) {
        for (int i = 0; i < 10; i++) {
            String id = type.getId() + Integer.toString(i);
            boolean installed = Math.random() > 0.5;
            String name = RandomStringUtils.randomAlphabetic(5);
            String label = name + " " + StringUtils.capitalize(type.getId());
            String typeId = type.getId();
            String version = "1.0";
            String link = (Math.random() < 0.5) ? null : "http://lmgtfy.com/?q=" + name;
            String description = createDescription();
            String imageLink = null;
            String backgroundColor = createRandomColor();
            Extension extension = new Extension(id, typeId, label, version, link, installed, description,
                    backgroundColor, imageLink);
            extensions.put(extension.getId(), extension);
        }
    }
}
 
private void testMutability() {
  for (int i = 0; i < NUM_ROWS; i++) {
    int row = _random.nextInt(NUM_ROWS);

    int intValue = _random.nextInt();
    _readerWriter.setInt(row, 0, intValue);
    Assert.assertEquals(_readerWriter.getInt(row, 0), intValue);

    long longValue = _random.nextLong();
    _readerWriter.setLong(row, 1, longValue);
    Assert.assertEquals(_readerWriter.getLong(row, 1), longValue);

    float floatValue = _random.nextFloat();
    _readerWriter.setFloat(row, 2, floatValue);
    Assert.assertEquals(_readerWriter.getFloat(row, 2), floatValue);

    double doubleValue = _random.nextDouble();
    _readerWriter.setDouble(row, 3, doubleValue);
    Assert.assertEquals(_readerWriter.getDouble(row, 3), doubleValue);

    String stringValue = RandomStringUtils.randomAlphabetic(STRING_LENGTH);
    _readerWriter.setString(row, 4, stringValue);
    Assert.assertEquals(_readerWriter.getString(row, 4), stringValue);
  }
}
 
public void testConfigComponentLookUpAndCopy() throws Exception {
        selectFrameIframePortlet();
        waitAndClickSearchSecond();
        waitAndClickByLinkText("copy");
        String fourLetters = RandomStringUtils.randomAlphabetic(4);
        waitAndTypeByName("document.documentHeader.documentDescription","Test description of Component copy " + AutomatedFunctionalTestUtils
                .createUniqueDtsPlusTwoRandomCharsNot9Digits());
        selectByName("document.newMaintainableObject.namespaceCode","KR-WKFLW - Workflow");
        waitAndTypeByName("document.newMaintainableObject.code","ActionList2" + fourLetters);
        waitAndTypeByName("document.newMaintainableObject.name",fourLetters);
        waitAndTypeByName("document.newMaintainableObject.name","Action List 2 " + fourLetters);
        waitAndClickByName("methodToCall.route");
        checkForDocError();
        waitAndClickByName("methodToCall.close");
//         waitAndClickByName("methodToCall.processAnswer.button1");
    }
 
源代码6 项目: dhis2-core   文件: UniqueNameVerifierTest.java
@Test
public void verifyResourceTableColumnNameAreUniqueWhenComputingShortName2()
{
    // Category short name will be shorten to 49 chars, and create 3 identical
    // short-names
    String indicatorGroupSetName = RandomStringUtils.randomAlphabetic( 50 );

    final List<IndicatorGroupSet> indicatorGroupSets = IntStream.of( 1, 2, 3 )
        .mapToObj( i -> new IndicatorGroupSet( indicatorGroupSetName + 1 ) )
        .peek( c -> c.setUid( CodeGenerator.generateUid() ) ).collect( Collectors.toList() );

    IndicatorGroupSetResourceTable indicatorGroupSetResourceTable = new IndicatorGroupSetResourceTable(
        indicatorGroupSets );

    final String sql = indicatorGroupSetResourceTable.getCreateTempTableStatement();

    assertEquals( countMatches( sql, "\"" + indicatorGroupSets.get( 0 ).getName() + "\"" ), 1 );
    assertEquals( countMatches( sql, "\"" + indicatorGroupSets.get( 0 ).getName() + "1\"" ), 1 );
    assertEquals( countMatches( sql, "\"" + indicatorGroupSets.get( 0 ).getName() + "2\"" ), 1 );

}
 
源代码7 项目: pinpoint   文件: NioUdpDataSenderTest.java
@Test(expected = IOException.class)
public void exceedMessageSendTest() throws IOException {
    String random = RandomStringUtils.randomAlphabetic(ThriftUdpMessageSerializer.UDP_MAX_PACKET_LENGTH + 100);

    TAgentInfo agentInfo = new TAgentInfo();
    agentInfo.setAgentId(random);

    NioUDPDataSender sender = newNioUdpDataSender();
    sender.send(agentInfo);

    waitMessageReceived(1);
}
 
源代码8 项目: kylin-on-parquet-v2   文件: TopNCounterTest.java
protected String prepareTestDate() throws IOException {
    String[] allKeys = new String[KEY_SPACE];

    for (int i = 0; i < KEY_SPACE; i++) {
        allKeys[i] = RandomStringUtils.randomAlphabetic(10);
    }

    outputMsg("Start to create test random data...");
    long startTime = System.currentTimeMillis();
    ZipfDistribution zipf = new ZipfDistribution(KEY_SPACE, 0.5);
    int keyIndex;

    File tempFile = File.createTempFile("ZipfDistribution", ".txt");

    if (tempFile.exists())
        FileUtils.forceDelete(tempFile);
    Writer fw = new OutputStreamWriter(new FileOutputStream(tempFile), StandardCharsets.UTF_8);
    try {
        for (int i = 0; i < TOTAL_RECORDS; i++) {
            keyIndex = zipf.sample() - 1;
            fw.write(allKeys[keyIndex]);
            fw.write('\n');
        }
    } finally {
        if (fw != null)
            fw.close();
    }

    outputMsg("Create test data takes : " + (System.currentTimeMillis() - startTime) / 1000 + " seconds.");
    outputMsg("Test data in : " + tempFile.getAbsolutePath());

    return tempFile.getAbsolutePath();
}
 
源代码9 项目: canal-1.1.3   文件: MutliAviaterFilterTest.java
private void doRegexTest() {
    AviaterRegexFilter filter3 = new AviaterRegexFilter("otter2.otter_stability1|otter1.otter_stability1|"
                                                        + RandomStringUtils.randomAlphabetic(200));
    boolean result = filter3.filter("otter1.otter_stability1");
    Assert.assertEquals(true, result);
    result = filter3.filter("otter2.otter_stability1");
    Assert.assertEquals(true, result);
}
 
@Test
public void testStompSendReceiveWithMaxFramePayloadLength() throws Exception {
   // Assert that sending message > default 64kb fails
   int size = 65536;
   String largeString1 = RandomStringUtils.randomAlphabetic(size);
   String largeString2 = RandomStringUtils.randomAlphabetic(size);

   StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri, false);
   conn.getTransport().setMaxFrameSize(stompWSMaxFrameSize);
   conn.getTransport().connect();

   StompClientConnection conn2 = StompClientConnectionFactory.createClientConnection(wsURI, false);
   conn2.getTransport().setMaxFrameSize(stompWSMaxFrameSize);
   conn2.getTransport().connect();

   Wait.waitFor(() -> conn2.getTransport().isConnected() && conn.getTransport().isConnected(), 10000);
   conn.connect();
   conn2.connect();

   subscribeQueue(conn2, "sub1", getQueuePrefix() + getQueueName());

   try {
      // Client is kicked when sending frame > largest frame size.
      send(conn, getQueuePrefix() + getQueueName(), "text/plain", largeString1, false);
      Wait.waitFor(() -> !conn.getTransport().isConnected(), 2000);
      assertFalse(conn.getTransport().isConnected());

      send(conn2, getQueuePrefix() + getQueueName(), "text/plain", largeString2, false);
      Wait.waitFor(() -> !conn2.getTransport().isConnected(), 2000);
      assertTrue(conn2.getTransport().isConnected());

      ClientStompFrame frame = conn2.receiveFrame();
      assertNotNull(frame);
      assertEquals(largeString2, frame.getBody());

   } finally {
      conn2.closeTransport();
      conn.closeTransport();
   }
}
 
源代码11 项目: atlas   文件: ObjectUpdateSynchronizerTest.java
public void run() {
    objectUpdateSynchronizer.lockObject(CollectionUtils.arrayToList(ids));
    for (int i = 0; i < MAX_COUNT; i++) {
        outputList.add(i);
        RandomStringUtils.randomAlphabetic(20);
    }

    objectUpdateSynchronizer.releaseLockedObjects();
}
 
源代码12 项目: usergrid   文件: SelectMappingsQueryTest.java
/**
 * Field named testProp can be over-written by field named TESTPROP.
 */
@Test
public void testFieldOverride2() throws Exception {

    String collectionName = "tennisballs";

    // create entity with TESTPROP=value
    String value = RandomStringUtils.randomAlphabetic( 20 );
    Entity entity = new Entity().withProp( "TESTPROP", value );
    app().collection( collectionName ).post( entity );
    waitForQueueDrainAndRefreshIndex();

    // override with testProp=newValue
    String newValue = RandomStringUtils.randomAlphabetic( 20 );
    entity = new Entity().withProp( "testProp", newValue );
    app().collection( collectionName ).post( entity );
    waitForQueueDrainAndRefreshIndex();

    // testProp and TESTPROP should new be queryable by new value

    QueryParameters params = new QueryParameters()
        .setQuery( "select * where testProp='" + newValue + "'" );
    Collection coll = this.app().collection(collectionName).get( params );
    assertEquals( 1, coll.getNumOfEntities() );

    params = new QueryParameters()
        .setQuery( "select * where TESTPROP='" + newValue + "'" );
    coll = app().collection(collectionName).get( params );
    assertEquals( 1, coll.getNumOfEntities() );
}
 
源代码13 项目: dhis2-core   文件: DashboardServiceTest.java
private EventChart createEventChart( Program program )
{
    EventChart eventChart = new EventChart( RandomStringUtils.randomAlphabetic( 5 ) );
    eventChart.setProgram( program );
    eventChart.setType( ChartType.COLUMN );
    return eventChart;
}
 
源代码14 项目: rice   文件: CampusAftBase.java
private void reattemptPrimaryKey() throws InterruptedException {
    int attempts = 0;
    while (isTextPresent("a record with the same primary key already exists.") && ++attempts <= 10) {
        jGrowl("record with the same primary key already exists trying another, attempt: " + attempts);
        clearTextByName("document.newMaintainableObject.code"); // primary key
        String randomNumbeForCode = RandomStringUtils.randomNumeric(1);
        String randomAlphabeticForCode = RandomStringUtils.randomAlphabetic(1);
        jiraAwareTypeByName("document.newMaintainableObject.code", randomNumbeForCode + randomAlphabeticForCode);
        waitAndClickByName("methodToCall.route");
        waitForProgress("Submitting...");
    }
}
 
@BeforeClass
public static void setup() {
	name = RandomStringUtils.randomAlphabetic(5);
	value = RandomStringUtils.randomAlphanumeric(10);
	injectorName = RandomStringUtils.randomAlphabetic(5);
	parameters = new ConfigurationParameter[8];
	for (int i = 0; i < parameters.length; i++) {
		parameters[i] = new ConfigurationParameterImpl(name, value, (i & 1) == 1, (i & 2) == 2 ? injectorName : null, i > 4);
	}
	EncryptionProvider.initialize();
}
 
@BeforeClass
public static void setup() {
	name = RandomStringUtils.randomAlphabetic(5);
	value = RandomStringUtils.randomAlphanumeric(10);
	parameters = new ValueProviderParameter[8];
	for (int i = 0; i < 8; i++) {
		parameters[i] = new ValueProviderParameterImpl(name, i % 2 == (i < 4 ? 0 : 1) ? value : null, i % 4 > 1,
				(i % 4) % 3 != 0);
	}
	EncryptionProvider.initialize();
}
 
@Test
public void testWithSubjectNoProgressThread(){
	String subject = RandomStringUtils.randomAlphabetic(10);
	TestExecutionContext<String> context  = new TestExecutionContextImpl<>(subject);
	Assert.assertEquals(subject, context.getSubject());
	// Check that nothing explodes
	context.getProgressListener().setTotal(100);
	context.getProgressListener().setCompleted(5);
	context.getProgressListener().setMessage("Nearly there");
	context.getProgressListener().complete();
	context.checkCancelled();
}
 
源代码18 项目: BUbiNG   文件: RandomTestMocks.java
public HttpRequest(final int maxNumberOfHeaders, final int maxLenghtOfHeader, final int pos) {
	this.requestLine = new BasicRequestLine("GET", RandomStringUtils.randomAlphabetic(RNG.nextInt(maxLenghtOfHeader) + 1), PROTOCOL_VERSION);
	Header[] headers = randomHeaders(maxNumberOfHeaders, maxLenghtOfHeader);
	headers[RNG.nextInt(headers.length)] = new BasicHeader("Position", Integer.toString(pos));
	this.setHeaders(headers);
}
 
源代码19 项目: indexr   文件: TestFetcher.java
@Override
public List<UTF8Row> next() throws Exception {
    if (sleep > 0) {
        Thread.sleep(sleep);
    }

    int colId = 0;
    StringBuilder sb = new StringBuilder();
    sb.append('{');
    if (!Strings.isEmpty(tagField) && randomTags != null && !randomTags.isEmpty()) {
        sb.append("\"").append(tagField).append("\":\"").append(randomTags.get(random.nextInt(randomTags.size()))).append("\",");
    }
    for (ColumnSchema cs : schema.getColumns()) {
        sb.append('\"').append(cs.getName()).append("\": ");
        switch (cs.getSqlType()) {
            case DATE:
                LocalDate date = LocalDate.now();
                sb.append('\"').append(date.format(DateTimeUtil.DATE_FORMATTER)).append('\"');
                break;
            case TIME:
                LocalTime time = LocalTime.now();
                sb.append('\"').append(time.format(DateTimeUtil.TIME_FORMATTER)).append('\"');
                break;
            case DATETIME:
                LocalDateTime dateTime = LocalDateTime.now();
                sb.append('\"').append(dateTime.format(DateTimeUtil.DATETIME_FORMATTER)).append('\"');
                break;
            case VARCHAR:
                if (randomValue) {
                    String colValue = RandomStringUtils.randomAlphabetic(random.nextInt(20));
                    sb.append('\"').append(colValue).append('\"');
                } else {
                    sb.append("\"1\"");
                }
                break;
            default:
                if (randomValue) {
                    sb.append(random.nextInt());
                } else {
                    sb.append(1);
                }
        }

        colId++;
        if (colId < schema.getColumns().size()) {
            sb.append(',');
        }
    }
    sb.append('}');

    byte[] data = sb.toString().getBytes("utf-8");
    return utf8JsonRowCreator.create(data);
}
 
源代码20 项目: j-road   文件: BasepackageBinder.java
@Override
public String lookupPackageForNamespace(String uri) {
  String random = RandomStringUtils.randomAlphabetic(5);

  uri = uri.replace("-", random);

  String pck = NameUtil.getPackageFromNamespace(uri).replace(random, "_");

  return basePackage == null ? pck : basePackage + "." + pck;
}