From 657bae7449af71fe8de1b9ceef49cabafbd3b115 Mon Sep 17 00:00:00 2001 From: John Green Date: Wed, 6 Mar 2024 11:01:15 +0000 Subject: [PATCH] APIS-6891: Subproject for integration tests (#115) * APIS-6891: Subproject for integration tests * APIS-6891: build.sbt fixes --- .scalafmt.conf | 6 +- .../AcceptanceTestSpec.scala | 42 +++---- .../ApiSubscriptionFieldsHappySpec.scala | 48 ++++---- .../ApiSubscriptionFieldsUnhappySpec.scala | 9 +- .../ExternalServicesConfig.scala} | 2 +- ...ubscriptionFieldDefinitionsHappySpec.scala | 28 +++-- ...scriptionFieldDefinitionsUnhappySpec.scala | 7 +- .../controller/Helper.scala | 5 +- build.sbt | 107 ++++++------------ project/AppDependencies.scala | 10 +- project/ScoverageSettings.scala | 1 - project/plugins.sbt | 9 +- run_all_tests.sh | 4 +- 13 files changed, 117 insertions(+), 161 deletions(-) rename acceptance/{ => test}/uk/gov/hmrc/apisubscriptionfields/AcceptanceTestSpec.scala (88%) rename acceptance/{ => test}/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsHappySpec.scala (87%) rename acceptance/{ => test}/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsUnhappySpec.scala (97%) rename acceptance/{uk/gov/hmrc/apisubscriptionfields/ExternalServices.scala => test/uk/gov/hmrc/apisubscriptionfields/ExternalServicesConfig.scala} (95%) rename acceptance/{ => test}/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsHappySpec.scala (88%) rename acceptance/{ => test}/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsUnhappySpec.scala (97%) rename acceptance/{ => test}/uk/gov/hmrc/apisubscriptionfields/controller/Helper.scala (87%) diff --git a/.scalafmt.conf b/.scalafmt.conf index 1a13616..5ac8eb7 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version="3.5.3" +version="3.7.17" runner.dialect = "scala213" maxColumn = 180 @@ -31,9 +31,9 @@ newlines.implicitParamListModifierPrefer = before newlines.avoidForSimpleOverflow = [tooLong, punct, slc] rewrite.rules = [SortModifiers] -rewrite.imports.sort = ascii +rewrite.rules = [AsciiSortImports] verticalMultiline.atDefnSite = true verticalMultiline.newlineAfterOpenParen = true -includeNoParensInSelectChains = true \ No newline at end of file +includeNoParensInSelectChains = true diff --git a/acceptance/uk/gov/hmrc/apisubscriptionfields/AcceptanceTestSpec.scala b/acceptance/test/uk/gov/hmrc/apisubscriptionfields/AcceptanceTestSpec.scala similarity index 88% rename from acceptance/uk/gov/hmrc/apisubscriptionfields/AcceptanceTestSpec.scala rename to acceptance/test/uk/gov/hmrc/apisubscriptionfields/AcceptanceTestSpec.scala index 668acf0..96f3659 100644 --- a/acceptance/uk/gov/hmrc/apisubscriptionfields/AcceptanceTestSpec.scala +++ b/acceptance/test/uk/gov/hmrc/apisubscriptionfields/AcceptanceTestSpec.scala @@ -17,7 +17,15 @@ package uk.gov.hmrc.apisubscriptionfields import java.util.UUID +import scala.concurrent.duration._ +import scala.concurrent.{Await, Future} + +import cats.data.NonEmptyList +import org.scalatest.featurespec.AnyFeatureSpec +import org.scalatest.matchers.should.Matchers +import org.scalatest.{BeforeAndAfterAll, GivenWhenThen} import org.scalatestplus.play.guice.GuiceOneServerPerSuite + import play.api.Application import play.api.inject.guice.GuiceApplicationBuilder import play.api.libs.json.Json @@ -25,26 +33,18 @@ import play.api.mvc._ import play.api.mvc.request.RequestTarget import play.api.test.FakeRequest import play.api.test.Helpers._ -import uk.gov.hmrc.apisubscriptionfields.model._ - -import scala.concurrent.duration._ -import scala.concurrent.{Await, Future} -import cats.data.NonEmptyList -import uk.gov.hmrc.apisubscriptionfields.controller.Helper import uk.gov.hmrc.mongo.MongoComponent -import org.scalatest.matchers.should.Matchers -import org.scalatest.GivenWhenThen -import org.scalatest.BeforeAndAfterAll -import org.scalatest.featurespec.AnyFeatureSpec +import uk.gov.hmrc.apisubscriptionfields.controller.Helper +import uk.gov.hmrc.apisubscriptionfields.model._ trait AcceptanceTestSpec extends AnyFeatureSpec - with GivenWhenThen - with BeforeAndAfterAll - with Matchers - with GuiceOneServerPerSuite - with FieldDefinitionTestData - with Helper { + with GivenWhenThen + with BeforeAndAfterAll + with Matchers + with GuiceOneServerPerSuite + with FieldDefinitionTestData + with Helper { protected val ValidRequest = FakeRequest() .withHeaders(RequestHeaders.ACCEPT_HMRC_JSON_HEADER) @@ -81,8 +81,8 @@ trait AcceptanceTestSpec extends AnyFeatureSpec s"/field/application/$clientId/context/$apiContext/version/$apiVersionNbr" override def fakeApplication(): Application = new GuiceApplicationBuilder().configure(Map( - "metrics.jvm" -> false, - "run.mode" -> "Stub", + "metrics.jvm" -> false, + "run.mode" -> "Stub", "Test.microservice.services.api-subscription-fields.host" -> ExternalServicesConfig.Host, "Test.microservice.services.api-subscription-fields.port" -> ExternalServicesConfig.Port )) @@ -103,11 +103,11 @@ trait AcceptanceTestSpec extends AnyFeatureSpec } private def dropDatabase(): Unit = { - await( app.injector.instanceOf[MongoComponent].database.drop().toFuture()) + await(app.injector.instanceOf[MongoComponent].database.drop().toFuture()) } def createRequest(method: String, path: String) = ValidRequest .withMethod(method) - .withTarget( RequestTarget(uriString ="", path= path, queryString = Map.empty)) -} \ No newline at end of file + .withTarget(RequestTarget(uriString = "", path = path, queryString = Map.empty)) +} diff --git a/acceptance/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsHappySpec.scala b/acceptance/test/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsHappySpec.scala similarity index 87% rename from acceptance/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsHappySpec.scala rename to acceptance/test/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsHappySpec.scala index bcba204..22344b3 100644 --- a/acceptance/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsHappySpec.scala +++ b/acceptance/test/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsHappySpec.scala @@ -16,33 +16,34 @@ package uk.gov.hmrc.apisubscriptionfields -import org.scalatest.OptionValues -import org.scalatest.BeforeAndAfterAll +import scala.concurrent.duration._ +import scala.concurrent.{Await, Future} + +import org.scalatest.{BeforeAndAfterAll, OptionValues} + import play.api.libs.json.Json import play.api.mvc._ import play.api.mvc.request.RequestTarget import play.api.test.FakeRequest import play.api.test.Helpers._ +import uk.gov.hmrc.apiplatform.modules.common.domain.models._ + import uk.gov.hmrc.apisubscriptionfields.model._ -import scala.concurrent.Future -import scala.concurrent.Await -import scala.concurrent.duration._ import uk.gov.hmrc.apisubscriptionfields.utils.ApplicationLogger -import uk.gov.hmrc.apiplatform.modules.common.domain.models._ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec - with OptionValues - with JsonFormatters - with SubscriptionFieldsTestData - with FieldDefinitionTestData - with BeforeAndAfterAll - with ApplicationLogger { + with OptionValues + with JsonFormatters + with SubscriptionFieldsTestData + with FieldDefinitionTestData + with BeforeAndAfterAll + with ApplicationLogger { override def beforeAll(): Unit = { super.beforeAll() val putRequest = validDefinitionPutRequest(NelOfFieldDefinitions) - .withTarget( RequestTarget(uriString="", path=definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) + .withTarget(RequestTarget(uriString = "", path = definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) Await.result(route(app, putRequest).get, 10.seconds) } @@ -50,20 +51,19 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec override def afterAll(): Unit = { val request = ValidRequest .withMethod(DELETE) - .withTarget( RequestTarget(uriString="", path=definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) + .withTarget(RequestTarget(uriString = "", path = definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) route(app, request) super.afterAll() } - Feature("Subscription-Fields") { appLogger.logger.info(s"App.mode = ${app.mode.toString}") Scenario("the API is called to store some values for a new subscription field") { - val request: Request[AnyContentAsJson] = createSubscriptionFieldsRequest() + val request: Request[AnyContentAsJson] = createSubscriptionFieldsRequest() When("a PUT request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -75,7 +75,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec status(resultFuture) shouldBe CREATED And("the response body should be a valid response") - val sfr = contentAsJson(resultFuture).validate[SubscriptionFields] + val sfr = contentAsJson(resultFuture).validate[SubscriptionFields] val fieldsId = sfr.get.fieldsId sfr.isSuccess shouldBe true @@ -87,7 +87,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec .withJsonBody(Json.toJson(makeSubscriptionFieldsRequest(SampleFields1))) } - def createSubscriptionFields()= { + def createSubscriptionFields() = { route(app, createSubscriptionFieldsRequest()) } @@ -108,7 +108,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec status(resultFuture) shouldBe OK And("the response body should be a valid response") - val sfr = contentAsJson(resultFuture).validate[SubscriptionFields] + val sfr = contentAsJson(resultFuture).validate[SubscriptionFields] val fieldsId = sfr.get.fieldsId sfr.isSuccess shouldBe true @@ -132,7 +132,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec status(resultFuture) shouldBe OK And("the response body should be a valid response") - val sfr = contentAsJson(resultFuture).validate[BulkSubscriptionFieldsResponse] + val sfr = contentAsJson(resultFuture).validate[BulkSubscriptionFieldsResponse] val fieldsId = sfr.get.subscriptions.head.fieldsId sfr.isSuccess shouldBe true @@ -145,7 +145,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec createSubscriptionFields() - val requestId = createRequest(GET, subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) + val requestId = createRequest(GET, subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) When("an id GET request with data is sent to the API") val result: Option[Future[Result]] = route(app, requestId) @@ -164,7 +164,6 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec val requestFieldsId = createRequest(GET, fieldsIdEndpoint(fieldsId.value)) - When("a fieldsId GET request with data is sent to the API") val resultFieldsId: Option[Future[Result]] = route(app, requestFieldsId) @@ -193,11 +192,10 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec result shouldBe defined val resultFuture = result.value - status(resultFuture) shouldBe OK And("the response body should be a valid response") - val sfr = contentAsJson(resultFuture).validate[BulkSubscriptionFieldsResponse] + val sfr = contentAsJson(resultFuture).validate[BulkSubscriptionFieldsResponse] val fieldsId = sfr.get.subscriptions.head.fieldsId sfr.isSuccess shouldBe true @@ -221,7 +219,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec status(resultFuture) shouldBe OK And("the response body should be a valid response") - val sfr = contentAsJson(resultFuture).validate[SubscriptionFields] + val sfr = contentAsJson(resultFuture).validate[SubscriptionFields] val fieldsId = sfr.get.fieldsId sfr.isSuccess shouldBe true diff --git a/acceptance/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsUnhappySpec.scala b/acceptance/test/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsUnhappySpec.scala similarity index 97% rename from acceptance/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsUnhappySpec.scala rename to acceptance/test/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsUnhappySpec.scala index 88d08db..b47da1d 100644 --- a/acceptance/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsUnhappySpec.scala +++ b/acceptance/test/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsUnhappySpec.scala @@ -16,15 +16,16 @@ package uk.gov.hmrc.apisubscriptionfields +import scala.concurrent.Future + import org.scalatest.OptionValues + import play.api.libs.json.Json import play.api.mvc._ import play.api.test.Helpers._ -import uk.gov.hmrc.apisubscriptionfields.model.ErrorCode -import uk.gov.hmrc.apisubscriptionfields.model.JsErrorResponse -import uk.gov.hmrc.apisubscriptionfields.utils.ApplicationLogger -import scala.concurrent.Future +import uk.gov.hmrc.apisubscriptionfields.model.{ErrorCode, JsErrorResponse} +import uk.gov.hmrc.apisubscriptionfields.utils.ApplicationLogger class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec with OptionValues diff --git a/acceptance/uk/gov/hmrc/apisubscriptionfields/ExternalServices.scala b/acceptance/test/uk/gov/hmrc/apisubscriptionfields/ExternalServicesConfig.scala similarity index 95% rename from acceptance/uk/gov/hmrc/apisubscriptionfields/ExternalServices.scala rename to acceptance/test/uk/gov/hmrc/apisubscriptionfields/ExternalServicesConfig.scala index 70f5850..51d5294 100644 --- a/acceptance/uk/gov/hmrc/apisubscriptionfields/ExternalServices.scala +++ b/acceptance/test/uk/gov/hmrc/apisubscriptionfields/ExternalServicesConfig.scala @@ -18,5 +18,5 @@ package uk.gov.hmrc.apisubscriptionfields object ExternalServicesConfig { val Port: Int = 11111 - val Host = "localhost" + val Host = "localhost" } diff --git a/acceptance/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsHappySpec.scala b/acceptance/test/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsHappySpec.scala similarity index 88% rename from acceptance/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsHappySpec.scala rename to acceptance/test/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsHappySpec.scala index 5ef543c..c8d7319 100644 --- a/acceptance/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsHappySpec.scala +++ b/acceptance/test/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsHappySpec.scala @@ -16,27 +16,28 @@ package uk.gov.hmrc.apisubscriptionfields +import scala.concurrent.Future + import org.scalatest.OptionValues + import play.api.mvc._ import play.api.mvc.request.RequestTarget import play.api.test.Helpers._ + import uk.gov.hmrc.apisubscriptionfields.model._ -import scala.concurrent.Future class SubscriptionFieldDefinitionsHappySpec extends AcceptanceTestSpec - with OptionValues - with SubscriptionFieldsTestData - with FieldDefinitionTestData - with JsonFormatters { - + with OptionValues + with SubscriptionFieldsTestData + with FieldDefinitionTestData + with JsonFormatters { Feature("Fields-Definition") { - Scenario("the API is called to store some new fields definitions") { Given("Definitiions are created ") val putRequest = validDefinitionPutRequest(NelOfFieldDefinitions) - .withTarget( RequestTarget(uriString="", path=definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) + .withTarget(RequestTarget(uriString = "", path = definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) When("a PUT request with data is sent to the API") val putResult: Option[Future[Result]] = route(app, putRequest) @@ -54,14 +55,11 @@ class SubscriptionFieldDefinitionsHappySpec extends AcceptanceTestSpec sfr.get shouldBe ApiFieldDefinitions(FakeContext, FakeVersion, NelOfFieldDefinitions) } - - - Scenario("the API is called to GET a known fields definition") { Then("a request with a known fields definition") val request = ValidRequest - .withMethod(GET) + .withMethod(GET) .withTarget(RequestTarget(uriString = "", path = definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) When("a GET request with data is sent to the API") @@ -106,8 +104,8 @@ class SubscriptionFieldDefinitionsHappySpec extends AcceptanceTestSpec Scenario("the API is called to update some existing fields definitions") { Given("a request with valid payload") - val request = validDefinitionPutRequest(NelOfFieldDefinitions) - .withTarget( RequestTarget(uriString="", path=definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) + val request = validDefinitionPutRequest(NelOfFieldDefinitions) + .withTarget(RequestTarget(uriString = "", path = definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) When("a PUT request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -129,7 +127,7 @@ class SubscriptionFieldDefinitionsHappySpec extends AcceptanceTestSpec Given("a request with valid payload") val request = ValidRequest .withMethod(DELETE) - .withTarget( RequestTarget(uriString="", path=definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) + .withTarget(RequestTarget(uriString = "", path = definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) When("a DELETE request sent to the API") val result: Option[Future[Result]] = route(app, request) diff --git a/acceptance/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsUnhappySpec.scala b/acceptance/test/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsUnhappySpec.scala similarity index 97% rename from acceptance/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsUnhappySpec.scala rename to acceptance/test/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsUnhappySpec.scala index ad6d13a..b3039e8 100644 --- a/acceptance/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsUnhappySpec.scala +++ b/acceptance/test/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsUnhappySpec.scala @@ -16,15 +16,16 @@ package uk.gov.hmrc.apisubscriptionfields +import scala.concurrent.Future + import org.scalatest.OptionValues + import play.api.libs.json.Json import play.api.mvc._ import play.api.mvc.request.RequestTarget import play.api.test.Helpers._ -import uk.gov.hmrc.apisubscriptionfields.model.ErrorCode -import uk.gov.hmrc.apisubscriptionfields.model.JsErrorResponse -import scala.concurrent.Future +import uk.gov.hmrc.apisubscriptionfields.model.{ErrorCode, JsErrorResponse} class SubscriptionFieldDefinitionsUnhappySpec extends AcceptanceTestSpec with OptionValues diff --git a/acceptance/uk/gov/hmrc/apisubscriptionfields/controller/Helper.scala b/acceptance/test/uk/gov/hmrc/apisubscriptionfields/controller/Helper.scala similarity index 87% rename from acceptance/uk/gov/hmrc/apisubscriptionfields/controller/Helper.scala rename to acceptance/test/uk/gov/hmrc/apisubscriptionfields/controller/Helper.scala index ea9c163..071dc2d 100644 --- a/acceptance/uk/gov/hmrc/apisubscriptionfields/controller/Helper.scala +++ b/acceptance/test/uk/gov/hmrc/apisubscriptionfields/controller/Helper.scala @@ -16,11 +16,12 @@ package uk.gov.hmrc.apisubscriptionfields.controller -import uk.gov.hmrc.apisubscriptionfields.model.{Types, FieldDefinition} import cats.data.{NonEmptyList => NEL} +import uk.gov.hmrc.apisubscriptionfields.model.{FieldDefinition, Types} + trait Helper { - def makeSubscriptionFieldsRequest(fields: Types.Fields): SubscriptionFieldsRequest = SubscriptionFieldsRequest(fields) + def makeSubscriptionFieldsRequest(fields: Types.Fields): SubscriptionFieldsRequest = SubscriptionFieldsRequest(fields) def makeFieldDefinitionsRequest(definitions: NEL[FieldDefinition]): FieldDefinitionsRequest = FieldDefinitionsRequest(definitions) } diff --git a/build.sbt b/build.sbt index c96052e..3b3a1fc 100644 --- a/build.sbt +++ b/build.sbt @@ -1,62 +1,25 @@ -/* - * Copyright 2017 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import sbt.Keys.{parallelExecution, _} -import sbt._ -import uk.gov.hmrc.DefaultBuildSettings.{addTestReportOption, defaultSettings, scalaSettings} -import uk.gov.hmrc.SbtAutoBuildPlugin -import uk.gov.hmrc.sbtdistributables.SbtDistributablesPlugin -import uk.gov.hmrc.sbtdistributables.SbtDistributablesPlugin._ -import uk.gov.hmrc.versioning.SbtGitVersioning -import bloop.integrations.sbt.BloopDefaults - +import uk.gov.hmrc.DefaultBuildSettings +import uk.gov.hmrc.DefaultBuildSettings._ import scala.language.postfixOps val appName = "api-subscription-fields" -scalaVersion := "2.13.12" +Global / bloopAggregateSourceDependencies := true +Global / bloopExportJarClassifiers := Some(Set("sources")) +ThisBuild / scalaVersion := "2.13.12" +ThisBuild / majorVersion := 0 +ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always ThisBuild / semanticdbEnabled := true ThisBuild / semanticdbVersion := scalafixSemanticdb.revision -ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always - -lazy val plugins: Seq[Plugins] = Seq(PlayScala, SbtAutoBuildPlugin, SbtDistributablesPlugin) -lazy val playSettings: Seq[Setting[_]] = Seq.empty - -lazy val AcceptanceTest = config("acceptance") extend Test - -lazy val acceptanceTestSettings = - inConfig(AcceptanceTest)(Defaults.testSettings) ++ - inConfig(AcceptanceTest)(BloopDefaults.configSettings) ++ - Seq( - AcceptanceTest / unmanagedSourceDirectories := Seq(baseDirectory.value / "acceptance"), - AcceptanceTest / fork := false, - AcceptanceTest / parallelExecution := false, - addTestReportOption(AcceptanceTest, "acceptance-reports") - ) - lazy val microservice = Project(appName, file(".")) - .enablePlugins(plugins: _*) - .configs(AcceptanceTest) - .settings(playSettings: _*) - .settings(scalaSettings: _*) - .settings(defaultSettings(): _*) - .settings(acceptanceTestSettings: _*) - .settings(headerSettings(AcceptanceTest) ++ automateHeaderSettings(AcceptanceTest)) + .enablePlugins(PlayScala, SbtDistributablesPlugin) + .disablePlugins(JUnitXmlReportPlugin) + .settings( + libraryDependencies ++= AppDependencies(), + retrieveManaged := true + ) .settings(ScoverageSettings()) .settings( routesImport ++= Seq( @@ -64,37 +27,33 @@ lazy val microservice = Project(appName, file(".")) "uk.gov.hmrc.apiplatform.modules.common.domain.models._", "uk.gov.hmrc.apisubscriptionfields.controller.Binders._" ) - - ) - .settings( - libraryDependencies ++= AppDependencies(), ) - .settings( - Test / fork := false, - addTestReportOption(Test, "test-reports"), - Test / parallelExecution := false - ) - .settings(majorVersion := 0) .settings( scalacOptions ++= Seq( - "-Wconf:cat=unused&src=.*RoutesPrefix\\.scala:s", - "-Wconf:cat=unused&src=.*Routes\\.scala:s", - "-Wconf:cat=unused&src=.*ReverseRoutes\\.scala:s", - "-Xlint:-byname-implicit" + // https://www.scala-lang.org/2021/01/12/configuring-and-suppressing-warnings.html + // suppress warnings in generated routes files + "-Wconf:src=routes/.*:s", + "-Xlint:-byname-implicit" ) ) + +lazy val acceptance = (project in file("acceptance")) + .enablePlugins(PlayScala) + .dependsOn(microservice % "test->test") .settings( - commands += Command.command("testAll") { state => "test" :: "acceptance:test" :: state } + name := "acceptance-tests", + Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-eT"), + DefaultBuildSettings.itSettings(), + addTestReportOption(Test, "acceptance-reports") ) -def onPackageName(rootPackage: String): String => Boolean = { testName => testName startsWith rootPackage } - -// Note that this task has to be scoped globally -Global / bloopAggregateSourceDependencies := true - commands ++= Seq( - Command.command("run-all-tests") { state => "test" :: "acceptance:test" :: state }, - Command.command("clean-and-test") { state => "clean" :: "compile" :: "run-all-tests" :: state }, - // Coverage does not need compile ! - Command.command("pre-commit") { state => "clean" :: "scalafmtAll" :: "scalafixAll" :: "coverage" :: "run-all-tests" :: "coverageOff" :: "coverageReport" :: state } + Command.command("cleanAll") { state => "clean" :: "acceptance/clean" :: state }, + Command.command("fmtAll") { state => "scalafmtAll" :: "acceptance/scalafmtAll" :: state }, + Command.command("fixAll") { state => "scalafixAll" :: "acceptance/scalafixAll" :: state }, + Command.command("testAll") { state => "test" :: "acceptance/test" :: state }, + + Command.command("run-all-tests") { state => "testAll" :: state }, + Command.command("clean-and-test") { state => "cleanAll" :: "compile" :: "run-all-tests" :: state }, + Command.command("pre-commit") { state => "cleanAll" :: "fmtAll" :: "fixAll" :: "coverage" :: "testAll" :: "coverageOff" :: "coverageAggregate" :: state } ) diff --git a/project/AppDependencies.scala b/project/AppDependencies.scala index 47571c2..0d8c26e 100644 --- a/project/AppDependencies.scala +++ b/project/AppDependencies.scala @@ -1,18 +1,17 @@ import sbt._ -import play.core.PlayVersion object AppDependencies { def apply(): Seq[ModuleID] = dependencies ++ testDependencies private lazy val mongoVersion = "1.7.0" private lazy val bootstrapVersion = "8.4.0" - val commonDomainVersion = "0.12.0" + val commonDomainVersion = "0.13.0" private lazy val dependencies = Seq( "uk.gov.hmrc" %% "bootstrap-backend-play-30" % bootstrapVersion, "uk.gov.hmrc.mongo" %% "hmrc-mongo-play-30" % mongoVersion, "uk.gov.hmrc" %% "http-metrics" % "2.8.0", - "org.typelevel" %% "cats-core" % "2.9.0", + "org.typelevel" %% "cats-core" % "2.10.0", "eu.timepit" %% "refined" % "0.10.2", "commons-validator" % "commons-validator" % "1.6", "uk.gov.hmrc" %% "api-platform-common-domain" % commonDomainVersion @@ -23,6 +22,7 @@ object AppDependencies { "uk.gov.hmrc.mongo" %% "hmrc-mongo-test-play-30" % mongoVersion, "uk.gov.hmrc" %% "api-platform-test-common-domain" % commonDomainVersion, "org.pegdown" % "pegdown" % "1.6.0", - "org.mockito" %% "mockito-scala-scalatest" % "1.17.29", - ).map(d => d % "test,acceptance") + "org.mockito" %% "mockito-scala-scalatest" % "1.17.30" + ).map(d => d % "test") } + diff --git a/project/ScoverageSettings.scala b/project/ScoverageSettings.scala index 9139608..9358790 100644 --- a/project/ScoverageSettings.scala +++ b/project/ScoverageSettings.scala @@ -9,7 +9,6 @@ object ScoverageSettings { // Semicolon-separated list of regexs matching classes to exclude coverageExcludedPackages := Seq( "", - "com.kenshoo.play.metrics.*", "prod.*", "testOnlyDoNotUseInAppConf.*", "app.*", diff --git a/project/plugins.sbt b/project/plugins.sbt index 762edfc..9718b18 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,12 +1,13 @@ -resolvers += "HMRC-open-artefacts-maven" at "https://open.artefacts.tax.service.gov.uk/maven2" -resolvers += Resolver.url("HMRC-open-artefacts-ivy", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(Resolver.ivyStylePatterns) +resolvers += MavenRepository("HMRC-open-artefacts-maven2", "https://open.artefacts.tax.service.gov.uk/maven2") +resolvers += Resolver.url("HMRC-open-artefacts-ivy2", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(Resolver.ivyStylePatterns) +resolvers += Resolver.typesafeRepo("releases") addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.20.0") addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.5.0") addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9") -addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") +addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % "1.0.0") addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.1") -addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.5.11") +addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.5.15") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.1") diff --git a/run_all_tests.sh b/run_all_tests.sh index 022d239..35a85cb 100755 --- a/run_all_tests.sh +++ b/run_all_tests.sh @@ -1,4 +1,2 @@ #!/usr/bin/env bash - -export SBT_OPTS="-XX:MaxMetaspaceSize=1G" -sbt clean coverage test acceptance:test coverageReport +sbt pre-commit