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: The `ProducerThread` logs directly using `System`. I sent #4846 to fix this. Once that's merged I'll update this test. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@activemq.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org