diff --git a/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala b/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala index 6cff9706b..7f475ca08 100644 --- a/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala +++ b/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala @@ -26,13 +26,82 @@ object SwaggerDefinitionsJSON { amount = "100" ) - val createViewJSON = CreateViewJSON( + val createViewJson = CreateViewJson( name = "test", description = "good", is_public = true, which_alias_to_use = "good", - hide_metadata_if_alias_used = true, - allowed_actions = List("good") + hide_metadata_if_alias_used = false, + allowed_actions = List( + "can_see_transaction_this_bank_account", + "can_see_transaction_other_bank_account", + "can_see_transaction_metadata", + "can_see_transaction_label", + "can_see_transaction_amount", + "can_see_transaction_type", + "can_see_transaction_currency", + "can_see_transaction_start_date", + "can_see_transaction_finish_date", + "can_see_transaction_balance", + "can_see_comments", + "can_see_narrative", "can_see_tags", + "can_see_images", + "can_see_bank_account_owners", + "can_see_bank_account_type", + "can_see_bank_account_balance", + "can_see_bank_account_currency", + "can_see_bank_account_label", + "can_see_bank_account_national_identifier", + "can_see_bank_account_swift_bic", + "can_see_bank_account_iban", + "can_see_bank_account_number", + "can_see_bank_account_bank_name", + "can_see_other_account_national_identifier", + "can_see_other_account_swift_bic", + "can_see_other_account_iban", + "can_see_other_account_bank_name", + "can_see_other_account_number", + "can_see_other_account_metadata", + "can_see_other_account_kind", + "can_see_more_info", + "can_see_url", + "can_see_image_url", + "can_see_open_corporates_url", + "can_see_corporate_location", + "can_see_physical_location", + "can_see_public_alias", + "can_see_private_alias", + "can_add_more_info", + "can_add_url", + "can_add_image_url", + "can_add_open_corporates_url", + "can_add_corporate_location", + "can_add_physical_location", + "can_add_public_alias", + "can_add_private_alias", + "can_delete_corporate_location", + "can_delete_physical_location", + "can_edit_narrative", + "can_add_comment", + "can_delete_comment", + "can_add_tag", + "can_delete_tag", + "can_add_image", + "can_delete_image", + "can_add_where_tag", + "can_see_where_tag", + "can_delete_where_tag", + "can_create_counterparty", + //V300 New + "can_see_bank_routing_scheme", + "can_see_bank_routing_address", + "can_see_bank_account_routing_scheme", + "can_see_bank_account_routing_address", + "can_see_other_bank_routing_scheme", + "can_see_other_bank_routing_address", + "can_see_other_account_routing_scheme", + "can_see_other_account_routing_addres" + ) ) val updateViewJSON = UpdateViewJSON( @@ -40,7 +109,76 @@ object SwaggerDefinitionsJSON { is_public = true, which_alias_to_use = "good", hide_metadata_if_alias_used = true, - allowed_actions = List("good") + allowed_actions = List( + "can_see_transaction_this_bank_account", + "can_see_transaction_other_bank_account", + "can_see_transaction_metadata", + "can_see_transaction_label", + "can_see_transaction_amount", + "can_see_transaction_type", + "can_see_transaction_currency", + "can_see_transaction_start_date", + "can_see_transaction_finish_date", + "can_see_transaction_balance", + "can_see_comments", + "can_see_narrative", "can_see_tags", + "can_see_images", + "can_see_bank_account_owners", + "can_see_bank_account_type", + "can_see_bank_account_balance", + "can_see_bank_account_currency", + "can_see_bank_account_label", + "can_see_bank_account_national_identifier", + "can_see_bank_account_swift_bic", + "can_see_bank_account_iban", + "can_see_bank_account_number", + "can_see_bank_account_bank_name", + "can_see_other_account_national_identifier", + "can_see_other_account_swift_bic", + "can_see_other_account_iban", + "can_see_other_account_bank_name", + "can_see_other_account_number", + "can_see_other_account_metadata", + "can_see_other_account_kind", + "can_see_more_info", + "can_see_url", + "can_see_image_url", + "can_see_open_corporates_url", + "can_see_corporate_location", + "can_see_physical_location", + "can_see_public_alias", + "can_see_private_alias", + "can_add_more_info", + "can_add_url", + "can_add_image_url", + "can_add_open_corporates_url", + "can_add_corporate_location", + "can_add_physical_location", + "can_add_public_alias", + "can_add_private_alias", + "can_delete_corporate_location", + "can_delete_physical_location", + "can_edit_narrative", + "can_add_comment", + "can_delete_comment", + "can_add_tag", + "can_delete_tag", + "can_add_image", + "can_delete_image", + "can_add_where_tag", + "can_see_where_tag", + "can_delete_where_tag", + "can_create_counterparty", + //V300 New + "can_see_bank_routing_scheme", + "can_see_bank_routing_address", + "can_see_bank_account_routing_scheme", + "can_see_bank_account_routing_address", + "can_see_other_bank_routing_scheme", + "can_see_other_bank_routing_address", + "can_see_other_account_routing_scheme", + "can_see_other_account_routing_addres" + ) ) val transactionTypeId = TransactionTypeId(value = "123") diff --git a/src/main/scala/code/api/v1_2/OBPAPI1.2.scala b/src/main/scala/code/api/v1_2/OBPAPI1.2.scala index f896ed22b..cf67d71f5 100644 --- a/src/main/scala/code/api/v1_2/OBPAPI1.2.scala +++ b/src/main/scala/code/api/v1_2/OBPAPI1.2.scala @@ -209,7 +209,7 @@ object OBPAPI1_2 extends OBPRestHelper with MdcLoggable { case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "views" :: Nil JsonPost json -> _ => { user => for { - json <- tryo{json.extract[CreateViewJSON]} ?~ "wrong JSON format" + json <- tryo{json.extract[CreateViewJson]} ?~ "wrong JSON format" u <- user ?~ "user not found" account <- BankAccount(bankId, accountId) view <- account createView (u, json) diff --git a/src/main/scala/code/api/v1_2_1/APIMethods121.scala b/src/main/scala/code/api/v1_2_1/APIMethods121.scala index c2995dce4..1494eaad8 100644 --- a/src/main/scala/code/api/v1_2_1/APIMethods121.scala +++ b/src/main/scala/code/api/v1_2_1/APIMethods121.scala @@ -8,7 +8,7 @@ import code.api.util.APIUtil._ import code.api.util.ErrorMessages._ import code.bankconnectors.{OBPFromDate, OBPOffset, OBPToDate, _} import code.metadata.counterparties.Counterparties -import code.model.{CreateViewJSON, UpdateViewJSON, _} +import code.model.{CreateViewJson, UpdateViewJSON, _} import net.liftweb.common.{Full, _} import net.liftweb.http.rest.RestHelper import net.liftweb.http.{JsonResponse, Req} @@ -519,7 +519,7 @@ trait APIMethods121 { | The 'hide_metadata_if_alias_used' field in the JSON can take boolean values. If it is set to `true` and there is an alias on the other account then the other accounts' metadata (like more_info, url, image_url, open_corporates_url, etc.) will be hidden. Otherwise the metadata will be shown. | | The 'allowed_actions' field is a list containing the name of the actions allowed on this view, all the actions contained will be set to `true` on the view creation, the rest will be set to `false`.""", - createViewJSON, + createViewJson, viewJSONV121, List( UserNotLoggedIn, @@ -538,7 +538,7 @@ trait APIMethods121 { user => for { u <- user ?~ UserNotLoggedIn - json <- tryo{json.extract[CreateViewJSON]} ?~ InvalidJsonFormat + json <- tryo{json.extract[CreateViewJson]} ?~ InvalidJsonFormat account <- BankAccount(bankId, accountId) ?~! BankAccountNotFound view <- account createView (u, json) } yield { diff --git a/src/main/scala/code/api/v2_2_0/APIMethods220.scala b/src/main/scala/code/api/v2_2_0/APIMethods220.scala index 8c735c656..d78e3b040 100644 --- a/src/main/scala/code/api/v2_2_0/APIMethods220.scala +++ b/src/main/scala/code/api/v2_2_0/APIMethods220.scala @@ -159,7 +159,7 @@ trait APIMethods220 { | | You should use a leading _ (underscore) for the view name because other view names may become reserved by OBP internally | """, - createViewJSON, + createViewJson, viewJSONV220, List( UserNotLoggedIn, @@ -175,7 +175,7 @@ trait APIMethods220 { case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "views" :: Nil JsonPost json -> _ => { user => for { - json <- tryo{json.extract[CreateViewJSON]} ?~!InvalidJsonFormat + json <- tryo{json.extract[CreateViewJson]} ?~!InvalidJsonFormat u <- user ?~!UserNotLoggedIn account <- BankAccount(bankId, accountId) ?~! BankAccountNotFound view <- account createView (u, json) diff --git a/src/main/scala/code/api/v3_0_0/APIMethods300.scala b/src/main/scala/code/api/v3_0_0/APIMethods300.scala index c8798e737..ec5b78fe4 100644 --- a/src/main/scala/code/api/v3_0_0/APIMethods300.scala +++ b/src/main/scala/code/api/v3_0_0/APIMethods300.scala @@ -130,7 +130,7 @@ trait APIMethods300 { | | You should use a leading _ (underscore) for the view name because other view names may become reserved by OBP internally | """, - SwaggerDefinitionsJSON.createViewJSON, + SwaggerDefinitionsJSON.createViewJson, viewJsonV300, List( UserNotLoggedIn, @@ -146,7 +146,7 @@ trait APIMethods300 { case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "views" :: Nil JsonPost json -> _ => { user => for { - json <- tryo{json.extract[CreateViewJSON]} ?~!InvalidJsonFormat + json <- tryo{json.extract[CreateViewJson]} ?~!InvalidJsonFormat u <- user ?~!UserNotLoggedIn account <- BankAccount(bankId, accountId) ?~! BankAccountNotFound view <- account createView (u, json) diff --git a/src/main/scala/code/model/BankingData.scala b/src/main/scala/code/model/BankingData.scala index b1ed73df9..02820b543 100644 --- a/src/main/scala/code/model/BankingData.scala +++ b/src/main/scala/code/model/BankingData.scala @@ -479,7 +479,7 @@ trait BankAccount extends MdcLoggable { Failure("user : " + user.emailAddress + " does not have access to owner view on account " + accountId, Empty, Empty) } - final def createView(userDoingTheCreate : User,v: CreateViewJSON): Box[View] = { + final def createView(userDoingTheCreate : User,v: CreateViewJson): Box[View] = { if(!userDoingTheCreate.ownerAccess(this)) { Failure({"user: " + userDoingTheCreate.idGivenByProvider + " at provider " + userDoingTheCreate.provider + " does not have owner access"}) } else { diff --git a/src/main/scala/code/model/View.scala b/src/main/scala/code/model/View.scala index 1ff142343..43b94606c 100644 --- a/src/main/scala/code/model/View.scala +++ b/src/main/scala/code/model/View.scala @@ -70,7 +70,7 @@ trait ViewSpecification { /* The JSON that should be supplied to create a view. Conforms to ViewSpecification */ -case class CreateViewJSON( +case class CreateViewJson( name: String, description: String, is_public: Boolean, diff --git a/src/main/scala/code/remotedata/RemotedataViews.scala b/src/main/scala/code/remotedata/RemotedataViews.scala index 56589bb88..585a7b3fa 100644 --- a/src/main/scala/code/remotedata/RemotedataViews.scala +++ b/src/main/scala/code/remotedata/RemotedataViews.scala @@ -2,7 +2,7 @@ package code.remotedata import akka.pattern.ask import code.actorsystem.ObpActorInit -import code.model.{CreateViewJSON, Permission, UpdateViewJSON, _} +import code.model.{CreateViewJson, Permission, UpdateViewJSON, _} import code.views.{RemotedataViewsCaseClasses, Views} import net.liftweb.common.{Box, Full} import scala.collection.immutable.List @@ -33,7 +33,7 @@ object RemotedataViews extends ObpActorInit with Views { def view(viewId : ViewId, account: BankAccountUID) : Box[View] = extractFutureToBox(actor ? cc.view(viewId, account)) - def createView(bankAccountId: BankAccountUID, view: CreateViewJSON): Box[View] = + def createView(bankAccountId: BankAccountUID, view: CreateViewJson): Box[View] = extractFutureToBox(actor ? cc.createView(bankAccountId, view)) def updateView(bankAccountId : BankAccountUID, viewId: ViewId, viewUpdateJson : UpdateViewJSON) : Box[View] = diff --git a/src/main/scala/code/remotedata/RemotedataViewsActor.scala b/src/main/scala/code/remotedata/RemotedataViewsActor.scala index 29719bd5c..aca329da9 100644 --- a/src/main/scala/code/remotedata/RemotedataViewsActor.scala +++ b/src/main/scala/code/remotedata/RemotedataViewsActor.scala @@ -42,7 +42,7 @@ class RemotedataViewsActor extends Actor with ObpActorHelper with MdcLoggable { logger.debug("view(" + viewId +", "+ bankAccountId + ")") sender ! extractResult(mapper.view(viewId, bankAccountId)) - case cc.createView(bankAccountId : BankAccountUID, view: CreateViewJSON) => + case cc.createView(bankAccountId : BankAccountUID, view: CreateViewJson) => logger.debug("createView(" + bankAccountId +","+ view +")") sender ! extractResult(mapper.createView(bankAccountId, view)) diff --git a/src/main/scala/code/views/MapperViews.scala b/src/main/scala/code/views/MapperViews.scala index cf44db9a7..d7a6627d2 100644 --- a/src/main/scala/code/views/MapperViews.scala +++ b/src/main/scala/code/views/MapperViews.scala @@ -5,7 +5,7 @@ import code.accountholder.{AccountHolders, MapperAccountHolders} import code.api.APIFailure import code.model.dataAccess.ViewImpl.create import code.model.dataAccess.{ResourceUser, ViewImpl, ViewPrivileges} -import code.model.{CreateViewJSON, Permission, UpdateViewJSON, User, _} +import code.model.{CreateViewJson, Permission, UpdateViewJSON, User, _} import net.liftweb.common._ import net.liftweb.mapper.{By, Schemifier} import net.liftweb.util.Helpers._ @@ -203,7 +203,7 @@ object MapperViews extends Views with MdcLoggable { /* Create View based on the Specification (name, alias behavior, what fields can be seen, actions are allowed etc. ) * */ - def createView(bankAccountId: BankAccountUID, view: CreateViewJSON): Box[View] = { + def createView(bankAccountId: BankAccountUID, view: CreateViewJson): Box[View] = { if(view.is_public && !ALLOW_PUBLIC_VIEWS) { return Failure(AllowPublicViewsNotSpecified) diff --git a/src/main/scala/code/views/Views.scala b/src/main/scala/code/views/Views.scala index 120f4b901..0d090aab7 100644 --- a/src/main/scala/code/views/Views.scala +++ b/src/main/scala/code/views/Views.scala @@ -4,7 +4,7 @@ import net.liftweb.common.Box import code.model._ import net.liftweb.util.SimpleInjector import code.model.Permission -import code.model.CreateViewJSON +import code.model.CreateViewJson import code.remotedata.RemotedataViews object Views extends SimpleInjector { @@ -29,7 +29,7 @@ trait Views { def view(viewId : ViewId, bankAccountId: BankAccountUID) : Box[View] def view(viewUID : ViewUID) : Box[View] - def createView(bankAccountId: BankAccountUID, view: CreateViewJSON): Box[View] + def createView(bankAccountId: BankAccountUID, view: CreateViewJson): Box[View] def removeView(viewId: ViewId, bankAccountId: BankAccountUID): Box[Unit] def updateView(bankAccountId : BankAccountUID, viewId : ViewId, viewUpdateJson : UpdateViewJSON) : Box[View] def views(bankAccountId : BankAccountUID) : List[View] @@ -71,7 +71,7 @@ class RemotedataViewsCaseClasses { case class addPermissions(views: List[ViewUID], user: User) case class revokePermission(viewUID: ViewUID, user: User) case class revokeAllPermissions(bankId: BankId, accountId: AccountId, user: User) - case class createView(bankAccountId: BankAccountUID, view: CreateViewJSON) + case class createView(bankAccountId: BankAccountUID, view: CreateViewJson) case class removeView(viewId: ViewId, bankAccountId: BankAccountUID) case class updateView(bankAccountId: BankAccountUID, viewId: ViewId, viewUpdateJson: UpdateViewJSON) case class views(bankAccountId: BankAccountUID) diff --git a/src/test/scala/code/api/v1_2_0/API12Test.scala b/src/test/scala/code/api/v1_2_0/API12Test.scala index a31fc4cbb..81c2b223f 100644 --- a/src/test/scala/code/api/v1_2_0/API12Test.scala +++ b/src/test/scala/code/api/v1_2_0/API12Test.scala @@ -53,8 +53,6 @@ class API1_2Test extends User1AllPrivileges with DefaultUsers { def v1_2Request = baseRequest / "obp" / "v1.2" - implicit val dateFormats = net.liftweb.json.DefaultFormats - val viewFileds = List( "can_see_transaction_this_bank_account","can_see_transaction_other_bank_account", "can_see_transaction_metadata","can_see_transaction_label","can_see_transaction_amount", @@ -157,9 +155,6 @@ class API1_2Test extends User1AllPrivileges with DefaultUsers { object GetTransactionAccount extends Tag("getTransactionAccount") /********************* API test methods ********************/ - val emptyJSON : JObject = - ("error" -> "empty List") - val errorAPIResponse = new APIResponse(400,emptyJSON) def randomViewPermalink(bankId: String, account: AccountJSON) : String = { val request = v1_2Request / "banks" / bankId / "accounts" / account.id / "views" <@(consumer, token1) @@ -232,8 +227,8 @@ class API1_2Test extends User1AllPrivileges with DefaultUsers { viewsIdsToGrant } - def randomView(isPublic: Boolean, alias: String) : CreateViewJSON = { - CreateViewJSON( + def randomView(isPublic: Boolean, alias: String) : CreateViewJson = { + CreateViewJson( name = randomString(3), description = randomString(3), is_public = isPublic, @@ -287,7 +282,7 @@ class API1_2Test extends User1AllPrivileges with DefaultUsers { makeGetRequest(request) } - def postView(bankId: String, accountId: String, view: CreateViewJSON, consumerAndToken: Option[(Consumer, Token)]): APIResponse = { + def postView(bankId: String, accountId: String, view: CreateViewJson, consumerAndToken: Option[(Consumer, Token)]): APIResponse = { val request = (v1_2Request / "banks" / bankId / "accounts" / accountId / "views").POST <@(consumerAndToken) makePostRequest(request, write(view)) } diff --git a/src/test/scala/code/api/v1_2_1/API121Test.scala b/src/test/scala/code/api/v1_2_1/API121Test.scala index de18d8fc9..141634de7 100644 --- a/src/test/scala/code/api/v1_2_1/API121Test.scala +++ b/src/test/scala/code/api/v1_2_1/API121Test.scala @@ -51,8 +51,6 @@ class API1_2_1Test extends User1AllPrivileges with DefaultUsers with PrivateUser def v1_2Request = baseRequest / "obp" / "v1.2.1" - implicit val dateFormats = net.liftweb.json.DefaultFormats - val viewFields = List( "can_see_transaction_this_bank_account","can_see_transaction_other_bank_account", "can_see_transaction_metadata","can_see_transaction_label","can_see_transaction_amount", @@ -161,10 +159,6 @@ class API1_2_1Test extends User1AllPrivileges with DefaultUsers with PrivateUser object Payments extends Tag("payments") /********************* API test methods ********************/ - val emptyJSON : JObject = - ("error" -> "empty List") - val errorAPIResponse = new APIResponse(400,emptyJSON) - def randomViewPermalink(bankId: String, account: AccountJSON) : String = { val request = v1_2Request / "banks" / bankId / "accounts" / account.id / "views" <@(consumer, token1) val reply = makeGetRequest(request) @@ -241,8 +235,8 @@ class API1_2_1Test extends User1AllPrivileges with DefaultUsers with PrivateUser viewsIdsToGrant } - def randomView(isPublic: Boolean, alias: String) : CreateViewJSON = { - CreateViewJSON( + def randomView(isPublic: Boolean, alias: String) : CreateViewJson = { + CreateViewJson( name = randomString(3), description = randomString(3), is_public = isPublic, @@ -313,7 +307,7 @@ class API1_2_1Test extends User1AllPrivileges with DefaultUsers with PrivateUser makeGetRequest(request) } - def postView(bankId: String, accountId: String, view: CreateViewJSON, consumerAndToken: Option[(Consumer, Token)]): APIResponse = { + def postView(bankId: String, accountId: String, view: CreateViewJson, consumerAndToken: Option[(Consumer, Token)]): APIResponse = { val request = (v1_2Request / "banks" / bankId / "accounts" / accountId / "views").POST <@(consumerAndToken) makePostRequest(request, write(view)) } @@ -1463,7 +1457,7 @@ class API1_2_1Test extends User1AllPrivileges with DefaultUsers with PrivateUser val bankId = randomBank val bankAccount : AccountJSON = randomPrivateAccount(bankId) val viewsBefore = getAccountViews(bankId, bankAccount.id, user1).body.extract[ViewsJSONV121].views - val viewWithEmptyName = CreateViewJSON( + val viewWithEmptyName = CreateViewJson( name = "", description = randomString(3), is_public = true, diff --git a/src/test/scala/code/api/v1_3_0/PhysicalCardsTest.scala b/src/test/scala/code/api/v1_3_0/PhysicalCardsTest.scala index f93b9a518..02ac9ea42 100644 --- a/src/test/scala/code/api/v1_3_0/PhysicalCardsTest.scala +++ b/src/test/scala/code/api/v1_3_0/PhysicalCardsTest.scala @@ -21,8 +21,6 @@ import code.util.Helper.MdcLoggable class PhysicalCardsTest extends ServerSetup with DefaultUsers with DefaultConnectorTestSetup { - implicit val dateFormats = net.liftweb.json.DefaultFormats - def v1_3Request = baseRequest / "obp" / "v1.3.0" lazy val bank = createBank("a-bank") diff --git a/src/test/scala/code/api/v2_2_0/API2_2_0Test.scala b/src/test/scala/code/api/v2_2_0/API2_2_0Test.scala index 92f8c5133..68af02a1c 100644 --- a/src/test/scala/code/api/v2_2_0/API2_2_0Test.scala +++ b/src/test/scala/code/api/v2_2_0/API2_2_0Test.scala @@ -32,13 +32,12 @@ Berlin 13359, Germany package code.api.v2_2_0 -import _root_.net.liftweb.json.JsonAST.JObject import _root_.net.liftweb.json.Serialization.write +import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.createViewJson import code.api.util.APIUtil.OAuth._ import code.api.v1_2._ -import code.model.{Consumer => OBPConsumer, Token => OBPToken, _} +import code.model.{CreateViewJson, UpdateViewJSON} import code.setup.{APIResponse, DefaultUsers, User1AllPrivileges} -import net.liftweb.json.JsonDSL._ import net.liftweb.util.Helpers._ import org.scalatest._ @@ -47,30 +46,6 @@ import scala.util.Random._ class API2_2_0Test extends User1AllPrivileges with V220ServerSetup with DefaultUsers { - implicit val dateFormats = net.liftweb.json.DefaultFormats - - val viewFileds = List( - "can_see_transaction_this_bank_account","can_see_transaction_other_bank_account", - "can_see_transaction_metadata","can_see_transaction_label","can_see_transaction_amount", - "can_see_transaction_type","can_see_transaction_currency","can_see_transaction_start_date", - "can_see_transaction_finish_date","can_see_transaction_balance","can_see_comments", - "can_see_narrative","can_see_tags","can_see_images","can_see_bank_account_owners", - "can_see_bank_account_type","can_see_bank_account_balance","can_see_bank_account_currency", - "can_see_bank_account_label","can_see_bank_account_national_identifier", - "can_see_bank_account_swift_bic","can_see_bank_account_iban","can_see_bank_account_number", - "can_see_bank_account_bank_name","can_see_other_account_national_identifier", - "can_see_other_account_swift_bic","can_see_other_account_iban", - "can_see_other_account_bank_name","can_see_other_account_number", - "can_see_other_account_metadata","can_see_other_account_kind","can_see_more_info", - "can_see_url","can_see_image_url","can_see_open_corporates_url","can_see_corporate_location", - "can_see_physical_location","can_see_public_alias","can_see_private_alias","can_add_more_info", - "can_add_url","can_add_image_url","can_add_open_corporates_url","can_add_corporate_location", - "can_add_physical_location","can_add_public_alias","can_add_private_alias", - "can_delete_corporate_location","can_delete_physical_location","can_edit_narrative", - "can_add_comment","can_delete_comment","can_add_tag","can_delete_tag","can_add_image", - "can_delete_image","can_add_where_tag","can_see_where_tag","can_delete_where_tag", "can_create_counterparty" - ) - /************************* test tags ************************/ /** @@ -91,12 +66,6 @@ class API2_2_0Test extends User1AllPrivileges with V220ServerSetup with DefaultU /********************* API test methods ********************/ - val emptyJSON : JObject = - ("error" -> "empty List") - val errorAPIResponse = new APIResponse(400,emptyJSON) - - - def randomBank : String = { val banksJson = getBanksInfo.body.extract[BanksJSON] @@ -119,16 +88,7 @@ class API2_2_0Test extends User1AllPrivileges with V220ServerSetup with DefaultU viewsIdsToGrant } - def randomView(isPublic: Boolean, alias: String) : CreateViewJSON = { - CreateViewJSON( - name = randomString(3), - description = randomString(3), - is_public = isPublic, - which_alias_to_use=alias, - hide_metadata_if_alias_used=false, - allowed_actions = viewFileds - ) - } + def randomView(isPublic: Boolean, alias: String) = createViewJson def getAPIInfo : APIResponse = { @@ -156,7 +116,7 @@ class API2_2_0Test extends User1AllPrivileges with V220ServerSetup with DefaultU makeGetRequest(request) } - def postView(bankId: String, accountId: String, view: CreateViewJSON, consumerAndToken: Option[(Consumer, Token)]): APIResponse = { + def postView(bankId: String, accountId: String, view: CreateViewJson, consumerAndToken: Option[(Consumer, Token)]): APIResponse = { val request = (v2_2Request / "banks" / bankId / "accounts" / accountId / "views").POST <@(consumerAndToken) makePostRequest(request, write(view)) } diff --git a/src/test/scala/code/api/v3_0_0/API3_0_0Test.scala b/src/test/scala/code/api/v3_0_0/API3_0_0Test.scala index 3c4a72c6e..b91aca7ab 100644 --- a/src/test/scala/code/api/v3_0_0/API3_0_0Test.scala +++ b/src/test/scala/code/api/v3_0_0/API3_0_0Test.scala @@ -31,79 +31,20 @@ Berlin 13359, Germany */ package code.api.v3_0_0 -import _root_.net.liftweb.json.JsonAST.JObject import _root_.net.liftweb.json.Serialization.write import code.api.util.APIUtil.OAuth._ import code.api.v1_2._ -import code.api.v2_2_0.{AccountsJSONV220, ViewJSONV220, ViewsJSONV220} -import code.model.{CreateViewJSON, UpdateViewJSON} +import code.api.v2_2_0.{ViewJSONV220, ViewsJSONV220} +import code.model.{CreateViewJson, UpdateViewJSON} import code.setup.{APIResponse, DefaultUsers, User1AllPrivileges} -import net.liftweb.json.JsonDSL._ import net.liftweb.util.Helpers._ -import org.scalatest._ - import scala.util.Random._ - +import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultUsers { - - implicit val dateFormats = net.liftweb.json.DefaultFormats - - val viewFileds = List( - "can_see_transaction_this_bank_account","can_see_transaction_other_bank_account", - "can_see_transaction_metadata","can_see_transaction_label","can_see_transaction_amount", - "can_see_transaction_type","can_see_transaction_currency","can_see_transaction_start_date", - "can_see_transaction_finish_date","can_see_transaction_balance","can_see_comments", - "can_see_narrative","can_see_tags","can_see_images","can_see_bank_account_owners", - "can_see_bank_account_type","can_see_bank_account_balance","can_see_bank_account_currency", - "can_see_bank_account_label","can_see_bank_account_national_identifier", - "can_see_bank_account_swift_bic","can_see_bank_account_iban","can_see_bank_account_number", - "can_see_bank_account_bank_name","can_see_other_account_national_identifier", - "can_see_other_account_swift_bic","can_see_other_account_iban", - "can_see_other_account_bank_name","can_see_other_account_number", - "can_see_other_account_metadata","can_see_other_account_kind","can_see_more_info", - "can_see_url","can_see_image_url","can_see_open_corporates_url","can_see_corporate_location", - "can_see_physical_location","can_see_public_alias","can_see_private_alias","can_add_more_info", - "can_add_url","can_add_image_url","can_add_open_corporates_url","can_add_corporate_location", - "can_add_physical_location","can_add_public_alias","can_add_private_alias", - "can_delete_corporate_location","can_delete_physical_location","can_edit_narrative", - "can_add_comment","can_delete_comment","can_add_tag","can_delete_tag","can_add_image", - "can_delete_image","can_add_where_tag","can_see_where_tag","can_delete_where_tag", "can_create_counterparty", - //V300 New - "can_see_bank_routing_scheme", - "can_see_bank_routing_address", - "can_see_bank_account_routing_scheme", - "can_see_bank_account_routing_address", - "can_see_other_bank_routing_scheme", - "can_see_other_bank_routing_address", - "can_see_other_account_routing_scheme", - "can_see_other_account_routing_addres" - ) - - /************************* test tags ************************/ - - /** - * Example: To run tests with tag "getPermissions": - * mvn test -D tagsToInclude - * - * This is made possible by the scalatest maven plugin - */ - - object API3_0 extends Tag("api3.0.0") - object APIInfo extends Tag("apiInfo") - object GetHostedBanks extends Tag("hostedBanks") - object GetHostedBank extends Tag("getHostedBank") - object GetViews extends Tag("getViews") - object PostView extends Tag("postView") - object PutView extends Tag("putView") - - - - /********************* API test methods ********************/ - val emptyJSON : JObject = ("error" -> "empty List") - val errorAPIResponse = new APIResponse(400,emptyJSON) - - + + val view = createViewJson + def randomBankId : String = { val banksJson = getBanksInfo.body.extract[BanksJSON] val randomPosition = nextInt(banksJson.banks.size) @@ -117,26 +58,6 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU accountsJson(randomPosition) } - def randomViewsIdsToGrant(bankId : String, accountId : String) : List[String]= { - //get the view ids of the available views on the bank accounts - val viewsIds = getAccountViews(bankId, accountId, user1).body.extract[ViewsJSONV220].views.map(_.id) - //choose randomly some view ids to grant - val (viewsIdsToGrant, _) = viewsIds.splitAt(nextInt(viewsIds.size) + 1) - viewsIdsToGrant - } - - def randomView(isPublic: Boolean, alias: String) : CreateViewJSON = { - CreateViewJSON( - name = randomString(3), - description = randomString(3), - is_public = isPublic, - which_alias_to_use=alias, - hide_metadata_if_alias_used=false, - allowed_actions = viewFileds - ) - } - - def getAPIInfo : APIResponse = { val request = v3_0Request makeGetRequest(request) @@ -162,7 +83,7 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU makeGetRequest(request) } - def postView(bankId: String, accountId: String, view: CreateViewJSON, consumerAndToken: Option[(Consumer, Token)]): APIResponse = { + def postView(bankId: String, accountId: String, view: CreateViewJson, consumerAndToken: Option[(Consumer, Token)]): APIResponse = { val request = (v3_0Request / "banks" / bankId / "accounts" / accountId / "views").POST <@(consumerAndToken) makePostRequest(request, write(view)) } @@ -172,11 +93,9 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU makePutRequest(request, write(view)) } - - /************************ the tests ************************/ feature("base line URL works"){ - scenario("we get the api information", API3_0, APIInfo) { + scenario("we get the api information") { Given("We will not use an access token") When("the request is sent") val reply = getAPIInfo @@ -188,7 +107,7 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU } feature("Information about the hosted banks"){ - scenario("we get the hosted banks information", API3_0, GetHostedBanks) { + scenario("we get the hosted banks information") { Given("We will not use an access token") When("the request is sent") val reply = getBanksInfo @@ -202,7 +121,7 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU } feature("Information about one hosted bank"){ - scenario("we get the hosted bank information", API3_0, GetHostedBank) { + scenario("we get the hosted bank information") { Given("We will not use an access token") When("the request is sent") val reply = getBankInfo(randomBankId) @@ -212,7 +131,7 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU bankInfo.id.nonEmpty should equal (true) } - scenario("we don't get the hosted bank information", API3_0, GetHostedBank) { + scenario("we don't get the hosted bank information") { Given("We will not use an access token and request a random bankId") When("the request is sent") val reply = getBankInfo(randomString(5)) @@ -224,7 +143,7 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU } feature("List of the views of specific bank account - v3.0.0"){ - scenario("We will get the list of the available views on a bank account", API3_0, GetViews) { + scenario("We will get the list of the available views on a bank account") { Given("We will use an access token") val bankId = randomBankId val bankAccount : code.api.v1_2.AccountJSON = randomPrivateAccount(bankId) @@ -235,7 +154,7 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU reply.body.extract[ViewsJsonV300] } - scenario("We will not get the list of the available views on a bank account due to missing token", API3_0, GetViews) { + scenario("We will not get the list of the available views on a bank account due to missing token") { Given("We will not use an access token") val bankId = randomBankId val bankAccount : code.api.v1_2.AccountJSON = randomPrivateAccount(bankId) @@ -247,7 +166,7 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU reply.body.extract[ErrorMessage].error.nonEmpty should equal (true) } - scenario("We will not get the list of the available views on a bank account due to insufficient privileges", API3_0, GetViews) { + scenario("We will not get the list of the available views on a bank account due to insufficient privileges") { Given("We will use an access token") val bankId = randomBankId val bankAccount : code.api.v1_2.AccountJSON = randomPrivateAccount(bankId) @@ -260,12 +179,12 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU } } feature("Create a view on a bank account - v3.0.0"){ - scenario("we will create a view on a bank account", API3_0, PostView) { + scenario("we will create a view on a bank account") { Given("We will use an access token") val bankId = randomBankId val bankAccount : code.api.v1_2.AccountJSON = randomPrivateAccount(bankId) val viewsBefore = getAccountViews(bankId, bankAccount.id, user1).body.extract[ViewsJsonV300].views - val view = randomView(true, "") + When("the request is sent") val reply = postView(bankId, bankAccount.id, view, user1) Then("we should get a 201 code") @@ -276,11 +195,10 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU viewsBefore.size should equal (viewsAfter.size -1) } - scenario("We will not create a view on a bank account due to missing token", API3_0, PostView) { + scenario("We will not create a view on a bank account due to missing token") { Given("We will not use an access token") val bankId = randomBankId val bankAccount : code.api.v1_2.AccountJSON = randomPrivateAccount(bankId) - val view = randomView(true, "") When("the request is sent") val reply = postView(bankId, bankAccount.id, view, None) Then("we should get a 400 code") @@ -289,11 +207,10 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU reply.body.extract[ErrorMessage].error.nonEmpty should equal (true) } - scenario("We will not create a view on a bank account due to insufficient privileges", API3_0, PostView) { + scenario("We will not create a view on a bank account due to insufficient privileges") { Given("We will use an access token") val bankId = randomBankId val bankAccount : code.api.v1_2.AccountJSON = randomPrivateAccount(bankId) - val view = randomView(true, "") When("the request is sent") val reply = postView(bankId, bankAccount.id, view, user3) Then("we should get a 400 code") @@ -302,10 +219,9 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU reply.body.extract[ErrorMessage].error.nonEmpty should equal (true) } - scenario("We will not create a view because the bank account does not exist", API3_0, PostView) { + scenario("We will not create a view because the bank account does not exist") { Given("We will use an access token") val bankId = randomBankId - val view = randomView(true, "") When("the request is sent") val reply = postView(bankId, randomString(3), view, user1) Then("we should get a 400 code") @@ -314,11 +230,10 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU reply.body.extract[ErrorMessage].error.nonEmpty should equal (true) } - scenario("We will not create a view because the view already exists", API3_0, PostView) { + scenario("We will not create a view because the view already exists") { Given("We will use an access token") val bankId = randomBankId val bankAccount : code.api.v1_2.AccountJSON = randomPrivateAccount(bankId) - val view = randomView(true, "") postView(bankId, bankAccount.id, view, user1) When("the request is sent") val reply = postView(bankId, bankAccount.id, view, user1) @@ -356,11 +271,10 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU ) } - scenario("we will update a view on a bank account", API3_0, PutView) { + scenario("we will update a view on a bank account") { Given("A view exists") val bankId = randomBankId val bankAccount : code.api.v1_2.AccountJSON = randomPrivateAccount(bankId) - val view = randomView(true, "") val creationReply = postView(bankId, bankAccount.id, view, user1) creationReply.code should equal (201) val createdView : ViewJsonV300 = creationReply.body.extract[ViewJsonV300] @@ -386,7 +300,7 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU updatedView.hide_metadata_if_alias_used should equal(true) } - scenario("we will not update a view that doesn't exist", API3_0, PutView) { + scenario("we will not update a view that doesn't exist") { val bankId = randomBankId val bankAccount : code.api.v1_2.AccountJSON = randomPrivateAccount(bankId) @@ -403,11 +317,10 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU reply.code should equal(404) } - scenario("We will not update a view on a bank account due to missing token", API3_0, PutView) { + scenario("We will not update a view on a bank account due to missing token") { Given("A view exists") val bankId = randomBankId val bankAccount : code.api.v1_2.AccountJSON = randomPrivateAccount(bankId) - val view = randomView(true, "") val creationReply = postView(bankId, bankAccount.id, view, user1) creationReply.code should equal (201) val createdView : ViewJsonV300 = creationReply.body.extract[ViewJsonV300] @@ -421,11 +334,10 @@ class API3_0_0Test extends User1AllPrivileges with V300ServerSetup with DefaultU reply.body.extract[ErrorMessage].error.nonEmpty should equal (true) } - scenario("we will not update a view on a bank account due to insufficient privileges", API3_0, PutView) { + scenario("we will not update a view on a bank account due to insufficient privileges") { Given("A view exists") val bankId = randomBankId val bankAccount : code.api.v1_2.AccountJSON = randomPrivateAccount(bankId) - val view = randomView(true, "") val creationReply = postView(bankId, bankAccount.id, view, user1) creationReply.code should equal (201) val createdView : ViewJsonV300 = creationReply.body.extract[ViewJsonV300] diff --git a/src/test/scala/code/sandbox/PostCounterpartyMetadata.scala b/src/test/scala/code/sandbox/PostCounterpartyMetadata.scala index 31117e5b9..97c6cc6d6 100644 --- a/src/test/scala/code/sandbox/PostCounterpartyMetadata.scala +++ b/src/test/scala/code/sandbox/PostCounterpartyMetadata.scala @@ -40,9 +40,10 @@ TESOBE (http://www.tesobe.com/) * into your props file. * */ -import code.api.ObpJson.{BarebonesAccountsJson, _} +import code.util.ObpJson.{BarebonesAccountsJson, _} import code.api._ import code.setup.SendServerRequests +import code.util.{Header, OAuthClient, ObpGet, ObpPost} import net.liftweb.common.Full import net.liftweb.json.JsonDSL._ import net.liftweb.json._ diff --git a/src/test/scala/code/sandbox/PostCustomer.scala b/src/test/scala/code/sandbox/PostCustomer.scala index d50d70421..fcd2ccc94 100644 --- a/src/test/scala/code/sandbox/PostCustomer.scala +++ b/src/test/scala/code/sandbox/PostCustomer.scala @@ -42,9 +42,10 @@ TESOBE (http://www.tesobe.com/) import java.util.Date -import code.api.ObpJson._ +import code.util.ObpJson._ import code.api._ import code.setup.SendServerRequests +import code.util.{OAuthClient, ObpGet, ObpPost} import net.liftweb.common.{Box, Empty, Full} import net.liftweb.http.RequestVar import net.liftweb.json._ diff --git a/src/test/scala/code/setup/ServerSetup.scala b/src/test/scala/code/setup/ServerSetup.scala index f896755a7..b2a874423 100644 --- a/src/test/scala/code/setup/ServerSetup.scala +++ b/src/test/scala/code/setup/ServerSetup.scala @@ -38,8 +38,11 @@ import code.TestServer import code.model.BankId import code.util.Helper.MdcLoggable import dispatch._ +import net.liftweb.json.JsonAST.JObject import net.liftweb.json.{DefaultFormats, ShortTypeHints} import org.scalatest._ +import _root_.net.liftweb.json.JsonAST.JObject +import net.liftweb.json.JsonDSL._ trait ServerSetup extends FeatureSpec with SendServerRequests with BeforeAndAfterEach with GivenWhenThen @@ -47,6 +50,8 @@ trait ServerSetup extends FeatureSpec with SendServerRequests with ShouldMatchers with MdcLoggable { implicit val formats = DefaultFormats.withHints(ShortTypeHints(List())) + implicit val dateFormats = net.liftweb.json.DefaultFormats + val server = TestServer def baseRequest = host(server.host, server.port) @@ -67,6 +72,9 @@ trait ServerSetup extends FeatureSpec with SendServerRequests val mockCustomerNumber = "93934903208565488" val mockCustomerId = "cba6c9ef-73fa-4032-9546-c6f6496b354a" + val emptyJSON : JObject = ("error" -> "empty List") + val errorAPIResponse = new APIResponse(400,emptyJSON) + } trait ServerSetupWithTestData extends ServerSetup with DefaultConnectorTestSetup { diff --git a/src/test/scala/code/api/OAuthClient.scala b/src/test/scala/code/util/OAuthClient.scala similarity index 98% rename from src/test/scala/code/api/OAuthClient.scala rename to src/test/scala/code/util/OAuthClient.scala index 07d405db6..3fe1a6bcb 100644 --- a/src/test/scala/code/api/OAuthClient.scala +++ b/src/test/scala/code/util/OAuthClient.scala @@ -30,20 +30,20 @@ Berlin 13359, Germany */ -package code.api +package code.util +import java.net.{URI, URLDecoder} + +import code.util.Helper.MdcLoggable import net.liftweb.common.{Box, Empty, Failure, Full} import net.liftweb.util.Props import oauth.signpost.basic.{DefaultOAuthConsumer, DefaultOAuthProvider} import oauth.signpost.{OAuthConsumer, OAuthProvider} -import org.apache.http.NameValuePair +import org.apache.http.client.utils.URLEncodedUtils import org.openqa.selenium._ import org.openqa.selenium.htmlunit.HtmlUnitDriver -import java.net.{URI, URLDecoder} -import org.apache.http.client.utils.URLEncodedUtils + import scala.collection.JavaConversions._ -import scala.util.DynamicVariable -import code.util.Helper.MdcLoggable sealed trait Provider { val name : String diff --git a/src/test/scala/code/api/ObpAPI.scala b/src/test/scala/code/util/ObpAPI.scala similarity index 98% rename from src/test/scala/code/api/ObpAPI.scala rename to src/test/scala/code/util/ObpAPI.scala index 91e955a1d..a9bec1450 100644 --- a/src/test/scala/code/api/ObpAPI.scala +++ b/src/test/scala/code/util/ObpAPI.scala @@ -1,26 +1,22 @@ -package code.api +package code.util -import net.liftweb.json._ -import net.liftweb.json.JObject -import net.liftweb.json.JsonDSL._ -import net.liftweb.common.Box -import net.liftweb.common.Full -import net.liftweb.json.JsonAST.JValue -import net.liftweb.common.Empty -import java.net.URL -import java.io.{BufferedWriter, OutputStreamWriter} -import java.net.HttpURLConnection -import net.liftweb.common.Failure -import java.io.{PrintWriter, StringWriter, BufferedReader, InputStreamReader} -import net.liftweb.util.Helpers._ -import java.util.Date -import net.liftweb.http.RequestVar +import java.io._ +import java.net.{HttpURLConnection, URL} import java.text.SimpleDateFormat +import java.util.Date + import code.util.Helper.MdcLoggable +import code.util.ObpJson._ +import net.liftweb.common.{Box, Empty, Failure, Full} +import net.liftweb.http.RequestVar +import net.liftweb.json.JsonAST.JValue +import net.liftweb.json.JsonDSL._ +import net.liftweb.json.{JObject, _} +import net.liftweb.util.Helpers._ import net.liftweb.util.Props -import code.api.ObpJson._ case class Header(key: String, value: String) +case class ObpError(error :String) object ObpAPI extends MdcLoggable { implicit val formats = DefaultFormats @@ -219,7 +215,7 @@ object ObpAPI extends MdcLoggable { } } -case class ObpError(error :String) + object OBPRequest extends MdcLoggable { implicit val formats = DefaultFormats