Package org.springframework.amqp.core

Examples of org.springframework.amqp.core.MessageProperties


public class SimpleMessageConverterTests {

  @Test
  public void bytesAsDefaultMessageBodyType() throws Exception {
    SimpleMessageConverter converter = new SimpleMessageConverter();
    Message message = new Message("test".getBytes(), new MessageProperties());
    Object result = converter.fromMessage(message);
    assertEquals(byte[].class, result.getClass());
    assertEquals("test", new String((byte[]) result, "UTF-8"));
  }
View Full Code Here


  }

  @Test
  public void messageToString() {
    SimpleMessageConverter converter = new SimpleMessageConverter();
    Message message = new Message("test".getBytes(), new MessageProperties());
    message.getMessageProperties().setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN);
    Object result = converter.fromMessage(message);
    assertEquals(String.class, result.getClass());
    assertEquals("test", result);
  }
View Full Code Here

  }

  @Test
  public void messageToBytes() {
    SimpleMessageConverter converter = new SimpleMessageConverter();
    Message message = new Message(new byte[] { 1, 2, 3 }, new MessageProperties());
    message.getMessageProperties().setContentType(MessageProperties.CONTENT_TYPE_BYTES);
    Object result = converter.fromMessage(message);
    assertEquals(byte[].class, result.getClass());
    byte[] resultBytes = (byte[]) result;
    assertEquals(3, resultBytes.length);
View Full Code Here

  }

  @Test
  public void messageToSerializedObject() throws Exception {
    SimpleMessageConverter converter = new SimpleMessageConverter();
    MessageProperties properties = new MessageProperties();
    properties.setContentType(MessageProperties.CONTENT_TYPE_SERIALIZED_OBJECT);
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    ObjectOutputStream objectStream = new ObjectOutputStream(byteStream);
    TestBean testBean = new TestBean("foo");
    objectStream.writeObject(testBean);
    objectStream.flush();
View Full Code Here

  }

  @Test
  public void stringToMessage() throws Exception {
    SimpleMessageConverter converter = new SimpleMessageConverter();
    Message message = converter.toMessage("test", new MessageProperties());
    String contentType = message.getMessageProperties().getContentType();
    String content = new String(message.getBody(),
        message.getMessageProperties().getContentEncoding());
    assertEquals("text/plain", contentType);
    assertEquals("test", content);
View Full Code Here

  }

  @Test
  public void bytesToMessage() throws Exception {
    SimpleMessageConverter converter = new SimpleMessageConverter();
    Message message = converter.toMessage(new byte[] { 1, 2, 3 }, new MessageProperties());
    String contentType = message.getMessageProperties().getContentType();
    byte[] body = message.getBody();
    assertEquals("application/octet-stream", contentType);
    assertEquals(3, body.length);
    assertEquals(1, body[0]);
View Full Code Here

  @Test
  public void serializedObjectToMessage() throws Exception {
    SimpleMessageConverter converter = new SimpleMessageConverter();
    TestBean testBean = new TestBean("foo");
    Message message = converter.toMessage(testBean, new MessageProperties());
    String contentType = message.getMessageProperties().getContentType();
    byte[] body = message.getBody();
    assertEquals("application/x-java-serialized-object", contentType);
    ByteArrayInputStream bais = new ByteArrayInputStream(body);
    Object deserializedObject = new ObjectInputStream(bais).readObject();
View Full Code Here

   * Converts from a AMQP Message to an Object.
   */
  @Override
  public Object fromMessage(Message message) throws MessageConversionException {
    Object content = null;
    MessageProperties properties = message.getMessageProperties();
    if (properties != null) {
      String contentType = properties.getContentType();
      if (contentType != null && contentType.startsWith("text")) {
        String encoding = properties.getContentEncoding();
        if (encoding == null) {
          encoding = this.defaultCharset;
        }
        try {
          content = new String(message.getBody(), encoding);
View Full Code Here

public class SerializerMessageConverterTests {

  @Test
  public void bytesAsDefaultMessageBodyType() throws Exception {
    SerializerMessageConverter converter = new SerializerMessageConverter();
    Message message = new Message("test".getBytes(), new MessageProperties());
    Object result = converter.fromMessage(message);
    assertEquals(byte[].class, result.getClass());
    assertEquals("test", new String((byte[]) result, "UTF-8"));
  }
View Full Code Here

  }

  @Test
  public void messageToString() {
    SerializerMessageConverter converter = new SerializerMessageConverter();
    Message message = new Message("test".getBytes(), new MessageProperties());
    message.getMessageProperties().setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN);
    Object result = converter.fromMessage(message);
    assertEquals(String.class, result.getClass());
    assertEquals("test", result);
  }
View Full Code Here

TOP

Related Classes of org.springframework.amqp.core.MessageProperties

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.