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

APIS-6912: Subprojects for integration and component tests #50

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version="3.5.3"
version="3.7.17"
runner.dialect = "scala213"

maxColumn = 180
Expand Down
86 changes: 38 additions & 48 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,73 +1,63 @@
import uk.gov.hmrc.sbtdistributables.SbtDistributablesPlugin._
import uk.gov.hmrc.DefaultBuildSettings
import AppDependencies._

import bloop.integrations.sbt.BloopDefaults
import uk.gov.hmrc.DefaultBuildSettings._

val appName = "api-platform-xml-services"

Global / bloopAggregateSourceDependencies := true
Global / bloopExportJarClassifiers := Some(Set("sources"))

scalaVersion := "2.13.12"

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


lazy val microservice = Project(appName, file("."))
.enablePlugins(PlayScala, SbtDistributablesPlugin)
.disablePlugins(JUnitXmlReportPlugin)
.settings(
name := appName,
organization := "uk.gov.hmrc",
majorVersion := 0,
PlayKeys.playDefaultPort := 11116,
libraryDependencies ++= AppDependencies(),
retrieveManaged := true
PlayKeys.playDefaultPort := 11116,
libraryDependencies ++= AppDependencies(),
retrieveManaged := true,
// https://www.scala-lang.org/2021/01/12/configuring-and-suppressing-warnings.html
// suppress warnings in generated routes files
scalacOptions += "-Wconf:src=routes/.*:s"
)
.settings(ScoverageSettings())
.settings(Compile / unmanagedResourceDirectories += baseDirectory.value / "resources")
.configs(IntegrationTest)
.settings(DefaultBuildSettings.integrationTestSettings())
.settings(inConfig(IntegrationTest)(scalafixConfigSettings(IntegrationTest)))
.settings(inConfig(IntegrationTest)(ScalafmtPlugin.scalafmtConfigSettings))
.settings(
IntegrationTest / testOptions := Seq(Tests.Argument(TestFrameworks.ScalaTest, "-eT")),
IntegrationTest / unmanagedSourceDirectories += baseDirectory.value / "testcommon",
IntegrationTest / unmanagedSourceDirectories += baseDirectory.value / "it",
IntegrationTest / parallelExecution := false
)
.settings(Compile / unmanagedResourceDirectories += baseDirectory.value / "resources")
.settings(
Test / fork := false,
Test / parallelExecution := false,
Test / testOptions := Seq(Tests.Argument(TestFrameworks.ScalaTest, "-eT")),
Test / unmanagedSourceDirectories += baseDirectory.value / "testcommon",
Test / unmanagedSourceDirectories += baseDirectory.value / "test"
Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-eT"),
Test / unmanagedSourceDirectories += baseDirectory.value / "testcommon"
)
.settings(
routesImport ++= Seq(
"uk.gov.hmrc.apiplatformxmlservices.controllers.binders._",
"uk.gov.hmrc.apiplatformxmlservices.models._",
"uk.gov.hmrc.apiplatform.modules.common.domain.models._",
"uk.gov.hmrc.apiplatform.modules.apis.domain.models._"
)
)
.settings(
scalacOptions ++= Seq(
"-Wconf:cat=unused&src=views/.*\\.scala:s",
"-Wconf:cat=unused&src=.*RoutesPrefix\\.scala:s",
"-Wconf:cat=unused&src=.*Routes\\.scala:s",
"-Wconf:cat=unused&src=.*ReverseRoutes\\.scala:s"
routesImport ++= Seq(
"uk.gov.hmrc.apiplatformxmlservices.controllers.binders._",
"uk.gov.hmrc.apiplatformxmlservices.models._",
"uk.gov.hmrc.apiplatform.modules.common.domain.models._",
"uk.gov.hmrc.apiplatform.modules.apis.domain.models._"
)
)
.disablePlugins(JUnitXmlReportPlugin)

Global / bloopAggregateSourceDependencies := true

commands ++= Seq(
Command.command("run-all-tests") { state => "test" :: "it:test" :: state },
lazy val it = (project in file("it"))
.enablePlugins(PlayScala)
.dependsOn(microservice % "test->test")
.settings(
name := "integration-tests",
Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-eT"),
DefaultBuildSettings.itSettings(),
addTestReportOption(Test, "int-test-reports")
)

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" :: "coverageReport" :: "coverageOff" :: state }
commands ++= Seq(
Command.command("cleanAll") { state => "clean" :: "it/clean" :: state },
Command.command("fmtAll") { state => "scalafmtAll" :: "it/scalafmtAll" :: state },
Command.command("fixAll") { state => "scalafixAll" :: "it/scalafixAll" :: state },
Command.command("testAll") { state => "test" :: "it/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 }
)
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class OrganisationControllerISpec extends ServerBaseISpec with BeforeAndAfterEac
val result = callGetEndpoint(s"$url/organisations")
result.status mustBe OK
val organisations = Json.parse(result.body).as[List[Organisation]]
organisations must contain only (anOrganisation, organisation2)
organisations must contain.only(anOrganisation, organisation2)
}

"respond with 404 when VendorId not found" in new Setup {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class OrganisationRepositoryISpec

val results = await(repo.findByOrganisationName(OrganisationName("DEF")))

results should contain allOf (org3, org4)
results should contain.allOf(org3, org4)
}

"return no organisations when there are no matches" in new Setup {
Expand Down
9 changes: 4 additions & 5 deletions project/AppDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ object AppDependencies {

lazy val mongoVersion = "1.7.0"
lazy val bootstrapVersion = "8.4.0"
val apiDomainVersion = "0.11.0"
val commonDomainVersion = "0.10.0"
val apiDomainVersion = "0.15.0"
val commonDomainVersion = "0.13.0"

def apply(): Seq[ModuleID] =
compile ++ test
Expand All @@ -25,8 +25,7 @@ object AppDependencies {
"uk.gov.hmrc" %% "bootstrap-test-play-30" % bootstrapVersion,
"uk.gov.hmrc.mongo" %% "hmrc-mongo-test-play-30" % mongoVersion,
"org.pegdown" % "pegdown" % "1.6.0",
"org.mockito" %% "mockito-scala-scalatest" % "1.17.29",
"com.github.tomakehurst" % "wiremock-jre8-standalone" % "2.35.1",
"org.mockito" %% "mockito-scala-scalatest" % "1.17.30",
"uk.gov.hmrc" %% "api-platform-test-common-domain" % commonDomainVersion
).map(_ % "test, it")
).map(_ % "test")
}
18 changes: 9 additions & 9 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ resolvers += MavenRepository("HMRC-open-artefacts-maven2", "https://open.artefac
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.playframework" % "sbt-plugin" % "3.0.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("ch.epfl.scala" %% "sbt-scalafix" % "0.11.1")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.5.13")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.20.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.5.0")
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")
addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % "1.0.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.1")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.5.15")

ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always
ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always
2 changes: 1 addition & 1 deletion run_all_tests.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
sbt clean scalafmtAll scalafixAll scalastyle coverage test it:test coverageReport
sbt pre-commit
41 changes: 21 additions & 20 deletions scalastyle-config.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<scalastyle>
<name>Scalastyle standard configuration</name>
<check level="warning" class="org.scalastyle.file.FileTabChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.FileTabChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.file.FileLengthChecker" enabled="true">
<parameters>
<parameter name="maxFileLength"><![CDATA[800]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.file.HeaderMatchesChecker" enabled="false"></check>
<check level="warning" class="org.scalastyle.scalariform.SpacesAfterPlusChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.WhitespaceEndOfLineChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.SpacesBeforePlusChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.HeaderMatchesChecker" enabled="false"/>
<check level="warning" class="org.scalastyle.scalariform.SpacesAfterPlusChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.file.WhitespaceEndOfLineChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.scalariform.SpacesBeforePlusChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.file.FileLineLengthChecker" enabled="false"/>
<check level="warning" class="org.scalastyle.scalariform.ClassNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter>
Expand All @@ -25,7 +26,7 @@
<parameter name="regex"><![CDATA[^[a-z][A-Za-z]*$]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.EqualsHashCodeChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.EqualsHashCodeChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.scalariform.IllegalImportsChecker" enabled="true">
<parameters>
<parameter name="illegalImports"><![CDATA[sun._,java.awt._]]></parameter>
Expand All @@ -41,14 +42,14 @@
<parameter name="ignore"><![CDATA[-1,0,1,2,3]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.NoWhitespaceBeforeLeftBracketChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NoWhitespaceAfterLeftBracketChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.ReturnChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NullChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NoCloneChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NoFinalizeChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.CovariantEqualsChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.StructuralTypeChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NoWhitespaceBeforeLeftBracketChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.scalariform.NoWhitespaceAfterLeftBracketChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.scalariform.ReturnChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.scalariform.NullChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.scalariform.NoCloneChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.scalariform.NoFinalizeChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.scalariform.CovariantEqualsChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.scalariform.StructuralTypeChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.file.RegexChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[println]]></parameter>
Expand All @@ -64,8 +65,8 @@
<parameter name="maximum"><![CDATA[10]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.UppercaseLChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.SimplifyBooleanExpressionChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.UppercaseLChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.scalariform.SimplifyBooleanExpressionChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.scalariform.IfBraceChecker" enabled="true">
<parameters>
<parameter name="singleLineAllowed"><![CDATA[true]]></parameter>
Expand All @@ -87,7 +88,7 @@
<parameter name="maxMethods"><![CDATA[30]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.PublicMethodsHaveTypeChecker" enabled="false"></check>
<check level="warning" class="org.scalastyle.file.NewLineAtEofChecker" enabled="false"></check>
<check level="warning" class="org.scalastyle.file.NoNewLineAtEofChecker" enabled="false"></check>
</scalastyle>
<check level="warning" class="org.scalastyle.scalariform.PublicMethodsHaveTypeChecker" enabled="false"/>
<check level="warning" class="org.scalastyle.file.NewLineAtEofChecker" enabled="false"/>
<check level="warning" class="org.scalastyle.file.NoNewLineAtEofChecker" enabled="false"/>
</scalastyle>