Skip to content
This repository was archived by the owner on Mar 28, 2025. It is now read-only.

Commit 0227000

Browse files
committed
* Fix - review of code warnings.
* Fix - update of visibility on methods and attributes. * Fix - removed old no more used object LoggerConfig.
1 parent 11293dc commit 0227000

File tree

9 files changed

+44
-63
lines changed

9 files changed

+44
-63
lines changed

testApi/src/main/scala/africa/absa/testing/scapi/config/ScAPIRunnerConfig.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,23 @@ object ScAPIRunnerConfig {
115115
opt[String]("filter")
116116
.optional()
117117
.action((value, config) => { config.copy(filter = value) })
118-
.text(s"Filter rule to select test definitions file (recursive) to include into test suite. Default is all '${DefaultFilter}'")
118+
.text(s"Filter rule to select test definitions file (recursive) to include into test suite. Default is all '$DefaultFilter'")
119119

120120
opt[Seq[String]]("categories")
121121
.optional()
122122
.valueName("<v1>,<v2>")
123123
.action((value, config) => { config.copy(categories = value.toSet) })
124-
.text(s"Select which test categories will be included into test suite. Default is all '${DefaultCategories}'")
124+
.text(s"Select which test categories will be included into test suite. Default is all '$DefaultCategories'")
125125

126126
opt[Int]("thread-count")
127127
.optional()
128128
.action((value, config) => { config.copy(threadCount = value) })
129-
.text(s"Maximum count of thread used to run test suite. Default is '${DefaultThreadCount}'")
129+
.text(s"Maximum count of thread used to run test suite. Default is '$DefaultThreadCount'")
130130

131131
opt[String]("file-format")
132132
.optional()
133133
.action((value, config) => { config.copy(fileFormat = value) })
134-
.text(s"Format of definition files. Default is all '${DefaultFileFormat}'")
134+
.text(s"Format of definition files. Default is all '$DefaultFileFormat'")
135135

136136
opt[String]("report")
137137
.optional()

testApi/src/main/scala/africa/absa/testing/scapi/json/SuiteFactory.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ object SuiteFactory {
127127
* @param environmentMap The map containing environment variables.
128128
* @return A SuiteBundle instance.
129129
*/
130-
def loadJsonSuiteBundle(suitePath: String, environmentMap: Map[String, String]): SuiteBundle = {
130+
private def loadJsonSuiteBundle(suitePath: String, environmentMap: Map[String, String]): SuiteBundle = {
131131
val (suiteFilePath, suiteFileName) = FileUtils.splitPathAndFileName(suitePath)
132132
val suiteName = suiteFileName.stripSuffix(".suite.json")
133133

@@ -189,7 +189,8 @@ object SuiteFactory {
189189
* @param extension The file extension.
190190
* @param parser The parser function used to parse JSON string.
191191
* @return A Suite instance.
192-
*/ def loadJsonSuite[T <: SuiteAround](suiteFilePath: String,
192+
*/
193+
private def loadJsonSuite[T <: SuiteAround](suiteFilePath: String,
193194
suiteName: String,
194195
properties: Map[String, String],
195196
jsonSchema: URL,
@@ -212,7 +213,7 @@ object SuiteFactory {
212213
* @param jsonString The JSON string to be parsed.
213214
* @return A SuiteConstants instance.
214215
*/
215-
def parseToSuiteConstant(jsonString: String): SuiteConstants = {
216+
private def parseToSuiteConstant(jsonString: String): SuiteConstants = {
216217
import SuiteConstantJsonProtocol.suiteConstantFormat
217218
jsonString.parseJson.convertTo[SuiteConstants]
218219
}
@@ -223,7 +224,7 @@ object SuiteFactory {
223224
* @param jsonString The JSON string to be parsed.
224225
* @return A SuiteBefore instance.
225226
*/
226-
def parseToSuiteBefore(jsonString: String): SuiteBefore = {
227+
private def parseToSuiteBefore(jsonString: String): SuiteBefore = {
227228
import SuiteBeforeJsonProtocol.suiteBeforeFormat
228229
jsonString.parseJson.convertTo[SuiteBefore]
229230
}
@@ -234,7 +235,7 @@ object SuiteFactory {
234235
* @param jsonString The JSON string to be parsed.
235236
* @return A SuiteAfter instance.
236237
*/
237-
def parseToSuiteAfter(jsonString: String): SuiteAfter = {
238+
private def parseToSuiteAfter(jsonString: String): SuiteAfter = {
238239
import SuiteAfterJsonProtocol.suiteAfterFormat
239240
jsonString.parseJson.convertTo[SuiteAfter]
240241
}
@@ -245,7 +246,7 @@ object SuiteFactory {
245246
* @param jsonString The JSON string to be parsed.
246247
* @return A Suite instance.
247248
*/
248-
def parseToSuite(jsonString: String): Suite = {
249+
private def parseToSuite(jsonString: String): Suite = {
249250
import SuiteJsonProtocol.suiteFormat
250251
jsonString.parseJson.convertTo[Suite]
251252
}
@@ -333,7 +334,7 @@ object ResponseActionJsonProtocol extends DefaultJsonProtocol {
333334

334335
val paramFields = a.params.view.mapValues(JsString(_)).toSeq
335336

336-
JsObject((fixedFields ++ paramFields): _*)
337+
JsObject(fixedFields ++ paramFields: _*)
337338
}
338339

339340
def read(value: JsValue): ResponseAction = {

testApi/src/main/scala/africa/absa/testing/scapi/json/schema/JsonSchemaValidator.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,28 @@ import java.net.URL
3131
* @param schemaPath Path to the JSON Schema file.
3232
*/
3333
case class JsonSchemaValidator(jsonPath: String, schemaPath: URL) {
34-
protected val mapper: ObjectMapper = new ObjectMapper()
34+
private val mapper: ObjectMapper = new ObjectMapper()
3535

3636
/**
3737
* Method to read JSON data from the specified file path.
3838
*
3939
* @return JsonNode object representing the JSON data.
4040
*/
41-
def jsonNode: JsonNode = mapper.readTree(JsonUtils.stringFromPath(jsonPath))
41+
private def jsonNode: JsonNode = mapper.readTree(JsonUtils.stringFromPath(jsonPath))
4242

4343
/**
4444
* Method to create a JsonSchemaFactory instance.
4545
*
4646
* @return JsonSchemaFactory instance.
4747
*/
48-
def jsonSchemaFactory: JsonSchemaFactory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V202012)
48+
private def jsonSchemaFactory: JsonSchemaFactory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V202012)
4949

5050
/**
5151
* Method to generate a JsonSchema from the provided schema file path.
5252
*
5353
* @return JsonSchema object representing the JSON schema.
5454
*/
55-
def jsonSchema: JsonSchema = jsonSchemaFactory.getSchema(JsonUtils.stringFromPath(schemaPath))
55+
private def jsonSchema: JsonSchema = jsonSchemaFactory.getSchema(JsonUtils.stringFromPath(schemaPath))
5656

5757
/**
5858
* Method to validate the JSON data against the provided schema.

testApi/src/main/scala/africa/absa/testing/scapi/logging/LoggerConfig.scala

Lines changed: 0 additions & 21 deletions
This file was deleted.

testApi/src/main/scala/africa/absa/testing/scapi/rest/response/Response.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ object Response {
7373
| Required Response-Action:
7474
| Group->'${resolvedResponseAction.group}',
7575
| Method->'${resolvedResponseAction.name}',
76-
| Params->'${filteredParams}',
76+
| Params->'$filteredParams',
7777
| Actual Response:
7878
| $response""".stripMargin
7979
val exceptionLog = exception.map(e => s"\nException: ${e.getMessage}").getOrElse("")

testApi/src/main/scala/africa/absa/testing/scapi/rest/response/action/LogResponseAction.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ object LogResponseAction extends ResponsePerformer {
4545
case Some(message) => ContentValidator.validateNonEmptyString(message, s"ResponseLog.${responseAction.name}.message")
4646
case None => throw new IllegalArgumentException(s"Missing required 'message' for assertion ${responseAction.name} logic.")
4747
}
48-
case _ => throw UndefinedResponseActionTypeException(responseAction.name.toString)
48+
case _ => throw UndefinedResponseActionTypeException(responseAction.name)
4949
}
5050
}
5151

testApi/src/main/scala/africa/absa/testing/scapi/suite/runner/SuiteRunner.scala

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import scala.util.{Failure, Try}
3131
* Main object handling the running of test suites.
3232
*/
3333
object SuiteRunner {
34-
type RestClientCreator = () => RestClient
34+
private type RestClientCreator = () => RestClient
3535

3636
/**
3737
* Run a set of test suites.
@@ -86,16 +86,11 @@ object SuiteRunner {
8686
* @return SuiteResults after the execution of the suite-before method.
8787
*/
8888
private def runSuiteBefore(suiteEndpoint: String, suiteBeforeName: String, method: Method, environment: Environment, restClientCreator: RestClientCreator): SuiteResult = {
89-
Logger.debug(s"Suite-Before: ${suiteBeforeName} - Started")
89+
Logger.debug(s"Suite-Before: $suiteBeforeName - Started")
9090
val testStartTime: Long = System.currentTimeMillis()
9191

9292
try {
93-
val response: Response = sendRequest(method, environment, restClientCreator)
94-
val result: Try[Unit] = Response.perform(
95-
response = response,
96-
responseAction = method.responseActions
97-
)
98-
93+
val result: Try[Unit] = processRequest(method, environment, restClientCreator)
9994
val testEndTime: Long = System.currentTimeMillis()
10095
Logger.debug(s"Suite-Before: method '${method.name}' - ${if (result.isSuccess) "completed successfully" else "failed"}.")
10196
SuiteResult(
@@ -123,12 +118,7 @@ object SuiteRunner {
123118
val testStartTime: Long = System.currentTimeMillis()
124119

125120
try {
126-
val response: Response = sendRequest(test, environment, restClientCreator)
127-
val result: Try[Unit] = Response.perform(
128-
response = response,
129-
responseAction = test.responseActions
130-
)
131-
121+
val result: Try[Unit] = processRequest(test, environment, restClientCreator)
132122
val testEndTime: Long = System.currentTimeMillis()
133123
Logger.debug(s"Suite-Test: '${test.name}' - ${if (result.isSuccess) "completed successfully" else "failed"}.")
134124
SuiteResult(
@@ -157,16 +147,11 @@ object SuiteRunner {
157147
* @return SuiteResults after the execution of the suite-after method.
158148
*/
159149
private def runSuiteAfter(suiteEndpoint: String, suiteAfterName: String, method: Method, environment: Environment, restClientCreator: RestClientCreator): SuiteResult = {
160-
Logger.debug(s"Suite-After: ${suiteAfterName} - Started")
150+
Logger.debug(s"Suite-After: $suiteAfterName - Started")
161151
val testStartTime: Long = System.currentTimeMillis()
162152

163153
try {
164-
val response: Response = sendRequest(method, environment, restClientCreator)
165-
val result: Try[Unit] = Response.perform(
166-
response = response,
167-
responseAction = method.responseActions
168-
)
169-
154+
val result: Try[Unit] = processRequest(method, environment, restClientCreator)
170155
val testEndTime: Long = System.currentTimeMillis()
171156
Logger.debug(s"After method '${method.name}' ${if (result.isSuccess) "completed successfully" else "failed"}.")
172157
SuiteResult(
@@ -199,6 +184,23 @@ object SuiteRunner {
199184
)
200185
}
201186

187+
/**
188+
* Process the request and perform the associated response actions.
189+
*
190+
* @param requestable The request-able method containing the actions and response actions.
191+
* @param environment The current environment.
192+
* @param restClientCreator A creator function for the REST client.
193+
* @return A Try containing the result of the response actions.
194+
*/
195+
private def processRequest(requestable: Requestable, environment: Environment, restClientCreator: RestClientCreator): Try[Unit] = {
196+
val response: Response = sendRequest(requestable, environment, restClientCreator)
197+
val result: Try[Unit] = Response.perform(
198+
response = response,
199+
responseAction = requestable.responseActions
200+
)
201+
result
202+
}
203+
202204
/**
203205
* Handles exceptions occurring during suite running.
204206
*
@@ -212,7 +214,7 @@ object SuiteRunner {
212214
private def handleException(e: Throwable, suiteEndpoint: String, name: String, testStartTime: Long, resultType: String, categories: Option[String] = None): SuiteResult = {
213215
val testEndTime = System.currentTimeMillis()
214216
val message = e match {
215-
case _ => s"Request exception occurred while running suite: ${suiteEndpoint}, ${resultType}: ${name}. Exception: ${e.getMessage}"
217+
case _ => s"Request exception occurred while running suite: $suiteEndpoint, $resultType: $name. Exception: ${e.getMessage}"
216218
}
217219
Logger.error(message)
218220
resultType match {

testApi/src/main/scala/africa/absa/testing/scapi/utils/cache/RuntimeCache.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,9 @@ object RuntimeCache {
130130
case "global" => GlobalLevel
131131
case "suite" => SuiteLevel
132132
case "test" => TestLevel
133-
case _ => {
133+
case _ =>
134134
Logger.warn(s"Not known expiration cache level: '$level'. Used default TEST level.")
135135
TestLevel
136-
}
137136
}
138137
}
139138

testApi/src/main/scala/africa/absa/testing/scapi/utils/validation/ContentValidator.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ object ContentValidator {
7272
def validateNotNone(input: Option[String], paramName: String): Unit = {
7373
input match {
7474
case Some(_) => // do nothing, input is valid
75-
case None => throw new ContentValidationFailedException(paramName, "Input cannot be None")
75+
case None => throw ContentValidationFailedException(paramName, "Input cannot be None")
7676
}
7777
}
7878
}

0 commit comments

Comments
 (0)