Skip to content

Commit

Permalink
Merge branch 'master' into feature/35_suite_can_pass_with_all_codes
Browse files Browse the repository at this point in the history
# Conflicts:
#	testApi/src/main/scala/africa/absa/testing/scapi/rest/response/Response.scala
#	testApi/src/main/scala/africa/absa/testing/scapi/suite/runner/SuiteRunner.scala
#	testApi/src/test/resources/test_project/suites/demo/getOwners.suite.json
  • Loading branch information
miroslavpojer committed Nov 9, 2023
2 parents 6b12344 + 69594e9 commit cb86c2d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,19 @@ object Response {
* The appropriate group's performAssertions method is called based on the group type of each Assertion.
* Returns true only if all assertions return true, and false as soon as any assertion returns false.
*
* @param environment The current environment.
* @param response The response on which actions will be performed.
* @param responseActions The set of response actions that dictate what actions will be performed on the response.
* @return Boolean indicating whether all response actions passed (true) or any response action failed (false). TODO
* @throws IllegalArgumentException If an response action group is not supported.
*/
def perform(environment: Environment, response: Response, responseActions: Seq[ResponseAction]): Try[Unit] = {
def perform(response: Response, responseActions: Seq[ResponseAction]): Try[Unit] = {
def logParameters(response: Response, resolvedResponseAction: ResponseAction, exception: Option[Throwable] = None): Unit = {
val filteredParams = resolvedResponseAction.params.filter(_._1 != "method").map { case (k, v) => s"$k->$v" }.mkString(", ")
val filteredParams = resolvedResponseAction.params
.flatMap {
case (k, v) if k != "method" => Some(s"$k->$v")
case _ => None
}
.mkString(", ")
val baseLog =
s"""
|Parameters received:
Expand All @@ -81,7 +85,7 @@ object Response {
Logger.debug(s"Response-${resolvedResponseAction.group}: '${resolvedResponseAction.name}' - error details:$baseLog$exceptionLog")
}

responseActions.iterator.map { responseAction =>
responseActions.map { responseAction =>
val resolvedResponseAction: ResponseAction = responseAction.resolveByRuntimeCache()
Logger.debug(s"Response-${resolvedResponseAction.group}: '${resolvedResponseAction.name}' - Started.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ object SuiteRunner {
private def processRequest(requestable: Requestable, environment: Environment, restClientCreator: RestClientCreator): Try[Unit] = {
val response: Response = sendRequest(requestable, environment, restClientCreator)
Response.perform(
environment = environment,
response = response,
responseActions = requestable.responseActions
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
{
"method": "log.info",
"message": "{{ cache.ownerId }}"
},
{
"method": "log.info",
"message": "{{ cache.ownerName }}"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ class ResponseLogTest extends FunSuite {
*/

test("performAssertion - ERROR supported") {
val assertion = ResponseAction(group = ResponseActionGroupType.Log, name = LogType.Error, Map("message" -> "info message"))
val assertion = ResponseAction(group = ResponseActionGroupType.Log, name = LogType.Error, Map("message" -> "error message"))
val response = Response(500, "OK", "", "", Map("Content-Type" -> Seq("application/json")), Map.empty, 100)
assert(LogResponseAction.performResponseAction(response, assertion).isSuccess)
}

test("performAssertion - WARN supported") {
val assertion = ResponseAction(group = ResponseActionGroupType.Log, name = LogType.Warn, Map("message" -> "info message"))
val assertion = ResponseAction(group = ResponseActionGroupType.Log, name = LogType.Warn, Map("message" -> "warn message"))
val response = Response(401, "OK", "", "", Map("Content-Type" -> Seq("application/json")), Map.empty, 100)
assert(LogResponseAction.performResponseAction(response, assertion).isSuccess)
}
Expand All @@ -86,7 +86,7 @@ class ResponseLogTest extends FunSuite {
}

test("performAssertion - DEBUG supported") {
val assertion = ResponseAction(group = ResponseActionGroupType.Log, name = LogType.Debug, Map("message" -> "info message"))
val assertion = ResponseAction(group = ResponseActionGroupType.Log, name = LogType.Debug, Map("message" -> "debug message"))
val response = Response(200, "OK", "", "", Map("Content-Type" -> Seq("application/json")), Map.empty, 100)
assert(LogResponseAction.performResponseAction(response, assertion).isSuccess)
}
Expand Down

0 comments on commit cb86c2d

Please sign in to comment.