From 746cf718eec5dcac32a77fa6071d5436cb3ffd81 Mon Sep 17 00:00:00 2001 From: hongwei Date: Tue, 4 Jul 2023 01:54:37 +0800 Subject: [PATCH] bugfix/fixed future issue for setAccountHolderAndRefreshUserAccountAccess method --- .../scala/code/api/v2_2_0/APIMethods220.scala | 2 +- .../scala/code/api/v3_1_0/APIMethods310.scala | 7 +++--- .../scala/code/api/v4_0_0/APIMethods400.scala | 4 ++-- .../scala/code/api/v5_0_0/APIMethods500.scala | 2 +- .../code/model/dataAccess/AuthUser.scala | 17 +++++++++---- .../BankAccountCreationDispatcher.scala | 2 +- .../main/scala/code/views/MapperViews.scala | 4 ++-- .../scala/code/api/v2_2_0/AccountTest.scala | 19 --------------- .../scala/code/api/v3_1_0/AccountTest.scala | 24 +------------------ .../code/api/v4_0_0/AccountAccessTest.scala | 3 --- .../scala/code/api/v4_0_0/AccountTest.scala | 14 +---------- .../api/v4_0_0/DeleteAccountCascadeTest.scala | 4 ---- .../api/v4_0_0/DeleteBankCascadeTest.scala | 5 +--- .../api/v4_0_0/SettlementAccountTest.scala | 4 ---- .../code/api/v4_0_0/V400ServerSetup.scala | 4 +--- .../scala/code/api/v5_0_0/AccountTest.scala | 19 --------------- 16 files changed, 27 insertions(+), 107 deletions(-) diff --git a/obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala b/obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala index 4c7d51483..441a8246b 100644 --- a/obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala +++ b/obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala @@ -832,7 +832,7 @@ trait APIMethods220 { //1 Create or Update the `Owner` for the new account //2 Add permission to the user //3 Set the user as the account holder - _ = BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, postedOrLoggedInUser, callContext) + _ <- BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, postedOrLoggedInUser, callContext) } yield { (JSONFactory220.createAccountJSON(userIdAccountOwner, bankAccount), HttpCode.`200`(callContext)) diff --git a/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala b/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala index 111ddf641..7fad0ea25 100644 --- a/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala +++ b/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala @@ -1890,7 +1890,7 @@ trait APIMethods310 { _ <- NewStyle.function.hasEntitlement("", userId, canRefreshUser, callContext) startTime <- Future{Helpers.now} (user, callContext) <- NewStyle.function.findByUserId(userId, callContext) - _ = AuthUser.refreshUser(user, callContext) + _ <- AuthUser.refreshUser(user, callContext) endTime <- Future{Helpers.now} durationTime = endTime.getTime - startTime.getTime } yield { @@ -2340,8 +2340,9 @@ trait APIMethods310 { "", List.empty, callContext) + success <- BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, u, callContext) }yield { - BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, u, callContext) + success } case _ => Future{""} } @@ -5428,7 +5429,7 @@ trait APIMethods310 { //1 Create or Update the `Owner` for the new account //2 Add permission to the user //3 Set the user as the account holder - _ = BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, postedOrLoggedInUser, callContext) + _ <- BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, postedOrLoggedInUser, callContext) } yield { (JSONFactory310.createAccountJSON(userIdAccountOwner, bankAccount, accountAttributes), HttpCode.`201`(callContext)) } diff --git a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala index eb13446ab..b07b088e0 100644 --- a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala +++ b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala @@ -536,7 +536,7 @@ trait APIMethods400 { //1 Create or Update the `Owner` for the new account //2 Add permission to the user //3 Set the user as the account holder - _ = BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, postedOrLoggedInUser, callContext) + _ <- BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, postedOrLoggedInUser, callContext) } yield { (JSONFactory400.createSettlementAccountJson(userIdAccountOwner, bankAccount, accountAttributes), HttpCode.`201`(callContext)) } @@ -2631,7 +2631,7 @@ trait APIMethods400 { //1 Create or Update the `Owner` for the new account //2 Add permission to the user //3 Set the user as the account holder - _ = BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, postedOrLoggedInUser, callContext) + _ <- BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, postedOrLoggedInUser, callContext) } yield { (JSONFactory310.createAccountJSON(userIdAccountOwner, bankAccount, accountAttributes), HttpCode.`201`(callContext)) } diff --git a/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala b/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala index c7859a310..1f038ae5b 100644 --- a/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala +++ b/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala @@ -391,7 +391,7 @@ trait APIMethods500 { //1 Create or Update the `Owner` for the new account //2 Add permission to the user //3 Set the user as the account holder - _ = BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, postedOrLoggedInUser, callContext) + _ <- BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, postedOrLoggedInUser, callContext) } yield { (JSONFactory310.createAccountJSON(userIdAccountOwner, bankAccount, accountAttributes), HttpCode.`201`(callContext)) } diff --git a/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala b/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala index c31faa332..d16c37a63 100644 --- a/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala +++ b/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala @@ -1376,8 +1376,11 @@ def restoreSomeSessions(): Unit = { connectorEmptyResponse(_, callContext) } _ = logger.debug(s"--> for user($user): AuthUser.refreshUserAccountAccess.accounts : ${accountsHeld}") + + success = refreshViewsAccountAccessAndHolders(user, accountsHeld, callContext) + }yield { - refreshViewsAccountAccessAndHolders(user, accountsHeld, callContext) + success } } @@ -1387,7 +1390,7 @@ def restoreSomeSessions(): Unit = { * This method can only be used by the original user(account holder). * InboundAccount return many fields, but in this method, we only need bankId, accountId and viewId so far. */ - def refreshViewsAccountAccessAndHolders(user: User, accountsHeld: List[InboundAccount], callContext: Option[CallContext]): Unit = { + def refreshViewsAccountAccessAndHolders(user: User, accountsHeld: List[InboundAccount], callContext: Option[CallContext]) = { if(user.isOriginalUser){ //first, we compare the accounts in obp and the accounts in cbs, val (_, privateAccountAccess) = Views.views.vend.privateViewsUserCanAccess(user) @@ -1471,7 +1474,7 @@ def restoreSomeSessions(): Unit = { //cbs has new views which are not in obp yet, we need to create new data for these accounts. csbNewViewsForAccount = cbsViewsForAccount diff obpViewsForAccount _ = logger.debug("refreshViewsAccountAccessAndHolders.csbNewViewsForAccount-------" + csbNewViewsForAccount) - _ = if(csbNewViewsForAccount.nonEmpty){ + success = if(csbNewViewsForAccount.nonEmpty){ for{ newViewForAccount <- csbNewViewsForAccount _ = logger.debug("refreshViewsAccountAccessAndHolders.csbNewViewsForAccount.newViewForAccount start:-------" + newViewForAccount) @@ -1487,10 +1490,14 @@ def restoreSomeSessions(): Unit = { } } } yield { - bankAccountId + success } } - } + true + } + else { + false + } } /** * Find the authUser by author user name(authUser and resourceUser are the same). diff --git a/obp-api/src/main/scala/code/model/dataAccess/BankAccountCreationDispatcher.scala b/obp-api/src/main/scala/code/model/dataAccess/BankAccountCreationDispatcher.scala index f773e7454..a03dee52e 100644 --- a/obp-api/src/main/scala/code/model/dataAccess/BankAccountCreationDispatcher.scala +++ b/obp-api/src/main/scala/code/model/dataAccess/BankAccountCreationDispatcher.scala @@ -85,7 +85,7 @@ package code.model.dataAccess { * * @return This is a procedure, no return value. Just use the side effect. */ - def setAccountHolderAndRefreshUserAccountAccess(bankId : BankId, accountId : AccountId, user: User, callContext: Option[CallContext]): Unit = { + def setAccountHolderAndRefreshUserAccountAccess(bankId : BankId, accountId : AccountId, user: User, callContext: Option[CallContext]) = { // Here, we can call `addPermissionToSystemOwnerView` directly, but from now on, we try to simulate the CBS account creation. // 1st-getOrCreateAccountHolder: in this method, we only create the account holder, no view, account access involved here. AccountHolders.accountHolders.vend.getOrCreateAccountHolder(user: User, BankIdAccountId(bankId, accountId)) diff --git a/obp-api/src/main/scala/code/views/MapperViews.scala b/obp-api/src/main/scala/code/views/MapperViews.scala index 1faae5b3f..4255216a5 100644 --- a/obp-api/src/main/scala/code/views/MapperViews.scala +++ b/obp-api/src/main/scala/code/views/MapperViews.scala @@ -609,7 +609,7 @@ object MapperViews extends Views with MdcLoggable { def getOrCreateSystemViewFromCbs(viewId: String): Box[View] = { - logger.debug(s"-->getOrCreateSystemViewFromCbs.${viewId} --- start ") + logger.debug(s"-->getOrCreateSystemViewFromCbs--- start--${viewId} ") val ownerView = SYSTEM_OWNER_VIEW_ID.equals(viewId.toLowerCase) val accountantsView = SYSTEM_ACCOUNTANT_VIEW_ID.equals(viewId.toLowerCase) @@ -633,7 +633,7 @@ object MapperViews extends Views with MdcLoggable { Failure(ViewIdNotSupported+ s"Your input viewId is :$viewId") } - logger.debug(s"-->getOrCreateSystemViewFromCbs.${viewId } --- finish : ${theView} ") + logger.debug(s"-->getOrCreateSystemViewFromCbs --- finish.${viewId } : ${theView} ") theView } diff --git a/obp-api/src/test/scala/code/api/v2_2_0/AccountTest.scala b/obp-api/src/test/scala/code/api/v2_2_0/AccountTest.scala index 24099686e..a1a62b879 100644 --- a/obp-api/src/test/scala/code/api/v2_2_0/AccountTest.scala +++ b/obp-api/src/test/scala/code/api/v2_2_0/AccountTest.scala @@ -15,14 +15,6 @@ import scala.util.Random class AccountTest extends V220ServerSetup with DefaultUsers { - override def beforeAll(): Unit = { - super.beforeAll() - } - - override def afterAll(): Unit = { - super.afterAll() - } - val mockAccountId1 = "NEW_MOCKED_ACCOUNT_ID_01" val mockAccountId2 = "NEW_MOCKED_ACCOUNT_ID_02" @@ -51,9 +43,6 @@ class AccountTest extends V220ServerSetup with DefaultUsers { val responsePut = makePutRequest(requestPut, write(accountPutJSON)) And("We should get a 200") responsePut.code should equal(200) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(2) When("We make the authenticated access request") val requestGetAll = (v2_2Request / "accounts").GET <@ (user1) @@ -98,10 +87,6 @@ class AccountTest extends V220ServerSetup with DefaultUsers { val requestPut = (v2_2Request / "banks" / testBank.value / "accounts" / mockAccountId1).PUT <@ (user1) val responsePut = makePutRequest(requestPut, write(accountPutJSON)) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(2) - And("We should get a 200") responsePut.code should equal(200) @@ -165,10 +150,6 @@ class AccountTest extends V220ServerSetup with DefaultUsers { val requestPut = (v2_2Request / "banks" / testBank.value / "accounts" / mockAccountId1).PUT <@ (user1) val responsePut = makePutRequest(requestPut, write(accountPutJSON)) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(2) - Then("we get the account access for this account") val accountViewsRequest = (v2_2Request / "banks" / testBank.value / "accounts" / mockAccountId1 / "views").GET <@(user1) val accountViewsResponse = makeGetRequest(accountViewsRequest) diff --git a/obp-api/src/test/scala/code/api/v3_1_0/AccountTest.scala b/obp-api/src/test/scala/code/api/v3_1_0/AccountTest.scala index 2526199fb..af88c2de4 100644 --- a/obp-api/src/test/scala/code/api/v3_1_0/AccountTest.scala +++ b/obp-api/src/test/scala/code/api/v3_1_0/AccountTest.scala @@ -103,10 +103,6 @@ class AccountTest extends V310ServerSetup with DefaultUsers { responsePut1.code should equal(200) responsePut1.body.extract[UpdateAccountResponseJsonV310].account_routings should be (testPutJsonWithIban.account_routings) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(2) - val responseGet1 = makeGetRequest(requestGet) And("We should get 200 and updated account routings in the getAccount response") responseGet1.code should equal(200) @@ -202,10 +198,6 @@ class AccountTest extends V310ServerSetup with DefaultUsers { val response310 = makePutRequest(request310, write(putCreateAccountJSONV310)) Then("We should get a 201") response310.code should equal(201) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(2) - val account = response310.body.extract[CreateAccountResponseJsonV310] account.product_code should be (putCreateAccountJSONV310.product_code) @@ -217,10 +209,6 @@ class AccountTest extends V310ServerSetup with DefaultUsers { account.label should be (putCreateAccountJSONV310.label) account.account_routings should be (putCreateAccountJSONV310.account_routings) - - //We need to waite some time for the account creation, because we introduce `AuthUser.refreshUser(user, callContext)` - //It may not finished when we call the get accounts directly. - TimeUnit.SECONDS.sleep(2) Then(s"we call $ApiEndpoint4 to get the account back") val requestApiEndpoint4 = (v3_1_0_Request / "my" / "accounts" ).PUT <@(user1) @@ -278,10 +266,7 @@ class AccountTest extends V310ServerSetup with DefaultUsers { val response310 = makePutRequest(request310, write(putCreateAccountJson)) Then("We should get a 201") response310.code should equal(201) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(2) - + val account = response310.body.extract[CreateAccountResponseJsonV310] account.product_code should be (putCreateAccountJson.product_code) account.`label` should be (putCreateAccountJson.`label`) @@ -308,10 +293,6 @@ class AccountTest extends V310ServerSetup with DefaultUsers { Then("We should get a 201") responseUser2_310.code should equal(201) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(2) - Then(s"we call $ApiEndpoint6 to get the account back by user2") val requestApiUser2Endpoint6 = (v3_1_0_Request /"banks" / testBankId.value / "accounts" / userAccountId / Constant.SYSTEM_OWNER_VIEW_ID/ "account" ).GET <@(user2) @@ -328,9 +309,6 @@ class AccountTest extends V310ServerSetup with DefaultUsers { Then("We should get a 201") response310_1.code should equal(201) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(2) val account = response310_1.body.extract[CreateAccountResponseJsonV310] account.product_code should be (putCreateAccountJSONV310.product_code) account.`label` should be (putCreateAccountJSONV310.`label`) diff --git a/obp-api/src/test/scala/code/api/v4_0_0/AccountAccessTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/AccountAccessTest.scala index 324b7dc2f..04c96ab46 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/AccountAccessTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/AccountAccessTest.scala @@ -44,9 +44,6 @@ class AccountAccessTest extends V400ServerSetup { val request400 = (v4_0_0_Request / "banks" / bankId / "accounts" ).POST <@(user1) val response400 = makePostRequest(request400, write(addAccountJson)) Then("We should get a 201") - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(3) response400.code should equal(201) response400.body.extract[CreateAccountResponseJsonV310] diff --git a/obp-api/src/test/scala/code/api/v4_0_0/AccountTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/AccountTest.scala index 7c1e111cb..0a40d27eb 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/AccountTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/AccountTest.scala @@ -106,10 +106,7 @@ class AccountTest extends V400ServerSetup { Then("We should get a 201") response400.code should equal(201) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(2) - + val account = response400.body.extract[CreateAccountResponseJsonV310] account.account_id should not be empty account.product_code should be (addAccountJson.product_code) @@ -121,11 +118,6 @@ class AccountTest extends V400ServerSetup { account.label should be (addAccountJson.label) account.account_routings should be (addAccountJson.account_routings) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(3) - - Then(s"We call $ApiEndpoint1 to get the account back") val request = (v4_0_0_Request /"my" / "banks" / testBankId.value/ "accounts" / account.account_id / "account").GET <@ (user1) val response = makeGetRequest(request) @@ -170,10 +162,6 @@ class AccountTest extends V400ServerSetup { Then("We should get a 201") response400_1.code should equal(201) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(2) - val account = response400_1.body.extract[CreateAccountResponseJsonV310] account.account_id should not be empty account.product_code should be (addAccountJson.product_code) diff --git a/obp-api/src/test/scala/code/api/v4_0_0/DeleteAccountCascadeTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/DeleteAccountCascadeTest.scala index bf77ecf97..78eb5eba9 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/DeleteAccountCascadeTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/DeleteAccountCascadeTest.scala @@ -70,10 +70,6 @@ class DeleteAccountCascadeTest extends V400ServerSetup { val account = response400.body.extract[CreateAccountResponseJsonV310] account.account_id should not be empty - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(3) - val postBodyView = createViewJsonV300.copy(name = "_cascade_delete", metadata_view = "_cascade_delete", is_public = false).toCreateViewJson createViewViaEndpoint(bankId, account.account_id, postBodyView, user1) diff --git a/obp-api/src/test/scala/code/api/v4_0_0/DeleteBankCascadeTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/DeleteBankCascadeTest.scala index c79ee5621..6d65c160f 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/DeleteBankCascadeTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/DeleteBankCascadeTest.scala @@ -65,10 +65,7 @@ class DeleteBankCascadeTest extends V400ServerSetup { val request400 = (v4_0_0_Request / "banks" / bankId / "accounts" ).POST <@(user1) val response400 = makePostRequest(request400, write(addAccountJson)) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(3) - + Then("We should get a 201") response400.code should equal(201) val account = response400.body.extract[CreateAccountResponseJsonV310] diff --git a/obp-api/src/test/scala/code/api/v4_0_0/SettlementAccountTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/SettlementAccountTest.scala index 19b6a80d4..a7033c64e 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/SettlementAccountTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/SettlementAccountTest.scala @@ -125,10 +125,6 @@ class SettlementAccountTest extends V400ServerSetup { makePostRequest((v4_0_0_Request / "banks" / testBankId.value / "settlement-accounts" ).POST <@(user1), write(createSettlementAccountJson)) makePostRequest((v4_0_0_Request / "banks" / testBankId.value / "settlement-accounts" ).POST <@(user1), write(createSettlementAccountOtherUser)) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(4) - When("We send the request") val addedEntitlement: Box[Entitlement] = Entitlement.entitlement.vend.addEntitlement(testBankId.value, resourceUser1.userId, ApiRole.CanGetSettlementAccountAtOneBank.toString) diff --git a/obp-api/src/test/scala/code/api/v4_0_0/V400ServerSetup.scala b/obp-api/src/test/scala/code/api/v4_0_0/V400ServerSetup.scala index 06dfd0767..8b42fb359 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/V400ServerSetup.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/V400ServerSetup.scala @@ -277,9 +277,7 @@ trait V400ServerSetup extends ServerSetupWithTestData with DefaultUsers { And("We make a request v4.0.0") val request400 = (v4_0_0_Request / "banks" / bankId / "accounts" ).POST <@(consumerAndToken) val response400 = makePostRequest(request400, write(json)) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(3) + Then("We should get a 201") response400.code should equal(201) diff --git a/obp-api/src/test/scala/code/api/v5_0_0/AccountTest.scala b/obp-api/src/test/scala/code/api/v5_0_0/AccountTest.scala index a7fc8df38..c6aae646c 100644 --- a/obp-api/src/test/scala/code/api/v5_0_0/AccountTest.scala +++ b/obp-api/src/test/scala/code/api/v5_0_0/AccountTest.scala @@ -64,10 +64,6 @@ class AccountTest extends V500ServerSetup with DefaultUsers { val response = makePutRequest(request, write(putCreateAccountJSONV310)) Then("We should get a 201") response.code should equal(201) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(2) - val account = response.body.extract[CreateAccountResponseJsonV310] account.product_code should be (putCreateAccountJSONV310.product_code) @@ -80,10 +76,6 @@ class AccountTest extends V500ServerSetup with DefaultUsers { account.account_routings should be (putCreateAccountJSONV310.account_routings) - //We need to waite some time for the account creation, because we introduce `AuthUser.refreshUser(user, callContext)` - //It may not finished when we call the get accounts directly. - TimeUnit.SECONDS.sleep(2) - Then(s"we call $ApiEndpoint4 to get the account back") val requestApiEndpoint4 = (v5_0_0_Request / "my" / "accounts" ).PUT <@(user1) val responseApiEndpoint4 = makeGetRequest(requestApiEndpoint4) @@ -141,9 +133,6 @@ class AccountTest extends V500ServerSetup with DefaultUsers { val response500 = makePutRequest(request500, write(putCreateAccountJson)) Then("We should get a 201") response500.code should equal(201) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(2) val account = response500.body.extract[CreateAccountResponseJsonV310] account.product_code should be (putCreateAccountJson.product_code) @@ -172,11 +161,6 @@ class AccountTest extends V500ServerSetup with DefaultUsers { Then("We should get a 201") responseUser2_500.code should equal(201) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(2) - - Then(s"we call $ApiEndpoint6 to get the account back by user2") val requestApiUser2Endpoint6 = (v5_0_0_Request /"banks" / testBankId.value / "accounts" / userAccountId / Constant.SYSTEM_OWNER_VIEW_ID/ "account" ).GET <@(user2) val responseApiUser2Endpoint6 = makeGetRequest(requestApiUser2Endpoint6) @@ -193,9 +177,6 @@ class AccountTest extends V500ServerSetup with DefaultUsers { Then("We should get a 201") response310_1.code should equal(201) - //for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method, - //it is an asynchronous process, need some time to be done. - TimeUnit.SECONDS.sleep(2) val account = response310_1.body.extract[CreateAccountResponseJsonV310] account.product_code should be (putCreateAccountJSONV310.product_code) account.`label` should be (putCreateAccountJSONV310.`label`)