Skip to content

Commit

Permalink
DL-15127 : Play3.0 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
kannanEkambaram committed Dec 24, 2024
1 parent 327d74a commit b51f680
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 87 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ The list of software providers is loaded from the `SoftwareProviders.json` file.
### Running the service locally

#### Using Service Manager
To run all the dependent services and start software choices frontend, you can either use `sm --start SOFTWARE_CHOICES_ALL -r` or `sm2 --start SOFTWARE_CHOICES_ALL -r` if you are using sm2.
To run all the dependent services and start software choices frontend, use `sm2 --start SOFTWARE_CHOICES_ALL`.

Alternatively, if you want to start the service individually, you can either use `sm --start SOFTWARE_CHOICES_FRONTEND -r` or `sm2 --start SOFTWARE_CHOICES_FRONTEND -r` if you are using sm2.
Alternatively, if you want to start the service individually, use `sm2 --start SOFTWARE_CHOICES_FRONTEND`.

Prior to starting the service locally, make sure the instance running in service manager is stopped. This can be done by running either `sm --stop SOFTWARE_CHOICES_FRONTEND`, or `sm2 --stop SOFTWARE_CHOICES_FRONTEND` if you are using sm2.
Prior to starting the service locally, make sure the instance running in service manager is stopped.
This can be done by running either `sm2 --stop SOFTWARE_CHOICES_FRONTEND`.

### From source code on your local machine
1. Clone this repository into the development environment on your machine.
Expand Down
14 changes: 11 additions & 3 deletions app/config/ErrorHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ package config

import javax.inject.{Inject, Singleton}
import play.api.i18n.MessagesApi
import play.api.mvc.Request
import play.api.mvc.{Request, RequestHeader}
import play.twirl.api.Html
import uk.gov.hmrc.play.bootstrap.frontend.http.FrontendErrorHandler
import views.html.templates.error_template

import scala.language.implicitConversions


@Singleton
class ErrorHandler @Inject()(val messagesApi: MessagesApi,view : error_template, implicit val appConfig: AppConfig) extends FrontendErrorHandler {
override def standardErrorTemplate(pageTitle: String, heading: String, message: String)(implicit request: Request[_]): Html =
class ErrorHandler @Inject()(val messagesApi: MessagesApi,
view : error_template,
implicit val appConfig: AppConfig) extends FrontendErrorHandler {

implicit def rhToRequest(rh: RequestHeader): Request[_] = Request(rh, "")

override def standardErrorTemplate(pageTitle: String, heading: String, message: String)(implicit rh: Request[_]): Html =
view(pageTitle, heading, message)
}
1 change: 0 additions & 1 deletion app/controllers/LanguageSwitchController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import utils.LoggingUtil

import javax.inject.Inject


class LanguageSwitchController @Inject()(cc: MessagesControllerComponents)
extends FrontendController(cc)
with I18nSupport
Expand Down
20 changes: 14 additions & 6 deletions app/utils/LoggingUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@ import uk.gov.hmrc.http.{HeaderNames, HttpResponse, SessionKeys}

trait LoggingUtil extends LoggerLike {

lazy val trueClientIp: Request[_] => Option[String] = request => request.headers.get(HeaderNames.trueClientIp).map(trueClientIp => s"trueClientIp: $trueClientIp ")
lazy val trueClientIp: Request[_] => Option[String] =
request => request.headers.get(HeaderNames.trueClientIp).map(trueClientIp => s"trueClientIp: $trueClientIp ")

lazy val sessionId: Request[_] => Option[String] = request => request.session.get(SessionKeys.sessionId).map(sessionId => s"sessionId: $sessionId ")
lazy val sessionId: Request[_] => Option[String] =
request => request.session.get(SessionKeys.sessionId).map(sessionId => s"sessionId: $sessionId ")

lazy val identifiers: Request[_] => String = request => Seq(trueClientIp(request), sessionId(request)).flatten.foldLeft("")(_ + _)
lazy val identifiers: Request[_] => String =
request => Seq(trueClientIp(request), sessionId(request)).flatten.foldLeft("")(_ + _)

lazy val trueClientIpFromHttpResponse: HttpResponse => Option[String] = httpResponse => httpResponse.headers.get(HeaderNames.trueClientIp).map(trueClientIp => s"trueClientIp: $trueClientIp")
lazy val sessionIdFromHttpResponse: HttpResponse => Option[String] = httpResponse => httpResponse.headers.get(HeaderNames.xSessionId).map(sessionId => s"sessionId: $sessionId")
lazy val identifiersFromHttpResponse: HttpResponse => String = request => Seq(trueClientIpFromHttpResponse(request), sessionIdFromHttpResponse(request)).flatten.foldLeft("")(_ + _)
lazy val trueClientIpFromHttpResponse: HttpResponse => Option[String] =
httpResponse => httpResponse.headers.get(HeaderNames.trueClientIp).map(trueClientIp => s"trueClientIp: $trueClientIp")

lazy val sessionIdFromHttpResponse: HttpResponse => Option[String] =
httpResponse => httpResponse.headers.get(HeaderNames.xSessionId).map(sessionId => s"sessionId: $sessionId")

lazy val identifiersFromHttpResponse: HttpResponse => String =
request => Seq(trueClientIpFromHttpResponse(request), sessionIdFromHttpResponse(request)).flatten.foldLeft("")(_ + _)

lazy val logger: Logger = LoggerFactory.getLogger(getClass)

Expand Down
32 changes: 15 additions & 17 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import sbt.Keys.scalacOptions
import uk.gov.hmrc.DefaultBuildSettings.integrationTestSettings
import uk.gov.hmrc.sbtdistributables.SbtDistributablesPlugin.publishingSettings
import sbt.*

val appName = "software-choices-frontend"
val silencerVersion = "1.7.19"

val silencerVersion = "1.7.0"

lazy val coverageSettings: Seq[Setting[_]] = {
import scoverage.ScoverageKeys
lazy val coverageSettings: Seq[Def.Setting[?]] = {
import scoverage.*

val excludedPackages = Seq(
"<empty>",
Expand All @@ -24,23 +21,24 @@ lazy val coverageSettings: Seq[Setting[_]] = {

Seq(
ScoverageKeys.coverageExcludedPackages := excludedPackages.mkString(";"),
ScoverageKeys.coverageMinimum := 90,
ScoverageKeys.coverageFailOnMinimum := false,
ScoverageKeys.coverageHighlighting := true
ScoverageKeys.coverageMinimumStmtTotal := 90,
ScoverageKeys.coverageFailOnMinimum := false,
ScoverageKeys.coverageHighlighting := true
)
}

lazy val microservice = Project(appName, file("."))
lazy val microservice: Project = Project(appName, file("."))
.enablePlugins(play.sbt.PlayScala, SbtAutoBuildPlugin, SbtGitVersioning, SbtDistributablesPlugin)
.settings(coverageSettings: _*)
.disablePlugins(JUnitXmlReportPlugin)

.settings(coverageSettings *)
.settings(
majorVersion := 0,
libraryDependencies ++= AppDependencies.compile ++ AppDependencies.test
)
.settings(publishingSettings: _*)
.settings(scalaVersion := "2.13.14")
.configs(IntegrationTest)
.settings(integrationTestSettings(): _*)
.settings(scalaVersion := "2.12.12")
.settings(inConfig(IntegrationTest)(Defaults.itSettings): _*)
.settings(
TwirlKeys.templateImports ++= Seq(
"uk.gov.hmrc.hmrcfrontend.views.html.helpers._",
Expand All @@ -53,7 +51,7 @@ lazy val microservice = Project(appName, file("."))
// You may turn it on for `views` too to suppress warnings from unused imports in compiled twirl templates, but this will hide other warnings.
scalacOptions += "-P:silencer:pathFilters=views;routes",
libraryDependencies ++= Seq(
compilerPlugin("com.github.ghik" % "silencer-plugin" % silencerVersion cross CrossVersion.full),
"com.github.ghik" % "silencer-lib" % silencerVersion % Provided cross CrossVersion.full
compilerPlugin("com.github.ghik" % "silencer-plugin" % silencerVersion cross CrossVersion.full),
"com.github.ghik" % "silencer-lib" % silencerVersion % Provided cross CrossVersion.full
)
)
2 changes: 1 addition & 1 deletion conf/SoftwareProviders.json
Original file line number Diff line number Diff line change
Expand Up @@ -5210,7 +5210,7 @@
"agent": false,
"accounting": true,
"spreadsheets": false,
"viewReturn": true,
"viewReturn": false,
"viewLiabilities": false,
"viewPayments": false,
"cognitive": false,
Expand Down
2 changes: 0 additions & 2 deletions conf/prod.routes
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Add all the application routes to the app.routes file
-> /making-tax-digital-software app.Routes
-> / health.Routes

GET /admin/metrics com.kenshoo.play.metrics.MetricsController.metrics
29 changes: 15 additions & 14 deletions project/AppDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,29 @@
*/

import play.core.PlayVersion.current
import sbt._
import sbt.*

object AppDependencies {

val playUiVersion = "9.11.0-play-28"
val jsoupVersion = "1.15.3"
val bootstrapVersion = "7.12.0"
val scalaTestPlusVersion = "5.0.0"
val scalaMockVersion = "3.6.0"
val jsoupVersion = "1.15.3"
val bootstrapVersion = "8.6.0"
val scalaTestPlusVersion = "7.0.1"
val scalaMockVersion = "5.1.0"

val compile: Seq[ModuleID] = Seq(
"uk.gov.hmrc" %% "bootstrap-frontend-play-28" % bootstrapVersion,
"uk.gov.hmrc" %% "play-frontend-hmrc-play-28" % "8.5.0",
"org.webjars" % "jquery" % "3.6.3"
"uk.gov.hmrc" %% "bootstrap-frontend-play-30" % bootstrapVersion,
"uk.gov.hmrc" %% "play-frontend-hmrc-play-30" % "8.5.0",
"org.webjars" % "jquery" % "3.7.1"
)

val test: Seq[ModuleID] = Seq(
"org.jsoup" % "jsoup" % jsoupVersion % "test",
"com.typesafe.play" %% "play-test" % current % "test",
"org.scalatestplus.play" %% "scalatestplus-play" % scalaTestPlusVersion % "test",
"org.scalamock" %% "scalamock-scalatest-support" % scalaMockVersion % "test",
"org.pegdown" % "pegdown" % "1.6.0" % "test"
"org.jsoup" % "jsoup" % jsoupVersion % "test",
"org.playframework" %% "play-test" % current % "test",
"org.scalatestplus.play" %% "scalatestplus-play" % scalaTestPlusVersion % "test",
"org.scalamock" %% "scalamock" % scalaMockVersion % "test",
"org.pegdown" % "pegdown" % "1.6.0" % "test",
"com.vladsch.flexmark" % "flexmark-all" % "0.64.8" % "test"
)

def apply(): Seq[sbt.ModuleID] = compile ++ test
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.7.2
sbt.version=1.9.9
14 changes: 7 additions & 7 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
resolvers += "HMRC-open-artefacts-maven" at "https://open.artefacts.tax.service.gov.uk/maven2"
resolvers += "HMRC-open-artefacts-maven2" at "https://open.artefacts.tax.service.gov.uk/maven2"
resolvers += Resolver.url("HMRC-open-artefacts-ivy", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(Resolver.ivyStylePatterns)

addSbtPlugin("uk.gov.hmrc" %% "sbt-auto-build" % "3.16.0")
addSbtPlugin("uk.gov.hmrc" %% "sbt-auto-build" % "3.20.0")

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

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.18")
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.1")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.2.1")

addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0" exclude("org.scala-lang.modules", "scala-xml_2.12"))

addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.4.11")
addSbtPlugin("io.github.irundaia" % "sbt-sassify" % "1.5.2")
2 changes: 2 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
sbt clean compile coverage test coverageReport
38 changes: 19 additions & 19 deletions scalastyle-config.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<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>
Expand All @@ -9,7 +9,7 @@
<check level="warning" class="org.scalastyle.file.HeaderMatchesChecker" enabled="true">
<parameters>
<parameter name="header"><![CDATA[/*
* Copyright 2022 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,9 +25,9 @@
*/]]></parameter>
</parameters>
</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.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="true">
<parameters>
<parameter name="maxLineLength"><![CDATA[160]]></parameter>
Expand All @@ -49,7 +49,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 @@ -65,14 +65,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 @@ -88,8 +88,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 @@ -111,7 +111,7 @@
<parameter name="maxMethods"><![CDATA[30]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.PublicMethodsHaveTypeChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.NewLineAtEofChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.NoNewLineAtEofChecker" enabled="false"></check>
<check level="warning" class="org.scalastyle.scalariform.PublicMethodsHaveTypeChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.file.NewLineAtEofChecker" enabled="true"/>
<check level="warning" class="org.scalastyle.file.NoNewLineAtEofChecker" enabled="false"/>
</scalastyle>
2 changes: 1 addition & 1 deletion test/SoftwareProviderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SoftwareProviderSpec extends TestUtils {
Source.fromInputStream(stream).getLines.toSeq
}

val expectedProviders: Seq[String] = Source.fromFile("test/resources/TestSoftwareProviders.json").getLines.toSeq
val expectedProviders: Seq[String] = Source.fromFile("test/resources/TestSoftwareProviders.json").getLines().toSeq

for (i <- expectedProviders.indices) {
actualProviders(i) shouldBe expectedProviders(i)
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/LanguageSwitchControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package controllers

import org.scalatest.MustMatchers.convertToAnyMustWrapper
import org.scalatest.matchers.must.Matchers.convertToAnyMustWrapper
import play.api.Application
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.mvc.{Cookies, Result}
Expand Down
5 changes: 3 additions & 2 deletions test/forms/FiltersFormSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package forms

import enums.Filter._
import models.FiltersFormModel
import org.scalatest.{Matchers, WordSpec}
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

class FiltersFormSpec extends WordSpec with Matchers {
class FiltersFormSpec extends AnyWordSpec with Matchers {

"Binding a form with invalid data" when {

Expand Down
2 changes: 1 addition & 1 deletion test/resources/TestSoftwareProviders.json
Original file line number Diff line number Diff line change
Expand Up @@ -5210,7 +5210,7 @@
"agent": false,
"accounting": true,
"spreadsheets": false,
"viewReturn": true,
"viewReturn": false,
"viewLiabilities": false,
"viewPayments": false,
"cognitive": false,
Expand Down
6 changes: 3 additions & 3 deletions test/utils/MaterializerSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package utils

import akka.actor.ActorSystem
import org.apache.pekko.actor.ActorSystem

trait MaterializerSupport {
implicit val system = ActorSystem("Sys")
implicit val actorSystem = ActorSystem()
implicit val system: ActorSystem = ActorSystem("Sys")
implicit val actorSystem: ActorSystem = ActorSystem()
}
13 changes: 8 additions & 5 deletions test/utils/TestUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,28 @@
package utils

import config.mocks.MockAppConfig
import org.scalatest.{BeforeAndAfterEach, Matchers, WordSpec}
import org.scalatest.BeforeAndAfterEach
import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.matchers.should.Matchers
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api.i18n.{Lang, Messages, MessagesApi, MessagesImpl}
import play.api.inject.Injector
import play.api.mvc.AnyContentAsEmpty
import play.api.test.FakeRequest

trait TestUtils extends WordSpec with Matchers with GuiceOneAppPerSuite with BeforeAndAfterEach with MaterializerSupport {
trait TestUtils extends AnyWordSpec with Matchers with GuiceOneAppPerSuite with BeforeAndAfterEach with MaterializerSupport {

override def beforeEach() {
override def beforeEach(): Unit = {
super.beforeEach()
appConfig.priceFilterEnabled(true)
appConfig.welshEnabled(false)
}

implicit lazy val fakeRequest = FakeRequest("GET", "/")
implicit lazy val fakeRequest: FakeRequest[AnyContentAsEmpty.type] = FakeRequest("GET", "/")

lazy val injector: Injector = app.injector
lazy val messagesApi: MessagesApi = injector.instanceOf[MessagesApi]
implicit lazy val messages: Messages = MessagesImpl(Lang("en"), messagesApi)
implicit lazy val appConfig = injector.instanceOf[MockAppConfig]
implicit lazy val appConfig: MockAppConfig = injector.instanceOf[MockAppConfig]

}

0 comments on commit b51f680

Please sign in to comment.