Search in sources :

Example 46 with AccountTransaction

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

the class CrossEntryCheckTest method testMissingAccountTransferInIssue.

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

Example 47 with AccountTransaction

use of name.abuchen.portfolio.model.AccountTransaction 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 48 with AccountTransaction

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

the class CrossEntryCheckTest method testThatAccountTransactionsWithoutSecurity.

@Test
public void testThatAccountTransactionsWithoutSecurity() {
    Portfolio second = new Portfolio();
    client.addPortfolio(second);
    account.addTransaction(new AccountTransaction(LocalDateTime.now(), CurrencyUnit.EUR, 1, null, AccountTransaction.Type.BUY));
    List<Issue> issues = new CrossEntryCheck().execute(client);
    assertThat(issues.size(), is(1));
    assertThat(issues.get(0).getAvailableFixes().get(0), is(instanceOf(DeleteTransactionFix.class)));
    applyFixes(client, issues);
    ClientSnapshot.create(client, new TestCurrencyConverter(), LocalDate.now());
}
Also used : Issue(name.abuchen.portfolio.checks.Issue) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Portfolio(name.abuchen.portfolio.model.Portfolio) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Test(org.junit.Test)

Example 49 with AccountTransaction

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

the class CrossEntryCheckTest method testMissingAccountTransferOutIssue.

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

Example 50 with AccountTransaction

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

the class IBFlexStatementExtractorTest method testIBAcitvityStatement.

@Test
public void testIBAcitvityStatement() throws IOException {
    InputStream activityStatement = getClass().getResourceAsStream("IBActivityStatement.xml");
    Client client = new Client();
    IBFlexStatementExtractor extractor = new IBFlexStatementExtractor(client);
    Extractor.InputFile tempFile = createTempFile(activityStatement);
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(Collections.singletonList(tempFile), errors);
    results.stream().filter(i -> !(i instanceof SecurityItem)).forEach(i -> assertThat(i.getAmount(), notNullValue()));
    assertThat(results.size(), is(29));
    assertFirstSecurity(results.stream().filter(i -> i instanceof SecurityItem).findFirst());
    assertFirstTransaction(results.stream().filter(i -> i instanceof BuySellEntryItem).findFirst());
    assertSecondSecurity(results.stream().filter(i -> i instanceof SecurityItem).reduce((previous, current) -> current).get());
    assertFourthTransaction(results.stream().filter(i -> i instanceof BuySellEntryItem).skip(3).findFirst());
    assertInterestCharge(results.stream().filter(i -> i instanceof TransactionItem).filter(i -> i.getSubject() instanceof AccountTransaction && ((AccountTransaction) i.getSubject()).getType() == Type.INTEREST_CHARGE).findFirst());
    assertTax(results.stream().filter(i -> i instanceof TransactionItem).filter(i -> i.getSubject() instanceof AccountTransaction && ((AccountTransaction) i.getSubject()).getType() == Type.TAXES).findFirst());
    assertFee(results.stream().filter(i -> i instanceof TransactionItem).filter(i -> i.getSubject() instanceof AccountTransaction && ((AccountTransaction) i.getSubject()).getType() == Type.FEES).skip(2).findFirst());
    assertFeeRefund(results.stream().filter(i -> i instanceof TransactionItem).filter(i -> i.getSubject() instanceof AccountTransaction && ((AccountTransaction) i.getSubject()).getType() == Type.FEES_REFUND).findFirst());
// TODO Check CorporateActions
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Type(name.abuchen.portfolio.model.AccountTransaction.Type) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) Quote(name.abuchen.portfolio.money.Quote) Item(name.abuchen.portfolio.datatransfer.Extractor.Item) LocalDateTime(java.time.LocalDateTime) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) ArrayList(java.util.ArrayList) IOUtils(org.apache.pdfbox.io.IOUtils) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) File(java.io.File) List(java.util.List) Unit(name.abuchen.portfolio.model.Transaction.Unit) Optional(java.util.Optional) Collections(java.util.Collections) InputStream(java.io.InputStream) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) 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) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Aggregations

AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)218 Client (name.abuchen.portfolio.model.Client)169 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)152 Money (name.abuchen.portfolio.money.Money)148 IOException (java.io.IOException)141 Unit (name.abuchen.portfolio.model.Transaction.Unit)135 Test (org.junit.Test)133 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)131 Security (name.abuchen.portfolio.model.Security)129 ArrayList (java.util.ArrayList)125 Values (name.abuchen.portfolio.money.Values)117 List (java.util.List)110 LocalDateTime (java.time.LocalDateTime)109 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)103 CoreMatchers.is (org.hamcrest.CoreMatchers.is)102 Assert.assertThat (org.junit.Assert.assertThat)102 Item (name.abuchen.portfolio.datatransfer.Extractor.Item)99 SecurityItem (name.abuchen.portfolio.datatransfer.Extractor.SecurityItem)99 TransactionItem (name.abuchen.portfolio.datatransfer.Extractor.TransactionItem)99 Optional (java.util.Optional)87