From 0bea82189d07a45eb80431c510de97992f9809ee Mon Sep 17 00:00:00 2001 From: Matthew Clark <36630558+mattclark-zerogravit@users.noreply.github.com> Date: Fri, 6 Mar 2020 09:27:32 +0000 Subject: [PATCH] API-4199 (#62) * API-4199: Refactor WIP * API-4199: moved Acceptance Tests into root * API-4199: acceptance tests now passing * API-4199: acceptance tests now passing * API-4199: acceptance tests now passing Co-authored-by: Chris Rowe Co-authored-by: Matt Clark --- LICENSE | 5 +- .../acceptance/AcceptanceTestSpec.scala | 23 ++++--- .../ApiSubscriptionFieldsHappySpec.scala | 54 ++++++++++----- .../ApiSubscriptionFieldsUnhappySpec.scala | 21 +++--- .../acceptance}/ExternalServices.scala | 2 +- ...ubscriptionFieldDefinitionsHappySpec.scala | 47 +++++++------ ...scriptionFieldDefinitionsUnhappySpec.scala | 25 +++++-- .../controller/CommonController.scala | 4 +- .../FieldsDefinitionController.scala | 4 +- .../SubscriptionFieldsController.scala | 3 +- .../repository/MongoDb.scala | 9 ++- build.sbt | 66 ++++++++----------- conf/app.routes | 22 +++---- dependencyReport.py | 61 ----------------- project/build.properties | 2 +- project/plugins.sbt | 12 ++-- run_all_tests.sh | 1 - .../apisubscriptionfields}/TestData.scala | 2 +- ...FieldsDefinitionControllerDeleteSpec.scala | 8 +-- .../FieldsDefinitionControllerGetSpec.scala | 6 +- .../FieldsDefinitionControllerPutSpec.scala | 7 +- ...bscriptionFieldsControllerDeleteSpec.scala | 8 +-- .../SubscriptionFieldsControllerGetSpec.scala | 8 +-- .../SubscriptionFieldsControllerPutSpec.scala | 11 ++-- .../model/JsonFormatterSpec.scala | 2 +- .../FieldsDefinitionRepositorySpec.scala | 2 +- .../repository/MongoErrorHandlerSpec.scala | 0 .../repository/MongoFormattersSpec.scala | 0 .../SubscriptionFieldsRepositorySpec.scala | 2 +- .../service/FieldsDefinitionServiceSpec.scala | 4 +- .../SubscriptionFieldsServiceSpec.scala | 2 +- .../util/WireMockRunner.scala | 41 ------------ 32 files changed, 201 insertions(+), 263 deletions(-) rename {test/acceptance => acceptance}/uk/gov/hmrc/apisubscriptionfields/acceptance/AcceptanceTestSpec.scala (83%) rename {test/acceptance => acceptance}/uk/gov/hmrc/apisubscriptionfields/acceptance/ApiSubscriptionFieldsHappySpec.scala (80%) rename {test/acceptance => acceptance}/uk/gov/hmrc/apisubscriptionfields/acceptance/ApiSubscriptionFieldsUnhappySpec.scala (84%) rename {test/util/uk/gov/hmrc/apisubscriptionfields/util => acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance}/ExternalServices.scala (92%) rename {test/acceptance => acceptance}/uk/gov/hmrc/apisubscriptionfields/acceptance/SubscriptionFieldDefinitionsHappySpec.scala (71%) rename {test/acceptance => acceptance}/uk/gov/hmrc/apisubscriptionfields/acceptance/SubscriptionFieldDefinitionsUnhappySpec.scala (82%) delete mode 100644 dependencyReport.py rename test/{util/uk/gov/hmrc/apisubscriptionfields/util => uk/gov/hmrc/apisubscriptionfields}/TestData.scala (98%) rename test/{unit => }/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerDeleteSpec.scala (85%) rename test/{unit => }/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerGetSpec.scala (95%) rename test/{unit => }/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerPutSpec.scala (92%) rename test/{unit => }/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerDeleteSpec.scala (91%) rename test/{unit => }/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerGetSpec.scala (95%) rename test/{unit => }/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerPutSpec.scala (85%) rename test/{unit => }/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatterSpec.scala (97%) rename test/{unit => }/uk/gov/hmrc/apisubscriptionfields/repository/FieldsDefinitionRepositorySpec.scala (98%) rename test/{unit => }/uk/gov/hmrc/apisubscriptionfields/repository/MongoErrorHandlerSpec.scala (100%) rename test/{unit => }/uk/gov/hmrc/apisubscriptionfields/repository/MongoFormattersSpec.scala (100%) rename test/{unit => }/uk/gov/hmrc/apisubscriptionfields/repository/SubscriptionFieldsRepositorySpec.scala (99%) rename test/{unit => }/uk/gov/hmrc/apisubscriptionfields/service/FieldsDefinitionServiceSpec.scala (95%) rename test/{unit => }/uk/gov/hmrc/apisubscriptionfields/service/SubscriptionFieldsServiceSpec.scala (98%) delete mode 100644 test/util/uk/gov/hmrc/apisubscriptionfields/util/WireMockRunner.scala diff --git a/LICENSE b/LICENSE index 66b771c..d645695 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,4 @@ + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -178,7 +179,7 @@ APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" + boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a @@ -186,7 +187,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2018 HM Revenue & Customs + Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/test/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/AcceptanceTestSpec.scala b/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/AcceptanceTestSpec.scala similarity index 83% rename from test/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/AcceptanceTestSpec.scala rename to acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/AcceptanceTestSpec.scala index 1d12b88..26aeede 100644 --- a/test/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/AcceptanceTestSpec.scala +++ b/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/AcceptanceTestSpec.scala @@ -19,16 +19,18 @@ package uk.gov.hmrc.apisubscriptionfields.acceptance import java.util.UUID import org.scalatest._ -import org.scalatestplus.play.guice.GuiceOneAppPerSuite +import org.scalatestplus.play.guice.GuiceOneServerPerSuite import play.api.Application import play.api.inject.guice.GuiceApplicationBuilder import play.api.libs.json.Json -import play.api.mvc.{AnyContentAsEmpty, AnyContentAsJson} +import play.api.mvc._ +import play.api.mvc.request.RequestTarget import play.api.test.FakeRequest -import play.modules.reactivemongo.MongoDbConnection +import play.api.test.Helpers._ +import play.modules.reactivemongo.ReactiveMongoComponent +import uk.gov.hmrc.apisubscriptionfields.RequestHeaders import uk.gov.hmrc.apisubscriptionfields.model.JsonFormatters._ import uk.gov.hmrc.apisubscriptionfields.model._ -import uk.gov.hmrc.apisubscriptionfields.util.{ExternalServicesConfig, RequestHeaders} import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.duration._ @@ -38,7 +40,7 @@ trait AcceptanceTestSpec extends FeatureSpec with GivenWhenThen with BeforeAndAfterAll with Matchers - with GuiceOneAppPerSuite { + with GuiceOneServerPerSuite { protected val ValidRequest = FakeRequest() .withHeaders(RequestHeaders.ACCEPT_HMRC_JSON_HEADER) @@ -65,13 +67,13 @@ trait AcceptanceTestSpec extends FeatureSpec validSubscriptionPutRequest(SubscriptionFieldsRequest(fields)) protected def validSubscriptionPutRequest(contents: SubscriptionFieldsRequest): FakeRequest[AnyContentAsJson] = - fakeRequestWithHeaders.withJsonBody(Json.toJson(contents)) + fakeRequestWithHeaders.withMethod(PUT).withJsonBody(Json.toJson(contents)) protected def validDefinitionPutRequest(fieldDefinitions: Seq[FieldDefinition]): FakeRequest[AnyContentAsJson] = validDefinitionPutRequest(FieldsDefinitionRequest(fieldDefinitions)) protected def validDefinitionPutRequest(contents: FieldsDefinitionRequest): FakeRequest[AnyContentAsJson] = - fakeRequestWithHeaders.withJsonBody(Json.toJson(contents)) + fakeRequestWithHeaders.withMethod(PUT).withJsonBody(Json.toJson(contents)) protected def fakeRequestWithHeaders: FakeRequest[AnyContentAsEmpty.type] = { FakeRequest().withHeaders(RequestHeaders.ACCEPT_HMRC_JSON_HEADER, RequestHeaders.CONTENT_TYPE_HEADER) @@ -98,6 +100,11 @@ trait AcceptanceTestSpec extends FeatureSpec } private def dropDatabase(): Unit = { - await(new MongoDbConnection() {}.db().drop()) + await( app.injector.instanceOf[ReactiveMongoComponent].mongoConnector.db().drop()) } + + def createRequest(method: String, path: String) = + ValidRequest + .withMethod(method) + .withTarget( RequestTarget(uriString ="", path= path, queryString = Map.empty)) } \ No newline at end of file diff --git a/test/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/ApiSubscriptionFieldsHappySpec.scala b/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/ApiSubscriptionFieldsHappySpec.scala similarity index 80% rename from test/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/ApiSubscriptionFieldsHappySpec.scala rename to acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/ApiSubscriptionFieldsHappySpec.scala index eee3b5b..6ff7a6a 100644 --- a/test/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/ApiSubscriptionFieldsHappySpec.scala +++ b/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/ApiSubscriptionFieldsHappySpec.scala @@ -18,30 +18,31 @@ package uk.gov.hmrc.apisubscriptionfields.acceptance import org.scalatest.OptionValues import play.api.Logger +import play.api.libs.json.Json import play.api.mvc._ +import play.api.mvc.request.RequestTarget +import play.api.test.FakeRequest import play.api.test.Helpers._ import uk.gov.hmrc.apisubscriptionfields.model._ -import uk.gov.hmrc.apisubscriptionfields.util.{FieldsDefinitionTestData, SubscriptionFieldsTestData} +import uk.gov.hmrc.apisubscriptionfields.{FieldsDefinitionTestData, SubscriptionFieldsTestData} import scala.concurrent.Future class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec with OptionValues + with JsonFormatters with SubscriptionFieldsTestData with FieldsDefinitionTestData { - import uk.gov.hmrc.apisubscriptionfields.model.JsonFormatters._ - feature("Subscription-Fields") { Logger.logger.info(s"App.mode = ${app.mode.toString}") scenario("the API is called to store some values for a new subscription field") { Given("a request with valid payload") - val request = validSubscriptionPutRequest(SampleFields1) - .copyFakeRequest(method = PUT, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) + val request = createSubscriptionFieldsRequest() - When("a PUT request with data is sent to the API") + 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") @@ -58,11 +59,21 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec sfr.get shouldBe SubscriptionFieldsResponse(fakeRawClientId, "acontext", "1.0.2", fieldsId, SampleFields1) } + def createSubscriptionFieldsRequest(): FakeRequest[AnyContentAsJson] = { + createRequest(PUT, subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) + .withJsonBody(Json.toJson(SubscriptionFieldsRequest(SampleFields1))) + } + + def createSubscriptionFields()= { + route(app, createSubscriptionFieldsRequest()) + } + scenario("the API is called to GET some existing subscription fields") { Given("a request with a known subscription field") - val request = ValidRequest - .copyFakeRequest(method = GET, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) + createSubscriptionFields() + + 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) @@ -84,8 +95,9 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec scenario("the API is called to GET all existing subscription fields") { Given("a request with a known subscription field") - val request = ValidRequest - .copyFakeRequest(method = GET, uri = allSubscriptionFieldsEndpoint) + createSubscriptionFields() + + val request = createRequest(GET, allSubscriptionFieldsEndpoint) When("a GET request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -107,8 +119,10 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec scenario("the API is called to GET with a known fieldsId") { Given("a request with a known fieldsId") - val requestId = ValidRequest - .copyFakeRequest(method = GET, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) + + createSubscriptionFields() + + val requestId = createRequest(GET, subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) When("an id GET request with data is sent to the API") val result: Option[Future[Result]] = route(app, requestId) @@ -124,7 +138,9 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec Given("a request with a known fieldsId") val fieldsId = sfr.get.fieldsId - val requestFieldsId = ValidRequest.copyFakeRequest(method = GET, uri = fieldsIdEndpoint(fieldsId.value)) + + val requestFieldsId = createRequest(GET, fieldsIdEndpoint(fieldsId.value)) + When("a fieldsId GET request with data is sent to the API") val resultFieldsId: Option[Future[Result]] = route(app, requestFieldsId) @@ -143,7 +159,9 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec scenario("the API is called to GET existing subscription fields by application clientId") { Given("a request with a known client identifier") - val request = ValidRequest.copyFakeRequest(method = GET, uri = byClientIdEndpoint(fakeRawClientId)) + createSubscriptionFields() + + val request = createRequest(GET, byClientIdEndpoint(fakeRawClientId)) When("a GET request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -165,8 +183,9 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec scenario("the API is called to update existing subscription fields") { Given("a request with valid payload") + createSubscriptionFields() val request = validSubscriptionPutRequest(SampleFields2) - .copyFakeRequest(method = PUT, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) + .withTarget(RequestTarget(uriString = "", path = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion), queryString = Map.empty)) When("a PUT request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -188,8 +207,9 @@ class ApiSubscriptionFieldsHappySpec extends AcceptanceTestSpec scenario("the API is called to DELETE existing subscription fields") { Given("a request with existing subscription fields") - val request = ValidRequest - .copyFakeRequest(method = DELETE, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) + createSubscriptionFields() + + val request = createRequest(DELETE, subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) When("a GET request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) diff --git a/test/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/ApiSubscriptionFieldsUnhappySpec.scala b/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/ApiSubscriptionFieldsUnhappySpec.scala similarity index 84% rename from test/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/ApiSubscriptionFieldsUnhappySpec.scala rename to acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/ApiSubscriptionFieldsUnhappySpec.scala index 7a7d901..3f67036 100644 --- a/test/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/ApiSubscriptionFieldsUnhappySpec.scala +++ b/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/ApiSubscriptionFieldsUnhappySpec.scala @@ -21,9 +21,9 @@ import play.api.Logger import play.api.libs.json.Json import play.api.mvc._ import play.api.test.Helpers._ +import uk.gov.hmrc.apisubscriptionfields.SubscriptionFieldsTestData import uk.gov.hmrc.apisubscriptionfields.model.ErrorCode.{INVALID_REQUEST_PAYLOAD, NOT_FOUND_CODE} import uk.gov.hmrc.apisubscriptionfields.model.JsErrorResponse -import uk.gov.hmrc.apisubscriptionfields.util.SubscriptionFieldsTestData import scala.concurrent.Future @@ -37,9 +37,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec scenario("the API is called to GET non-existing subscription fields") { Given("the API is called to GET non-existing subscription fields") - val request = ValidRequest - .copyFakeRequest(method = GET, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) - + 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) @@ -56,7 +54,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec scenario("the API is called to GET with an unknown fieldsId") { Given("the API is called to GET with an unknown fieldsId") - val request = ValidRequest.copyFakeRequest(method = GET, uri = fieldsIdEndpoint(FakeRawFieldsId)) + val request = createRequest(GET, fieldsIdEndpoint(FakeRawFieldsId)) When("a GET request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -74,7 +72,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec scenario("the API is called to GET an unknown application clientId") { Given("the API is called to GET an unknown application clientId") - val request = ValidRequest.copyFakeRequest(method = GET, uri = byClientIdEndpoint(fakeRawClientId)) + val request = createRequest(GET, byClientIdEndpoint(fakeRawClientId)) When("a GET request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -92,8 +90,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec scenario("the API is called to DELETE an unknown subscription field") { Given("a request with an unknown subscription field") - val request = ValidRequest - .copyFakeRequest(method = DELETE, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) + val request = createRequest(DELETE, subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) When("a GET request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -111,8 +108,8 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec 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 = ValidRequest - .copyFakeRequest(method = PUT, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion), body = Json.parse("{}")) + val request = createRequest(PUT, subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) + .withJsonBody(Json.parse("{}")) When("a PUT request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -130,8 +127,8 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec 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 = ValidRequest - .copyFakeRequest(method = PUT, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion), body = InvalidNonJsonPayload) + val request = createRequest(PUT, subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) + .withBody(InvalidNonJsonPayload) When("a PUT request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) diff --git a/test/util/uk/gov/hmrc/apisubscriptionfields/util/ExternalServices.scala b/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/ExternalServices.scala similarity index 92% rename from test/util/uk/gov/hmrc/apisubscriptionfields/util/ExternalServices.scala rename to acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/ExternalServices.scala index da34d7f..ada8fe7 100644 --- a/test/util/uk/gov/hmrc/apisubscriptionfields/util/ExternalServices.scala +++ b/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/ExternalServices.scala @@ -14,7 +14,7 @@ * limitations under the License. */ -package uk.gov.hmrc.apisubscriptionfields.util +package uk.gov.hmrc.apisubscriptionfields.acceptance object ExternalServicesConfig { val Port: Int = 11111 diff --git a/test/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/SubscriptionFieldDefinitionsHappySpec.scala b/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/SubscriptionFieldDefinitionsHappySpec.scala similarity index 71% rename from test/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/SubscriptionFieldDefinitionsHappySpec.scala rename to acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/SubscriptionFieldDefinitionsHappySpec.scala index e1cf30c..daa36db 100644 --- a/test/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/SubscriptionFieldDefinitionsHappySpec.scala +++ b/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/SubscriptionFieldDefinitionsHappySpec.scala @@ -18,47 +18,51 @@ package uk.gov.hmrc.apisubscriptionfields.acceptance import org.scalatest.OptionValues import play.api.mvc._ +import play.api.mvc.request.RequestTarget import play.api.test.Helpers._ import uk.gov.hmrc.apisubscriptionfields.model._ -import uk.gov.hmrc.apisubscriptionfields.util.{FieldsDefinitionTestData, SubscriptionFieldsTestData} +import uk.gov.hmrc.apisubscriptionfields.{FieldsDefinitionTestData, SubscriptionFieldsTestData} import scala.concurrent.Future class SubscriptionFieldDefinitionsHappySpec extends AcceptanceTestSpec with OptionValues with SubscriptionFieldsTestData - with FieldsDefinitionTestData { - - import uk.gov.hmrc.apisubscriptionfields.model.JsonFormatters._ + with FieldsDefinitionTestData + with JsonFormatters { feature("Fields-Definition") { scenario("the API is called to store some new fields definitions") { - - Given("a request with valid payload") - val request = validDefinitionPutRequest(FakeFieldsDefinitions) - .copyFakeRequest(method = PUT, uri = definitionEndpoint(fakeRawContext, fakeRawVersion)) + Given("Definitiions are created ") + val putRequest = validDefinitionPutRequest(FakeFieldsDefinitions) + .withTarget( RequestTarget(uriString="", path=definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) When("a PUT request with data is sent to the API") - val result: Option[Future[Result]] = route(app, request) + val putResult: Option[Future[Result]] = route(app, putRequest) Then(s"a response with a 201 status is received") - result shouldBe 'defined - val resultFuture = result.value + putResult shouldBe 'defined + val putResultFuture = putResult.value - status(resultFuture) shouldBe CREATED + status(putResultFuture) shouldBe CREATED And("the response body should be a valid response") - val sfr = contentAsJson(resultFuture).validate[FieldsDefinitionResponse] + val sfr = contentAsJson(putResultFuture).validate[FieldsDefinitionResponse] sfr.isSuccess shouldBe true sfr.get shouldBe FieldsDefinitionResponse(fakeRawContext, fakeRawVersion, FakeFieldsDefinitions) } + + + scenario("the API is called to GET a known fields definition") { - Given("a request with a known fields definition") - val request = ValidRequest.copyFakeRequest(method = GET, uri = definitionEndpoint(fakeRawContext, fakeRawVersion)) + Then("a request with a known fields definition") + val request = ValidRequest + .withMethod(GET) + .withTarget(RequestTarget(uriString = "", path = definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) When("a GET request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -79,7 +83,9 @@ class SubscriptionFieldDefinitionsHappySpec extends AcceptanceTestSpec scenario("the API is called to GET all fields definitions") { Given("a request for all fields definition") - val request = ValidRequest.copyFakeRequest(method = GET, uri = allDefinitionsEndpoint) + val request = ValidRequest + .withMethod(GET) + .withTarget(RequestTarget(uriString = allDefinitionsEndpoint, path = allDefinitionsEndpoint, queryString = Map.empty)) When("a GET request is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -100,8 +106,8 @@ class SubscriptionFieldDefinitionsHappySpec extends AcceptanceTestSpec scenario("the API is called to update some existing fields definitions") { Given("a request with valid payload") - val request = validDefinitionPutRequest(Seq.empty) - .copyFakeRequest(method = PUT, uri = definitionEndpoint(fakeRawContext, fakeRawVersion)) + val request = validDefinitionPutRequest(Seq.empty) + .withTarget( RequestTarget(uriString="", path=definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) When("a PUT request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -122,8 +128,9 @@ class SubscriptionFieldDefinitionsHappySpec extends AcceptanceTestSpec scenario("the API is called to delete some existing fields definitions") { Given("a request with valid payload") - val request = validDefinitionPutRequest(Seq.empty) - .copyFakeRequest(method = DELETE, uri = definitionEndpoint(fakeRawContext, fakeRawVersion)) + val request = ValidRequest + .withMethod(DELETE) + .withTarget( RequestTarget(uriString="", path=definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) When("a DELETE request sent to the API") val result: Option[Future[Result]] = route(app, request) diff --git a/test/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/SubscriptionFieldDefinitionsUnhappySpec.scala b/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/SubscriptionFieldDefinitionsUnhappySpec.scala similarity index 82% rename from test/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/SubscriptionFieldDefinitionsUnhappySpec.scala rename to acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/SubscriptionFieldDefinitionsUnhappySpec.scala index db0d78e..2900ebd 100644 --- a/test/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/SubscriptionFieldDefinitionsUnhappySpec.scala +++ b/acceptance/uk/gov/hmrc/apisubscriptionfields/acceptance/SubscriptionFieldDefinitionsUnhappySpec.scala @@ -19,10 +19,11 @@ package uk.gov.hmrc.apisubscriptionfields.acceptance import org.scalatest.OptionValues import play.api.libs.json.Json import play.api.mvc._ +import play.api.mvc.request.RequestTarget import play.api.test.Helpers._ +import uk.gov.hmrc.apisubscriptionfields.SubscriptionFieldsTestData import uk.gov.hmrc.apisubscriptionfields.model.ErrorCode.{INVALID_REQUEST_PAYLOAD, NOT_FOUND_CODE} import uk.gov.hmrc.apisubscriptionfields.model.JsErrorResponse -import uk.gov.hmrc.apisubscriptionfields.util.SubscriptionFieldsTestData import scala.concurrent.Future @@ -34,7 +35,7 @@ class SubscriptionFieldDefinitionsUnhappySpec extends AcceptanceTestSpec scenario("the API is called to GET an unknown fields definition") { Given("the API is called to GET an unknown fields definition") - val request = ValidRequest.copyFakeRequest(method = GET, uri = definitionEndpoint(fakeRawContext, "unknown")) + val request = ValidRequest.withTarget(RequestTarget(uriString = "", path = definitionEndpoint(fakeRawContext, "unknown"), queryString = Map.empty)) When("a GET request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -53,7 +54,9 @@ class SubscriptionFieldDefinitionsUnhappySpec extends AcceptanceTestSpec Given("the API is called to PUT a fields definition with an invalid JSON payload") val request = ValidRequest - .copyFakeRequest(method = PUT, uri = definitionEndpoint(fakeRawContext, fakeRawVersion), body = Json.parse("{}")) + .withMethod(PUT) + .withTarget(RequestTarget(uriString = "", path = definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) + .withJsonBody(Json.parse("{}")) When("a PUT request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -83,9 +86,13 @@ class SubscriptionFieldDefinitionsUnhappySpec extends AcceptanceTestSpec |""".stripMargin Given("the API is called to PUT a fields definition with an invalid JSON payload") - val request = ValidRequest.copyFakeRequest(method = PUT, uri = definitionEndpoint(fakeRawContext, fakeRawVersion)) + + val request = ValidRequest + .withMethod(PUT) + .withTarget(RequestTarget(uriString = "", path = definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) .withJsonBody(Json.parse(invalidFieldDefinition)) + When("a PUT request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -102,8 +109,11 @@ class SubscriptionFieldDefinitionsUnhappySpec extends AcceptanceTestSpec scenario("the API is called to PUT a fields definition with an invalid non JSON payload") { Given("the API is called to PUT a fields definition with an invalid non JSON payload") + val request = ValidRequest - .copyFakeRequest(method = PUT, uri = definitionEndpoint(fakeRawContext, fakeRawVersion), body = InvalidNonJsonPayload) + .withMethod(PUT) + .withTarget(RequestTarget(uriString = "", path = definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) + .withBody(InvalidNonJsonPayload) When("a PUT request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -121,8 +131,11 @@ class SubscriptionFieldDefinitionsUnhappySpec extends AcceptanceTestSpec scenario("the API is called to DELETE an unknown fields definition") { Given("a request with an unknown fields definition") + val request = ValidRequest - .copyFakeRequest(method = DELETE, uri = definitionEndpoint(fakeRawContext, "unknown")) + .withMethod(DELETE) + .withTarget(RequestTarget(uriString = "", path = definitionEndpoint(fakeRawContext, "unknown"), queryString = Map.empty)) + When("a GET request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) diff --git a/app/uk/gov/hmrc/apisubscriptionfields/controller/CommonController.scala b/app/uk/gov/hmrc/apisubscriptionfields/controller/CommonController.scala index 3b93b54..32ee1e7 100644 --- a/app/uk/gov/hmrc/apisubscriptionfields/controller/CommonController.scala +++ b/app/uk/gov/hmrc/apisubscriptionfields/controller/CommonController.scala @@ -21,12 +21,12 @@ import play.api.libs.json._ import play.api.mvc.{Request, Result} import uk.gov.hmrc.apisubscriptionfields.model.ErrorCode._ import uk.gov.hmrc.apisubscriptionfields.model.JsErrorResponse -import uk.gov.hmrc.play.bootstrap.controller.BaseController +import uk.gov.hmrc.play.bootstrap.controller.BackendBaseController import scala.concurrent.Future import scala.util.{Failure, Success, Try} -trait CommonController extends BaseController { +trait CommonController extends BackendBaseController { override protected def withJsonBody[T] (f: (T) => Future[Result])(implicit request: Request[JsValue], m: Manifest[T], reads: Reads[T]): Future[Result] = { diff --git a/app/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionController.scala b/app/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionController.scala index bdffbf1..607d07a 100644 --- a/app/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionController.scala +++ b/app/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionController.scala @@ -27,7 +27,7 @@ import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future @Singleton -class FieldsDefinitionController @Inject() (service: FieldsDefinitionService) extends CommonController { +class FieldsDefinitionController @Inject() (cc: ControllerComponents, service: FieldsDefinitionService) extends CommonController { import JsonFormatters._ @@ -67,4 +67,6 @@ class FieldsDefinitionController @Inject() (service: FieldsDefinitionService) ex case None => notFoundResponse(rawApiContext, rawApiVersion) } recover recovery } + + override protected def controllerComponents: ControllerComponents = cc } diff --git a/app/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsController.scala b/app/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsController.scala index 0a57058..b8397f3 100644 --- a/app/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsController.scala +++ b/app/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsController.scala @@ -29,7 +29,7 @@ import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future @Singleton -class SubscriptionFieldsController @Inject()(service: SubscriptionFieldsService) extends CommonController { +class SubscriptionFieldsController @Inject()(cc: ControllerComponents, service: SubscriptionFieldsService) extends CommonController { import JsonFormatters._ @@ -107,4 +107,5 @@ class SubscriptionFieldsController @Inject()(service: SubscriptionFieldsService) } recover recovery } + override protected def controllerComponents: ControllerComponents = cc } diff --git a/app/uk/gov/hmrc/apisubscriptionfields/repository/MongoDb.scala b/app/uk/gov/hmrc/apisubscriptionfields/repository/MongoDb.scala index c69a318..b2867e2 100644 --- a/app/uk/gov/hmrc/apisubscriptionfields/repository/MongoDb.scala +++ b/app/uk/gov/hmrc/apisubscriptionfields/repository/MongoDb.scala @@ -16,10 +16,9 @@ package uk.gov.hmrc.apisubscriptionfields.repository -import javax.inject.Singleton - import com.google.inject.ImplementedBy -import play.modules.reactivemongo.MongoDbConnection +import javax.inject.{Inject, Singleton} +import play.modules.reactivemongo.ReactiveMongoComponent import reactivemongo.api.DB @ImplementedBy(classOf[MongoDb]) @@ -28,6 +27,6 @@ trait MongoDbProvider { } @Singleton -class MongoDb extends MongoDbConnection with MongoDbProvider { - override val mongo: () => DB = db +class MongoDb @Inject()(component: ReactiveMongoComponent) extends MongoDbProvider { + override val mongo: () => DB = component.mongoConnector.db } diff --git a/build.sbt b/build.sbt index 100f15a..c0cea21 100644 --- a/build.sbt +++ b/build.sbt @@ -14,8 +14,7 @@ * limitations under the License. */ -import sbt.Keys._ -import sbt.Tests.{Group, SubProcess} +import sbt.Keys.{parallelExecution, _} import sbt._ import uk.gov.hmrc.DefaultBuildSettings.{addTestReportOption, defaultSettings, scalaSettings} import uk.gov.hmrc.SbtAutoBuildPlugin @@ -26,73 +25,77 @@ import uk.gov.hmrc.versioning.SbtGitVersioning import scala.language.postfixOps val compile = Seq( - "uk.gov.hmrc" %% "bootstrap-play-25" % "5.1.0", - "uk.gov.hmrc" %% "simple-reactivemongo" % "7.22.0-play-25" + "uk.gov.hmrc" %% "bootstrap-play-26" % "1.4.0", + "uk.gov.hmrc" %% "simple-reactivemongo" % "7.22.0-play-26" ) -val overrides = Seq( - "org.reactivemongo" %% "reactivemongo" % "0.16.6" +// we need to override the akka version for now as newer versions are not compatible with reactivemongo +lazy val akkaVersion = "2.5.23" +lazy val akkaHttpVersion = "10.0.15" + +val overrides: Seq[ModuleID] = Seq( + "com.typesafe.akka" %% "akka-stream" % akkaVersion, + "com.typesafe.akka" %% "akka-protobuf" % akkaVersion, + "com.typesafe.akka" %% "akka-slf4j" % akkaVersion, + "com.typesafe.akka" %% "akka-actor" % akkaVersion, + "com.typesafe.akka" %% "akka-http-core" % akkaHttpVersion ) def test(scope: String = "test,acceptance") = Seq( - "uk.gov.hmrc" %% "hmrctest" % "3.9.0-play-25" % scope, - "uk.gov.hmrc" %% "reactivemongo-test" % "4.15.0-play-25" % scope, + "uk.gov.hmrc" %% "hmrctest" % "3.9.0-play-26" % scope, + "uk.gov.hmrc" %% "reactivemongo-test" % "4.16.0-play-26" % scope, "org.scalamock" %% "scalamock-scalatest-support" % "3.6.0" % scope, - "org.scalatest" %% "scalatest" % "3.0.4" % scope, - "org.scalatestplus.play" %% "scalatestplus-play" % "2.0.1" % scope, + "org.scalatest" %% "scalatest" % "3.0.5" % scope, + "org.scalatestplus.play" %% "scalatestplus-play" % "3.1.2" % scope, "org.pegdown" % "pegdown" % "1.6.0" % scope, - "com.github.tomakehurst" % "wiremock" % "2.11.0" % scope, "com.typesafe.play" %% "play-test" % play.core.PlayVersion.current % scope, - "org.mockito" % "mockito-core" % "1.9.5" % "test" + "org.mockito" % "mockito-core" % "1.10.19" % "test" ) val appName = "api-subscription-fields" -lazy val appDependencies: Seq[ModuleID] = compile ++ overrides ++ test() +lazy val appDependencies: Seq[ModuleID] = compile ++ test() resolvers ++= Seq(Resolver.bintrayRepo("hmrc", "releases"), Resolver.jcenterRepo) -lazy val plugins: Seq[Plugins] = Seq.empty +lazy val plugins: Seq[Plugins] = Seq(PlayScala, SbtAutoBuildPlugin, SbtGitVersioning, SbtDistributablesPlugin, SbtArtifactory) lazy val playSettings: Seq[Setting[_]] = Seq.empty -lazy val AcceptanceTest = config("acceptance") extend Test -val testConfig = Seq(AcceptanceTest, Test) +lazy val AcceptanceTest = config("acceptance") extend Test lazy val microservice = Project(appName, file(".")) - .enablePlugins(Seq(PlayScala, SbtAutoBuildPlugin, SbtGitVersioning, SbtDistributablesPlugin, SbtArtifactory) ++ plugins: _*) - .configs(testConfig: _*) + .enablePlugins(plugins: _*) + .configs(AcceptanceTest) .settings(playSettings: _*) .settings(scalaSettings: _*) .settings(publishingSettings: _*) .settings(defaultSettings(): _*) .settings(acceptanceTestSettings: _*) - .settings(scalaVersion := "2.11.11") + .settings(scalaVersion := "2.12.10") .settings( libraryDependencies ++= appDependencies, + dependencyOverrides ++= overrides, evictionWarningOptions in update := EvictionWarningOptions.default.withWarnScalaVersionEviction(false) ) .settings(scoverageSettings) .settings( - testOptions in Test := Seq(Tests.Filter(unitFilter), Tests.Argument("-eT")), fork in Test := false, - addTestReportOption(Test, "test-reports") + addTestReportOption(Test, "test-reports"), + parallelExecution in Test := false ) .settings(majorVersion := 0) lazy val acceptanceTestSettings = inConfig(AcceptanceTest)(Defaults.testSettings) ++ Seq( - testOptions in AcceptanceTest := Seq(Tests.Filter(acceptanceFilter)), - unmanagedSourceDirectories in AcceptanceTest := Seq( - baseDirectory.value / "test" / "acceptance", - baseDirectory.value / "test" / "util" - ), + unmanagedSourceDirectories in AcceptanceTest := Seq(baseDirectory.value / "acceptance"), fork in AcceptanceTest := false, parallelExecution in AcceptanceTest := false, addTestReportOption(AcceptanceTest, "acceptance-reports") ) + lazy val scoverageSettings: Seq[Setting[_]] = Seq( coverageExcludedPackages := ";Reverse.*;.*model.*;.*config.*;.*(AuthService|BuildInfo|Routes).*;.*.application;.*.definition", coverageMinimum := 97, @@ -101,18 +104,7 @@ lazy val scoverageSettings: Seq[Setting[_]] = Seq( parallelExecution in Test := false ) -def unitFilter(name: String): Boolean = !acceptanceFilter(name) -def acceptanceFilter(name: String): Boolean = name contains "acceptance" - -def oneForkedJvmPerTest(tests: Seq[TestDefinition]): Seq[Group] = - tests map { - test => Group(test.name, Seq(test), SubProcess(ForkOptions(runJVMOptions = Seq("-Dtest.name=" + test.name)))) - } -def forkedJvmPerTestConfig(tests: Seq[TestDefinition], packages: String*): Seq[Group] = - tests.groupBy(_.name.takeWhile(_ != '.')).filter(packageAndTests => packages contains packageAndTests._1) map { - case (packg, theTests) => Group(packg, theTests, SubProcess(ForkOptions())) - } toSeq def onPackageName(rootPackage: String): String => Boolean = { testName => testName startsWith rootPackage diff --git a/conf/app.routes b/conf/app.routes index 09b4c45..404941b 100644 --- a/conf/app.routes +++ b/conf/app.routes @@ -1,14 +1,14 @@ # microservice-specific routes -PUT /definition/context/:apiContext/version/:apiVersion @uk.gov.hmrc.apisubscriptionfields.controller.FieldsDefinitionController.upsertFieldsDefinition(apiContext: String, apiVersion: String) -GET /definition/context/:apiContext/version/:apiVersion @uk.gov.hmrc.apisubscriptionfields.controller.FieldsDefinitionController.getFieldsDefinition(apiContext: String, apiVersion: String) -GET /definition @uk.gov.hmrc.apisubscriptionfields.controller.FieldsDefinitionController.getAllFieldsDefinitions -DELETE /definition/context/:apiContext/version/:apiVersion @uk.gov.hmrc.apisubscriptionfields.controller.FieldsDefinitionController.deleteFieldsDefinition(apiContext: String, apiVersion: String) +PUT /definition/context/:apiContext/version/:apiVersion uk.gov.hmrc.apisubscriptionfields.controller.FieldsDefinitionController.upsertFieldsDefinition(apiContext: String, apiVersion: String) +GET /definition/context/:apiContext/version/:apiVersion uk.gov.hmrc.apisubscriptionfields.controller.FieldsDefinitionController.getFieldsDefinition(apiContext: String, apiVersion: String) +GET /definition uk.gov.hmrc.apisubscriptionfields.controller.FieldsDefinitionController.getAllFieldsDefinitions +DELETE /definition/context/:apiContext/version/:apiVersion uk.gov.hmrc.apisubscriptionfields.controller.FieldsDefinitionController.deleteFieldsDefinition(apiContext: String, apiVersion: String) -PUT /field/application/:clientId/context/:apiContext/version/:apiVersion @uk.gov.hmrc.apisubscriptionfields.controller.SubscriptionFieldsController.upsertSubscriptionFields(clientId: String, apiContext: String, apiVersion: String) -GET /field/application/:clientId/context/:apiContext/version/:apiVersion @uk.gov.hmrc.apisubscriptionfields.controller.SubscriptionFieldsController.getSubscriptionFields(clientId: String, apiContext: String, apiVersion: String) -GET /field/:fieldsId @uk.gov.hmrc.apisubscriptionfields.controller.SubscriptionFieldsController.getSubscriptionFieldsByFieldsId(fieldsId: java.util.UUID) -GET /field/application/:clientId @uk.gov.hmrc.apisubscriptionfields.controller.SubscriptionFieldsController.getBulkSubscriptionFieldsByClientId(clientId: String) -GET /field @uk.gov.hmrc.apisubscriptionfields.controller.SubscriptionFieldsController.getAllSubscriptionFields -DELETE /field/application/:clientId @uk.gov.hmrc.apisubscriptionfields.controller.SubscriptionFieldsController.deleteAllSubscriptionFieldsForClient(clientId: String) -DELETE /field/application/:clientId/context/:apiContext/version/:apiVersion @uk.gov.hmrc.apisubscriptionfields.controller.SubscriptionFieldsController.deleteSubscriptionFields(clientId: String, apiContext: String, apiVersion: String) +PUT /field/application/:clientId/context/:apiContext/version/:apiVersion uk.gov.hmrc.apisubscriptionfields.controller.SubscriptionFieldsController.upsertSubscriptionFields(clientId: String, apiContext: String, apiVersion: String) +GET /field/application/:clientId/context/:apiContext/version/:apiVersion uk.gov.hmrc.apisubscriptionfields.controller.SubscriptionFieldsController.getSubscriptionFields(clientId: String, apiContext: String, apiVersion: String) +GET /field/:fieldsId uk.gov.hmrc.apisubscriptionfields.controller.SubscriptionFieldsController.getSubscriptionFieldsByFieldsId(fieldsId: java.util.UUID) +GET /field/application/:clientId uk.gov.hmrc.apisubscriptionfields.controller.SubscriptionFieldsController.getBulkSubscriptionFieldsByClientId(clientId: String) +GET /field uk.gov.hmrc.apisubscriptionfields.controller.SubscriptionFieldsController.getAllSubscriptionFields +DELETE /field/application/:clientId uk.gov.hmrc.apisubscriptionfields.controller.SubscriptionFieldsController.deleteAllSubscriptionFieldsForClient(clientId: String) +DELETE /field/application/:clientId/context/:apiContext/version/:apiVersion uk.gov.hmrc.apisubscriptionfields.controller.SubscriptionFieldsController.deleteSubscriptionFields(clientId: String, apiContext: String, apiVersion: String) diff --git a/dependencyReport.py b/dependencyReport.py deleted file mode 100644 index ccf61fd..0000000 --- a/dependencyReport.py +++ /dev/null @@ -1,61 +0,0 @@ -import os, urllib, json -import requests -from sys import argv - -def fetchDependencies(repositoryName): - r = urllib.urlopen(os.environ['CATALOGUE_DEPENDENCIES_URL']) - j = json.load(r) - for i in range(len(j)): - if j[i]['repositoryName'] == repositoryName: - return j[i] - - return {} - -def findOutOfDateDependencies(dependencies): - outOfDateDependencies = [] - for i in range(len(dependencies)): - dependency = dependencies[i] - latestVersion = (dependency['latestVersion']['major'], - dependency['latestVersion']['minor'], - dependency['latestVersion']['patch']) - currentVersion = (dependency['currentVersion']['major'], - dependency['currentVersion']['minor'], - dependency['currentVersion']['patch']) - - if latestVersion > currentVersion: - outOfDateDependencies.append(dependency) - - return outOfDateDependencies - -def reportOnDependencies(dependencyType, dependencies): - print dependencyType + " needing upgrade:" - outOfDateDependencies = findOutOfDateDependencies(dependencies) - if len(outOfDateDependencies) > 0: - for i in range(len(outOfDateDependencies)): - dependency = outOfDateDependencies[i] - print ' \033[38;5;15m\033[48;5;1m{} {}.{}.{} -> {}.{}.{}\033[39;49m'.format( - dependency['name'], - dependency['currentVersion']['major'], - dependency['currentVersion']['minor'], - dependency['currentVersion']['patch'], - dependency['latestVersion']['major'], - dependency['latestVersion']['minor'], - dependency['latestVersion']['patch']) - else: - print '\033[38;5;2m No upgrades required\033[39;49m' - - -def generateReport(repositoryName): - print 'Generating dependency report...' - dependencies = fetchDependencies(repositoryName) - - reportOnDependencies('Libraries', dependencies['libraryDependencies']) - reportOnDependencies('SBT plugins', dependencies['sbtPluginsDependencies']) - reportOnDependencies('Other dependencies', dependencies['otherDependencies']) - - -if __name__ == "__main__": - if 'CATALOGUE_DEPENDENCIES_URL' in os.environ: - generateReport(argv[1]) - else: - print 'CATALOGUE_DEPENDENCIES_URL environment variable not set - cannot generate dependency report' diff --git a/project/build.properties b/project/build.properties index 133a8f1..a82bb05 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.17 +sbt.version=1.3.7 diff --git a/project/plugins.sbt b/project/plugins.sbt index 1e2c738..5496ee8 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -3,10 +3,10 @@ resolvers += "HMRC Releases" at "https://dl.bintray.com/hmrc/releases" resolvers += "Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases/" -addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "1.16.0") -addSbtPlugin("uk.gov.hmrc" % "sbt-git-versioning" % "1.19.0") -addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "1.6.0") -addSbtPlugin("uk.gov.hmrc" % "sbt-artifactory" % "0.20.0") -addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.19") -addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1") +addSbtPlugin("uk.gov.hmrc" %% "sbt-auto-build" % "2.6.0") +addSbtPlugin("uk.gov.hmrc" %% "sbt-git-versioning" % "2.1.0") +addSbtPlugin("uk.gov.hmrc" %% "sbt-distributables" % "2.0.0") +addSbtPlugin("org.scoverage" %% "sbt-scoverage" % "1.5.1") addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") +addSbtPlugin("com.typesafe.play" %% "sbt-plugin" % "2.6.24") +addSbtPlugin("uk.gov.hmrc" %% "sbt-artifactory" % "1.0.0") \ No newline at end of file diff --git a/run_all_tests.sh b/run_all_tests.sh index f1efbe8..d93dcfc 100755 --- a/run_all_tests.sh +++ b/run_all_tests.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash sbt clean coverage test acceptance:test coverageReport -python dependencyReport.py api-subscription-fields diff --git a/test/util/uk/gov/hmrc/apisubscriptionfields/util/TestData.scala b/test/uk/gov/hmrc/apisubscriptionfields/TestData.scala similarity index 98% rename from test/util/uk/gov/hmrc/apisubscriptionfields/util/TestData.scala rename to test/uk/gov/hmrc/apisubscriptionfields/TestData.scala index 89199e5..2ce5a54 100644 --- a/test/util/uk/gov/hmrc/apisubscriptionfields/util/TestData.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/TestData.scala @@ -14,7 +14,7 @@ * limitations under the License. */ -package uk.gov.hmrc.apisubscriptionfields.util +package uk.gov.hmrc.apisubscriptionfields import java.util.UUID diff --git a/test/unit/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerDeleteSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerDeleteSpec.scala similarity index 85% rename from test/unit/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerDeleteSpec.scala rename to test/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerDeleteSpec.scala index e7211a6..6909071 100644 --- a/test/unit/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerDeleteSpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerDeleteSpec.scala @@ -18,19 +18,19 @@ package uk.gov.hmrc.apisubscriptionfields.controller import org.scalamock.scalatest.MockFactory import play.api.libs.json.{JsDefined, JsString} -import play.api.test.FakeRequest +import play.api.test.{FakeRequest, StubControllerComponentsFactory} import play.api.test.Helpers._ +import uk.gov.hmrc.apisubscriptionfields.FieldsDefinitionTestData import uk.gov.hmrc.apisubscriptionfields.model.JsonFormatters import uk.gov.hmrc.apisubscriptionfields.service.FieldsDefinitionService import uk.gov.hmrc.play.test.UnitSpec -import uk.gov.hmrc.apisubscriptionfields.util.FieldsDefinitionTestData import scala.concurrent.Future -class FieldsDefinitionControllerDeleteSpec extends UnitSpec with FieldsDefinitionTestData with MockFactory with JsonFormatters { +class FieldsDefinitionControllerDeleteSpec extends UnitSpec with FieldsDefinitionTestData with MockFactory with JsonFormatters with StubControllerComponentsFactory { private val mockFieldsDefinitionService = mock[FieldsDefinitionService] - private val controller = new FieldsDefinitionController(mockFieldsDefinitionService) + private val controller = new FieldsDefinitionController(stubControllerComponents(), mockFieldsDefinitionService) "DELETE /definition/context/:apiContext/version/:apiVersion" should { "return NO_CONTENT (204) when successfully deleted from repo" in { diff --git a/test/unit/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerGetSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerGetSpec.scala similarity index 95% rename from test/unit/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerGetSpec.scala rename to test/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerGetSpec.scala index 442b402..8bfbcc0 100644 --- a/test/unit/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerGetSpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerGetSpec.scala @@ -20,17 +20,17 @@ import org.scalamock.scalatest.MockFactory import play.api.libs.json.{JsDefined, JsString, Json} import play.api.test.Helpers._ import play.api.test._ +import uk.gov.hmrc.apisubscriptionfields.FieldsDefinitionTestData import uk.gov.hmrc.apisubscriptionfields.model.{BulkFieldsDefinitionsResponse, FieldsDefinitionResponse, JsonFormatters} import uk.gov.hmrc.apisubscriptionfields.service.FieldsDefinitionService import uk.gov.hmrc.play.test.UnitSpec -import uk.gov.hmrc.apisubscriptionfields.util.FieldsDefinitionTestData import scala.concurrent.Future -class FieldsDefinitionControllerGetSpec extends UnitSpec with FieldsDefinitionTestData with MockFactory with JsonFormatters { +class FieldsDefinitionControllerGetSpec extends UnitSpec with FieldsDefinitionTestData with MockFactory with JsonFormatters with StubControllerComponentsFactory { private val mockFieldsDefinitionService = mock[FieldsDefinitionService] - private val controller = new FieldsDefinitionController(mockFieldsDefinitionService) + private val controller = new FieldsDefinitionController(stubControllerComponents(), mockFieldsDefinitionService) private val responseJsonString = """{ diff --git a/test/unit/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerPutSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerPutSpec.scala similarity index 92% rename from test/unit/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerPutSpec.scala rename to test/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerPutSpec.scala index 92df065..6c05221 100644 --- a/test/unit/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerPutSpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/controller/FieldsDefinitionControllerPutSpec.scala @@ -21,20 +21,21 @@ import play.api.libs.json.{JsValue, Json} import play.api.mvc._ import play.api.test.Helpers._ import play.api.test._ +import uk.gov.hmrc.apisubscriptionfields.FieldsDefinitionTestData import uk.gov.hmrc.apisubscriptionfields.model.{FieldsDefinitionRequest, JsonFormatters} import uk.gov.hmrc.apisubscriptionfields.service.FieldsDefinitionService import uk.gov.hmrc.play.test.UnitSpec -import uk.gov.hmrc.apisubscriptionfields.util.FieldsDefinitionTestData import scala.concurrent.Future class FieldsDefinitionControllerPutSpec extends UnitSpec with FieldsDefinitionTestData with MockFactory - with JsonFormatters { + with JsonFormatters + with StubControllerComponentsFactory { private val mockFieldsDefinitionService = mock[FieldsDefinitionService] - private val controller = new FieldsDefinitionController(mockFieldsDefinitionService) + private val controller = new FieldsDefinitionController(stubControllerComponents(), mockFieldsDefinitionService) "PUT /definition/context/:apiContext/version/:apiVersion" should { "return CREATED when created in the repo" in { diff --git a/test/unit/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerDeleteSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerDeleteSpec.scala similarity index 91% rename from test/unit/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerDeleteSpec.scala rename to test/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerDeleteSpec.scala index cf4a0ae..d552094 100644 --- a/test/unit/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerDeleteSpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerDeleteSpec.scala @@ -18,19 +18,19 @@ package uk.gov.hmrc.apisubscriptionfields.controller import org.scalamock.scalatest.MockFactory import play.api.libs.json.{JsDefined, JsString} -import play.api.test.FakeRequest +import play.api.test.{FakeRequest, StubControllerComponentsFactory} import play.api.test.Helpers._ +import uk.gov.hmrc.apisubscriptionfields.SubscriptionFieldsTestData import uk.gov.hmrc.apisubscriptionfields.model.{ApiContext, ApiVersion, ClientId, JsonFormatters} import uk.gov.hmrc.apisubscriptionfields.service.SubscriptionFieldsService import uk.gov.hmrc.play.test.UnitSpec -import uk.gov.hmrc.apisubscriptionfields.util.SubscriptionFieldsTestData import scala.concurrent.Future -class SubscriptionFieldsControllerDeleteSpec extends UnitSpec with SubscriptionFieldsTestData with MockFactory with JsonFormatters { +class SubscriptionFieldsControllerDeleteSpec extends UnitSpec with SubscriptionFieldsTestData with MockFactory with JsonFormatters with StubControllerComponentsFactory { private val mockSubscriptionFieldsService = mock[SubscriptionFieldsService] - private val controller = new SubscriptionFieldsController(mockSubscriptionFieldsService) + private val controller = new SubscriptionFieldsController(stubControllerComponents(), mockSubscriptionFieldsService) "DELETE /field/application/:clientId/context/:apiContext/version/:apiVersion" should { "return NO_CONTENT (204) when successfully deleted from repo" in { diff --git a/test/unit/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerGetSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerGetSpec.scala similarity index 95% rename from test/unit/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerGetSpec.scala rename to test/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerGetSpec.scala index 94be54f..3bd04ce 100644 --- a/test/unit/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerGetSpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerGetSpec.scala @@ -21,17 +21,17 @@ import play.api.libs.json.{JsDefined, JsString, Json} import play.api.mvc._ import play.api.test.Helpers._ import play.api.test._ -import uk.gov.hmrc.apisubscriptionfields.model._ +import uk.gov.hmrc.apisubscriptionfields.SubscriptionFieldsTestData +import uk.gov.hmrc.apisubscriptionfields.model.{ApiContext, ApiVersion, BulkSubscriptionFieldsResponse, ClientId, JsonFormatters, SubscriptionFieldsId, SubscriptionFieldsResponse} import uk.gov.hmrc.apisubscriptionfields.service.SubscriptionFieldsService -import uk.gov.hmrc.apisubscriptionfields.util.SubscriptionFieldsTestData import uk.gov.hmrc.play.test.UnitSpec import scala.concurrent.Future -class SubscriptionFieldsControllerGetSpec extends UnitSpec with SubscriptionFieldsTestData with MockFactory with JsonFormatters { +class SubscriptionFieldsControllerGetSpec extends UnitSpec with SubscriptionFieldsTestData with MockFactory with JsonFormatters with StubControllerComponentsFactory { private val mockSubscriptionFieldsService = mock[SubscriptionFieldsService] - private val controller = new SubscriptionFieldsController(mockSubscriptionFieldsService) + private val controller = new SubscriptionFieldsController(stubControllerComponents(), mockSubscriptionFieldsService) private val responseJsonString = """{ diff --git a/test/unit/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerPutSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerPutSpec.scala similarity index 85% rename from test/unit/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerPutSpec.scala rename to test/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerPutSpec.scala index 6edef8c..6893b84 100644 --- a/test/unit/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerPutSpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsControllerPutSpec.scala @@ -19,22 +19,23 @@ package uk.gov.hmrc.apisubscriptionfields.controller import org.scalamock.scalatest.MockFactory import play.api.libs.json.{JsValue, Json} import play.api.mvc._ -import play.api.test.FakeRequest +import play.api.test.{FakeRequest, StubControllerComponentsFactory} import play.api.test.Helpers._ -import uk.gov.hmrc.apisubscriptionfields.model._ +import uk.gov.hmrc.apisubscriptionfields.SubscriptionFieldsTestData +import uk.gov.hmrc.apisubscriptionfields.model.{ApiContext, ApiVersion, ClientId, Fields, JsonFormatters, SubscriptionFieldsRequest} import uk.gov.hmrc.apisubscriptionfields.service.SubscriptionFieldsService import uk.gov.hmrc.play.test.UnitSpec -import uk.gov.hmrc.apisubscriptionfields.util.SubscriptionFieldsTestData import scala.concurrent.Future class SubscriptionFieldsControllerPutSpec extends UnitSpec with SubscriptionFieldsTestData with MockFactory - with JsonFormatters { + with JsonFormatters + with StubControllerComponentsFactory { private val mockSubscriptionFieldsService = mock[SubscriptionFieldsService] - private val controller = new SubscriptionFieldsController(mockSubscriptionFieldsService) + private val controller = new SubscriptionFieldsController(stubControllerComponents(), mockSubscriptionFieldsService) "PUT /field/application/:clientId/context/:apiContext/version/:apiVersion" should { "return CREATED when created in the repo" in { diff --git a/test/unit/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatterSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatterSpec.scala similarity index 97% rename from test/unit/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatterSpec.scala rename to test/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatterSpec.scala index 98e0027..11720f5 100644 --- a/test/unit/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatterSpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatterSpec.scala @@ -17,7 +17,7 @@ package uk.gov.hmrc.apisubscriptionfields.model import org.scalatest.{Matchers, WordSpec} -import uk.gov.hmrc.apisubscriptionfields.util.{FieldsDefinitionTestData, SubscriptionFieldsTestData} +import uk.gov.hmrc.apisubscriptionfields.{FieldsDefinitionTestData, SubscriptionFieldsTestData} class JsonFormatterSpec extends WordSpec with Matchers diff --git a/test/unit/uk/gov/hmrc/apisubscriptionfields/repository/FieldsDefinitionRepositorySpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/repository/FieldsDefinitionRepositorySpec.scala similarity index 98% rename from test/unit/uk/gov/hmrc/apisubscriptionfields/repository/FieldsDefinitionRepositorySpec.scala rename to test/uk/gov/hmrc/apisubscriptionfields/repository/FieldsDefinitionRepositorySpec.scala index 33c0b1a..ffbfc0e 100644 --- a/test/unit/uk/gov/hmrc/apisubscriptionfields/repository/FieldsDefinitionRepositorySpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/repository/FieldsDefinitionRepositorySpec.scala @@ -21,7 +21,7 @@ import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach} import reactivemongo.api.DB import reactivemongo.bson.BSONDocument import uk.gov.hmrc.apisubscriptionfields.model.{ApiContext, ApiVersion, JsonFormatters} -import uk.gov.hmrc.apisubscriptionfields.util.FieldsDefinitionTestData +import uk.gov.hmrc.apisubscriptionfields.FieldsDefinitionTestData import uk.gov.hmrc.mongo.MongoSpecSupport import uk.gov.hmrc.play.test.UnitSpec diff --git a/test/unit/uk/gov/hmrc/apisubscriptionfields/repository/MongoErrorHandlerSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/repository/MongoErrorHandlerSpec.scala similarity index 100% rename from test/unit/uk/gov/hmrc/apisubscriptionfields/repository/MongoErrorHandlerSpec.scala rename to test/uk/gov/hmrc/apisubscriptionfields/repository/MongoErrorHandlerSpec.scala diff --git a/test/unit/uk/gov/hmrc/apisubscriptionfields/repository/MongoFormattersSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/repository/MongoFormattersSpec.scala similarity index 100% rename from test/unit/uk/gov/hmrc/apisubscriptionfields/repository/MongoFormattersSpec.scala rename to test/uk/gov/hmrc/apisubscriptionfields/repository/MongoFormattersSpec.scala diff --git a/test/unit/uk/gov/hmrc/apisubscriptionfields/repository/SubscriptionFieldsRepositorySpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/repository/SubscriptionFieldsRepositorySpec.scala similarity index 99% rename from test/unit/uk/gov/hmrc/apisubscriptionfields/repository/SubscriptionFieldsRepositorySpec.scala rename to test/uk/gov/hmrc/apisubscriptionfields/repository/SubscriptionFieldsRepositorySpec.scala index ca6b137..61221df 100644 --- a/test/unit/uk/gov/hmrc/apisubscriptionfields/repository/SubscriptionFieldsRepositorySpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/repository/SubscriptionFieldsRepositorySpec.scala @@ -23,7 +23,7 @@ import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach} import reactivemongo.api.DB import reactivemongo.bson._ import uk.gov.hmrc.apisubscriptionfields.model._ -import uk.gov.hmrc.apisubscriptionfields.util.SubscriptionFieldsTestData +import uk.gov.hmrc.apisubscriptionfields.SubscriptionFieldsTestData import uk.gov.hmrc.mongo.MongoSpecSupport import uk.gov.hmrc.play.test.UnitSpec diff --git a/test/unit/uk/gov/hmrc/apisubscriptionfields/service/FieldsDefinitionServiceSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/service/FieldsDefinitionServiceSpec.scala similarity index 95% rename from test/unit/uk/gov/hmrc/apisubscriptionfields/service/FieldsDefinitionServiceSpec.scala rename to test/uk/gov/hmrc/apisubscriptionfields/service/FieldsDefinitionServiceSpec.scala index f8dbb61..c066d2f 100644 --- a/test/unit/uk/gov/hmrc/apisubscriptionfields/service/FieldsDefinitionServiceSpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/service/FieldsDefinitionServiceSpec.scala @@ -17,9 +17,9 @@ package uk.gov.hmrc.apisubscriptionfields.service import org.scalamock.scalatest.MockFactory -import uk.gov.hmrc.apisubscriptionfields.model._ +import uk.gov.hmrc.apisubscriptionfields.FieldsDefinitionTestData +import uk.gov.hmrc.apisubscriptionfields.model.{ApiContext, ApiVersion, BulkFieldsDefinitionsResponse, FieldsDefinitionResponse} import uk.gov.hmrc.apisubscriptionfields.repository.{FieldsDefinition, FieldsDefinitionRepository} -import uk.gov.hmrc.apisubscriptionfields.util.FieldsDefinitionTestData import uk.gov.hmrc.play.test.UnitSpec import scala.concurrent.Future diff --git a/test/unit/uk/gov/hmrc/apisubscriptionfields/service/SubscriptionFieldsServiceSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/service/SubscriptionFieldsServiceSpec.scala similarity index 98% rename from test/unit/uk/gov/hmrc/apisubscriptionfields/service/SubscriptionFieldsServiceSpec.scala rename to test/uk/gov/hmrc/apisubscriptionfields/service/SubscriptionFieldsServiceSpec.scala index 49f298f..e98739e 100644 --- a/test/unit/uk/gov/hmrc/apisubscriptionfields/service/SubscriptionFieldsServiceSpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/service/SubscriptionFieldsServiceSpec.scala @@ -21,7 +21,7 @@ import java.util.UUID import org.scalamock.scalatest.MockFactory import uk.gov.hmrc.apisubscriptionfields.model._ import uk.gov.hmrc.apisubscriptionfields.repository._ -import uk.gov.hmrc.apisubscriptionfields.util.SubscriptionFieldsTestData +import uk.gov.hmrc.apisubscriptionfields.SubscriptionFieldsTestData import uk.gov.hmrc.play.test.UnitSpec import scala.concurrent.Future diff --git a/test/util/uk/gov/hmrc/apisubscriptionfields/util/WireMockRunner.scala b/test/util/uk/gov/hmrc/apisubscriptionfields/util/WireMockRunner.scala deleted file mode 100644 index 5cb867c..0000000 --- a/test/util/uk/gov/hmrc/apisubscriptionfields/util/WireMockRunner.scala +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2020 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.gov.hmrc.apisubscriptionfields.util - -import com.github.tomakehurst.wiremock.WireMockServer -import com.github.tomakehurst.wiremock.client.WireMock -import com.github.tomakehurst.wiremock.core.WireMockConfiguration._ -import uk.gov.hmrc.apisubscriptionfields.util.ExternalServicesConfig._ - -trait WireMockRunner { - - lazy val wireMockUrl = s"http://$Host:$Port" - lazy val wireMockServer = new WireMockServer(wireMockConfig().port(Port)) - - def startMockServer() { - if (!wireMockServer.isRunning) wireMockServer.start() - WireMock.configureFor(Host, Port) - } - - def resetMockServer() { - WireMock.reset() - } - - def stopMockServer() { - wireMockServer.stop() - } -} \ No newline at end of file