TradeAttributeExposureFunction implements ExposureFunction { @Override public List<ExternalId> getIds(Trade trade) { ImmutableList.Builder<ExternalId> builder = ImmutableList.builder(); for (Map.Entry<String, String> entry: trade.getAttributes().entrySet()) { builder.add(ExternalId.of(TRADE_ATTRIBUTE_IDENTIFIER, entry.getKey() + "=" + entry.getValue())); } return builder.build(); }  @Override String getName(); @Override List<ExternalId> getIds(Trade trade); static final String NAME; static final String TRADE_ATTRIBUTE_IDENTIFIER; }
@Test public void testSingleAttribute() { FRASecurity security = ExposureFunctionTestHelper.getFRASecurity(); Trade trade = ExposureFunctionTestHelper.getTrade(security); Map<String, String> attributes = new HashMap<>(); String key = "Attribute1"; String value = "Value1"; attributes.put(key, value); trade.setAttributes(attributes); List<ExternalId> ids = EXPOSURE_FUNCTION.getIds(trade); assertEquals("Expected one ExternalId", 1, ids.size()); assertEquals("Expected trade attribute with key " + key + ", value " + value, ExternalId.of(TradeAttributeExposureFunction.TRADE_ATTRIBUTE_IDENTIFIER, key + "=" + value), ids.get(0)); }
@Test public void testMultipleAttributes() { FRASecurity security = ExposureFunctionTestHelper.getFRASecurity(); Trade trade = ExposureFunctionTestHelper.getTrade(security); Map<String, String> attributes = new HashMap<>(); String key1 = "Attribute1"; String value1 = "Value1"; attributes.put(key1, value1); String key2 = "Attribute2"; String value2 = "Value2"; attributes.put(key2, value2); trade.setAttributes(attributes); List<ExternalId> ids = EXPOSURE_FUNCTION.getIds(trade); assertEquals("Expected two ExternalIds", 2, ids.size()); assertTrue("Expected trade attribute with key " + key1 + ", value " + value1, ids.contains(ExternalId.of(TradeAttributeExposureFunction.TRADE_ATTRIBUTE_IDENTIFIER, key1 + "=" + value1))); assertTrue("Expected trade attribute with key " + key2 + ", value " + value2, ids.contains(ExternalId.of(TradeAttributeExposureFunction.TRADE_ATTRIBUTE_IDENTIFIER, key2 + "=" + value2))); }