├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── build.gradle ├── diagrams └── eventing ├── dist └── 1.4 │ ├── fix4j-assert-acceptance-1.4.jar │ ├── fix4j-assert-all-1.4.jar │ ├── fix4j-assert-codegen-1.4.jar │ ├── fix4j-assert-core-1.4.jar │ ├── fix4j-assert-fixspec-50sp2-1.4.jar │ ├── fix4j-assert-integration-1.4.jar │ ├── fix4j-assert-quickfix-1.4.jar │ └── fix4j-assert-testcommon-1.4.jar ├── fix4j-assert-acceptance ├── build.gradle └── src │ └── test │ ├── groovy │ └── org │ │ └── fix4j │ │ └── test │ │ └── acceptance │ │ ├── BlockingSessionTest.groovy │ │ ├── BlockingSessionTimeoutTest.groovy │ │ ├── ConsumerSessionTest.groovy │ │ ├── MatchingSessionTest.groovy │ │ ├── MatchingSessionTimeoutTest.groovy │ │ └── OnFailureReportsTest.groovy │ └── resources │ └── foo.properties ├── fix4j-assert-all ├── build.gradle └── src │ └── main │ └── java │ └── org │ └── fix4j │ └── test │ └── DefaultContextFactory.java ├── fix4j-assert-codegen ├── build.gradle └── src │ └── main │ ├── groovy │ └── org │ │ └── fix4j │ │ └── spec │ │ └── codegen │ │ ├── Asserts.groovy │ │ ├── CompositeContentHelper.groovy │ │ ├── FieldClassEnumCreator.groovy │ │ ├── FieldTypeCreator.groovy │ │ ├── FieldTypesEnumCreator.groovy │ │ ├── FixSpecificationClassCreator.groovy │ │ ├── MsgTypeCreator.groovy │ │ ├── MsgTypesEnumCreator.groovy │ │ ├── SpecParser.groovy │ │ ├── StandardHeaderCreator.groovy │ │ ├── StandardTrailerCreator.groovy │ │ └── Util.groovy │ └── resources │ ├── specifications │ └── FIX44.xml │ └── templates │ ├── FieldTypes.java │ ├── FixSpec.java │ └── MsgTypes.java ├── fix4j-assert-core ├── build.gradle └── src │ ├── main │ └── java │ │ └── org │ │ └── fix4j │ │ └── test │ │ ├── expression │ │ ├── FlexibleMessageExpressionParser.java │ │ ├── MessageExpression.java │ │ └── RawFixMessageExpressionParser.java │ │ ├── fixmodel │ │ ├── BaseFieldsAndGroups.java │ │ ├── BaseFixMessage.java │ │ ├── BaseFixMessageBuilder.java │ │ ├── BaseGroup.java │ │ ├── Field.java │ │ ├── FieldSource.java │ │ ├── FieldsAndGroups.java │ │ ├── FieldsAndGroupsBuilder.java │ │ ├── FixMessage.java │ │ ├── FixMessageUnflattener.java │ │ ├── Group.java │ │ ├── GroupBuilder.java │ │ ├── Handler.java │ │ ├── PrettyPrintable.java │ │ ├── PrettyStripper.java │ │ └── RegexMatchingField.java │ │ ├── fixspec │ │ ├── BaseFieldAndGroupTypes.java │ │ ├── BaseFieldType.java │ │ ├── BaseGroupType.java │ │ ├── BaseMsgType.java │ │ ├── BaseTag.java │ │ ├── FieldAndGroupTypes.java │ │ ├── FieldClass.java │ │ ├── FieldClassLookup.java │ │ ├── FieldType.java │ │ ├── FieldTypeSource.java │ │ ├── FieldTypeValue.java │ │ ├── FieldTypeValueEnum.java │ │ ├── FixSpecification.java │ │ ├── GroupKey.java │ │ ├── GroupType.java │ │ ├── MemberFieldType.java │ │ ├── MessageChildType.java │ │ ├── MessageExampleGenerator.java │ │ ├── MsgType.java │ │ ├── Tag.java │ │ └── Type.java │ │ ├── integration │ │ ├── FixEngineSession.java │ │ ├── FixEngineSessionFactory.java │ │ ├── FixSessionIdConverter.java │ │ └── MessageConverter.java │ │ ├── matching │ │ ├── FixFieldMatchResult.java │ │ ├── MatchingInboundSession.java │ │ ├── matchactivity │ │ │ ├── DiscardUntilFirstMatchThenRunSecondMatchProcessor.java │ │ │ ├── DiscardUntilMatchProcessor.java │ │ │ ├── DiscardedMessageReport.java │ │ │ ├── MatchActivity.java │ │ │ ├── MatchActivityDirectiveAndReport.java │ │ │ ├── MatchActivityMessageProcessor.java │ │ │ ├── MatchActivityResult.java │ │ │ ├── MatchFailureTextFactory.java │ │ │ └── MustMatchFirstMessage.java │ │ └── matchers │ │ │ ├── BaseMatchResult.java │ │ │ ├── FixMessageMatcher.java │ │ │ ├── MatchEveryMessageMatcher.java │ │ │ ├── MatchNoMessagesMatcher.java │ │ │ ├── MatchResult.java │ │ │ ├── MsgTypeMatcher.java │ │ │ └── SimpleMatchResult.java │ │ ├── messageflags │ │ ├── MessageFlag.java │ │ ├── MessageFlagRule.java │ │ ├── MessageFlagRules.java │ │ ├── MessageFlags.java │ │ ├── MissingRequiredFieldMessageFlagRule.java │ │ ├── SessionLevelRejectMessageFlagRule.java │ │ └── SimpleMessageFlagRule.java │ │ ├── plumbing │ │ ├── AbstractChainedConsumer.java │ │ ├── AbstractChainedSupplier.java │ │ ├── BlockingPipe.java │ │ ├── Consumer.java │ │ ├── ExceptionHandler.java │ │ ├── Filter.java │ │ ├── Processor.java │ │ ├── Provider.java │ │ ├── ShuntFromSupplierToConsumer.java │ │ └── Supplier.java │ │ ├── processors │ │ ├── FixMessageProcessors.java │ │ ├── InboundIgnoreProcessor.java │ │ ├── InboundMessageFlagFailureProcessor.java │ │ ├── InboundProcessors.java │ │ ├── InboundRecentMessageProcessor.java │ │ ├── OnFailureReporter.java │ │ ├── OnFailureReporters.java │ │ ├── OutboundMessageFlagFailureProcessor.java │ │ ├── OutboundProcessors.java │ │ └── OutboundRecentMessageProcessor.java │ │ ├── properties │ │ ├── ApplicationProperties.java │ │ ├── ApplicationPropertiesFactory.java │ │ ├── CompositePropertyMap.java │ │ ├── ImmutablePropertyAndSource.java │ │ ├── MapPropertySource.java │ │ ├── MutablePropertyAndSource.java │ │ ├── PropertyAndSource.java │ │ ├── PropertyKeysAndDefaultValues.java │ │ ├── PropertySource.java │ │ ├── PropertyUtils.java │ │ ├── SystemEnvVariablePropertySource.java │ │ └── SystemPropertySource.java │ │ ├── session │ │ ├── AbstractContextFactory.java │ │ ├── BlockingSession.java │ │ ├── ConsumerSession.java │ │ ├── ContextFactory.java │ │ ├── DispatchingSession.java │ │ ├── Failure.java │ │ ├── FixConnectionMode.java │ │ ├── FixSession.java │ │ ├── FixSessionId.java │ │ ├── MatchingSession.java │ │ ├── MessageDispatcher.java │ │ ├── RecentMessages.java │ │ ├── SessionConnectors.java │ │ ├── SessionContext.java │ │ ├── SimpleOutboundSession.java │ │ ├── TestClientSession.java │ │ ├── TestSessionHelper.java │ │ └── TimeoutReport.java │ │ └── util │ │ ├── ArrayListMultimap.java │ │ ├── Asserts.java │ │ ├── BaseReport.java │ │ ├── BoundedArray.java │ │ ├── CompositeReport.java │ │ ├── Consts.java │ │ ├── DateUtils.java │ │ ├── ExceptionUtils.java │ │ ├── Keyable.java │ │ ├── Multimap.java │ │ ├── PeekableIterator.java │ │ ├── Report.java │ │ ├── ReportLevel.java │ │ ├── Reportable.java │ │ ├── StringUtils.java │ │ ├── TwoWayMap.java │ │ └── Utils.java │ └── test │ └── groovy │ └── org │ └── fix4j │ └── test │ ├── fixmodel │ ├── FieldTest.groovy │ └── RegexMatchingFieldTest.groovy │ ├── fixspec │ ├── BaseFieldAndGroupTypesTest.groovy │ ├── BaseGroupTypeTest.groovy │ ├── BaseMsgTypeTest.groovy │ └── ExampleTypes.groovy │ ├── properties │ ├── CompositePropertyMapTest.groovy │ └── SystemEnvVariablePropertySourceTest.groovy │ └── util │ ├── ArrayListMultimapTest.groovy │ ├── AssertsTest.groovy │ ├── BoundedArrayTest.groovy │ ├── DateUtilsTest.groovy │ ├── PeekableIteratorTest.groovy │ └── StringUtilsTest.groovy ├── fix4j-assert-examples ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ └── test │ ├── java │ └── org │ │ └── fix4j │ │ └── test │ │ └── examples │ │ ├── clients │ │ ├── MatchingSessionTest.java │ │ └── VariousMessageFormatsTest.java │ │ ├── config │ │ ├── CustomFixEngine.java │ │ ├── CustomInboundProcessorWhichDropsAMessage.java │ │ ├── CustomOutboundProcessorWhichDropsAMessage.java │ │ ├── CustomOutboundProcessorWhichPopulatesAMessageField.java │ │ ├── CustomOutboundProcessorWhichRaisesATestFailure.java │ │ └── SpecifyingTestProperties.java │ │ ├── servers │ │ ├── DispatchingSessionsTest.java │ │ └── MultipleSessionsTest.java │ │ └── utils │ │ ├── TestServerToJustLogIncomingMessages.java │ │ └── TestServerToPriceAndFillAnOrder.java │ └── resources │ └── foo.properties ├── fix4j-assert-fixspec-50sp2 ├── build.gradle └── src │ └── codegen │ └── resources │ └── FIX50SP2.xml ├── fix4j-assert-integration ├── build.gradle └── src │ └── test │ └── groovy │ └── org │ └── fix4j │ └── test │ ├── expression │ ├── MatcherParserTest.groovy │ └── MessageExpressionMatcherTest.groovy │ ├── fixmodel │ ├── BaseFixMessageBuilderTest.groovy │ ├── BaseFixMessageTest.groovy │ └── PrettyStripperTest.groovy │ ├── fixspec │ ├── BaseFieldAndGroupTypesTest.groovy │ └── MessageExampleGeneratorTest.groovy │ ├── matching │ ├── FlexibleMessageExpressionParserTest.groovy │ └── RawFixMessageExpressionParserTest.groovy │ ├── messageflags │ ├── MessageFlagRuleTest.groovy │ └── MissingRequiredFieldMessageFlagRuleTest.groovy │ └── session │ └── MessageDispatcherTest.groovy ├── fix4j-assert-quickfix ├── build.gradle └── src │ ├── main │ └── java │ │ └── org │ │ └── fix4j │ │ └── test │ │ └── integration │ │ └── quickfix │ │ ├── FromQuickFixMessageConverter.java │ │ ├── QuickFixApplication.java │ │ ├── QuickFixProperties.java │ │ ├── QuickFixSessionIdConverter.java │ │ ├── QuickFixTestSession.java │ │ ├── QuickFixTestSessionFactory.java │ │ └── ToQuickFixMessageConverter.java │ └── test │ └── groovy │ └── org │ └── fix4j │ └── test │ └── integration │ └── quickfix │ └── ToQuickFixMessageConverterTest.groovy ├── fix4j-assert-testcommon ├── build.gradle └── src │ └── main │ ├── java │ └── org │ │ └── fix4j │ │ └── test │ │ └── TestMessages.java │ └── resources │ └── log4j.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── resources ├── 21dd4eee1c8b6e2318124f5e2b4836.gif ├── 27f0f25e146ee91d9c18b1ce5b9177.gif ├── 3ef573e56e86dbcb636c873ee72c7b.gif ├── 584253c733399f0bdf89fd6788828e.gif ├── 61099ab32b9bd7a4b9afa39a552ae723.png ├── 620aa92ec747a7e9dd5b76aabea55f.gif ├── 6856420882_017d7cfd5b_o.jpg ├── 7002530447_06208c6b6f_o.jpg ├── 7956f338891f3d3280044d8f4ad57b.gif ├── GitHub-Logo.png ├── c0253b51f6e7e723f93035cad2c837.gif ├── cd2d5acc4fc1854069e754cf0d1f77.gif ├── e29050824ed2a1d92a2a10eceda040.gif ├── f290c34b1268e94a01b5d1c28b3158.gif ├── github-logo-white-on-black.jpg ├── github-logo-white.png ├── github.png ├── jpeg_905.jpg └── right-cerulean@2x.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | **/target 2 | *.iml 3 | **/.idea/* 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | -------------------------------------------------------------------------------- /diagrams/eventing: -------------------------------------------------------------------------------- 1 | #![Fix message path] 2 | ext:External[pe] 3 | qfa:QuickFixApplication[at] 4 | qfts:QuickFixTestSession[a] 5 | fromQuickFixMessageConverter:Consumer 6 | fromThirdPartyFixEngine:BlockingPipe 7 | toThirdPartyFixEngine:BlockingPipe 8 | fromNetwork-to-fixMessageQueue:Shunt[t] 9 | fixMessageQueue:BlockingPipe 10 | fixTestClientSession:FixTestClientSession[a] 11 | fixMessageAsserter:FixMessageAsserter[a] 12 | test:Test[at] 13 | 14 | 15 | *1 fromNetwork-to-fixMessageQueue 16 | fromNetwork-to-fixMessageQueue 17 | Created in:FixTestClientSession 18 | *1 19 | 20 | *1 fixMessageQueue 21 | fixMessageQueue 22 | Created in:FixTestClientSession 23 | *1 24 | 25 | *1 fromThirdPartyFixEngine 26 | fromThirdPartyFixEngine 27 | Created in:TestHelper 28 | *1 29 | 30 | *1 toThirdPartyFixEngine 31 | toThirdPartyFixEngine 32 | Created in:TestHelper 33 | *1 34 | 35 | *1 fromQuickFixMessageConverter 36 | fromQuickFixMessageConverter 37 | Created in: FromQuickFixMessageConverter 38 | by: QuickFixTestSession 39 | *1 40 | 41 | qfa:fromQuickFixMessageConverter.accept(fixMessage) 42 | fromQuickFixMessageConverter:fromThirdPartyFixEngine.accept(simpleMessage) 43 | fromNetwork-to-fixMessageQueue:fromThirdPartyFixEngine.get() returns Message 44 | fromNetwork-to-fixMessageQueue:fixMessageQueue.accept(simpleMessage) 45 | test:fixTestClientSession.discardUntilExpected() 46 | fixTestClientSession:fixMessageQueue.get()/poll() returns simpleMessage 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /dist/1.4/fix4j-assert-acceptance-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/dist/1.4/fix4j-assert-acceptance-1.4.jar -------------------------------------------------------------------------------- /dist/1.4/fix4j-assert-all-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/dist/1.4/fix4j-assert-all-1.4.jar -------------------------------------------------------------------------------- /dist/1.4/fix4j-assert-codegen-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/dist/1.4/fix4j-assert-codegen-1.4.jar -------------------------------------------------------------------------------- /dist/1.4/fix4j-assert-core-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/dist/1.4/fix4j-assert-core-1.4.jar -------------------------------------------------------------------------------- /dist/1.4/fix4j-assert-fixspec-50sp2-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/dist/1.4/fix4j-assert-fixspec-50sp2-1.4.jar -------------------------------------------------------------------------------- /dist/1.4/fix4j-assert-integration-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/dist/1.4/fix4j-assert-integration-1.4.jar -------------------------------------------------------------------------------- /dist/1.4/fix4j-assert-quickfix-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/dist/1.4/fix4j-assert-quickfix-1.4.jar -------------------------------------------------------------------------------- /dist/1.4/fix4j-assert-testcommon-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/dist/1.4/fix4j-assert-testcommon-1.4.jar -------------------------------------------------------------------------------- /fix4j-assert-acceptance/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | description = '' 3 | dependencies { 4 | compile project(':fix4j-assert-core') 5 | compile project(':fix4j-assert-all') 6 | compile project(':fix4j-assert-testcommon') 7 | } 8 | -------------------------------------------------------------------------------- /fix4j-assert-acceptance/src/test/groovy/org/fix4j/test/acceptance/BlockingSessionTimeoutTest.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.acceptance; 2 | 3 | import org.fix4j.spec.fix50sp2.MsgTypes; 4 | import org.fix4j.test.DefaultContextFactory; 5 | import org.fix4j.test.fixmodel.FixMessage; 6 | import org.fix4j.test.session.BlockingSession; 7 | import org.fix4j.test.session.FixConnectionMode; 8 | import org.fix4j.test.session.FixSessionId; 9 | import org.fix4j.test.session.TestSessionHelper; 10 | import org.junit.AfterClass 11 | import org.junit.Before; 12 | import org.junit.BeforeClass; 13 | import org.junit.Test 14 | import spock.lang.Specification; 15 | 16 | import java.util.concurrent.atomic.AtomicReference; 17 | 18 | import static org.junit.Assert.fail; 19 | 20 | /** 21 | * User: ben 22 | * Date: 13/08/2014 23 | * Time: 8:57 PM 24 | */ 25 | public class BlockingSessionTimeoutTest extends Specification{ 26 | private static BlockingSession server; 27 | private static BlockingSession client; 28 | 29 | public void setup() throws InterruptedException { 30 | final TestSessionHelper helper = new TestSessionHelper(new DefaultContextFactory()); 31 | server = helper.createBlockingSession(new FixSessionId("FIX.4.4", "SERVER_COMP_ID", "CLIENT_COMP_ID"), FixConnectionMode.ACCEPTOR); 32 | client = helper.createBlockingSession(new FixSessionId("FIX.4.4", "CLIENT_COMP_ID", "SERVER_COMP_ID"), FixConnectionMode.INITIATOR); 33 | 34 | //Consume up the logon messages 35 | while(!client.getNextMessage().getTypeOfMessage().equals(MsgTypes.Logon)); 36 | while(!server.getNextMessage().getTypeOfMessage().equals(MsgTypes.Logon)); 37 | } 38 | 39 | public void cleanup() throws InterruptedException { 40 | client.shutdown(); 41 | server.shutdown(); 42 | } 43 | 44 | public void testServerDoesNotTimeOut() { 45 | expect: 46 | final AtomicReference fixMessageHolder = new AtomicReference<>(); 47 | 48 | final Thread thread = new Thread(new Runnable() { 49 | @Override 50 | public void run() { 51 | fixMessageHolder.set(server.getNextMessage()); 52 | } 53 | }); 54 | Thread.sleep(3000); 55 | assert fixMessageHolder.get() == null; 56 | thread.interrupt(); 57 | } 58 | 59 | public void testClientDoesNotTimeOut() throws InterruptedException { 60 | expect: 61 | final AtomicReference fixMessageHolder = new AtomicReference<>(); 62 | 63 | final Thread thread = new Thread(new Runnable() { 64 | @Override 65 | public void run() { 66 | fixMessageHolder.set(client.getNextMessage()); 67 | } 68 | }); 69 | Thread.sleep(3000); 70 | assert fixMessageHolder.get() == null; 71 | thread.interrupt(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /fix4j-assert-acceptance/src/test/resources/foo.properties: -------------------------------------------------------------------------------- 1 | fix4j.default.fix.msg.wait.timeout.ms=33333 2 | fix4j.quickfix.reconnect.interval=33 3 | -------------------------------------------------------------------------------- /fix4j-assert-all/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | description = '' 3 | dependencies { 4 | compile project(':fix4j-assert-core') 5 | compile project(':fix4j-assert-fixspec-50sp2') 6 | compile project(':fix4j-assert-quickfix') 7 | testCompile(group: 'junit', name: 'junit', version:'4.12') { 8 | exclude(module: 'hamcrest-core') 9 | } 10 | testCompile group: 'org.hamcrest', name: 'hamcrest-core', version:'1.3' 11 | testCompile group: 'org.hamcrest', name: 'hamcrest-library', version:'1.3' 12 | testCompile(group: 'org.mockito', name: 'mockito-core', version:'2.0.31-beta') { 13 | exclude(module: 'hamcrest-core') 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /fix4j-assert-all/src/main/java/org/fix4j/test/DefaultContextFactory.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test; 2 | 3 | import org.fix4j.spec.fix50sp2.FixSpec; 4 | import org.fix4j.test.fixspec.FixSpecification; 5 | import org.fix4j.test.integration.FixEngineSessionFactory; 6 | import org.fix4j.test.integration.quickfix.QuickFixTestSessionFactory; 7 | import org.fix4j.test.properties.ApplicationProperties; 8 | import org.fix4j.test.session.AbstractContextFactory; 9 | 10 | import java.util.Map; 11 | import java.util.Properties; 12 | 13 | /** 14 | * User: ben 15 | * Date: 9/12/14 16 | * Time: 4:50 PM 17 | */ 18 | public class DefaultContextFactory extends AbstractContextFactory { 19 | 20 | public DefaultContextFactory() { 21 | super(FixSpec.INSTANCE); 22 | } 23 | 24 | @Override 25 | protected FixEngineSessionFactory createFixEngineSessionFactory(final FixSpecification fixSpecification) { 26 | return new QuickFixTestSessionFactory(fixSpecification); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /fix4j-assert-codegen/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | description = '' 3 | dependencies { 4 | compile group: 'org.codehaus.groovy', name: 'groovy-all', version:'2.3.8' 5 | } 6 | -------------------------------------------------------------------------------- /fix4j-assert-codegen/src/main/groovy/org/fix4j/spec/codegen/Asserts.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.spec.codegen; 2 | 3 | /** 4 | * User: ben 5 | * Date: 25/08/2014 6 | * Time: 4:54 PM 7 | */ 8 | 9 | public class Asserts { 10 | public static void assertTrue(final boolean condition){ 11 | if(!condition) throw new IllegalArgumentException("Condition is not true."); 12 | } 13 | 14 | public static void assertFalse(final boolean condition){ 15 | if(condition) throw new IllegalArgumentException("Condition is not false."); 16 | } 17 | 18 | public static void assertNull(final Object shouldBeNull){ 19 | if( shouldBeNull != null) throw new IllegalArgumentException("Object is not null."); 20 | } 21 | 22 | public static void assertNotNull(final Object shouldNotBeNull){ 23 | if( shouldNotBeNull == null) throw new IllegalArgumentException("Object is null."); 24 | } 25 | 26 | public static void assertTrue(final String message, final boolean condition){ 27 | if(!condition) throw new IllegalArgumentException(message); 28 | } 29 | 30 | public static void assertFalse(final String message, final boolean condition){ 31 | if(condition) throw new IllegalArgumentException(message); 32 | } 33 | 34 | public static void assertNull(final String message, final Object shouldBeNull){ 35 | if( shouldBeNull != null) throw new IllegalArgumentException(message); 36 | } 37 | 38 | public static void assertNotNull(final String message, final Object shouldNotBeNull){ 39 | if( shouldNotBeNull == null) throw new IllegalArgumentException(message); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /fix4j-assert-codegen/src/main/groovy/org/fix4j/spec/codegen/CompositeContentHelper.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.spec.codegen 2 | /** 3 | * User: ben 4 | * Date: 9/09/2014 5 | * Time: 5:41 AM 6 | */ 7 | public class CompositeContentHelper { 8 | 9 | public static final String INDENT = " " 10 | 11 | private CompositeContentHelper() {} 12 | 13 | public static void buildGroupChildrenForClass(final children, final StringBuilder sb, final String indent) { 14 | if(children == null) return; 15 | final Iterator it = children.iterator(); 16 | final String newIndent = indent + INDENT; 17 | 18 | while(it.hasNext()){ 19 | final def child = it.next(); 20 | if (child.type == "field") { 21 | sb.append("${newIndent}FieldTypes.${child.name}.required(${(child.required == 'Y'? 'true': 'false')})"); 22 | 23 | } else if (child.type == "group") { 24 | sb.append("${newIndent}new BaseGroupType(\n"); 25 | sb.append("${newIndent}${INDENT}FieldTypes.${child.name}.required(${(child.required == 'Y' ? 'true': 'false')}),\n"); 26 | buildGroupChildrenForClass(child.children.values(), sb, newIndent); 27 | sb.append("${newIndent})"); 28 | 29 | } else { 30 | throw new IllegalArgumentException("child of unknown type:" + child); 31 | } 32 | 33 | if(it.hasNext()){ 34 | sb.append(","); 35 | } 36 | sb.append("\n"); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /fix4j-assert-codegen/src/main/groovy/org/fix4j/spec/codegen/FieldClassEnumCreator.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.spec.codegen 2 | /** 3 | * User: ben 4 | * Date: 5/09/2014 5 | * Time: 5:46 AM 6 | */ 7 | public class FieldClassEnumCreator { 8 | protected static void writeFieldClassEnumJavaFile(final String packageName, final Collection fieldClasses) { 9 | final String fieldClassEnumContent = createFieldClassEnum(packageName, fieldClasses); 10 | def fieldClassEnumFile = new File("FieldClass.java") 11 | fieldClassEnumFile.write(fieldClassEnumContent) 12 | println "Written FieldClass.java to:" + fieldClassEnumFile.absolutePath; 13 | } 14 | 15 | private static String createFieldClassEnum(final String packageName, final Collection fieldClasses){ 16 | final StringBuilder sb = new StringBuilder(); 17 | sb.append("package $packageName;\n" + 18 | "\n" + 19 | "\n" + 20 | "public enum FieldClass {\n"); 21 | 22 | def it = fieldClasses.iterator(); 23 | while(it.hasNext()){ 24 | def fieldClass = it.next(); 25 | sb.append(" ${fieldClass}"); 26 | if(it.hasNext()) sb.append(",\n"); 27 | else sb.append(";\n") 28 | } 29 | 30 | sb.append("}"); 31 | return sb.toString(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /fix4j-assert-codegen/src/main/groovy/org/fix4j/spec/codegen/FieldTypesEnumCreator.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.spec.codegen 2 | 3 | import groovy.text.GStringTemplateEngine 4 | 5 | /** 6 | * User: ben 7 | * Date: 26/08/2014 8 | * Time: 5:59 AM 9 | */ 10 | public class FieldTypesEnumCreator { 11 | 12 | protected static writeFieldTypesEnumFile(final String packageName, final Collection fields) { 13 | def binding = [packageName: packageName, fields: fields]; 14 | final InputStream inputStream = Util.getFileOnClasspath("/templates/FieldTypes.java"); 15 | def engine = new GStringTemplateEngine() 16 | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); 17 | def template = engine.createTemplate(reader).make(binding) 18 | 19 | final String fieldTypeEnumContent = template.toString(); 20 | def fieldClassEnumFile = new File("FieldTypes.java") 21 | fieldClassEnumFile.write(fieldTypeEnumContent) 22 | println "Written FieldTypes.java to:" + fieldClassEnumFile.absolutePath; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /fix4j-assert-codegen/src/main/groovy/org/fix4j/spec/codegen/FixSpecificationClassCreator.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.spec.codegen 2 | 3 | import groovy.text.GStringTemplateEngine 4 | 5 | /** 6 | * User: ben 7 | * Date: 26/08/2014 8 | * Time: 5:59 AM 9 | */ 10 | public class FixSpecificationClassCreator { 11 | 12 | protected static writeFixSpecificationFile(final String packageName) { 13 | def binding = [packageName: packageName]; 14 | final InputStream inputStream = Util.getFileOnClasspath("/templates/FixSpec.java"); 15 | def engine = new GStringTemplateEngine() 16 | final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); 17 | def template = engine.createTemplate(reader).make(binding) 18 | 19 | final String fileContent = template.toString(); 20 | def file = new File("FixSpec.java") 21 | file.write(fileContent) 22 | println "Written FixSpec.java to:" + file.absolutePath; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /fix4j-assert-codegen/src/main/groovy/org/fix4j/spec/codegen/MsgTypeCreator.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.spec.codegen 2 | /** 3 | * User: ben 4 | * Date: 26/08/2014 5 | * Time: 5:59 AM 6 | */ 7 | public class MsgTypeCreator { 8 | 9 | public static void writeMsgTypesJavaFiles(final String packageName, final LinkedHashMap messages) { 10 | def it = messages.values().iterator(); 11 | while(it.hasNext()){ 12 | def message = it.next(); 13 | final File parentDir = new File("msgtype"); 14 | if(!parentDir.exists()) parentDir.mkdir(); 15 | final File file = new File("msgtype/" + message.name + ".java"); 16 | file.write(createMsgTypeClassContent(packageName, message)); 17 | } 18 | } 19 | 20 | private static String createMsgTypeClassContent(final String packageName, final def message) { 21 | final StringBuilder sb = new StringBuilder(); 22 | sb.append("package ${packageName}.msgtype;\n" + 23 | "\n" + 24 | "import org.fix4j.test.fixspec.BaseGroupType;\n" + 25 | "import org.fix4j.test.fixspec.BaseMsgType;\n" + 26 | "import ${packageName}.FieldTypes;\n" + 27 | "\n" + 28 | "public class ${message.name} extends BaseMsgType{\n" + 29 | " public static final ${message.name} INSTANCE = new ${message.name}();\n\n" + 30 | " private ${message.name}() {\n" + 31 | " super(\n" + 32 | " \"${message.name}\",\n" + 33 | " \"${message.msgType}\",\n" + 34 | " \"${message.msgcat}\",\n"); 35 | 36 | CompositeContentHelper.buildGroupChildrenForClass(message.children.values(), sb, " "); 37 | sb.append(" );\n" + 38 | " }\n" + 39 | "}\n"); 40 | def str = sb.toString() 41 | return str 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /fix4j-assert-codegen/src/main/groovy/org/fix4j/spec/codegen/MsgTypesEnumCreator.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.spec.codegen 2 | 3 | import groovy.text.GStringTemplateEngine 4 | 5 | 6 | /** 7 | * User: ben 8 | * Date: 26/08/2014 9 | * Time: 5:59 AM 10 | */ 11 | public class MsgTypesEnumCreator { 12 | 13 | protected static writeMsgTypesEnumFile(final String packageName, final Collection messages) { 14 | def binding = [packageName: packageName, messages: messages]; 15 | final InputStream inputStream = Util.getFileOnClasspath("/templates/MsgTypes.java"); 16 | def engine = new GStringTemplateEngine() 17 | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); 18 | def template = engine.createTemplate(reader).make(binding) 19 | 20 | final String fieldTypeEnumContent = template.toString(); 21 | def fieldClassEnumFile = new File("MsgTypes.java") 22 | fieldClassEnumFile.write(fieldTypeEnumContent) 23 | println "Written MsgTypes.java to:" + fieldClassEnumFile.absolutePath; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /fix4j-assert-codegen/src/main/groovy/org/fix4j/spec/codegen/StandardHeaderCreator.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.spec.codegen 2 | /** 3 | * User: ben 4 | * Date: 26/08/2014 5 | * Time: 5:59 AM 6 | */ 7 | public class StandardHeaderCreator { 8 | 9 | protected static writeStandardHeaderJavaFile(final String packageName, final Collection headerFields) { 10 | def file = new File("StandardHeader.java") 11 | file.write(createStandardHeaderContent(packageName, headerFields)); 12 | println "Written StandardHeader.java to:" + file.absolutePath; 13 | } 14 | 15 | private static String createStandardHeaderContent(final String packageName, final def fields) { 16 | final StringBuilder sb = new StringBuilder(); 17 | sb.append("package ${packageName};\n" + 18 | "\n" + 19 | "import org.fix4j.test.fixspec.BaseFieldAndGroupTypes;\n" + 20 | "import org.fix4j.test.fixspec.BaseGroupType;\n" + 21 | "\n" + 22 | "public class StandardHeader extends BaseFieldAndGroupTypes {\n" + 23 | " public StandardHeader(){\n" + 24 | " super(\n"); 25 | CompositeContentHelper.buildGroupChildrenForClass(fields, sb, " "); 26 | sb.append(" );\n"); 27 | sb.append(" }\n" + 28 | "}"); 29 | def str = sb.toString(); 30 | return str 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /fix4j-assert-codegen/src/main/groovy/org/fix4j/spec/codegen/StandardTrailerCreator.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.spec.codegen 2 | /** 3 | * User: ben 4 | * Date: 26/08/2014 5 | * Time: 5:59 AM 6 | */ 7 | public class StandardTrailerCreator { 8 | 9 | protected static writeStandardTrailerJavaFile(final String packageName, final Collection trailerFields) { 10 | def file = new File("StandardTrailer.java") 11 | file.write(createStandardHeaderContent(packageName, trailerFields)); 12 | println "Written StandardTrailer.java to:" + file.absolutePath; 13 | } 14 | 15 | private static String createStandardHeaderContent(final String packageName, final def fields) { 16 | final StringBuilder sb = new StringBuilder(); 17 | sb.append("package ${packageName};\n" + 18 | "\n" + 19 | "import org.fix4j.test.fixspec.BaseFieldAndGroupTypes;\n" + 20 | "import org.fix4j.test.fixspec.BaseGroupType;\n" + 21 | "\n" + 22 | "public class StandardTrailer extends BaseFieldAndGroupTypes {\n" + 23 | " public StandardTrailer(){\n" + 24 | " super(\n"); 25 | CompositeContentHelper.buildGroupChildrenForClass(fields, sb, " "); 26 | sb.append(" );\n"); 27 | sb.append(" }\n" + 28 | "}"); 29 | def str = sb.toString(); 30 | return str 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /fix4j-assert-codegen/src/main/groovy/org/fix4j/spec/codegen/Util.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.spec.codegen 2 | 3 | /** 4 | * User: ben 5 | * Date: 5/09/2014 6 | * Time: 5:39 AM 7 | */ 8 | class Util { 9 | private Util() {} 10 | 11 | public static InputStream getFileOnClasspath(String fileLocationOnClasspath) { 12 | return SpecParser.class.getResourceAsStream(fileLocationOnClasspath); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /fix4j-assert-codegen/src/main/resources/templates/FieldTypes.java: -------------------------------------------------------------------------------- 1 | package $packageName; 2 | 3 | import ${packageName}.fieldtype.*; 4 | import org.fix4j.test.fixspec.FieldClass; 5 | import org.fix4j.test.fixspec.Tag; 6 | import org.fix4j.test.fixspec.FieldType; 7 | import java.util.Collections; 8 | import java.util.LinkedHashMap; 9 | import java.util.Map; 10 | 11 | public class FieldTypes{ 12 | private static final Map fieldTypesByTagInt = new LinkedHashMap<>(); 13 | private static final Map fieldTypesByName = new LinkedHashMap<>(); 14 | <% 15 | 16 | def it = fields.iterator(); 17 | while(it.hasNext()){ 18 | def field = it.next(); 19 | %> public static final ${field.name} ${field.name} = register(${packageName}.fieldtype.${field.name}.INSTANCE); 20 | <%}%> 21 | 22 | private static T register(final T fieldType) { 23 | fieldTypesByTagInt.put(fieldType.getTag().getValue(), fieldType); 24 | fieldTypesByName.put(fieldType.getName(), fieldType); 25 | return fieldType; 26 | } 27 | 28 | //Private, as this sucker should not be instantiated 29 | private FieldTypes(){} 30 | 31 | public static FieldType getFieldTypeByTag(final Tag tag) { 32 | return fieldTypesByTagInt.get(tag.getValue()); 33 | } 34 | 35 | public static FieldType getFieldTypeByName(final String name) { 36 | return fieldTypesByName.get(name); 37 | } 38 | 39 | public static FieldType getFieldTypeByTag(final int tag) { 40 | return fieldTypesByTagInt.get(tag); 41 | } 42 | 43 | public static FieldType forCustomTag(final int customTag){ 44 | return FieldType.Factory.forCustomTag(customTag); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /fix4j-assert-codegen/src/main/resources/templates/MsgTypes.java: -------------------------------------------------------------------------------- 1 | package ${packageName}; 2 | 3 | import ${packageName}.msgtype.*; 4 | import org.fix4j.test.fixspec.GroupKey; 5 | import org.fix4j.test.fixspec.GroupType; 6 | import org.fix4j.test.fixspec.MsgType; 7 | import org.fix4j.test.fixspec.Tag; 8 | import java.util.LinkedHashMap; 9 | import java.util.Map; 10 | 11 | public class MsgTypes { 12 | private static final Map msgTypesByTagStr = new LinkedHashMap<>(); 13 | private static final Map msgTypesByName = new LinkedHashMap<>(); 14 | private static final Map groupTypesByKey = new LinkedHashMap<>(); 15 | <% 16 | def it = messages.iterator(); 17 | while(it.hasNext()){ 18 | def message = it.next();%> 19 | public static final ${message.name} ${message.name} = register(${packageName}.msgtype.${message.name}.INSTANCE);<% 20 | } 21 | %> 22 | 23 | private static T register(final T msgType) { 24 | msgTypesByTagStr.put(msgType.getTag().getValue(), msgType); 25 | msgTypesByName.put(msgType.getName(), msgType); 26 | for(final GroupType groupType: msgType.getAllGroupTypesRecursively()){ 27 | groupTypesByKey.put(groupType.getGroupKey(msgType), groupType); 28 | } 29 | return msgType; 30 | } 31 | 32 | //Private, as this sucker should not be instantiated 33 | private MsgTypes(){} 34 | 35 | public static MsgType getMsgTypeByTag(final Tag tag) { 36 | return msgTypesByTagStr.get(tag.getValue()); 37 | } 38 | 39 | public static GroupType getGroupTypeByKey(final GroupKey groupKey) { 40 | return groupTypesByKey.get(groupKey); 41 | } 42 | 43 | public static MsgType getMsgTypeByName(final String msgTypeName) { 44 | return msgTypesByName.get(msgTypeName); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /fix4j-assert-core/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | description = '' 3 | dependencies { 4 | testCompile project(':fix4j-assert-testcommon') 5 | } 6 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixmodel/BaseGroup.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixmodel; 2 | 3 | import org.fix4j.test.fixspec.GroupType; 4 | import org.fix4j.test.fixspec.Tag; 5 | import org.fix4j.test.util.StringUtils; 6 | 7 | import java.util.ArrayList; 8 | import java.util.LinkedHashMap; 9 | import java.util.LinkedList; 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | /** 14 | * User: ben 15 | * Date: 25/09/2014 16 | * Time: 5:16 PM 17 | */ 18 | public class BaseGroup implements Group { 19 | private final GroupType groupType; 20 | private final Field noOfField; 21 | private final List repeats; 22 | 23 | public BaseGroup(final GroupType groupType, final Field noOfField, final List repeats) { 24 | this.groupType = groupType; 25 | this.noOfField = noOfField; 26 | this.repeats = repeats; 27 | } 28 | 29 | public Tag getTag() { 30 | return noOfField.getTag(); 31 | } 32 | 33 | @Override 34 | public GroupType getType() { 35 | return groupType; 36 | } 37 | 38 | @Override 39 | public Field getNoOfField() { 40 | return noOfField; 41 | } 42 | 43 | @Override 44 | public List getRepeats() { 45 | return repeats; 46 | } 47 | 48 | @Override 49 | public List getAllFieldsRecursively() { 50 | final List fields = new ArrayList<>(); 51 | fields.add(noOfField); 52 | for (final FieldsAndGroups repeat : repeats) { 53 | fields.addAll(repeat.getAllFieldsRecursively()); 54 | } 55 | return fields; 56 | } 57 | 58 | @Override 59 | public Map getFieldReferenceMap() { 60 | final Map map = new LinkedHashMap<>(); 61 | int i=0; 62 | map.putAll(noOfField.getFieldReferenceMap()); 63 | for (final FieldsAndGroups repeat : repeats) { 64 | map.putAll(StringUtils.prefixAllKeysWith(noOfField.getType().getName() + "[" + i + "].", repeat.getFieldReferenceMap())); 65 | map.putAll(StringUtils.prefixAllKeysWith(noOfField.getType().getTag().getValue() + "[" + i + "].", repeat.getFieldReferenceMap())); 66 | i++; 67 | } 68 | return map; 69 | } 70 | 71 | @Override 72 | public String toPrettyString() { 73 | final StringBuilder sb = new StringBuilder(); 74 | sb.append(noOfField.toPrettyString()); 75 | int i=1; 76 | for (final FieldsAndGroups repeat : repeats) { 77 | sb.append(StringUtils.indentAllLinesWithFirstLinesIndentEndingIn("" + i++ + ".", repeat.toPrettyString())); 78 | } 79 | return sb.toString(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixmodel/FieldSource.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixmodel; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | /** 7 | * User: ben 8 | * Date: 16/10/2014 9 | * Time: 7:48 PM 10 | */ 11 | public interface FieldSource { 12 | List getAllFieldsRecursively(); 13 | Map getFieldReferenceMap(); 14 | } 15 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixmodel/FieldsAndGroups.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixmodel; 2 | 3 | import org.fix4j.test.fixspec.FieldType; 4 | import org.fix4j.test.fixspec.GroupType; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * User: ben 10 | * Date: 16/10/2014 11 | * Time: 9:21 PM 12 | */ 13 | public interface FieldsAndGroups extends FieldSource, PrettyPrintable{ 14 | List getFields(); 15 | List getGroups(); 16 | Field getField(FieldType fieldType); 17 | Group getGroup(GroupType groupType); 18 | Field getField(int tag); 19 | FieldsAndGroups withField(final Field field); 20 | } 21 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixmodel/FieldsAndGroupsBuilder.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixmodel; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * User: ben 8 | * Date: 17/10/2014 9 | * Time: 7:55 PM 10 | */ 11 | public class FieldsAndGroupsBuilder { 12 | private final List groups = new ArrayList<>(); 13 | private final List fields = new ArrayList<>(); 14 | 15 | public FieldsAndGroupsBuilder withField(final Field field){ 16 | fields.add(field); 17 | return this; 18 | } 19 | 20 | public FieldsAndGroupsBuilder withGroup(final Group group){ 21 | groups.add(group); 22 | return this; 23 | } 24 | 25 | public FieldsAndGroups build(){ 26 | return new BaseFieldsAndGroups(fields, groups); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixmodel/FixMessage.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixmodel; 2 | 3 | 4 | import org.fix4j.test.fixspec.FieldType; 5 | import org.fix4j.test.fixspec.MsgType; 6 | import org.fix4j.test.fixspec.Tag; 7 | import org.fix4j.test.session.FixSessionId; 8 | 9 | import java.util.List; 10 | 11 | public interface FixMessage extends FieldSource, PrettyPrintable { 12 | boolean isOfType(MsgType msgType); 13 | MsgType getTypeOfMessage(); 14 | FieldsAndGroups getHeader(); 15 | FieldsAndGroups getTrailer(); 16 | FieldsAndGroups getBody(); 17 | String toDelimitedMessageWithDescriptors(); 18 | String toDelimitedMessage(); 19 | FixSessionId getSessionId(); 20 | Field getField(FieldType fieldType); 21 | Field getField(int tag); 22 | List getFields(FieldType fieldType); 23 | List getFields(int tag); 24 | Field getField(String reference); 25 | } 26 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixmodel/FixMessageUnflattener.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixmodel; 2 | 3 | import org.fix4j.test.fixspec.FieldType; 4 | import org.fix4j.test.util.ArrayListMultimap; 5 | import org.fix4j.test.util.Multimap; 6 | 7 | import java.util.Collection; 8 | 9 | /** 10 | * User: ben 11 | * Date: 23/09/2014 12 | * Time: 5:49 AM 13 | */ 14 | public class FixMessageUnflattener { 15 | private FixMessageUnflattener() {} 16 | 17 | public static Multimap unflatten(final Collection fields){ 18 | final Multimap map = new ArrayListMultimap(); 19 | for(final Field field: fields){ 20 | map.put(field.getFieldType(), field.getValue()); 21 | } 22 | return map; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixmodel/Group.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixmodel; 2 | 3 | import org.fix4j.test.fixspec.GroupType; 4 | import org.fix4j.test.fixspec.Tag; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * User: ben 10 | * Date: 26/09/2014 11 | * Time: 5:33 AM 12 | */ 13 | public interface Group extends FieldSource, PrettyPrintable { 14 | GroupType getType(); 15 | Field getNoOfField(); 16 | List getRepeats(); 17 | Tag getTag(); 18 | } 19 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixmodel/GroupBuilder.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixmodel; 2 | 3 | import org.fix4j.test.fixspec.GroupType; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * User: ben 10 | * Date: 17/10/2014 11 | * Time: 7:54 PM 12 | */ 13 | public class GroupBuilder { 14 | private GroupType groupType; 15 | private Field noOfField; 16 | private List repeats = new ArrayList<>(); 17 | 18 | public GroupBuilder withGroupType(final GroupType groupType) { 19 | this.groupType = groupType; 20 | return this; 21 | } 22 | 23 | public GroupBuilder withNoOfField(final Field noOfField){ 24 | this.noOfField = noOfField; 25 | return this; 26 | } 27 | 28 | public GroupBuilder withRepeat(final FieldsAndGroups fieldsAndGroups){ 29 | this.repeats.add(fieldsAndGroups); 30 | return this; 31 | } 32 | 33 | public Group build(){ 34 | return new BaseGroup(groupType, noOfField, repeats); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixmodel/Handler.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixmodel; 2 | 3 | import org.fix4j.test.fixspec.MsgType; 4 | 5 | /** 6 | * User: ben 7 | * Date: 18/11/14 8 | * Time: 6:15 AM 9 | */ 10 | public interface Handler{ 11 | } 12 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixmodel/PrettyPrintable.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixmodel; 2 | 3 | /** 4 | * User: ben 5 | * Date: 26/10/2014 6 | * Time: 10:36 AM 7 | */ 8 | public interface PrettyPrintable { 9 | String toPrettyString(); 10 | } 11 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixmodel/PrettyStripper.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixmodel; 2 | 3 | import org.fix4j.test.properties.ApplicationProperties; 4 | import org.fix4j.test.properties.PropertyKeysAndDefaultValues; 5 | import org.fix4j.test.util.Consts; 6 | 7 | /** 8 | * User: ben 9 | * Date: 31/10/2014 10 | * Time: 7:49 PM 11 | */ 12 | public class PrettyStripper { 13 | 14 | public static String stripPrettiness(final String prettyMessage) { 15 | final String fixDelim = ApplicationProperties.Singleton.instance().getAsString(PropertyKeysAndDefaultValues.FIX_FIELD_DELIM); 16 | 17 | String str = prettyMessage.replaceAll("(?s)" + BaseFixMessage.BANNER_STR + ".*" + BaseFixMessage.BANNER_STR, ""); 18 | str = str.replaceAll("(?m)^\\s*" + BaseFixMessage.PRETTY_HEADER_TITLE + "\\s*$", ""); 19 | str = str.replaceAll("(?m)^\\s*" + BaseFixMessage.PRETTY_BODY_TITLE + "\\s*$", ""); 20 | str = str.replaceAll("(?m)^\\s*" + BaseFixMessage.PRETTY_TRAILER_TITLE + "\\s*$", ""); 21 | 22 | //Strip space from start of string 23 | str = str.replaceAll("(?m)^\\s+", ""); 24 | 25 | //Strip space from start of field after delimiter 26 | str = str.replaceAll("(?m)" + fixDelim + "\\s+", Consts.ASCII_1); 27 | 28 | //Strip space from end of string (not including carriage returns) 29 | str = str.replaceAll("(?m)[\\t ]+$", ""); 30 | 31 | //Strip space from end of field up to next delimiter 32 | str = str.replaceAll("(?m)[\\t ]+" + fixDelim, Consts.ASCII_1); 33 | 34 | //Strip group repeat prefixes (lines starting with digits then a dot 35 | str = str.replaceAll("(?m)^\\d+\\.\\s*", ""); 36 | 37 | //Strip group repeat prefixes (fields starting with digits then a dot 38 | str = str.replaceAll("(?m)" + fixDelim + "\\d+\\.\\s*", Consts.ASCII_1); 39 | 40 | //Replace any remaining fix delims 41 | str = str.replaceAll("(?m)" + fixDelim, Consts.ASCII_1); 42 | 43 | //Strip line feeds 44 | str = str.replaceAll("\\r", ""); 45 | 46 | //Strip lines containing just whitespace 47 | str = str.replaceAll("(?m)^\\s+$\\n", ""); 48 | 49 | //String empty lines 50 | str = str.replaceAll("\\n\\1+", "\\n"); 51 | 52 | //Replace all carriage returns with a delimiter 53 | str = str.replaceAll("\\n", Consts.ASCII_1); 54 | 55 | //Strip off delimiter at end of string if there is one 56 | str = str.replaceAll("(?m)" + Consts.ASCII_1 + "$", ""); 57 | 58 | return str; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixmodel/RegexMatchingField.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixmodel; 2 | 3 | import org.fix4j.test.fixspec.FieldType; 4 | import org.fix4j.test.fixspec.Tag; 5 | import org.fix4j.test.util.Consts; 6 | 7 | import java.util.Collections; 8 | import java.util.LinkedHashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.regex.Pattern; 12 | 13 | /** 14 | * User: ben 15 | * Date: 2/09/2014 16 | * Time: 4:51 PM 17 | */ 18 | public class RegexMatchingField extends Field { 19 | private Pattern cachedPattern; 20 | 21 | public RegexMatchingField(final FieldType fieldType, final String regex) { 22 | super(fieldType, regex); 23 | if(!containsRegexForwardSlashes(regex)){ 24 | throw new IllegalArgumentException("regex must begin and end with forward slashes. e.g. /.*/"); 25 | } 26 | } 27 | 28 | public static String unescapeRegexForwardSlashes(final String value){ 29 | if(!containsEscapedRegexForwardSlashes(value)) return value; 30 | else return value.replaceAll("\\\\/", "/"); 31 | } 32 | 33 | public static boolean containsRegexForwardSlashes(final String value){ 34 | return value != null && value.startsWith("/") && value.endsWith("/"); 35 | } 36 | 37 | public static boolean containsEscapedRegexForwardSlashes(final String value){ 38 | return value != null && value.startsWith("\\/") && value.endsWith("\\/"); 39 | } 40 | 41 | public static String removeRegexForwardSlashes(final String value){ 42 | if(!containsRegexForwardSlashes(value)){ 43 | throw new IllegalArgumentException("Value is not a regex! Regex must start and end with a foward slash '/'. e.g. /.*/ Actual value:" + value); 44 | } 45 | return value.substring(1,value.length() - 1); 46 | } 47 | 48 | @Override 49 | public boolean matchesValueOf(final Field actual) { 50 | //If both values are null or zero length 51 | if(this.getValue() == null && actual.getValue() == null){ 52 | return true; 53 | 54 | //If only one of the values is null or zero length 55 | } else if(this.getValue() == null || actual.getValue() == null) { 56 | return false; 57 | 58 | } else { 59 | if(cachedPattern == null){ 60 | final String regexStr = removeRegexForwardSlashes(getValue()); 61 | cachedPattern = Pattern.compile(regexStr); 62 | } 63 | return cachedPattern.matcher(actual.getValue()).matches(); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixspec/BaseTag.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec; 2 | 3 | /** 4 | * User: ben 5 | * Date: 12/09/2014 6 | * Time: 5:18 AM 7 | */ 8 | public class BaseTag implements Tag { 9 | private final T value; 10 | 11 | public static BaseTag create(int value){ 12 | return new BaseTag<>(value); 13 | } 14 | 15 | public static BaseTag create(String value){ 16 | return new BaseTag<>(value); 17 | } 18 | 19 | public BaseTag(final T value) { 20 | this.value = value; 21 | } 22 | 23 | @Override 24 | public T getValue() { 25 | return value; 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return value.toString(); 31 | } 32 | 33 | @Override 34 | public boolean equals(final Object o) { 35 | if (this == o) return true; 36 | if (!(o instanceof Tag)) return false; 37 | final Tag baseTag = (Tag) o; 38 | if (!value.equals(baseTag.getValue())) return false; 39 | return true; 40 | } 41 | 42 | @Override 43 | public int hashCode() { 44 | return value.hashCode(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixspec/FieldAndGroupTypes.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec; 2 | 3 | import org.fix4j.test.fixmodel.PrettyPrintable; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * User: ben 9 | * Date: 16/10/2014 10 | * Time: 9:21 PM 11 | */ 12 | public interface FieldAndGroupTypes extends PrettyPrintable, FieldTypeSource{ 13 | List getFieldTypes(); 14 | List getGroupTypes(); 15 | GroupType getGroupType(int tag); 16 | boolean containsChild(FieldType type); 17 | boolean containsRecursively(FieldType type); 18 | List getFieldOrder(); 19 | } 20 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixspec/FieldClassLookup.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec; 2 | 3 | /** 4 | * User: ben 5 | * Date: 17/09/2014 6 | * Time: 5:42 AM 7 | */ 8 | public class FieldClassLookup { 9 | private FieldClassLookup() {} 10 | 11 | public static FieldClass lookup(final String fieldClass){ 12 | if(fieldClass.equals("DAY-OF-MONTH")) { 13 | return FieldClass.DAYOFMONTH; 14 | 15 | } else if(fieldClass.equals("NUMINGRP")) { 16 | return FieldClass.NUMINGROUP; 17 | 18 | } else { 19 | return FieldClass.valueOf(fieldClass); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixspec/FieldType.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec; 2 | 3 | 4 | import org.omg.CORBA.UNKNOWN; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * User: ben 10 | * Date: 25/08/2014 11 | * Time: 10:24 PM 12 | */ 13 | public interface FieldType extends MessageChildType { 14 | boolean isNumInGroup(); 15 | boolean isKnownValue(final String ordinal); 16 | String getDescriptionForKnownValue(final String ordinal); 17 | String getDescriptionForKnownValue(final String ordinal, final String defaultIfNotFound); 18 | FieldClass getFieldClass(); 19 | String formatValue(final String value); 20 | Tag getTag(); 21 | Map getEnumValues(); 22 | MemberFieldType required(boolean required); 23 | 24 | public static class Factory{ 25 | private Factory() {} 26 | 27 | public static FieldType forCustomTag(final int tag){ 28 | return new BaseFieldType("CUSTOM", tag); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixspec/FieldTypeSource.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec; 2 | 3 | import java.util.Map; 4 | import java.util.Set; 5 | 6 | /** 7 | * User: ben 8 | * Date: 31/10/2014 9 | * Time: 8:54 PM 10 | */ 11 | public interface FieldTypeSource { 12 | Set getAllFieldTypesRecursively(); 13 | Map getAllFieldTypesByTagRecursively(); 14 | Set getAllGroupTypesRecursively(); 15 | Map getAllGroupTypesByTagRecursively(); 16 | } 17 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixspec/FieldTypeValue.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec; 2 | 3 | /** 4 | * User: ben 5 | * Date: 11/11/2014 6 | * Time: 4:38 PM 7 | */ 8 | public class FieldTypeValue { 9 | private final String ordinal; 10 | 11 | public FieldTypeValue(final String ordinal) { 12 | this.ordinal = ordinal; 13 | } 14 | 15 | public String getOrdinal() { 16 | return ordinal; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixspec/FieldTypeValueEnum.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec; 2 | 3 | /** 4 | * User: ben 5 | * Date: 11/11/2014 6 | * Time: 4:38 PM 7 | */ 8 | public interface FieldTypeValueEnum { 9 | public String getOrdinal(); 10 | } 11 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixspec/FixSpecification.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | 5 | /** 6 | * User: ben 7 | * Date: 28/08/2014 8 | * Time: 5:21 AM 9 | */ 10 | public interface FixSpecification { 11 | Integer MSG_TYPE_TAG_NUMBER = 35; 12 | FieldType getFieldTypeByTag(Tag tag); 13 | FieldType getFieldTypeByTag(int tag); 14 | FieldAndGroupTypes getStandardHeaderType(); 15 | FieldAndGroupTypes getStandardTrailerType(); 16 | int getMsgTypeTagNumber(); 17 | Tag getMsgTypeTag(); 18 | MsgType getMsgTypeByTag(Tag tag); 19 | MsgType getMsgTypeByTag(String tagValue); 20 | GroupType getGroupTypeByKey(GroupKey groupKey); 21 | FieldType getFieldTypeByName(String fieldName); 22 | FieldType getMsgTypeFieldType(); 23 | FixMessage parse(final String expression); 24 | FixMessage parseRawFix(final String expression); 25 | MsgType getMsgTypeByName(String msgTypeName); 26 | } 27 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixspec/GroupKey.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec; 2 | 3 | /** 4 | * User: ben 5 | * Date: 13/10/2014 6 | * Time: 7:38 PM 7 | */ 8 | public class GroupKey { 9 | private final MsgType msgType; 10 | private final FieldType noOfFieldType; 11 | 12 | public GroupKey(final MsgType msgType, final FieldType noOfFieldType) { 13 | this.msgType = msgType; 14 | this.noOfFieldType = noOfFieldType; 15 | } 16 | 17 | public MsgType getMsgType() { 18 | return msgType; 19 | } 20 | 21 | public FieldType getNoOfFieldType() { 22 | return noOfFieldType; 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return "GroupKey{" + 28 | "msgType=" + msgType + 29 | ", noOfFieldType=" + noOfFieldType + 30 | '}'; 31 | } 32 | 33 | @Override 34 | public boolean equals(final Object o) { 35 | if (this == o) return true; 36 | if (!(o instanceof GroupKey)) return false; 37 | final GroupKey groupKey = (GroupKey) o; 38 | if (!msgType.equals(groupKey.msgType)) return false; 39 | if (!noOfFieldType.equals(groupKey.noOfFieldType)) return false; 40 | return true; 41 | } 42 | 43 | @Override 44 | public int hashCode() { 45 | int result = msgType.hashCode(); 46 | result = 31 * result + noOfFieldType.hashCode(); 47 | return result; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixspec/GroupType.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * User: ben 7 | * Date: 26/08/2014 8 | * Time: 5:34 AM 9 | */ 10 | 11 | 12 | public interface GroupType extends FieldAndGroupTypes, MessageChildType{ 13 | public FieldType getNoOfFieldType(); 14 | public GroupKey getGroupKey(final MsgType msgType); 15 | public MessageChildType getFirstChildTypeOfRepeatingGroup(); 16 | List getFieldOrder(); 17 | Tag getTag(); 18 | boolean isRequired(); 19 | } 20 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixspec/MemberFieldType.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * User: ben 7 | * Date: 12/11/2014 8 | * Time: 5:12 PM 9 | */ 10 | public class MemberFieldType implements FieldType { 11 | private final boolean required; 12 | private final FieldType fieldType; 13 | 14 | public MemberFieldType(final FieldType fieldType, final boolean required) { 15 | this.required = required; 16 | this.fieldType = fieldType; 17 | } 18 | 19 | public boolean isRequired() { 20 | return required; 21 | } 22 | 23 | public Tag getTag() { 24 | return fieldType.getTag(); 25 | } 26 | 27 | public String toPrettyString() { 28 | return fieldType.toPrettyString(); 29 | } 30 | 31 | public boolean isNumInGroup() { 32 | return fieldType.isNumInGroup(); 33 | } 34 | 35 | public boolean isKnownValue(final String ordinal) { 36 | return fieldType.isKnownValue(ordinal); 37 | } 38 | 39 | public String getDescriptionForKnownValue(final String ordinal, final String defaultIfNotKnown) { 40 | return fieldType.getDescriptionForKnownValue(ordinal, defaultIfNotKnown); 41 | } 42 | 43 | public String getDescriptionForKnownValue(final String ordinal) { 44 | return fieldType.getDescriptionForKnownValue(ordinal); 45 | } 46 | 47 | public FieldClass getFieldClass() { 48 | return fieldType.getFieldClass(); 49 | } 50 | 51 | public String formatValue(final String value) { 52 | return fieldType.formatValue(value); 53 | } 54 | 55 | public Map getEnumValues() { 56 | return fieldType.getEnumValues(); 57 | } 58 | 59 | @Override 60 | public MemberFieldType required(final boolean required) { 61 | throw new UnsupportedOperationException("Already a MemberFieldType! A MemberFieldType is effectively a wrapper of a FieldType with an added 'required' field. (The same goes for GroupType to GroupType). Therefore you should not be wrapping a wrapper! Please only call this on a descendent of FieldType which is NOT already a MemberFieldType."); 62 | } 63 | 64 | public String getName() { 65 | return fieldType.getName(); 66 | } 67 | 68 | public String toString() { 69 | return fieldType.toString(); 70 | } 71 | 72 | public boolean equals(final Object o) { 73 | return fieldType.equals(o); 74 | } 75 | 76 | public int hashCode() { 77 | return fieldType.hashCode(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixspec/MessageChildType.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec; 2 | 3 | /** 4 | * User: ben 5 | * Date: 13/10/2014 6 | * Time: 5:07 PM 7 | */ 8 | public interface MessageChildType extends Type { 9 | } 10 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixspec/MsgType.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec; 2 | 3 | 4 | import org.fix4j.test.fixmodel.FixMessage; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * User: ben 10 | * Date: 25/08/2014 11 | * Time: 10:24 PM 12 | */ 13 | public interface MsgType extends FieldAndGroupTypes, Type { 14 | String getName(); 15 | List getFieldTypes(); 16 | List getGroupTypes(); 17 | Tag getTag(); 18 | boolean containsChild(FieldType type); 19 | FixMessage generateExampleMessage(FixSpecification fixSpecification); 20 | } 21 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixspec/Tag.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec; 2 | 3 | /** 4 | * User: ben 5 | * Date: 12/09/2014 6 | * Time: 5:17 AM 7 | */ 8 | public interface Tag { 9 | T getValue(); 10 | } 11 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/fixspec/Type.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec; 2 | 3 | /** 4 | * User: ben 5 | * Date: 27/08/2014 6 | * Time: 8:22 PM 7 | */ 8 | public interface Type { 9 | String getName(); 10 | Tag getTag(); 11 | String toPrettyString(); 12 | } 13 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/integration/FixEngineSession.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.integration; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.plumbing.Consumer; 5 | import org.fix4j.test.session.FixSession; 6 | 7 | /** 8 | * User: ben 9 | * Date: 25/09/2014 10 | * Time: 5:41 AM 11 | */ 12 | public interface FixEngineSession extends FixSession, Consumer { 13 | void shutdown(); 14 | void shutdown(boolean force); 15 | void startup(); 16 | 17 | /** 18 | * Overriding for documentation purposes only. 19 | * 20 | * This accept method will be called for OUTBOUND fix messages. i.e. message which are coming 21 | * from the test client, and need to go out to the "network". 22 | * 23 | * @param fixMessage 24 | */ 25 | @Override 26 | void accept(FixMessage fixMessage); 27 | } 28 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/integration/FixEngineSessionFactory.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.integration; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.plumbing.Consumer; 5 | import org.fix4j.test.session.FixConnectionMode; 6 | import org.fix4j.test.session.FixSessionId; 7 | 8 | /** 9 | * User: ben 10 | * Date: 20/08/2014 11 | * Time: 5:42 PM 12 | */ 13 | public interface FixEngineSessionFactory { 14 | /** 15 | * To clarify how messages should be routed to and from the test client. 16 | * 17 | * When creating a FixEngineSession: 18 | * 19 | * INBOUND (from network): 20 | * -- Arrival: of the fix message to the FixEngineSession is a matter for the implementing code. 21 | * -- Departure: of the fix message must be to the consumer which is passed in via the constructor below "toTestClient". e.g. toTestClient.accept(FixMessage) 22 | * 23 | * OUTBOUND (to network): 24 | * -- Arrival: of the fix message coming from the test client is via FixEngineSession#accept(FixMessage) method. 25 | * -- Departure: of the fix message is a matter for the implementing code. 26 | * 27 | * @param sessionId The sessionId for the fix session to create. 28 | * @param fixConnectionMode Whether this fix session should be the INITIATOR of the fix connection, or the ACCEPTOR. 29 | * @param toTestClient This is where INBOUND fix messages should be sent. e.g. toTestClient.accept(inboundFixMessage) 30 | */ 31 | FixEngineSession createSession(final FixSessionId sessionId, final FixConnectionMode fixConnectionMode, final Consumer toTestClient); 32 | } 33 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/integration/FixSessionIdConverter.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.integration; 2 | 3 | import org.fix4j.test.session.FixSessionId; 4 | 5 | /** 6 | * User: ben 7 | * Date: 14/08/2014 8 | * Time: 2:53 PM 9 | */ 10 | public interface FixSessionIdConverter { 11 | FixSessionId toFixSessionId(S sessionId); 12 | S fromFixSessionId(FixSessionId fixSessionId); 13 | } 14 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/integration/MessageConverter.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.integration; 2 | 3 | import org.fix4j.test.plumbing.Consumer; 4 | 5 | /** 6 | * F = From 7 | * T = To 8 | * 9 | * User: ben 10 | * Date: 14/08/2014 11 | * Time: 2:53 PM 12 | */ 13 | public interface MessageConverter { 14 | Consumer convertAndSendMessagesTo(Consumer messageConsumer); 15 | T convert(F message); 16 | } 17 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/matching/FixFieldMatchResult.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.matching; 2 | 3 | import org.fix4j.test.fixspec.FieldType; 4 | import org.fix4j.test.util.Consts; 5 | import org.fix4j.test.util.Report; 6 | import org.fix4j.test.util.StringUtils; 7 | 8 | /** 9 | * User: ben 10 | * Date: 19/08/2014 11 | * Time: 5:30 PM 12 | */ 13 | public class FixFieldMatchResult implements Report { 14 | private final boolean matches; 15 | private final FieldType type; 16 | private final String actualValue; 17 | private final String expectedExpression; 18 | 19 | public FixFieldMatchResult(final boolean matches, final FieldType type, final String actualValue, final String expectedExpression) { 20 | this.matches = matches; 21 | this.type = type; 22 | this.actualValue = actualValue; 23 | this.expectedExpression = expectedExpression; 24 | } 25 | 26 | public boolean matches() { 27 | return matches; 28 | } 29 | 30 | @Override 31 | public String getReportAsString() { 32 | final String actual = type.formatValue(actualValue); 33 | final String expected = type.formatValue(expectedExpression); 34 | return (matches ? "OK " : "FAIL ") 35 | + StringUtils.niceIfNull(type + ": " + actual, "") 36 | + (matches ? " == " : " != ") 37 | + StringUtils.niceIfNull(expected, "") 38 | + Consts.EOL; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/matching/matchactivity/DiscardUntilFirstMatchThenRunSecondMatchProcessor.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.matching.matchactivity; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.matching.matchers.FixMessageMatcher; 5 | import org.fix4j.test.matching.matchers.MatchResult; 6 | import org.fix4j.test.session.Failure; 7 | import org.fix4j.test.session.TimeoutReport; 8 | import org.fix4j.test.util.Consts; 9 | import org.fix4j.test.util.Report; 10 | 11 | /** 12 | * User: ben 13 | * Date: 7/11/2014 14 | * Time: 5:11 AM 15 | */ 16 | public class DiscardUntilFirstMatchThenRunSecondMatchProcessor implements MatchActivityMessageProcessor { 17 | private final FixMessageMatcher firstMatch; 18 | private final FixMessageMatcher secondMatch; 19 | 20 | public DiscardUntilFirstMatchThenRunSecondMatchProcessor(final FixMessageMatcher firstMatch, final FixMessageMatcher secondMatch) { 21 | this.firstMatch = firstMatch; 22 | this.secondMatch = secondMatch; 23 | } 24 | 25 | @Override 26 | public MatchActivityDirectiveAndReport processMessage(final FixMessage fixMessage) { 27 | final MatchResult firstMatchResult = firstMatch.getMatchResult(fixMessage); 28 | if(firstMatchResult.matches()){ 29 | final MatchResult secondMatchResult = secondMatch.getMatchResult(fixMessage); 30 | if(!secondMatchResult.matches()){ 31 | final String failureText = 32 | "1. Found message that matches: " + firstMatch + Consts.EOL 33 | + "2. But message does not match: " + secondMatch + Consts.EOL; 34 | 35 | throw new Failure(fixMessage, (new MatchFailureTextFactory()).generateFailureMessage(fixMessage, secondMatchResult, failureText)); 36 | } 37 | return MatchActivityDirectiveAndReport.finish(secondMatchResult); 38 | } else { 39 | return MatchActivityDirectiveAndReport.discardAndContinue(); 40 | } 41 | } 42 | 43 | @Override 44 | public Report handleTimeout() { 45 | throw new Failure(new TimeoutReport(firstMatch)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/matching/matchactivity/DiscardUntilMatchProcessor.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.matching.matchactivity; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.matching.matchers.FixMessageMatcher; 5 | import org.fix4j.test.matching.matchers.MatchResult; 6 | import org.fix4j.test.session.Failure; 7 | import org.fix4j.test.session.TimeoutReport; 8 | import org.fix4j.test.util.Report; 9 | 10 | /** 11 | * User: ben 12 | * Date: 7/11/2014 13 | * Time: 5:11 AM 14 | */ 15 | public class DiscardUntilMatchProcessor implements MatchActivityMessageProcessor { 16 | private final FixMessageMatcher fixMessageMatcher; 17 | 18 | public DiscardUntilMatchProcessor(final FixMessageMatcher fixMessageMatcher) { 19 | this.fixMessageMatcher = fixMessageMatcher; 20 | } 21 | 22 | @Override 23 | public MatchActivityDirectiveAndReport processMessage(final FixMessage message) { 24 | final MatchResult result = fixMessageMatcher.getMatchResult(message); 25 | if(result.matches()){ 26 | return MatchActivityDirectiveAndReport.finish(result); 27 | } else { 28 | return MatchActivityDirectiveAndReport.discardAndContinue(); 29 | } 30 | } 31 | 32 | @Override 33 | public Report handleTimeout() { 34 | throw new Failure(new TimeoutReport(fixMessageMatcher)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/matching/matchactivity/DiscardedMessageReport.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.matching.matchactivity; 2 | 3 | import org.fix4j.test.session.RecentMessages; 4 | import org.fix4j.test.util.Consts; 5 | import org.fix4j.test.util.Report; 6 | 7 | /** 8 | * User: ben 9 | * Date: 5/11/2014 10 | * Time: 5:33 PM 11 | */ 12 | public class DiscardedMessageReport implements Report { 13 | private final RecentMessages discardedMessages; 14 | 15 | public DiscardedMessageReport(final RecentMessages discardedMessages) { 16 | this.discardedMessages = discardedMessages; 17 | } 18 | 19 | @Override 20 | public String getReportAsString() { 21 | if(!discardedMessages.isEmpty()) { 22 | return "DISCARDED MESSAGES (oldest to newest):" + Consts.EOL + discardedMessages.toPrettyString(); 23 | } else { 24 | return ""; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/matching/matchactivity/MatchActivityDirectiveAndReport.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.matching.matchactivity; 2 | 3 | import org.fix4j.test.util.Report; 4 | import org.fix4j.test.util.Reportable; 5 | 6 | /** 7 | * User: ben 8 | * Date: 7/11/2014 9 | * Time: 5:19 AM 10 | */ 11 | public class MatchActivityDirectiveAndReport implements Reportable { 12 | private final ResultDirective resultDirective; 13 | private final Report report; 14 | 15 | public static MatchActivityDirectiveAndReport discardAndContinue(){ return new MatchActivityDirectiveAndReport(ResultDirective.DISCARD_AND_CONTINUE); } 16 | public static MatchActivityDirectiveAndReport finish(final Report report){ return new MatchActivityDirectiveAndReport(ResultDirective.FINISH, report);} 17 | 18 | private MatchActivityDirectiveAndReport(final ResultDirective resultDirective, final Report report) { 19 | this.resultDirective = resultDirective; 20 | this.report = report; 21 | } 22 | 23 | private MatchActivityDirectiveAndReport(final ResultDirective resultDirective) { 24 | this.resultDirective = resultDirective; 25 | this.report = null; 26 | } 27 | 28 | public boolean discardThisMessage(){ 29 | return resultDirective.discardThisMessage(); 30 | } 31 | 32 | public boolean finished(){ 33 | return resultDirective.finished(); 34 | } 35 | 36 | @Override 37 | public Report getReport() { 38 | return report; 39 | } 40 | 41 | enum ResultDirective { 42 | DISCARD_AND_CONTINUE(false, true), 43 | FINISH(true, false); 44 | 45 | private final boolean finish; 46 | private final boolean logAsDiscarded; 47 | 48 | ResultDirective(final boolean finish, final boolean logAsDiscarded) { 49 | this.finish = finish; 50 | this.logAsDiscarded = logAsDiscarded; 51 | } 52 | 53 | public boolean finished() { 54 | return finish; 55 | } 56 | 57 | public boolean discardThisMessage() { 58 | return logAsDiscarded; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/matching/matchactivity/MatchActivityMessageProcessor.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.matching.matchactivity; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.util.Report; 5 | 6 | /** 7 | * User: ben 8 | * Date: 5/11/2014 9 | * Time: 5:10 PM 10 | */ 11 | public interface MatchActivityMessageProcessor { 12 | MatchActivityDirectiveAndReport processMessage(FixMessage message); 13 | Report handleTimeout(); 14 | } 15 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/matching/matchactivity/MatchActivityResult.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.matching.matchactivity; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.util.CompositeReport; 5 | import org.fix4j.test.util.Report; 6 | import org.fix4j.test.util.Reportable; 7 | 8 | import java.util.Arrays; 9 | 10 | /** 11 | * User: ben 12 | * Date: 10/11/2014 13 | * Time: 5:58 AM 14 | */ 15 | public class MatchActivityResult implements Reportable { 16 | private final Report report; 17 | private final FixMessage message; 18 | private final boolean success; 19 | 20 | public MatchActivityResult(final boolean success, final FixMessage message, final Report report) { 21 | this.success = success; 22 | this.report = report; 23 | this.message = message; 24 | } 25 | 26 | public MatchActivityResult(final boolean success, final FixMessage message, final Report ... reports) { 27 | this.success = success; 28 | this.report = new CompositeReport(Arrays.asList(reports)); 29 | this.message = message; 30 | } 31 | 32 | public FixMessage getMessage() { 33 | return message; 34 | } 35 | 36 | @Override 37 | public Report getReport() { 38 | return report; 39 | } 40 | 41 | public boolean isSuccess() { 42 | return success; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/matching/matchactivity/MatchFailureTextFactory.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.matching.matchactivity; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.matching.matchers.MatchResult; 5 | import org.fix4j.test.util.Consts; 6 | import org.fix4j.test.util.StringUtils; 7 | 8 | /** 9 | * User: ben 10 | * Date: 28/11/14 11 | * Time: 6:09 AM 12 | */ 13 | public class MatchFailureTextFactory { 14 | public String generateFailureMessage(final FixMessage message, final MatchResult matchResult, final String failureText) { 15 | return Consts.EOL 16 | + StringUtils.indentAllLines(1, failureText) 17 | + StringUtils.indentAllLines(1, "MATCH DETAILS::" + Consts.EOL) 18 | + StringUtils.indentAllLines(2, matchResult.getReportAsString()) 19 | + StringUtils.indentAllLines(1, "MESSAGE RECEIVED::" + Consts.EOL) 20 | + StringUtils.indentAllLines(2, message.toPrettyString()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/matching/matchactivity/MustMatchFirstMessage.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.matching.matchactivity; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.matching.matchers.FixMessageMatcher; 5 | import org.fix4j.test.matching.matchers.MatchResult; 6 | import org.fix4j.test.session.Failure; 7 | import org.fix4j.test.session.TimeoutReport; 8 | import org.fix4j.test.util.Report; 9 | 10 | /** 11 | * User: ben 12 | * Date: 7/11/2014 13 | * Time: 5:11 AM 14 | */ 15 | public class MustMatchFirstMessage implements MatchActivityMessageProcessor { 16 | private final FixMessageMatcher fixMessageMatcher; 17 | 18 | public MustMatchFirstMessage(final FixMessageMatcher fixMessageMatcher) { 19 | this.fixMessageMatcher = fixMessageMatcher; 20 | } 21 | 22 | @Override 23 | public MatchActivityDirectiveAndReport processMessage(final FixMessage fixMessage) { 24 | final MatchResult matchResult = fixMessageMatcher.getMatchResult(fixMessage); 25 | if(matchResult.matches()) { 26 | return MatchActivityDirectiveAndReport.finish(matchResult); 27 | } else { 28 | throw new Failure((new MatchFailureTextFactory()).generateFailureMessage(fixMessage, matchResult, "Message does not match:" + fixMessageMatcher)); 29 | } 30 | } 31 | 32 | @Override 33 | public Report handleTimeout() { 34 | throw new Failure(new TimeoutReport(fixMessageMatcher)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/matching/matchers/BaseMatchResult.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.matching.matchers; 2 | 3 | import org.fix4j.test.util.BaseReport; 4 | import org.fix4j.test.util.Report; 5 | 6 | /** 7 | * User: ben 8 | * Date: 20/11/14 9 | * Time: 9:24 AM 10 | */ 11 | public class BaseMatchResult implements MatchResult{ 12 | private final Report report; 13 | private final boolean matches; 14 | 15 | public BaseMatchResult(final boolean matches, final Report report) { 16 | this.report = report; 17 | this.matches = matches; 18 | } 19 | 20 | public BaseMatchResult(final boolean matches, final String report) { 21 | this.report = new BaseReport(report); 22 | this.matches = matches; 23 | } 24 | 25 | @Override 26 | public boolean matches(){ 27 | return matches; 28 | } 29 | 30 | @Override 31 | public String getReportAsString() { 32 | return report.getReportAsString(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/matching/matchers/FixMessageMatcher.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.matching.matchers; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | 5 | /** 6 | * User: ben 7 | * Date: 29/09/2014 8 | * Time: 5:46 AM 9 | */ 10 | public interface FixMessageMatcher { 11 | MatchResult getMatchResult(FixMessage message); 12 | } 13 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/matching/matchers/MatchEveryMessageMatcher.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.matching.matchers; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | 5 | 6 | /** 7 | * User: ben 8 | * Date: 20/11/14 9 | * Time: 1:22 AM 10 | */ 11 | public class MatchEveryMessageMatcher implements FixMessageMatcher { 12 | public static final BaseMatchResult MATCH_RESULT = new BaseMatchResult(true, "Any message is OK"); 13 | 14 | public MatchEveryMessageMatcher() {} 15 | 16 | @Override 17 | public MatchResult getMatchResult(final FixMessage message) { 18 | return MATCH_RESULT; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/matching/matchers/MatchNoMessagesMatcher.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.matching.matchers; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | 5 | 6 | /** 7 | * User: ben 8 | * Date: 20/11/14 9 | * Time: 1:22 AM 10 | */ 11 | public class MatchNoMessagesMatcher implements FixMessageMatcher { 12 | public static final BaseMatchResult MATCH_RESULT = new BaseMatchResult(false, "No messages accepted"); 13 | 14 | public MatchNoMessagesMatcher() {} 15 | 16 | @Override 17 | public MatchResult getMatchResult(final FixMessage message) { 18 | return MATCH_RESULT; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/matching/matchers/MatchResult.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.matching.matchers; 2 | 3 | import org.fix4j.test.util.Report; 4 | 5 | /** 6 | * User: ben 7 | * Date: 20/11/14 8 | * Time: 9:24 AM 9 | */ 10 | public interface MatchResult extends Report { 11 | public boolean matches(); 12 | } 13 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/matching/matchers/MsgTypeMatcher.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.matching.matchers; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.fixspec.MsgType; 5 | 6 | 7 | /** 8 | * User: ben 9 | * Date: 20/11/14 10 | * Time: 1:22 AM 11 | */ 12 | public class MsgTypeMatcher implements FixMessageMatcher { 13 | private final MsgType expectedMsgType; 14 | 15 | public MsgTypeMatcher(final MsgType expectedMsgType) { 16 | this.expectedMsgType = expectedMsgType; 17 | } 18 | 19 | @Override 20 | public MatchResult getMatchResult(final FixMessage message) { 21 | if(message.isOfType(expectedMsgType)){ 22 | return new BaseMatchResult(true, "Message is of type: " + expectedMsgType); 23 | } else { 24 | return new BaseMatchResult(false, "Message is NOT of type: " + expectedMsgType); 25 | } 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return "MsgTypeMatcher{" + 31 | "expectedMsgType=" + expectedMsgType + 32 | '}'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/matching/matchers/SimpleMatchResult.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.matching.matchers; 2 | 3 | import org.fix4j.test.util.Report; 4 | import org.fix4j.test.util.Reportable; 5 | 6 | /** 7 | * User: ben 8 | * Date: 20/11/14 9 | * Time: 9:24 AM 10 | */ 11 | public class SimpleMatchResult implements Reportable { 12 | private final boolean matches; 13 | private final Report report; 14 | 15 | public SimpleMatchResult(final boolean matches, final Report report) { 16 | this.matches = matches; 17 | this.report = report; 18 | } 19 | 20 | public boolean matches() { 21 | return matches; 22 | } 23 | 24 | public Report getReport() { 25 | return report; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/messageflags/MessageFlag.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.messageflags; 2 | 3 | import org.fix4j.test.fixmodel.Field; 4 | import org.fix4j.test.fixmodel.FixMessage; 5 | import org.fix4j.test.fixmodel.PrettyPrintable; 6 | import org.fix4j.test.util.Consts; 7 | import org.fix4j.test.util.StringUtils; 8 | 9 | import java.util.LinkedHashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | */ 14 | public class MessageFlag implements PrettyPrintable { 15 | private final FixMessage fixMessage; 16 | private final String alert; 17 | 18 | public MessageFlag(final FixMessage fixMessage, final String alert) { 19 | this.fixMessage = fixMessage; 20 | this.alert = alert; 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return toPrettyString(); 26 | } 27 | 28 | public FixMessage getFixMessage() { 29 | return fixMessage; 30 | } 31 | 32 | @Override 33 | public String toPrettyString() { 34 | if(StringUtils.containsAtLeastOneVariable(alert)){ 35 | final Map fieldMap = fixMessage.getFieldReferenceMap(); 36 | final Map fieldValueMap = new LinkedHashMap<>(fieldMap.size()); 37 | for (final String key : fieldMap.keySet()) { 38 | fieldValueMap.put(key, fieldMap.get(key).getFormattedValue()); 39 | } 40 | return StringUtils.substituteVariables(alert, fieldValueMap) + Consts.EOL; 41 | } else { 42 | return alert + Consts.EOL; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/messageflags/MessageFlagRule.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.messageflags; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | 5 | /** 6 | * This class implements rule which can be applied to a fixMessage to produce {@link org.fix4j.test.messageflags.MessageFlags} 7 | * 8 | * MessageFlags are useful to alert the test author to certain aspects of an outgoing or incoming fixMessage. 9 | * 10 | * For example, we may wish to alert the test author that they have specified fields in a repeating group in the wrong order. 11 | * 12 | * If MessageFlags are triggered, they can then be used to fail a test (and provide the test author/runner with detail as to what flag was triggered) 13 | * Or to simply display warnings in the test log. 14 | * 15 | * User: ben 16 | */ 17 | public interface MessageFlagRule { 18 | boolean isTriggered(FixMessage fixMessage); 19 | MessageFlags getMessageFlags(FixMessage fixMessage); 20 | } 21 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/messageflags/MessageFlagRules.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.messageflags; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.fixspec.FieldType; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Collection; 8 | import java.util.Collections; 9 | import java.util.List; 10 | 11 | /** 12 | * User: ben 13 | * Date: 1/10/2014 14 | * Time: 6:10 AM 15 | */ 16 | public class MessageFlagRules { 17 | public static final MessageFlagRules EMPTY = new MessageFlagRules(new ArrayList(0)); 18 | private final List messageFlagRules; 19 | 20 | public MessageFlagRules(final List messageFlagRules) { 21 | this.messageFlagRules = Collections.unmodifiableList(messageFlagRules); 22 | } 23 | 24 | public MessageFlags getFlagsForMessage(final FixMessage fixMessage){ 25 | final List messageFlags = new ArrayList<>(); 26 | for (final MessageFlagRule rule : messageFlagRules) { 27 | if(rule.isTriggered(fixMessage)){ 28 | messageFlags.addAll(rule.getMessageFlags(fixMessage).getFlags()); 29 | } 30 | } 31 | return new MessageFlags(fixMessage, messageFlags); 32 | } 33 | 34 | public static Collection fieldsShouldNotBeSet(final String messagePostfix, final FieldType ... fieldTypes) { 35 | final List messageFlagRules = new ArrayList<>(fieldTypes.length); 36 | for (final FieldType fieldType : fieldTypes) { 37 | messageFlagRules.add(SimpleMessageFlagRule.forAnyValueOfField(fieldType, fieldType.toString() + ": " + messagePostfix)); 38 | } 39 | return messageFlagRules; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/messageflags/MessageFlags.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.messageflags; 2 | 3 | 4 | import org.fix4j.test.fixmodel.FixMessage; 5 | import org.fix4j.test.fixmodel.PrettyPrintable; 6 | import org.fix4j.test.util.Consts; 7 | import org.fix4j.test.util.Report; 8 | 9 | import java.util.ArrayList; 10 | import java.util.Collections; 11 | import java.util.List; 12 | 13 | /** 14 | * User: ben 15 | * Date: 7/11/2014 16 | * Time: 5:58 PM 17 | */ 18 | public class MessageFlags implements PrettyPrintable, Report { 19 | public static final MessageFlags EMPTY = new MessageFlags(null, new ArrayList()); 20 | private final List flags; 21 | private final FixMessage fixMessage; 22 | 23 | public MessageFlags(final FixMessage fixMessage, final List flags) { 24 | this.fixMessage = fixMessage; 25 | this.flags = flags; 26 | } 27 | 28 | public boolean isEmpty(){ 29 | return flags.isEmpty(); 30 | } 31 | 32 | public FixMessage getFixMessage() { 33 | return fixMessage; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "MessageFlags{" + 39 | "flags=" + flags + 40 | '}'; 41 | } 42 | 43 | @Override 44 | public String toPrettyString(){ 45 | if(fixMessage == null) return ""; 46 | final StringBuilder sb = new StringBuilder(); 47 | if(flags.size() > 0) { 48 | int i=1; 49 | sb.append(fixMessage).append(Consts.EOL); 50 | for (final MessageFlag triggeredFlag : flags) { 51 | sb.append(Consts.INDENT).append(i++).append(". ").append(triggeredFlag.toPrettyString()); 52 | } 53 | } 54 | return sb.toString(); 55 | } 56 | 57 | public void addAll(final MessageFlags msgFlags){ 58 | this.flags.addAll(msgFlags.flags); 59 | } 60 | 61 | public static MessageFlags singleFlag(final FixMessage fixMessage, final String message) { 62 | final List flags = Collections.singletonList(new MessageFlag(fixMessage, message)); 63 | return new MessageFlags(fixMessage, flags); 64 | } 65 | 66 | public List getFlags() { 67 | return flags; 68 | } 69 | 70 | @Override 71 | public String getReportAsString() { 72 | return toPrettyString(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/messageflags/MissingRequiredFieldMessageFlagRule.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.messageflags; 2 | 3 | import org.fix4j.test.fixmodel.FieldsAndGroups; 4 | import org.fix4j.test.fixmodel.FixMessage; 5 | import org.fix4j.test.fixmodel.Group; 6 | import org.fix4j.test.fixspec.FieldAndGroupTypes; 7 | import org.fix4j.test.fixspec.GroupType; 8 | import org.fix4j.test.fixspec.MemberFieldType; 9 | import org.fix4j.test.matching.matchers.MatchEveryMessageMatcher; 10 | import org.fix4j.test.matching.matchers.FixMessageMatcher; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | * User: ben 17 | * Date: 1/10/2014 18 | * Time: 6:04 AM 19 | */ 20 | public class MissingRequiredFieldMessageFlagRule implements MessageFlagRule { 21 | private final FixMessageMatcher matcher; 22 | 23 | public MissingRequiredFieldMessageFlagRule() { 24 | matcher = new MatchEveryMessageMatcher(); 25 | } 26 | 27 | @Override 28 | public boolean isTriggered(final FixMessage fixMessage){ 29 | return matcher.getMatchResult(fixMessage).matches(); 30 | } 31 | 32 | @Override 33 | public MessageFlags getMessageFlags(final FixMessage fixMessage){ 34 | final List messageFlagStrings = new ArrayList<>(); 35 | messageFlagStrings.addAll(getMissingRequiredFields(fixMessage.getTypeOfMessage(), fixMessage.getBody())); 36 | 37 | final List messageFlags = new ArrayList<>(); 38 | for (final String messageFlagStr : messageFlagStrings) { 39 | messageFlags.add(new MessageFlag(fixMessage, messageFlagStr)); 40 | } 41 | return new MessageFlags(fixMessage, messageFlags); 42 | } 43 | 44 | private List getMissingRequiredFields(final FieldAndGroupTypes fieldAndGroupTypes, final FieldsAndGroups fieldAndGroupValues){ 45 | final List messageFlags = new ArrayList<>(); 46 | for (final MemberFieldType fieldType : fieldAndGroupTypes.getFieldTypes()) { 47 | if(fieldType.isRequired()){ 48 | if(fieldAndGroupValues.getField(fieldType) == null){ 49 | messageFlags.add("Required field not found: " + fieldType.toPrettyString()); 50 | } 51 | } 52 | } 53 | for (final GroupType groupType : fieldAndGroupTypes.getGroupTypes()) { 54 | if(groupType.isRequired()){ 55 | final Group group = fieldAndGroupValues.getGroup(groupType); 56 | if(group == null){ 57 | messageFlags.add("Required group not found: " + groupType.getNoOfFieldType().toPrettyString()); 58 | } else { 59 | for (final FieldsAndGroups fieldsAndGroups : group.getRepeats()) { 60 | messageFlags.addAll(getMissingRequiredFields(groupType, fieldsAndGroups)); 61 | } 62 | } 63 | } 64 | } 65 | return messageFlags; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/messageflags/SessionLevelRejectMessageFlagRule.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.messageflags; 2 | 3 | import org.fix4j.test.expression.FlexibleMessageExpressionParser; 4 | import org.fix4j.test.fixmodel.Field; 5 | import org.fix4j.test.fixmodel.FixMessage; 6 | import org.fix4j.test.fixspec.FieldType; 7 | import org.fix4j.test.fixspec.FixSpecification; 8 | import org.fix4j.test.matching.matchers.FixMessageMatcher; 9 | import org.fix4j.test.util.Consts; 10 | 11 | /** 12 | * User: ben 13 | * Date: 1/10/2014 14 | * Time: 6:04 AM 15 | */ 16 | public class SessionLevelRejectMessageFlagRule implements MessageFlagRule { 17 | private final FixMessageMatcher matcher; 18 | private final FixSpecification fixSpecification; 19 | 20 | public SessionLevelRejectMessageFlagRule(final FixSpecification fixSpecification) { 21 | this.fixSpecification = fixSpecification; 22 | final FlexibleMessageExpressionParser messageExpressionParser = new FlexibleMessageExpressionParser(fixSpecification); 23 | matcher = messageExpressionParser.parse("35=3");// "Session level reject 24 | } 25 | 26 | @Override 27 | public boolean isTriggered(final FixMessage fixMessage){ 28 | return matcher.getMatchResult(fixMessage).matches(); 29 | } 30 | 31 | @Override 32 | public MessageFlags getMessageFlags(final FixMessage fixMessage){ 33 | final Field sessionRejectReason = fixMessage.getBody().getField(fixSpecification.getFieldTypeByName("SessionRejectReason")); 34 | final Field text = fixMessage.getBody().getField(fixSpecification.getFieldTypeByName("Text")); 35 | final Field refTagId = fixMessage.getBody().getField(fixSpecification.getFieldTypeByName("RefTagID")); 36 | String refTagName; 37 | if(refTagId != null){ 38 | try { 39 | int refTagIdInt = Integer.valueOf(refTagId.getValue()); 40 | final FieldType fieldType = fixSpecification.getFieldTypeByTag(refTagIdInt); 41 | if(fieldType != null) { 42 | refTagName = fieldType.getName(); 43 | } else { 44 | refTagName = null; 45 | } 46 | } catch(NumberFormatException e){ 47 | refTagName = null; 48 | } 49 | } else { 50 | refTagName = null; 51 | } 52 | 53 | String message = "Session level reject::"; 54 | message += (sessionRejectReason != null ? sessionRejectReason.toStringWithDescriptors() + "::": ""); 55 | message += (text != null ? text.toStringWithDescriptors(): ""); 56 | if(refTagId != null){ 57 | message += refTagId.toStringWithDescriptors(); 58 | if(refTagName != null){ 59 | message += "[" + refTagName + "]"; 60 | } 61 | message += "::"; 62 | } 63 | message += Consts.EOL; 64 | message += fixMessage.toPrettyString(); 65 | 66 | return MessageFlags.singleFlag(fixMessage, message); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/messageflags/SimpleMessageFlagRule.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.messageflags; 2 | 3 | import org.fix4j.test.expression.MessageExpression; 4 | import org.fix4j.test.expression.FlexibleMessageExpressionParser; 5 | import org.fix4j.test.fixmodel.FixMessage; 6 | import org.fix4j.test.fixspec.FieldType; 7 | import org.fix4j.test.fixspec.FixSpecification; 8 | import org.fix4j.test.fixspec.MsgType; 9 | import org.fix4j.test.matching.matchers.FixMessageMatcher; 10 | import org.fix4j.test.matching.matchers.MsgTypeMatcher; 11 | 12 | /** 13 | * User: ben 14 | * Date: 1/10/2014 15 | * Time: 6:04 AM 16 | */ 17 | public class SimpleMessageFlagRule implements MessageFlagRule { 18 | private final FixMessageMatcher matcher; 19 | private final String alert; 20 | 21 | public SimpleMessageFlagRule(final FixMessageMatcher matcher, final String alert) { 22 | this.matcher = matcher; 23 | this.alert = alert; 24 | } 25 | 26 | public SimpleMessageFlagRule(final MsgType msgType, final String alert) { 27 | this(new MsgTypeMatcher(msgType), alert); 28 | } 29 | 30 | public SimpleMessageFlagRule(final FixSpecification fixSpecification, final String expression, final String alert) { 31 | this(new FlexibleMessageExpressionParser(fixSpecification).parse(expression), alert); 32 | } 33 | 34 | @Override 35 | public boolean isTriggered(final FixMessage fixMessage){ 36 | return matcher.getMatchResult(fixMessage).matches(); 37 | } 38 | 39 | @Override 40 | public MessageFlags getMessageFlags(final FixMessage fixMessage){ 41 | return MessageFlags.singleFlag(fixMessage, alert); 42 | } 43 | 44 | public static MessageFlagRule forAnyValueOfField(final FieldType fieldType, final String message) { 45 | return new SimpleMessageFlagRule(MessageExpression.forAnyValueOfField(fieldType), message); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/plumbing/AbstractChainedConsumer.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.plumbing; 2 | 3 | /** 4 | * User: ben 5 | * Date: 21/11/14 6 | * Time: 4:49 PM 7 | */ 8 | public abstract class AbstractChainedConsumer implements Consumer, Processor{ 9 | private final Consumer destination; 10 | 11 | public AbstractChainedConsumer(final Consumer destination) { 12 | this.destination = destination; 13 | } 14 | 15 | @Override 16 | public void accept(M m) { 17 | m = process(m); 18 | if(m != null){ 19 | destination.accept(m); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/plumbing/AbstractChainedSupplier.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.plumbing; 2 | 3 | import org.fix4j.test.util.DateUtils; 4 | 5 | /** 6 | * User: ben 7 | * Date: 21/11/14 8 | * Time: 4:49 PM 9 | */ 10 | public abstract class AbstractChainedSupplier implements Supplier, Processor{ 11 | private final Supplier source; 12 | 13 | public AbstractChainedSupplier(final Supplier source) { 14 | this.source = source; 15 | } 16 | 17 | @Override 18 | public M get(final long timeoutInMillis) { 19 | final long startTime = DateUtils.now(); 20 | while(DateUtils.timeSince(startTime) < timeoutInMillis) { 21 | long timeRemaining = timeoutInMillis - DateUtils.timeSince(startTime); 22 | final M message = source.get(timeRemaining); 23 | if(message == null){ 24 | return null; 25 | } 26 | final M entity = process(message); 27 | if(entity != null){ 28 | return message; 29 | } 30 | } 31 | return null; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/plumbing/BlockingPipe.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.plumbing; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.util.concurrent.BlockingQueue; 7 | import java.util.concurrent.LinkedBlockingQueue; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | /** 11 | * User: ben 12 | * Date: 20/08/2014 13 | * Time: 4:48 PM 14 | */ 15 | public class BlockingPipe implements Consumer, Supplier { 16 | private final static Logger LOGGER = LoggerFactory.getLogger(BlockingPipe.class); 17 | private final BlockingQueue blockingQueue; 18 | private final String id; 19 | 20 | public BlockingPipe(final String id) { 21 | this.id = id; 22 | this.blockingQueue = new LinkedBlockingQueue(); 23 | } 24 | 25 | @Override 26 | public void accept(final M m) { 27 | try { 28 | LOGGER.info("Adding message to pipe [" + id + "]:" + m); 29 | blockingQueue.put(m); 30 | } catch (InterruptedException e) { 31 | throw new RuntimeException(e); 32 | } 33 | } 34 | 35 | @Override 36 | public M get(long timeoutInMillis) { 37 | try { 38 | LOGGER.info( "[" + id + "] Polling for (waiting for " + timeoutInMillis + "ms) message from pipe"); 39 | final M message = blockingQueue.poll(timeoutInMillis, TimeUnit.MILLISECONDS); 40 | if(message == null){ 41 | LOGGER.info("[" + id + "] Timed out wait for message from pipe"); 42 | } else { 43 | LOGGER.info("[" + id + "] Polled message from pipe: " + message); 44 | } 45 | return message; 46 | } catch (InterruptedException e) { 47 | throw new RuntimeException(e); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/plumbing/Consumer.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.plumbing; 2 | 3 | /** 4 | * User: ben 5 | * Date: 20/08/2014 6 | * Time: 4:47 PM 7 | */ 8 | public interface Consumer { 9 | void accept(M m); 10 | } 11 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/plumbing/ExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.plumbing; 2 | 3 | /** 4 | * User: ben 5 | * Date: 22/12/14 6 | * Time: 3:28 PM 7 | */ 8 | public interface ExceptionHandler { 9 | public Throwable handle(final Throwable t); 10 | } 11 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/plumbing/Filter.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.plumbing; 2 | 3 | /** 4 | * User: ben 5 | * Date: 29/09/2014 6 | * Time: 2:05 PM 7 | */ 8 | public interface Filter { 9 | boolean accept(T t); 10 | } 11 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/plumbing/Processor.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.plumbing; 2 | 3 | /** 4 | * User: ben 5 | * Date: 1/12/14 6 | * Time: 5:59 AM 7 | */ 8 | public interface Processor { 9 | /** 10 | * The process method accepts an entity to be processed, and should return the processed entity. 11 | * 12 | * If the processor wishes to halt further processing of the entity, then null should be returned. 13 | * 14 | * @param entity The entity that is to be processed. 15 | * @return The entity that should be used from now onwards. 16 | */ 17 | T process(T entity); 18 | } 19 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/plumbing/Provider.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.plumbing; 2 | 3 | /** 4 | * User: ben 5 | * Date: 20/08/2014 6 | * Time: 4:48 PM 7 | */ 8 | public interface Provider { 9 | M get(); 10 | } 11 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/plumbing/ShuntFromSupplierToConsumer.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.plumbing; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.util.concurrent.ExecutorService; 7 | import java.util.concurrent.Executors; 8 | 9 | /** 10 | * User: ben 11 | * Date: 20/08/2014 12 | * Time: 4:52 PM 13 | */ 14 | public class ShuntFromSupplierToConsumer implements Runnable { 15 | private final static Logger LOGGER = LoggerFactory.getLogger(BlockingPipe.class); 16 | private final Consumer consumer; 17 | private final Supplier supplier; 18 | private final String id; 19 | private final ExceptionHandler exceptionHandler; 20 | private ExecutorService executorService; 21 | 22 | public ShuntFromSupplierToConsumer(final String id, final Supplier supplier, final Consumer consumer) { 23 | this.id = id; 24 | this.consumer = consumer; 25 | this.supplier = supplier; 26 | this.exceptionHandler = null; 27 | } 28 | 29 | public ShuntFromSupplierToConsumer(final String id, final Supplier supplier, final Consumer consumer, final ExceptionHandler exceptionHandler) { 30 | this.id = id; 31 | this.consumer = consumer; 32 | this.supplier = supplier; 33 | this.exceptionHandler = exceptionHandler; 34 | } 35 | 36 | @Override 37 | public void run(){ 38 | try { 39 | while(true){ 40 | try { 41 | LOGGER.debug("[" + id + "] Waiting for next message from supplier"); 42 | final M m = supplier.get(Long.MAX_VALUE); 43 | LOGGER.debug("[" + id + "] Shunting message:" + m + " from:" + supplier + " to " + consumer); 44 | consumer.accept(m); 45 | } catch(Throwable e){ 46 | if(exceptionHandler != null) { 47 | final Throwable throwable = exceptionHandler.handle(e); 48 | if (throwable != null) { 49 | throw throwable; 50 | } 51 | } else { 52 | throw e; 53 | } 54 | } 55 | } 56 | } catch (Throwable throwable) { 57 | executorService.shutdown(); 58 | throw new RuntimeException(throwable); 59 | } 60 | } 61 | 62 | public void start() { 63 | this.executorService = Executors.newSingleThreadExecutor(); 64 | executorService.submit(this); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/plumbing/Supplier.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.plumbing; 2 | 3 | /** 4 | * Simple Supplier interface. 5 | */ 6 | public interface Supplier { 7 | /** 8 | * @param timeoutInMillis 9 | * @return null if timeout is reached before the next object becomes available. Non-null if 10 | * an object becomes available before timeout is reached. 11 | */ 12 | M get(long timeoutInMillis); 13 | } 14 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/processors/FixMessageProcessors.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.processors; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.plumbing.Processor; 5 | import org.fix4j.test.util.CompositeReport; 6 | import org.fix4j.test.util.Report; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | import java.util.List; 11 | 12 | /** 13 | * User: ben 14 | * Date: 1/12/14 15 | * Time: 4:46 PM 16 | */ 17 | public class FixMessageProcessors implements Processor, OnFailureReporter { 18 | private final List> processors; 19 | 20 | public FixMessageProcessors(final List> processors) { 21 | this.processors = processors; 22 | } 23 | 24 | @Override 25 | public FixMessage process(final FixMessage entity) { 26 | FixMessage returnMessage = entity; 27 | for (final Processor processor : processors) { 28 | returnMessage = processor.process(returnMessage); 29 | if(returnMessage == null){ 30 | return null; 31 | } 32 | } 33 | return returnMessage; 34 | } 35 | 36 | @Override 37 | public Report getReportOnFailure() { 38 | final List reports = new ArrayList<>(); 39 | for (final Processor processor : processors) { 40 | if(processor instanceof OnFailureReporter){ 41 | reports.add(((OnFailureReporter) processor).getReportOnFailure()); 42 | } 43 | } 44 | return new CompositeReport(reports); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/processors/InboundIgnoreProcessor.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.processors; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.matching.matchers.FixMessageMatcher; 5 | import org.fix4j.test.plumbing.Processor; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | /** 10 | * User: ben 11 | * Date: 21/11/14 12 | * Time: 4:49 PM 13 | */ 14 | public class InboundIgnoreProcessor implements Processor { 15 | private final static Logger LOGGER = LoggerFactory.getLogger(InboundIgnoreProcessor.class); 16 | private final FixMessageMatcher messagesToIgnore; 17 | 18 | public InboundIgnoreProcessor(final FixMessageMatcher messagesToIgnore) { 19 | this.messagesToIgnore = messagesToIgnore; 20 | } 21 | 22 | @Override 23 | public FixMessage process(final FixMessage message) { 24 | if(messagesToIgnore.getMatchResult(message).matches()){ 25 | LOGGER.info("Ignoring: " + message.toDelimitedMessageWithDescriptors()); 26 | return null; 27 | } 28 | return message; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/processors/InboundMessageFlagFailureProcessor.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.processors; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.messageflags.MessageFlagRules; 5 | import org.fix4j.test.messageflags.MessageFlags; 6 | import org.fix4j.test.plumbing.Processor; 7 | import org.fix4j.test.session.Failure; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | /** 12 | * User: ben 13 | * Date: 21/11/14 14 | * Time: 4:49 PM 15 | */ 16 | public class InboundMessageFlagFailureProcessor implements Processor{ 17 | private final static Logger LOGGER = LoggerFactory.getLogger(InboundMessageFlagFailureProcessor.class); 18 | private final MessageFlagRules inboundMessageFlagRules; 19 | private final boolean fastFailOnTriggerOfIncomingMessageFlag; 20 | 21 | public InboundMessageFlagFailureProcessor(final MessageFlagRules inboundMessageFlagRules, final boolean fastFailOnTriggerOfIncomingMessageFlag) { 22 | this.inboundMessageFlagRules = inboundMessageFlagRules; 23 | this.fastFailOnTriggerOfIncomingMessageFlag = fastFailOnTriggerOfIncomingMessageFlag; 24 | } 25 | 26 | @Override 27 | public FixMessage process(final FixMessage message) { 28 | final MessageFlags messageFlags = inboundMessageFlagRules.getFlagsForMessage(message); 29 | if (!messageFlags.isEmpty()) { 30 | if(fastFailOnTriggerOfIncomingMessageFlag) { 31 | throw new Failure(messageFlags, message); 32 | } else { 33 | LOGGER.warn(messageFlags.toPrettyString()); 34 | } 35 | } 36 | return message; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/processors/InboundProcessors.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.processors; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.plumbing.AbstractChainedSupplier; 5 | import org.fix4j.test.plumbing.Processor; 6 | import org.fix4j.test.plumbing.Supplier; 7 | import org.fix4j.test.util.Report; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * User: ben 13 | * Date: 22/11/14 14 | * Time: 5:00 AM 15 | */ 16 | public class InboundProcessors extends AbstractChainedSupplier implements OnFailureReporter { 17 | private final FixMessageProcessors processors; 18 | 19 | public InboundProcessors(final Supplier source, final List> processors) { 20 | super(source); 21 | this.processors = new FixMessageProcessors(processors); 22 | } 23 | 24 | @Override 25 | public FixMessage process(final FixMessage entity) { 26 | return processors.process(entity); 27 | } 28 | 29 | @Override 30 | public Report getReportOnFailure() { 31 | return processors.getReportOnFailure(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/processors/InboundRecentMessageProcessor.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.processors; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.messageflags.MessageFlagRules; 5 | import org.fix4j.test.plumbing.Processor; 6 | import org.fix4j.test.plumbing.Provider; 7 | import org.fix4j.test.session.RecentMessages; 8 | import org.fix4j.test.util.CompositeReport; 9 | import org.fix4j.test.util.Report; 10 | 11 | /** 12 | * User: ben 13 | * Date: 21/11/14 14 | * Time: 4:49 PM 15 | */ 16 | public class InboundRecentMessageProcessor implements Provider, Processor, OnFailureReporter { 17 | private final RecentMessages recentMessages; 18 | private final MessageFlagRules inboundMessageFlagWarningRules; 19 | 20 | public InboundRecentMessageProcessor(final MessageFlagRules inboundMessageFlagWarningRules) { 21 | this.recentMessages = new RecentMessages(10); 22 | this.inboundMessageFlagWarningRules = inboundMessageFlagWarningRules; 23 | } 24 | 25 | @Override 26 | public FixMessage process(final FixMessage message) { 27 | recentMessages.add(message); 28 | return message; 29 | } 30 | 31 | @Override 32 | public RecentMessages get() { 33 | return recentMessages; 34 | } 35 | 36 | @Override 37 | public Report getReportOnFailure() { 38 | final Report recentMessagesReport = recentMessages.getReportWithHeading("RECENT INBOUND MESSAGES"); 39 | final Report messageWarningReport = recentMessages.getReportForFlaggedMessages(inboundMessageFlagWarningRules); 40 | return new CompositeReport(recentMessagesReport, messageWarningReport); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/processors/OnFailureReporter.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.processors; 2 | 3 | import org.fix4j.test.util.Report; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * User: bens 10 | * Date: 1/12/14 11 | * Time: 5:39 PM 12 | */ 13 | public interface OnFailureReporter { 14 | public static class Util{ 15 | public static List fetchReportsFromReporters(final List reporters) { 16 | final ArrayList reports = new ArrayList<>(); 17 | for (final OnFailureReporter reporter : reporters) { 18 | reports.add(reporter.getReportOnFailure()); 19 | } 20 | return reports; 21 | } 22 | } 23 | Report getReportOnFailure(); 24 | } 25 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/processors/OnFailureReporters.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.processors; 2 | 3 | import org.fix4j.test.session.Failure; 4 | import org.fix4j.test.session.FixSessionId; 5 | import org.fix4j.test.util.Report; 6 | 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | /** 11 | * User: ben 12 | * Date: 2/12/14 13 | * Time: 5:42 AM 14 | */ 15 | public class OnFailureReporters { 16 | private final List reporters; 17 | 18 | public OnFailureReporters(final OnFailureReporter ... reporters) { 19 | this.reporters = Arrays.asList(reporters); 20 | } 21 | 22 | public Error enrichFailureWithAdditionalReports(final FixSessionId fixSessionId, final Failure failure) { 23 | final List reports = OnFailureReporter.Util.fetchReportsFromReporters(reporters); 24 | return failure.withPrefixedMessage(fixSessionId.toString() + ": ").withAdditionalReports(reports); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/processors/OutboundMessageFlagFailureProcessor.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.processors; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.plumbing.Processor; 5 | import org.fix4j.test.session.Failure; 6 | import org.fix4j.test.messageflags.MessageFlagRules; 7 | import org.fix4j.test.messageflags.MessageFlags; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | /** 12 | * User: ben 13 | * Date: 21/11/14 14 | * Time: 4:49 PM 15 | */ 16 | public class OutboundMessageFlagFailureProcessor implements Processor { 17 | private final MessageFlagRules outboundMessageFlagRules; 18 | private final static Logger LOGGER = LoggerFactory.getLogger(InboundMessageFlagFailureProcessor.class); 19 | private final boolean fastFailOnTriggerOfOutboundMessageFlag; 20 | 21 | public OutboundMessageFlagFailureProcessor(final MessageFlagRules outboundMessageFlagRules, final boolean fastFailOnTriggerOfOutboundMessageFlag) { 22 | this.outboundMessageFlagRules = outboundMessageFlagRules; 23 | this.fastFailOnTriggerOfOutboundMessageFlag = fastFailOnTriggerOfOutboundMessageFlag; 24 | } 25 | 26 | @Override 27 | public FixMessage process(final FixMessage message) { 28 | if(fastFailOnTriggerOfOutboundMessageFlag) { 29 | final MessageFlags messageFlags = outboundMessageFlagRules.getFlagsForMessage(message); 30 | if (!messageFlags.isEmpty()) { 31 | throw new Failure(messageFlags, message); 32 | } else { 33 | LOGGER.warn(messageFlags.toPrettyString()); 34 | } 35 | } 36 | return message; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/processors/OutboundProcessors.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.processors; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.plumbing.AbstractChainedConsumer; 5 | import org.fix4j.test.plumbing.Consumer; 6 | import org.fix4j.test.plumbing.Processor; 7 | import org.fix4j.test.util.Report; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * User: ben 13 | * Date: 22/11/14 14 | * Time: 5:00 AM 15 | */ 16 | public class OutboundProcessors extends AbstractChainedConsumer implements OnFailureReporter { 17 | private final FixMessageProcessors processors; 18 | 19 | public OutboundProcessors(final Consumer source, final List> processors) { 20 | super(source); 21 | this.processors = new FixMessageProcessors(processors); 22 | } 23 | 24 | @Override 25 | public FixMessage process(final FixMessage entity) { 26 | return processors.process(entity); 27 | } 28 | 29 | @Override 30 | public Report getReportOnFailure() { 31 | return processors.getReportOnFailure(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/processors/OutboundRecentMessageProcessor.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.processors; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.messageflags.MessageFlagRules; 5 | import org.fix4j.test.plumbing.Processor; 6 | import org.fix4j.test.plumbing.Provider; 7 | import org.fix4j.test.session.RecentMessages; 8 | import org.fix4j.test.util.CompositeReport; 9 | import org.fix4j.test.util.Report; 10 | 11 | /** 12 | * User: ben 13 | * Date: 21/11/14 14 | * Time: 4:49 PM 15 | */ 16 | public class OutboundRecentMessageProcessor implements OnFailureReporter, Provider, Processor { 17 | private final RecentMessages recentMessages; 18 | private final MessageFlagRules outboundMessageFlagWarningRules; 19 | 20 | public OutboundRecentMessageProcessor(final MessageFlagRules outboundMessageFlagWarningRules) { 21 | this.recentMessages = new RecentMessages(10); 22 | this.outboundMessageFlagWarningRules = outboundMessageFlagWarningRules; 23 | } 24 | 25 | @Override 26 | public FixMessage process(final FixMessage message) { 27 | recentMessages.add(message); 28 | return message; 29 | } 30 | 31 | @Override 32 | public Report getReportOnFailure() { 33 | final Report recentMessagesReport = recentMessages.getReportWithHeading("RECENT OUTBOUND MESSAGES"); 34 | final Report messageWarnings = recentMessages.getReportForFlaggedMessages(outboundMessageFlagWarningRules); 35 | return new CompositeReport(recentMessagesReport, messageWarnings); 36 | } 37 | 38 | @Override 39 | public RecentMessages get() { 40 | return recentMessages; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/properties/ApplicationProperties.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.properties; 2 | 3 | import org.fix4j.test.util.Keyable; 4 | 5 | /** 6 | * User: ben 7 | * Date: 4/12/14 8 | * Time: 10:32 AM 9 | */ 10 | public interface ApplicationProperties { 11 | public static class Singleton{ 12 | private static ApplicationProperties instance; 13 | 14 | public static ApplicationProperties instance(){ 15 | if(instance == null) { 16 | instance = new ApplicationPropertiesFactory().createApplicationProperties(); 17 | } 18 | return instance; 19 | } 20 | 21 | public static void setInstance(final ApplicationProperties applicationProperties){ 22 | instance = applicationProperties; 23 | } 24 | } 25 | 26 | public String getAsString(final String key); 27 | public String getAsString(final String key, final String defaultValue); 28 | 29 | public String getAsString(final Keyable key); 30 | public String getAsString(final Keyable key, final String defaultValue); 31 | 32 | public Boolean getAsBoolean(final String key); 33 | public Boolean getAsBoolean(final String key, final Boolean defaultValue); 34 | 35 | public Boolean getAsBoolean(final Keyable key); 36 | public Boolean getAsBoolean(final Keyable key, final Boolean defaultValue); 37 | 38 | public Integer getAsInt(final String key); 39 | public Integer getAsInt(final String key, final Integer defaultValue); 40 | 41 | public Integer getAsInt(final Keyable key); 42 | public Integer getAsInt(final Keyable key, final Integer defaultValue); 43 | 44 | public Double getAsDouble(final String key); 45 | public Double getAsDouble(final String key, final Double defaultValue); 46 | 47 | public Double getAsDouble(final Keyable key); 48 | public Double getAsDouble(final Keyable key, final Double defaultValue); 49 | 50 | public Long getAsLong(final String key); 51 | public Long getAsLong(final String key, final Long defaultValue); 52 | 53 | public Long getAsLong(final Keyable key); 54 | public Long getAsLong(final Keyable key, final Long defaultValue); 55 | } 56 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/properties/ApplicationPropertiesFactory.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.properties; 2 | 3 | /** 4 | * User: ben 5 | * Date: 25/09/15 6 | * Time: 6:44 AM 7 | */ 8 | public class ApplicationPropertiesFactory { 9 | public ApplicationProperties createApplicationProperties() { 10 | return createApplicationProperties(null); 11 | } 12 | 13 | public ApplicationProperties createApplicationProperties(final PropertySource sessionProperties) { 14 | final CompositePropertyMap.Builder builder = CompositePropertyMap.Builder.create("ALL"); 15 | if(sessionProperties != null) builder.addLast(sessionProperties); 16 | builder.addLast(new SystemPropertySource()); 17 | builder.addLast(new SystemEnvVariablePropertySource()); 18 | builder.addLast(PropertyKeysAndDefaultValues.getDefaultProperties()); 19 | return builder.build(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/properties/ImmutablePropertyAndSource.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.properties; 2 | 3 | /** 4 | * User: ben 5 | * Date: 25/09/15 6 | * Time: 5:59 PM 7 | */ 8 | class ImmutablePropertyAndSource implements PropertyAndSource { 9 | private final String value; 10 | private final String source; 11 | 12 | public ImmutablePropertyAndSource(final String value, final String source) { 13 | this.value = value; 14 | this.source = source; 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | return value + " [" + source + "]"; 20 | } 21 | 22 | public String getValue() { 23 | return value; 24 | } 25 | 26 | public String getSource() { 27 | return source; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/properties/MapPropertySource.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.properties; 2 | 3 | import java.util.Collections; 4 | import java.util.LinkedHashMap; 5 | import java.util.Map; 6 | import java.util.Properties; 7 | 8 | /** 9 | * User: ben 10 | * Date: 3/12/14 11 | * Time: 5:10 PM 12 | */ 13 | public class MapPropertySource implements PropertySource { 14 | private final Map properties; 15 | private final String sourceName; 16 | 17 | public MapPropertySource(final Map properties, final String sourceName) { 18 | this.properties = Collections.unmodifiableMap(properties); 19 | this.sourceName = sourceName; 20 | } 21 | 22 | public MapPropertySource(final Properties properties, final String sourceName) { 23 | this(PropertyUtils.convertObjectMapToStringMap(properties), sourceName); 24 | } 25 | 26 | 27 | @Override 28 | public String getSourceName() { 29 | return this.sourceName; 30 | } 31 | 32 | @Override 33 | public Map getProperties() { 34 | return properties; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/properties/MutablePropertyAndSource.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.properties; 2 | 3 | /** 4 | * User: ben 5 | * Date: 25/09/15 6 | * Time: 5:59 PM 7 | */ 8 | class MutablePropertyAndSource implements PropertyAndSource { 9 | private String value; 10 | private final String source; 11 | 12 | public MutablePropertyAndSource(final String value, final String source) { 13 | this.value = value; 14 | this.source = source; 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | return value + " [" + source + "]"; 20 | } 21 | 22 | public String getValue() { 23 | return value; 24 | } 25 | 26 | public String getSource() { 27 | return source; 28 | } 29 | 30 | public void setValue(final String value) { 31 | this.value = value; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/properties/PropertyAndSource.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.properties; 2 | 3 | /** 4 | * User: ben 5 | * Date: 25/09/15 6 | * Time: 6:00 PM 7 | */ 8 | public interface PropertyAndSource { 9 | String getValue(); 10 | String getSource(); 11 | } 12 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/properties/PropertyKeysAndDefaultValues.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.properties; 2 | 3 | import org.fix4j.test.util.Keyable; 4 | 5 | import java.util.LinkedHashMap; 6 | import java.util.Map; 7 | 8 | /** 9 | * User: ben 10 | * Date: 4/12/14 11 | * Time: 4:56 PM 12 | */ 13 | public enum PropertyKeysAndDefaultValues implements Keyable { 14 | DEFAULT_FIX_MSG_WAIT_TIMEOUT_MS("fix4j.default.fix.msg.wait.timeout.ms", "2000"), 15 | POLL_PERIOD_MS("fix4j.poll.period.ms", "100"), 16 | SIZE_OF_RECENTLY_SENT_MESSAGES("fix4j.size.of.recently.sent.messages", "5"), 17 | SIZE_OF_DISCARDED_MESSAGES("fix4j.size.of.discarded.messages", "5"), 18 | DISPLAY_INCOMING_MESSAGE_FLAGS("fix4j.display.incoming.message.flags", "true"), 19 | FAST_FAIL_ON_TRIGGER_OF_INCOMING_MESSAGE_FLAG("fix4j.fast.fail.on.trigger.of.incoming.message.flag", "true"), 20 | FAST_FAIL_ON_TRIGGER_OF_OUTBOUND_MESSAGE_FLAG("fix4j.fast.fail.on.trigger.of.outbound.message.flag", "true"), 21 | FIX_FIELD_DELIM("fix4j.fix.field.delim", "(\\||\\^A|\\u0001)"), 22 | DEFAULT_MESSAGES_TO_IGNORE("fix4j.default.messages.to.ignore", "35=0"); 23 | 24 | private final String defaultValue; 25 | private final String key; 26 | 27 | private PropertyKeysAndDefaultValues(final String key, final String defaultValue) { 28 | this.defaultValue = defaultValue; 29 | this.key = key; 30 | } 31 | 32 | @Override 33 | public String getKey() { 34 | return key; 35 | } 36 | 37 | public static PropertySource getDefaultProperties(){ 38 | final Map properties = new LinkedHashMap<>(PropertyKeysAndDefaultValues.values().length); 39 | for (final PropertyKeysAndDefaultValues key : values()) { 40 | properties.put(key.getKey(), key.defaultValue); 41 | } 42 | return new MapPropertySource(properties, "DefaultValues"); 43 | } 44 | 45 | public String getDefaultValue() { 46 | return defaultValue; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/properties/PropertySource.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.properties; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * User: ben 8 | * Date: 3/12/14 9 | * Time: 5:05 PM 10 | */ 11 | public interface PropertySource { 12 | Map getProperties(); 13 | public String getSourceName(); 14 | } 15 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/properties/PropertyUtils.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.properties; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * User: ben 8 | * Date: 17/12/14 9 | * Time: 11:50 PM 10 | */ 11 | public class PropertyUtils { 12 | private PropertyUtils() { 13 | } 14 | 15 | public static Map getPropertiesWithFix4jKeyPrefix(final Map environmentVariables) { 16 | final Map processedVariables = new LinkedHashMap<>(); 17 | for (final String key : environmentVariables.keySet()) { 18 | if(key.toUpperCase().startsWith("FIX4J")){ 19 | processedVariables.put(key, environmentVariables.get(key)); 20 | } 21 | } 22 | return processedVariables; 23 | } 24 | 25 | public static Map formatKeys(final Map environmentVariables) { 26 | final Map processedVariables = new LinkedHashMap<>(); 27 | for (final String envVarKey : environmentVariables.keySet()) { 28 | final String newKey = envVarKey.replace('_', '.').toLowerCase(); 29 | processedVariables.put(newKey, environmentVariables.get(envVarKey)); 30 | } 31 | return processedVariables; 32 | } 33 | 34 | public static Map convertObjectMapToStringMap(final Map properties) { 35 | final Map stringProperties = new LinkedHashMap<>(); 36 | for (final Object key : properties.keySet()) { 37 | stringProperties.put(key.toString(), properties.get(key).toString()); 38 | } 39 | return stringProperties; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/properties/SystemEnvVariablePropertySource.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.properties; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * Provides a source of properties from the JVMs list of environment variables. 8 | * 9 | * Only environment variables starting with "fix4j" or "FIX4J" will be sourced. 10 | * 11 | * Also, keys will be formatted using the following two rules: 12 | * -Underscores are replaces with periods '.' 13 | * -The key is converted to lowercase (value is left as is) 14 | * 15 | * For example, the environment variables: 16 | * FIX4J_FIRST_PROPERTY=blah1 17 | * FIX4J_SECOND_PROPERTY=BLAH2 18 | * fix4j_third_property=blah3 19 | * RANDOM_PROPERTY=dunno 20 | * 21 | * Will become available in the property source as: 22 | * fix4.first.property=blah1 23 | * fix4.second.property=BLAH2 24 | * fix4.third.property=blah1 25 | * 26 | * User: ben 27 | */ 28 | public class SystemEnvVariablePropertySource implements PropertySource { 29 | private final static String SOURCE_NAME = "ENVIRONMENT_VARIABLES"; 30 | 31 | @Override 32 | public String getSourceName() { 33 | return SOURCE_NAME; 34 | } 35 | 36 | @Override 37 | public Map getProperties() { 38 | return getAndFormatRelevantEnvironmentVariables(System.getenv()); 39 | } 40 | 41 | public Map getAndFormatRelevantEnvironmentVariables(final Map environmentVariables) { 42 | return PropertyUtils.formatKeys(PropertyUtils.getPropertiesWithFix4jKeyPrefix(environmentVariables)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/properties/SystemPropertySource.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.properties; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * Provides a source of properties from the JVMs list of system properties. 8 | * 9 | * These are the properties that are usually available by calling System.getProperty(key) 10 | * 11 | * These properties can be specified programatically, e.g. 12 | * 13 | * System.setProperty("fix4j.first.property", "blah"); 14 | * 15 | * ...or via the command line: 16 | * java -Dfix4j.first.property=blah MyAppOrTest 17 | * 18 | * Please note, only keys prefixed with "fix4j" or "FIX4J" will be available. 19 | * 20 | * User: ben 21 | */ 22 | public class SystemPropertySource implements PropertySource { 23 | private final static String SOURCE_NAME = "SYSTEM_PROPERTIES"; 24 | 25 | @Override 26 | public String getSourceName() { 27 | return SOURCE_NAME; 28 | } 29 | 30 | @Override 31 | public Map getProperties() { 32 | return PropertyUtils.getPropertiesWithFix4jKeyPrefix(PropertyUtils.convertObjectMapToStringMap(System.getProperties())); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/session/ConsumerSession.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.session; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.fixspec.FixSpecification; 5 | import org.fix4j.test.plumbing.Consumer; 6 | import org.fix4j.test.plumbing.ShuntFromSupplierToConsumer; 7 | 8 | /** 9 | * User: ben 10 | * Date: 21/08/2014 11 | * Time: 5:26 AM 12 | */ 13 | public class ConsumerSession implements TestClientSession{ 14 | private final SimpleOutboundSession outboundSession; 15 | private final SessionContext sessionContext; 16 | 17 | public ConsumerSession(final SessionContext sessionContext, final Consumer toTestClient) { 18 | new ShuntFromSupplierToConsumer<>("fromNetwork-to-testClient", sessionContext.sessionConnectors.inboundSupplier, toTestClient).start(); 19 | this.outboundSession = new SimpleOutboundSession(sessionContext.fixSpecification, sessionContext.sessionConnectors.outboundConsumer); 20 | this.sessionContext = sessionContext; 21 | } 22 | 23 | public void send(final String messageStr) { 24 | try { 25 | outboundSession.send(messageStr); 26 | } catch (final Failure failure) { 27 | throw sessionContext.enrichFailureWithAdditionalReports(failure); 28 | } 29 | } 30 | 31 | public void send(final FixMessage message){ 32 | try { 33 | outboundSession.send(message); 34 | } catch (final Failure failure) { 35 | throw sessionContext.enrichFailureWithAdditionalReports(failure); 36 | } 37 | } 38 | 39 | @Override 40 | public void shutdown(){ 41 | sessionContext.fixEngineSession.shutdown(); 42 | } 43 | 44 | @Override 45 | public FixSpecification getFixSpecification() { 46 | return sessionContext.fixSpecification; 47 | } 48 | 49 | @Override 50 | public FixSessionId getSessionId() { 51 | return sessionContext.fixSessionId; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/session/ContextFactory.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.session; 2 | 3 | import org.fix4j.test.fixspec.FixSpecification; 4 | import org.fix4j.test.properties.ApplicationProperties; 5 | 6 | import java.util.Map; 7 | import java.util.Properties; 8 | 9 | /** 10 | * User: ben 11 | * Date: 2/12/14 12 | * Time: 5:35 AM 13 | */ 14 | public interface ContextFactory { 15 | SessionContext createSessionContext(FixSessionId fixSessionId, FixConnectionMode fixConnectionMode, Map sessionProperties); 16 | FixSpecification getFixSpecification(); 17 | } 18 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/session/DispatchingSession.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.session; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.fixmodel.Handler; 5 | import org.fix4j.test.fixspec.FixSpecification; 6 | import org.fix4j.test.plumbing.ExceptionHandler; 7 | import org.fix4j.test.plumbing.ShuntFromSupplierToConsumer; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | /** 12 | * User: ben 13 | * Date: 21/08/2014 14 | * Time: 5:26 AM 15 | */ 16 | public class DispatchingSession implements TestClientSession, ExceptionHandler { 17 | private final static Logger LOGGER = LoggerFactory.getLogger(DispatchingSession.class); 18 | private final SimpleOutboundSession outboundSession; 19 | private final SessionContext sessionContext; 20 | 21 | public DispatchingSession(final SessionContext sessionContext, final Handler messageHandler) { 22 | this.sessionContext = sessionContext; 23 | final MessageDispatcher messageDispatcher = new MessageDispatcher(sessionContext.fixSpecification, messageHandler); 24 | new ShuntFromSupplierToConsumer<>("fromNetwork-to-messageDispatcher", sessionContext.sessionConnectors.inboundSupplier, messageDispatcher, this).start(); 25 | this.outboundSession = new SimpleOutboundSession(sessionContext.fixSpecification, sessionContext.sessionConnectors.outboundConsumer); 26 | } 27 | 28 | public void send(final String messageStr) { 29 | try { 30 | outboundSession.send(messageStr); 31 | } catch (final Failure failure) { 32 | throw sessionContext.enrichFailureWithAdditionalReports(failure); 33 | } 34 | } 35 | 36 | public void send(final FixMessage message){ 37 | try { 38 | outboundSession.send(message); 39 | } catch (final Failure failure) { 40 | throw sessionContext.enrichFailureWithAdditionalReports(failure); 41 | } 42 | } 43 | 44 | @Override 45 | public void shutdown() { 46 | sessionContext.fixEngineSession.shutdown(); 47 | } 48 | 49 | @Override 50 | public FixSpecification getFixSpecification() { 51 | return sessionContext.fixSpecification; 52 | } 53 | 54 | @Override 55 | public FixSessionId getSessionId() { 56 | return sessionContext.fixSessionId; 57 | } 58 | 59 | @Override 60 | public Throwable handle(final Throwable t) { 61 | LOGGER.error("Exception occurred whilst receiving messages. Shutting down session.", t); 62 | this.shutdown(); 63 | return t; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/session/Failure.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.session; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.util.CompositeReport; 5 | import org.fix4j.test.util.Consts; 6 | import org.fix4j.test.util.Report; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * User: ben 12 | * Date: 22/11/14 13 | * Time: 4:25 AM 14 | */ 15 | public class Failure extends AssertionError { 16 | private static final long serialVersionUID = -6098281437774175888L; 17 | private final FixMessage fixMessage; 18 | 19 | public Failure(final Report report, final FixMessage fixMessage) { 20 | super(report.getReportAsString() + fixMessage.toDelimitedMessageWithDescriptors() + Consts.EOL); 21 | this.fixMessage = fixMessage; 22 | } 23 | 24 | public Failure(final FixMessage fixMessage, final Throwable cause) { 25 | super("Exception when processing messsage: " + fixMessage.toDelimitedMessageWithDescriptors() + Consts.EOL, cause); 26 | this.fixMessage = fixMessage; 27 | } 28 | 29 | public Failure(final Report report) { 30 | super(report.getReportAsString()); 31 | this.fixMessage = null; 32 | } 33 | 34 | public Failure(final String message) { 35 | super(message); 36 | this.fixMessage = null; 37 | } 38 | 39 | public Failure(final String message, final Throwable cause) { 40 | super(message, cause); 41 | this.fixMessage = null; 42 | } 43 | 44 | public Failure(final Throwable cause) { 45 | super(cause); 46 | this.fixMessage = null; 47 | } 48 | 49 | public Failure(final String heading, final Report report) { 50 | super(heading + Consts.EOL + report.getReportAsString()); 51 | this.fixMessage = null; 52 | } 53 | 54 | public Failure(final FixMessage fixMessage, final String message) { 55 | super(message); 56 | this.fixMessage = fixMessage; 57 | } 58 | 59 | public Failure(final String message, final FixMessage fixMessage, final Throwable cause) { 60 | super(message, cause); 61 | this.fixMessage = fixMessage; 62 | } 63 | 64 | public Failure withAdditionalReports(final List reports) { 65 | final CompositeReport otherReports = new CompositeReport(reports); 66 | return new Failure(this.getMessage() + otherReports.getReportAsString(), fixMessage, this.getCause()); 67 | } 68 | 69 | public Failure withHeading(final String heading) { 70 | return new Failure(heading + Consts.EOL + getMessage(), fixMessage, this.getCause()); 71 | } 72 | 73 | public Failure withPrefixedMessage(final String prefix) { 74 | return new Failure(prefix + getMessage(), fixMessage, this.getCause()); 75 | } 76 | 77 | public FixMessage getFixMessage() { 78 | return fixMessage; 79 | } 80 | 81 | @Override 82 | public String toString() { 83 | return "FAILURE: " + super.getMessage() + Consts.EOL; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/session/FixConnectionMode.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.session; 2 | 3 | /** 4 | * User: ben 5 | * Date: 25/11/14 6 | * Time: 5:35 AM 7 | */ 8 | public enum FixConnectionMode { 9 | INITIATOR, 10 | ACCEPTOR; 11 | } 12 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/session/FixSession.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.session; 2 | 3 | /** 4 | * User: ben 5 | * Date: 20/08/2014 6 | * Time: 6:08 AM 7 | */ 8 | public interface FixSession { 9 | void logon(); 10 | void logout(); 11 | } 12 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/session/FixSessionId.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.session; 2 | 3 | /** 4 | * User: ben 5 | * Date: 20/08/2014 6 | * Time: 5:51 AM 7 | */ 8 | public class FixSessionId { 9 | private final String beginString; 10 | private final String senderCompId; 11 | private final String targetCompId; 12 | 13 | public FixSessionId(final String beginString, final String senderCompId, final String targetCompId) { 14 | this.beginString = beginString; 15 | this.senderCompId = senderCompId; 16 | this.targetCompId = targetCompId; 17 | } 18 | 19 | public String getBeginString() { 20 | return beginString; 21 | } 22 | 23 | public String getSenderCompId() { 24 | return senderCompId; 25 | } 26 | 27 | public String getTargetCompId() { 28 | return targetCompId; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return beginString + ":" + senderCompId + "->" + targetCompId; 34 | } 35 | 36 | /** 37 | * @return A FixSessionId with sender and target compIDs switched. 38 | */ 39 | public FixSessionId reverse(){ 40 | return new FixSessionId(beginString, targetCompId, senderCompId); 41 | } 42 | 43 | @Override 44 | public boolean equals(final Object o) { 45 | if (this == o) return true; 46 | if (!(o instanceof FixSessionId)) return false; 47 | 48 | final FixSessionId that = (FixSessionId) o; 49 | 50 | if (!beginString.equals(that.beginString)) return false; 51 | if (!senderCompId.equals(that.senderCompId)) return false; 52 | if (!targetCompId.equals(that.targetCompId)) return false; 53 | 54 | return true; 55 | } 56 | 57 | @Override 58 | public int hashCode() { 59 | int result = beginString.hashCode(); 60 | result = 31 * result + senderCompId.hashCode(); 61 | result = 31 * result + targetCompId.hashCode(); 62 | return result; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/session/SessionConnectors.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.session; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.plumbing.Consumer; 5 | import org.fix4j.test.plumbing.Supplier; 6 | 7 | /** 8 | * User: ben 9 | * Date: 24/11/14 10 | * Time: 5:11 PM 11 | */ 12 | public class SessionConnectors { 13 | public final Supplier inboundSupplier; 14 | public final Consumer outboundConsumer; 15 | 16 | public SessionConnectors(final Supplier inboundSupplier, final Consumer outboundConsumer) { 17 | this.inboundSupplier = inboundSupplier; 18 | this.outboundConsumer = outboundConsumer; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/session/SessionContext.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.session; 2 | 3 | import org.fix4j.test.integration.FixEngineSession; 4 | import org.fix4j.test.fixspec.FixSpecification; 5 | import org.fix4j.test.processors.OnFailureReporters; 6 | import org.fix4j.test.properties.ApplicationProperties; 7 | 8 | /** 9 | * User: ben 10 | * Date: 25/11/14 11 | * Time: 5:27 PM 12 | */ 13 | public class SessionContext { 14 | public final SessionConnectors sessionConnectors; 15 | public final FixSessionId fixSessionId; 16 | public final OnFailureReporters onFailureReporters; 17 | public final FixConnectionMode fixConnectionMode; 18 | public final FixEngineSession fixEngineSession; 19 | public final FixSpecification fixSpecification; 20 | 21 | public SessionContext(final SessionConnectors sessionConnectors, final FixSessionId fixSessionId, final OnFailureReporters onFailureReporters, final FixConnectionMode fixConnectionMode, final FixEngineSession fixEngineSession, final FixSpecification fixSpecification) { 22 | this.sessionConnectors = sessionConnectors; 23 | this.fixSessionId = fixSessionId; 24 | this.onFailureReporters = onFailureReporters; 25 | this.fixConnectionMode = fixConnectionMode; 26 | this.fixEngineSession = fixEngineSession; 27 | this.fixSpecification = fixSpecification; 28 | } 29 | 30 | public Error enrichFailureWithAdditionalReports(final Failure failure) { 31 | return onFailureReporters.enrichFailureWithAdditionalReports(fixSessionId, failure); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/session/SimpleOutboundSession.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.session; 2 | 3 | import org.fix4j.test.fixmodel.FixMessage; 4 | import org.fix4j.test.fixspec.FixSpecification; 5 | import org.fix4j.test.expression.MessageExpression; 6 | import org.fix4j.test.expression.FlexibleMessageExpressionParser; 7 | import org.fix4j.test.plumbing.Consumer; 8 | import org.fix4j.test.util.Consts; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | /** 13 | * User: ben 14 | * Date: 19/11/14 15 | * Time: 12:52 AM 16 | */ 17 | public class SimpleOutboundSession { 18 | private final static Logger LOGGER = LoggerFactory.getLogger(SimpleOutboundSession.class); 19 | private final FixSpecification fixSpecification; 20 | private final Consumer toNetwork; 21 | private final FlexibleMessageExpressionParser messageExpressionParser; 22 | 23 | public SimpleOutboundSession(final FixSpecification fixSpecification, final Consumer toNetwork) { 24 | this.fixSpecification = fixSpecification; 25 | this.toNetwork = toNetwork; 26 | this.messageExpressionParser = new FlexibleMessageExpressionParser(fixSpecification); 27 | } 28 | 29 | public void send(final String messageStr) { 30 | final MessageExpression expression = messageExpressionParser.parse(messageStr); 31 | final FixMessage message = expression.asMessage(fixSpecification); 32 | send(message); 33 | } 34 | 35 | public void send(final FixMessage message){ 36 | LOGGER.info(">>>>>>" + Consts.EOL + message.toPrettyString()); 37 | toNetwork.accept(message); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/session/TestClientSession.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.session; 2 | 3 | import org.fix4j.test.fixspec.FixSpecification; 4 | 5 | /** 6 | * User: ben 7 | * Date: 2/12/14 8 | * Time: 5:59 AM 9 | */ 10 | public interface TestClientSession { 11 | void shutdown(); 12 | FixSpecification getFixSpecification(); 13 | FixSessionId getSessionId(); 14 | } 15 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/session/TimeoutReport.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.session; 2 | 3 | import org.fix4j.test.matching.matchers.FixMessageMatcher; 4 | import org.fix4j.test.util.Consts; 5 | import org.fix4j.test.util.Report; 6 | 7 | /** 8 | * User: ben 9 | * Date: 7/11/2014 10 | * Time: 6:31 PM 11 | */ 12 | public class TimeoutReport implements Report { 13 | private final FixMessageMatcher matcher; 14 | 15 | public TimeoutReport(final FixMessageMatcher matcher) { 16 | this.matcher = matcher; 17 | } 18 | 19 | public TimeoutReport() { 20 | this.matcher = null; 21 | } 22 | 23 | @Override 24 | public String getReportAsString() { 25 | if(matcher == null){ 26 | return "Timeout waiting for next message" + Consts.EOL; 27 | } else { 28 | return "Timeout waiting for message which matches: " + matcher.toString() + Consts.EOL; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/util/ArrayListMultimap.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.Iterator; 6 | import java.util.List; 7 | import java.util.concurrent.ConcurrentHashMap; 8 | 9 | /** 10 | * User: ben 11 | * Date: 23/09/2014 12 | * Time: 5:23 AM 13 | */ 14 | public class ArrayListMultimap implements Multimap { 15 | private final List EMPTY = Collections.unmodifiableList(new ArrayList()); 16 | private final ConcurrentHashMap> map = new ConcurrentHashMap>(); 17 | 18 | @Override 19 | public List get(final K key) { 20 | final List results = map.get(key); 21 | if(results == null) return EMPTY; 22 | else return Collections.unmodifiableList(results); 23 | } 24 | 25 | @Override 26 | public V getExpectingOne(final K key) { 27 | final List results = get(key); 28 | if(results.size() == 0 || results.size() > 1){ 29 | throw new IllegalStateException("Single result expected, " + results.size() + " found. key:" + key + " values:" + results); 30 | } else { 31 | return results.get(0); 32 | } 33 | } 34 | 35 | @Override 36 | public V getFirst(final K key) { 37 | final List results = get(key); 38 | if(results.size() == 0){ 39 | throw new IllegalStateException("At least one result expected, none found. Key:" + key); 40 | } else { 41 | return results.get(0); 42 | } 43 | } 44 | 45 | @Override 46 | public void put(final K key, final V value) { 47 | if(value == null){ 48 | throw new IllegalArgumentException("Value cannot be null"); 49 | } 50 | List results = map.get(key); 51 | if(results == null){ 52 | List newList = new ArrayList(); 53 | List alreadyExistingList = map.putIfAbsent(key, newList); 54 | results = (alreadyExistingList != null) ? alreadyExistingList: newList; 55 | } 56 | results.add(value); 57 | } 58 | 59 | @Override 60 | public boolean containsAtLeastOneValueFor(final K key){ 61 | //assumes that empty lists will not be stored in the map 62 | return map.containsKey(key); 63 | } 64 | 65 | @Override 66 | public boolean containsKey(final K key){ 67 | return containsAtLeastOneValueFor(key); 68 | } 69 | 70 | @Override 71 | public List allValues() { 72 | final List returnList = new ArrayList(); 73 | for(final K key: map.keySet()){ 74 | returnList.addAll(map.get(key)); 75 | } 76 | return Collections.unmodifiableList(returnList); 77 | } 78 | 79 | @Override 80 | public Iterator values(){ 81 | return allValues().iterator(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/util/Asserts.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util; 2 | 3 | /** 4 | * User: ben 5 | * Date: 25/08/2014 6 | * Time: 4:54 PM 7 | */ 8 | 9 | public class Asserts { 10 | private Asserts() { 11 | } 12 | 13 | public static void assertTrue(final boolean condition){ 14 | if(!condition) throw new IllegalArgumentException("Condition is not true."); 15 | } 16 | 17 | public static void assertFalse(final boolean condition){ 18 | if(condition) throw new IllegalArgumentException("Condition is not false."); 19 | } 20 | 21 | public static void assertNull(final Object shouldBeNull){ 22 | if( shouldBeNull != null) throw new IllegalArgumentException("Object is not null."); 23 | } 24 | 25 | public static void assertNotNull(final Object shouldNotBeNull){ 26 | if( shouldNotBeNull == null) throw new IllegalArgumentException("Object is null."); 27 | } 28 | 29 | public static void assertTrue(final String message, final boolean condition){ 30 | if(!condition) throw new IllegalArgumentException(message); 31 | } 32 | 33 | public static void assertFalse(final String message, final boolean condition){ 34 | if(condition) throw new IllegalArgumentException(message); 35 | } 36 | 37 | public static void assertNull(final String message, final Object shouldBeNull){ 38 | if( shouldBeNull != null) throw new IllegalArgumentException(message); 39 | } 40 | 41 | public static void assertNotNull(final String message, final Object shouldNotBeNull){ 42 | if( shouldNotBeNull == null) throw new IllegalArgumentException(message); 43 | } 44 | 45 | public static void assertEquals(final String message, final Object o1, final Object o2) { 46 | if(o1 == o2) return; 47 | boolean notEqual = (o1 == null || o2 == null || !o1.equals(o2)); 48 | if(notEqual){ 49 | final String formattedMessage = "Objects are not equal. o1:" + o1 + " o2:" + o2 + (message == null ? "": ": " + message); 50 | throw new IllegalArgumentException(formattedMessage); 51 | } 52 | } 53 | 54 | public static void assertEquals(final Object o1, final Object o2) { 55 | assertEquals(null, o1, o2); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/util/BaseReport.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util; 2 | 3 | /** 4 | * User: ben 5 | * Date: 19/11/14 6 | * Time: 4:41 PM 7 | */ 8 | public class BaseReport implements Report { 9 | private final String content; 10 | 11 | public BaseReport(final String content) { 12 | this.content = content; 13 | } 14 | 15 | public String getReportAsString(){ 16 | if(content != null && content.length() > 0){ 17 | return StringUtils.indentAllLines(content) + Consts.EOL; 18 | } else { 19 | return ""; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/util/BoundedArray.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util; 2 | 3 | import java.util.Iterator; 4 | import java.util.concurrent.ConcurrentLinkedDeque; 5 | 6 | /** 7 | * User: ben 8 | * Date: 27/09/2014 9 | * Time: 4:53 AM 10 | */ 11 | public class BoundedArray implements Iterable { 12 | private final ConcurrentLinkedDeque list; 13 | private final int capacity; 14 | private boolean capacityWasHit = false; 15 | 16 | public BoundedArray(final int capacity) { 17 | this.list = new ConcurrentLinkedDeque<>(); 18 | this.capacity = capacity; 19 | } 20 | 21 | public synchronized void add(T element) { 22 | if(capacity == 0) return; 23 | if(list.size() >= capacity){ 24 | capacityWasHit = true; 25 | list.removeFirst(); 26 | } 27 | list.add(element); 28 | } 29 | 30 | public synchronized void addAll(final Iterator i) { 31 | if(capacity == 0) return; 32 | while(i.hasNext()){ 33 | add(i.next()); 34 | } 35 | } 36 | 37 | @Override 38 | public Iterator iterator(){ 39 | return list.iterator(); 40 | } 41 | 42 | public boolean isEmpty() { 43 | return list.isEmpty(); 44 | } 45 | 46 | public boolean wasAddedToWhenAtCapacity(){ 47 | return capacityWasHit; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/util/CompositeReport.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | /** 9 | * User: ben 10 | * Date: 19/11/14 11 | * Time: 4:41 PM 12 | */ 13 | public class CompositeReport implements Report { 14 | private final List reports; 15 | 16 | public CompositeReport(final List reports) { 17 | this.reports = Collections.unmodifiableList(reports); 18 | } 19 | 20 | public CompositeReport(final Report ... reports) { 21 | this.reports = Collections.unmodifiableList(Arrays.asList(reports)); 22 | } 23 | 24 | public String getReportAsString(){ 25 | final StringBuilder sb = new StringBuilder(); 26 | for (final Report report : reports) { 27 | sb.append(report.getReportAsString()); 28 | } 29 | return sb.toString(); 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "CompositeReport{" + 35 | "reports=" + reports + 36 | '}'; 37 | } 38 | 39 | public static class CompositeReportBuilder{ 40 | private final List reports = new ArrayList<>(); 41 | 42 | public CompositeReportBuilder add(final Report report){ 43 | this.reports.add(report); 44 | return this; 45 | } 46 | 47 | public CompositeReport build(){ 48 | return new CompositeReport(reports); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/util/Consts.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util; 2 | 3 | /** 4 | * User: ben 5 | * Date: 19/08/2014 6 | * Time: 6:07 AM 7 | */ 8 | public class Consts { 9 | private Consts() {} 10 | public static final String EOL_EOL = "\n\n"; 11 | public static final String EOL = "\n"; 12 | public static final String INDENT = " "; 13 | public static final String DOUBLE_INDENT = INDENT + INDENT; 14 | public static final String ASCII_1 = "\u0001"; 15 | public static final String FIX_FIELD_DISPLAY_DELIM = "|"; 16 | public static final String FIX_FIELD_DISPLAY_DELIM_REGEX = "\\|"; 17 | public static final String FIX_FIELD_EQUALS = "="; 18 | public static final int DEFAULT_NUM_OF_GROUP_REPEATS_IN_EXAMPLE_GENERATOR = 3; 19 | } 20 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/util/ExceptionUtils.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * User: ben 8 | * Date: 15/01/15 9 | * Time: 7:17 AM 10 | */ 11 | public class ExceptionUtils { 12 | private ExceptionUtils() { 13 | } 14 | 15 | public static void assertExceptionMessagesContain(Throwable exception, final String str){ 16 | final List messages = new ArrayList<>(); 17 | while(true){ 18 | messages.add(exception.getMessage()); 19 | if(exception.getMessage().contains(str)){ 20 | return; 21 | } else if(exception.getCause() != null && exception.getCause() != exception && !exception.getCause().equals(exception)){ 22 | exception = exception.getCause(); 23 | } else { 24 | throw new AssertionError("Exception, and 'chain' of causes, do not have messages which contain text '" + str + "'. All messages: " + messages); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/util/Keyable.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util; 2 | 3 | /** 4 | * User: ben 5 | * Date: 17/12/14 6 | * Time: 5:11 PM 7 | */ 8 | public interface Keyable { 9 | public T getKey(); 10 | } 11 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/util/Multimap.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util; 2 | 3 | import java.util.Collection; 4 | import java.util.Collections; 5 | import java.util.Iterator; 6 | import java.util.List; 7 | 8 | /** 9 | * User: ben 10 | * Date: 23/09/2014 11 | * Time: 5:21 AM 12 | */ 13 | public interface Multimap { 14 | Collection get(K key); 15 | V getExpectingOne(K key); 16 | V getFirst(K key); 17 | void put(K key, V value); 18 | boolean containsAtLeastOneValueFor(K key); 19 | boolean containsKey(K key); 20 | List allValues(); 21 | Iterator values(); 22 | 23 | public static class Utils{ 24 | public static Multimap unmodifiableMultimap(final Multimap multimap){ 25 | return new Multimap() { 26 | @Override 27 | public Collection get(final K key) { 28 | //I know that ArrayListMultimap already returns an unmodifiable List. However not sure 29 | //what the implementation is here, so being cautious. 30 | return Collections.unmodifiableCollection(multimap.get(key)); 31 | } 32 | 33 | @Override 34 | public V getExpectingOne(final K key) { 35 | return multimap.getExpectingOne(key); 36 | } 37 | 38 | @Override 39 | public V getFirst(final K key) { 40 | return multimap.getFirst(key); 41 | } 42 | 43 | @Override 44 | public void put(final K key, final V value) { 45 | throw new UnsupportedOperationException("Cannot modify this multimap as it has been created as Unmodifiable."); 46 | } 47 | 48 | @Override 49 | public boolean containsAtLeastOneValueFor(final K key) { 50 | return multimap.containsAtLeastOneValueFor(key); 51 | } 52 | 53 | @Override 54 | public boolean containsKey(final K key) { 55 | return multimap.containsKey(key); 56 | } 57 | 58 | @Override 59 | public List allValues() { 60 | return multimap.allValues(); 61 | } 62 | 63 | @Override 64 | public Iterator values() { 65 | return allValues().iterator(); 66 | } 67 | }; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/util/PeekableIterator.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util; 2 | 3 | import java.util.Iterator; 4 | 5 | /** 6 | * User: ben 7 | * Date: 3/09/2014 8 | * Time: 6:50 PM 9 | */ 10 | public class PeekableIterator implements Iterator { 11 | private final Iterator iterator; 12 | private T peekedValue = null; 13 | 14 | public PeekableIterator(final Iterator iterator) { 15 | this.iterator = iterator; 16 | } 17 | 18 | public PeekableIterator(final Iterable iterable) { 19 | this.iterator = iterable.iterator(); 20 | } 21 | 22 | @Override 23 | public boolean hasNext() { 24 | return peekedValue != null || iterator.hasNext(); 25 | } 26 | 27 | @Override 28 | public T next() { 29 | if(peekedValue != null){ 30 | final T returnValue = peekedValue; 31 | peekedValue = null; 32 | return returnValue; 33 | } else { 34 | return iterator.next(); 35 | } 36 | } 37 | 38 | @Override 39 | public void remove() { 40 | if(peekedValue != null){ 41 | final T returnValue = peekedValue; 42 | peekedValue = null; 43 | } else { 44 | iterator.remove(); 45 | } 46 | } 47 | 48 | public T peek(){ 49 | if(peekedValue != null){ 50 | return peekedValue; 51 | } else { 52 | peekedValue = iterator.next(); 53 | return peekedValue; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/util/Report.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * There are a number of requirements, for classes that return a report: 8 | * --With some classes we want to return a FAIL/WARN/INFO. e.g. We might want to fail-fast when inbound messages are flagged, i.e. we've received a session 9 | * level reject. Whereas we might have configured the system to just flag it as a warning. 10 | * 11 | * FAIL/WARN/INFO & report 12 | * 13 | * 14 | * --With some classes we want to return matches=true/false. e.g. a matcher might be used to decide whether to filter out 15 | * a message. Or a matcher might be used to decide whether we have a message which passes our assert. Using a FAIL for a non-match 16 | * in the filter might seem strange. i.e. we get a FAIL so we don't filter. 17 | * 18 | * MatchResult 19 | * true/false & report 20 | * 21 | * 22 | * --With some classes we want to return a "directive" and a report. e.g. when doing a discardUntilMatch assert, we want 23 | * to let the MatchActivity know to discard non matching messages. When a message matches, then we want to stop discarding 24 | * and return a report showing how the match occurred. So in this case returning a FAIL when it doesn't match, and an INFO 25 | * when it does match, does not really make sense. 26 | * 27 | * MatchActivityDirectiveAndReport 28 | * directive & report 29 | * 30 | * 31 | * --In some cases we want to return the matches message and a report. e.g. when doing message matching for oncoming messages. 32 | * MatchActivityResult 33 | * message & success & report 34 | * 35 | */ 36 | public interface Report { 37 | public static class Util{ 38 | public static List fetchReportsFromReporters(final List reporters) { 39 | final ArrayList reports = new ArrayList<>(); 40 | for (final Reportable reporter : reporters) { 41 | reports.add(reporter.getReport()); 42 | } 43 | return reports; 44 | } 45 | } 46 | String getReportAsString(); 47 | } 48 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/util/ReportLevel.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util; 2 | 3 | /** 4 | * User: ben 5 | * Date: 19/11/14 6 | * Time: 4:49 PM 7 | */ 8 | public enum ReportLevel { 9 | FAIL(3), WARN(2), INFO(1), EMPTY(0); 10 | 11 | private final int index; 12 | 13 | private ReportLevel(final int index) { 14 | this.index = index; 15 | } 16 | 17 | public static ReportLevel getLowestLevel() { 18 | return EMPTY; 19 | } 20 | 21 | public boolean isAtLeast(final ReportLevel reportLevel){ 22 | return this.index >= reportLevel.index; 23 | } 24 | 25 | public static ReportLevel highestOf(final ReportLevel ... levels) { 26 | ReportLevel highest = null; 27 | for (final ReportLevel level : levels) { 28 | if(highest == null || level.index > highest.index){ 29 | highest = level; 30 | } 31 | } 32 | return highest; 33 | } 34 | 35 | public boolean isFail() { 36 | return this == FAIL; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/util/Reportable.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util; 2 | 3 | /** 4 | * User: ben 5 | * Date: 27/09/2014 6 | * Time: 5:02 AM 7 | */ 8 | public interface Reportable { 9 | public Report getReport(); 10 | } 11 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/util/TwoWayMap.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) quickfixengine.org All rights reserved. 3 | * 4 | * This file is part of the QuickFIX FIX Engine 5 | * 6 | * This file may be distributed under the terms of the quickfixengine.org 7 | * license as defined by quickfixengine.org and appearing in the file 8 | * LICENSE included in the packaging of this file. 9 | * 10 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING 11 | * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A 12 | * PARTICULAR PURPOSE. 13 | * 14 | * See http://www.quickfixengine.org/LICENSE for licensing information. 15 | * 16 | * Contact ask@quickfixengine.org if any conditions of this licensing 17 | * are not clear to you. 18 | ******************************************************************************/ 19 | 20 | package org.fix4j.test.util; 21 | 22 | import java.util.HashMap; 23 | 24 | public class TwoWayMap { 25 | private HashMap firstToSecond = new HashMap(); 26 | private HashMap secondToFirst = new HashMap(); 27 | 28 | public void put(Object first, Object second) { 29 | firstToSecond.put(first, second); 30 | secondToFirst.put(second, first); 31 | } 32 | 33 | public Object getFirst(Object first) { 34 | return firstToSecond.get(first); 35 | } 36 | 37 | public Object getSecond(Object second) { 38 | return secondToFirst.get(second); 39 | } 40 | 41 | public String toString() { 42 | return firstToSecond.toString() + "\n" + secondToFirst.toString(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/main/java/org/fix4j/test/util/Utils.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | import java.util.concurrent.BlockingQueue; 6 | import java.util.concurrent.Callable; 7 | 8 | /** 9 | * User: ben 10 | * Date: 19/08/2014 11 | * Time: 6:02 PM 12 | */ 13 | public class Utils { 14 | public static int[] toIntArray(List list) { 15 | int[] ret = new int[list.size()]; 16 | int i = 0; 17 | for (Integer e : list) 18 | ret[i++] = e; 19 | return ret; 20 | } 21 | 22 | public static V executeUntilNonNullOrTimeout(final long timeoutMs, final long timeBetweenPollsMs, final Callable callable) throws InterruptedException { 23 | final long started = new Date().getTime(); 24 | long elapsedTime = 0; 25 | while (elapsedTime < timeoutMs) { 26 | final V value; 27 | try { 28 | value = callable.call(); 29 | } catch (Exception e) { 30 | throw new RuntimeException(e); 31 | } 32 | if (value != null) { 33 | return value; 34 | } else { 35 | elapsedTime = (new Date().getTime()) - started; 36 | } 37 | Thread.sleep(timeBetweenPollsMs); 38 | } 39 | return null; 40 | } 41 | 42 | /** 43 | * Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty. 44 | * @return the head of this queue, or null if this queue is empty 45 | * @throws InterruptedException 46 | */ 47 | public static T peek(final BlockingQueue queue, final long timeoutMs, final long timeBetweenPollsMs) throws InterruptedException { 48 | return Utils.executeUntilNonNullOrTimeout(timeoutMs, timeBetweenPollsMs, new Callable() { 49 | @Override 50 | public T call() throws Exception { 51 | return queue.peek(); 52 | } 53 | }); 54 | } 55 | 56 | /** 57 | * Retrieves and removes the head of this queue, or returns null if this queue is empty. 58 | * @return the head of this queue, or null if this queue is empty 59 | * @throws InterruptedException 60 | */ 61 | public static T poll(final BlockingQueue queue, final long timeoutMs, final long timeBetweenPollsMs) throws InterruptedException { 62 | return Utils.executeUntilNonNullOrTimeout(timeoutMs, timeBetweenPollsMs, new Callable() { 63 | @Override 64 | public T call() throws Exception { 65 | return queue.poll(); 66 | } 67 | }); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/test/groovy/org/fix4j/test/fixmodel/FieldTest.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixmodel 2 | 3 | import spock.lang.Specification 4 | 5 | /** 6 | * User: ben 7 | * Date: 9/12/14 8 | * Time: 5:32 PM 9 | */ 10 | class FieldTest extends Specification { 11 | 12 | def "test matchesValueOf"(){ 13 | expect: 14 | assert matches("blah", "blah"); 15 | assert !matches("\\w+", "asdfasdf"); 16 | assert matches("", ""); 17 | assert matches(null, ""); 18 | assert matches("", null); 19 | assert matches(null, null); 20 | assert !matches("asdf", null); 21 | assert !matches(null, "asdf"); 22 | } 23 | 24 | boolean matches(final String expected, final String actual) { 25 | final Field expectedField = new Field(null, expected); 26 | final Field actualField = new Field(null, actual); 27 | return expectedField.matchesValueOf(actualField); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/test/groovy/org/fix4j/test/fixmodel/RegexMatchingFieldTest.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixmodel 2 | 3 | import spock.lang.Specification 4 | 5 | /** 6 | * User: ben 7 | * Date: 22/12/14 8 | * Time: 9:13 AM 9 | */ 10 | class RegexMatchingFieldTest extends Specification { 11 | def "test UnescapeRegexForwardSlashes"() { 12 | expect: 13 | assert RegexMatchingField.unescapeRegexForwardSlashes("\\/asdf\\/") == "/asdf/"; 14 | assert RegexMatchingField.unescapeRegexForwardSlashes("\\/\\/") == "//"; 15 | assert RegexMatchingField.unescapeRegexForwardSlashes("\\/.*\\/") == "/.*/"; 16 | assert RegexMatchingField.unescapeRegexForwardSlashes("asdf\\/asdf\\/") == "asdf\\/asdf\\/"; 17 | assert RegexMatchingField.unescapeRegexForwardSlashes("\\/asdf\\/asdf") == "\\/asdf\\/asdf"; 18 | } 19 | 20 | def "test ContainsRegexForwardSlashes"() { 21 | expect: 22 | assert RegexMatchingField.containsRegexForwardSlashes("/asdf/"); 23 | assert RegexMatchingField.containsRegexForwardSlashes("//"); 24 | assert !RegexMatchingField.containsRegexForwardSlashes("asdf/asdf/"); 25 | assert !RegexMatchingField.containsRegexForwardSlashes("/asdf"); 26 | assert !RegexMatchingField.containsRegexForwardSlashes("asdf/"); 27 | assert !RegexMatchingField.containsRegexForwardSlashes(""); 28 | assert !RegexMatchingField.containsRegexForwardSlashes(null); 29 | } 30 | 31 | def "test ContainsEscapedRegexForwardSlashes"() { 32 | expect: 33 | assert RegexMatchingField.containsEscapedRegexForwardSlashes("\\/asdf\\/"); 34 | assert RegexMatchingField.containsEscapedRegexForwardSlashes("\\/\\/"); 35 | assert !RegexMatchingField.containsEscapedRegexForwardSlashes("asdf\\/asdf\\/"); 36 | assert !RegexMatchingField.containsEscapedRegexForwardSlashes("\\/asdf"); 37 | assert !RegexMatchingField.containsEscapedRegexForwardSlashes("asdf\\/"); 38 | assert !RegexMatchingField.containsEscapedRegexForwardSlashes(""); 39 | assert !RegexMatchingField.containsEscapedRegexForwardSlashes(null); 40 | } 41 | 42 | def "test MatchesValueOf"() { 43 | expect: 44 | assert matches("/.*/", "asdf"); 45 | assert matches("/.*/", ""); 46 | assert !matches("/.+/", ""); 47 | assert !matches("/.*/", null); 48 | assert matches("/\\w+/", "asdf"); 49 | } 50 | 51 | 52 | def "test exception when creating a RegexMatchingField which does not contain forward slashes"() { 53 | when: 54 | new RegexMatchingField(null, "asdf"); 55 | 56 | then: 57 | thrown IllegalArgumentException; 58 | } 59 | 60 | def matches(final String regexExpected, final String actual) { 61 | final Field expectedField = new RegexMatchingField(null, regexExpected); 62 | final Field actualField = new Field(null, actual); 63 | return expectedField.matchesValueOf(actualField); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/test/groovy/org/fix4j/test/fixspec/BaseFieldAndGroupTypesTest.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec 2 | 3 | import spock.lang.Specification 4 | 5 | /** 6 | * User: ben 7 | * Date: 16/01/15 8 | * Time: 6:30 AM 9 | */ 10 | class BaseFieldAndGroupTypesTest extends Specification { 11 | def "ToPrettyString"() { 12 | expect: 13 | ExampleTypes.fieldAndGroupTypes1.toPrettyString() == 14 | "[fieldTypeGroup1Field1]4\n" + 15 | "[fieldTypeGroup1Field2]5\n" + 16 | "[fieldTypeNoOfGroup2]6\n" + 17 | " [fieldTypeGroup2Field1]7\n" + 18 | " [fieldTypeGroup2Field2]8\n"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/test/groovy/org/fix4j/test/fixspec/BaseGroupTypeTest.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec 2 | 3 | import spock.lang.Specification 4 | 5 | /** 6 | * User: ben 7 | * Date: 16/01/15 8 | * Time: 6:15 AM 9 | */ 10 | class BaseGroupTypeTest extends Specification { 11 | def "ToPrettyString"() { 12 | expect: 13 | assert ExampleTypes.group1.toPrettyString() == 14 | "[fieldTypeNoOfGroup1]3\n" + 15 | " [fieldTypeGroup1Field1]4\n" + 16 | " [fieldTypeGroup1Field2]5\n" + 17 | " [fieldTypeNoOfGroup2]6\n" + 18 | " [fieldTypeGroup2Field1]7\n" + 19 | " [fieldTypeGroup2Field2]8\n"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/test/groovy/org/fix4j/test/properties/SystemEnvVariablePropertySourceTest.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.properties 2 | 3 | import spock.lang.Specification 4 | 5 | /** 6 | * User: ben 7 | * Date: 17/12/14 8 | * Time: 11:23 PM 9 | */ 10 | class SystemEnvVariablePropertySourceTest extends Specification { 11 | def "test GetAndFormatRelevantEnvironmentVariables"() { 12 | given: 13 | def map = [FIX4J_BLAH_ONE: "blah", FIX4J_BLAH_TWO: "blah2", FIX4J__three: "blah", FIX_BLAH: "asdf" ]; 14 | 15 | when: 16 | def processed = (new SystemEnvVariablePropertySource()).getAndFormatRelevantEnvironmentVariables(map); 17 | 18 | then: 19 | assert processed == ["fix4j.blah.one": "blah", "fix4j.blah.two": "blah2", "fix4j..three": "blah" ]; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/test/groovy/org/fix4j/test/util/BoundedArrayTest.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util 2 | 3 | import spock.lang.Specification 4 | 5 | /** 6 | * User: ben 7 | * Date: 8/12/14 8 | * Time: 4:56 PM 9 | */ 10 | class BoundedArrayTest extends Specification { 11 | def "Add"() { 12 | when: 13 | BoundedArray array = new BoundedArray<>(3); 14 | array.add("one"); 15 | array.add("two"); 16 | array.add("three"); 17 | array.add("four"); 18 | 19 | then: 20 | def iterator = array.iterator() 21 | assert iterator.next() == "two" 22 | assert iterator.next() == "three" 23 | assert iterator.next() == "four" 24 | 25 | } 26 | 27 | def "AddAll"() { 28 | when: 29 | BoundedArray array = new BoundedArray<>(3); 30 | array.addAll(["one", "two", "three", "four"].iterator()); 31 | 32 | then: 33 | def iterator = array.iterator() 34 | assert iterator.next() == "two" 35 | assert iterator.next() == "three" 36 | assert iterator.next() == "four" 37 | } 38 | 39 | 40 | def "IsEmpty"() { 41 | when: 42 | BoundedArray array = new BoundedArray<>(3); 43 | 44 | then: 45 | assert array.isEmpty() 46 | 47 | when: 48 | array.add("one"); 49 | 50 | then: 51 | assert !array.isEmpty() 52 | 53 | when: 54 | array.add("two"); 55 | 56 | then: 57 | assert !array.isEmpty() 58 | 59 | when: 60 | array.add("three"); 61 | 62 | then: 63 | assert !array.isEmpty() 64 | 65 | when: 66 | array.add("four"); 67 | 68 | then: 69 | assert !array.isEmpty() 70 | } 71 | 72 | def "WasAddedToWhenAtCapacity"() { 73 | when: 74 | BoundedArray array = new BoundedArray<>(3); 75 | 76 | then: 77 | assert !array.wasAddedToWhenAtCapacity() 78 | 79 | when: 80 | array.add("one"); 81 | 82 | then: 83 | assert !array.wasAddedToWhenAtCapacity() 84 | 85 | when: 86 | array.add("two"); 87 | 88 | then: 89 | assert !array.wasAddedToWhenAtCapacity() 90 | 91 | when: 92 | array.add("three"); 93 | 94 | then: 95 | assert !array.wasAddedToWhenAtCapacity() 96 | 97 | when: 98 | array.add("four"); 99 | 100 | then: 101 | assert array.wasAddedToWhenAtCapacity() 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/test/groovy/org/fix4j/test/util/DateUtilsTest.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util 2 | 3 | import spock.lang.Specification 4 | 5 | import java.text.SimpleDateFormat 6 | 7 | /** 8 | * User: ben 9 | * Date: 25/09/2014 10 | * Time: 6:03 AM 11 | */ 12 | class DateUtilsTest extends Specification { 13 | def "test parseTimestampWithLocalTimezone"() { 14 | when: 15 | final Date date = DateUtils.parseTimestamp("20070123-19:01:17"); 16 | 17 | then: 18 | final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HH:mm:ssZ"); 19 | assert dateFormat.format(date) == "20070123-19:01:17" + getCurrentTimezoneOffsetAtDate(date); 20 | } 21 | 22 | public static String getCurrentTimezoneOffsetAtDate(final Date date) { 23 | TimeZone tz = TimeZone.getDefault(); 24 | Calendar cal = GregorianCalendar.getInstance(tz); 25 | double offsetInMillis = tz.getOffset(date.getTime()); 26 | double offsetInMinutes = (offsetInMillis / 60000); 27 | double minutesRemainder = offsetInMinutes % 60.0 28 | 29 | int offsetInHours = Math.abs(offsetInMillis / 3600000.0) 30 | int offsetInMinutesUnderAnHour = Math.abs(minutesRemainder) 31 | 32 | String offset = String.format('%02d%02d', offsetInHours, offsetInMinutesUnderAnHour); 33 | offset = (offsetInMillis >= 0 ? "+" : "-") + offset; 34 | return offset; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /fix4j-assert-core/src/test/groovy/org/fix4j/test/util/PeekableIteratorTest.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.util 2 | 3 | import spock.lang.Specification 4 | 5 | /** 6 | * User: ben 7 | * Date: 3/09/2014 8 | * Time: 6:53 PM 9 | */ 10 | class PeekableIteratorTest extends Specification { 11 | def "simple test"() { 12 | expect: 13 | final PeekableIterator i = new PeekableIterator<>(["one", "two", "three"]); 14 | assert i.hasNext(); 15 | assert i.peek() == "one"; 16 | assert i.peek() == "one"; 17 | assert i.peek() == "one"; 18 | assert i.hasNext(); 19 | assert i.next() == "one"; 20 | assert i.hasNext(); 21 | assert i.next() == "two"; 22 | assert i.hasNext(); 23 | assert i.peek() == "three"; 24 | assert i.hasNext(); 25 | assert i.peek() == "three"; 26 | assert i.hasNext(); 27 | assert i.next() == "three"; 28 | assert !i.hasNext(); 29 | } 30 | 31 | def "test remove"() { 32 | expect: 33 | final PeekableIterator i = new PeekableIterator<>(["one", "two", "three"]); 34 | assert i.hasNext(); 35 | assert i.peek() == "one"; 36 | assert i.peek() == "one"; 37 | assert i.peek() == "one"; 38 | assert i.hasNext(); 39 | i.remove(); 40 | assert i.hasNext(); 41 | assert i.next() == "two"; 42 | assert i.hasNext(); 43 | assert i.peek() == "three"; 44 | assert i.hasNext(); 45 | i.remove(); 46 | assert !i.hasNext(); 47 | } 48 | 49 | def "test next when started full but end up empty"() { 50 | when: 51 | final PeekableIterator i = new PeekableIterator<>(["one", "two", "three"]); 52 | assert i.next() == "one"; 53 | assert i.next() == "two"; 54 | assert i.next() == "three"; 55 | i.next(); 56 | 57 | then: 58 | thrown(NoSuchElementException); 59 | } 60 | 61 | def "test next when started empty"() { 62 | when: 63 | final PeekableIterator i = new PeekableIterator<>([]); 64 | i.next(); 65 | 66 | then: 67 | thrown(NoSuchElementException); 68 | } 69 | 70 | def "test peek when started full but end up empty"() { 71 | when: 72 | final PeekableIterator i = new PeekableIterator<>(["one", "two", "three"]); 73 | assert i.next() == "one"; 74 | assert i.next() == "two"; 75 | assert i.next() == "three"; 76 | i.peek(); 77 | 78 | then: 79 | thrown(NoSuchElementException); 80 | } 81 | 82 | def "test peek when started empty"() { 83 | when: 84 | final PeekableIterator i = new PeekableIterator<>([]); 85 | i.peek(); 86 | 87 | then: 88 | thrown(NoSuchElementException); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /fix4j-assert-examples/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'maven' 3 | 4 | /** 5 | NOTE!: this gradle module does NOT have a parent. 6 | 7 | It is designed to be run after a maven release to central has been done as a way to test the release. 8 | 9 | When running the tests, the fix4j artifacts should be downloaded from the central repo. 10 | **/ 11 | 12 | group = 'org.fix4j' 13 | version = '1.0' 14 | 15 | description = 'Module to test a released version of fix4j-assert' 16 | 17 | sourceCompatibility = 1.7 18 | targetCompatibility = 1.7 19 | tasks.withType(JavaCompile) { 20 | options.encoding = 'UTF-8' 21 | } 22 | 23 | 24 | 25 | repositories { 26 | maven { url "https://oss.sonatype.org/content/repositories/staging/" } 27 | maven { url "http://repo.maven.apache.org/maven2" } 28 | maven { url "http://repo.marketcetera.org/maven" } 29 | } 30 | dependencies { 31 | compile group: 'org.fix4j', name: 'fix4j-assert-core', version:'1.6' 32 | testCompile group: 'org.fix4j', name: 'fix4j-assert-all', version:'1.6' 33 | testCompile group: 'org.fix4j', name: 'fix4j-assert-testcommon', version:'1.6' 34 | } 35 | -------------------------------------------------------------------------------- /fix4j-assert-examples/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/fix4j-assert-examples/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /fix4j-assert-examples/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jan 25 06:30:41 GMT 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /fix4j-assert-examples/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /fix4j-assert-examples/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'fix4j-assert-examples' 2 | -------------------------------------------------------------------------------- /fix4j-assert-examples/src/test/java/org/fix4j/test/examples/clients/MatchingSessionTest.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.examples.clients; 2 | 3 | import org.fix4j.spec.fix50sp2.FieldTypes; 4 | import org.fix4j.spec.fix50sp2.MsgTypes; 5 | import org.fix4j.test.DefaultContextFactory; 6 | import org.fix4j.test.examples.utils.TestServerToPriceAndFillAnOrder; 7 | import org.fix4j.test.fixmodel.FixMessage; 8 | import org.fix4j.test.session.FixConnectionMode; 9 | import org.fix4j.test.session.FixSessionId; 10 | import org.fix4j.test.session.MatchingSession; 11 | import org.fix4j.test.session.TestSessionHelper; 12 | import org.junit.After; 13 | import org.junit.Before; 14 | import org.junit.Test; 15 | 16 | /** 17 | * User: ben 18 | * Date: 13/08/2014 19 | * Time: 8:57 PM 20 | */ 21 | public class MatchingSessionTest { 22 | private TestServerToPriceAndFillAnOrder server; 23 | private MatchingSession client; 24 | 25 | @Before 26 | public void setup(){ 27 | /* 28 | Start the test server - usually if you are testing your own fix application, you wouldn't 29 | need a test server. At this point, you would start your own application that you are 30 | testing. 31 | */ 32 | server = new TestServerToPriceAndFillAnOrder(); 33 | new Thread(server).start(); 34 | } 35 | 36 | @Test 37 | public void testMatchingSession() { 38 | //Set the timeout to wait during a match before throwing an exception 39 | System.setProperty("fix4j.default.fix.msg.wait.timeout.ms", "20000"); 40 | final TestSessionHelper helper = new TestSessionHelper(new DefaultContextFactory()); 41 | 42 | //Create a new session which initiates connection to the server 43 | client = helper.createMatchingSession(new FixSessionId("FIX.4.4", "CLIENT_COMP_ID", "SERVER_COMP_ID"), FixConnectionMode.INITIATOR); 44 | 45 | //Discard all messages until a Logon message is received 46 | client.discardUntil(MsgTypes.Logon); 47 | 48 | //Send a MarketDataRequest 49 | client.send("35=V|262=request123|263=0|264=20|267=2|269=0|269=1|146=1|55=AUD/USD|"); 50 | 51 | //Discard all messages until a MarketDataIncrementalRefresh is received, with a symbol of AUD/USD"); 52 | final FixMessage quote = client.discardUntil(MsgTypes.MarketDataIncrementalRefresh, "55=AUD/USD"); 53 | quote.getField("NoMDEntries[2].MDEntryPx").assertValueEquals(1.12335); 54 | 55 | //Now send an order..."); 56 | client.send("35=D|38=1000|59=1|100=N|40=1|11=ORD10001|60=20070123-19:01:17|55=AUD/USD|54=1|9004=asdf"); 57 | 58 | //Waiting for fill 59 | final FixMessage fill = client.discardUntil(MsgTypes.ExecutionReport); 60 | 61 | //Got fill, finished! (Assert ClientOrderId just because) 62 | fill.getField(FieldTypes.ClOrdID).assertValueEquals("ORD10001"); 63 | } 64 | 65 | @After 66 | public void shutdown(){ 67 | client.shutdown(); 68 | server.shutdown();; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /fix4j-assert-examples/src/test/java/org/fix4j/test/examples/servers/DispatchingSessionsTest.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.examples.servers; 2 | 3 | import org.fix4j.spec.fix50sp2.FieldTypes; 4 | import org.fix4j.spec.fix50sp2.FixSpec; 5 | import org.fix4j.spec.fix50sp2.MsgTypes; 6 | import org.fix4j.test.DefaultContextFactory; 7 | import org.fix4j.test.TestMessages; 8 | import org.fix4j.test.fixmodel.FixMessage; 9 | import org.fix4j.test.fixmodel.Handler; 10 | import org.fix4j.test.properties.PropertyKeysAndDefaultValues; 11 | import org.fix4j.test.session.DispatchingSession; 12 | import org.fix4j.test.session.FixConnectionMode; 13 | import org.fix4j.test.session.FixSessionId; 14 | import org.fix4j.test.session.MatchingSession; 15 | import org.fix4j.test.session.TestSessionHelper; 16 | import org.fix4j.test.util.StringUtils; 17 | import org.junit.After; 18 | import org.junit.Test; 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | 22 | import java.util.HashMap; 23 | import java.util.LinkedHashMap; 24 | 25 | /** 26 | * This example demonstrates the use of a DispatcherSession to dispatch messages using reflection. 27 | * 28 | * A DispatchingSession can be useful if writing a server to use for testing. 29 | * 30 | */ 31 | public class DispatchingSessionsTest implements Handler { 32 | private MatchingSession client; 33 | private DispatchingSession server; 34 | 35 | @Test 36 | public void runTest() { 37 | final TestSessionHelper helper = new TestSessionHelper(new DefaultContextFactory()); 38 | 39 | this.server = helper.createDispatchingSession(new FixSessionId("FIX.4.4", "SERVER_COMP_ID", "CLIENT_COMP_ID"), FixConnectionMode.ACCEPTOR, StringUtils.parseMap("quickfix.socket.accept.port:" + 9880), this); 40 | this.client = helper.createMatchingSession(new FixSessionId("FIX.4.4", "CLIENT_COMP_ID", "SERVER_COMP_ID"), FixConnectionMode.INITIATOR, StringUtils.parseMap("quickfix.socket.connect.port:9880")); 41 | 42 | client.send(TestMessages.MARKET_DATA_REQUEST_1); 43 | client.discardUntil(MsgTypes.MarketDataIncrementalRefresh); 44 | 45 | client.send(TestMessages.NEW_ORDER_SINGLE); 46 | client.discardUntil(MsgTypes.ExecutionReport); 47 | } 48 | 49 | @After 50 | public void tearDown(){ 51 | client.shutdown();; 52 | server.shutdown(); 53 | } 54 | 55 | public void onMarketDataRequest(final FixMessage marketDataRequest){ 56 | System.out.println("Got an MDR, and sending back a price!"); 57 | server.send(TestMessages.MARKET_DATA_INCREMENTAL_REFRESH); 58 | } 59 | 60 | public void onNewOrderSingle(final FixMessage marketDataRequest){ 61 | System.out.println("Got an order!, sending back an execution report!"); 62 | server.send(TestMessages.EXECUTION_REPORT); 63 | } 64 | 65 | public void onLogon(final FixMessage logon){ 66 | //Do nothing 67 | } 68 | 69 | public void onLogout(final FixMessage logout){ 70 | //Do nothing 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /fix4j-assert-examples/src/test/java/org/fix4j/test/examples/utils/TestServerToJustLogIncomingMessages.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.examples.utils; 2 | 3 | import org.fix4j.test.DefaultContextFactory; 4 | import org.fix4j.test.session.BlockingSession; 5 | import org.fix4j.test.session.FixConnectionMode; 6 | import org.fix4j.test.session.FixSessionId; 7 | import org.fix4j.test.session.TestSessionHelper; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | /** 12 | * This server just logs received messages. 13 | */ 14 | public class TestServerToJustLogIncomingMessages implements Runnable { 15 | private final static Logger LOGGER = LoggerFactory.getLogger(TestServerToJustLogIncomingMessages.class); 16 | private boolean stop = false; 17 | 18 | public static void main(String[] args) { 19 | new Thread(new TestServerToJustLogIncomingMessages()).start(); 20 | } 21 | 22 | public void run() { 23 | final TestSessionHelper helper = new TestSessionHelper(new DefaultContextFactory()); 24 | final BlockingSession server = helper.createBlockingSession(new FixSessionId("FIX.4.4", "SERVER_COMP_ID", "CLIENT_COMP_ID"), FixConnectionMode.ACCEPTOR); 25 | while(!stop){ 26 | LOGGER.info(server.getNextMessage().toPrettyString()); 27 | } 28 | LOGGER.info("Shutting down..."); 29 | server.shutdown(); 30 | } 31 | 32 | public void shutdown() { 33 | this.stop = true; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /fix4j-assert-examples/src/test/java/org/fix4j/test/examples/utils/TestServerToPriceAndFillAnOrder.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.examples.utils; 2 | 3 | import org.fix4j.spec.fix50sp2.MsgTypes; 4 | import org.fix4j.test.DefaultContextFactory; 5 | import org.fix4j.test.TestMessages; 6 | import org.fix4j.test.fixmodel.FixMessage; 7 | import org.fix4j.test.properties.PropertyKeysAndDefaultValues; 8 | import org.fix4j.test.session.FixConnectionMode; 9 | import org.fix4j.test.session.FixSessionId; 10 | import org.fix4j.test.session.MatchingSession; 11 | import org.fix4j.test.session.TestSessionHelper; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | /** 16 | * Can be used by a client test to: 17 | * --Receive a MarketDataRequest 18 | * --Respond with a dummy price 19 | * --Receive an order 20 | * --Fill that order. 21 | * 22 | * Only runs through this sequence once. 23 | */ 24 | public class TestServerToPriceAndFillAnOrder implements Runnable { 25 | private final static Logger LOGGER = LoggerFactory.getLogger(TestServerToPriceAndFillAnOrder.class); 26 | private MatchingSession server; 27 | 28 | public static void main(String[] args) { 29 | new Thread(new TestServerToPriceAndFillAnOrder()).start(); 30 | } 31 | 32 | public void run() { 33 | System.setProperty(PropertyKeysAndDefaultValues.DEFAULT_FIX_MSG_WAIT_TIMEOUT_MS.getKey(), "20000"); 34 | final TestSessionHelper helper = new TestSessionHelper(new DefaultContextFactory()); 35 | server = helper.createMatchingSession(new FixSessionId("FIX.4.4", "SERVER_COMP_ID", "CLIENT_COMP_ID"), FixConnectionMode.ACCEPTOR); 36 | 37 | LOGGER.info("Waiting for MarketDataRequest..."); 38 | final FixMessage marketDataRequest = server.discardUntil(MsgTypes.MarketDataRequest); 39 | 40 | LOGGER.info("Got MDR: " + marketDataRequest.toPrettyString()); 41 | LOGGER.info("Sending back price."); 42 | 43 | server.send(TestMessages.MARKET_DATA_INCREMENTAL_REFRESH); 44 | 45 | LOGGER.info("Sent price, waiting for order..."); 46 | final FixMessage newOrder = server.discardUntil(MsgTypes.NewOrderSingle); 47 | 48 | LOGGER.info("Got order: " + newOrder.toPrettyString() + "\nSending fill..."); 49 | server.send("35=8|55=CVS|37=ORD10001/03232009|11=ORD10001|17=12345678|150=3|39=2|150=2|54=1|38=1000|40=1|59=1|31=1.12355|32=1000|14=0|6=0|151=0|60=20070123-19:01:17|58=Fill|30=N|207=N|63=0|"); 50 | } 51 | 52 | 53 | public void shutdown() { 54 | server.shutdown(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /fix4j-assert-examples/src/test/resources/foo.properties: -------------------------------------------------------------------------------- 1 | fix4j.default.fix.msg.wait.timeout.ms=33333 2 | fix4j.quickfix.reconnect.interval=33 3 | -------------------------------------------------------------------------------- /fix4j-assert-fixspec-50sp2/build.gradle: -------------------------------------------------------------------------------- 1 | description = '' 2 | 3 | 4 | sourceSets { 5 | main { 6 | java { 7 | srcDir 'src/generated/java' 8 | } 9 | } 10 | codegen { 11 | java { 12 | srcDir 'src/codegen/java' 13 | } 14 | resources { 15 | srcDir 'src/codegen/resources' 16 | } 17 | } 18 | } 19 | 20 | task genMain( type: JavaExec ) { 21 | main = 'org.fix4j.spec.codegen.SpecParser' 22 | classpath = sourceSets.codegen.runtimeClasspath 23 | args = ['/FIX50SP2.xml', 'org.fix4j.spec.fix50sp2'] 24 | final File javaWorkingDir = new File("${projectDir}/src/generated/java/org/fix4j/spec/fix50sp2/") 25 | javaWorkingDir.mkdirs() 26 | workingDir = javaWorkingDir.absolutePath 27 | } 28 | 29 | clean.doFirst { 30 | delete "${projectDir}/src/generated" 31 | } 32 | 33 | dependencies { 34 | compile project(':fix4j-assert-core') 35 | codegenCompile project(':fix4j-assert-codegen') 36 | } 37 | 38 | compileJava.dependsOn(genMain) 39 | -------------------------------------------------------------------------------- /fix4j-assert-integration/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | description = '' 3 | dependencies { 4 | compile project(':fix4j-assert-core') 5 | compile project(':fix4j-assert-fixspec-50sp2') 6 | compile project(':fix4j-assert-testcommon') 7 | } 8 | -------------------------------------------------------------------------------- /fix4j-assert-integration/src/test/groovy/org/fix4j/test/expression/MatcherParserTest.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.expression 2 | 3 | import org.fix4j.test.fixspec.FixSpecification 4 | import org.fix4j.spec.fix50sp2.FixSpec 5 | import spock.lang.Specification 6 | 7 | /** 8 | * User: ben 9 | * Date: 2/09/2014 10 | * Time: 5:03 PM 11 | */ 12 | class MatcherParserTest extends Specification { 13 | private FixSpecification fixSpecification = FixSpec.INSTANCE; 14 | private FlexibleMessageExpressionParser parser = new FlexibleMessageExpressionParser(fixSpecification); 15 | 16 | def testParseByFieldNumbersAndParseByFieldNamesAreEqual() { 17 | expect: 18 | final MessageExpression messageExpressionParsedByFieldNumber = parser.parse("8=FIX.4.2|9=130|35=D|34=659|49=BROKER04|56=REUTERS|52=20070123-19:09:43|38=1000|59=1|100=N|40=1|11=ORD10001|60=20070123-19:01:17|55=HPQ|54=1|21=2|10=004"); 19 | final MessageExpression messageExpressionParsedByFieldName = parser.parse("BeginString=FIX.4.2|BodyLength=130|MsgType=D|MsgSeqNum=659|SenderCompID=BROKER04|TargetCompID=REUTERS|SendingTime=20070123-19:09:43|OrderQty=1000|TimeInForce=1|ExDestination=N|OrdType=1|ClOrdID=ORD10001|TransactTime=20070123-19:01:17|Symbol=HPQ|Side=1|HandlInst=2|CheckSum=004|"); 20 | assert messageExpressionParsedByFieldNumber.equals(messageExpressionParsedByFieldName); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /fix4j-assert-integration/src/test/groovy/org/fix4j/test/expression/MessageExpressionMatcherTest.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.expression 2 | 3 | import org.fix4j.spec.fix50sp2.FixSpec 4 | import org.fix4j.test.TestMessages 5 | import org.fix4j.test.fixmodel.FixMessage 6 | import spock.lang.Specification 7 | 8 | /** 9 | * User: ben 10 | * Date: 22/12/14 11 | * Time: 8:39 AM 12 | */ 13 | class MessageExpressionMatcherTest extends Specification { 14 | def "test message type"(){ 15 | when: 16 | final FixMessage fixMessage = FixSpec.INSTANCE.parse(TestMessages.NEW_ORDER_SINGLE); 17 | 18 | then: 19 | assert matches("35=D", fixMessage) 20 | assert !matches("35=A", fixMessage) 21 | assert !matches("35=.*", fixMessage) //This should not match. Without the forward slashes, the .* is treated as literal text 22 | assert matches("35=/.*/", fixMessage) //This SHOULD match, because of the surrounding forward slashes, the .* is treated as a regex. 23 | } 24 | 25 | protected boolean matches(String matchingExpression, FixMessage fixMessage) { 26 | MessageExpression expression = new FlexibleMessageExpressionParser(FixSpec.INSTANCE).parse(matchingExpression); 27 | return expression.getMatchResult(fixMessage).matches(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /fix4j-assert-integration/src/test/groovy/org/fix4j/test/fixspec/BaseFieldAndGroupTypesTest.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec 2 | 3 | import org.fix4j.spec.fix50sp2.FieldTypes 4 | import org.fix4j.spec.fix50sp2.MsgTypes 5 | import spock.lang.Specification 6 | 7 | /** 8 | * User: ben 9 | * Date: 1/11/2014 10 | * Time: 6:09 AM 11 | */ 12 | class BaseFieldAndGroupTypesTest extends Specification { 13 | def "test GetAllGroupTypesRecursively"() { 14 | when: 15 | final MsgType msgType = MsgTypes.MarketDataIncrementalRefresh; 16 | 17 | then: 18 | final Set groupTypes = msgType.getAllGroupTypesRecursively(); 19 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoComplexEventDates); 20 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoComplexEventTimes); 21 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoComplexEvents); 22 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoEvents); 23 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoInstrumentParties); 24 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoInstrumentPartySubIDs); 25 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoLegSecurityAltID); 26 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoLegs); 27 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoMDEntries); 28 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoOfSecSizes); 29 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoPartyIDs); 30 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoPartySubIDs); 31 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoRateSources); 32 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoRoutingIDs); 33 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoSecurityAltID); 34 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoStatsIndicators); 35 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoUnderlyingSecurityAltID); 36 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoUnderlyingStips); 37 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoUnderlyings); 38 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoUndlyInstrumentParties); 39 | containsGroupTypeWithNoOfField(groupTypes, FieldTypes.NoUndlyInstrumentPartySubIDs); 40 | } 41 | 42 | private boolean containsGroupTypeWithNoOfField(final Set groupTypes, final FieldType fieldType) { 43 | for (final GroupType groupType : groupTypes) { 44 | if(groupType.getNoOfFieldType().equals(fieldType)){ 45 | return true; 46 | } 47 | } 48 | return false; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /fix4j-assert-integration/src/test/groovy/org/fix4j/test/fixspec/MessageExampleGeneratorTest.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.fixspec 2 | 3 | import org.fix4j.test.fixmodel.FixMessage 4 | import org.fix4j.spec.fix50sp2.FixSpec 5 | import org.fix4j.spec.fix50sp2.MsgTypes 6 | import org.slf4j.Logger 7 | import org.slf4j.LoggerFactory 8 | import spock.lang.Specification 9 | 10 | /** 11 | * User: ben 12 | * Date: 30/10/2014 13 | * Time: 6:12 AM 14 | */ 15 | class MessageExampleGeneratorTest extends Specification { 16 | private final static Logger LOGGER = LoggerFactory.getLogger(MessageExampleGeneratorTest.class); 17 | 18 | def "test generateExampleMessage"() { 19 | expect: 20 | final FixMessage message = MsgTypes.ExecutionReport.generateExampleMessage(FixSpec.INSTANCE); 21 | LOGGER.info message.toPrettyString(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /fix4j-assert-integration/src/test/groovy/org/fix4j/test/messageflags/MissingRequiredFieldMessageFlagRuleTest.groovy: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.messageflags 2 | 3 | import org.fix4j.test.fixmodel.BaseFixMessage 4 | import org.fix4j.test.fixspec.FixSpecification 5 | import org.fix4j.spec.fix50sp2.FixSpec 6 | import spock.lang.Specification 7 | 8 | /** 9 | * User: ben 10 | * Date: 14/11/2014 11 | * Time: 6:00 AM 12 | */ 13 | class MissingRequiredFieldMessageFlagRuleTest extends Specification { 14 | 15 | public void "test GetMessageFlags - Nothing missing"() { 16 | given: 17 | final String msg = 18 | "[MsgType]35=V[MARKETDATAREQUEST]|" + 19 | "[MDReqID]262=AASDJKG790|" + 20 | "[SubscriptionRequestType]263=0[SNAPSHOT]|" + 21 | "[MarketDepth]264=20|" + 22 | "[NoMDEntryTypes]267=2|" + 23 | "[MDEntryType]269=0[BID]|" + 24 | "[MDEntryType]269=1[OFFER]|" + 25 | "[NoRelatedSym]146=3|" + 26 | "[Symbol]55=GBP/USD|" + 27 | "[SettlDate]64=SP|" + 28 | "[Symbol]55=AUD/USD|" + 29 | "[SettlDate]64=1W|" + 30 | "[Symbol]55=USD/JPY|" + 31 | "[SettlDate]64=1W"; 32 | 33 | final FixSpecification spec = FixSpec.INSTANCE 34 | BaseFixMessage fixMessage = spec.parse(msg) 35 | final MissingRequiredFieldMessageFlagRule rule = new MissingRequiredFieldMessageFlagRule(); 36 | 37 | expect: 38 | assert rule.isTriggered(fixMessage); 39 | assert rule.getMessageFlags(fixMessage).getReportAsString() == ""; 40 | } 41 | 42 | public void "test GetMessageFlags - MarketDepth and NoRelatedSym group missing"() { 43 | given: 44 | final String msg = 45 | "[MsgType]35=V[MARKETDATAREQUEST]|" + 46 | "[MDReqID]262=AASDJKG790|" + 47 | "[SubscriptionRequestType]263=0[SNAPSHOT]|" + 48 | "[NoMDEntryTypes]267=2|" + 49 | "[MDEntryType]269=0[BID]|" + 50 | "[MDEntryType]269=1[OFFER]"; 51 | 52 | final FixSpecification spec = FixSpec.INSTANCE 53 | BaseFixMessage fixMessage = spec.parse(msg) 54 | 55 | when: 56 | final MissingRequiredFieldMessageFlagRule rule = new MissingRequiredFieldMessageFlagRule(); 57 | 58 | then: 59 | assert rule.isTriggered(fixMessage); 60 | assert rule.getMessageFlags(fixMessage).getReportAsString() == 61 | "[MsgType]35=V[MARKETDATAREQUEST]|[MDReqID]262=AASDJKG790|[SubscriptionRequestType]263=0[SNAPSHOT]|[NoMDEntryTypes]267=2|[MDEntryType]269=0[BID]|[MDEntryType]269=1[OFFER]\n" + 62 | " 1. Required field not found: [MarketDepth]264\n" + 63 | " 2. Required group not found: [NoRelatedSym]146\n"; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /fix4j-assert-quickfix/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | description = '' 3 | dependencies { 4 | compile project(':fix4j-assert-core') 5 | compile group: 'org.apache.servicemix.bundles', name: 'org.apache.servicemix.bundles.quickfix', version:'1.5.3_1' 6 | compile group: 'org.apache.mina', name: 'mina-core', version:'1.1.0' 7 | testCompile project(':fix4j-assert-fixspec-50sp2') 8 | testCompile project(':fix4j-assert-testcommon') 9 | } 10 | -------------------------------------------------------------------------------- /fix4j-assert-quickfix/src/main/java/org/fix4j/test/integration/quickfix/QuickFixProperties.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.integration.quickfix; 2 | 3 | import org.fix4j.test.util.Keyable; 4 | 5 | /** 6 | * User: ben 7 | * Date: 17/12/14 8 | * Time: 5:02 PM 9 | */ 10 | public enum QuickFixProperties implements Keyable { 11 | SOCKET_CONNECT_HOST("fix4j.quickfix.socket.connect.host"), 12 | START_TIME("fix4j.quickfix.start.time"), 13 | END_TIME("fix4j.quickfix.end.time"), 14 | HEART_BEAT_INTERVAL("fix4j.quickfix.heart.beat.interval"), 15 | RECONNECT_INTERVAL("fix4j.quickfix.reconnect.interval"), 16 | USE_DATA_DICTIONARY("fix4j.quickfix.use.data.dictionary"), 17 | SOCKET_CONNECT_PORT("fix4j.quickfix.socket.connect.port"), 18 | SOCKET_ACCEPT_PORT("fix4j.quickfix.socket.accept.port"), 19 | LOG_HEARTBEATS("fix4j.quickfix.log.heartbeats"), 20 | ALLOW_UNKNOWN_MSG_FIELDS("fix4j.quickfix.allow.unknown.msg.fields"), 21 | VALIDATE_FIELDS_OUT_OF_ORDER("fix4j.quickfix.validate.fields.out.of.order"), 22 | VALIDATE_FIELDS_HAVE_VALUES("fix4j.quickfix.validate.fields.have.values"), 23 | VALIDATE_USER_DEFINED_FIELDS("fix4j.quickfix.validate.user.defined.fields"); 24 | 25 | private final String key; 26 | 27 | QuickFixProperties(final String key){ 28 | this.key = key; 29 | } 30 | 31 | public String getKey() { 32 | return key; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /fix4j-assert-quickfix/src/main/java/org/fix4j/test/integration/quickfix/QuickFixSessionIdConverter.java: -------------------------------------------------------------------------------- 1 | package org.fix4j.test.integration.quickfix; 2 | 3 | import org.fix4j.test.integration.FixSessionIdConverter; 4 | import org.fix4j.test.session.FixSessionId; 5 | import quickfix.SessionID; 6 | 7 | /** 8 | * User: ben 9 | * Date: 20/08/2014 10 | * Time: 5:50 AM 11 | */ 12 | public class QuickFixSessionIdConverter implements FixSessionIdConverter { 13 | @Override 14 | public FixSessionId toFixSessionId(final SessionID sessionId) { 15 | return new FixSessionId(sessionId.getBeginString(), sessionId.getSenderCompID(), sessionId.getTargetCompID()); 16 | } 17 | 18 | @Override 19 | public SessionID fromFixSessionId(final FixSessionId fixSessionId) { 20 | return new SessionID(fixSessionId.getBeginString(), fixSessionId.getSenderCompId(), fixSessionId.getTargetCompId()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /fix4j-assert-testcommon/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | description = '' 3 | dependencies { 4 | compile(group: 'junit', name: 'junit', version:'4.11') { 5 | exclude(module: 'hamcrest-core') 6 | } 7 | compile group: 'org.codehaus.groovy', name: 'groovy-all', version:'2.3.8' 8 | compile group: 'org.apache.maven.surefire', name: 'surefire-junit4', version:'2.17' 9 | compile(group: 'org.spockframework', name: 'spock-maven', version:'0.7-groovy-2.0') { 10 | exclude(module: 'surefire-junit47') 11 | } 12 | testCompile group: 'org.hamcrest', name: 'hamcrest-core', version:'1.3' 13 | testCompile group: 'org.hamcrest', name: 'hamcrest-library', version:'1.3' 14 | testCompile(group: 'org.mockito', name: 'mockito-core', version:'2.0.31-beta') { 15 | exclude(module: 'hamcrest-core') 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /fix4j-assert-testcommon/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, stdout 3 | 4 | # Direct log messages to stdout 5 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 6 | log4j.appender.stdout.Target=System.out 7 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jan 25 06:41:06 GMT 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /resources/21dd4eee1c8b6e2318124f5e2b4836.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/21dd4eee1c8b6e2318124f5e2b4836.gif -------------------------------------------------------------------------------- /resources/27f0f25e146ee91d9c18b1ce5b9177.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/27f0f25e146ee91d9c18b1ce5b9177.gif -------------------------------------------------------------------------------- /resources/3ef573e56e86dbcb636c873ee72c7b.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/3ef573e56e86dbcb636c873ee72c7b.gif -------------------------------------------------------------------------------- /resources/584253c733399f0bdf89fd6788828e.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/584253c733399f0bdf89fd6788828e.gif -------------------------------------------------------------------------------- /resources/61099ab32b9bd7a4b9afa39a552ae723.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/61099ab32b9bd7a4b9afa39a552ae723.png -------------------------------------------------------------------------------- /resources/620aa92ec747a7e9dd5b76aabea55f.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/620aa92ec747a7e9dd5b76aabea55f.gif -------------------------------------------------------------------------------- /resources/6856420882_017d7cfd5b_o.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/6856420882_017d7cfd5b_o.jpg -------------------------------------------------------------------------------- /resources/7002530447_06208c6b6f_o.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/7002530447_06208c6b6f_o.jpg -------------------------------------------------------------------------------- /resources/7956f338891f3d3280044d8f4ad57b.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/7956f338891f3d3280044d8f4ad57b.gif -------------------------------------------------------------------------------- /resources/GitHub-Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/GitHub-Logo.png -------------------------------------------------------------------------------- /resources/c0253b51f6e7e723f93035cad2c837.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/c0253b51f6e7e723f93035cad2c837.gif -------------------------------------------------------------------------------- /resources/cd2d5acc4fc1854069e754cf0d1f77.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/cd2d5acc4fc1854069e754cf0d1f77.gif -------------------------------------------------------------------------------- /resources/e29050824ed2a1d92a2a10eceda040.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/e29050824ed2a1d92a2a10eceda040.gif -------------------------------------------------------------------------------- /resources/f290c34b1268e94a01b5d1c28b3158.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/f290c34b1268e94a01b5d1c28b3158.gif -------------------------------------------------------------------------------- /resources/github-logo-white-on-black.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/github-logo-white-on-black.jpg -------------------------------------------------------------------------------- /resources/github-logo-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/github-logo-white.png -------------------------------------------------------------------------------- /resources/github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/github.png -------------------------------------------------------------------------------- /resources/jpeg_905.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/jpeg_905.jpg -------------------------------------------------------------------------------- /resources/right-cerulean@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tools4j/fix4j-assert/fbae1acfd61312a824eb9791acb365839f02b640/resources/right-cerulean@2x.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'fix4j-assert' 2 | include ':fix4j-assert-core' 3 | include ':fix4j-assert-quickfix' 4 | include ':fix4j-assert-acceptance' 5 | include ':fix4j-assert-codegen' 6 | include ':fix4j-assert-fixspec-50sp2' 7 | include ':fix4j-assert-all' 8 | include ':fix4j-assert-testcommon' 9 | include ':fix4j-assert-integration' 10 | 11 | project(':fix4j-assert-core').projectDir = "$rootDir/fix4j-assert-core" as File 12 | project(':fix4j-assert-quickfix').projectDir = "$rootDir/fix4j-assert-quickfix" as File 13 | project(':fix4j-assert-acceptance').projectDir = "$rootDir/fix4j-assert-acceptance" as File 14 | project(':fix4j-assert-codegen').projectDir = "$rootDir/fix4j-assert-codegen" as File 15 | project(':fix4j-assert-fixspec-50sp2').projectDir = "$rootDir/fix4j-assert-fixspec-50sp2" as File 16 | project(':fix4j-assert-all').projectDir = "$rootDir/fix4j-assert-all" as File 17 | project(':fix4j-assert-testcommon').projectDir = "$rootDir/fix4j-assert-testcommon" as File 18 | project(':fix4j-assert-integration').projectDir = "$rootDir/fix4j-assert-integration" as File --------------------------------------------------------------------------------