public class MessageTest extends TestCase {
public static final String VERSION = "$Id: MessageTest.java,v 1.9 2005/04/12 13:04:15 sanity Exp $";
public void testMessage() throws Exception {
MessageType request = new MessageType("Request");
request.addField("boolean", Boolean.class);
request.addField("byte", Byte.class);
request.addField("short", Short.class);
request.addField("int", Integer.class);
request.addField("string", String.class);
request.addField("buffer", Buffer.class);
request.addLinkedListField("list", String.class);
Message m1 = new Message(request);
m1.set("boolean", true);
m1.set("byte", (byte) 15);
m1.set("short", (short) 32);
m1.set("int", (int) 64);
m1.set("string", "gnirts");
Buffer b = new Buffer(new byte[10]);
m1.set("buffer", b);
LinkedList ll = new LinkedList();
ll.add("one");
ll.add("two");
ll.add("three");
m1.set("list", ll);
System.out.println("Original: " + m1);
DatagramPacket dp = m1.encodeToPacket();
Message m2 = Message.decodeFromPacket(dp);
System.out.println("Decoded: " + m2);
MessageFilter filter1 = MessageFilter.create(1000, request).setField("string", "abacus");
MessageFilter filter2 = MessageFilter.create(1000, request).setField("string", "gnirts");
assertFalse(filter1.match(m2));
assertTrue(filter2.match(m2));
request.unregister();
MessageType shortRequest = new MessageType("Request");
shortRequest.addField("boolean", Boolean.class);
shortRequest.addField("byte", Byte.class);
shortRequest.addField("short", Short.class);
shortRequest.addField("int", Integer.class);
Message m3 = Message.decodeFromPacket(dp);
System.out.println("Short decoded: "+m3);
Message m4 = new Message(shortRequest);
m4.set("boolean", true);
m4.set("byte", (byte) 15);
m4.set("short", (short) 32);
m4.set("int", (int) 64);
DatagramPacket dp2 = m4.encodeToPacket();
shortRequest.unregister();
request = new MessageType("Request");
request.addField("boolean", Boolean.class);
request.addField("byte", Byte.class);
request.addField("short", Short.class);
request.addField("int", Integer.class);
request.addField("string", String.class);