feature/OBPv500 added the headAtms

This commit is contained in:
hongwei 2022-06-23 11:43:29 +02:00
parent 76a9b0fd91
commit d5cbefa436
5 changed files with 146 additions and 4 deletions

View File

@ -11471,8 +11471,7 @@ trait APIMethods400 {
EmptyBody,
atmsJsonV400,
List(
$UserNotLoggedIn,
InvalidJsonFormat,
$BankNotFound,
UnknownError
),
List(apiTagATM, apiTagNewStyle)

View File

@ -15,7 +15,8 @@ import com.openbankproject.commons.ExecutionContext.Implicits.global
import com.openbankproject.commons.model.{BankId, UserAuthContextUpdateStatus}
import com.openbankproject.commons.model.enums.StrongCustomerAuthentication
import com.openbankproject.commons.util.ApiVersion
import net.liftweb.common.Full
import net.liftweb.common.{Full}
import net.liftweb.http.{Req}
import net.liftweb.http.rest.RestHelper
import scala.collection.immutable.{List, Nil}
@ -27,6 +28,20 @@ trait APIMethods500 {
val Implementations5_0_0 = new Implementations500()
protected trait TestHead {
/**
* Test to see if the request is a GET and expecting JSON in the response.
* The path and the Req instance are extracted.
*/
def unapply(r: Req): Option[(List[String], Req)] =
if (r.requestType.head_? && testResponse_?(r))
Some(r.path.partPath -> r) else None
def testResponse_?(r: Req): Boolean
}
lazy val JsonHead = new TestHead with JsonTest
class Implementations500 {
val implementedInApiVersion = ApiVersion.v5_0_0
@ -226,6 +241,36 @@ trait APIMethods500 {
}
staticResourceDocs += ResourceDoc(
headAtms,
implementedInApiVersion,
nameOf(headAtms),
"HEAD",
"/banks/BANK_ID/atms",
"Head Bank ATMS",
s"""Head Bank ATMS.""",
EmptyBody,
atmsJsonV400,
List(
$BankNotFound,
UnknownError
),
List(apiTagATM, apiTagNewStyle)
)
lazy val headAtms : OBPEndpoint = {
case "banks" :: BankId(bankId) :: "atms" :: Nil JsonHead _ => {
cc =>
for {
(_, callContext) <- getAtmsIsPublic match {
case false => authenticatedAccess(cc)
case true => anonymousAccess(cc)
}
} yield {
("", HttpCode.`200`(callContext))
}
}
}
}
}

View File

@ -0,0 +1,75 @@
/**
Open Bank Project - API
Copyright (C) 2011-2019, TESOBE GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Email: contact@tesobe.com
TESOBE GmbH
Osloerstrasse 16/17
Berlin 13359, Germany
This product includes software developed at
TESOBE (http://www.tesobe.com/)
*/
package code.api.v5_0_0
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.{postUserAuthContextJson, postUserAuthContextUpdateJsonV310}
import code.api.util.APIUtil.OAuth._
import code.api.util.ApiRole._
import code.api.util.ErrorMessages._
import code.api.v3_1_0.CustomerJsonV310
import code.api.v5_0_0.OBPAPI5_0_0.Implementations5_0_0
import code.entitlement.Entitlement
import com.github.dwickern.macros.NameOf.nameOf
import com.openbankproject.commons.model.ErrorMessage
import com.openbankproject.commons.util.ApiVersion
import net.liftweb.json.Serialization.write
import org.scalatest.Tag
import scala.language.postfixOps
class ATMTest extends V500ServerSetupAsync {
/**
* Test tags
* Example: To run tests with tag "getPermissions":
* mvn test -D tagsToInclude
*
* This is made possible by the scalatest maven plugin
*/
object VersionOfApi extends Tag(ApiVersion.v5_0_0.toString)
object ApiEndpoint1 extends Tag(nameOf(Implementations5_0_0.headAtms))
feature("Head Bank ATMS v5.0.0") {
scenario("We will call the Add endpoint properly", ApiEndpoint1, VersionOfApi) {
When("We make a request v5.0.0")
lazy val bankId = randomBankId
val request500 = (v5_0_0_Request / "banks" / bankId / "atms").HEAD
val response500 = makeHeadRequest(request500)
Then("We should get a 200")
response500.code should equal(200)
}
scenario("We will call the Add endpoint with wrong BankId", ApiEndpoint1, VersionOfApi) {
When("We make a request v5.0.0")
val request500 = (v5_0_0_Request / "banks" / "xx_non_existing_bank_id" / "atms").HEAD
val response500 = makeHeadRequest(request500)
Then("We should get a 404")
response500.code should equal(404)
}
}
}

View File

@ -1,10 +1,23 @@
package code.api.v5_0_0
import code.api.v4_0_0.BanksJson400
import code.setup._
import dispatch.Req
import scala.util.Random.nextInt
trait V500ServerSetupAsync extends ServerSetupWithTestDataAsync with DefaultUsers {
def v5_0_0_Request: Req = baseRequest / "obp" / "v5.0.0"
def randomBankId : String = {
def getBanksInfo : APIResponse = {
val request = v5_0_0_Request / "banks"
makeGetRequest(request)
}
val banksJson = getBanksInfo.body.extract[BanksJson400]
val randomPosition = nextInt(banksJson.banks.size)
val bank = banksJson.banks(randomPosition)
bank.id
}
}

View File

@ -258,6 +258,16 @@ trait SendServerRequests {
val jsonReq = createRequest(reqData)
getAPIResponse(jsonReq)
}
/**
* this method does a HEAD request given a URL
*/
def makeHeadRequest(req: Req, params: List[(String, String)] = Nil) : APIResponse = {
val extra_headers = Map.empty ++ params
val reqData = extractParamsAndHeaders(req.HEAD, "", "UTF-8", extra_headers)
val jsonReq = createRequest(reqData)
getAPIResponse(jsonReq)
}
/**
* this method does a GET request given a URL
*/