Validators { public static void checkTopic(String topic) throws MQClientException { if (UtilAll.isBlank(topic)) { throw new MQClientException("the specified topic is blank", null); } if (!regularExpressionMatcher(topic, PATTERN)) { throw new MQClientException(String.format( "the specified topic[%s] contains illegal characters, allowing only %s", topic, VALID_PATTERN_STR), null); } if (topic.length() > CHARACTER_MAX_LENGTH) { throw new MQClientException("the specified topic is longer than topic max length 255.", null); } if (topic.equals(MixAll.DEFAULT_TOPIC)) { throw new MQClientException( String.format("the topic[%s] is conflict with default topic.", topic), null); } }  static boolean regularExpressionMatcher(String origin, Pattern pattern); static String getGroupWithRegularExpression(String origin, String patternStr); static void checkTopic(String topic); static void checkGroup(String group); static void checkMessage(Message msg, DefaultMQProducer defaultMQProducer); static final String VALID_PATTERN_STR; static final Pattern PATTERN; static final int CHARACTER_MAX_LENGTH; }
@Test public void topicValidatorTest() { try { Validators.checkTopic("Hello"); Validators.checkTopic("%RETRY%Hello"); Validators.checkTopic("_%RETRY%Hello"); Validators.checkTopic("-%RETRY%Hello"); Validators.checkTopic("223-%RETRY%Hello"); } catch (Exception e) { e.printStackTrace(); Assert.assertTrue(false); } }