Tabnine Logo
SimpleMessageConverter.toMessage
Code IndexAdd Tabnine to your IDE (free)

How to use
toMessage
method
in
org.springframework.jms.support.converter.SimpleMessageConverter

Best Java code snippets using org.springframework.jms.support.converter.SimpleMessageConverter.toMessage (Showing top 9 results out of 315)

origin: spring-projects/spring-framework

@Test(expected = MessageConversionException.class)
public void testToMessageThrowsExceptionIfGivenIncompatibleObjectToConvert() throws Exception {
  new SimpleMessageConverter().toMessage(new Object(), null);
}
origin: spring-projects/spring-framework

@Test(expected = MessageConversionException.class)
public void testToMessageThrowsExceptionIfGivenNullObjectToConvert() throws Exception {
  new SimpleMessageConverter().toMessage(null, null);
}
origin: spring-projects/spring-framework

@Test
public void testMapConversionWhereMapHasNonStringTypesForKeys() throws JMSException {
  MapMessage message = mock(MapMessage.class);
  Session session = mock(Session.class);
  given(session.createMapMessage()).willReturn(message);
  Map<Integer, String> content = new HashMap<>(1);
  content.put(1, "value1");
  SimpleMessageConverter converter = new SimpleMessageConverter();
  try {
    converter.toMessage(content, session);
    fail("expected MessageConversionException");
  }
  catch (MessageConversionException ex) { /* expected */ }
}
origin: spring-projects/spring-framework

@Test
public void testMapConversionWhereMapHasNNullForKey() throws JMSException {
  MapMessage message = mock(MapMessage.class);
  Session session = mock(Session.class);
  given(session.createMapMessage()).willReturn(message);
  Map<Object, String> content = new HashMap<>(1);
  content.put(null, "value1");
  SimpleMessageConverter converter = new SimpleMessageConverter();
  try {
    converter.toMessage(content, session);
    fail("expected MessageConversionException");
  }
  catch (MessageConversionException ex) { /* expected */ }
}
origin: spring-projects/spring-framework

@Test
public void testToMessageSimplyReturnsMessageAsIsIfSuppliedWithMessage() throws JMSException {
  Session session = mock(Session.class);
  ObjectMessage message = mock(ObjectMessage.class);
  SimpleMessageConverter converter = new SimpleMessageConverter();
  Message msg = converter.toMessage(message, session);
  assertSame(message, msg);
}
origin: spring-projects/spring-framework

@Test
public void testStringConversion() throws JMSException {
  Session session = mock(Session.class);
  TextMessage message = mock(TextMessage.class);
  String content = "test";
  given(session.createTextMessage(content)).willReturn(message);
  given(message.getText()).willReturn(content);
  SimpleMessageConverter converter = new SimpleMessageConverter();
  Message msg = converter.toMessage(content, session);
  assertEquals(content, converter.fromMessage(msg));
}
origin: spring-projects/spring-framework

@Test
public void testSerializableConversion() throws JMSException {
  Session session = mock(Session.class);
  ObjectMessage message = mock(ObjectMessage.class);
  Integer content = new Integer(5);
  given(session.createObjectMessage(content)).willReturn(message);
  given(message.getObject()).willReturn(content);
  SimpleMessageConverter converter = new SimpleMessageConverter();
  Message msg = converter.toMessage(content, session);
  assertEquals(content, converter.fromMessage(msg));
}
origin: spring-projects/spring-framework

@Test
public void testMapConversion() throws JMSException {
  Session session = mock(Session.class);
  MapMessage message = mock(MapMessage.class);
  Map<String, String> content = new HashMap<>(2);
  content.put("key1", "value1");
  content.put("key2", "value2");
  given(session.createMapMessage()).willReturn(message);
  given(message.getMapNames()).willReturn(Collections.enumeration(content.keySet()));
  given(message.getObject("key1")).willReturn("value1");
  given(message.getObject("key2")).willReturn("value2");
  SimpleMessageConverter converter = new SimpleMessageConverter();
  Message msg = converter.toMessage(content, session);
  assertEquals(content, converter.fromMessage(msg));
  verify(message).setObject("key1", "value1");
  verify(message).setObject("key2", "value2");
}
origin: spring-projects/spring-framework

@Test
public void testByteArrayConversion() throws JMSException {
  Session session = mock(Session.class);
  BytesMessage message = mock(BytesMessage.class);
  byte[] content = "test".getBytes();
  final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(content);
  given(session.createBytesMessage()).willReturn(message);
  given(message.getBodyLength()).willReturn((long) content.length);
  given(message.readBytes(any(byte[].class))).willAnswer(new Answer<Integer>() {
    @Override
    public Integer answer(InvocationOnMock invocation) throws Throwable {
      return byteArrayInputStream.read((byte[]) invocation.getArguments()[0]);
    }
  });
  SimpleMessageConverter converter = new SimpleMessageConverter();
  Message msg = converter.toMessage(content, session);
  assertEquals(content.length, ((byte[]) converter.fromMessage(msg)).length);
  verify(message).writeBytes(content);
}
org.springframework.jms.support.converterSimpleMessageConvertertoMessage

Javadoc

This implementation creates a TextMessage for a String, a BytesMessage for a byte array, a MapMessage for a Map, and an ObjectMessage for a Serializable object.

Popular methods of SimpleMessageConverter

  • <init>
  • fromMessage
    This implementation converts a TextMessage back to a String, a ByteMessage back to a byte array, a M
  • createMessageForByteArray
    Create a JMS BytesMessage for the given byte array.
  • createMessageForMap
    Create a JMS MapMessage for the given Map.
  • createMessageForSerializable
    Create a JMS ObjectMessage for the given Serializable object.
  • createMessageForString
    Create a JMS TextMessage for the given String.
  • extractByteArrayFromMessage
    Extract a byte array from the given BytesMessage.
  • extractMapFromMessage
    Extract a Map from the given MapMessage.
  • extractSerializableFromMessage
    Extract a Serializable object from the given ObjectMessage.
  • extractStringFromMessage
    Extract a String from the given TextMessage.

Popular in Java

  • Making http post requests using okhttp
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getExternalFilesDir (Context)
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now