MessageCracker { public void crack(quickfix.Message message, SessionID sessionID) throws UnsupportedMessageType, FieldNotFound, IncorrectTagValue { Invoker invoker = invokers.get(message.getClass()); if (invoker != null) { try { invoker.Invoke(message, sessionID); } catch (InvocationTargetException ite) { try { throw ((InvocationTargetException)ite).getTargetException(); } catch (UnsupportedMessageType e) { throw e; } catch (FieldNotFound e) { throw e; } catch (IncorrectTagValue e) { throw e; } catch (Throwable t) { propagate(t); } } catch (Exception e) { propagate(e); } } else { onMessage(message, sessionID); } } protected  MessageCracker();  MessageCracker(Object messageHandler); void initialize(Object messageHandler); void crack(quickfix.Message message, SessionID sessionID);  }
@Test(expected=UnsupportedMessageType.class) public void testInvokerException1() throws Exception { quickfix.fixt11.Logon logon = new quickfix.fixt11.Logon(new EncryptMethod( EncryptMethod.NONE_OTHER), new HeartBtInt(30), new DefaultApplVerID(ApplVerID.FIX42)); MessageCracker cracker = new MessageCracker() { @SuppressWarnings("unused") @Handler public void handle(quickfix.fixt11.Logon logon, SessionID sessionID) throws UnsupportedMessageType { throw new UnsupportedMessageType(); } }; cracker.crack(logon, new SessionID(FixVersions.BEGINSTRING_FIXT11, "SENDER", "TARGET")); }
@Test(expected=FieldNotFound.class) public void testInvokerException2() throws Exception { quickfix.fixt11.Logon logon = new quickfix.fixt11.Logon(new EncryptMethod( EncryptMethod.NONE_OTHER), new HeartBtInt(30), new DefaultApplVerID(ApplVerID.FIX42)); MessageCracker cracker = new MessageCracker() { @SuppressWarnings("unused") @Handler public void handle(quickfix.fixt11.Logon logon, SessionID sessionID) throws FieldNotFound { throw new FieldNotFound(10); } }; cracker.crack(logon, new SessionID(FixVersions.BEGINSTRING_FIXT11, "SENDER", "TARGET")); }
@Test(expected=IncorrectTagValue.class) public void testInvokerException3() throws Exception { quickfix.fixt11.Logon logon = new quickfix.fixt11.Logon(new EncryptMethod( EncryptMethod.NONE_OTHER), new HeartBtInt(30), new DefaultApplVerID(ApplVerID.FIX42)); MessageCracker cracker = new MessageCracker() { @SuppressWarnings("unused") @Handler public void handle(quickfix.fixt11.Logon logon, SessionID sessionID) throws IncorrectTagValue { throw new IncorrectTagValue("test"); } }; cracker.crack(logon, new SessionID(FixVersions.BEGINSTRING_FIXT11, "SENDER", "TARGET")); }
@Test(expected=RuntimeException.class) public void testInvokerException4() throws Exception { quickfix.fixt11.Logon logon = new quickfix.fixt11.Logon(new EncryptMethod( EncryptMethod.NONE_OTHER), new HeartBtInt(30), new DefaultApplVerID(ApplVerID.FIX42)); MessageCracker cracker = new MessageCracker() { @SuppressWarnings("unused") @Handler public void handle(quickfix.fixt11.Logon logon, SessionID sessionID) throws InvalidObjectException { throw new InvalidObjectException("test"); } }; cracker.crack(logon, new SessionID(FixVersions.BEGINSTRING_FIXT11, "SENDER", "TARGET")); }
@Test public void testAnnotationBasedCracking() throws Exception { quickfix.fixt11.Logon logon = new quickfix.fixt11.Logon(new EncryptMethod( EncryptMethod.NONE_OTHER), new HeartBtInt(30), new DefaultApplVerID(ApplVerID.FIX42)); MessageCracker cracker = new MessageCracker() { @SuppressWarnings("unused") @Handler public void handle(quickfix.fixt11.Logon logon, SessionID sessionID) { messageCracked++; } }; cracker.crack(logon, new SessionID(FixVersions.BEGINSTRING_FIXT11, "SENDER", "TARGET")); assertTrue(messageCracked > 0); }
@Test() public void testFallback() throws Exception { quickfix.fixt11.Logon logon = new quickfix.fixt11.Logon(new EncryptMethod( EncryptMethod.NONE_OTHER), new HeartBtInt(30), new DefaultApplVerID(ApplVerID.FIX42)); MessageCracker cracker = new MessageCracker() { @Override protected void onMessage(Message message, SessionID sessionID) throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue { messageCracked++; } }; cracker.crack(logon, new SessionID(FixVersions.BEGINSTRING_FIXT11, "SENDER", "TARGET")); assertTrue(messageCracked > 0); }
@Test(expected=UnsupportedMessageType.class) public void testFallbackWithNoOverrid() throws Exception { quickfix.fixt11.Logon logon = new quickfix.fixt11.Logon(new EncryptMethod( EncryptMethod.NONE_OTHER), new HeartBtInt(30), new DefaultApplVerID(ApplVerID.FIX42)); MessageCracker cracker = new MessageCracker(); cracker.crack(logon, new SessionID(FixVersions.BEGINSTRING_FIXT11, "SENDER", "TARGET")); }
@Test() public void testExternalDelegation() throws Exception { quickfix.fixt11.Logon logon = new quickfix.fixt11.Logon(new EncryptMethod( EncryptMethod.NONE_OTHER), new HeartBtInt(30), new DefaultApplVerID(ApplVerID.FIX42)); MessageCracker cracker = new MessageCracker(new MessageHandler()); cracker.crack(logon, new SessionID(FixVersions.BEGINSTRING_FIXT11, "SENDER", "TARGET")); assertTrue(messageCracked > 0); }
@Test public void testFixT11AppMessageCracking() throws Exception { quickfix.fix50.Email message = new quickfix.fix50.Email(); message.getHeader().setString(BeginString.FIELD, FixVersions.BEGINSTRING_FIXT11); message.getHeader().setString(SenderCompID.FIELD, "SENDER"); message.getHeader().setString(TargetCompID.FIELD, "TARGET"); message.getHeader().setString(ApplVerID.FIELD, ApplVerID.FIX50); MessageCracker cracker = new MessageCracker() { @SuppressWarnings("unused") public void onMessage(quickfix.fix50.Email email, SessionID sessionID) { messageCracked++; } }; cracker.crack(message, new SessionID(FixVersions.BEGINSTRING_FIXT11, "SENDER", "TARGET")); assertTrue(messageCracked > 0); }
@Test public void testFixtMessageCrackingWithNonFix50ApplVerID() throws Exception { quickfix.fix44.Email message = createFix44Email(); message.getHeader().setString(ApplVerID.FIELD, ApplVerID.FIX44); MessageCracker cracker = new MessageCracker() { @SuppressWarnings("unused") public void onMessage(quickfix.fix44.Email email, SessionID sessionID) { messageCracked++; } }; cracker.crack(message, new SessionID(FixVersions.BEGINSTRING_FIXT11, "SENDER", "TARGET")); assertTrue(messageCracked > 0); }
@Test public void testFixtMessageCrackingWithSessionDefaultApplVerID() throws Exception { quickfix.fix44.Email message = createFix44Email(); stub(mockSession.getTargetDefaultApplicationVersionID()).toReturn( new ApplVerID(ApplVerID.FIX44)); MessageCracker cracker = new MessageCracker() { @SuppressWarnings("unused") public void onMessage(quickfix.fix44.Email email, SessionID sessionID) { messageCracked++; } }; cracker.crack(message, new SessionID(FixVersions.BEGINSTRING_FIXT11, "SENDER", "TARGET")); assertTrue(messageCracked > 0); }
@Test public void testFixtAdminMessageCracking() throws Exception { quickfix.fixt11.Logon logon = new quickfix.fixt11.Logon(new EncryptMethod( EncryptMethod.NONE_OTHER), new HeartBtInt(30), new DefaultApplVerID(ApplVerID.FIX42)); MessageCracker cracker = new MessageCracker() { @SuppressWarnings("unused") public void onMessage(quickfix.fixt11.Logon logon, SessionID sessionID) { messageCracked++; } }; cracker.crack(logon, new SessionID(FixVersions.BEGINSTRING_FIXT11, "SENDER", "TARGET")); assertTrue(messageCracked > 0); }