@SuppressWarnings({"rawtypes", "unchecked" })
private void testBeans(final MessageBodyWriter producer, final MessageBodyReader consumer) {
final MutableFudgeMsg msgIn = OpenGammaFudgeContext.getInstance().newMessage();
msgIn.add("foo", "bar");
msgIn.add("number", 42);
final FudgeMsgEnvelope msgInEnv = new FudgeMsgEnvelope(msgIn, 0, 0);
assertTrue(producer.isWriteable(msgInEnv.getClass(), null, null, null));
final long predictedSize = producer.getSize(msgInEnv, null, null, null, null);
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
producer.writeTo(msgInEnv, msgInEnv.getClass(), null, null, null, null, bos);
} catch (IOException e) {
throw new OpenGammaRuntimeException("ioexception", e);
}
final byte[] data = bos.toByteArray();
if (predictedSize != -1) {
assertEquals(predictedSize, data.length);
}
assertTrue(consumer.isReadable(FudgeMsgEnvelope.class, null, null, null));
final ByteArrayInputStream bis = new ByteArrayInputStream(data);
final FudgeMsg msgOut;
try {
final FudgeMsgEnvelope env = (FudgeMsgEnvelope) consumer.readFrom(FudgeMsgEnvelope.class, null, null, null, null, bis);
assertNotNull(env);
msgOut = env.getMessage();
} catch (IOException e) {
throw new OpenGammaRuntimeException("ioexception", e);
}
assertNotNull(msgOut);
assertEquals("bar", msgOut.getFieldValue(String.class, msgOut.getByName("foo")));