Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
da93faa
wallet: Add isWithdrawAllowed test
ebrahimmfadae May 15, 2022
e4684a2
wallet: Use mockito-kotlin library
ebrahimmfadae May 16, 2022
3dcf735
wallet: Use assertJ
ebrahimmfadae May 16, 2022
2414e2b
Merge branch 'dev' into 266-write-tests-for-create-and-cancel-order
ebrahimmfadae May 16, 2022
c182667
Merge branch 'dev' into 266-write-tests-for-create-and-cancel-order
ebrahimmfadae May 16, 2022
b2f3350
wallet: Add base class for testing services
ebrahimmfadae May 16, 2022
62a9638
wallet: Add is withdraw allowed tests to wallet owner
ebrahimmfadae May 16, 2022
1eb75f1
wallet: Add wallet manager tests
ebrahimmfadae May 16, 2022
d6eaea2
wallet: Add wallet owner manager tests
ebrahimmfadae May 16, 2022
9f82e76
wallet: Add currency service tests
ebrahimmfadae May 16, 2022
68cf744
wallet: Add transfer service tests
ebrahimmfadae May 16, 2022
a7aa020
wallet: Add more tests to wallet manager
ebrahimmfadae May 17, 2022
e58bdd1
wallet: Improve update balance test coverage
ebrahimmfadae May 17, 2022
df11740
wallet: Improve is withdraw allowed test coverage
ebrahimmfadae May 17, 2022
577d229
wallet: Add is deposit allowed tests
ebrahimmfadae May 17, 2022
0600491
wallet: Refactor wallet owner manager
ebrahimmfadae May 17, 2022
add13d7
wallet: Refactor transfer service tests
ebrahimmfadae May 17, 2022
0bcef90
wallet: Refactor currency service tests
ebrahimmfadae May 17, 2022
78ee45d
Merge branch 'dev' into 266-write-tests-for-create-and-cancel-order
ebrahimmfadae May 17, 2022
e4793f9
Merge branch 'dev' into 266-write-tests-for-create-and-cancel-order
ebrahimmfadae May 18, 2022
3366d30
wallet: Organize tests
ebrahimmfadae May 18, 2022
fd9bd09
wallet: Improve wallet manager tests
ebrahimmfadae May 18, 2022
522ab46
wallet: Improve currency service tests
ebrahimmfadae May 18, 2022
f69ad23
wallet: Improve wallet owner manager tests
ebrahimmfadae May 18, 2022
3730b13
wallet: Improve wallet owner manager tests
ebrahimmfadae May 18, 2022
d590bfa
wallet: Improve wallet manager tests
ebrahimmfadae May 18, 2022
9b6edc2
wallet: Improve transfer service tests
ebrahimmfadae May 18, 2022
dad9160
wallet: Improve wallet manager tests
ebrahimmfadae May 19, 2022
a8be03c
wallet: Use onBlocking in tests to support suspend functions
ebrahimmfadae May 19, 2022
48476d3
wallet: Refactor tests
ebrahimmfadae May 19, 2022
dbc09be
wallet: Refactor tests
ebrahimmfadae May 19, 2022
eeaec9c
matching-gateway: Add create order tests
ebrahimmfadae May 19, 2022
57fa25d
Merge branch 'dev' into 266-write-tests-for-create-and-cancel-order
ebrahimmfadae May 19, 2022
8b07dd1
matching-gateway: Improve tests
ebrahimmfadae May 19, 2022
04a7a45
Merge branch 'dev' into 266-write-tests-for-create-and-cancel-order
ebrahimmfadae May 19, 2022
5136d9d
matching-gateway: Improve kafka health indicator
ebrahimmfadae May 19, 2022
1df1d3f
matching-gateway: Add more tests
ebrahimmfadae May 20, 2022
ce23cbc
api: Add test classes
ebrahimmfadae May 20, 2022
175785b
api: Add symbol mapper tests
ebrahimmfadae May 21, 2022
060fcee
api: Add order persister tests
ebrahimmfadae May 21, 2022
842c913
api: Add trade persister tests
ebrahimmfadae May 21, 2022
fc44b5e
api: Add user query handler tests
ebrahimmfadae May 21, 2022
19ad3c2
api: Add market query handler tests
ebrahimmfadae May 21, 2022
39e9874
api: Add more order persister tests
ebrahimmfadae May 21, 2022
a420778
api: Add market query handler test stubs
ebrahimmfadae May 22, 2022
b4a8b46
api: Add user query handler test stubs
ebrahimmfadae May 22, 2022
7da068c
api: Add stubbing methods
ebrahimmfadae May 22, 2022
aadcbd8
api: Refactor tests given data
ebrahimmfadae May 22, 2022
3197d82
maven: Skip tests on build
ebrahimmfadae May 22, 2022
51e09fc
maven: Fix mockito-kotlin dependencies
ebrahimmfadae May 22, 2022
d48465b
maven: Fix mockito-kotlin dependencies
ebrahimmfadae May 22, 2022
4ef3726
api: Refactor market query handler tests
ebrahimmfadae May 22, 2022
30ec97c
api: Refactor user query handler tests
ebrahimmfadae May 22, 2022
3a3dc23
api: Refactor market query handler tests
ebrahimmfadae May 22, 2022
acf3543
api: Improve tests sample data
ebrahimmfadae May 22, 2022
ab6d037
api: Remove hardcoded data from tests
ebrahimmfadae May 22, 2022
ad3e287
api: Improve test case titles
ebrahimmfadae May 22, 2022
4f00baf
api: Move tests to postgres module
ebrahimmfadae May 22, 2022
6672c61
wallet: Move each test to its correspondence module
ebrahimmfadae May 22, 2022
872f65d
wallet: Remove base classes
ebrahimmfadae May 22, 2022
34db047
matching-gateway: Remove test base classes
ebrahimmfadae May 22, 2022
5be79a0
wallet: Remove test folder from wallet-app
ebrahimmfadae May 22, 2022
307b23c
wallet: Improve test titles
ebrahimmfadae May 22, 2022
f1879e4
matching-gateway: Refactor order service tests
ebrahimmfadae May 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions accountant/accountant-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,9 @@
<artifactId>spring-tx</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>
</project>
138 changes: 71 additions & 67 deletions api/api-ports/api-persister-postgres/pom.xml
Original file line number Diff line number Diff line change
@@ -1,67 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>co.nilin.opex.api</groupId>
<artifactId>api</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<groupId>co.nilin.opex.api.ports.postgres</groupId>
<artifactId>api-persister-postgres</artifactId>
<name>api-persister-postgres</name>
<description>Persist items of Opex api on Postgres</description>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>co.nilin.opex.api.core</groupId>
<artifactId>api-core</artifactId>
</dependency>
<dependency>
<groupId>co.nilin.opex.utility.error</groupId>
<artifactId>error-handler</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.projectreactor.kotlin</groupId>
<artifactId>reactor-kotlin-extensions</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-reactor</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>co.nilin.opex.api</groupId>
<artifactId>api</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<groupId>co.nilin.opex.api.ports.postgres</groupId>
<artifactId>api-persister-postgres</artifactId>
<name>api-persister-postgres</name>
<description>Persist items of Opex api on Postgres</description>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>co.nilin.opex.api.core</groupId>
<artifactId>api-core</artifactId>
</dependency>
<dependency>
<groupId>co.nilin.opex.utility.error</groupId>
<artifactId>error-handler</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.projectreactor.kotlin</groupId>
<artifactId>reactor-kotlin-extensions</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-reactor</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito.kotlin</groupId>
<artifactId>mockito-kotlin</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package co.nilin.opex.api.ports.postgres.impl

import co.nilin.opex.api.core.inout.OrderDirection
import co.nilin.opex.api.core.inout.OrderStatus
import co.nilin.opex.api.core.spi.SymbolMapper
import co.nilin.opex.api.ports.postgres.dao.OrderRepository
import co.nilin.opex.api.ports.postgres.dao.OrderStatusRepository
import co.nilin.opex.api.ports.postgres.dao.TradeRepository
import co.nilin.opex.api.ports.postgres.impl.sample.Valid
import kotlinx.coroutines.flow.count
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.mockito.kotlin.*
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono

class MarketQueryHandlerTest {
private val orderRepository: OrderRepository = mock()
private val tradeRepository: TradeRepository = mock()
private val orderStatusRepository: OrderStatusRepository = mock()
private val symbolMapper: SymbolMapper = mock()
private val marketQueryHandler =
MarketQueryHandlerImpl(orderRepository, tradeRepository, orderStatusRepository, symbolMapper)

@Test
fun givenAggregatedOrderPrice_whenOpenASKOrders_thenReturnOrderBookResponseList(): Unit = runBlocking {
stubbing(orderRepository) {
on {
findBySymbolAndDirectionAndStatusSortAscendingByPrice(
eq(Valid.ETH_USDT),
eq(OrderDirection.ASK),
eq(1),
argThat {
this == listOf(
OrderStatus.NEW.code,
OrderStatus.PARTIALLY_FILLED.code
)
}
)
} doReturn Flux.just(Valid.AGGREGATED_ORDER_PRICE_MODEL)
}

val orderBookResponses = marketQueryHandler.openAskOrders(Valid.ETH_USDT, 1)

assertThat(orderBookResponses).isNotNull
assertThat(orderBookResponses.size).isEqualTo(1)
assertThat(orderBookResponses.first()).isEqualTo(Valid.ORDER_BOOK_RESPONSE)
}

@Test
fun givenAggregatedOrderPrice_whenOpenBIDOrders_thenReturnOrderBookResponseList(): Unit = runBlocking {
stubbing(orderRepository) {
on {
findBySymbolAndDirectionAndStatusSortDescendingByPrice(
eq(Valid.ETH_USDT),
eq(OrderDirection.BID),
eq(1),
argThat {
this == listOf(
OrderStatus.NEW.code,
OrderStatus.PARTIALLY_FILLED.code
)
}
)
} doReturn Flux.just(Valid.AGGREGATED_ORDER_PRICE_MODEL)
}

val orderBookResponses = marketQueryHandler.openBidOrders(Valid.ETH_USDT, 1)

assertThat(orderBookResponses).isNotNull
assertThat(orderBookResponses.size).isEqualTo(1)
assertThat(orderBookResponses.first()).isEqualTo(Valid.ORDER_BOOK_RESPONSE)
}

@Test
fun givenOrder_whenLastOrder_thenReturnQueryOrderResponse(): Unit = runBlocking {
stubbing(orderRepository) {
on {
findLastOrderBySymbol(Valid.ETH_USDT)
} doReturn Mono.just(Valid.MAKER_ORDER_MODEL)
}
stubbing(orderStatusRepository) {
on {
findMostRecentByOUID(Valid.MAKER_ORDER_MODEL.ouid)
} doReturn Mono.just(Valid.MAKER_ORDER_STATUS_MODEL)
}

val queryOrderResponse = marketQueryHandler.lastOrder(Valid.ETH_USDT)

assertThat(queryOrderResponse).isNotNull
assertThat(queryOrderResponse).isEqualTo(Valid.MAKER_QUERY_ORDER_RESPONSE)
}

@Test
fun givenOrderAndTradeAndSymbolAlias_whenLastPrice_thenPriceTickerResponse(): Unit = runBlocking {
stubbing(tradeRepository) {
on {
findAllGroupBySymbol()
} doReturn Flux.just(Valid.TRADE_MODEL)
on {
findBySymbolGroupBySymbol(Valid.ETH_USDT)
} doReturn Flux.just(Valid.TRADE_MODEL)
}
stubbing(orderRepository) {
on {
findByOuid(Valid.MAKER_ORDER_MODEL.ouid)
} doReturn Mono.just(Valid.MAKER_ORDER_MODEL)
}
stubbing(symbolMapper) {
onBlocking {
map(Valid.ETH_USDT)
} doReturn "ETHUSDT"
}

val priceTickerResponse = marketQueryHandler.lastPrice(Valid.ETH_USDT)

assertThat(priceTickerResponse).isNotNull
assertThat(priceTickerResponse.size).isEqualTo(1)
assertThat(priceTickerResponse.first().symbol).isEqualTo("ETHUSDT")
assertThat(priceTickerResponse.first().price).isEqualTo("100000.0")
}

@Test
fun givenOrderAndTrade_whenRecentTrades_thenMarketTradeResponseFlow(): Unit = runBlocking {
stubbing(tradeRepository) {
on {
findBySymbolSortDescendingByCreateDate(Valid.ETH_USDT, 1)
} doReturn flow {
emit(Valid.TRADE_MODEL)
}
}
stubbing(orderRepository) {
on {
findByOuid(Valid.TRADE_MODEL.makerOuid)
} doReturn Mono.just(Valid.MAKER_ORDER_MODEL)
on {
findByOuid(Valid.TRADE_MODEL.takerOuid)
} doReturn Mono.just(Valid.TAKER_ORDER_MODEL)
}

val marketTradeResponses = marketQueryHandler.recentTrades(Valid.ETH_USDT, 1)

assertThat(marketTradeResponses).isNotNull
assertThat(marketTradeResponses.count()).isEqualTo(1)
assertThat(marketTradeResponses.first()).isEqualTo(Valid.MARKET_TRADE_RESPONSE)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package co.nilin.opex.api.ports.postgres.impl

import co.nilin.opex.api.ports.postgres.dao.OrderRepository
import co.nilin.opex.api.ports.postgres.dao.OrderStatusRepository
import co.nilin.opex.api.ports.postgres.impl.sample.Valid
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThatNoException
import org.junit.jupiter.api.Test
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.stubbing
import reactor.core.publisher.Mono

class OrderPersisterTest {
private val orderRepository: OrderRepository = mock()
private val orderStatusRepository: OrderStatusRepository = mock()
private val orderPersister = OrderPersisterImpl(orderRepository, orderStatusRepository)

@Test
fun givenOrderRepo_whenSaveRichOrder_thenSuccess(): Unit = runBlocking {
stubbing(orderRepository) {
on {
save(any())
} doReturn Mono.just(Valid.MAKER_ORDER_MODEL)
}
stubbing(orderStatusRepository) {
on {
save(any())
} doReturn Mono.just(Valid.MAKER_ORDER_STATUS_MODEL)
}

assertThatNoException().isThrownBy { runBlocking { orderPersister.save(Valid.RICH_ORDER) } }
}

@Test
fun givenOrderRepo_whenUpdateRichOrder_thenSuccess(): Unit = runBlocking {
stubbing(orderStatusRepository) {
on {
save(any())
} doReturn Mono.just(Valid.MAKER_ORDER_STATUS_MODEL)
}

assertThatNoException().isThrownBy { runBlocking { orderPersister.update(Valid.RICH_ORDER_UPDATE) } }
}
}
Loading