public void test_addWithOnePremiumTrade_add() {
LocalDate tradeDate = _now.toLocalDate();
OffsetTime tradeTime = _now.toOffsetTime().minusSeconds(500);
ManageablePosition position = new ManageablePosition(BigDecimal.TEN, ExternalId.of("A", "B"));
ManageableTrade trade = new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "B"), tradeDate, tradeTime, ExternalId.of("CPS", "CPV"));
trade.setPremium(1000000.00);
trade.setPremiumCurrency(Currency.USD);
trade.setPremiumDate(tradeDate.plusDays(1));
trade.setPremiumTime(tradeTime);
position.getTrades().add(trade);
PositionDocument doc = new PositionDocument();
doc.setPosition(position);
PositionDocument test = _posMaster.add(doc);
Instant now = Instant.now(_posMaster.getClock());
UniqueId uniqueId = test.getUniqueId();
assertNotNull(uniqueId);
assertEquals("DbPos", uniqueId.getScheme());
assertTrue(uniqueId.isVersioned());
assertTrue(Long.parseLong(uniqueId.getValue()) >= 1000);
assertEquals("0", uniqueId.getVersion());
assertEquals(now, test.getVersionFromInstant());
assertEquals(null, test.getVersionToInstant());
assertEquals(now, test.getCorrectionFromInstant());
assertEquals(null, test.getCorrectionToInstant());
ManageablePosition testPosition = test.getPosition();
assertNotNull(testPosition);
assertEquals(uniqueId, testPosition.getUniqueId());
assertEquals(BigDecimal.TEN, testPosition.getQuantity());
ExternalIdBundle secKey = testPosition.getSecurityLink().getExternalId();
assertEquals(1, secKey.size());
assertTrue(secKey.getExternalIds().contains(ExternalId.of("A", "B")));
assertNotNull(testPosition.getTrades());
assertEquals(1, testPosition.getTrades().size());
ManageableTrade testTrade = testPosition.getTrades().get(0);
assertNotNull(testTrade);
assertEquals(BigDecimal.TEN, testTrade.getQuantity());
assertEquals(tradeDate, testTrade.getTradeDate());
assertEquals(tradeTime, testTrade.getTradeTime());
assertEquals(ExternalId.of("CPS", "CPV"), testTrade.getCounterpartyExternalId());