QuickFixJTemplate implements QuickFixJOperations { @Override public boolean send(Message message) { Assert.notNull(message, "'message' must not be null"); SessionID sessionID = QuickFixJSessionID.quickFixJSessionIDBuilder() .message(message) .build().toSessionID(); return doSend(message, sessionID); } QuickFixJTemplate();  QuickFixJTemplate(SessionLookupHandler sessionLookupHandler); void setSessionLookupHandler(SessionLookupHandler sessionLookupHandler); void setDoValidation(boolean doValidation); @Override boolean send(Message message); @Override boolean send(Message message, String qualifier); @Override boolean send(Message message, String senderCompID, String targetCompID); @Override boolean send(Message message, String senderCompID, String targetCompID, String qualifier); @Override boolean send(Message message, SessionID sessionID);  }
@Test public void shouldSendMessage() throws FieldNotFound { mockMessage(expectedBeginString, expectedSender, expectedTarget); mockSessionFound(); SessionID expectedSessionID = new SessionID(expectedBeginString, expectedSender, expectedTarget); given(session.send(message)).willReturn(true); boolean sent = quickFixJTemplate.send(message); assertThat(sent).isTrue(); assertSessionID(expectedSessionID); assertMessageSent(expectedSender, expectedTarget); }
@Test public void shouldSendMessageWithQualifier() throws FieldNotFound { mockMessage(expectedBeginString, expectedSender, expectedTarget); mockSessionFound(); SessionID expectedSessionID = new SessionID(expectedBeginString, expectedSender, expectedTarget, expectedQualifier); given(session.send(message)).willReturn(true); boolean sent = quickFixJTemplate.send(message, expectedQualifier); assertThat(sent).isTrue(); assertSessionID(expectedSessionID); assertMessageSent(expectedSender, expectedTarget); }
@Test public void shouldSendMessageWithSenderAndTarget() throws FieldNotFound { mockMessage(expectedBeginString, expectedSender, expectedTarget); mockSessionFound(); SessionID expectedSessionID = new SessionID(expectedBeginString, expectedSender, expectedTarget); given(session.send(message)).willReturn(true); boolean sent = quickFixJTemplate.send(message, expectedSender, expectedTarget); assertThat(sent).isTrue(); assertSessionID(expectedSessionID); assertMessageSent(expectedSender, expectedTarget); }
@Test public void shouldSendMessageWithSenderAndTargetAndQualifier() throws FieldNotFound { mockMessage(expectedBeginString, expectedSender, expectedTarget); mockSessionFound(); SessionID expectedSessionID = new SessionID(expectedBeginString, expectedSender, expectedTarget, expectedQualifier); given(session.send(message)).willReturn(true); boolean sent = quickFixJTemplate.send(message, expectedSender, expectedTarget, expectedQualifier); assertThat(sent).isTrue(); assertSessionID(expectedSessionID); assertMessageSent(expectedSender, expectedTarget); }
@Test public void shouldSendMessageWithSessionID() throws FieldNotFound { mockMessage(expectedBeginString, expectedSender, expectedTarget); mockSessionFound(); SessionID expectedSessionID = new SessionID(expectedBeginString, expectedSender, expectedTarget, expectedQualifier); given(session.send(message)).willReturn(true); boolean sent = quickFixJTemplate.send(message, expectedSessionID); assertThat(sent).isTrue(); assertSessionID(expectedSessionID); assertMessageSent(expectedSender, expectedTarget); }
@Test public void shouldSendMessageWithValidation() throws FieldNotFound, IncorrectTagValue, IncorrectDataFormat { mockMessage(expectedBeginString, expectedSender, expectedTarget); mockSessionFound(); mockDataDictionary(); SessionID expectedSessionID = new SessionID(expectedBeginString, expectedSender, expectedTarget); given(session.send(message)).willReturn(true); boolean sent = quickFixJTemplate.send(message); assertSessionID(expectedSessionID); assertThat(sent).isTrue(); assertMessageSent(expectedSender, expectedTarget); ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class); verify(applicationDataDictionary).validate(messageCaptor.capture(), eq(true)); }
@Test public void shouldThrowSessionNotFoundException() throws FieldNotFound { mockMessage(expectedBeginString, expectedSender, expectedTarget); mockSessionNotFound(); assertThatExceptionOfType(SessionNotFoundException.class) .isThrownBy(() -> quickFixJTemplate.send(message)); }
@Test public void shouldThrowMessageValidationException() throws FieldNotFound, IncorrectTagValue, IncorrectDataFormat { mockMessage(expectedBeginString, expectedSender, expectedTarget); mockSessionFound(); mockDataDictionaryValidationFailure(); assertThatExceptionOfType(MessageValidationException.class) .isThrownBy(() -> quickFixJTemplate.send(message)); }
@Test public void shouldThrowFieldNotFoundExceptionWithInvalidTargetCompID() throws FieldNotFound { mockMessageWithInvalidTargetCompIDHeader(); assertThatExceptionOfType(FieldNotFoundException.class) .isThrownBy(() -> quickFixJTemplate.send(message)) .withMessageContaining("Field with ID 56 not found in message"); }
@Test public void shouldThrowFieldNotFoundExceptionWithInvalidSenderCompID() throws FieldNotFound { mockMessageWithInvalidSenderCompIDHeader(); assertThatExceptionOfType(FieldNotFoundException.class) .isThrownBy(() -> quickFixJTemplate.send(message)) .withMessageContaining("Field with ID 49 not found in message"); }
@Test public void shouldThrowFieldNotFoundExceptionWithInvalidBeginString() throws FieldNotFound { mockMessageWithInvalidBeginStringHeader(); assertThatExceptionOfType(FieldNotFoundException.class) .isThrownBy(() -> quickFixJTemplate.send(message)) .withMessageContaining("Field with ID 8 not found in message"); }