@Test public void testMessageCodecLookup() { for (Message message : testMessages) { MessageCodec<?> codec = codecLookup.find(message.getClass()); assertNotNull("Message " + message + " did not have a codec!", codec); MessageCodec<?> idCodec = codecLookup.find(codec.getOpcode()); assertNotNull("No codec for opcode " + codec.getOpcode() + " in codec lookup!", idCodec); } }
@Test @SuppressWarnings({"unchecked", "rawtypes"}) public void testMessageEncoding() throws IOException { for (Message message : testMessages) { MessageCodec codec = codecLookup.find(message.getClass()); ChannelBuffer encoded = codec.encodeToServer(message); Message decoded = codec.decodeFromClient(encoded); assertEquals("Failed (C -> S) for: " + message.getClass().getName(), message, decoded); encoded = codec.encodeToClient(message); decoded = codec.decodeFromServer(encoded); assertEquals("Failed (S -> C) for: " + message.getClass().getName(), message, decoded); } }
@Test public void testTestCompleteness() { final TIntSet testedOpcodes = new TIntHashSet(); for (Message message : testMessages) { MessageCodec<?> codec = codecLookup.find(message.getClass()); if (codec != null) { testedOpcodes.add(codec.getOpcode()); } } for (MessageCodec<?> codec : codecLookup.getCodecs()) { assertTrue( "Opcode " + codec.getOpcode() + " not tested", testedOpcodes.contains(codec.getOpcode())); } }
@Override public ChannelBuffer writeHeader(MessageCodec<?> codec, ChannelBuffer data) { ChannelBuffer buffer = ChannelBuffers.buffer(1); buffer.writeByte(codec.getOpcode()); return buffer; }