[ 
https://issues.apache.org/jira/browse/ARTEMIS-4648?focusedWorklogId=908840&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-908840
 ]

ASF GitHub Bot logged work on ARTEMIS-4648:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 07/Mar/24 21:40
            Start Date: 07/Mar/24 21:40
    Worklog Time Spent: 10m 
      Work Description: jbertram commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1516682947


##########
artemis-cli/src/test/java/org/apache/activemq/cli/test/CliProducerTest.java:
##########
@@ -88,6 +91,138 @@ public void testSendMessage() throws Exception {
       checkSentMessages(session, address, null);
    }
 
+   @Test
+   public void testBooleanMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, 
"[{'type':'boolean','key':'myTrueBoolean','value':'true'},{'type':'boolean','key':'myFalseBoolean','value':'false'}]".replaceAll("'",
 "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myTrueBoolean"));
+      Assert.assertTrue(m.getBooleanProperty("myTrueBoolean"));
+      Assert.assertTrue(m.propertyExists("myFalseBoolean"));
+      Assert.assertFalse(m.getBooleanProperty("myFalseBoolean"));
+   }
+
+   @Test
+   public void testIntMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, 
("[{'type':'int','key':'myInt','value':'" + Integer.MAX_VALUE + 
"'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myInt"));
+      Assert.assertEquals(Integer.MAX_VALUE, m.getIntProperty("myInt"));
+
+      assertEquals(0L, produceMessages(address, null, 1, 
("[{'type':'int','key':'myInt','value':'" + Integer.MAX_VALUE + 1 + 
"'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testLongMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, 
("[{'type':'long','key':'myLong','value':'" + Long.MAX_VALUE + 
"'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myLong"));
+      Assert.assertEquals(Long.MAX_VALUE, m.getLongProperty("myLong"));
+
+      assertEquals(0L, produceMessages(address, null, 1, 
("[{'type':'long','key':'myLong','value':'" + Long.MAX_VALUE + 1 + 
"'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testByteMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, 
"[{'type':'byte','key':'myByte','value':'127'}]".replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myByte"));
+      Assert.assertEquals((byte) 127, m.getByteProperty("myByte"));
+
+      assertEquals(0L, produceMessages(address, null, 1, 
"[{'type':'byte','key':'myByte','value':'128'}]".replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testShortMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, 
("[{'type':'short','key':'myShort','value':'" + Short.MAX_VALUE + 
"'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myShort"));
+      Assert.assertEquals(Short.MAX_VALUE, m.getShortProperty("myShort"));
+
+      assertEquals(0L, produceMessages(address, null, 1, 
("[{'type':'short','key':'myShort','value':'" + Short.MAX_VALUE + 1 + 
"'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testFloatMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, 
("[{'type':'float','key':'myFloat','value':'" + Float.MAX_VALUE + 
"'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myFloat"));
+      Assert.assertEquals(Float.MAX_VALUE, m.getFloatProperty("myFloat"), 0.0);
+
+      assertEquals(0L, produceMessages(address, null, 1, 
("[{'type':'float','key':'myFloat','value':'badFloat'}]").replaceAll("'", 
"\"")));
+   }
+
+   @Test
+   public void testDoubleMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, 
("[{'type':'double','key':'myDouble','value':'" + Double.MAX_VALUE + 
"'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myDouble"));
+      Assert.assertEquals(Double.MAX_VALUE, m.getDoubleProperty("myDouble"), 
0.0);
+
+      assertEquals(0L, produceMessages(address, null, 1, 
("[{'type':'double','key':'myDouble','value':'badDouble'}]").replaceAll("'", 
"\"")));
+   }
+
+   @Test
+   public void testStringMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, 
"[{'type':'string','key':'myString','value':'foo'}]".replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myString"));
+      Assert.assertEquals("foo", m.getStringProperty("myString"));
+   }
+
+   @Test
+   public void testBadMessageProperties() throws Exception {
+      PrintStream originalErr = System.err;
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      PrintStream newErr = new PrintStream(baos);
+      System.setErr(newErr);
+      try {
+         produceMessages("test", null, 1, 
"[{'type':'myType','key':'myKey','value':'myValue'}]".replaceAll("'", "\""));
+         assertEquals("Unable to set property: myKey. Did not recognize type: 
myType. Supported types are: boolean, int, long, byte, short, float, double, 
string.\n", baos.toString());
+      } finally {
+         System.setErr(originalErr);
+      }

Review Comment:
   Done.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 908840)
    Time Spent: 2h 20m  (was: 2h 10m)

> Support typed properties on CLI producer
> ----------------------------------------
>
>                 Key: ARTEMIS-4648
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-4648
>             Project: ActiveMQ Artemis
>          Issue Type: New Feature
>            Reporter: Justin Bertram
>            Assignee: Justin Bertram
>            Priority: Major
>          Time Spent: 2h 20m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to