/** * Represents this token as a String. * * @return String representation of the token */ public String toString() { return StringUtils.repeat(this.value.toString(), this.count); } }
private String constructInsertQuery(String tableName, List<List<Column>> columnLists) { StringBuilder sb = new StringBuilder(); sb.append("Insert into ").append(tableName).append(" ("); Collection<String> columnNames = Collections2.transform(columnLists.get(0), new Function<Column, String>() { @Override public String apply(Column input) { return input.getColumnName(); } }); String columns = Joiner.on(",").join(columnNames); sb.append(columns).append(") values ( "); String placeHolders = StringUtils.chop(StringUtils.repeat("?,", columnNames.size())); sb.append(placeHolders).append(")"); return sb.toString(); }
private static List<Metric> selectMetrics(Context context) throws SQLException { List<String> metricKeys = new ArrayList<>(COVERAGE_METRIC_KEYS); metricKeys.addAll(COVERAGE_METRIC_KEYS.stream().map(metricKey -> IT_PREFIX + metricKey).collect(Collectors.toList())); metricKeys.addAll(COVERAGE_METRIC_KEYS.stream().map(metricKey -> OVERALL_PREFIX + metricKey).collect(Collectors.toList())); metricKeys.addAll(metricKeys.stream().map(metricKey -> NEW_PREFIX + metricKey).collect(Collectors.toList())); Select select = context.prepareSelect("select id, name from metrics where name in (" + repeat("?", ",", metricKeys.size()) + ")"); for (int i = 0; i < metricKeys.size(); i++) { select.setString(i + 1, metricKeys.get(i)); } return select.list(Metric::new); }
private <T> void verifySupportHeadAndOrTrailingWhitespaces(T value, BiFunction<Configuration, String, Optional<T>> t) { String randomKey = RandomStringUtils.randomAlphabetic(3); String randomNumberOfWhitespaces = StringUtils.repeat(" ", 1 + new Random().nextInt(10)); assertThat(t.apply(underTest.put(randomKey, randomNumberOfWhitespaces + String.valueOf(value)), randomKey)).isEqualTo(Optional.of(value)); assertThat(t.apply(underTest.put(randomKey, String.valueOf(value) + randomNumberOfWhitespaces), randomKey)).isEqualTo(Optional.of(value)); assertThat(t.apply(underTest.put(randomKey, randomNumberOfWhitespaces + String.valueOf(value) + randomNumberOfWhitespaces), randomKey)).isEqualTo(Optional.of(value)); }
@DataProvider public static Object[][] validOldFormatServerIds() { return new Object[][] { {UuidFactoryImpl.INSTANCE.create()}, {randomAlphabetic(NOT_UUID_DATASET_ID_LENGTH)}, {repeat(SPLIT_CHARACTER + "", NOT_UUID_DATASET_ID_LENGTH)}, {randomAlphabetic(UUID_DATASET_ID_LENGTH)}, {repeat(SPLIT_CHARACTER + "", UUID_DATASET_ID_LENGTH)} }; }
@Test public void setMessage_accept_argument_of_size_4000() { String str = repeat("a", 4000); underTest.setMessage(str); assertThat(underTest.getMessage()).isEqualTo(str); }
@Test public void reformatParam_truncates_if_too_long() { String param = repeat("a", SqlLogFormatter.PARAM_MAX_WIDTH + 10); String formattedParam = SqlLogFormatter.reformatParam(param); assertThat(formattedParam) .hasSize(SqlLogFormatter.PARAM_MAX_WIDTH) .endsWith("...") .startsWith(repeat("a", SqlLogFormatter.PARAM_MAX_WIDTH - 3)); }
@Test public void setMessage_fails_with_IAE_if_argument_has_size_bigger_then_4000() { int size = 4000 + 1 + new Random().nextInt(100); String str = repeat("a", size); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("message is too long: " + size); underTest.setMessage(str); } }
@Test public void create_error_msg_from_long_content() { String content = StringUtils.repeat("mystring", 1000); assertThat(ScannerWsClient.createErrorMessage(new HttpException("url", 400, content))).hasSize(15 + 128); }
@Test public void fail_if_version_name_is_longer_then_100_characters() { SnapshotDto snapshotDto = new SnapshotDto(); snapshotDto.setVersion(null); snapshotDto.setVersion("1.0"); snapshotDto.setVersion(repeat("a", 100)); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Event name length (101) is longer than the maximum authorized (100). " + "'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' was provided."); snapshotDto.setVersion(repeat("a", 101)); } }
@DataProvider public static Object[][] validServerIdWithDatabaseId() { return new Object[][] { {randomAlphabetic(DATABASE_ID_LENGTH), randomAlphabetic(NOT_UUID_DATASET_ID_LENGTH)}, {randomAlphabetic(DATABASE_ID_LENGTH), randomAlphabetic(UUID_DATASET_ID_LENGTH)}, {randomAlphabetic(DATABASE_ID_LENGTH), repeat(SPLIT_CHARACTER + "", NOT_UUID_DATASET_ID_LENGTH)}, {randomAlphabetic(DATABASE_ID_LENGTH), repeat(SPLIT_CHARACTER + "", UUID_DATASET_ID_LENGTH)}, {randomAlphabetic(DATABASE_ID_LENGTH), UuidFactoryImpl.INSTANCE.create()}, }; }
@Test public void fail_if_key_is_too_long() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Rule key is too long: "); new RuleDto().setRuleKey(repeat("x", 250)); }
@Test public void fail_if_name_is_too_long() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Rule name is too long: "); new RuleDto().setName(repeat("x", 300)); }
@Test public void snashotDto_can_hold_version_larger_than_100_read_from_database() { SnapshotDto analysis = insertAnalysis("P1", "A1", STATUS_PROCESSED, false); db.commit(); String tooLongVersion = StringUtils.repeat("d", 200); db.executeUpdateSql("update snapshots set version='" + tooLongVersion + "' where uuid='" + analysis.getUuid() + "'"); db.commit(); assertThat(underTest.selectByUuid(dbSession, analysis.getUuid()) .map(SnapshotDto::getVersion)) .contains(tooLongVersion); }
@Test(expected = IllegalArgumentException.class) public void fail_if_name_is_too_long() throws Exception { loginAsAdminOnDefaultOrganization(); newRequest() .setParam("name", StringUtils.repeat("a", 255 + 1)) .execute(); }
@Test public void limit_version_name_length_to_100_for_analysis_events() { SnapshotDto analysis = createAnalysisAndLogInAsProjectAdministrator("5.6"); db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(OTHER.getLabel()).setName("E1 name")); db.events().insertEvent(newEvent(analysis).setUuid("E2").setCategory(VERSION.getLabel()).setName("E2 name")); call("E1", repeat("a", 100)); call("E1", repeat("a", 101)); call("E2", repeat("a", 100)); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Version length (101) is longer than the maximum authorized (100). 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' was provided"); call("E2", repeat("a", 101)); }
@Test public void fail_with_too_long_version() { ProjectReactor reactor = createProjectReactor("foo", def -> def.setVersion(repeat("a", 101))); thrown.expect(MessageException.class); thrown.expectMessage("\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\" is not a valid version name for module \"foo\". " + "The maximum length for version numbers is 100 characters."); validator.validate(reactor); }
@Test public void not_fail_with_valid_version() { validator.validate(createProjectReactor("foo", def -> def.setVersion("1.0"))); validator.validate(createProjectReactor("foo", def -> def.setVersion("2017-10-16"))); validator.validate(createProjectReactor("foo", def -> def.setVersion(repeat("a", 100)))); }