From 4c2f815597a32cb315c8f92bcfca4953b7d1a222 Mon Sep 17 00:00:00 2001 From: Darren Walker <9861667+FluentSynergyDW@users.noreply.github.com> Date: Wed, 24 Apr 2019 15:02:45 +0100 Subject: [PATCH 1/3] APIS-4348 Removed service-locator registration. --- .../config/ConfigurationProviders.scala | 28 ---------- .../config/ServiceLocatorRegistration.scala | 41 --------------- .../connector/ServiceLocatorConnector.scala | 51 ------------------- .../models/Registration.scala | 25 --------- conf/application.conf | 13 ----- .../uk/gov/hmrc/PlatformIntegrationSpec.scala | 39 ++------------ 6 files changed, 5 insertions(+), 192 deletions(-) delete mode 100644 app/uk/gov/hmrc/thirdpartyapplication/config/ServiceLocatorRegistration.scala delete mode 100644 app/uk/gov/hmrc/thirdpartyapplication/connector/ServiceLocatorConnector.scala delete mode 100644 app/uk/gov/hmrc/thirdpartyapplication/models/Registration.scala diff --git a/app/uk/gov/hmrc/thirdpartyapplication/config/ConfigurationProviders.scala b/app/uk/gov/hmrc/thirdpartyapplication/config/ConfigurationProviders.scala index eae24cb03..98bd7eecb 100644 --- a/app/uk/gov/hmrc/thirdpartyapplication/config/ConfigurationProviders.scala +++ b/app/uk/gov/hmrc/thirdpartyapplication/config/ConfigurationProviders.scala @@ -36,8 +36,6 @@ class ConfigurationModule extends Module { override def bindings(environment: Environment, configuration: Configuration): Seq[Binding[_]] = { Seq( - bind[ServiceLocatorRegistrationConfig].toProvider[ServiceLocatorRegistrationConfigProvider], - bind[ServiceLocatorConfig].toProvider[ServiceLocatorConfigProvider], bind[DocumentationConfig].toProvider[DocumentationConfigProvider], bind[RefreshSubscriptionsJobConfig].toProvider[RefreshSubscriptionsJobConfigProvider], bind[UpliftVerificationExpiryJobConfig].toProvider[UpliftVerificationExpiryJobConfigProvider], @@ -63,32 +61,6 @@ object ConfigHelper { } } -@Singleton -class ServiceLocatorRegistrationConfigProvider @Inject()(val runModeConfiguration: Configuration, environment: Environment) - extends Provider[ServiceLocatorRegistrationConfig] with ServicesConfig { - - override protected def mode = environment.mode - - override def get() = { - val registrationEnabled = getConfBool("service-locator.enabled", defBool = true) - ServiceLocatorRegistrationConfig(registrationEnabled) - } -} - -@Singleton -class ServiceLocatorConfigProvider @Inject()(val runModeConfiguration: Configuration, environment: Environment) - extends Provider[ServiceLocatorConfig] with ServicesConfig { - - override protected def mode = environment.mode - - override def get() = { - val appName = getString("appName") - val appUrl = getString("appUrl") - val serviceLocatorBaseUrl = baseUrl("service-locator") - ServiceLocatorConfig(appName, appUrl, serviceLocatorBaseUrl) - } -} - @Singleton class DocumentationConfigProvider @Inject()(val runModeConfiguration: Configuration, environment: Environment) extends Provider[DocumentationConfig] with ServicesConfig { diff --git a/app/uk/gov/hmrc/thirdpartyapplication/config/ServiceLocatorRegistration.scala b/app/uk/gov/hmrc/thirdpartyapplication/config/ServiceLocatorRegistration.scala deleted file mode 100644 index 27013ace5..000000000 --- a/app/uk/gov/hmrc/thirdpartyapplication/config/ServiceLocatorRegistration.scala +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2019 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.thirdpartyapplication.config - -import com.google.inject.AbstractModule -import javax.inject.{Inject, Singleton} -import play.api.Logger -import uk.gov.hmrc.thirdpartyapplication.connector.ServiceLocatorConnector - -class ServiceLocatorRegistrationModule extends AbstractModule { - override def configure(): Unit = { - bind(classOf[ServiceLocatorRegistration]).asEagerSingleton() - } -} - -@Singleton -class ServiceLocatorRegistration @Inject()(config: ServiceLocatorRegistrationConfig, connector: ServiceLocatorConnector) { - - if (config.registrationEnabled) { - Logger.info(s"Service Locator registration is enabled") - connector.register() - } else { - Logger.info(s"Service Locator registration is disabled") - } -} - -case class ServiceLocatorRegistrationConfig(registrationEnabled: Boolean) diff --git a/app/uk/gov/hmrc/thirdpartyapplication/connector/ServiceLocatorConnector.scala b/app/uk/gov/hmrc/thirdpartyapplication/connector/ServiceLocatorConnector.scala deleted file mode 100644 index 0cf4ce6a8..000000000 --- a/app/uk/gov/hmrc/thirdpartyapplication/connector/ServiceLocatorConnector.scala +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2019 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.thirdpartyapplication.connector - -import javax.inject.Inject -import play.api.Logger -import play.api.http.ContentTypes.JSON -import play.api.http.HeaderNames.CONTENT_TYPE -import uk.gov.hmrc.thirdpartyapplication.models.Registration -import uk.gov.hmrc.http.HeaderCarrier -import uk.gov.hmrc.play.bootstrap.http.HttpClient - -import scala.concurrent.{ExecutionContext, Future} - -class ServiceLocatorConnector @Inject()(http: HttpClient, config: ServiceLocatorConfig)(implicit val ec: ExecutionContext) { - - def register(): Future[Boolean] = { - implicit val hc: HeaderCarrier = new HeaderCarrier - - val registration = Registration(config.appName, config.appUrl, Some(Map("third-party-api" -> "true"))) - - http.POST(s"${config.serviceLocatorBaseUrl}/registration", registration, Seq(CONTENT_TYPE -> JSON)) map { _ => - Logger.info("Service is registered on the service locator") - true - } recover { - case e: Throwable => - Logger.error("Service could not register on the service locator", e) - false - } - } -} - -case class ServiceLocatorConfig(appName: String, appUrl: String, serviceLocatorBaseUrl: String) - - - - diff --git a/app/uk/gov/hmrc/thirdpartyapplication/models/Registration.scala b/app/uk/gov/hmrc/thirdpartyapplication/models/Registration.scala deleted file mode 100644 index 4d297cd48..000000000 --- a/app/uk/gov/hmrc/thirdpartyapplication/models/Registration.scala +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2019 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.thirdpartyapplication.models - -import play.api.libs.json.Json - -case class Registration(serviceName: String, serviceUrl: String, metadata:Option[Map[String, String]] = None) - -object Registration { - implicit val format = Json.format[Registration] -} diff --git a/conf/application.conf b/conf/application.conf index d8bf2b81a..e06d9bcb1 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -15,7 +15,6 @@ include "backend.conf" appName = third-party-application -appUrl = "http://localhost:9607" # An ApplicationLoader that uses Guice to bootstrap the application. play.application.loader = "uk.gov.hmrc.play.bootstrap.ApplicationLoader" @@ -42,7 +41,6 @@ play.http.errorHandler = "uk.gov.hmrc.play.bootstrap.http.JsonErrorHandler" play.modules.enabled += "play.modules.reactivemongo.ReactiveMongoHmrcModule" play.modules.enabled += "uk.gov.hmrc.play.bootstrap.HttpClientModule" play.modules.enabled += "uk.gov.hmrc.thirdpartyapplication.config.ConfigurationModule" -play.modules.enabled += "uk.gov.hmrc.thirdpartyapplication.config.ServiceLocatorRegistrationModule" play.modules.enabled += "uk.gov.hmrc.thirdpartyapplication.config.SchedulerModule" play.modules.enabled += "uk.gov.hmrc.thirdpartyapplication.config.ApiStorageModule" @@ -221,11 +219,6 @@ Dev { port = 9988 } - service-locator { - host = localhost - port = 9602 - } - third-party-delegated-authority { protocol = https host = localhost @@ -309,12 +302,6 @@ Test { port = 22226 } - service-locator { - enabled = false - host = localhost - port = 9602 - } - third-party-delegated-authority { host = localhost port = 22228 diff --git a/test/it/uk/gov/hmrc/PlatformIntegrationSpec.scala b/test/it/uk/gov/hmrc/PlatformIntegrationSpec.scala index b1a574efd..c0c99caf4 100644 --- a/test/it/uk/gov/hmrc/PlatformIntegrationSpec.scala +++ b/test/it/uk/gov/hmrc/PlatformIntegrationSpec.scala @@ -16,15 +16,10 @@ package it.uk.gov.hmrc.thirdpartyapplication -import com.github.tomakehurst.wiremock.WireMockServer -import com.github.tomakehurst.wiremock.client.WireMock -import com.github.tomakehurst.wiremock.client.WireMock._ -import com.github.tomakehurst.wiremock.core.WireMockConfiguration._ import org.scalatest.concurrent.ScalaFutures import org.scalatest.mockito.MockitoSugar import org.scalatest.{BeforeAndAfterEach, TestData} import org.scalatestplus.play.guice.GuiceOneAppPerTest -import play.api.http.Status import play.api.inject.guice.GuiceApplicationBuilder import play.api.test.FakeRequest import play.api.{Application, Mode} @@ -34,50 +29,26 @@ import uk.gov.hmrc.thirdpartyapplication.controllers.DocumentationController /** * Testcase to verify the capability of integration with the API platform. * - * 1, To integrate with API platform the service needs to register itself to the service locator by calling the /registration endpoint and providing - * - application name - * - application url - * - * 2a, To expose API's to Third Party Developers, the service needs to make the API definition available under api/definition GET endpoint - * 2b, The endpoints need to be defined in an application.raml file for all versions For all of the endpoints defined documentation will be provided and be - * available under api/documentation/[version]/[endpoint name] GET endpoint + * 1a, To expose API's to Third Party Developers, the service needs to make the API definition available under api/definition GET endpoint + * 1b, The endpoints need to be defined in an application.raml file for all versions For all of the endpoints defined documentation will be provided and + * be available under api/documentation/[version]/[endpoint name] GET endpoint * Example: api/documentation/1.0/Fetch-Some-Data * + * See: https://confluence.tools.tax.service.gov.uk/display/ApiPlatform/API+Platform+Architecture+with+Flows */ - - trait PlatformIntegrationSpec extends UnitSpec with MockitoSugar with ScalaFutures with BeforeAndAfterEach with GuiceOneAppPerTest { implicit def mat: akka.stream.Materializer = app.injector.instanceOf[akka.stream.Materializer] val publishApiDefinition: Boolean - val stubHost = "localhost" - val stubPort = sys.env.getOrElse("WIREMOCK_SERVICE_LOCATOR_PORT", "11111").toInt - val wireMockServer = new WireMockServer(wireMockConfig().port(stubPort)) override def newAppForTest(testData: TestData): Application = GuiceApplicationBuilder() .configure("run.mode" -> "Stub") .configure(Map( - "appName" -> "application-name", - "appUrl" -> "http://microservice-name.example.local", "publishApiDefinition" -> publishApiDefinition, - "api.context" -> "test-api-context", - "Test.microservice.services.service-locator.host" -> stubHost, - "Test.microservice.services.service-locator.port" -> stubPort, - "Test.microservice.services.service-locator.enabled" -> true + "api.context" -> "test-api-context" )).in(Mode.Test).build() - override def beforeEach() { - wireMockServer.start() - WireMock.configureFor(stubHost, stubPort) - stubFor(post(urlMatching("/registration")).willReturn(aResponse().withStatus(Status.NO_CONTENT))) - } - - override protected def afterEach(): Unit = { - wireMockServer.stop() - wireMockServer.resetMappings() - } - trait Setup { val documentationController = app.injector.instanceOf[DocumentationController] val request = FakeRequest() From e7b448ca9f49cd0cf2acb9d54712307f14fd8c23 Mon Sep 17 00:00:00 2001 From: Darren Walker <9861667+FluentSynergyDW@users.noreply.github.com> Date: Wed, 24 Apr 2019 15:09:51 +0100 Subject: [PATCH 2/3] APIS-4348 Updated dependency versions. --- build.sbt | 11 +++++------ project/plugins.sbt | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/build.sbt b/build.sbt index 0809d7d66..4cc3fbc6a 100644 --- a/build.sbt +++ b/build.sbt @@ -11,16 +11,15 @@ lazy val appName = "third-party-application" lazy val appDependencies: Seq[ModuleID] = compile ++ test lazy val compile = Seq( - "uk.gov.hmrc" %% "bootstrap-play-25" % "4.9.0", + "uk.gov.hmrc" %% "bootstrap-play-25" % "4.11.0", "uk.gov.hmrc" %% "mongo-lock" % "6.12.0-play-25", - "uk.gov.hmrc" %% "simple-reactivemongo" % "7.16.0-play-25", - "uk.gov.hmrc" %% "play-scheduling" % "5.4.0", - "uk.gov.hmrc" %% "play-json-union-formatter" % "1.4.0", + "uk.gov.hmrc" %% "play-scheduling" % "6.0.0", + "uk.gov.hmrc" %% "play-json-union-formatter" % "1.5.0", "uk.gov.hmrc" %% "play-hmrc-api" % "3.4.0-play-25" ) lazy val test = Seq( - "uk.gov.hmrc" %% "reactivemongo-test" % "4.10.0-play-25" % "test,it", - "uk.gov.hmrc" %% "hmrctest" % "3.6.0-play-25" % "test,it", + "uk.gov.hmrc" %% "reactivemongo-test" % "4.13.0-play-25" % "test,it", + "uk.gov.hmrc" %% "hmrctest" % "3.8.0-play-25" % "test,it", "org.pegdown" % "pegdown" % "1.6.0" % "test,it", "org.scalaj" %% "scalaj-http" % "2.3.0" % "test,it", "org.scalatest" %% "scalatest" % "2.2.6" % "test,it", diff --git a/project/plugins.sbt b/project/plugins.sbt index 4ad8121e9..b61b44fa8 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -6,10 +6,10 @@ resolvers += Resolver.url("scoverage-bintray", url("https://dl.bintray.com/sksam resolvers += "Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases/" -addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "1.14.0") -addSbtPlugin("uk.gov.hmrc" % "sbt-git-versioning" % "1.16.0") -addSbtPlugin("uk.gov.hmrc" % "sbt-artifactory" % "0.17.0") -addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "1.3.0") +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-artifactory" % "0.19.0") +addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "1.5.0") addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.19") addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1") addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") From 12cd4b5489e3869f9e66f6b395fbe3a4655e4e49 Mon Sep 17 00:00:00 2001 From: Darren Walker <9861667+FluentSynergyDW@users.noreply.github.com> Date: Wed, 24 Apr 2019 15:13:50 +0100 Subject: [PATCH 3/3] APIS-4348 Addressed a couple of compiler warnings. --- build.sbt | 2 +- .../hmrc/thirdpartyapplication/helpers/AuthSpecHelpers.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index 4cc3fbc6a..6cd58fac1 100644 --- a/build.sbt +++ b/build.sbt @@ -59,7 +59,7 @@ lazy val microservice = (project in file(".")) .settings(inConfig(TemplateItTest)(Defaults.itSettings): _*) .settings( Keys.fork in IntegrationTest := false, - unmanagedSourceDirectories in IntegrationTest <<= (baseDirectory in IntegrationTest) (base => Seq(base / "test")), + unmanagedSourceDirectories in IntegrationTest := (baseDirectory in IntegrationTest) (base => Seq(base / "test")).value, addTestReportOption(IntegrationTest, "int-test-reports"), testGrouping in IntegrationTest := oneForkedJvmPerTest((definedTests in IntegrationTest).value), testOptions in IntegrationTest := Seq(Tests.Filter(itFilter), Tests.Argument(TestFrameworks.ScalaTest, "-eT")), diff --git a/test/unit/uk/gov/hmrc/thirdpartyapplication/helpers/AuthSpecHelpers.scala b/test/unit/uk/gov/hmrc/thirdpartyapplication/helpers/AuthSpecHelpers.scala index 4f54fc73d..a79943535 100644 --- a/test/unit/uk/gov/hmrc/thirdpartyapplication/helpers/AuthSpecHelpers.scala +++ b/test/unit/uk/gov/hmrc/thirdpartyapplication/helpers/AuthSpecHelpers.scala @@ -27,7 +27,7 @@ import scala.concurrent.{ExecutionContext, Future} object AuthSpecHelpers { def givenUserIsAuthenticated(underTest: AuthorisationWrapper) = { - when(underTest.authConnector.authorise(any, any[Retrieval[Any]])(any[HeaderCarrier], any[ExecutionContext])).thenReturn(Future.successful()) + when(underTest.authConnector.authorise(any, any[Retrieval[Any]])(any[HeaderCarrier], any[ExecutionContext])).thenReturn(Future.successful(())) } def givenUserIsNotAuthenticated(underTest: AuthorisationWrapper) = {