Skip to content

Commit

Permalink
Uplift (#92)
Browse files Browse the repository at this point in the history
* sbt, app dependencies and conf

* scoverage settings

* Upgrade bootstrap
  • Loading branch information
peteslater-ee authored Jun 22, 2021
1 parent 7ad2bea commit 1bd0df7
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import uk.gov.hmrc.apisubscriptionfields.config.ApplicationConfig
import uk.gov.hmrc.apisubscriptionfields.model.Types.FieldValue
import uk.gov.hmrc.apisubscriptionfields.model._
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.play.bootstrap.http.HttpClient
import uk.gov.hmrc.http.HttpClient
import uk.gov.hmrc.play.http.metrics._
import uk.gov.hmrc.http.HttpReads.Implicits._

import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal
Expand Down Expand Up @@ -58,13 +59,13 @@ class PushPullNotificationServiceConnector @Inject()(http: HttpClient, appConfig

def updateCallBackUrl(clientId: ClientId, boxId: BoxId, callbackUrl: FieldValue)
(implicit hc: HeaderCarrier): Future[PPNSCallBackUrlValidationResponse] = {
val payload = UpdateCallBackUrlRequest(clientId, callbackUrl)
http.PUT[UpdateCallBackUrlRequest, UpdateCallBackUrlResponse](s"$externalServiceUri/box/${boxId.value.toString}/callback", payload)
.map(response =>
if (response.successful) PPNSCallBackUrlSuccessResponse
else response.errorMessage.fold(PPNSCallBackUrlFailedResponse("Unknown Error"))(PPNSCallBackUrlFailedResponse)
).recover {
case NonFatal(e) => throw new RuntimeException(s"Unexpected response from $externalServiceUri: ${e.getMessage}")
}
val payload = UpdateCallBackUrlRequest(clientId, callbackUrl)
http.PUT[UpdateCallBackUrlRequest, UpdateCallBackUrlResponse](s"$externalServiceUri/box/${boxId.value.toString}/callback", payload)
.map(response =>
if (response.successful) PPNSCallBackUrlSuccessResponse
else response.errorMessage.fold(PPNSCallBackUrlFailedResponse("Unknown Error"))(PPNSCallBackUrlFailedResponse)
).recover {
case NonFatal(e) => throw new RuntimeException(s"Unexpected response from $externalServiceUri: ${e.getMessage}")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import play.api.libs.json._
import play.api.mvc.{Request, Result}
import uk.gov.hmrc.apisubscriptionfields.model.ErrorCode._
import uk.gov.hmrc.apisubscriptionfields.model.JsErrorResponse
import uk.gov.hmrc.play.bootstrap.controller.BackendBaseController
import uk.gov.hmrc.play.bootstrap.backend.controller.BackendBaseController

import scala.concurrent.Future
import scala.util.{Failure, Success, Try}
Expand Down
1 change: 0 additions & 1 deletion app/uk/gov/hmrc/apisubscriptionfields/model/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package uk.gov.hmrc.apisubscriptionfields.model
import eu.timepit.refined._
import eu.timepit.refined.api.Refined
import eu.timepit.refined.string._
import eu.timepit.refined.boolean._

object Types {
type RegexExpr = String Refined Regex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class SubscriptionFieldsService @Inject() (
}
}

private def upsertSubscriptionFields(clientId: ClientId, apiContext: ApiContext, apiVersion: ApiVersion, fields: Fields)
(implicit hc: HeaderCarrier): Future[SuccessfulSubsFieldsUpsertResponse] = {
private def upsertSubscriptionFields(clientId: ClientId, apiContext: ApiContext, apiVersion: ApiVersion, fields: Fields): Future[SuccessfulSubsFieldsUpsertResponse] = {
val subscriptionFieldsId = SubscriptionFieldsId(uuidCreator.uuid())
val subscriptionFields = SubscriptionFields(clientId, apiContext, apiVersion, subscriptionFieldsId, fields)

Expand Down
43 changes: 5 additions & 38 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ import bloop.integrations.sbt.BloopDefaults

import scala.language.postfixOps

val compile = Seq(
"uk.gov.hmrc" %% "bootstrap-play-26" % "1.4.0",
"uk.gov.hmrc" %% "simple-reactivemongo" % "7.30.0-play-26",
"org.julienrf" %% "play-json-derived-codecs" % "6.0.0",
"com.typesafe.play" %% "play-json" % "2.7.1",
"uk.gov.hmrc" %% "http-metrics" % "1.10.0",
"org.typelevel" %% "cats-core" % "2.1.0",
"eu.timepit" %% "refined" % "0.9.13",
"be.venneborg" %% "play26-refined" % "0.5.0",
"commons-validator" % "commons-validator" % "1.6"
)

// we need to override the akka version for now as newer versions are not compatible with reactivemongo
lazy val akkaVersion = "2.5.23"
lazy val akkaHttpVersion = "10.0.15"
Expand All @@ -49,25 +37,14 @@ val overrides: Seq[ModuleID] = Seq(
"com.typesafe.akka" %% "akka-http-core" % akkaHttpVersion
)

def test(scope: String = "test,acceptance") = Seq(
"uk.gov.hmrc" %% "reactivemongo-test" % "4.21.0-play-26" % scope,
"org.scalatestplus.play" %% "scalatestplus-play" % "3.1.3" % scope,
"org.mockito" %% "mockito-scala-scalatest" % "1.14.4" % scope,
"org.pegdown" % "pegdown" % "1.6.0" % scope,
"com.typesafe.play" %% "play-test" % play.core.PlayVersion.current % scope,
"com.github.tomakehurst" % "wiremock-jre8" % "2.26.3" % scope
)

val appName = "api-subscription-fields"

lazy val appDependencies: Seq[ModuleID] = compile ++ test()

resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
)

lazy val plugins: Seq[Plugins] = Seq(PlayScala, SbtAutoBuildPlugin, SbtGitVersioning, SbtDistributablesPlugin, SbtArtifactory)
lazy val plugins: Seq[Plugins] = Seq(PlayScala, SbtAutoBuildPlugin, SbtDistributablesPlugin)
lazy val playSettings: Seq[Setting[_]] = Seq.empty

lazy val AcceptanceTest = config("acceptance") extend Test
Expand All @@ -80,22 +57,19 @@ lazy val microservice = Project(appName, file("."))
.settings(publishingSettings: _*)
.settings(defaultSettings(): _*)
.settings(acceptanceTestSettings: _*)
.settings(scalaVersion := "2.12.11")
.settings(
inConfig(AcceptanceTest)(BloopDefaults.configSettings)
)
.settings(scalaVersion := "2.12.12")
.settings(ScoverageSettings())
.settings(
routesImport ++= Seq(
"uk.gov.hmrc.apisubscriptionfields.model._",
"uk.gov.hmrc.apisubscriptionfields.controller.Binders._"
)
)
.settings(
libraryDependencies ++= appDependencies,
libraryDependencies ++= AppDependencies(),
dependencyOverrides ++= overrides,
evictionWarningOptions in update := EvictionWarningOptions.default.withWarnScalaVersionEviction(false)
)
.settings(scoverageSettings)
.settings(
fork in Test := false,
addTestReportOption(Test, "test-reports"),
Expand All @@ -106,21 +80,14 @@ lazy val microservice = Project(appName, file("."))

lazy val acceptanceTestSettings =
inConfig(AcceptanceTest)(Defaults.testSettings) ++
inConfig(AcceptanceTest)(BloopDefaults.configSettings) ++
Seq(
unmanagedSourceDirectories in AcceptanceTest := Seq(baseDirectory.value / "acceptance"),
fork in AcceptanceTest := false,
parallelExecution in AcceptanceTest := false,
addTestReportOption(AcceptanceTest, "acceptance-reports")
)

lazy val scoverageSettings: Seq[Setting[_]] = Seq(
coverageExcludedPackages := "<empty>;Reverse.*;.*model.*;.*config.*;.*(AuthService|BuildInfo|Routes).*;.*.application;.*.definition",
coverageMinimum := 94,
coverageFailOnMinimum := true,
coverageHighlighting := true,
parallelExecution in Test := false
)

def onPackageName(rootPackage: String): String => Boolean = { testName => testName startsWith rootPackage }

// Note that this task has to be scoped globally
Expand Down
10 changes: 5 additions & 5 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ play.modules.enabled += "uk.gov.hmrc.play.bootstrap.AuditModule"
play.modules.enabled += "uk.gov.hmrc.play.bootstrap.graphite.GraphiteMetricsModule"

# Provides an implementation and configures all filters required by a Platform backend microservice.
play.modules.enabled += "uk.gov.hmrc.play.bootstrap.MicroserviceModule"
play.modules.enabled += "uk.gov.hmrc.play.bootstrap.backend.BackendModule"
play.http.filters = "uk.gov.hmrc.play.bootstrap.filters.MicroserviceFilters"

# Json error handler
Expand All @@ -58,17 +58,17 @@ play.modules.enabled += "uk.gov.hmrc.play.http.metrics.Module"
# ~~~~~
# The secret key is used to secure cryptographics functions.
# If you deploy your application to several instances be sure to use the same key!
play.crypto.secret="VJ2GT0tQY4ucpdoPeAeJ2hHCPCBYx6gxthXL2WkoOMMgtbgvswGurFEOzhMzOX4q"
play.http.secret.key = "VJ2GT0tQY4ucpdoPeAeJ2hHCPCBYx6gxthXL2WkoOMMgtbgvswGurFEOzhMzOX4q"

# Session configuration
# ~~~~~
application.session.httpOnly=false
play.http.session.httpOnly = false

application.session.secure=false
play.http.session.secure = false

# The application languages
# ~~~~~
application.langs="en"
play.i18n.langs = ["en"]

# Router
# ~~~~~
Expand Down
27 changes: 27 additions & 0 deletions project/AppDependencies.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sbt._
import play.core.PlayVersion

object AppDependencies {
def apply(): Seq[ModuleID] = dependencies ++ testDependencies

private lazy val dependencies = Seq(
"uk.gov.hmrc" %% "bootstrap-backend-play-26" % "4.0.0",
"uk.gov.hmrc" %% "simple-reactivemongo" % "7.30.0-play-26",
"org.julienrf" %% "play-json-derived-codecs" % "6.0.0",
"com.typesafe.play" %% "play-json" % "2.8.1",
"uk.gov.hmrc" %% "http-metrics" % "1.11.0",
"org.typelevel" %% "cats-core" % "2.1.0",
"eu.timepit" %% "refined" % "0.9.13",
"be.venneborg" %% "play26-refined" % "0.5.0",
"commons-validator" % "commons-validator" % "1.6"
)

private lazy val testDependencies = Seq(
"uk.gov.hmrc" %% "reactivemongo-test" % "4.21.0-play-26",
"org.scalatestplus.play" %% "scalatestplus-play" % "3.1.3",
"org.mockito" %% "mockito-scala-scalatest" % "1.14.4",
"org.pegdown" % "pegdown" % "1.6.0",
"com.typesafe.play" %% "play-test" % play.core.PlayVersion.current,
"com.github.tomakehurst" % "wiremock-jre8-standalone" % "2.27.1"
).map(d => d % "test,acceptance")
}
20 changes: 20 additions & 0 deletions project/ScoverageSettings.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import scoverage.ScoverageKeys._

object ScoverageSettings {
def apply() = Seq(
coverageMinimum := 94.00,
coverageFailOnMinimum := true,
coverageHighlighting := true,

// Semicolon-separated list of regexs matching classes to exclude
coverageExcludedPackages := Seq(
"<empty>",
"com.kenshoo.play.metrics.*",
"prod.*",
"testOnlyDoNotUseInAppConf.*",
"app.*",
"uk.gov.hmrc.apisubscriptionfields.config",
"uk.gov.hmrc.BuildInfo"
).mkString(";")
)
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.3.7
sbt.version=1.4.9
5 changes: 1 addition & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ resolvers += Resolver.url("HMRC-open-artefacts-ivy", url("https://open.artefacts

resolvers += "Typesafe Releases" at "https://repo.typesafe.com/typesafe/releases/"

addSbtPlugin("uk.gov.hmrc" %% "sbt-auto-build" % "2.14.0")
addSbtPlugin("uk.gov.hmrc" %% "sbt-git-versioning" % "2.1.0")
addSbtPlugin("uk.gov.hmrc" %% "sbt-auto-build" % "3.0.0")
addSbtPlugin("uk.gov.hmrc" %% "sbt-distributables" % "2.0.0")
addSbtPlugin("org.scoverage" %% "sbt-scoverage" % "1.5.1")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
addSbtPlugin("com.typesafe.play" %% "sbt-plugin" % "2.6.24")
addSbtPlugin("uk.gov.hmrc" %% "sbt-artifactory" % "1.0.0")
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.10.0-RC1")

addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.8")
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class PushPullNotificationServiceConnectorSpec
primeStub(path, requestBody, responseBody)

val ret: Unit = await(connector.subscribe(boxId, callbackUrl))
ret shouldBe ()
ret shouldBe (())

verifyMock(path)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import scala.concurrent.Future.{successful,failed}
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.apisubscriptionfields.connector.PushPullNotificationServiceConnector
import scala.concurrent.ExecutionContext.Implicits.global
import cats.data.{NonEmptyList => NEL}

class PushPullNotificationServiceSpec extends AsyncHmrcSpec with SubscriptionFieldsTestData with FieldDefinitionTestData {

Expand All @@ -47,9 +46,6 @@ class PushPullNotificationServiceSpec extends AsyncHmrcSpec with SubscriptionFie
val callbackUrl = "123"
val oCallbackUrl = Some(callbackUrl)
val ppnsFieldDefinition = FieldDefinition(ppnsFieldName, "description-1", "hint-1", PPNS_FIELD, "short-description-1" )
val fieldDef2 = FieldDefinition(fieldN(2), "description-2", "hint-2", STRING, "short-description-2" )
val fieldDefns: NEL[FieldDefinition] = NEL.of(ppnsFieldDefinition, fieldDef2)
val fields: Types.Fields = Map(fieldN(1) -> oCallbackUrl.value, fieldN(2) -> "something else")
val expectedTopicName = s"${apiContext.value}##${apiVersion.value}##$ppnsFieldName"


Expand Down

0 comments on commit 1bd0df7

Please sign in to comment.