FIXMessageDecoder implements MessageDecoder { @Override public MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws ProtocolCodecException { int messageCount = 0; while (parseMessage(in, out)) { messageCount++; } if (messageCount > 0) { if (state == SEEKING_HEADER) { position = 0; } return MessageDecoderResult.OK; } else { position -= in.position(); return MessageDecoderResult.NEED_DATA; } } FIXMessageDecoder();  FIXMessageDecoder(String charset);  FIXMessageDecoder(String charset, String delimiter); @Override MessageDecoderResult decodable(IoSession session, IoBuffer in); @Override MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out); @Override void finishDecode(IoSession session, ProtocolDecoderOutput out); List<String> extractMessages(File file); void extractMessages(File file, final MessageListener listener);  }
@Test public void testStringDecoding() throws Exception { decoder = new FIXMessageDecoder("UTF-16"); setUpBuffer("8=FIX.4.2\0019=12\00135=X\001108=30\00110=049\001"); MessageDecoderResult decoderResult = decoder.decode(null, buffer, decoderOutput); assertEquals("wrong decoder result", MessageDecoderResult.OK, decoderResult); assertEquals("Wrong encoding", 14397, (int) decoderOutput.getMessage().charAt(0)); }
@Test public void testFixtStringDecoding() throws Exception { decoder = new FIXMessageDecoder("UTF-16"); setUpBuffer("8=FIXT.1.1\0019=12\00135=X\001108=30\00110=049\001"); MessageDecoderResult decoderResult = decoder.decode(null, buffer, decoderOutput); assertEquals("wrong decoder result", MessageDecoderResult.OK, decoderResult); assertEquals("Wrong encoding", 14397, (int) decoderOutput.getMessage().charAt(0)); }
@Test public void testMessageWithoutChecksum() throws Exception { String badMessage = "8=FIX.4.4\0019=275\00135=D\00134=3\00149=441000-XXXXX-X-XXXX-001\00152=20131113-10:22:31.567\00156=XXXXX\0011=A1\00111=9fef3663330e209e1bce\00118=H\001" + "22=4\00138=200\00140=M\00148=XX0005519XXXX\00154=1\00155=[N/A]\00158=MassTest\00159=0\00160=20131113-10:22:31.567\001100=XXXX\001" + "526=9fef3663330e209e1bce\00125029=12345\001453=1\001448=XXXXXXXX030\001447=D\001452=3610=016\001"; setUpBuffer(badMessage); assertEquals("wrong decoder result", MessageDecoderResult.NEED_DATA, decoder.decode(null, buffer, decoderOutput)); }
@Test public void testBadLengthOnLogon() throws Exception { String badMessage = "8=FIX.4.2\0019=10\00135=A\001108=30\00110=036\001"; setUpBuffer(badMessage); try { decoder.decode(null, buffer, decoderOutput); fail("no exception"); } catch (CriticalProtocolCodecException e) { } }
@Test public void testNPE() throws Exception { try { decoder.decode(null, null, null); fail("no exception"); } catch (ProtocolCodecException e) { assertTrue(e.getCause() instanceof NullPointerException); } }
@Test public void testFailedPatternMatchAtEndOfBuffer() throws Exception { decoder = new FIXMessageDecoder("UTF-16"); setUpBuffer("8=FIX.4.2\0019=12\00135=X\001108=30\0011wmyadz"); MessageDecoderResult decoderResult = decoder.decode(null, buffer, decoderOutput); assertEquals("wrong decoder result", MessageDecoderResult.NEED_DATA, decoderResult); }