/** * Obtains an instance of the parser, based on the specified selector. * <p> * The FpML parser has a number of plugin points that can be controlled: * <ul> * <li>the {@linkplain FpmlPartySelector party selector} * <li>the {@linkplain FpmlTradeInfoParserPlugin trade info parser} * <li>the {@linkplain FpmlParserPlugin trade parsers} * <li>the {@linkplain ReferenceData reference data} * </ul> * This method uses the {@linkplain FpmlTradeInfoParserPlugin#standard() standard} * trade info parser, the trade parsers registered in {@link FpmlParserPlugin} * configuration and the {@linkplain ReferenceData#standard() standard} reference data. * * @param ourPartySelector the selector used to find "our" party within the set of parties in the FpML document * @return the document parser */ public static FpmlDocumentParser of(FpmlPartySelector ourPartySelector) { return of(ourPartySelector, FpmlTradeInfoParserPlugin.standard()); }
public void documentTenor() { XmlElement tradeDateEl = XmlElement.ofContent("tradeDate", "2000-06-30"); XmlElement tradeHeaderEl = XmlElement.ofChildren("tradeHeader", ImmutableList.of(tradeDateEl)); XmlElement tradeEl = XmlElement.ofChildren("trade", ImmutableMap.of("href", "foo"), ImmutableList.of(tradeHeaderEl)); XmlElement rootEl = XmlElement.ofChildren("dataDocument", ImmutableList.of(tradeEl)); FpmlDocument test = new FpmlDocument(rootEl, ImmutableMap.of(), FpmlPartySelector.any(), FpmlTradeInfoParserPlugin.standard(), REF_DATA); assertEquals(test.convertIndexTenor("1", "M"), Tenor.TENOR_1M); assertEquals(test.convertIndexTenor("12", "M"), Tenor.TENOR_12M); assertEquals(test.convertIndexTenor("1", "Y"), Tenor.TENOR_12M); assertEquals(test.convertIndexTenor("13", "Y"), Tenor.of(Period.ofYears(13))); }
public void documentFrequency() { XmlElement tradeDateEl = XmlElement.ofContent("tradeDate", "2000-06-30"); XmlElement tradeHeaderEl = XmlElement.ofChildren("tradeHeader", ImmutableList.of(tradeDateEl)); XmlElement tradeEl = XmlElement.ofChildren("trade", ImmutableMap.of("href", "foo"), ImmutableList.of(tradeHeaderEl)); XmlElement rootEl = XmlElement.ofChildren("dataDocument", ImmutableList.of(tradeEl)); FpmlDocument test = new FpmlDocument(rootEl, ImmutableMap.of(), FpmlPartySelector.any(), FpmlTradeInfoParserPlugin.standard(), REF_DATA); assertEquals(test.convertFrequency("1", "M"), Frequency.P1M); assertEquals(test.convertFrequency("12", "M"), Frequency.P12M); assertEquals(test.convertFrequency("1", "Y"), Frequency.P12M); assertEquals(test.convertFrequency("13", "Y"), Frequency.of(Period.ofYears(13))); }
public void document() { XmlElement tradeDateEl = XmlElement.ofContent("tradeDate", "2000-06-30"); XmlElement tradeHeaderEl = XmlElement.ofChildren("tradeHeader", ImmutableList.of(tradeDateEl)); XmlElement tradeEl = XmlElement.ofChildren("trade", ImmutableMap.of("href", "foo"), ImmutableList.of(tradeHeaderEl)); XmlElement rootEl = XmlElement.ofChildren("dataDocument", ImmutableList.of(tradeEl)); FpmlDocument test = new FpmlDocument(rootEl, ImmutableMap.of(), FpmlPartySelector.any(), FpmlTradeInfoParserPlugin.standard(), REF_DATA); assertEquals(test.getFpmlRoot(), rootEl); assertEquals(test.getParties(), ImmutableListMultimap.of()); assertEquals(test.getReferences(), ImmutableMap.of()); assertEquals(test.getOurPartyHrefIds(), ImmutableList.of()); assertThrows(() -> test.lookupReference(tradeEl), FpmlParseException.class, ".*reference not found.*"); assertThrows(() -> test.validateNotPresent(tradeEl, "tradeHeader"), FpmlParseException.class, ".*tradeHeader.*"); }
public void badTradeDate() { XmlElement tradeDateEl = XmlElement.ofContent("tradeDate", "2000/06/30"); XmlElement tradeHeaderEl = XmlElement.ofChildren("tradeHeader", ImmutableList.of(tradeDateEl)); XmlElement tradeTypeEl = XmlElement.ofContent("foo", "fakeTradeType"); XmlElement tradeEl = XmlElement.ofChildren("trade", ImmutableList.of(tradeHeaderEl, tradeTypeEl)); XmlElement rootEl = XmlElement.ofChildren("dataDocument", ImmutableList.of(tradeEl)); FpmlParserPlugin tradeParser = new FpmlParserPlugin() { @Override public Trade parseTrade(FpmlDocument document, XmlElement tradeEl) { document.parseTradeInfo(tradeEl); // expected to throw an exception throw new UnsupportedOperationException(); } @Override public String getName() { return "foo"; } }; FpmlDocumentParser parser = FpmlDocumentParser.of(FpmlPartySelector.any(), FpmlTradeInfoParserPlugin.standard(), ImmutableMap.of("foo", tradeParser)); assertThrows( () -> parser.parseTrades(rootEl, ImmutableMap.of()), DateTimeParseException.class, ".*2000/06/30.*"); }