NO-JIRA Moving HQ Converter into HQ client module

This commit is contained in:
Clebert Suconic 2022-08-02 10:00:24 -04:00 committed by clebertsuconic
parent 1662bc740e
commit 4a7710918d
5 changed files with 77 additions and 48 deletions

View File

@ -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 = '\'';

View File

@ -46,6 +46,11 @@
<groupId>org.osgi</groupId>
<artifactId>osgi.cmpn</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -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;
}
}

View File

@ -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));
}
}

View File

@ -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";