Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/8 implement methods #27

Merged
merged 33 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ca67acc
#17 - Assertion rename and simplification
miroslavpojer Aug 22, 2023
b1e3ade
Merge branch 'master' into feature/17_assertion_rename_and_simplifica…
miroslavpojer Aug 22, 2023
9d89dc1
#17 - Assertion rename and simplification
miroslavpojer Aug 22, 2023
0b5a476
#18 - Refactoring of ResponseAction to dynamic
miroslavpojer Aug 22, 2023
2e68674
#18 - Refactoring of ResponseAction to dynamic
miroslavpojer Aug 22, 2023
4d5a6bc
* Repairs of unit tests.
miroslavpojer Aug 22, 2023
f14b81f
#8 - Implement method ideas
miroslavpojer Aug 23, 2023
104415f
* Implemented methods for Assertion 'ResponseAction' - status-code-..…
miroslavpojer Aug 23, 2023
2559bb2
* Implemented methods for Assertion 'ResponseAction' - response-time-…
miroslavpojer Aug 24, 2023
643a68a
* Implemented methods for Assertion 'ResponseAction' - cookie-... part
miroslavpojer Aug 24, 2023
e0ac15d
Merge branch 'master' into feature/8-implement_methods
miroslavpojer Aug 26, 2023
6032a64
* Fix multiline strings review note.
miroslavpojer Sep 7, 2023
c203ab6
* Fix - multiline strings review note.
miroslavpojer Sep 21, 2023
2e251ae
* Fix - replace Assert type of response actions by enum.
miroslavpojer Sep 21, 2023
3dc366b
* Fix - Update of javaDoc after migration from boolean to Try[Unit] r…
miroslavpojer Oct 3, 2023
02a2447
* Fix - replaced tuple by new CookieValue class.
miroslavpojer Oct 6, 2023
11293dc
* Fix - add missed class file.
miroslavpojer Oct 6, 2023
0227000
* Fix - review of code warnings.
miroslavpojer Oct 6, 2023
8b4c12e
* Fix - Removed no more used class and object TestResults.scala.
miroslavpojer Oct 9, 2023
1aa261b
* Fix - moved Factory classes to dedicated package.
miroslavpojer Oct 13, 2023
d51747d
* Fix - rename Suite to TestSet.
miroslavpojer Oct 13, 2023
0f82356
* Fix - removed only keyword.
miroslavpojer Oct 13, 2023
2f579ac
* Change: set jacoco-report debug to find source of logic failing.
miroslavpojer Oct 13, 2023
f353d54
* Change: set jacoco-report debug to find source of logic failing.
miroslavpojer Oct 13, 2023
aca8587
* Fix - expected change to fix jacoco report issue and better package…
miroslavpojer Oct 13, 2023
1d2c8ab
* Fix - expected change to fix jacoco report issue and better package…
miroslavpojer Oct 13, 2023
e2fec8f
* Fix - log action methods returns Unit.
miroslavpojer Nov 1, 2023
470efbf
* Fix - Improved usage of resultType enums.
miroslavpojer Nov 1, 2023
a15a420
* Fix - Removed usage of Success from Action implementations.
miroslavpojer Nov 1, 2023
5ec5a73
* Fix - Renamed and moved Type to String implicit conversion as they …
miroslavpojer Nov 1, 2023
e4ce58a
* Fix - correct usage clue calls in assert (not assertEquals) method.
miroslavpojer Nov 2, 2023
236cbae
* Fix - removed used only keyword from test name.
miroslavpojer Nov 2, 2023
4e0d029
* Fix - Applied Scala CamelCase to enumaration contants.
miroslavpojer Nov 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ object Dependencies {
private val commonsIoVersion = "2.13.0"
private val requestsVersion = "0.8.0"
private val loggerVersion = "2.14.1"
private val scalaXmlVersion = "1.3.0"

def getScalaDependency(scalaVersion: String): ModuleID = "org.scala-lang" % "scala-library" % scalaVersion

Expand All @@ -40,6 +41,7 @@ object Dependencies {
"com.lihaoyi" %% "requests" % requestsVersion,
"org.apache.logging.log4j" % "log4j-core" % loggerVersion,
"org.apache.logging.log4j" % "log4j-api" % loggerVersion,
"org.scala-lang.modules" %% "scala-xml" % scalaXmlVersion,

// test
"org.scalameta" %% "munit" % munitVersion % Test
Expand Down
2 changes: 1 addition & 1 deletion testApi/src/main/resources/schema/after.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"properties": {
"method": {
"type": "string",
"enum": ["assert.status-code", "assert.body-contains", "log.info", "extractJson.string-from-list"],
"enum": ["assert.response-time-is-below", "assert.response-time-is-above", "assert.status-code-equals", "assert.status-code-is-success", "assert.status-code-is-client-error", "assert.status-code-is-server-error", "assert.header-exists", "assert.header-value-equals", "assert.content-type-is-json", "assert.content-type-is-xml", "assert.content-type-is-html", "assert.cookie-exists", "assert.cookie-value-equals", "assert.cookie-is-secured", "assert.cookie-is-not-secured", "assert.body-contains-text", "log.error", "log.warn", "log.info", "log.debug", "extractJson.string-from-list"],
"description": "The method to be used for the response action. Restricted to specific values."
}
},
Expand Down
2 changes: 1 addition & 1 deletion testApi/src/main/resources/schema/before.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"properties": {
"method": {
"type": "string",
"enum": ["assert.status-code", "assert.body-contains", "log.info", "extractJson.string-from-list"],
"enum": ["assert.response-time-is-below", "assert.response-time-is-above", "assert.status-code-equals", "assert.status-code-is-success", "assert.status-code-is-client-error", "assert.status-code-is-server-error", "assert.header-exists", "assert.header-value-equals", "assert.content-type-is-json", "assert.content-type-is-xml", "assert.content-type-is-html", "assert.cookie-exists", "assert.cookie-value-equals", "assert.cookie-is-secured", "assert.cookie-is-not-secured", "assert.body-contains-text", "log.error", "log.warn", "log.info", "log.debug", "extractJson.string-from-list"],
"description": "The method to be used for the response action."
}
},
Expand Down
6 changes: 3 additions & 3 deletions testApi/src/main/resources/schema/suite.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"properties": {
"method": {
"type": "string",
"enum": ["assert.status-code", "assert.body-contains", "log.info", "extractJson.string-from-list"],
"enum": ["assert.response-time-is-below", "assert.response-time-is-above", "assert.status-code-equals", "assert.status-code-is-success", "assert.status-code-is-client-error", "assert.status-code-is-server-error", "assert.header-exists", "assert.header-value-equals", "assert.content-type-is-json", "assert.content-type-is-xml", "assert.content-type-is-html", "assert.cookie-exists", "assert.cookie-value-equals", "assert.cookie-is-secured", "assert.cookie-is-not-secured", "assert.body-contains-text", "log.error", "log.warn", "log.info", "log.debug", "extractJson.string-from-list"],
"description": "The method to be used for the response action."
}
},
Expand All @@ -156,7 +156,7 @@
{
"properties": {
"method": {
"const": "assert.status-code"
"const": "assert.status-code-equals"
}
},
"required": ["code"]
Expand Down Expand Up @@ -190,7 +190,7 @@
{
"properties": {
"method": {
"const": "assert.status-code"
"const": "assert.status-code-equals"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package africa.absa.testing.scapi.json
trait Requestable {
def name: String

def headers: Set[Header]
def headers: Seq[Header]

def actions: Set[Action]
def actions: Seq[Action]

def responseActions: Set[ResponseAction]
def responseActions: Seq[ResponseAction]
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import africa.absa.testing.scapi.json.{Action, Header, Requestable, ResponseActi
* @param responseActions The set of responseAction objects for the method.
*/
case class Method(name: String,
headers: Set[Header],
actions: Set[Action],
responseActions: Set[ResponseAction]) extends Requestable {
headers: Seq[Header],
Zejnilovic marked this conversation as resolved.
Show resolved Hide resolved
actions: Seq[Action],
responseActions: Seq[ResponseAction]) extends Requestable {
/**
* Method to resolve references within the Method instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import africa.absa.testing.scapi.json.{Action, Header, Requestable, ResponseActi
* @param only The control if test should be only be running when set to true.
*/
case class SuiteTestScenario(name: String,
categories: Set[String],
headers: Set[Header],
actions: Set[Action],
responseActions: Set[ResponseAction],
categories: Seq[String],
headers: Seq[Header],
actions: Seq[Action],
responseActions: Seq[ResponseAction],
only: Option[Boolean] = Some(false)) extends Requestable {
/**
* Method to resolve references within the SuiteTestScenario instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object RequestHeaders {
* @param headersSet A set of Header objects to be processed.
* @return A Map where the key is the header name (lowercase) and the value is the resolved header value.
*/
def buildHeaders(headersSet: Set[Header]): Map[String, String] = {
def buildHeaders(headersSet: Seq[Header]): Map[String, String] = {
headersSet.foldLeft(Map.empty[String, String]) {
(acc, header) => header.name.toLowerCase match {
case CONTENT_TYPE => acc + (header.name -> RuntimeCache.resolve(header.value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,35 @@ package africa.absa.testing.scapi.rest.request.sender

import africa.absa.testing.scapi.rest.response.Response

import java.net.HttpCookie

/**
* ScAPIRequestSender is an implementation of the RequestSender interface.
* It provides the capability to send different types of HTTP requests including GET, POST, PUT, and DELETE.
*/
object ScAPIRequestSender extends RequestSender {

private def sendRequest(requestFunc: => requests.Response, url: String, headers: Map[String, String], verifySslCerts: Boolean, data: String, params: Map[String, String]): Response = {
Zejnilovic marked this conversation as resolved.
Show resolved Hide resolved
val startTime = System.nanoTime()
val response = requestFunc
val endTime = System.nanoTime()

val extractedCookies: Map[String, (String, Boolean)] = response.cookies.view.map {
case (name, cookie: HttpCookie) =>
(name, (cookie.getValue, cookie.getSecure))
}.toMap

Response(
response.statusCode,
response.text(),
url = response.url,
statusMessage = response.statusMessage,
response.headers,
cookies = extractedCookies,
(endTime - startTime) / 1_000_000
)
}

/**
* Sends a GET request to the provided URL with the given headers, SSL certificate verification setting, data, and parameters.
*
Expand All @@ -34,8 +58,7 @@ object ScAPIRequestSender extends RequestSender {
* @return Response Returns the response from the GET request.
*/
override def get(url: String, headers: Map[String, String], verifySslCerts: Boolean, data: String, params: Map[String, String]): Response = {
val response = requests.get(url = url, headers = headers, verifySslCerts = verifySslCerts, data = data, params = params)
Response(response.statusCode, response.text(), response.headers.toMap)
sendRequest(requests.get(url = url, headers = headers, verifySslCerts = verifySslCerts, data = data, params = params), url, headers, verifySslCerts, data, params)
}

/**
Expand All @@ -49,8 +72,7 @@ object ScAPIRequestSender extends RequestSender {
* @return Response Returns the response from the POST request.
*/
override def post(url: String, headers: Map[String, String], verifySslCerts: Boolean, data: String, params: Map[String, String]): Response = {
val response = requests.post(url = url, headers = headers, verifySslCerts = verifySslCerts, data = data, params = params)
Response(response.statusCode, response.text(), response.headers.toMap)
sendRequest(requests.post(url = url, headers = headers, verifySslCerts = verifySslCerts, data = data, params = params), url, headers, verifySslCerts, data, params)
}

/**
Expand All @@ -64,8 +86,7 @@ object ScAPIRequestSender extends RequestSender {
* @return Response Returns the response from the PUT request.
*/
override def put(url: String, headers: Map[String, String], verifySslCerts: Boolean, data: String, params: Map[String, String]): Response = {
val response = requests.put(url = url, headers = headers, verifySslCerts = verifySslCerts, data = data, params = params)
Response(response.statusCode, response.text(), response.headers.toMap)
sendRequest(requests.put(url = url, headers = headers, verifySslCerts = verifySslCerts, data = data, params = params), url, headers, verifySslCerts, data, params)
}

/**
Expand All @@ -79,7 +100,6 @@ object ScAPIRequestSender extends RequestSender {
* @return Response Returns the response from the DELETE request.
*/
override def delete(url: String, headers: Map[String, String], verifySslCerts: Boolean, data: String, params: Map[String, String]): Response = {
val response = requests.delete(url = url, headers = headers, verifySslCerts = verifySslCerts, data = data, params = params)
Response(response.statusCode, response.text(), response.headers.toMap)
sendRequest(requests.delete(url = url, headers = headers, verifySslCerts = verifySslCerts, data = data, params = params), url, headers, verifySslCerts, data, params)
}
}
Loading