Skip to content

Commit

Permalink
0.9.2 Fixed multiple shell commands not working for queue/topic names…
Browse files Browse the repository at this point in the history
… containing the colon or asterisk character
  • Loading branch information
antonwierenga committed Jul 16, 2022
1 parent 563e2c0 commit a1be916
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ organization := "com.antonwierenga"

name := "activemq-cli"

version := "0.9.0"
version := "0.9.2"

scalaVersion := "2.11.6"

Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/activemq/cli/ActiveMQCLI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class ActiveMQCLI extends CommandMarker {

object ActiveMQCLI extends App {

lazy val ReleaseNotes = Map("v0.9.0" List(
lazy val ReleaseNotes = Map("v0.9.2" List(
"Fixed multiple shell commands not working for queue/topic names containing the colon or asterisk character"
), "v0.9.0" List(
"Updated shell command 'list-queues': new option --exclude-filter",
"Updated shell command 'purge-all-queues': new option --exclude-filter",
"Updated shell command 'remove-all-queues': new option --exclude-filter"
Expand Down
12 changes: 8 additions & 4 deletions src/main/scala/activemq/cli/command/Commands.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,28 @@ abstract class Commands extends PrintStackTraceExecutionProcessor {

def validateTopicExists(brokerViewMBean: BrokerViewMBean, topic: String): ObjectName = {
brokerViewMBean.getTopics.filter(objectName
getDestinationKeyProperty(objectName).contains(topic)).headOption.getOrElse(
getDestinationKeyProperty(objectName).contains(replaceSpecialCharacters(topic))).headOption.getOrElse(
throw new IllegalArgumentException(s"Topic '$topic' does not exist")
)
}

def validateTopicNotExists(brokerViewMBean: BrokerViewMBean, topic: String): Unit = {
if (!brokerViewMBean.getTopics.filter(objectName
getDestinationKeyProperty(objectName).equals(topic)).isEmpty) {
getDestinationKeyProperty(objectName).equals(replaceSpecialCharacters(topic))).isEmpty) {
throw new IllegalArgumentException(s"Topic '$topic' already exists")
}
}

def validateQueueExists(brokerViewMBean: BrokerViewMBean, queue: String): ObjectName = {
brokerViewMBean.getQueues.filter(objectName
getDestinationKeyProperty(objectName).equals(queue)).headOption.getOrElse(
getDestinationKeyProperty(objectName).equals(replaceSpecialCharacters(queue))).headOption.getOrElse(
throw new IllegalArgumentException(s"Queue '$queue' does not exist")
)
}

def validateQueueNotExists(brokerViewMBean: BrokerViewMBean, queue: String): Unit = {
if (!brokerViewMBean.getQueues.filter(objectName
getDestinationKeyProperty(objectName).equals(queue)).isEmpty) {
getDestinationKeyProperty(objectName).equals(replaceSpecialCharacters(queue))).isEmpty) {
throw new IllegalArgumentException(s"Queue '$queue' already exists")
}
}
Expand Down Expand Up @@ -284,4 +284,8 @@ abstract class Commands extends PrintStackTraceExecutionProcessor {
0
}
}

def replaceSpecialCharacters(name: String): String = {
name.replace("*", "*").replace(":", "_")
}
}
7 changes: 7 additions & 0 deletions src/test/scala/activemq/cli/command/QueueCommandsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ class QueueCommandsTests {
assertEquals(warn(s"No queues found"), shell.executeCommand("list-queues").getResult)
}

@Test
def testRemoveQueueWithAsteriskAndColon = {
assertEquals(info("Queue 'test*:Queue' added"), shell.executeCommand("add-queue --name test*:Queue").getResult)
assertEquals(info("Queue 'test*:Queue' removed"), shell.executeCommand("remove-queue --name test*:Queue --force").getResult)
assertEquals(warn(s"No queues found"), shell.executeCommand("list-queues").getResult)
}

@Test
def testPurgeQueue = {
assertEquals(info("Messages sent to queue 'testQueue': 1"), shell.executeCommand("send-message --queue testQueue --body testMessage").getResult)
Expand Down

0 comments on commit a1be916

Please sign in to comment.