}
/*
- * Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit
+ * Allowed characters are alphanumeric, '-', '_', with at least one non-digit
*/
- private static final String VALID_MODULE_KEY_REGEXP = "[\\p{Alnum}\\-_.:]*[\\p{Alpha}\\-_.:]+[\\p{Alnum}\\-_.:]*";
+ private static final String VALID_METRIC_KEY_REGEXP = "[\\p{Alnum}\\-_]*[\\p{Alpha}\\-_]+[\\p{Alnum}\\-_]*";
/**
* <p>Test if given parameter is valid for a project/module. Valid format is:</p>
* <li>Uppercase ASCII letters A-Z</li>
* <li>Lowercase ASCII letters a-z</li>
* <li>ASCII digits 0-9</li>
- * <li>Punctuation signs dash '-', underscore '_', period '.' and colon ':'</li>
+ * <li>Punctuation signs dash '-', underscore '_'</li>
* </ul>
* </li>
* <li>At least one non-digit</li>
* @return <code>true</code> if <code>candidateKey</code> can be used for a metric
*/
public static boolean isMetricKeyValid(String candidateKey) {
- return candidateKey.matches(VALID_MODULE_KEY_REGEXP);
+ return candidateKey.matches(VALID_METRIC_KEY_REGEXP);
}
public static String checkMetricKeyFormat(String candidateKey) {
if (!isMetricKeyValid(candidateKey)) {
- throw new IllegalArgumentException(String.format("Malformed metric key '%s'. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.",
+ throw new IllegalArgumentException(String.format("Malformed metric key '%s'. Allowed characters are alphanumeric, '-', '_', with at least one non-digit.",
candidateKey));
}
@Test
public void isMetricKeyValid() {
assertThat(MetricKeyValidator.isMetricKeyValid("")).isFalse();
- assertThat(MetricKeyValidator.isMetricKeyValid("1.2.3:ABC-1.2.3")).isTrue();
- assertThat(MetricKeyValidator.isMetricKeyValid("123.321")).isTrue();
+ assertThat(MetricKeyValidator.isMetricKeyValid("1_2_3-ABC-1_2_3")).isTrue();
+ assertThat(MetricKeyValidator.isMetricKeyValid("123_321")).isTrue();
assertThat(MetricKeyValidator.isMetricKeyValid("123456")).isFalse();
- assertThat(MetricKeyValidator.isMetricKeyValid("(123.A.321)")).isFalse();
+ assertThat(MetricKeyValidator.isMetricKeyValid("1.2.3_A_3:2:1")).isFalse();
}
@Test
public void checkMetricKeyFormat() {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Malformed metric key '123456'. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.");
+ expectedException.expectMessage("Malformed metric key '123456'. Allowed characters are alphanumeric, '-', '_', with at least one non-digit.");
MetricKeyValidator.checkMetricKeyFormat("123456");
}