Search in sources :

Example 1 with LoanDescriptor

use of com.github.robozonky.api.strategies.LoanDescriptor in project robozonky by RoboZonky.

the class JmxListenerServiceTest method getParametersForInvestmentRejected.

private DynamicTest getParametersForInvestmentRejected() {
    final Loan l = mockLoan();
    final LoanDescriptor ld = new LoanDescriptor(l);
    final RecommendedLoan r = ld.recommend(200).get();
    final Event evt = new InvestmentRejectedEvent(r, "");
    final Consumer<SoftAssertions> before = (softly) -> {
        final OperationsMBean mbean = getOperationsMBean();
        softly.assertThat(mbean.getRejectedInvestments()).isEmpty();
    };
    final Consumer<SoftAssertions> after = (softly) -> {
        final OperationsMBean mbean = getOperationsMBean();
        softly.assertThat(mbean.getRejectedInvestments()).containsOnlyKeys(l.getId());
        softly.assertThat(mbean.getLatestUpdatedDateTime()).isEqualTo(evt.getCreatedOn());
    };
    return getParameters(evt, before, after);
}
Also used : RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) ExecutionCompletedEvent(com.github.robozonky.api.notifications.ExecutionCompletedEvent) SoftAssertions(org.assertj.core.api.SoftAssertions) TestFactory(org.junit.jupiter.api.TestFactory) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) AfterAll(org.junit.jupiter.api.AfterAll) BigDecimal(java.math.BigDecimal) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) BeforeAll(org.junit.jupiter.api.BeforeAll) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) PurchasingStartedEvent(com.github.robozonky.api.notifications.PurchasingStartedEvent) Lifecycle(com.github.robozonky.app.runtime.Lifecycle) Assertions(org.assertj.core.api.Assertions) ShutdownHook(com.github.robozonky.app.ShutdownHook) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) EventListenerSupplier(com.github.robozonky.api.notifications.EventListenerSupplier) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) PurchasingCompletedEvent(com.github.robozonky.api.notifications.PurchasingCompletedEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) Event(com.github.robozonky.api.notifications.Event) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) Stream(java.util.stream.Stream) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) EventListener(com.github.robozonky.api.notifications.EventListener) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) DynamicTest(org.junit.jupiter.api.DynamicTest) Optional(java.util.Optional) ReturnCode(com.github.robozonky.api.ReturnCode) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) RoboZonkyEndingEvent(com.github.robozonky.api.notifications.RoboZonkyEndingEvent) AbstractRoboZonkyTest(com.github.robozonky.test.AbstractRoboZonkyTest) Collections(java.util.Collections) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) SoftAssertions(org.assertj.core.api.SoftAssertions) ExecutionCompletedEvent(com.github.robozonky.api.notifications.ExecutionCompletedEvent) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) PurchasingStartedEvent(com.github.robozonky.api.notifications.PurchasingStartedEvent) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) PurchasingCompletedEvent(com.github.robozonky.api.notifications.PurchasingCompletedEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) Event(com.github.robozonky.api.notifications.Event) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) RoboZonkyEndingEvent(com.github.robozonky.api.notifications.RoboZonkyEndingEvent) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent)

Example 2 with LoanDescriptor

use of com.github.robozonky.api.strategies.LoanDescriptor in project robozonky by RoboZonky.

the class JmxListenerServiceTest method getParametersForInvestmentDelegated.

private DynamicTest getParametersForInvestmentDelegated() {
    final Loan l = mockLoan();
    final LoanDescriptor ld = new LoanDescriptor(l);
    final RecommendedLoan r = ld.recommend(200).get();
    final Event evt = new InvestmentDelegatedEvent(r, "");
    final Consumer<SoftAssertions> before = (softly) -> {
        final OperationsMBean mbean = getOperationsMBean();
        softly.assertThat(mbean.getDelegatedInvestments()).isEmpty();
    };
    final Consumer<SoftAssertions> after = (softly) -> {
        final OperationsMBean mbean = getOperationsMBean();
        softly.assertThat(mbean.getDelegatedInvestments()).containsOnlyKeys(l.getId());
        softly.assertThat(mbean.getLatestUpdatedDateTime()).isEqualTo(evt.getCreatedOn());
    };
    return getParameters(evt, before, after);
}
Also used : RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) ExecutionCompletedEvent(com.github.robozonky.api.notifications.ExecutionCompletedEvent) SoftAssertions(org.assertj.core.api.SoftAssertions) TestFactory(org.junit.jupiter.api.TestFactory) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) AfterAll(org.junit.jupiter.api.AfterAll) BigDecimal(java.math.BigDecimal) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) BeforeAll(org.junit.jupiter.api.BeforeAll) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) PurchasingStartedEvent(com.github.robozonky.api.notifications.PurchasingStartedEvent) Lifecycle(com.github.robozonky.app.runtime.Lifecycle) Assertions(org.assertj.core.api.Assertions) ShutdownHook(com.github.robozonky.app.ShutdownHook) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) EventListenerSupplier(com.github.robozonky.api.notifications.EventListenerSupplier) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) PurchasingCompletedEvent(com.github.robozonky.api.notifications.PurchasingCompletedEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) Event(com.github.robozonky.api.notifications.Event) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) Stream(java.util.stream.Stream) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) EventListener(com.github.robozonky.api.notifications.EventListener) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) DynamicTest(org.junit.jupiter.api.DynamicTest) Optional(java.util.Optional) ReturnCode(com.github.robozonky.api.ReturnCode) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) RoboZonkyEndingEvent(com.github.robozonky.api.notifications.RoboZonkyEndingEvent) AbstractRoboZonkyTest(com.github.robozonky.test.AbstractRoboZonkyTest) Collections(java.util.Collections) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) SoftAssertions(org.assertj.core.api.SoftAssertions) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) ExecutionCompletedEvent(com.github.robozonky.api.notifications.ExecutionCompletedEvent) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) PurchasingStartedEvent(com.github.robozonky.api.notifications.PurchasingStartedEvent) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) PurchasingCompletedEvent(com.github.robozonky.api.notifications.PurchasingCompletedEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) Event(com.github.robozonky.api.notifications.Event) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) RoboZonkyEndingEvent(com.github.robozonky.api.notifications.RoboZonkyEndingEvent) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor)

Example 3 with LoanDescriptor

use of com.github.robozonky.api.strategies.LoanDescriptor in project robozonky by RoboZonky.

the class InvestingTest method noneAccepted.

@Test
void noneAccepted() {
    // new ID every time to avoid caches
    final int loanId = (int) (Math.random() * 1000);
    final Loan loan = Loan.custom().setId(loanId).setAmount(100_000).setRating(Rating.D).setMyInvestment(mockMyInvestment()).setDatePublished(OffsetDateTime.now()).build();
    final LoanDescriptor ld = new LoanDescriptor(loan);
    final Investor.Builder builder = new Investor.Builder().asDryRun();
    final Zonky z = harmlessZonky(9000);
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    when(z.getLoan(eq(loanId))).thenReturn(loan);
    final Authenticated auth = mockAuthentication(z);
    final Investing exec = new Investing(builder, NONE_ACCEPTING, auth);
    assertThat(exec.apply(portfolio, Collections.singleton(ld))).isEmpty();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 4 with LoanDescriptor

use of com.github.robozonky.api.strategies.LoanDescriptor in project robozonky by RoboZonky.

the class InvestingTest method noStrategy.

@Test
void noStrategy() {
    // new ID every time to avoid caches
    final int loanId = (int) (Math.random() * 1000);
    final Loan loan = Loan.custom().setId(loanId).setAmount(2).build();
    final LoanDescriptor ld = new LoanDescriptor(loan);
    final Investing exec = new Investing(null, Optional::empty, null);
    final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(1000);
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    assertThat(exec.apply(portfolio, Collections.singletonList(ld))).isEmpty();
    // check events
    final List<Event> events = this.getNewEvents();
    assertThat(events).isEmpty();
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Optional(java.util.Optional) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Event(com.github.robozonky.api.notifications.Event) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 5 with LoanDescriptor

use of com.github.robozonky.api.strategies.LoanDescriptor in project robozonky by RoboZonky.

the class InvestingTest method someAccepted.

@Test
void someAccepted() {
    // new ID every time to avoid caches
    final int loanId = (int) (Math.random() * 1000);
    final Loan loan = Loan.custom().setId(loanId).setAmount(100_000).setRating(Rating.D).setRemainingInvestment(20_000).setDatePublished(OffsetDateTime.now()).build();
    final LoanDescriptor ld = new LoanDescriptor(loan);
    final Investor.Builder builder = new Investor.Builder().asDryRun();
    final Zonky z = harmlessZonky(10_000);
    when(z.getLoan(eq(loanId))).thenReturn(loan);
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final Authenticated auth = mockAuthentication(z);
    final Investing exec = new Investing(builder, ALL_ACCEPTING, auth);
    final Collection<Investment> result = exec.apply(portfolio, Collections.singleton(ld));
    // dry run
    verify(z, never()).invest(any());
    assertThat(result).extracting(Investment::getLoanId).isEqualTo(Collections.singletonList(loanId));
    // re-check; no balance changed, no marketplace changed, nothing should happen
    assertThat(exec.apply(portfolio, Collections.singleton(ld))).isEmpty();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Zonky(com.github.robozonky.common.remote.Zonky) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Aggregations

LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)34 Test (org.junit.jupiter.api.Test)29 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)17 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)15 Portfolio (com.github.robozonky.app.portfolio.Portfolio)15 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)13 Zonky (com.github.robozonky.common.remote.Zonky)12 InvestmentStrategy (com.github.robozonky.api.strategies.InvestmentStrategy)11 Authenticated (com.github.robozonky.app.authentication.Authenticated)11 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)10 Event (com.github.robozonky.api.notifications.Event)8 InvestmentDelegatedEvent (com.github.robozonky.api.notifications.InvestmentDelegatedEvent)8 InvestmentMadeEvent (com.github.robozonky.api.notifications.InvestmentMadeEvent)8 InvestmentRejectedEvent (com.github.robozonky.api.notifications.InvestmentRejectedEvent)8 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)8 ExecutionCompletedEvent (com.github.robozonky.api.notifications.ExecutionCompletedEvent)7 MarketplaceLoan (com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan)7 ExecutionStartedEvent (com.github.robozonky.api.notifications.ExecutionStartedEvent)6 InvestmentSkippedEvent (com.github.robozonky.api.notifications.InvestmentSkippedEvent)6 Restrictions (com.github.robozonky.api.remote.entities.Restrictions)6