|
| 1 | +/* |
| 2 | + * Copyright 2023 ABSA Group Limited |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package africa.absa.testing.scapi |
| 18 | + |
| 19 | +import africa.absa.testing.scapi.config.ScAPIRunnerConfig |
| 20 | +import africa.absa.testing.scapi.json.Environment |
| 21 | +import africa.absa.testing.scapi.json.factory.{EnvironmentFactory, SuiteFactory} |
| 22 | +import africa.absa.testing.scapi.logging.Logger |
| 23 | +import africa.absa.testing.scapi.model.suite.{Suite, SuiteResult} |
| 24 | +import africa.absa.testing.scapi.reporter.StdOutReporter |
| 25 | +import africa.absa.testing.scapi.rest.RestClient |
| 26 | +import africa.absa.testing.scapi.rest.request.sender.ScAPIRequestSender |
| 27 | +import africa.absa.testing.scapi.suite.runner.SuiteRunner |
| 28 | +import org.apache.logging.log4j.Level |
| 29 | + |
| 30 | +import java.nio.file.{Files, Paths} |
| 31 | +import scala.util.{Failure, Success} |
| 32 | + |
| 33 | +/** |
| 34 | + * Object `ScAPIRunner` serves as the main entry point for the ScAPI runner. |
| 35 | + */ |
| 36 | +object ScAPIRunner2 { |
| 37 | + |
| 38 | + |
| 39 | + /** |
| 40 | + * The main method that is being invoked to run the ScAPI runner. |
| 41 | + * |
| 42 | + * @param args Command-line arguments. |
| 43 | + */ |
| 44 | + def run(args: Array[String]): String = { |
| 45 | + val cmd = ScAPIRunnerConfig.getCmdLineArguments(args) match { |
| 46 | + case Success(value) => value |
| 47 | + case Failure(exception) => throw exception |
| 48 | + } |
| 49 | + |
| 50 | + System.setProperty("log4j.configurationFile", "log4j2.xml") |
| 51 | + cmd match { |
| 52 | + case c if c.trace => Logger.setLevel(Level.TRACE) |
| 53 | + case c if c.debug => Logger.setLevel(Level.DEBUG) |
| 54 | + case _ => Logger.setLevel(Level.INFO) |
| 55 | + } |
| 56 | + cmd.logConfigInfo() |
| 57 | + |
| 58 | + val suitesPath = Paths.get(cmd.testRootPath, "suites") |
| 59 | + if (!Files.exists(suitesPath)) throw SuiteLoadFailedException("'suites' directory have to exist in project root.") |
| 60 | + |
| 61 | + // jsons to objects |
| 62 | + val environment: Environment = EnvironmentFactory.fromFile(cmd.envPath) |
| 63 | + val suiteBundles: Set[Suite] = SuiteFactory.fromFiles(environment, suitesPath, cmd.filter, cmd.fileFormat) |
| 64 | + SuiteFactory.validateSuiteContent(suiteBundles) |
| 65 | + |
| 66 | + // run tests and result reporting - use categories for test filtering |
| 67 | + if (cmd.validateOnly) { |
| 68 | + Logger.info("Validate only => end run.") |
| 69 | + "" |
| 70 | + } else { |
| 71 | + Logger.info("Running tests") |
| 72 | + val suiteResults: List[SuiteResult] = SuiteRunner.runSuites(suiteBundles, environment, () => new RestClient(ScAPIRequestSender)) |
| 73 | + StdOutReporter.printReport(suiteResults) |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + def newMethod(): Unit = { |
| 78 | + val decision = true |
| 79 | + if (decision) { |
| 80 | + Logger.info("I am always here") |
| 81 | + } else { |
| 82 | + Logger.info("Never see me here") |
| 83 | + } |
| 84 | + Logger.info(s"We meet here at final") |
| 85 | + } |
| 86 | + |
| 87 | + def main(args: Array[String]): Unit = { |
| 88 | + val output = run(args) |
| 89 | + Logger.info(s"ScAPI Runner output:\n$output") |
| 90 | + } |
| 91 | +} |
0 commit comments