[
https://issues.apache.org/jira/browse/ARTEMIS-4532?focusedWorklogId=901994&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-901994
]
ASF GitHub Bot logged work on ARTEMIS-4532:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 26/Jan/24 18:04
Start Date: 26/Jan/24 18:04
Worklog Time Spent: 10m
Work Description: 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.
Issue Time Tracking
-------------------
Worklog Id: (was: 901994)
Time Spent: 3h 40m (was: 3.5h)
> MQTT-to-core wildcard conversion is broken
> ------------------------------------------
>
> Key: ARTEMIS-4532
> URL: https://issues.apache.org/jira/browse/ARTEMIS-4532
> Project: ActiveMQ Artemis
> Issue Type: Bug
> Reporter: Justin Bertram
> Assignee: Justin Bertram
> Priority: Major
> Time Spent: 3h 40m
> Remaining Estimate: 0h
>
> Currently when an MQTT topic filter contains characters from the configured
> [wildcard
> syntax|https://activemq.apache.org/components/artemis/documentation/latest/wildcard-syntax.html#wildcard-syntax]
> the conversion to/from this syntax breaks.
> For example, when using the default wildcard syntax if an MQTT topic filter
> contains a {{.}} the conversion from the MQTT wildcard syntax to the core
> wildcard syntax and back will result in the {{.}} being replaced with a {{/}}.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)