jbertram commented on code in PR #4710: URL: https://github.com/apache/activemq-artemis/pull/4710#discussion_r1467969384
########## artemis-server/src/test/java/org/apache/activemq/artemis/core/config/WildcardConfigurationTest.java: ########## @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.artemis.core.config; + +import org.apache.activemq.artemis.utils.RandomUtil; +import org.junit.Assert; +import org.junit.Test; + +public class WildcardConfigurationTest extends Assert { + + private static final WildcardConfiguration MQTT_WILDCARD = new WildcardConfiguration().setDelimiter('/').setAnyWords('#').setSingleWord('+'); + private static final WildcardConfiguration DEFAULT_WILDCARD = new WildcardConfiguration(); + + @Test + public void testDefaultWildcard() { + assertEquals('.', DEFAULT_WILDCARD.getDelimiter()); + assertEquals('*', DEFAULT_WILDCARD.getSingleWord()); + assertEquals('#', DEFAULT_WILDCARD.getAnyWords()); + } + + @Test + public void testToFromCoreMQTT() { + testToFromCoreMQTT("foo.foo", "foo/foo"); + testToFromCoreMQTT("foo.*.foo", "foo/+/foo"); + testToFromCoreMQTT("foo.#", "foo/#"); + testToFromCoreMQTT("foo.*.foo.#", "foo/+/foo/#"); + testToFromCoreMQTT("foo\\.foo.foo", "foo.foo/foo"); + } + + private void testToFromCoreMQTT(String coreAddress, String mqttTopicFilter) { + assertEquals(coreAddress, MQTT_WILDCARD.convert(mqttTopicFilter, DEFAULT_WILDCARD)); + assertEquals(mqttTopicFilter, DEFAULT_WILDCARD.convert(coreAddress, MQTT_WILDCARD)); + } + + @Test + public void testEquality() { + WildcardConfiguration a = new WildcardConfiguration().setDelimiter('/').setAnyWords('#').setSingleWord('+'); + WildcardConfiguration b = new WildcardConfiguration().setDelimiter('/').setAnyWords('#').setSingleWord('+'); + + assertEquals(a, b); Review Comment: Done. ########## artemis-server/src/test/java/org/apache/activemq/artemis/core/config/WildcardConfigurationTest.java: ########## @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.artemis.core.config; + +import org.apache.activemq.artemis.utils.RandomUtil; +import org.junit.Assert; +import org.junit.Test; + +public class WildcardConfigurationTest extends Assert { + + private static final WildcardConfiguration MQTT_WILDCARD = new WildcardConfiguration().setDelimiter('/').setAnyWords('#').setSingleWord('+'); + private static final WildcardConfiguration DEFAULT_WILDCARD = new WildcardConfiguration(); + + @Test + public void testDefaultWildcard() { + assertEquals('.', DEFAULT_WILDCARD.getDelimiter()); + assertEquals('*', DEFAULT_WILDCARD.getSingleWord()); + assertEquals('#', DEFAULT_WILDCARD.getAnyWords()); + } + + @Test + public void testToFromCoreMQTT() { + testToFromCoreMQTT("foo.foo", "foo/foo"); + testToFromCoreMQTT("foo.*.foo", "foo/+/foo"); + testToFromCoreMQTT("foo.#", "foo/#"); + testToFromCoreMQTT("foo.*.foo.#", "foo/+/foo/#"); + testToFromCoreMQTT("foo\\.foo.foo", "foo.foo/foo"); + } + + private void testToFromCoreMQTT(String coreAddress, String mqttTopicFilter) { + assertEquals(coreAddress, MQTT_WILDCARD.convert(mqttTopicFilter, DEFAULT_WILDCARD)); + assertEquals(mqttTopicFilter, DEFAULT_WILDCARD.convert(coreAddress, MQTT_WILDCARD)); + } + + @Test + public void testEquality() { + WildcardConfiguration a = new WildcardConfiguration().setDelimiter('/').setAnyWords('#').setSingleWord('+'); + WildcardConfiguration b = new WildcardConfiguration().setDelimiter('/').setAnyWords('#').setSingleWord('+'); + + assertEquals(a, b); + + String toConvert = RandomUtil.randomString(); + assertTrue(toConvert == a.convert(toConvert, b)); + assertTrue(toConvert == a.convert(toConvert, a)); Review Comment: Done. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
