Search in sources :

Example 1 with AccountsProjectionRoot

use of tech.cassandre.trading.bot.api.graphql.client.generated.client.AccountsProjectionRoot in project cassandre-trading-bot by cassandre-tech.

the class AccountDataFetcherTest method accounts.

@Test
@DisplayName("accounts: [Account]")
public void accounts() {
    // Query and fields definition.
    GraphQLQueryRequest graphQLQueryRequest = new GraphQLQueryRequest(new AccountsGraphQLQuery.Builder().build(), new AccountsProjectionRoot().accountId().name());
    // Query execution.
    List<Account> accounts = dgsQueryExecutor.executeAndExtractJsonPathAsObject(graphQLQueryRequest.serialize(), "data." + DgsConstants.QUERY.Accounts + "[*]", new TypeRef<>() {
    });
    // Tests.
    assertEquals(2, accounts.size());
    // Trade account tests.
    final Optional<Account> tradeAccount = accounts.stream().filter(account -> "trade".equals(account.getAccountId())).findAny();
    assertTrue(tradeAccount.isPresent());
    assertEquals("trade", tradeAccount.get().getAccountId());
    assertEquals("trade account name", tradeAccount.get().getName());
    // Savings account tests.
    final Optional<Account> savingsAccount = accounts.stream().filter(account -> "savings".equals(account.getAccountId())).findAny();
    assertTrue(savingsAccount.isPresent());
    assertEquals("savings", savingsAccount.get().getAccountId());
    assertEquals("savings account name", savingsAccount.get().getName());
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Balance(tech.cassandre.trading.bot.api.graphql.client.generated.types.Balance) AccountByAccountIdProjectionRoot(tech.cassandre.trading.bot.api.graphql.client.generated.client.AccountByAccountIdProjectionRoot) AccountsGraphQLQuery(tech.cassandre.trading.bot.api.graphql.client.generated.client.AccountsGraphQLQuery) BaseMock(tech.cassandre.trading.bot.api.graphql.test.util.mock.BaseMock) Account(tech.cassandre.trading.bot.api.graphql.client.generated.types.Account) AccountByAccountIdGraphQLQuery(tech.cassandre.trading.bot.api.graphql.client.generated.client.AccountByAccountIdGraphQLQuery) BEFORE_EACH_TEST_METHOD(org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) BigDecimal(java.math.BigDecimal) DgsConstants(tech.cassandre.trading.bot.api.graphql.client.generated.DgsConstants) BTC(tech.cassandre.trading.bot.dto.util.CurrencyDTO.BTC) DgsAutoConfiguration(com.netflix.graphql.dgs.autoconfig.DgsAutoConfiguration) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ETH(tech.cassandre.trading.bot.dto.util.CurrencyDTO.ETH) AccountsProjectionRoot(tech.cassandre.trading.bot.api.graphql.client.generated.client.AccountsProjectionRoot) CassandreTradingBot(tech.cassandre.trading.bot.api.graphql.test.CassandreTradingBot) BaseDataFetcherTest(tech.cassandre.trading.bot.api.graphql.test.util.base.BaseDataFetcherTest) TypeRef(com.jayway.jsonpath.TypeRef) AccountDataFetcher(tech.cassandre.trading.bot.api.graphql.data.AccountDataFetcher) Import(org.springframework.context.annotation.Import) GraphQLQueryRequest(com.netflix.graphql.dgs.client.codegen.GraphQLQueryRequest) TestPropertySource(org.springframework.test.context.TestPropertySource) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DgsQueryExecutor(com.netflix.graphql.dgs.DgsQueryExecutor) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Account(tech.cassandre.trading.bot.api.graphql.client.generated.types.Account) AccountsProjectionRoot(tech.cassandre.trading.bot.api.graphql.client.generated.client.AccountsProjectionRoot) GraphQLQueryRequest(com.netflix.graphql.dgs.client.codegen.GraphQLQueryRequest) BaseDataFetcherTest(tech.cassandre.trading.bot.api.graphql.test.util.base.BaseDataFetcherTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

TypeRef (com.jayway.jsonpath.TypeRef)1 DgsQueryExecutor (com.netflix.graphql.dgs.DgsQueryExecutor)1 DgsAutoConfiguration (com.netflix.graphql.dgs.autoconfig.DgsAutoConfiguration)1 GraphQLQueryRequest (com.netflix.graphql.dgs.client.codegen.GraphQLQueryRequest)1 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1 Optional (java.util.Optional)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 DisplayName (org.junit.jupiter.api.DisplayName)1 Test (org.junit.jupiter.api.Test)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Import (org.springframework.context.annotation.Import)1 DirtiesContext (org.springframework.test.annotation.DirtiesContext)1 BEFORE_EACH_TEST_METHOD (org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)1 ActiveProfiles (org.springframework.test.context.ActiveProfiles)1 TestPropertySource (org.springframework.test.context.TestPropertySource)1 DgsConstants (tech.cassandre.trading.bot.api.graphql.client.generated.DgsConstants)1