Search in sources :

Example 16 with PortfolioTransaction

use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.

the class CSVPortfolioTransactionExtractorTest method testBuyTransaction.

@Test
public void testBuyTransaction() throws ParseException {
    Client client = new Client();
    Security security = new Security();
    security.setTickerSymbol("SAP.DE");
    client.addSecurity(security);
    CSVExtractor extractor = new CSVPortfolioTransactionExtractor(client);
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(0, Arrays.<String[]>asList(new String[] { "2013-01-02", "DE0007164600", "SAP.DE", "", "SAP SE", "100", "EUR", "11", "", "", "", "", "1,9", "BUY", "Notiz" }), buildField2Column(extractor), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(1));
    new AssertImportActions().check(results, CurrencyUnit.EUR);
    BuySellEntry entry = (BuySellEntry) results.stream().filter(i -> i instanceof BuySellEntryItem).findAny().get().getSubject();
    PortfolioTransaction t = entry.getPortfolioTransaction();
    assertThat(t.getType(), is(PortfolioTransaction.Type.BUY));
    assertThat(t.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 100_00)));
    assertThat(t.getNote(), is("Notiz"));
    assertThat(t.getDateTime(), is(LocalDateTime.parse("2013-01-02T00:00")));
    assertThat(t.getShares(), is(Values.Share.factorize(1.9)));
    assertThat(t.getSecurity(), is(security));
    assertThat(t.getUnitSum(Unit.Type.FEE), is(Money.of("EUR", 11_00)));
    assertThat(t.getUnit(Unit.Type.TAX).isPresent(), is(false));
    AccountTransaction at = entry.getAccountTransaction();
    assertThat(at.getType(), is(AccountTransaction.Type.BUY));
    assertThat(at.getUnitSum(Unit.Type.FEE), is(Money.of("EUR", 0)));
}
Also used : BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) ParseException(java.text.ParseException) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) PortfolioTransferItem(name.abuchen.portfolio.datatransfer.Extractor.PortfolioTransferItem) Item(name.abuchen.portfolio.datatransfer.Extractor.Item) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 17 with PortfolioTransaction

use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.

the class CrossEntryCheckTest method testThatAlmostMatchingBuySellEntriesAreNotMatched.

@Test
public void testThatAlmostMatchingBuySellEntriesAreNotMatched() {
    LocalDateTime date = LocalDateTime.now();
    portfolio.addTransaction(new PortfolioTransaction(date, CurrencyUnit.EUR, 1, security, 1, PortfolioTransaction.Type.SELL, 1, 0));
    account.addTransaction(new AccountTransaction(date, CurrencyUnit.EUR, 2, security, AccountTransaction.Type.SELL));
    List<Issue> issues = new CrossEntryCheck().execute(client);
    assertThat(issues.size(), is(2));
    List<Object> objects = new ArrayList<Object>(issues);
    assertThat(objects, hasItem(instanceOf(MissingBuySellAccountIssue.class)));
    assertThat(objects, hasItem(instanceOf(MissingBuySellPortfolioIssue.class)));
    applyFixes(client, issues);
}
Also used : LocalDateTime(java.time.LocalDateTime) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Issue(name.abuchen.portfolio.checks.Issue) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Test(org.junit.Test)

Example 18 with PortfolioTransaction

use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.

the class CrossEntryCheckTest method testMissingPortfolioTransferInIssue.

@Test
public void testMissingPortfolioTransferInIssue() {
    portfolio.addTransaction(new PortfolioTransaction(LocalDateTime.now(), CurrencyUnit.EUR, 1, security, 1, PortfolioTransaction.Type.TRANSFER_OUT, 1, 0));
    List<Issue> issues = new CrossEntryCheck().execute(client);
    assertThat(issues.size(), is(1));
    assertThat(issues.get(0), is(instanceOf(MissingPortfolioTransferIssue.class)));
    assertThat(issues.get(0).getEntity(), is((Object) portfolio));
    applyFixes(client, issues);
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Issue(name.abuchen.portfolio.checks.Issue) Test(org.junit.Test)

Example 19 with PortfolioTransaction

use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.

the class CrossEntryCheckTest method testThatNotTheSamePortfolioIsMatched.

@Test
public void testThatNotTheSamePortfolioIsMatched() {
    Portfolio second = new Portfolio();
    client.addPortfolio(second);
    LocalDateTime date = LocalDateTime.now();
    portfolio.addTransaction(new PortfolioTransaction(date, CurrencyUnit.EUR, 3, security, 1, PortfolioTransaction.Type.TRANSFER_IN, 1, 0));
    PortfolioTransaction umatched = new PortfolioTransaction(date, CurrencyUnit.EUR, 3, security, 1, PortfolioTransaction.Type.TRANSFER_OUT, 1, 0);
    portfolio.addTransaction(umatched);
    second.addTransaction(new PortfolioTransaction(date, CurrencyUnit.EUR, 3, security, 1, PortfolioTransaction.Type.TRANSFER_OUT, 1, 0));
    List<Issue> issues = new CrossEntryCheck().execute(client);
    assertThat(issues.size(), is(1));
    assertThat(issues.get(0), is(instanceOf(MissingPortfolioTransferIssue.class)));
    assertThat(portfolio.getTransactions(), hasItem(umatched));
    assertThat(second.getTransactions().get(0).getCrossEntry(), notNullValue());
    assertThat(second.getTransactions().get(0).getType(), is(PortfolioTransaction.Type.TRANSFER_OUT));
    applyFixes(client, issues);
}
Also used : LocalDateTime(java.time.LocalDateTime) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Issue(name.abuchen.portfolio.checks.Issue) Portfolio(name.abuchen.portfolio.model.Portfolio) Test(org.junit.Test)

Example 20 with PortfolioTransaction

use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.

the class CrossEntryCheckTest method testMissingPortfolioTransferOutIssue.

@Test
public void testMissingPortfolioTransferOutIssue() {
    portfolio.addTransaction(new PortfolioTransaction(LocalDateTime.now(), CurrencyUnit.EUR, 1, security, 1, PortfolioTransaction.Type.TRANSFER_IN, 1, 0));
    List<Issue> issues = new CrossEntryCheck().execute(client);
    assertThat(issues.size(), is(1));
    assertThat(issues.get(0), is(instanceOf(MissingPortfolioTransferIssue.class)));
    assertThat(issues.get(0).getEntity(), is((Object) portfolio));
    applyFixes(client, issues);
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Issue(name.abuchen.portfolio.checks.Issue) Test(org.junit.Test)

Aggregations

PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)131 Security (name.abuchen.portfolio.model.Security)85 Test (org.junit.Test)84 Client (name.abuchen.portfolio.model.Client)70 ArrayList (java.util.ArrayList)64 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)64 Unit (name.abuchen.portfolio.model.Transaction.Unit)56 Money (name.abuchen.portfolio.money.Money)56 IOException (java.io.IOException)47 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)44 List (java.util.List)43 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)42 Values (name.abuchen.portfolio.money.Values)41 LocalDateTime (java.time.LocalDateTime)39 Portfolio (name.abuchen.portfolio.model.Portfolio)39 CoreMatchers.is (org.hamcrest.CoreMatchers.is)35 Assert.assertThat (org.junit.Assert.assertThat)35 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)33 Collectors (java.util.stream.Collectors)30 BuySellEntryItem (name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem)28