Skip to content

Commit

Permalink
API-6683 - Upgrade to Scala 2.13 (#109)
Browse files Browse the repository at this point in the history
* API-6683 - Tidy up code before upgrade to Scala 2.13

* API-6683 - Upgraded to Scala 2.13

* API-6683 - PR comments
  • Loading branch information
peteslater-ee authored Mar 20, 2023
1 parent 0643b24 commit 0032e19
Show file tree
Hide file tree
Showing 30 changed files with 221 additions and 148 deletions.
24 changes: 22 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
version="3.5.3"
runner.dialect = "scala212"
runner.dialect = "scala213"

maxColumn = 180

assumeStandardLibraryStripMargin = true
align.stripMargin = true

align.preset = most
align.multiline = true

indent.extendSite = 4
indent.defnSite = 4

align.arrowEnumeratorGenerator = true

align.closeParenSite = true
align.openParenCallSite = false
align.openParenDefnSite = false
align.openParenCtrlSite = false

danglingParentheses.defnSite = true
danglingParentheses.callSite = true
danglingParentheses.exclude = []
danglingParentheses.exclude = []

newlines.source = keep
newlines.topLevelStatements = [before]
newlines.alwaysBeforeMultilineDef = false
newlines.implicitParamListModifierPrefer = before
# newlines.implicitParamListModifierForce = [before]
newlines.avoidForSimpleOverflow = [tooLong, punct, slc]

rewrite.rules = [SortModifiers]
rewrite.imports.sort = ascii

verticalMultiline.atDefnSite = true
verticalMultiline.newlineAfterOpenParen = true

includeNoParensInSelectChains = true
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package uk.gov.hmrc.apisubscriptionfields

import java.util.UUID
import org.scalatest._
import org.scalatestplus.play.guice.GuiceOneServerPerSuite
import play.api.Application
import play.api.inject.guice.GuiceApplicationBuilder
Expand All @@ -35,7 +34,12 @@ import cats.data.NonEmptyList
import uk.gov.hmrc.apisubscriptionfields.controller.Helper
import uk.gov.hmrc.mongo.MongoComponent

trait AcceptanceTestSpec extends FeatureSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.GivenWhenThen
import org.scalatest.BeforeAndAfterAll
import org.scalatest.featurespec.AnyFeatureSpec

trait AcceptanceTestSpec extends AnyFeatureSpec
with GivenWhenThen
with BeforeAndAfterAll
with Matchers
Expand Down Expand Up @@ -87,12 +91,16 @@ trait AcceptanceTestSpec extends FeatureSpec

protected def await[A](future: Future[A]): A = Await.result(future, 5.seconds)

override protected def beforeAll: Unit = {
override protected def beforeAll(): Unit = {
super.beforeAll()

dropDatabase()
}

override protected def afterAll: Unit = {
override protected def afterAll(): Unit = {
dropDatabase()

super.afterAll()
}

private def dropDatabase(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,38 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec
with BeforeAndAfterAll
with ApplicationLogger {

override def beforeAll() {
override def beforeAll(): Unit = {
super.beforeAll()

val putRequest = validDefinitionPutRequest(NelOfFieldDefinitions)
.withTarget( RequestTarget(uriString="", path=definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty))

Await.result(route(app, putRequest).get, 10.seconds)
}

override def afterAll() {
override def afterAll(): Unit = {
val request = ValidRequest
.withMethod(DELETE)
.withTarget( RequestTarget(uriString="", path=definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty))

route(app, request)

super.afterAll()
}


feature("Subscription-Fields") {
Feature("Subscription-Fields") {

appLogger.logger.info(s"App.mode = ${app.mode.toString}")

scenario("the API is called to store some values for a new subscription field") {
Scenario("the API is called to store some values for a new subscription field") {
val request: Request[AnyContentAsJson] = createSubscriptionFieldsRequest()

When("a PUT request with data is sent to the API")
val result: Option[Future[Result]] = route(app, request)

Then(s"a response with a 201 status is received")
result shouldBe 'defined
result shouldBe defined
val resultFuture = result.value

status(resultFuture) shouldBe CREATED
Expand All @@ -86,7 +90,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec
route(app, createSubscriptionFieldsRequest())
}

scenario("the API is called to GET some existing subscription fields") {
Scenario("the API is called to GET some existing subscription fields") {

Given("a request with a known subscription field")
createSubscriptionFields()
Expand All @@ -97,7 +101,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec
val result: Option[Future[Result]] = route(app, request)

Then(s"a response with a 200 status is received")
result shouldBe 'defined
result shouldBe defined
val resultFuture = result.value

status(resultFuture) shouldBe OK
Expand All @@ -110,7 +114,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec
sfr.get shouldBe SubscriptionFields(FakeClientId, ApiContext("acontext"), ApiVersion("1.0.2"), fieldsId, SampleFields1)
}

scenario("the API is called to GET all existing subscription fields") {
Scenario("the API is called to GET all existing subscription fields") {

Given("a request with a known subscription field")
createSubscriptionFields()
Expand All @@ -121,7 +125,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec
val result: Option[Future[Result]] = route(app, request)

Then(s"a response with a 200 status is received")
result shouldBe 'defined
result shouldBe defined
val resultFuture = result.value

status(resultFuture) shouldBe OK
Expand All @@ -134,7 +138,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec
sfr.get shouldBe BulkSubscriptionFieldsResponse(Seq(SubscriptionFields(FakeClientId, ApiContext("acontext"), ApiVersion("1.0.2"), fieldsId, SampleFields1)))
}

scenario("the API is called to GET with a known fieldsId") {
Scenario("the API is called to GET with a known fieldsId") {

Given("a request with a known fieldsId")

Expand All @@ -146,7 +150,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec
val result: Option[Future[Result]] = route(app, requestId)

Then(s"a response with a 200 status is received")
result shouldBe 'defined
result shouldBe defined
val resultFuture = result.value

status(resultFuture) shouldBe OK
Expand All @@ -164,7 +168,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec
val resultFieldsId: Option[Future[Result]] = route(app, requestFieldsId)

Then(s"a response with a 200 status is received")
resultFieldsId shouldBe 'defined
resultFieldsId shouldBe defined
val resultFieldsIdFuture = result.value

status(resultFieldsIdFuture) shouldBe OK
Expand All @@ -174,7 +178,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec
sfrFieldsId.get shouldBe SubscriptionFields(FakeClientId, ApiContext("acontext"), ApiVersion("1.0.2"), fieldsId, SampleFields1)
}

scenario("the API is called to GET existing subscription fields by application clientId") {
Scenario("the API is called to GET existing subscription fields by application clientId") {

Given("a request with a known client identifier")
createSubscriptionFields()
Expand All @@ -185,7 +189,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec
val result: Option[Future[Result]] = route(app, request)

Then(s"a response with a 200 status is received")
result shouldBe 'defined
result shouldBe defined
val resultFuture = result.value


Expand All @@ -199,7 +203,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec
sfr.get shouldBe BulkSubscriptionFieldsResponse(Seq(SubscriptionFields(FakeClientId, ApiContext("acontext"), ApiVersion("1.0.2"), fieldsId, SampleFields1)))
}

scenario("the API is called to update existing subscription fields") {
Scenario("the API is called to update existing subscription fields") {

Given("a request with valid payload")
createSubscriptionFields()
Expand All @@ -210,7 +214,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec
val result: Option[Future[Result]] = route(app, request)

Then(s"a response with a 200 status is received")
result shouldBe 'defined
result shouldBe defined
val resultFuture = result.value

status(resultFuture) shouldBe OK
Expand All @@ -223,7 +227,7 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec
sfr.get shouldBe SubscriptionFields(FakeClientId, ApiContext("acontext"), ApiVersion("1.0.2"), fieldsId, SampleFields2)
}

scenario("the API is called to DELETE existing subscription fields") {
Scenario("the API is called to DELETE existing subscription fields") {

Given("a request with existing subscription fields")
createSubscriptionFields()
Expand All @@ -234,13 +238,13 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec
val result: Option[Future[Result]] = route(app, request)

Then(s"a response with a 204 status is received")
result shouldBe 'defined
result shouldBe defined
val resultFuture = result.value

status(resultFuture) shouldBe NO_CONTENT

And("the response body is empty")
contentAsString(resultFuture) shouldBe 'empty
contentAsString(resultFuture) shouldBe empty
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec
with SubscriptionFieldsTestData
with ApplicationLogger {

feature("Subscription-Fields") {
Feature("Subscription-Fields") {
appLogger.logger.info(s"App.mode = ${app.mode.toString}")

scenario("the API is called to GET non-existing subscription fields") {
Scenario("the API is called to GET non-existing subscription fields") {

Given("the API is called to GET non-existing subscription fields")
val request = createRequest(GET, subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion))
When("a GET request with data is sent to the API")
val result: Option[Future[Result]] = route(app, request)

Then(s"a response with a 404 status is received")
result shouldBe 'defined
result shouldBe defined
val resultFuture = result.value

status(resultFuture) shouldBe NOT_FOUND
Expand All @@ -51,7 +51,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec
contentAsJson(resultFuture) shouldBe JsErrorResponse(NOT_FOUND_CODE, s"Subscription fields not found for ($fakeRawClientId, $fakeRawContext, $fakeRawVersion)")
}

scenario("the API is called to GET with an unknown fieldsId") {
Scenario("the API is called to GET with an unknown fieldsId") {

Given("the API is called to GET with an unknown fieldsId")
val request = createRequest(GET, fieldsIdEndpoint(FakeRawFieldsId))
Expand All @@ -60,7 +60,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec
val result: Option[Future[Result]] = route(app, request)

Then(s"a response with a 404 status is received")
result shouldBe 'defined
result shouldBe defined
val resultFuture = result.value

status(resultFuture) shouldBe NOT_FOUND
Expand All @@ -69,7 +69,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec
contentAsJson(resultFuture) shouldBe JsErrorResponse(NOT_FOUND_CODE, s"FieldsId (${FakeRawFieldsId.toString}) was not found")
}

scenario("the API is called to GET an unknown application clientId") {
Scenario("the API is called to GET an unknown application clientId") {

Given("the API is called to GET an unknown application clientId")
val request = createRequest(GET, byClientIdEndpoint(fakeRawClientId))
Expand All @@ -78,7 +78,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec
val result: Option[Future[Result]] = route(app, request)

Then(s"a response with a 404 status is received")
result shouldBe 'defined
result shouldBe defined
val resultFuture = result.value

status(resultFuture) shouldBe NOT_FOUND
Expand All @@ -87,7 +87,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec
contentAsJson(resultFuture) shouldBe JsErrorResponse(NOT_FOUND_CODE, s"ClientId ($fakeRawClientId) was not found")
}

scenario("the API is called to DELETE an unknown subscription field") {
Scenario("the API is called to DELETE an unknown subscription field") {

Given("a request with an unknown subscription field")
val request = createRequest(DELETE, subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion))
Expand All @@ -96,7 +96,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec
val result: Option[Future[Result]] = route(app, request)

Then(s"a response with a 404 status is received")
result shouldBe 'defined
result shouldBe defined
val resultFuture = result.value

status(resultFuture) shouldBe NOT_FOUND
Expand All @@ -105,7 +105,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec
contentAsJson(resultFuture) shouldBe JsErrorResponse(NOT_FOUND_CODE, s"Subscription fields not found for ($fakeRawClientId, $fakeRawContext, $fakeRawVersion)")
}

scenario("the API is called to PUT subscription fields with an invalid JSON payload") {
Scenario("the API is called to PUT subscription fields with an invalid JSON payload") {

Given("the API is called to PUT subscription fields with an invalid JSON payload")
val request = createRequest(PUT, subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion))
Expand All @@ -115,7 +115,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec
val result: Option[Future[Result]] = route(app, request)

Then(s"a response with a 422 status is received")
result shouldBe 'defined
result shouldBe defined
val resultFuture = result.value

status(resultFuture) shouldBe UNPROCESSABLE_ENTITY
Expand All @@ -124,7 +124,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec
contentAsJson(resultFuture) shouldBe JsErrorResponse(INVALID_REQUEST_PAYLOAD, _: Json.JsValueWrapper)
}

scenario("the API is called to PUT subscription fields with an invalid non JSON payload") {
Scenario("the API is called to PUT subscription fields with an invalid non JSON payload") {

Given("the API is called to PUT subscription fields with an invalid non JSON payload")
val request = createRequest(PUT, subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion))
Expand All @@ -134,7 +134,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec
val result: Option[Future[Result]] = route(app, request)

Then(s"a response with a 415 status is received")
result shouldBe 'defined
result shouldBe defined
val resultFuture = result.value

status(resultFuture) shouldBe UNSUPPORTED_MEDIA_TYPE
Expand Down
Loading

0 comments on commit 0032e19

Please sign in to comment.