Package org.springframework.amqp.core

Examples of org.springframework.amqp.core.Message


  }

  @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]);
    assertEquals(2, body[1]);
    assertEquals(3, body[2]);
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();
    assertEquals(testBean, deserializedObject);
  }
View Full Code Here

      messageProperties.setContentType(MessageProperties.CONTENT_TYPE_SERIALIZED_OBJECT);
    }
    if (bytes != null) {
      messageProperties.setContentLength(bytes.length);
    }
    return new Message(bytes, messageProperties);
  }
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

  }

  @Test
  public void messageToBytes() {
    SerializerMessageConverter converter = new SerializerMessageConverter();
    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);
    assertEquals(1, resultBytes[0]);
View Full Code Here

    TestBean testBean = new TestBean("foo");
    objectStream.writeObject(testBean);
    objectStream.flush();
    objectStream.close();
    byte[] bytes = byteStream.toByteArray();
    Message message = new Message(bytes, properties);
    Object result = converter.fromMessage(message);
    assertEquals(TestBean.class, result.getClass());
    assertEquals(testBean, result);
  }
View Full Code Here

    TestBean testBean = new TestBean("foo");
    objectStream.writeObject(testBean);
    objectStream.flush();
    objectStream.close();
    byte[] bytes = byteStream.toByteArray();
    Message message = new Message(bytes, properties);
    Object result = converter.fromMessage(message);
    assertEquals(TestBean.class, result.getClass());
    assertEquals(testBean, result);
  }
View Full Code Here

  }

  @Test
  public void stringToMessage() throws Exception {
    SerializerMessageConverter converter = new SerializerMessageConverter();
    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

TOP

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

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.