From 4a7710918d95140e0d907d60ba0b45c08af8529e Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Tue, 2 Aug 2022 10:00:24 -0400 Subject: [PATCH] NO-JIRA Moving HQ Converter into HQ client module --- .../artemis/utils/SelectorTranslator.java | 15 ------ .../artemis-hqclient-protocol/pom.xml | 5 ++ .../HQFilterConversionInterceptor.java | 20 ++++++- .../hornetq/SelectorTranslatorTest.java | 54 +++++++++++++++++++ .../jms/client/SelectorTranslatorTest.java | 31 ----------- 5 files changed, 77 insertions(+), 48 deletions(-) create mode 100644 artemis-protocols/artemis-hqclient-protocol/src/test/java/org/apache/activemq/artemis/core/protocol/hornetq/SelectorTranslatorTest.java diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/SelectorTranslator.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/SelectorTranslator.java index f3c214bf9a..f6b298320e 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/SelectorTranslator.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/SelectorTranslator.java @@ -54,21 +54,6 @@ public class SelectorTranslator { } - public static String convertHQToActiveMQFilterString(final String hqFilterString) { - if (hqFilterString == null) { - return null; - } - - String filterString = SelectorTranslator.parse(hqFilterString, "HQDurable", "AMQDurable"); - filterString = SelectorTranslator.parse(filterString, "HQPriority", "AMQPriority"); - filterString = SelectorTranslator.parse(filterString, "HQTimestamp", "AMQTimestamp"); - filterString = SelectorTranslator.parse(filterString, "HQUserID", "AMQUserID"); - filterString = SelectorTranslator.parse(filterString, "HQExpiration", "AMQExpiration"); - - return filterString; - - } - public static String parse(final String input, final String match, final String replace) { final char quote = '\''; diff --git a/artemis-protocols/artemis-hqclient-protocol/pom.xml b/artemis-protocols/artemis-hqclient-protocol/pom.xml index 9d61a0a31e..82df9e3e77 100644 --- a/artemis-protocols/artemis-hqclient-protocol/pom.xml +++ b/artemis-protocols/artemis-hqclient-protocol/pom.xml @@ -46,6 +46,11 @@ org.osgi osgi.cmpn + + junit + junit + test + diff --git a/artemis-protocols/artemis-hqclient-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/hornetq/HQFilterConversionInterceptor.java b/artemis-protocols/artemis-hqclient-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/hornetq/HQFilterConversionInterceptor.java index e1a5257d13..761aca678f 100644 --- a/artemis-protocols/artemis-hqclient-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/hornetq/HQFilterConversionInterceptor.java +++ b/artemis-protocols/artemis-hqclient-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/hornetq/HQFilterConversionInterceptor.java @@ -56,7 +56,23 @@ public class HQFilterConversionInterceptor implements Interceptor { if (filterString == null) { return null; } - return SimpleString.toSimpleString( - SelectorTranslator.convertHQToActiveMQFilterString(filterString.toString())); + return SimpleString.toSimpleString(convertHQToActiveMQFilterString(filterString.toString())); } + + + public static String convertHQToActiveMQFilterString(final String hqFilterString) { + if (hqFilterString == null) { + return null; + } + + String filterString = SelectorTranslator.parse(hqFilterString, "HQDurable", "AMQDurable"); + filterString = SelectorTranslator.parse(filterString, "HQPriority", "AMQPriority"); + filterString = SelectorTranslator.parse(filterString, "HQTimestamp", "AMQTimestamp"); + filterString = SelectorTranslator.parse(filterString, "HQUserID", "AMQUserID"); + filterString = SelectorTranslator.parse(filterString, "HQExpiration", "AMQExpiration"); + + return filterString; + + } + } diff --git a/artemis-protocols/artemis-hqclient-protocol/src/test/java/org/apache/activemq/artemis/core/protocol/hornetq/SelectorTranslatorTest.java b/artemis-protocols/artemis-hqclient-protocol/src/test/java/org/apache/activemq/artemis/core/protocol/hornetq/SelectorTranslatorTest.java new file mode 100644 index 0000000000..48269eec50 --- /dev/null +++ b/artemis-protocols/artemis-hqclient-protocol/src/test/java/org/apache/activemq/artemis/core/protocol/hornetq/SelectorTranslatorTest.java @@ -0,0 +1,54 @@ +/* + * 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.protocol.hornetq; + +import org.junit.Assert; +import org.junit.Test; + +public class SelectorTranslatorTest { + @Test + public void testConvertHQFilterString() { + String selector = "HQUserID = 'ID:AMQ-12435678'"; + + Assert.assertEquals("AMQUserID = 'ID:AMQ-12435678'", HQFilterConversionInterceptor.convertHQToActiveMQFilterString(selector)); + + selector = "HQUserID = 'HQUserID'"; + + Assert.assertEquals("AMQUserID = 'HQUserID'", HQFilterConversionInterceptor.convertHQToActiveMQFilterString(selector)); + + selector = "HQUserID = 'ID:AMQ-12435678'"; + + Assert.assertEquals("AMQUserID = 'ID:AMQ-12435678'", HQFilterConversionInterceptor.convertHQToActiveMQFilterString(selector)); + + selector = "HQDurable='NON_DURABLE'"; + + Assert.assertEquals("AMQDurable='NON_DURABLE'", HQFilterConversionInterceptor.convertHQToActiveMQFilterString(selector)); + + selector = "HQPriority=5"; + + Assert.assertEquals("AMQPriority=5", HQFilterConversionInterceptor.convertHQToActiveMQFilterString(selector)); + + selector = "HQTimestamp=12345678"; + + Assert.assertEquals("AMQTimestamp=12345678", HQFilterConversionInterceptor.convertHQToActiveMQFilterString(selector)); + + selector = "HQExpiration=12345678"; + + Assert.assertEquals("AMQExpiration=12345678", HQFilterConversionInterceptor.convertHQToActiveMQFilterString(selector)); + } + +} diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/client/SelectorTranslatorTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/client/SelectorTranslatorTest.java index bdfc611302..da7da4cea2 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/client/SelectorTranslatorTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/client/SelectorTranslatorTest.java @@ -204,37 +204,6 @@ public class SelectorTranslatorTest extends ActiveMQTestBase { checkNoSubstitute("JMSType"); } - @Test - public void testConvertHQFilterString() { - String selector = "HQUserID = 'ID:AMQ-12435678'"; - - Assert.assertEquals("AMQUserID = 'ID:AMQ-12435678'", SelectorTranslator.convertHQToActiveMQFilterString(selector)); - - selector = "HQUserID = 'HQUserID'"; - - Assert.assertEquals("AMQUserID = 'HQUserID'", SelectorTranslator.convertHQToActiveMQFilterString(selector)); - - selector = "HQUserID = 'ID:AMQ-12435678'"; - - Assert.assertEquals("AMQUserID = 'ID:AMQ-12435678'", SelectorTranslator.convertHQToActiveMQFilterString(selector)); - - selector = "HQDurable='NON_DURABLE'"; - - Assert.assertEquals("AMQDurable='NON_DURABLE'", SelectorTranslator.convertHQToActiveMQFilterString(selector)); - - selector = "HQPriority=5"; - - Assert.assertEquals("AMQPriority=5", SelectorTranslator.convertHQToActiveMQFilterString(selector)); - - selector = "HQTimestamp=12345678"; - - Assert.assertEquals("AMQTimestamp=12345678", SelectorTranslator.convertHQToActiveMQFilterString(selector)); - - selector = "HQExpiration=12345678"; - - Assert.assertEquals("AMQExpiration=12345678", SelectorTranslator.convertHQToActiveMQFilterString(selector)); - } - private void checkNoSubstitute(final String fieldName) { String selector = "Other" + fieldName + " = 767868";