@Override public boolean isBodyAssignableTo(@SuppressWarnings("rawtypes") Class c) throws JMSException { if (ActiveMQRAMessage.trace) { ActiveMQRALogger.LOGGER.trace("isBodyAssignableTo(" + c + ")"); } return message.isBodyAssignableTo(c); }
/** * @param type * @param clazz * @param bool * @throws JMSException */ private void bodyAssignableFrom(final JmsMessageType type, final boolean bool, Class... clazz) throws JMSException { Assert.assertNotNull("clazz!=null", clazz); Assert.assertTrue("clazz[] not empty", clazz.length > 0); Object body = createBodySendAndReceive(type); Message msg = queueConsumer.receive(500); Assert.assertNotNull("must have a msg", msg); Assert.assertEquals(type.toString(), msg.getStringProperty("type")); for (Class<?> c : clazz) { Assert.assertEquals( msg + " " + type + " & " + c + ": " + bool, bool, msg.isBodyAssignableTo(c)); if (bool) { Object receivedBody = msg.getBody(c); Assert.assertTrue("correct type " + c, c.isInstance(receivedBody)); if (body.getClass().isAssignableFrom(byte[].class)) { Arrays.equals((byte[]) body, (byte[]) receivedBody); } else { Assert.assertEquals( "clazz=" + c + ", bodies must match.. " + body.equals(receivedBody), body, receivedBody); } } else { try { Object foo = msg.getBody(c); Assert.fail("expected a " + MessageFormatException.class); } catch (MessageFormatException e) { // expected } } } }