From dd27340ef99ca7a93dfa732ec2e6eee02327605a Mon Sep 17 00:00:00 2001 From: Omer Arshad Date: Thu, 9 Dec 2021 06:36:48 +0000 Subject: [PATCH 1/2] GG-6062 : Upgrade to play 2.8 --- app/controllers/package.scala | 11 +++++-- build.sbt | 2 +- it/BaseFeatureISpec.scala | 6 ++-- it/FeatureSwitchControllerISpec.scala | 8 ++--- it/PlatformIntegrationISpec.scala | 6 ++-- it/SchemaISpec.scala | 5 ++-- it/UserInfoServiceISpec.scala | 30 +++++++++---------- project/AppDependencies.scala | 19 +++++++----- project/plugins.sbt | 4 +-- ...PartyDelegatedAuthorityConnectorSpec.scala | 3 +- test/controllers/ErrorResponseSpec.scala | 2 +- test/controllers/UserInfoControllerSpec.scala | 12 +++----- .../FeatureSwitchControllerSpec.scala | 2 -- test/data/UserInfoGeneratorSpec.scala | 3 +- test/services/UserInfoServiceSpec.scala | 20 +++++++------ test/services/UserInfoTransformerSpec.scala | 2 +- test/testSupport/UnitSpec.scala | 7 +++-- 17 files changed, 74 insertions(+), 68 deletions(-) diff --git a/app/controllers/package.scala b/app/controllers/package.scala index 1fe8f40..964ff0e 100644 --- a/app/controllers/package.scala +++ b/app/controllers/package.scala @@ -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] } diff --git a/build.sbt b/build.sbt index d95df4d..63f9a44 100644 --- a/build.sbt +++ b/build.sbt @@ -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, diff --git a/it/BaseFeatureISpec.scala b/it/BaseFeatureISpec.scala index b1f7062..49773c9 100644 --- a/it/BaseFeatureISpec.scala +++ b/it/BaseFeatureISpec.scala @@ -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 diff --git a/it/FeatureSwitchControllerISpec.scala b/it/FeatureSwitchControllerISpec.scala index 086d2ab..810f028 100644 --- a/it/FeatureSwitchControllerISpec.scala +++ b/it/FeatureSwitchControllerISpec.scala @@ -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 @@ -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 diff --git a/it/PlatformIntegrationISpec.scala b/it/PlatformIntegrationISpec.scala index a57938a..a016ed0 100644 --- a/it/PlatformIntegrationISpec.scala +++ b/it/PlatformIntegrationISpec.scala @@ -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) diff --git a/it/SchemaISpec.scala b/it/SchemaISpec.scala index 89286cd..9881e5e 100644 --- a/it/SchemaISpec.scala +++ b/it/SchemaISpec.scala @@ -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 diff --git a/it/UserInfoServiceISpec.scala b/it/UserInfoServiceISpec.scala index 5a330c1..e5fb731 100644 --- a/it/UserInfoServiceISpec.scala +++ b/it/UserInfoServiceISpec.scala @@ -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") @@ -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") @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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")) @@ -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") @@ -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") @@ -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") @@ -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") diff --git a/project/AppDependencies.scala b/project/AppDependencies.scala index 6b47762..698b571 100644 --- a/project/AppDependencies.scala +++ b/project/AppDependencies.scala @@ -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 diff --git a/project/plugins.sbt b/project/plugins.sbt index b110c70..46c674f 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -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") diff --git a/test/connectors/ThirdPartyDelegatedAuthorityConnectorSpec.scala b/test/connectors/ThirdPartyDelegatedAuthorityConnectorSpec.scala index 7a08f34..1116c94 100644 --- a/test/connectors/ThirdPartyDelegatedAuthorityConnectorSpec.scala +++ b/test/connectors/ThirdPartyDelegatedAuthorityConnectorSpec.scala @@ -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 diff --git a/test/controllers/ErrorResponseSpec.scala b/test/controllers/ErrorResponseSpec.scala index 15d64a9..60ea799 100644 --- a/test/controllers/ErrorResponseSpec.scala +++ b/test/controllers/ErrorResponseSpec.scala @@ -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 diff --git a/test/controllers/UserInfoControllerSpec.scala b/test/controllers/UserInfoControllerSpec.scala index bc81762..3918163 100644 --- a/test/controllers/UserInfoControllerSpec.scala +++ b/test/controllers/UserInfoControllerSpec.scala @@ -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 @@ -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" @@ -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"))) @@ -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"))) @@ -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())) diff --git a/test/controllers/testOnly/FeatureSwitchControllerSpec.scala b/test/controllers/testOnly/FeatureSwitchControllerSpec.scala index 8a891f2..17e853a 100644 --- a/test/controllers/testOnly/FeatureSwitchControllerSpec.scala +++ b/test/controllers/testOnly/FeatureSwitchControllerSpec.scala @@ -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} @@ -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( diff --git a/test/data/UserInfoGeneratorSpec.scala b/test/data/UserInfoGeneratorSpec.scala index 4bc7968..9b70ea8 100644 --- a/test/data/UserInfoGeneratorSpec.scala +++ b/test/data/UserInfoGeneratorSpec.scala @@ -19,11 +19,12 @@ package data import org.joda.time.LocalDate import org.scalatest.BeforeAndAfterEach import config.{FeatureSwitch, UserInfoFeatureSwitches} +import org.scalatest.matchers.should.Matchers import domain.UserInfo import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks import testSupport.UnitSpec -class UserInfoGeneratorSpec extends UnitSpec with ScalaCheckPropertyChecks with BeforeAndAfterEach { +class UserInfoGeneratorSpec extends UnitSpec with Matchers with ScalaCheckPropertyChecks with BeforeAndAfterEach { val ninoPattern = "^[A-CEGHJ-NOPR-TW-Z]{2}[0-9]{6}[ABCD\\s]{1}$".r val from = new LocalDate(1939, 12, 27) val until = new LocalDate(1998, 12, 29) diff --git a/test/services/UserInfoServiceSpec.scala b/test/services/UserInfoServiceSpec.scala index ae79d0b..e1908af 100644 --- a/test/services/UserInfoServiceSpec.scala +++ b/test/services/UserInfoServiceSpec.scala @@ -20,11 +20,9 @@ import connectors.{AuthConnector, AuthConnectorV1, ThirdPartyDelegatedAuthorityC import controllers.{Version_1_0, Version_1_1} import data.UserInfoGenerator import domain._ -import org.mockito.BDDMockito._ -import org.mockito.Matchers.{any, eq => eqTo} -import org.mockito.Mockito.{never, verify, when} +import org.mockito.BDDMockito.given import org.scalatest.concurrent.ScalaFutures -import org.scalatestplus.mockito.MockitoSugar +import org.mockito.scalatest.MockitoSugar import testSupport.UnitSpec import uk.gov.hmrc.auth.core.retrieve.{ItmpAddress, ItmpName} import uk.gov.hmrc.auth.core.{Enrolment, EnrolmentIdentifier, Enrolments} @@ -75,7 +73,7 @@ class UserInfoServiceSpec extends UnitSpec with MockitoSugar with ScalaFutures { given(mockAuthConnector.fetchEnrolments()(headers, implicitly)).willReturn(Some(enrolments)) given(mockAuthConnector.fetchDesUserInfo()(headers, implicitly)).willReturn(Some(desUserInfo)) when(mockAuthConnector.fetchUserDetails()(eqTo(headers), any[ExecutionContext])).thenReturn(Future.successful(Some(userDetails))) - given(mockUserInfoTransformer.transform(scopes, Some(authority), Some(desUserInfo), Some(enrolments), None)).willReturn(any[UserInfo], any[UserInfo]) + given(mockUserInfoTransformer.transform(scopes, Some(authority), Some(desUserInfo), Some(enrolments), Some(userDetails))).willReturn(any[UserInfo], any[UserInfo]) await(liveInfoService.fetchUserInfo(Version_1_0)) @@ -89,7 +87,8 @@ class UserInfoServiceSpec extends UnitSpec with MockitoSugar with ScalaFutures { val scopes = Set("address", "profile", "openid:gov-uk-identifiers", "openid:hmrc-enrolments") given(mockThirdPartyDelegatedAuthorityConnector.fetchScopes(authBearerToken)(headers, implicitly)).willReturn(scopes) given(mockAuthConnector.fetchAuthority()(headers, implicitly)).willReturn(Future(Some(authority.copy(nino = None)))) - given(mockAuthConnector.fetchEnrolments()(any(), any())).willReturn(Future(None)) + given(mockAuthConnector.fetchEnrolments()(headers, implicitly)).willReturn(Future(None)) + when(mockAuthConnector.fetchUserDetails()(eqTo(headers), any[ExecutionContext])).thenReturn(Future.successful(Some(userDetails))) a[BadRequestException] should be thrownBy await(liveInfoService.fetchUserInfo(Version_1_0)) } @@ -99,8 +98,9 @@ class UserInfoServiceSpec extends UnitSpec with MockitoSugar with ScalaFutures { val scopes = Set("openid:gov-uk-identifiers", "openid:hmrc-enrolments") given(mockThirdPartyDelegatedAuthorityConnector.fetchScopes(authBearerToken)(headers, implicitly)).willReturn(scopes) given(mockAuthConnector.fetchAuthority()(headers, implicitly)).willReturn(Some(authority)) - given(mockAuthConnector.fetchEnrolments()(any(), any())).willReturn(Future(None)) - given(mockUserInfoTransformer.transform(scopes, Some(authority), None, Some(enrolments), Some(userDetails))).willReturn(any[UserInfo], any[UserInfo]) + given(mockAuthConnector.fetchEnrolments()(headers, implicitly)).willReturn(Future(Some(enrolments))) + given(mockUserInfoTransformer.transform(scopes, Some(authority), None, Some(enrolments), None)).willReturn(any[UserInfo], any[UserInfo]) + given(mockAuthConnector.fetchUserDetails()(headers, implicitly)).willReturn(Future.successful(Some(userDetails))) await(liveInfoService.fetchUserInfo(Version_1_0)) @@ -116,6 +116,7 @@ class UserInfoServiceSpec extends UnitSpec with MockitoSugar with ScalaFutures { given(mockAuthConnector.fetchAuthority()(headers, implicitly)).willReturn(Some(authority)) given(mockAuthConnector.fetchEnrolments()(headers, implicitly)).willReturn(Some(enrolments)) given(mockUserInfoTransformer.transform(scopes, Some(authority), None, Some(enrolments), None)).willReturn(any[UserInfo], any[UserInfo]) + given(mockAuthConnector.fetchUserDetails()(headers, implicitly)).willReturn(Future.successful(Some(userDetails))) await(liveInfoService.fetchUserInfo(Version_1_0)) @@ -130,7 +131,8 @@ class UserInfoServiceSpec extends UnitSpec with MockitoSugar with ScalaFutures { given(mockAuthConnector.fetchAuthority()(headers, implicitly)).willReturn(Some(authority)) given(mockAuthConnector.fetchDesUserInfo()(headers, implicitly)).willReturn(None) - given(mockUserInfoTransformer.transform(scopes, Some(authority), None, Some(enrolments), None)).willReturn(any[UserInfo], any[UserInfo]) + given(mockUserInfoTransformer.transform(scopes, Some(authority), None, None, None)).willReturn(any[UserInfo], any[UserInfo]) + given(mockAuthConnector.fetchUserDetails()(headers, implicitly)).willReturn(Future.successful(Some(userDetails))) await(liveInfoService.fetchUserInfo(Version_1_0)) diff --git a/test/services/UserInfoTransformerSpec.scala b/test/services/UserInfoTransformerSpec.scala index 547a50d..88db361 100644 --- a/test/services/UserInfoTransformerSpec.scala +++ b/test/services/UserInfoTransformerSpec.scala @@ -20,7 +20,7 @@ import config.{FeatureSwitch, UserInfoFeatureSwitches} import domain._ import org.joda.time.LocalDate import org.scalatest.BeforeAndAfterEach -import org.scalatestplus.mockito.MockitoSugar +import org.mockito.scalatest.MockitoSugar import testSupport.UnitSpec import uk.gov.hmrc.auth.core.retrieve.{GatewayInformation, ItmpAddress, ItmpName, MdtpInformation} import uk.gov.hmrc.auth.core.{Enrolment, EnrolmentIdentifier, Enrolments} diff --git a/test/testSupport/UnitSpec.scala b/test/testSupport/UnitSpec.scala index ed1d4aa..f0c071d 100644 --- a/test/testSupport/UnitSpec.scala +++ b/test/testSupport/UnitSpec.scala @@ -17,18 +17,19 @@ package testSupport import java.nio.charset.Charset - import akka.stream.Materializer import akka.util.ByteString -import org.scalatest.{Matchers, WordSpec} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpec import play.api.libs.json.{JsValue, Json} import play.api.mvc.Result + import scala.language.postfixOps import scala.concurrent.duration.{Duration, _} import scala.concurrent.{Await, Future} import scala.language.implicitConversions -trait UnitSpec extends WordSpec with Matchers { +trait UnitSpec extends AnyWordSpec with Matchers { implicit def toFuture[A](a: A): Future[A] = Future.successful(a) From 868b6924ddb12b6206d06e41cc7f54609f126947 Mon Sep 17 00:00:00 2001 From: Omer Arshad Date: Thu, 9 Dec 2021 06:42:03 +0000 Subject: [PATCH 2/2] GG-6062 : Upgrade to play 2.8 --- test/data/UserInfoGeneratorSpec.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/data/UserInfoGeneratorSpec.scala b/test/data/UserInfoGeneratorSpec.scala index 9b70ea8..4bc7968 100644 --- a/test/data/UserInfoGeneratorSpec.scala +++ b/test/data/UserInfoGeneratorSpec.scala @@ -19,12 +19,11 @@ package data import org.joda.time.LocalDate import org.scalatest.BeforeAndAfterEach import config.{FeatureSwitch, UserInfoFeatureSwitches} -import org.scalatest.matchers.should.Matchers import domain.UserInfo import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks import testSupport.UnitSpec -class UserInfoGeneratorSpec extends UnitSpec with Matchers with ScalaCheckPropertyChecks with BeforeAndAfterEach { +class UserInfoGeneratorSpec extends UnitSpec with ScalaCheckPropertyChecks with BeforeAndAfterEach { val ninoPattern = "^[A-CEGHJ-NOPR-TW-Z]{2}[0-9]{6}[ABCD\\s]{1}$".r val from = new LocalDate(1939, 12, 27) val until = new LocalDate(1998, 12, 29)