Skip to content

Commit

Permalink
Merge pull request #82 from hmrc/GG-6062
Browse files Browse the repository at this point in the history
GG-6062 : Upgrade to play 2.8
  • Loading branch information
ShaneTN authored Dec 9, 2021
2 parents 017977f + 868b692 commit b6a681e
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 67 deletions.
11 changes: 9 additions & 2 deletions app/controllers/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ import play.api.libs.json.{JsValue, Json, Writes}

package object controllers {

implicit val errorResponseWrites = new Writes[ErrorResponse] {
def writes(e: ErrorResponse): JsValue = Json.obj("code" -> e.errorCode, "message" -> e.message)
def errorWrites[T <: ErrorResponse] = new Writes[T] {
override def writes(o: T): JsValue = Json.obj("code" -> o.errorCode, "message" -> o.message)
}

implicit val errorResponseWrites = errorWrites[ErrorResponse]
implicit val errorUnauthorizedWrites = errorWrites[ErrorUnauthorized]
implicit val errorNotFoundWrites = errorWrites[ErrorNotFound]
implicit val errorAcceptHeaderInvalidWrites = errorWrites[ErrorAcceptHeaderInvalid]
implicit val errorBadGatewayWrites = errorWrites[ErrorBadGateway]
implicit val errorBadRequestWrites = errorWrites[ErrorBadRequest]
}
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ val appName = "openid-connect-userinfo"
lazy val microservice = Project(appName, file("."))
.enablePlugins(play.sbt.PlayScala, SbtDistributablesPlugin)
.disablePlugins(JUnitXmlReportPlugin) //Required to prevent https://github.com/scalatest/scalatest/issues/1427
.settings(scalaVersion := "2.12.12")
.settings(scalaVersion := "2.12.13")
.settings(scalacOptions := Seq("-Xfatal-warnings", "-feature", "-deprecation"))
.settings(
majorVersion := 0,
Expand Down
6 changes: 3 additions & 3 deletions it/BaseFeatureISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ import com.github.tomakehurst.wiremock.client.WireMock.{aResponse, post, stubFor
import com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig
import com.typesafe.config.{Config, ConfigFactory}
import org.scalatest._
import org.scalatest.featurespec.AnyFeatureSpec
import org.scalatest.matchers.should.Matchers
import org.scalatestplus.play.guice.GuiceOneServerPerSuite
import play.api.Application
import play.api.inject.guice.GuiceApplicationBuilder
import uk.gov.hmrc.integration.ServiceSpec

import scala.concurrent.duration.{Duration, _}
import scala.concurrent.{Await, Future}
import scala.collection.JavaConverters._

import scala.util.Try

trait BaseFeatureISpec
extends FeatureSpec
extends AnyFeatureSpec
with GivenWhenThen
with Matchers
with GuiceOneServerPerSuite
Expand Down
8 changes: 4 additions & 4 deletions it/FeatureSwitchControllerISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class FeatureSwitchControllerISpec extends BaseFeatureISpec {

val serviceUrl = "/feature-switches"

feature("getting feature switches") {
scenario("calling GET /feature-switches") {
Feature("getting feature switches") {
Scenario("calling GET /feature-switches") {
Given("we call GET /feature-switches")

val result = Http(resource(s"$serviceUrl")).asString
Expand All @@ -34,8 +34,8 @@ class FeatureSwitchControllerISpec extends BaseFeatureISpec {
}
}

feature("updating feature switches") {
scenario("calling POST /feature-switches") {
Feature("updating feature switches") {
Scenario("calling POST /feature-switches") {
Given("we call GET /feature-switches")

val result = Http(resource(s"$serviceUrl")).asString
Expand Down
6 changes: 3 additions & 3 deletions it/PlatformIntegrationISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ class PlatformIntegrationISpec(implicit val wsClient: WSClient) extends BaseFeat
val documentationController = app.injector.instanceOf[DocumentationController]
val request = FakeRequest()

feature("microservice") {
Feature("microservice") {

scenario("provide definition endpoint") {
Scenario("provide definition endpoint") {
val response = Await.result(buildRequest(resource("/api/definition"), Seq.empty).get(), 1.minute)
response.status shouldBe 200
}

scenario("provide definition for versions 1.0 and 1.1") {
Scenario("provide definition for versions 1.0 and 1.1") {
val response = Await.result(buildRequest(resource("/api/definition"), Seq.empty).get(), 1.minute)
response.status shouldBe 200
val jsonBody = Json.parse(response.body)
Expand Down
5 changes: 2 additions & 3 deletions it/SchemaISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
*/

import java.nio.file.Paths

import com.fasterxml.jackson.databind.ObjectMapper
import com.github.fge.jsonschema.core.report.LogLevel
import com.github.fge.jsonschema.main.JsonSchemaFactory
import org.scalatest.FlatSpec
import org.scalatest.flatspec.AnyFlatSpec

class SchemaISpec extends FlatSpec {
class SchemaISpec extends AnyFlatSpec {
val validator = JsonSchemaFactory.byDefault().getValidator
val root = System.getProperty("user.dir")
val public10 = Paths.get(root, "public", "api", "conf", "1.0").toString
Expand Down
30 changes: 15 additions & 15 deletions it/UserInfoServiceISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ class UserInfoServiceISpec extends BaseFeatureISpec with AuthStub with ThirdPart
Some(government_gateway_v1),
Some(mdtp))

feature("fetch user information") {
Feature("fetch user information") {

scenario("fetch user profile v1") {
Scenario("fetch user profile v1") {

Given("A Auth token with 'openid', 'profile', 'address', 'openid:gov-uk-identifiers', 'openid:hmrc-enrolments', 'openid:mdtp'," +
"'email' and 'openid:government-gateway' scopes")
Expand Down Expand Up @@ -179,7 +179,7 @@ class UserInfoServiceISpec extends BaseFeatureISpec with AuthStub with ThirdPart
json shouldBe Json.toJson(userInfo_v1)
}

scenario("fetch user profile v2") {
Scenario("fetch user profile v2") {

Given("A Auth token with 'openid', 'profile', 'address', 'openid:gov-uk-identifiers', 'openid:hmrc-enrolments', 'openid:mdtp'," +
"'email' and 'openid:government-gateway' scopes")
Expand Down Expand Up @@ -224,7 +224,7 @@ class UserInfoServiceISpec extends BaseFeatureISpec with AuthStub with ThirdPart
json shouldBe Json.toJson(userInfo_v2)
}

scenario("fetch user profile without family name") {
Scenario("fetch user profile without family name") {

Given("A Auth token with 'openid', 'profile', 'address', 'openid:gov-uk-identifiers' and 'openid:hmrc-enrolments' scopes")
willReturnScopesForAuthBearerToken(authBearerToken,
Expand All @@ -251,7 +251,7 @@ class UserInfoServiceISpec extends BaseFeatureISpec with AuthStub with ThirdPart
mdtp = None))
}

scenario("fetch user data without enrolments when there are no enrolments") {
Scenario("fetch user data without enrolments when there are no enrolments") {

Given("A Auth token with 'openid', 'profile', 'address', 'openid:gov-uk-identifiers', 'email', 'openid:government-gateway' and 'openid:hmrc-enrolments' scopes")
willReturnScopesForAuthBearerToken(authBearerToken,
Expand All @@ -276,7 +276,7 @@ class UserInfoServiceISpec extends BaseFeatureISpec with AuthStub with ThirdPart
Json.parse(result.body) shouldBe Json.toJson(userInfo_v1.copy(hmrc_enrolments = None))
}

scenario("fetch user data without address and user details when there are no address and user details") {
Scenario("fetch user data without address and user details when there are no address and user details") {

Given("A Auth token with 'openid', 'profile', 'address', 'openid:gov-uk-identifiers' and 'openid:hmrc-enrolments' scopes")
willReturnScopesForAuthBearerToken(authBearerToken,
Expand Down Expand Up @@ -304,7 +304,7 @@ class UserInfoServiceISpec extends BaseFeatureISpec with AuthStub with ThirdPart
Json.parse(result.body) shouldBe Json.toJson(userWithNinoAndEnrolmentsOnly)
}

scenario("fetch enrolments only when scope contains 'openid:hmrc-enrolments'") {
Scenario("fetch enrolments only when scope contains 'openid:hmrc-enrolments'") {

Given("A Auth token with 'openid:hmrc-enrolments' scopes")
willReturnScopesForAuthBearerToken(authBearerToken,
Expand All @@ -329,7 +329,7 @@ class UserInfoServiceISpec extends BaseFeatureISpec with AuthStub with ThirdPart
Json.parse(result.body) shouldBe Json.toJson(userWithEnrolmentsOnly)
}

scenario("fetch government gateway details only when scope contains 'openid:government-gateway'") {
Scenario("fetch government gateway details only when scope contains 'openid:government-gateway'") {

Given("A Auth token with 'openid:government-gateway' scopes")
willReturnScopesForAuthBearerToken(authBearerToken,
Expand Down Expand Up @@ -361,9 +361,9 @@ class UserInfoServiceISpec extends BaseFeatureISpec with AuthStub with ThirdPart
}
}

feature("fetching user information propagates Unauthorized errors from upstream services") {
Feature("fetching user information propagates Unauthorized errors from upstream services") {

scenario("return 401 when Auth returns Unauthorized") {
Scenario("return 401 when Auth returns Unauthorized") {
Given("A Auth token with openid:government-gateway, openid:hmrc-enrolments, address scopes")
willReturnScopesForAuthBearerToken(authBearerToken,
Set("openid:government-gateway", "openid:hmrc-enrolments", "address"))
Expand All @@ -381,9 +381,9 @@ class UserInfoServiceISpec extends BaseFeatureISpec with AuthStub with ThirdPart
}
}

feature("fetching user information handles upstream errors") {
Feature("fetching user information handles upstream errors") {

scenario("return 502 when Auth returns error") {
Scenario("return 502 when Auth returns error") {
val errorMsg = "auth error msg"
val expectedErrorMessage = s"""{"code":"BAD_GATEWAY","message":"POST of 'http://localhost:$stubPort/auth/authorise' returned 503. Response body: '$errorMsg'"}"""
Given("A Auth token with openid:government-gateway, openid:hmrc-enrolments, address scopes")
Expand All @@ -403,7 +403,7 @@ class UserInfoServiceISpec extends BaseFeatureISpec with AuthStub with ThirdPart
Json.parse(result.body) shouldBe Json.parse(expectedErrorMessage)
}

scenario("return 502 when Auth returns not found") {
Scenario("return 502 when Auth returns not found") {
val errorMsg = "auth error msg"
val expectedErrorMessage = s"""{"code":"BAD_GATEWAY","message":"POST of 'http://localhost:$stubPort/auth/authorise' returned 404 (Not Found). Response body: '$errorMsg'"}"""
Given("A Auth token with openid:government-gateway, openid:hmrc-enrolments, address scopes")
Expand All @@ -423,7 +423,7 @@ class UserInfoServiceISpec extends BaseFeatureISpec with AuthStub with ThirdPart
Json.parse(result.body) shouldBe Json.parse(expectedErrorMessage)
}

scenario("fetching user info returns 5xx then we return 502") {
Scenario("fetching user info returns 5xx then we return 502") {

Given("A Auth token with 'openid', 'profile', 'address', 'openid:gov-uk-identifiers', 'openid:hmrc-enrolments', 'openid:mdtp'," +
"'email' and 'openid:government-gateway' scopes")
Expand Down Expand Up @@ -452,7 +452,7 @@ class UserInfoServiceISpec extends BaseFeatureISpec with AuthStub with ThirdPart

}

scenario("fetching user info returns 4xx then we return 502") {
Scenario("fetching user info returns 4xx then we return 502") {

Given("A Auth token with 'openid', 'profile', 'address', 'openid:gov-uk-identifiers', 'openid:hmrc-enrolments', 'openid:mdtp'," +
"'email' and 'openid:government-gateway' scopes")
Expand Down
19 changes: 11 additions & 8 deletions project/AppDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@ object AppDependencies {

val compile: Seq[ModuleID] = Seq(
ws,
"uk.gov.hmrc" %% "bootstrap-backend-play-27" % "5.7.0",
"uk.gov.hmrc" %% "domain" % "6.1.0-play-27",
"uk.gov.hmrc" %% "play-hmrc-api" % "6.4.0-play-27",
"uk.gov.hmrc" %% "bootstrap-backend-play-28" % "5.17.0",
"uk.gov.hmrc" %% "domain" % "6.2.0-play-28",
"uk.gov.hmrc" %% "play-hmrc-api" % "6.4.0-play-28",
"com.typesafe.play" %% "play-json-joda" % "2.7.4"
)

val test: Seq[ModuleID] = Seq(
"org.scalatest" %% "scalatest" % "3.2.7" % testScope,
"org.scalatestplus" %% "scalacheck-1-15" % "3.2.7.0" % testScope,
"org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0" % testScope,
"com.typesafe.play" %% "play-test" % PlayVersion.current % testScope,
"org.scalacheck" %% "scalacheck" % "1.13.5",
"com.github.tomakehurst" % "wiremock-jre8" % "2.24.1" % testScope,
"uk.gov.hmrc" %% "service-integration-test" % "1.1.0-play-27" % testScope,
"org.scalatestplus.play" %% "scalatestplus-play" % "3.1.3" % testScope,
"uk.gov.hmrc" %% "service-integration-test" % "1.2.0-play-28" % testScope,
"org.scoverage" %% "scalac-scoverage-plugin" % "1.3.1" % testScope,
"org.pegdown" % "pegdown" % "1.6.0" % testScope,
"org.jsoup" % "jsoup" % "1.10.3" % testScope,
"org.mockito" % "mockito-all" % "1.10.19" % testScope,
"org.scalaj" %% "scalaj-http" % "2.3.0" % testScope,
"com.github.fge" % "json-schema-validator" % "2.2.6" % testScope
"org.mockito" %% "mockito-scala-scalatest" % "1.16.37" % testScope,
"org.scalacheck" %% "scalacheck" % "1.14.0",
"com.github.fge" % "json-schema-validator" % "2.2.6" % testScope,
"com.vladsch.flexmark" % "flexmark-all" % "0.35.10" % testScope
)

def apply(): Seq[ModuleID] = compile ++ test
Expand Down
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ resolvers += Resolver.url("HMRC-open-artefacts-ivy", url("https://open.artefacts

addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.1.0")

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.7.6")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.8")

addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.3.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.6.0")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.client.WireMock._
import com.github.tomakehurst.wiremock.core.WireMockConfiguration._
import org.scalatest.BeforeAndAfterEach
import org.mockito.Mockito._
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import config.AppContext
import org.scalatestplus.mockito.MockitoSugar
import org.mockito.scalatest.MockitoSugar
import uk.gov.hmrc.http.{HeaderCarrier, HttpClient}

import scala.concurrent.ExecutionContext.Implicits.global
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/ErrorResponseSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package controllers

import org.scalatest.Matchers
import org.scalatest.matchers.should.Matchers
import play.api.libs.json.Json
import testSupport.UnitSpec

Expand Down
12 changes: 4 additions & 8 deletions test/controllers/UserInfoControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@
package controllers

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import config.AppContext
import domain.{Address, GovernmentGatewayDetails, UserInfo}
import org.joda.time.LocalDate
import org.mockito.BDDMockito.given
import org.mockito.Matchers
import org.mockito.Matchers.{any, eq => eqTo}
import org.scalatest.concurrent.ScalaFutures
import org.scalatestplus.mockito.MockitoSugar
import org.mockito.scalatest.MockitoSugar
import play.api.libs.json.Json
import play.api.mvc.ControllerComponents
import play.api.test.FakeRequest
Expand All @@ -39,7 +36,6 @@ import scala.concurrent.{ExecutionContext, Future}
class UserInfoControllerSpec(implicit val cc: ControllerComponents, ex: ExecutionContext) extends UnitSpec with MockitoSugar with ScalaFutures {

implicit val actorSystem: ActorSystem = ActorSystem("test")
implicit val materializer: ActorMaterializer = ActorMaterializer()
val ACCEPT_HEADER_V1_0 = "application/vnd.hmrc.1.0+json"
val ACCEPT_HEADER_V1_1 = "application/vnd.hmrc.1.1+json"

Expand Down Expand Up @@ -71,7 +67,7 @@ class UserInfoControllerSpec(implicit val cc: ControllerComponents, ex: Executio
"sandbox userInfo" should {
"retrieve user information v1.0" in new Setup {

given(mockSandboxUserInfoService.fetchUserInfo(eqTo(Version_1_0))(Matchers.any[HeaderCarrier])).willReturn(userInfoV1)
given(mockSandboxUserInfoService.fetchUserInfo(eqTo(Version_1_0))(any[HeaderCarrier])).willReturn(userInfoV1)

val result = await(sandboxController.userInfo()(FakeRequest().withHeaders("Accept" -> "application/vnd.hmrc.1.0+json")))

Expand All @@ -81,7 +77,7 @@ class UserInfoControllerSpec(implicit val cc: ControllerComponents, ex: Executio

"retrieve user information v1.1" in new Setup {

given(mockSandboxUserInfoService.fetchUserInfo(eqTo(Version_1_1))(Matchers.any[HeaderCarrier])).willReturn(userInfoV11)
given(mockSandboxUserInfoService.fetchUserInfo(eqTo(Version_1_1))(any[HeaderCarrier])).willReturn(userInfoV11)

val result = await(sandboxController.userInfo()(FakeRequest().withHeaders("Accept" -> "application/vnd.hmrc.1.1+json")))

Expand All @@ -91,7 +87,7 @@ class UserInfoControllerSpec(implicit val cc: ControllerComponents, ex: Executio

"fail with 406 (Not Acceptable) if version headers not present" in new Setup {

given(mockSandboxUserInfoService.fetchUserInfo(eqTo(Version_1_0))(Matchers.any[HeaderCarrier])).willReturn(userInfoV1)
given(mockSandboxUserInfoService.fetchUserInfo(eqTo(Version_1_0))(any[HeaderCarrier])).willReturn(userInfoV1)

val result = await(sandboxController.userInfo()(FakeRequest()))

Expand Down
2 changes: 0 additions & 2 deletions test/controllers/testOnly/FeatureSwitchControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package controllers.testOnly

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import org.scalatest.concurrent.ScalaFutures
import play.api.libs.json._
import play.api.mvc.{ControllerComponents, Request, Result}
Expand All @@ -30,7 +29,6 @@ import scala.concurrent.ExecutionContext
class FeatureSwitchControllerSpec(implicit val cc: ControllerComponents, val ex: ExecutionContext) extends UnitSpec with ScalaFutures {

implicit val actorSystem: ActorSystem = ActorSystem("test")
implicit val materializer: ActorMaterializer = ActorMaterializer()

trait Setup {
def featuresList(countryCodeEnabled: Boolean = false, addressLine5Enabled: Boolean = false): JsValue = Json.arr(
Expand Down
Loading

0 comments on commit b6a681e

Please sign in to comment.