Skip to content

Commit

Permalink
Merge pull request #137 from hmrc/revert-136-SAR-2859
Browse files Browse the repository at this point in the history
Revert "Sar 2859 - migrating to play 2.6"
  • Loading branch information
r-melvin authored Nov 21, 2018
2 parents a67f734 + 7c666d7 commit 8fd9f00
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 103 deletions.
28 changes: 15 additions & 13 deletions app/config/MicroserviceAppConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,34 @@

package config

import config.featureswitch.FeatureSwitching
import javax.inject.{Inject, Singleton}
import play.api.Configuration
import uk.gov.hmrc.play.bootstrap.config.ServicesConfig

import config.featureswitch.FeatureSwitching
import play.api.{Application, Configuration}
import uk.gov.hmrc.play.config.ServicesConfig

trait AppConfig {
val authURL: String
val ggURL: String
val ggAdminURL: String
val ggAuthenticationURL: String

def desURL: String

val desEnvironment: String
val desToken: String
val paperlessPreferencesExpirySeconds: Int
}

@Singleton
class MicroserviceAppConfig @Inject()(servicesConfig: ServicesConfig, configuration: Configuration) extends AppConfig with FeatureSwitching {
class MicroserviceAppConfig @Inject()(val app: Application) extends AppConfig with ServicesConfig with FeatureSwitching {
val configuration = app.configuration
override val mode = app.mode

private def loadConfig(key: String) = configuration.getOptional[String](key).getOrElse(throw new Exception(s"Missing configuration key: $key"))
private def loadConfig(key: String) = configuration.getString(key).getOrElse(throw new Exception(s"Missing configuration key: $key"))

override lazy val authURL = servicesConfig.baseUrl("auth")
override lazy val ggAuthenticationURL = servicesConfig.baseUrl("gg-authentication")
override lazy val ggURL = servicesConfig.baseUrl("government-gateway")
override lazy val ggAdminURL = servicesConfig.baseUrl("gg-admin")
override lazy val authURL = baseUrl("auth")
override lazy val ggAuthenticationURL = baseUrl("gg-authentication")
override lazy val ggURL = baseUrl("government-gateway")
override lazy val ggAdminURL = baseUrl("gg-admin")

private def desBase =
if (isEnabled(featureswitch.StubDESFeature)) "microservice.services.stub-des"
Expand All @@ -54,8 +55,9 @@ class MicroserviceAppConfig @Inject()(servicesConfig: ServicesConfig, configurat
override lazy val desToken = loadConfig(s"$desBase.authorization-token")
override val paperlessPreferencesExpirySeconds: Int = {
val key = s"paperless-preference.expiry-seconds"
configuration.getOptional[Int](key).getOrElse(throw new Exception(s"Missing configuration key: $key"))

configuration.getInt(s"paperless-preference.expiry-seconds")
.getOrElse(throw new Exception(s"Missing configuration key: $key"))
}

override protected def runModeConfiguration: Configuration = configuration
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@

package controllers.digitalcontact

import common.Constants._
import javax.inject.{Inject, Singleton}

import common.Constants._
import models.digitalcontact.PaperlessPreferenceKey
import play.api.libs.json.{JsError, JsSuccess, JsValue, Json}
import play.api.mvc.{Action, AnyContent, ControllerComponents}
import play.api.mvc.{Action, AnyContent}
import services.AuthService
import services.digitalcontact.PaperlessPreferenceService
import uk.gov.hmrc.play.bootstrap.controller.BackendController
import uk.gov.hmrc.play.bootstrap.controller.BaseController

import scala.concurrent.{ExecutionContext, Future}

@Singleton
class PaperlessPreferenceController @Inject()(authService: AuthService,
paperlessPreferenceService: PaperlessPreferenceService,
cc: ControllerComponents)(implicit ec: ExecutionContext)
extends BackendController(cc) {
paperlessPreferenceService: PaperlessPreferenceService)(implicit ec: ExecutionContext)
extends BaseController {

import authService._

Expand Down
8 changes: 4 additions & 4 deletions app/controllers/matching/LockoutStatusController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@
package controllers.matching

import javax.inject.{Inject, Singleton}

import models.lockout.LockoutRequest
import models.matching.LockoutResponse
import play.api.libs.json.Json
import play.api.mvc.{Action, AnyContent, ControllerComponents}
import play.api.mvc.{Action, AnyContent}
import services.{AuthService, LockoutStatusService}
import uk.gov.hmrc.play.bootstrap.controller.BackendController
import uk.gov.hmrc.play.bootstrap.controller.BaseController

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

@Singleton
class LockoutStatusController @Inject()(authService: AuthService,
lockoutStatusService: LockoutStatusService,
cc: ControllerComponents) extends BackendController(cc) {
lockoutStatusService: LockoutStatusService) extends BaseController {

import authService._

Expand Down
14 changes: 7 additions & 7 deletions app/controllers/subscription/SubscriptionController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@

package controllers.subscription

import javax.inject.Inject

import audit.{Logging, LoggingConfig}
import controllers.ITSASessionKeys
import javax.inject.Inject
import models.frontend.{FEFailureResponse, FERequest}
import play.api.libs.json.{JsError, JsSuccess}
import play.api.mvc._
import play.api.mvc.{Action, AnyContent, Request, Result}
import services.{AuthService, RosmAndEnrolManagerService}
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.play.bootstrap.controller.BackendController
import uk.gov.hmrc.play.bootstrap.controller.BaseController
import utils.JsonUtils._

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import uk.gov.hmrc.http.HeaderCarrier

class SubscriptionController @Inject()(logging: Logging,
subManService: RosmAndEnrolManagerService,
authService: AuthService,
cc: ControllerComponents
) extends BackendController(cc) {
authService: AuthService
) extends BaseController {
import authService._

def subscribe(nino: String): Action[AnyContent] = Action.async { implicit request =>
Expand Down
17 changes: 6 additions & 11 deletions app/controllers/subscription/SubscriptionStatusController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@

package controllers.subscription

import audit.{Logging, LoggingConfig}
import javax.inject.Inject

import audit.{Logging, LoggingConfig}
import models.frontend.FEFailureResponse
import play.api.libs.json.Json
import play.api.mvc.{Action, AnyContent, ControllerComponents}
import play.api.mvc.{Action, AnyContent}
import services.{AuthService, SubscriptionStatusService}
import uk.gov.hmrc.play.bootstrap.controller.BackendController
import uk.gov.hmrc.play.bootstrap.controller.BaseController
import utils.Implicits._
import utils.JsonUtils.toJsValue

import scala.concurrent.ExecutionContext.Implicits.global

class SubscriptionStatusController @Inject()(logging: Logging,
authService: AuthService,
subscriptionStatusService: SubscriptionStatusService,
cc: ControllerComponents) extends BackendController(cc) {

subscriptionStatusService: SubscriptionStatusService) extends BaseController {
import authService._

def checkSubscriptionStatus(nino: String): Action[AnyContent] = Action.async { implicit request =>
Expand All @@ -41,10 +39,7 @@ class SubscriptionStatusController @Inject()(logging: Logging,
subscriptionStatusService.checkMtditsaSubscription(nino).map {
case Right(success) =>
logging.debug(s"successful, responding with\n$success")
success match {
case None => Ok(Json.obj())
case _ => Ok(toJsValue(success))
}
Ok(toJsValue(success))
case Left(failure) =>
logging.warn(s"failed, responding with\nstatus=${failure.status}\nreason=${failure.reason}")
Status(failure.status)(toJsValue(FEFailureResponse(failure.reason)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@

package testonly.controllers.featureswitch

import javax.inject.Inject

import config.featureswitch.FeatureSwitch._
import config.featureswitch.{FeatureSwitch, FeatureSwitching}
import javax.inject.Inject
import play.api.i18n.MessagesApi
import play.api.libs.json.Json
import play.api.mvc.{ControllerComponents, Result}
import uk.gov.hmrc.play.bootstrap.controller.BackendController
import play.api.mvc.{Action, Result}
import uk.gov.hmrc.play.bootstrap.controller.BaseController

import scala.concurrent.Future

class FeatureSwitchController @Inject()(cc: ControllerComponents)
extends BackendController(cc) with FeatureSwitching {
class FeatureSwitchController @Inject()(val messagesApi: MessagesApi)
extends BaseController with FeatureSwitching {

private def returnCurrentSettings = Ok(Json.toJson(switches.map(fs => FeatureSwitchSetting(fs, isEnabled(fs)))))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
package testonly.controllers.matching

import javax.inject.{Inject, Singleton}
import play.api.mvc.{Action, AnyContent, ControllerComponents}
import repositories.LockoutMongoRepository
import uk.gov.hmrc.play.bootstrap.controller.BackendController

import play.api.mvc.{Action, AnyContent}
import repositories.LockoutMongoRepository
import uk.gov.hmrc.play.bootstrap.controller.BaseController
import scala.concurrent.ExecutionContext.Implicits.global

@Singleton
class ResetAgentLockoutController @Inject()(mongoRepository: LockoutMongoRepository,
cc: ControllerComponents) extends BackendController(cc) {
class ResetAgentLockoutController @Inject()(mongoRepository: LockoutMongoRepository) extends BaseController {

def resetAgentLockout: Action[AnyContent] = Action.async { implicit request =>
mongoRepository.dropDb map (_ => Ok)
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ lazy val microservice = Project(appName, file("."))
resolvers += Resolver.bintrayRepo("hmrc", "releases"),
resolvers += Resolver.jcenterRepo,
libraryDependencies ++= appDependencies,
dependencyOverrides ++= AppDependencies.overrides,
retrieveManaged := true,
evictionWarningOptions in update := EvictionWarningOptions.default.withWarnScalaVersionEviction(false)
evictionWarningOptions in update := EvictionWarningOptions.default.withWarnScalaVersionEviction(false),
routesGenerator := StaticRoutesGenerator
)
.configs(IntegrationTest)
.settings(inConfig(IntegrationTest)(Defaults.itSettings): _*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ package controllers.digitalcontact
import helpers.ComponentSpecBase
import helpers.servicemocks.AuthStub
import models.digitalcontact.PaperlessPreferenceKey
import org.scalatest.BeforeAndAfterEach
import play.api.http.Status
import repositories.digitalcontact.PaperlessPreferenceMongoRepository
import helpers.IntegrationTestConstants._
import play.api.libs.json.Json

import scala.concurrent.ExecutionContext.Implicits.global

class PaperlessPreferenceControllerISpec extends ComponentSpecBase {
class PaperlessPreferenceControllerISpec extends ComponentSpecBase with BeforeAndAfterEach {
val paperlessPreferenceRepository = app.injector.instanceOf[PaperlessPreferenceMongoRepository]

override def beforeEach(): Unit = {
Expand Down
2 changes: 1 addition & 1 deletion it/controllers/matching/LockoutStatusControllerISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import play.modules.reactivemongo.ReactiveMongoComponent
import repositories.LockoutMongoRepository
import scala.concurrent.ExecutionContext.Implicits.global

class LockoutStatusControllerISpec extends ComponentSpecBase {
class LockoutStatusControllerISpec extends ComponentSpecBase with BeforeAndAfterEach {
implicit lazy val mongo = app.injector.instanceOf[ReactiveMongoComponent]

object TestLockoutMongoRepository extends LockoutMongoRepository
Expand Down
2 changes: 1 addition & 1 deletion it/helpers/ComponentSpecBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ trait ComponentSpecBase extends UnitSpec
def post[T](uri: String, body: T)(implicit writes: Writes[T]): WSResponse = {
await(
buildClient(uri)
.withHttpHeaders(
.withHeaders(
"Content-Type" -> "application/json",
ITSASessionKeys.RequestURI -> IntegrationTestConstants.requestUri
)
Expand Down
2 changes: 1 addition & 1 deletion it/helpers/WiremockHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object WiremockHelper extends Eventually with IntegrationPatience {
case Some(body) => uriMapping.withRequestBody(equalTo(body))
case None => uriMapping
}
verify(postRequest)
verify(postRequest)
}

def verifyGet(uri: String): Unit = {
Expand Down
6 changes: 3 additions & 3 deletions it/helpers/servicemocks/WireMockMethods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ trait WireMockMethods {
val wireMockMapping: UrlPattern => MappingBuilder
}
case object GET extends HTTPMethod {
override val wireMockMapping: UrlPattern => MappingBuilder = get
override val wireMockMapping = get _
}
case object POST extends HTTPMethod {
override val wireMockMapping: UrlPattern => MappingBuilder = post
override val wireMockMapping = post _
}
case object PUT extends HTTPMethod{
override val wireMockMapping: UrlPattern => MappingBuilder = put
override val wireMockMapping = put _
}
}
39 changes: 12 additions & 27 deletions project/MicroServiceBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,26 @@ private object AppDependencies {

private val domainVersion = "5.1.0"
private val hmrcTestVersion = "3.0.0"
private val scalaTestVersion = "3.0.5"
private val scalaTestPlusVersion = "3.1.2"
private val scalaTestVersion = "3.0.1"
private val scalaTestPlusVersion = "2.0.0"
private val pegdownVersion = "1.6.0"
private val mockitoVersion = "2.7.17"

private val scalaJVersion = "2.3.0"
private val cucumberVersion = "1.2.5"
private val reactiveMongoVersion = "7.3.0-play-26"
private val wiremockVersion = "2.19.0"
private val bootstrapVersion = "0.30.0"

private val reactiveMongoVersion = "6.2.0"

private val wiremockVersion = "2.5.1"

private val bootstrapVersion = "1.7.0"


val compile = Seq(
ws,
"uk.gov.hmrc" %% "bootstrap-play-26" % bootstrapVersion,
"uk.gov.hmrc" %% "bootstrap-play-25" % bootstrapVersion,
"uk.gov.hmrc" %% "domain" % domainVersion,
"uk.gov.hmrc" %% "simple-reactivemongo" % reactiveMongoVersion
"uk.gov.hmrc" %% "play-reactivemongo" % reactiveMongoVersion
)

trait TestDependencies {
Expand Down Expand Up @@ -90,25 +94,6 @@ private object AppDependencies {
}.test
}

// Fixes a transitive dependency clash between wiremock and scalatestplus-play
val overrides: Set[ModuleID] = {
val jettyFromWiremockVersion = "9.2.24.v20180105"
Set(
"org.eclipse.jetty" % "jetty-client" % jettyFromWiremockVersion,
"org.eclipse.jetty" % "jetty-continuation" % jettyFromWiremockVersion,
"org.eclipse.jetty" % "jetty-http" % jettyFromWiremockVersion,
"org.eclipse.jetty" % "jetty-io" % jettyFromWiremockVersion,
"org.eclipse.jetty" % "jetty-security" % jettyFromWiremockVersion,
"org.eclipse.jetty" % "jetty-server" % jettyFromWiremockVersion,
"org.eclipse.jetty" % "jetty-servlet" % jettyFromWiremockVersion,
"org.eclipse.jetty" % "jetty-servlets" % jettyFromWiremockVersion,
"org.eclipse.jetty" % "jetty-util" % jettyFromWiremockVersion,
"org.eclipse.jetty" % "jetty-webapp" % jettyFromWiremockVersion,
"org.eclipse.jetty" % "jetty-xml" % jettyFromWiremockVersion,
"org.eclipse.jetty.websocket" % "websocket-api" % jettyFromWiremockVersion,
"org.eclipse.jetty.websocket" % "websocket-client" % jettyFromWiremockVersion,
"org.eclipse.jetty.websocket" % "websocket-common" % jettyFromWiremockVersion
)
}
def apply() = compile ++ Test() ++ IntegrationTest()
}

6 changes: 3 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "1.13.0")

addSbtPlugin("uk.gov.hmrc" % "sbt-git-versioning" % "1.15.0")

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

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.15")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.12")

resolvers += Resolver.url("scoverage-bintray", url("https://dl.bintray.com/sksamuel/sbt-plugins/"))(Resolver.ivyStylePatterns)

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

addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0")

addSbtPlugin("uk.gov.hmrc" % "sbt-artifactory" % "0.14.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-artifactory" % "0.13.0")



Expand Down
2 changes: 2 additions & 0 deletions test/connectors/mocks/TestBusinessDetailsConnector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import models.ErrorModel
import models.registration.GetBusinessDetailsSuccessResponseModel
import org.mockito.ArgumentMatchers
import org.mockito.Mockito._
import org.mockito._
import org.scalatest.mockito.MockitoSugar
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api.http.Status._
import play.api.libs.json.JsValue
import uk.gov.hmrc.http.{HttpGet, HttpPost}
import uk.gov.hmrc.play.bootstrap.http.HttpClient
import utils.Implicits._
import utils.TestConstants._
Expand Down
Loading

0 comments on commit 8fd9f00

Please sign in to comment.