diff --git a/testApi/src/main/scala/africa/absa/testing/scapi/rest/response/Response.scala b/testApi/src/main/scala/africa/absa/testing/scapi/rest/response/Response.scala index d798b9c..2de1f41 100644 --- a/testApi/src/main/scala/africa/absa/testing/scapi/rest/response/Response.scala +++ b/testApi/src/main/scala/africa/absa/testing/scapi/rest/response/Response.scala @@ -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: @@ -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.") diff --git a/testApi/src/main/scala/africa/absa/testing/scapi/suite/runner/SuiteRunner.scala b/testApi/src/main/scala/africa/absa/testing/scapi/suite/runner/SuiteRunner.scala index fb7f56e..ac67541 100644 --- a/testApi/src/main/scala/africa/absa/testing/scapi/suite/runner/SuiteRunner.scala +++ b/testApi/src/main/scala/africa/absa/testing/scapi/suite/runner/SuiteRunner.scala @@ -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 ) diff --git a/testApi/src/test/resources/test_project/suites/demo/getOwners.before.json b/testApi/src/test/resources/test_project/suites/demo/getOwners.before.json index e0a2e06..d92f050 100644 --- a/testApi/src/test/resources/test_project/suites/demo/getOwners.before.json +++ b/testApi/src/test/resources/test_project/suites/demo/getOwners.before.json @@ -76,6 +76,10 @@ { "method": "log.info", "message": "{{ cache.ownerId }}" + }, + { + "method": "log.info", + "message": "{{ cache.ownerName }}" } ] } diff --git a/testApi/src/test/scala/africa/absa/testing/scapi/rest/response/ResponseLogTest.scala b/testApi/src/test/scala/africa/absa/testing/scapi/rest/response/ResponseLogTest.scala index 25cf4c5..13a62cc 100644 --- a/testApi/src/test/scala/africa/absa/testing/scapi/rest/response/ResponseLogTest.scala +++ b/testApi/src/test/scala/africa/absa/testing/scapi/rest/response/ResponseLogTest.scala @@ -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) } @@ -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) }