public void testValidationWithNestedGroupAndStandardFieldsFIX50SP2()
      throws InvalidMessage, ConfigError {
    final quickfix.fix50.QuoteRequest quoteRequest = new quickfix.fix50.QuoteRequest();

    final quickfix.field.QuoteReqID gQuoteReqID = new quickfix.field.QuoteReqID();
    gQuoteReqID.setValue("12342");
    quoteRequest.setField(gQuoteReqID);

    final quickfix.fix50.QuoteRequest.NoRelatedSym gNoRelatedSym =
        buildNestedGroupWithStandardFieldsFIX50("DEFAULT_VALUE");
    gNoRelatedSym.setField(new Symbol("SYM00"));
    gNoRelatedSym.setField(new SettlDate2("20120801"));

    quoteRequest.addGroup(gNoRelatedSym);

    quoteRequest.addGroup(gNoRelatedSym);

    final String sourceFIXString = quoteRequest.toString();
    final DataDictionary fix50DataDictionary = new DataDictionary("FIX50SP2.xml");
    final quickfix.fix50.QuoteRequest validatedMessage =
        (quickfix.fix50.QuoteRequest) buildValidatedMessage(sourceFIXString, fix50DataDictionary);
    String validateFIXString = null;
    if (validatedMessage != null) {
      validateFIXString = validatedMessage.toString();
    }

    assertEquals("Message validation failed", sourceFIXString, validateFIXString);
    assertEquals(2, validatedMessage.getGroupCount(gNoRelatedSym.getFieldTag()));
  }
  public void testValidationWithNestedGroupAndStandardFields() throws InvalidMessage {
    final quickfix.fix44.QuoteRequest quoteRequest = new quickfix.fix44.QuoteRequest();

    final quickfix.field.QuoteReqID gQuoteReqID = new quickfix.field.QuoteReqID();
    gQuoteReqID.setValue("12342");
    quoteRequest.setField(gQuoteReqID);

    final quickfix.fix44.QuoteRequest.NoRelatedSym gNoRelatedSym =
        buildNestedGroupWithStandardFields("DEFAULT_VALUE");
    gNoRelatedSym.setField(new Symbol("SYM00"));

    quoteRequest.addGroup(gNoRelatedSym);

    quoteRequest.addGroup(gNoRelatedSym);

    final String sourceFIXString = quoteRequest.toString();

    final quickfix.fix44.QuoteRequest validatedMessage =
        (quickfix.fix44.QuoteRequest) buildValidatedMessage(sourceFIXString, defaultDataDictionary);
    String validateFIXString = null;
    if (validatedMessage != null) {
      validateFIXString = validatedMessage.toString();
    }

    assertEquals("Message validation failed", sourceFIXString, validateFIXString);
  }
  public void testGroupFieldsOrderWithCustomDataDictionary() throws InvalidMessage {
    final quickfix.fix44.QuoteRequest quoteRequest = new quickfix.fix44.QuoteRequest();

    final quickfix.field.QuoteReqID gQuoteReqID = new quickfix.field.QuoteReqID();
    gQuoteReqID.setValue("12342");
    quoteRequest.setField(gQuoteReqID);

    // The root group
    final quickfix.fix44.QuoteRequest.NoRelatedSym gNoRelatedSym =
        new quickfix.fix44.QuoteRequest.NoRelatedSym();
    gNoRelatedSym.setField(new Symbol("SYM00"));

    // The nested group
    final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs nestedgroup =
        new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs();
    nestedgroup.setField(new LegSymbol("DEFAULT_VALUE"));
    nestedgroup.setField(new OrderID("111")); // The non ordered field
    nestedgroup.setField(new StringField(9001, "1.9001")); // The custom non ordered field
    gNoRelatedSym.addGroup(nestedgroup);

    // Adding a second fake nested group to avoid being the case of having
    // one element which is not relevant :-)
    final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs oneMoreNestedgroup =
        new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs();
    oneMoreNestedgroup.setField(new LegSymbol("Donald"));
    oneMoreNestedgroup.setField(new OrderID("112")); // The non ordered field
    oneMoreNestedgroup.setField(new StringField(9001, "2.9001")); // The custom non ordered field
    gNoRelatedSym.addGroup(oneMoreNestedgroup);

    quoteRequest.addGroup(gNoRelatedSym);

    final String sourceFIXString = quoteRequest.toString();
    final quickfix.fix44.QuoteRequest validatedMessage =
        (quickfix.fix44.QuoteRequest) buildValidatedMessage(sourceFIXString, customDataDictionary);

    assertNull("Invalid message", validatedMessage.getException());

    String validatedFIXString = null;
    if (validatedMessage != null) {
      validatedFIXString = validatedMessage.toString();
    }

    assertEquals(
        "Message validation failed", checkSum(sourceFIXString), checkSum(validatedFIXString));
  }
  public void testValidationWithNestedGroupAndStandardFieldsWithoutDelimiter() {
    final quickfix.fix44.QuoteRequest quoteRequest = new quickfix.fix44.QuoteRequest();

    final quickfix.field.QuoteReqID gQuoteReqID = new quickfix.field.QuoteReqID();
    gQuoteReqID.setValue("12342");
    quoteRequest.setField(gQuoteReqID);

    final quickfix.fix44.QuoteRequest.NoRelatedSym gNoRelatedSym =
        buildNestedGroupWithStandardFields("DEFAULT_VALUE");

    quoteRequest.addGroup(gNoRelatedSym);

    quoteRequest.addGroup(gNoRelatedSym);

    final String sourceFIXString = quoteRequest.toString();

    try {
      buildValidatedMessage(sourceFIXString, defaultDataDictionary);
      fail("No Exception thrown");
    } catch (final InvalidMessage e) {
      // We expect that Exception did happen, so we don't do anything.
    }
  }