use of jakarta.jms.BytesMessage in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method fromBytesMessage.
@Test
void fromBytesMessage() throws Exception {
BytesMessage bytesMessageMock = mock(BytesMessage.class);
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
byte[] bytes = "{\"foo\":\"bar\"}".getBytes();
final ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes);
given(bytesMessageMock.getStringProperty("__typeid__")).willReturn(Object.class.getName());
given(bytesMessageMock.propertyExists("__encoding__")).willReturn(false);
given(bytesMessageMock.getBodyLength()).willReturn(Long.valueOf(bytes.length));
given(bytesMessageMock.readBytes(any(byte[].class))).willAnswer((Answer<Integer>) invocation -> byteStream.read((byte[]) invocation.getArguments()[0]));
Object result = converter.fromMessage(bytesMessageMock);
assertThat(unmarshalled).as("Invalid result").isEqualTo(result);
}
use of jakarta.jms.BytesMessage in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method toBytesMessage.
@Test
void toBytesMessage() throws Exception {
BytesMessage bytesMessageMock = mock(BytesMessage.class);
Date toBeMarshalled = new Date();
given(sessionMock.createBytesMessage()).willReturn(bytesMessageMock);
converter.toMessage(toBeMarshalled, sessionMock);
verify(bytesMessageMock).setStringProperty("__encoding__", "UTF-8");
verify(bytesMessageMock).setStringProperty("__typeid__", Date.class.getName());
verify(bytesMessageMock).writeBytes(isA(byte[].class));
}
Aggregations