Search in sources :

Example 1 with ClientFilter

use of name.abuchen.portfolio.snapshot.filter.ClientFilter in project portfolio by buchen.

the class GroupByTaxonomyTest method testThatAccountsAreClassifiedCorrectlyWhenFiltered.

@Test
public void testThatAccountsAreClassifiedCorrectlyWhenFiltered() {
    // bug report:
    // https://forum.portfolio-performance.info/t/vermoegensaufstellung-klassifizierung-mit-filter/1129
    Client client = new Client();
    Taxonomy taxonomy = // 
    new TaxonomyBuilder().addClassification(// 
    "debt").addTo(client);
    Security a = // 
    new SecurityBuilder().addPrice("2010-01-01", // 
    Values.Quote.factorize(10)).assign(taxonomy, "debt", // 
    Classification.ONE_HUNDRED_PERCENT).addTo(client);
    Account account = // 
    new AccountBuilder().deposit_("2010-01-01", Values.Amount.factorize(100)).assign(taxonomy, "debt", // 
    Classification.ONE_HUNDRED_PERCENT).addTo(client);
    // 
    new PortfolioBuilder(account).inbound_delivery(a, "2010-01-01", Values.Share.factorize(10), // 
    10000).addTo(client);
    ClientFilter filter = new ClientClassificationFilter(taxonomy.getClassificationById("debt"));
    LocalDate date = LocalDate.parse("2010-01-01");
    ClientSnapshot snapshot = ClientSnapshot.create(filter.filter(client), new TestCurrencyConverter(), date);
    assertNotNull(snapshot);
    GroupByTaxonomy grouping = snapshot.groupByTaxonomy(taxonomy);
    // everything is classified
    assertThat(grouping.asList().size(), is(1));
    // two positions in 'debt' category
    AssetCategory debt = grouping.byClassification(taxonomy.getClassificationById("debt"));
    assertThat(debt.getValuation(), is(Money.of(CurrencyUnit.EUR, Values.Money.factorize(200))));
    assertThat(debt.getPositions().size(), is(2));
    // nothing in unassigned
    AssetCategory unassigned = null;
    for (AssetCategory category : grouping.asList()) if (category.getClassification().getId().equals(Classification.UNASSIGNED_ID))
        unassigned = category;
    assertThat(unassigned, nullValue());
}
Also used : Account(name.abuchen.portfolio.model.Account) Taxonomy(name.abuchen.portfolio.model.Taxonomy) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Security(name.abuchen.portfolio.model.Security) LocalDate(java.time.LocalDate) TaxonomyBuilder(name.abuchen.portfolio.TaxonomyBuilder) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) ClientFilter(name.abuchen.portfolio.snapshot.filter.ClientFilter) AccountBuilder(name.abuchen.portfolio.AccountBuilder) Client(name.abuchen.portfolio.model.Client) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Test(org.junit.Test)

Aggregations

LocalDate (java.time.LocalDate)1 AccountBuilder (name.abuchen.portfolio.AccountBuilder)1 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)1 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)1 TaxonomyBuilder (name.abuchen.portfolio.TaxonomyBuilder)1 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)1 Account (name.abuchen.portfolio.model.Account)1 Client (name.abuchen.portfolio.model.Client)1 Security (name.abuchen.portfolio.model.Security)1 Taxonomy (name.abuchen.portfolio.model.Taxonomy)1 ClientClassificationFilter (name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter)1 ClientFilter (name.abuchen.portfolio.snapshot.filter.ClientFilter)1 Test (org.junit.Test)1