public static Object getComponentGroup(final Object stub, final int numberOfElements) throws Exception { return get(stub, "componentGroupGroup", numberOfElements); }
@Test public void decodesBadEnumValuesAsSentinelsUsingAsEnumMethods() throws Exception { final Decoder decoder = (Decoder)enumTestMessage.getConstructor().newInstance(); decode(ET_ONLY_REQ_FIELDS_WITH_BAD_VALUES, decoder); assertEquals(ENUM_UNKNOWN_CHAR, getRepresentation(get(decoder, CHAR_ENUM_REQ + "AsEnum"))); assertEquals(ENUM_UNKNOWN_INT, getRepresentation(get(decoder, INT_ENUM_REQ + "AsEnum"))); assertEquals(ENUM_UNKNOWN_STRING, getRepresentation(get(decoder, STRING_ENUM_REQ + "AsEnum"))); assertInvalid(decoder); }
@Test public void decodesMissingOptionalEnumValuesAsSentinelsUsingAsEnumMethods() throws Exception { final Decoder decoder = (Decoder)enumTestMessage.getConstructor().newInstance(); decode(ET_ONLY_REQ_FIELDS, decoder); assertEquals(ENUM_MISSING_CHAR, getRepresentation(get(decoder, CHAR_ENUM_OPT + "AsEnum"))); assertEquals(ENUM_MISSING_INT, getRepresentation(get(decoder, INT_ENUM_OPT + "AsEnum"))); assertEquals(ENUM_MISSING_STRING, getRepresentation(get(decoder, STRING_ENUM_OPT + "AsEnum"))); assertValid(decoder); }
public static Object getRepresentation(final Object object) throws Exception { return get(object, "representation"); }
@Test public void decodesMissingRequiredEnumFieldUsingAsEnumMethod() throws Exception { final Decoder decoder = (Decoder)enumTestMessage.getConstructor().newInstance(); decode(ET_MISSING_REQ_FIELD, decoder); assertEquals(UNKNOWN_NAME, get(decoder, STRING_ENUM_REQ + "AsEnum").toString()); assertEquals(ENUM_UNKNOWN_STRING, getRepresentation(get(decoder, STRING_ENUM_REQ + "AsEnum"))); assertInvalid(decoder); }
private int getGroupField(final Object group) throws Exception { return (int)get(group, "groupField"); }
@Test public void shouldBeAbleToExtractEnumFromStringFields() throws Exception { final Decoder decoder = decodeHeartbeat(NO_OPTIONAL_MESSAGE); final Object onBehalfEnum = get(decoder, "onBehalfOfCompIDAsEnum"); assertEquals("abc", getRepresentation(onBehalfEnum)); }
public static Iterable<?> getEgGroupIterable(final Decoder decoder) throws Exception { return (Iterable<?>)get(decoder, "egGroupGroupIterator"); }
public static Object getNestedGroup(final Object group, final int numberOfElements) throws Exception { return get(group, "nestedGroupGroup", numberOfElements); }
public static byte[] getBytes(final Decoder decoder, final String field) throws Exception { return (byte[])get(decoder, field); }
public static char[] getChars(final Decoder decoder, final String field) throws Exception { return (char[])get(decoder, field); }
private Object getMethod(final Object decoder, final String fieldName) throws Throwable { final char[] chars = fieldName.toCharArray(); chars[0] = Character.toLowerCase(chars[0]); return get(decoder, new String(chars)); }
@Test(expected = InvocationTargetException.class) public void missingOptionalFieldCausesGetterToThrow() throws Exception { final Object decoder = heartbeat.getConstructor().newInstance(); Reflection.get(decoder, TEST_REQ_ID); }
private void setupTrailer(final Encoder encoder, final String signature) throws Exception { final Object trailer = Reflection.get(encoder, "trailer"); if (signature.length() > 0) { setByteArray(trailer, "signature", signature.getBytes(StandardCharsets.US_ASCII)); setInt(trailer, "signatureLength", signature.length()); } setCharSequence(trailer, "checkSum", "12"); }
@Test public void shouldSkipUnknownFieldInRepeatingGroupAndPassValidation() throws Exception { final Decoder decoder = decodeHeartbeat(REPEATING_GROUP_WITH_UNKNOWN_FIELD); assertTrue("Failed validation with missing fields", decoder.validate()); Object group = get(decoder, "secondEgGroupGroup"); assertEquals("TOM", get(group, "secondGroupFieldAsString")); assertEquals(180, get(group, "thirdGroupField")); group = next(group); assertEquals("Barbara", get(group, "secondGroupFieldAsString")); assertEquals(123, get(group, "thirdGroupField")); }
@Test public void shouldSkipFieldUnknownToMessageButDefinedInFIXSpec() throws Exception { final Decoder decoder = decodeHeartbeat(REPEATING_GROUP_WITH_FIELD_UNKNOWN_TO_MESSAGE_BUT_IN_SPEC); assertTrue("Failed validation with missing fields", decoder.validate()); Object group = get(decoder, "secondEgGroupGroup"); assertEquals("TOM", get(group, "secondGroupFieldAsString")); assertEquals(180, get(group, "thirdGroupField")); group = next(group); assertEquals("Barbara", get(group, "secondGroupFieldAsString")); assertEquals(123, get(group, "thirdGroupField")); }
private void setupHeader(final Encoder encoder, final String beginString) throws Exception { final Object header = Reflection.get(encoder, "header"); setCharSequence(header, "beginString", beginString); setCharSequence(header, MSG_TYPE, "0"); }
@Test public void shouldDecodeComponents() throws Exception { final Decoder decoder = decodeHeartbeat(COMPONENT_MESSAGE); assertEquals(2, get(decoder, "componentField")); assertValid(decoder); }