Showing
3 changed files
with
35 additions
and
7 deletions
1 | +/** | |
2 | + * Copyright © 2016-2020 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.transport.mqtt.util; | |
17 | + | |
18 | +import lombok.Data; | |
19 | + | |
20 | +@Data | |
21 | +public class AlwaysTrueTopicFilter implements MqttTopicFilter { | |
22 | + | |
23 | + @Override | |
24 | + public boolean filter(String topic) { | |
25 | + return true; | |
26 | + } | |
27 | +} | ... | ... |
... | ... | @@ -36,7 +36,7 @@ public class MqttTopicFilterFactory { |
36 | 36 | if (filter.contains("+") || filter.contains("#")) { |
37 | 37 | String regex; |
38 | 38 | if (filter.equals("#")) { |
39 | - regex = filter.replace("#", "\\S+"); | |
39 | + return new AlwaysTrueTopicFilter(); | |
40 | 40 | } else { |
41 | 41 | regex = filter |
42 | 42 | .replace("\\", "\\\\") | ... | ... |
... | ... | @@ -31,9 +31,8 @@ public class MqttTopicFilterFactoryTest { |
31 | 31 | private static String TEST_STR_2 = "Sensor/Temperature"; |
32 | 32 | private static String TEST_STR_3 = "Sensor/Temperature2/House/48"; |
33 | 33 | private static String TEST_STR_4 = "/Sensor/Temperature2/House/48"; |
34 | - private static String TEST_STR_5 = String.format("%s%n%s", "/Sensor/Temperature", "/House/48"); | |
35 | - private static String TEST_STR_6 = ""; | |
36 | - private static String TEST_STR_7 = " "; | |
34 | + private static String TEST_STR_5 = "Sensor/ Temperature"; | |
35 | + private static String TEST_STR_6 = "/"; | |
37 | 36 | |
38 | 37 | @Test |
39 | 38 | public void metadataCanBeUpdated() throws ScriptException { |
... | ... | @@ -60,9 +59,11 @@ public class MqttTopicFilterFactoryTest { |
60 | 59 | assertTrue(filter.filter(TEST_STR_2)); |
61 | 60 | assertTrue(filter.filter(TEST_STR_3)); |
62 | 61 | assertTrue(filter.filter(TEST_STR_4)); |
63 | - assertFalse(filter.filter(TEST_STR_5)); | |
64 | - assertFalse(filter.filter(TEST_STR_6)); | |
65 | - assertFalse(filter.filter(TEST_STR_7)); | |
62 | + assertTrue(filter.filter(TEST_STR_5)); | |
63 | + assertTrue(filter.filter(TEST_STR_6)); | |
64 | + | |
65 | + filter = MqttTopicFilterFactory.toFilter("Sensor/Temperature#"); | |
66 | + assertFalse(filter.filter(TEST_STR_2)); | |
66 | 67 | } |
67 | 68 | |
68 | 69 | } | ... | ... |