Skip to content

Commit 9de2374

Browse files
authored
Merge pull request #2796 from hongwei1/develop-obp
fix(test): fix parallel test Props contamination and empty-list guards
2 parents 3007169 + c22d306 commit 9de2374

10 files changed

Lines changed: 2571 additions & 2603 deletions

File tree

obp-api/src/main/scala/code/api/ResourceDocs1_4_0/ResourceDocsAPIMethods.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth
179179
case ApiVersion.v1_2_1 => resourceDocs
180180
case ApiVersion.v6_0_0 => resourceDocs // fully on http4s — no Lift route filter
181181
case ApiVersion.v5_1_0 => resourceDocs // fully on http4s — no Lift route filter
182+
case ApiVersion.v5_0_0 => resourceDocs // fully on http4s — no Lift route filter
182183
case _ => resourceDocs.filter(rd => versionRoutesClasses.contains(rd.partialFunction.getClass))
183184
}
184185

obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala

Lines changed: 2534 additions & 2520 deletions
Large diffs are not rendered by default.

obp-api/src/main/scala/code/api/v5_0_0/Http4s500.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ object Http4s500 {
479479
}
480480

481481
resourceDocs += ResourceDoc(
482-
null, implementedInApiVersion, "createBank", "POST",
482+
null, implementedInApiVersion, nameOf(createBank), "POST",
483483
"/banks", "Create Bank",
484484
s"""Create a new bank (Authenticated access).
485485
|
@@ -535,7 +535,7 @@ object Http4s500 {
535535
}
536536

537537
resourceDocs += ResourceDoc(
538-
null, implementedInApiVersion, "updateBank", "PUT",
538+
null, implementedInApiVersion, nameOf(updateBank), "PUT",
539539
"/banks", "Update Bank",
540540
"Update an existing bank (Authenticated access).",
541541
postBankJson500, bankJson500,
@@ -615,7 +615,7 @@ object Http4s500 {
615615
}
616616

617617
resourceDocs += ResourceDoc(
618-
null, implementedInApiVersion, "createAccount", "PUT",
618+
null, implementedInApiVersion, nameOf(createAccount), "PUT",
619619
"/banks/BANK_ID/accounts/NEW_ACCOUNT_ID", "Create Account (PUT)",
620620
"""Create Account at bank specified by BANK_ID with Id specified by ACCOUNT_ID.
621621
|

obp-api/src/main/scala/code/api/v5_0_0/OBPAPI5_0_0.scala

Lines changed: 17 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -28,83 +28,37 @@ package code.api.v5_0_0
2828

2929
import scala.language.reflectiveCalls
3030
import code.api.OBPRestHelper
31-
import code.api.util.APIUtil.{OBPEndpoint, getAllowedEndpoints}
32-
import code.api.util.{APIUtil, VersionedOBPApis}
33-
import code.api.v1_3_0.APIMethods130
34-
import code.api.v1_4_0.APIMethods140
35-
import code.api.v2_0_0.APIMethods200
36-
import code.api.v2_1_0.APIMethods210
37-
import code.api.v2_2_0.APIMethods220
38-
import code.api.v3_0_0.APIMethods300
39-
import code.api.v3_0_0.custom.CustomAPIMethods300
40-
import code.api.v3_1_0.{APIMethods310, OBPAPI3_1_0}
41-
import code.api.v4_0_0.{APIMethods400, OBPAPI4_0_0}
42-
import code.api.v4_0_0.OBPAPI4_0_0.{Implementations4_0_0, endpointsOf4_0_0}
31+
import code.api.util.APIUtil.OBPEndpoint
32+
import code.api.util.VersionedOBPApis
33+
import code.api.v4_0_0.OBPAPI4_0_0
4334
import code.util.Helper.MdcLoggable
44-
import com.github.dwickern.macros.NameOf.nameOf
4535
import com.openbankproject.commons.util.{ApiVersion, ApiVersionStatus}
46-
import net.liftweb.common.{Box, Full}
47-
import net.liftweb.http.{LiftResponse, PlainTextResponse}
48-
import org.apache.http.HttpStatus
4936

5037
/*
51-
This file defines which endpoints from all the versions are available in v5.0.0
38+
This file defines which endpoints from all the versions are available in v5.0.0.
39+
All v5.0.0 endpoints have been migrated to Http4s500 — this object is retained
40+
only for resource-doc aggregation and the Lift dispatch registry.
5241
*/
53-
object OBPAPI5_0_0 extends OBPRestHelper
54-
with APIMethods130
55-
with APIMethods140
56-
with APIMethods200
57-
with APIMethods210
58-
with APIMethods220
59-
with APIMethods300
60-
with CustomAPIMethods300
61-
with APIMethods310
62-
with APIMethods400
63-
with APIMethods500
64-
with MdcLoggable
65-
with VersionedOBPApis{
42+
object OBPAPI5_0_0 extends OBPRestHelper with MdcLoggable with VersionedOBPApis {
6643

67-
val version : ApiVersion = ApiVersion.v5_0_0
44+
val version: ApiVersion = ApiVersion.v5_0_0
45+
val versionStatus = ApiVersionStatus.STABLE.toString
6846

69-
val versionStatus = ApiVersionStatus.STABLE.toString
47+
// Re-export so tests that import OBPAPI5_0_0.Implementations5_0_0 still compile
48+
// after APIMethods500 is replaced with an empty stub.
49+
val Implementations5_0_0 = Http4s500.Implementations5_0_0
7050

71-
// Possible Endpoints from 5.0.0, exclude one endpoint use - method,exclude multiple endpoints use -- method,
72-
// e.g getEndpoints(Implementations5_0_0) -- List(Implementations5_0_0.genericEndpoint, Implementations5_0_0.root)
73-
lazy val endpointsOf5_0_0 = getEndpoints(Implementations5_0_0)
74-
75-
// if old version ResourceDoc objects have the same name endpoint with new version, omit old version ResourceDoc.
51+
// All v5.0.0 endpoints live in Http4s500 — aggregate Http4s500.resourceDocs on top of v4.0.0.
7652
def allResourceDocs = collectResourceDocs(
7753
OBPAPI4_0_0.allResourceDocs,
78-
Implementations5_0_0.resourceDocs
54+
Http4s500.resourceDocs
7955
)
8056

81-
// all endpoints
82-
private val endpoints: List[OBPEndpoint] = OBPAPI4_0_0.routes ++ endpointsOf5_0_0
83-
84-
// Filter the possible endpoints by the disabled / enabled Props settings and add them together
85-
val routes : List[OBPEndpoint] = getAllowedEndpoints(endpoints, allResourceDocs)
57+
// No Lift routes — all v5.0.0 endpoints are served by Http4s500.
58+
val routes: List[OBPEndpoint] = Nil
8659

87-
// register v5.0.0 apis first, Make them available for use!
8860
registerRoutes(routes, allResourceDocs, apiPrefix, true)
8961

90-
9162
logger.info(s"version $version has been run! There are ${routes.length} routes, ${allResourceDocs.length} allResourceDocs.")
92-
93-
// specified response for OPTIONS request.
94-
private val corsResponse: Box[LiftResponse] = Full{
95-
val corsHeaders = List(
96-
"Access-Control-Allow-Origin" -> "*",
97-
"Access-Control-Allow-Methods" -> "GET, POST, OPTIONS, PUT, PATCH, DELETE",
98-
"Access-Control-Allow-Headers" -> "*",
99-
"Access-Control-Allow-Credentials" -> "true",
100-
"Access-Control-Max-Age" -> "1728000" //Tell client that this pre-flight info is valid for 20 days
101-
)
102-
PlainTextResponse("", corsHeaders, HttpStatus.SC_NO_CONTENT)
103-
}
104-
/*
105-
* process OPTIONS http request, just return no content and status is 204
106-
*/
107-
this.serve({
108-
case req if req.requestType.method == "OPTIONS" => corsResponse
109-
})
63+
// CORS for OPTIONS is handled by the http4s corsHandler layer — no Lift serve needed here.
11064
}

obp-api/src/main/scala/code/api/v6_0_0/Http4s600.scala

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import code.api.util.http4s.{ErrorResponseConverter, RequestScopeConnection, Res
1313
import code.api.util.http4s.Http4sRequestAttributes.{EndpointHelpers, RequestOps}
1414
import code.api.util.newstyle.ViewNewStyle
1515
import code.api.v2_0_0.JSONFactory200
16-
import code.api.v5_0_0.Http4s500
1716
import code.api.v5_1_0.{Http4s510, JSONFactory510}
1817
import code.api.v6_0_0.JSONFactory600.ScannedApiVersionJsonV600
1918
import code.accountattribute.AccountAttributeX
@@ -8504,21 +8503,17 @@ object Http4s600 {
85048503
val allRoutesWithMiddleware: HttpRoutes[IO] =
85058504
ResourceDocMiddleware.apply(resourceDocs)(allRoutes)
85068505

8507-
// ─── path-rewriting bridge: /obp/v6.0.0/… → /obp/v5.1.0/… → /obp/v5.0.0/… ──
8508-
// Tries v5.1.0 native Http4s routes first; if not handled there, falls back to
8509-
// the v5.0.0 cascade (v5.0.0 → v4.0.0 → v3.1.0 → v3.0.0).
8506+
// ─── path-rewriting bridge: /obp/v6.0.0/… → /obp/v5.1.0/… ─────────────
8507+
// Targets v5.1.0; Http4s510 has its own working cascade down to v5.0.0 → v4.0.0 → …
85108508
// NOT appended to allRoutes — see object-level scaladoc.
8511-
val v600ToV510Bridge: HttpRoutes[IO] = Kleisli[HttpF, Request[IO], Response[IO]] { req =>
8509+
lazy val v600ToV510Bridge: HttpRoutes[IO] = Kleisli[HttpF, Request[IO], Response[IO]] { req =>
85128510
val rawPath = req.uri.path.renderString
8513-
if (rawPath.startsWith("/obp/v6.0.0/")) {
8514-
val path510 = rawPath.replaceFirst("/obp/v6\\.0\\.0/", "/obp/v5.1.0/")
8515-
val req510 = req.withUri(req.uri.withPath(Uri.Path.unsafeFromString(path510)))
8516-
Http4s510.wrappedRoutesV510Services.run(req510)
8517-
.orElse {
8518-
val path500 = rawPath.replaceFirst("/obp/v6\\.0\\.0/", "/obp/v5.0.0/")
8519-
val req500 = req.withUri(req.uri.withPath(Uri.Path.unsafeFromString(path500)))
8520-
Http4s500.wrappedRoutesV500Services.run(req500)
8521-
}
8511+
if (rawPath.startsWith("/obp/v6.0.0/") &&
8512+
ResourceDocMatcher.findResourceDoc(req.method.name, req.uri.path, v6ResourceDocIndex).isEmpty) {
8513+
val rewritten = rawPath.replaceFirst("/obp/v6\\.0\\.0/", "/obp/v5.1.0/")
8514+
val newUri = req.uri.withPath(Uri.Path.unsafeFromString(rewritten))
8515+
Http4s510.wrappedRoutesV510Services.run(req.withUri(newUri))
8516+
.map(_.putHeaders(Header.Raw(CIString("X-OBP-Version-Served"), "v5.1.0")))
85228517
} else {
85238518
OptionT.none[IO, Response[IO]]
85248519
}
15 Bytes
Binary file not shown.

obp-api/src/test/scala/code/api/v4_0_0/GetScannedApiVersionsTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ import code.api.util.APIUtil
2929
import code.api.util.ApiRole._
3030
import code.api.v4_0_0.APIMethods400.Implementations4_0_0
3131
import code.entitlement.Entitlement
32+
import code.setup.PropsReset
3233
import com.github.dwickern.macros.NameOf.nameOf
3334
import com.openbankproject.commons.model.ListResult
3435
import com.openbankproject.commons.util.{ApiVersion, ScannedApiVersion}
3536
import org.scalatest.Tag
3637

3738
import scala.collection.JavaConverters._
38-
class GetScannedApiVersionsTest extends V400ServerSetup {
39+
class GetScannedApiVersionsTest extends V400ServerSetup with PropsReset {
3940

4041
/**
4142
* Test tags

obp-api/src/test/scala/code/api/v5_0_0/V500ServerSetup.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ trait V500ServerSetup extends ServerSetupWithTestData with DefaultUsers {
2929
makeGetRequest(request)
3030
}
3131
val banksJson = getBanksInfo.body.extract[BanksJson400]
32+
if (banksJson.banks.isEmpty) return "DEFAULT_BANK_ID_NOT_SET_Test"
3233
val randomPosition = nextInt(banksJson.banks.size)
3334
val bank = banksJson.banks(randomPosition)
3435
bank.id

obp-api/src/test/scala/code/api/v5_1_0/V510ServerSetup.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ trait V510ServerSetup extends ServerSetupWithTestData with DefaultUsers {
5858

5959
def randomPrivateAccount(bankId: String): AccountJSON = {
6060
val accountsJson = getPrivateAccounts(bankId, user1).body.extract[AccountsJSON].accounts
61+
if (accountsJson.isEmpty) throw new IllegalStateException(s"No private accounts found for bank $bankId")
6162
val randomPosition = nextInt(accountsJson.size)
6263
accountsJson(randomPosition)
6364
}
@@ -66,9 +67,10 @@ trait V510ServerSetup extends ServerSetupWithTestData with DefaultUsers {
6667
val request = v5_1_0_Request / "banks" / bankId / "accounts" / "private" <@(consumerAndToken)
6768
makeGetRequest(request)
6869
}
69-
70+
7071
def randomPrivateAccountViaEndpoint(bankId : String): AccountJSON = {
7172
val accountsJson = getPrivateAccountsViaEndpoint(bankId, user1).body.extract[AccountsJSON].accounts
73+
if (accountsJson.isEmpty) throw new IllegalStateException(s"No private accounts found via endpoint for bank $bankId")
7274
val randomPosition = nextInt(accountsJson.size)
7375
accountsJson(randomPosition)
7476
}

obp-api/src/test/scala/code/util/APIUtilHeavyTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class APIUtilHeavyTest extends V400ServerSetup with PropsReset {
4444
val bgVersion = ConstantsBG.berlinGroupVersion1.apiShortVersion
4545

4646
feature("test APIUtil.versionIsAllowed method") {
47-
scenario("various disabled/enabled version combinations") {
47+
scenario("Test versionIsAllowed with various disabled/enabled version combinations") {
4848
//This mean, we are only disabled the v4.0.0, all other versions should be enabled
4949
setPropsValues(
5050
"api_disabled_versions" -> "[v4.0.0]",

0 commit comments

Comments
 (0)