Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/remove page and update tests #4

Merged
merged 4 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,27 @@ data class GetPartyViewsPageResponseBody(
val pageIndex: Int,
val pageNumberOfElements: Int
)

@CordaSerializable
data class GetCommercialBankDetailsPageResponseBody(
val data: List<CommercialBankView>,
val first: Boolean,
val last: Boolean,
val totalPages: Int,
val totalElements: Int,
val pageSize: Int,
val pageIndex: Int,
val pageNumberOfElements: Int
)

@CordaSerializable
data class GetBankingEntityAccountsPageResponseBody(
val data: List<BankingEntityAccountView>,
val first: Boolean,
val last: Boolean,
val totalPages: Int,
val totalElements: Int,
val pageSize: Int,
val pageIndex: Int,
val pageNumberOfElements: Int
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data class CBDCBridgeInternalServerError(
) : Exception()

@CordaSerializable
data class CBDCBridgeBadRequest(
data class CBDCBridgeException(
val statusCode: Int,
val name: String,
override val message: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import com.cbdc.industria.tech.bridge.enums.CurrencyStatus
import net.corda.core.serialization.CordaSerializable

@CordaSerializable
data class CommercialBankChild(val id: Int, val name: String, val status: CurrencyStatus)
data class CommercialBankChild(val id: Long, val name: String, val status: CurrencyStatus)

Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package com.cbdc.industria.tech.bridge.services

import com.cbdc.industria.tech.bridge.data.Page
import com.cbdc.industria.tech.bridge.data.MakeDepositRequestBody
import com.cbdc.industria.tech.bridge.data.MakeWithdrawalRequestBody
import com.cbdc.industria.tech.bridge.data.OpenAccountResponseBody
import com.cbdc.industria.tech.bridge.data.CreateCommercialBankRequestBody
import com.cbdc.industria.tech.bridge.data.CreateCommercialBankResponseBody
import com.cbdc.industria.tech.bridge.data.GetBankingEntityAccountResponseBody
import com.cbdc.industria.tech.bridge.data.GetBankingEntityAccountsPageResponseBody
import com.cbdc.industria.tech.bridge.data.GetCommercialBankDetailsPageResponseBody
import com.cbdc.industria.tech.bridge.data.GetCommercialBankDetailsResponseBody
import com.cbdc.industria.tech.bridge.data.GetPartyResponseBody
import com.cbdc.industria.tech.bridge.data.GetPartyViewsPageResponseBody
import com.cbdc.industria.tech.bridge.data.MakeDepositRequestBody
import com.cbdc.industria.tech.bridge.data.MakeWithdrawalRequestBody
import com.cbdc.industria.tech.bridge.data.OpenAccountRequestBody
import com.cbdc.industria.tech.bridge.data.OpenAccountResponseBody
import com.cbdc.industria.tech.bridge.data.RegisterPartyRequestBody
import com.cbdc.industria.tech.bridge.data.RegisterPartyResponseBody
import com.cbdc.industria.tech.bridge.views.BankingEntityAccountView
import com.cbdc.industria.tech.bridge.views.CommercialBankView
import com.cbdc.industria.tech.bridge.views.PartyView
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutorService
Expand All @@ -25,9 +23,6 @@ import net.corda.core.node.AppServiceHub
import net.corda.core.node.services.CordaService
import net.corda.core.serialization.SingletonSerializeAsToken

typealias GetCommercialBankDetailsPageResponseBody = Page<CommercialBankView>
typealias GetBankingEntityAccountsPageResponseBody = Page<BankingEntityAccountView>

@CordaService
class CommercialBankCordaService(private val serviceHub: AppServiceHub) : CommercialBankService(
executor = Executors.newFixedThreadPool(THREADS_COUNT),
Expand Down Expand Up @@ -94,10 +89,10 @@ open class CommercialBankService(
if (pageSize > MAX_PAGE_SIZE)
throw IllegalArgumentException("pageSize must not be grater than $MAX_PAGE_SIZE.")

val future = CompletableFuture<Page<CommercialBankView>>()
val future = CompletableFuture<GetCommercialBankDetailsPageResponseBody>()

executor.execute {
val result = makeGetRequest<Page<CommercialBankView>>(
val result = makeGetRequest<GetCommercialBankDetailsPageResponseBody>(
url = "$host/$COMMERCIAL_BANKS",
headers = mapOf(
AUTH_HEADER_KEY to AUTH_TOKEN,
Expand Down Expand Up @@ -287,10 +282,10 @@ open class CommercialBankService(
if (pageSize > MAX_PAGE_SIZE)
throw IllegalArgumentException("pageSize must not be grater than $MAX_PAGE_SIZE.")

val future = CompletableFuture<Page<BankingEntityAccountView>>()
val future = CompletableFuture<GetBankingEntityAccountsPageResponseBody>()

executor.execute {
val result = makeGetRequest<Page<BankingEntityAccountView>>(
val result = makeGetRequest<GetBankingEntityAccountsPageResponseBody>(
url = "$host/$COMMERCIAL_BANKS/$bankId/$COMMERCIAL_BANKS_ACCOUNTS",
headers = mapOf(
AUTH_HEADER_KEY to AUTH_TOKEN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import com.cbdc.industria.tech.bridge.data.CreateCurrencyRequestBody
import com.cbdc.industria.tech.bridge.data.CreateCurrencyResponseBody
import com.cbdc.industria.tech.bridge.data.GetCurrencyDetailsPageResponseBody
import com.cbdc.industria.tech.bridge.data.GetCurrencyDetailsResponseBody
import com.cbdc.industria.tech.bridge.data.Page
import com.cbdc.industria.tech.bridge.views.CurrencyView
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutorService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.cbdc.industria.tech.bridge.services

import com.cbdc.industria.tech.bridge.exceptions.CBDCBridgeBadRequest
import com.cbdc.industria.tech.bridge.exceptions.CBDCBridgeException
import com.cbdc.industria.tech.bridge.exceptions.CBDCBridgeInternalServerError
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
Expand Down Expand Up @@ -80,7 +80,7 @@ inline fun <reified T : Any> Result<T, FuelError>.toCompletableFuture(future: Co
)
else
future.completeExceptionally(
CBDCBridgeBadRequest(
CBDCBridgeException(
statusCode = err.response.statusCode,
message = String(err.response.data),
name = err.exception::class.java.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.cbdc.industria.tech.bridge.services
import com.cbdc.industria.tech.bridge.data.CreatePaymentInterfaceProviderRequestBody
import com.cbdc.industria.tech.bridge.data.CreatePaymentInterfaceProviderResponseBody
import com.cbdc.industria.tech.bridge.data.GetBankingEntityAccountResponseBody
import com.cbdc.industria.tech.bridge.data.GetBankingEntityAccountsPageResponseBody
import com.cbdc.industria.tech.bridge.data.GetPIPDetailsPageResponseBody
import com.cbdc.industria.tech.bridge.data.GetPIPDetailsResponseBody
import com.cbdc.industria.tech.bridge.data.GetPartyResponseBody
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package com.cbdc.industria.tech.bridge.services
import com.cbdc.industria.tech.bridge.data.CreateNewEnvironmentResponseBody
import com.cbdc.industria.tech.bridge.data.GetEnvironmentDetailsPageResponseBody
import com.cbdc.industria.tech.bridge.data.GetEnvironmentDetailsResponseBody
import com.cbdc.industria.tech.bridge.data.Page
import com.cbdc.industria.tech.bridge.views.EnvironmentView
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class CommercialBankServiceTests {

@AfterEach
fun tearDown() {
commercialBankService.deleteCommercialBank(xEnvId = environmentId, xCurrencyId = currencyId, bankId = commercialBankId)
currenciesService.deleteCurrency(xEnvId = environmentId, currencyId = currencyId)
sandboxEnvService.deleteEnv(environmentId)
commercialBankService.deleteCommercialBank(xEnvId = environmentId, xCurrencyId = currencyId, bankId = commercialBankId).getOrThrow()
currenciesService.deleteCurrency(xEnvId = environmentId, currencyId = currencyId).getOrThrow()
sandboxEnvService.deleteEnv(environmentId).getOrThrow()
}

@Test
Expand Down Expand Up @@ -263,7 +263,7 @@ class CommercialBankServiceTests {
bankId = commercialBankId,
accountId = accountId,
body = MakeDepositRequestBody(100)
)
).getOrThrow()

assertThat(
commercialBankService.getAccount(
Expand All @@ -281,7 +281,7 @@ class CommercialBankServiceTests {
bankId = commercialBankId,
accountId = accountId,
body = MakeWithdrawalRequestBody(100)
)
).getOrThrow()

assertThat(
commercialBankService.getAccount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class CurrenciesServiceTests {

@AfterEach
fun tearDown() {
currenciesService.deleteCurrency(xEnvId = environmentId, currencyId = currencyId)
sandboxEnvService.deleteEnv(environmentId)
currenciesService.deleteCurrency(xEnvId = environmentId, currencyId = currencyId).getOrThrow()
sandboxEnvService.deleteEnv(environmentId).getOrThrow()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.cbdc.industria.tech.bridge

import com.cbdc.industria.tech.bridge.data.OpenBankingAccountAccessConsentCreationRequestBody
import com.cbdc.industria.tech.bridge.enums.CurrencyCode
import com.cbdc.industria.tech.bridge.services.CurrencyService
import com.cbdc.industria.tech.bridge.services.HOST_URL
Expand Down Expand Up @@ -40,8 +39,8 @@ class OpenBankingAccountInformationServiceTest {

@AfterEach
fun tearDown() {
currenciesService.deleteCurrency(xEnvId = environmentId, currencyId = currencyId)
sandboxEnvService.deleteEnv(environmentId)
currenciesService.deleteCurrency(xEnvId = environmentId, currencyId = currencyId).getOrThrow()
sandboxEnvService.deleteEnv(environmentId).getOrThrow()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.cbdc.industria.tech.bridge.data.OpenAccountRequestBody
import com.cbdc.industria.tech.bridge.data.RegisterPartyRequestBody
import com.cbdc.industria.tech.bridge.enums.CurrencyCode
import com.cbdc.industria.tech.bridge.enums.PartyType
import com.cbdc.industria.tech.bridge.services.CBDCLedgerService
import com.cbdc.industria.tech.bridge.services.CommercialBankService
import com.cbdc.industria.tech.bridge.services.CurrencyService
import com.cbdc.industria.tech.bridge.services.HOST_URL
Expand All @@ -30,7 +31,7 @@ class PIPServiceTests {
executor = Executors.newFixedThreadPool(THREADS_COUNT),
host = HOST_URL
)
private val mockCurrencyService = CurrencyService(
private val currencyService = CurrencyService(
executor = Executors.newFixedThreadPool(THREADS_COUNT),
host = HOST_URL
)
Expand All @@ -51,12 +52,12 @@ class PIPServiceTests {
fun createEnvAndCurrency() {
envId = sandboxEnvService.postEnv().getOrThrow().data.id
currencyId =
mockCurrencyService.postCurrency(envId, CreateCurrencyRequestBody(CurrencyCode.EUR)).getOrThrow().data.id
currencyService.postCurrency(envId, CreateCurrencyRequestBody(CurrencyCode.EUR)).getOrThrow().data.id
}

@AfterAll
fun deleteEnvAndCurrency() {
mockCurrencyService.deleteCurrency(envId, currencyId).getOrThrow()
currencyService.deleteCurrency(envId, currencyId).getOrThrow()
sandboxEnvService.deleteEnv(envId).getOrThrow()
}

Expand Down Expand Up @@ -155,42 +156,85 @@ class PIPServiceTests {
val filteredEnv = envs.data.filter { it.status != "TERMINATED" }

filteredEnv.forEach { env ->
val currenciesForEnv = mockCurrencyService.getCurrencies(env.id)
val currenciesForEnv = currencyService.getCurrencies(env.id)
.getOrThrow().data.filter { currencyView ->
currencyView.status.toString() != "TERMINATED"
&& env.currencies.map { it.currencyId }.contains(currencyView.id)
}

currenciesForEnv.forEach { currencyForEnv ->
try {
println(" env id: ${env.id} currency id: ${currencyForEnv.id}")
val pips = pipService.getPIPs(env.id, currencyForEnv.id)
.getOrThrow().data.filter { pip ->
pip.status != "TERMINATED"
&& currenciesForEnv.flatMap { currencyView ->
currencyView.pips.map { it.id }
}.contains(pip.id)
}

val pips = pipService.getPIPs(env.id, currencyForEnv.id)
.getOrThrow().data.filter { pip ->
pip.status != "TERMINATED"
&& currenciesForEnv.flatMap { currencyView ->
currencyView.pips.map { it.id }
}.contains(pip.id)
}
val comBanks = commercialBankService.getCommercialBanks(env.id, currencyForEnv.id)
.getOrThrow().data.filter { comBank ->
comBank.status.toString() != "TERMINATED" && currencyForEnv.commercialBanks.map { it.id }
.contains(comBank.id)
}

comBanks.forEach { comBank ->
val comAccounts =
commercialBankService.getAccounts(env.id, currencyForEnv.id, comBank.id).getOrThrow()
.data.filter { account ->
account.status.toString() == "OPEN"
&& comBank.accounts.map { it.accountId }.contains(account.id)
}

val comParties =
commercialBankService.getParties(env.id, currencyForEnv.id, comBank.id).getOrThrow()
.data.filter { account ->
account.status.toString() == "ACTIVE"
&& comBank.parties.map { it.partyId }.contains(account.id)
}

pips.forEach { pipView ->
pipView.accounts.forEach { account ->
if (account.status.toString() == "OPEN")
pipService.deletePIPAccount(env.id, currencyForEnv.id, pipView.id, account.accountId)
.getOrThrow()
comAccounts.forEach {
commercialBankService.deleteAccount(
env.id,
currencyForEnv.id,
comBank.id,
it.id
)
}
comParties.forEach {
commercialBankService.deleteParty(
env.id,
currencyForEnv.id,
comBank.id,
it.id
)
}
commercialBankService.deleteCommercialBank(env.id, currencyForEnv.id, comBank.id)
}
pipView.parties.forEach { party ->
if (party.status.toString() == "ACTIVE")
pipService.deletePIPParty(env.id, currencyForEnv.id, pipView.id, party.partyId).getOrThrow()

pips.forEach { pipView ->
pipView.accounts.forEach { account ->
if (account.status.toString() == "OPEN")
pipService.deletePIPAccount(env.id, currencyForEnv.id, pipView.id, account.accountId)
.getOrThrow()
}
pipView.parties.forEach { party ->
if (party.status.toString() == "ACTIVE")
pipService.deletePIPParty(env.id, currencyForEnv.id, pipView.id, party.partyId)
.getOrThrow()
}

pipService.deletePIP(env.id, currencyForEnv.id, pipView.id).getOrThrow()
}

pipService.deletePIP(env.id, currencyForEnv.id, pipView.id).getOrThrow()
currencyService.deleteCurrency(env.id, currencyForEnv.id).getOrThrow()
sandboxEnvService.deleteEnv(env.id).getOrThrow()
} catch (e: Exception) {
println(e.message)
}
}

env.currencies.forEach { mockCurrencyService.deleteCurrency(env.id, it.currencyId).getOrThrow() }
sandboxEnvService.deleteEnv(env.id).getOrThrow()
}
val envs2 = sandboxEnvService.getEnvs().getOrThrow().data.filter { it.status != "TERMINATED" }
assertThat(envs2.size).isEqualTo(0)
}

// @Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.cbdc.industria.tech.bridge

import com.cbdc.industria.tech.bridge.enums.CurrencyCode
import com.cbdc.industria.tech.bridge.services.HOST_URL
import com.cbdc.industria.tech.bridge.services.SandboxEnvService
import com.cbdc.industria.tech.bridge.services.THREADS_COUNT
Expand Down

This file was deleted.

Loading