Search in sources :

Example 56 with Portfolio

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

the class CheckCurrenciesPortfolioTransactionTest method testTransactionCurrencyMatchesSecurity.

@Test
public void testTransactionCurrencyMatchesSecurity() {
    Portfolio portfolio = new Portfolio();
    Security security = new Security("", "EUR");
    PortfolioTransaction t = new PortfolioTransaction();
    t.setType(Type.DELIVERY_INBOUND);
    t.setMonetaryAmount(Money.of("EUR", 1_00));
    t.setSecurity(security);
    assertThat(action.process(t, portfolio).getCode(), is(Status.Code.OK));
    security.setCurrencyCode("USD");
    assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security) Test(org.junit.Test)

Example 57 with Portfolio

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

the class CheckCurrenciesPortfolioTransactionTest method testTransactionForexTaxesAndFeesIfCurrenciesMatch.

@Test
public void testTransactionForexTaxesAndFeesIfCurrenciesMatch() {
    Portfolio portfolio = new Portfolio();
    Security security = new Security("", "EUR");
    Unit tax = new Unit(Unit.Type.TAX, Money.of("EUR", 5_00), Money.of("USD", 10_00), BigDecimal.valueOf(0.5));
    PortfolioTransaction t = new PortfolioTransaction();
    t.setType(Type.DELIVERY_OUTBOUND);
    t.setMonetaryAmount(Money.of("EUR", 20_00));
    t.setSecurity(security);
    t.addUnit(tax);
    assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security) Unit(name.abuchen.portfolio.model.Transaction.Unit) Test(org.junit.Test)

Example 58 with Portfolio

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

the class InsertActionTest method testConversionOfBuySellEntry.

@Test
public void testConversionOfBuySellEntry() {
    Account account = client.getAccounts().get(0);
    Portfolio portfolio = client.getPortfolios().get(0);
    InsertAction action = new InsertAction(client);
    action.setConvertBuySellToDelivery(true);
    action.process(entry, account, portfolio);
    assertThat(account.getTransactions().isEmpty(), is(true));
    assertThat(portfolio.getTransactions().size(), is(1));
    PortfolioTransaction delivery = portfolio.getTransactions().get(0);
    assertThat(delivery.getType(), is(Type.DELIVERY_INBOUND));
    assertTransaction(delivery);
}
Also used : Account(name.abuchen.portfolio.model.Account) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) Test(org.junit.Test)

Example 59 with Portfolio

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

the class InsertActionTest method testInsertOfBuySellEntry.

@Test
public void testInsertOfBuySellEntry() {
    Account account = client.getAccounts().get(0);
    Portfolio portfolio = client.getPortfolios().get(0);
    InsertAction action = new InsertAction(client);
    action.process(entry, account, portfolio);
    assertThat(account.getTransactions().size(), is(1));
    assertThat(portfolio.getTransactions().size(), is(1));
    PortfolioTransaction t = portfolio.getTransactions().get(0);
    assertThat(t.getType(), is(Type.BUY));
    assertTransaction(t);
}
Also used : Account(name.abuchen.portfolio.model.Account) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) Test(org.junit.Test)

Example 60 with Portfolio

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

the class InsertActionTest method prepare.

@Before
public void prepare() {
    client = new Client();
    Security security = new Security();
    client.addSecurity(security);
    Portfolio portfolio = new Portfolio();
    client.addPortfolio(portfolio);
    Account account = new Account();
    client.addAccount(account);
    entry = new BuySellEntry();
    entry.setType(Type.BUY);
    entry.setMonetaryAmount(Money.of(CurrencyUnit.EUR, 9_99));
    entry.setShares(99);
    entry.setDate(transactionDate);
    entry.setSecurity(security);
    entry.setNote("note");
    entry.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(CurrencyUnit.EUR, 1_99)));
}
Also used : Account(name.abuchen.portfolio.model.Account) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Portfolio(name.abuchen.portfolio.model.Portfolio) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit) Before(org.junit.Before)

Aggregations

Portfolio (name.abuchen.portfolio.model.Portfolio)75 Security (name.abuchen.portfolio.model.Security)52 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)44 Test (org.junit.Test)41 Account (name.abuchen.portfolio.model.Account)39 Client (name.abuchen.portfolio.model.Client)38 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)24 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)21 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)20 Unit (name.abuchen.portfolio.model.Transaction.Unit)19 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)17 LocalDate (java.time.LocalDate)16 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)12 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)11 Money (name.abuchen.portfolio.money.Money)11 ArrayList (java.util.ArrayList)10 Values (name.abuchen.portfolio.money.Values)10 AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)9 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)9 Collections (java.util.Collections)8