private void execute(final Message message)
throws Exception
{
assertNotNull("Created message", message) ;
message.getHeader().getCall().setTo(new EPR(new URI("test:to_uri"))) ;
final Context context = message.getContext() ;
assertNotNull("Context", context) ;
final Object result1 = context.setContext("foo", "bar") ;
assertNull("First setter result", result1) ;
assertEquals("Getting context", "bar", context.getContext("foo")) ;
final Set<String> keys = context.getContextKeys() ;
assertNotNull("Context keys", keys) ;
assertEquals("Context key count", 1, keys.size()) ;
assertTrue("Contains key", keys.contains("foo")) ;
final Object result2 = context.setContext("foo", "bar2") ;
assertEquals("Second setter result", "bar", result2) ;
assertEquals("Getting context", "bar2", context.getContext("foo")) ;
final Set<String> keys2 = context.getContextKeys() ;
assertNotNull("Context keys2", keys2) ;
assertEquals("Context key count", 1, keys2.size()) ;
assertTrue("Contains key", keys2.contains("foo")) ;
context.clearContext() ;
final Set<String> keys3 = context.getContextKeys() ;
assertNotNull("Context keys3", keys3) ;
assertEquals("Context key count", 0, keys3.size()) ;
try
{
context.setContext("non-serializable", new Object()) ;
fail("Non serializable object set on context");
}
catch (IllegalArgumentException ex) {} // expected
context.setContext("skey", "svalue") ;
final Serializable serializable = Util.serialize(message) ;
final ByteArrayOutputStream baos = new ByteArrayOutputStream() ;
final ObjectOutputStream oos = new ObjectOutputStream(baos) ;
oos.writeObject(serializable);
oos.close();
final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()) ;
final ObjectInputStream ois = new ObjectInputStream(bais) ;
final Serializable newSerializable = (Serializable)ois.readObject() ;
final Message newMessage = Util.deserialize(newSerializable) ;
assertEquals("Serialized context", "svalue", newMessage.getContext().getContext("skey")) ;
assertTrue("Implements ByReferenceMessage", (message instanceof ByReferenceMessage)) ;
final Message referencedMessage = ((ByReferenceMessage)message).reference() ;
assertSame("Attachment is same", message.getAttachment(), referencedMessage.getAttachment()) ;
assertSame("Body is same", message.getBody(), referencedMessage.getBody()) ;
assertSame("Fault is same", message.getFault(), referencedMessage.getFault()) ;
assertSame("Properties are same", message.getProperties(), referencedMessage.getProperties()) ;
assertSame("type is same", message.getType(), referencedMessage.getType()) ;
assertNotSame("header is not same", message.getHeader(), referencedMessage.getHeader()) ;
assertNotSame("Context is not same", context, referencedMessage.getContext()) ;
assertEquals("Header equals", message.getHeader().getCall().getTo(), referencedMessage.getHeader().getCall().getTo()) ;
message.getHeader().getCall().setTo(new EPR(new URI("test:to_uri2"))) ;
assertFalse("Header not equals", message.getHeader().getCall().getTo().equals(referencedMessage.getHeader().getCall().getTo())) ;
assertEquals("Context equals", context.getContext("skey"), referencedMessage.getContext().getContext("skey")) ;
context.setContext("skey", "other value") ;
assertFalse("Context not equals", context.getContext("skey").equals(referencedMessage.getContext().getContext("skey"))) ;