Skip to content

Commit

Permalink
API-7262 - rename connectors to names with transparency
Browse files Browse the repository at this point in the history
  • Loading branch information
anjumabbas5 committed Sep 26, 2024
1 parent 879cd3e commit 2bd2e0b
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ import play.api.inject.{Binding, Module}
import play.api.{Configuration, Environment}
import uk.gov.hmrc.play.bootstrap.config.ServicesConfig

import uk.gov.hmrc.apiplatforminboundsoap.connectors.OutboundConnector
import uk.gov.hmrc.apiplatforminboundsoap.connectors.ApiPlatformOutboundSoapConnector

class ConfigurationModule extends Module {

override def bindings(environment: Environment, configuration: Configuration): List[Binding[_]] = {

List(
bind[OutboundConnector.Config].toProvider[OutboundConnectorConfigProvider]
bind[ApiPlatformOutboundSoapConnector.Config].toProvider[ApiPlatformOutboundSoapConnectorConfigProvider]
)
}
}

@Singleton
class OutboundConnectorConfigProvider @Inject() (val configuration: Configuration)
class ApiPlatformOutboundSoapConnectorConfigProvider @Inject() (val configuration: Configuration)
extends ServicesConfig(configuration)
with Provider[OutboundConnector.Config] {
with Provider[ApiPlatformOutboundSoapConnector.Config] {

override def get(): OutboundConnector.Config = {
override def get(): ApiPlatformOutboundSoapConnector.Config = {
val url = baseUrl("api-platform-outbound-soap")
OutboundConnector.Config(url)
ApiPlatformOutboundSoapConnector.Config(url)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ import uk.gov.hmrc.http.{HeaderCarrier, HttpResponse, UpstreamErrorResponse}
import uk.gov.hmrc.apiplatforminboundsoap.models.{SendFail, SendResult, SendSuccess}
import uk.gov.hmrc.apiplatforminboundsoap.xml.XmlHelper

object OutboundConnector {
object ApiPlatformOutboundSoapConnector {
case class Config(baseUrl: String)
}

@Singleton
class OutboundConnector @Inject() (httpClientV2: HttpClientV2, appConfig: OutboundConnector.Config)(implicit ec: ExecutionContext)
class ApiPlatformOutboundSoapConnector @Inject() (httpClientV2: HttpClientV2, appConfig: ApiPlatformOutboundSoapConnector.Config)(implicit ec: ExecutionContext)
extends Logging with XmlHelper {

def postMessage(soapRequest: NodeSeq)(implicit hc: HeaderCarrier): Future[SendResult] = {
Expand All @@ -56,8 +56,7 @@ class OutboundConnector @Inject() (httpClientV2: HttpClientV2, appConfig: Outbou
}
}

private def postHttpRequest(soapEnvelope: NodeSeq, baseUrl: String, headers: Seq[(String, String)])
(implicit hc: HeaderCarrier): Future[Either[UpstreamErrorResponse, HttpResponse]] = {
private def postHttpRequest(soapEnvelope: NodeSeq, baseUrl: String, headers: Seq[(String, String)])(implicit hc: HeaderCarrier): Future[Either[UpstreamErrorResponse, HttpResponse]] = {
httpClientV2.post(new URL(baseUrl))
.withBody(soapEnvelope)
.transform(_.addHttpHeaders(headers: _*))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import uk.gov.hmrc.apiplatforminboundsoap.config.AppConfig
import uk.gov.hmrc.apiplatforminboundsoap.models.{SendFail, SendResult, SendSuccess, SoapRequest}

@Singleton
class InboundConnector @Inject() (httpClientV2: HttpClientV2, appConfig: AppConfig)(implicit ec: ExecutionContext) extends Logging {
class ImportControlInboundSoapConnector @Inject() (httpClientV2: HttpClientV2, appConfig: AppConfig)(implicit ec: ExecutionContext) extends Logging {

def postMessage(soapRequest: SoapRequest, headers: Seq[(String, String)])(implicit hc: HeaderCarrier): Future[SendResult] = {
postHttpRequest(soapRequest, headers).map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ import scala.xml.NodeSeq
import play.api.mvc.{Action, ControllerComponents}
import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController

import uk.gov.hmrc.apiplatforminboundsoap.connectors.OutboundConnector
import uk.gov.hmrc.apiplatforminboundsoap.connectors.ApiPlatformOutboundSoapConnector
import uk.gov.hmrc.apiplatforminboundsoap.controllers.actionBuilders.VerifyJwtTokenAction
import uk.gov.hmrc.apiplatforminboundsoap.models.{SendFail, SendSuccess}

@Singleton()
class ConfirmationController @Inject() (
outboundConnector: OutboundConnector,
apiPlatformOutboundSoapConnector: ApiPlatformOutboundSoapConnector,
cc: ControllerComponents,
verifyJwtTokenAction: VerifyJwtTokenAction
)(implicit ec: ExecutionContext
) extends BackendController(cc) {

def message(): Action[NodeSeq] = (Action andThen verifyJwtTokenAction).async(parse.xml) { implicit request =>
outboundConnector.postMessage(request.body) flatMap {
apiPlatformOutboundSoapConnector.postMessage(request.body) flatMap {
case SendSuccess =>
Future.successful(Ok.as("application/soap+xml"))
case SendFail(status) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import play.api.Logging
import uk.gov.hmrc.http.HeaderCarrier

import uk.gov.hmrc.apiplatforminboundsoap.config.AppConfig
import uk.gov.hmrc.apiplatforminboundsoap.connectors.InboundConnector
import uk.gov.hmrc.apiplatforminboundsoap.connectors.ImportControlInboundSoapConnector
import uk.gov.hmrc.apiplatforminboundsoap.models.{SendResult, SoapRequest}
import uk.gov.hmrc.apiplatforminboundsoap.xml.XmlHelper

@Singleton
class InboundMessageService @Inject() (appConfig: AppConfig, inboundConnector: InboundConnector) extends Logging with XmlHelper {
class InboundMessageService @Inject() (appConfig: AppConfig, importControlInboundSoapConnector: ImportControlInboundSoapConnector)
extends Logging with XmlHelper {

def processInboundMessage(soapRequest: NodeSeq, isTest: Boolean = false)(implicit hc: HeaderCarrier): Future[SendResult] = {
val newHeaders: Seq[(String, String)] = List(
Expand All @@ -41,6 +42,6 @@ class InboundMessageService @Inject() (appConfig: AppConfig, inboundConnector: I
)
val forwardUrl = if (isTest) appConfig.testForwardMessageUrl else appConfig.forwardMessageUrl

inboundConnector.postMessage(SoapRequest(soapRequest.text, forwardUrl), newHeaders)
importControlInboundSoapConnector.postMessage(SoapRequest(soapRequest.text, forwardUrl), newHeaders)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import uk.gov.hmrc.apiplatforminboundsoap.models.{SendFail, SendResult, SendSucc
import uk.gov.hmrc.apiplatforminboundsoap.stubs.ApiPlatformOutboundSoapStub
import uk.gov.hmrc.apiplatforminboundsoap.xml.XmlHelper

class OutboundConnectorISpec extends AnyWordSpec with Matchers with GuiceOneAppPerSuite
class ApiPlatformOutboundSoapConnectorISpec extends AnyWordSpec with Matchers with GuiceOneAppPerSuite
with ExternalWireMockSupport with ApiPlatformOutboundSoapStub with XmlHelper {
override implicit lazy val app: Application = appBuilder.build()
implicit val hc: HeaderCarrier = HeaderCarrier()
Expand All @@ -49,7 +49,7 @@ class OutboundConnectorISpec extends AnyWordSpec with Matchers with GuiceOneAppP
)

trait Setup {
val underTest: OutboundConnector = app.injector.instanceOf[OutboundConnector]
val underTest: ApiPlatformOutboundSoapConnector = app.injector.instanceOf[ApiPlatformOutboundSoapConnector]

def readFromFile(fileName: String) = {
XML.load(Source.fromResource(fileName).bufferedReader())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import uk.gov.hmrc.http.test.ExternalWireMockSupport
import uk.gov.hmrc.apiplatforminboundsoap.models.{SendFail, SendResult, SendSuccess, SoapRequest}
import uk.gov.hmrc.apiplatforminboundsoap.support.ExternalServiceStub

class InboundConnectorISpec extends AnyWordSpec with Matchers with GuiceOneAppPerSuite with ExternalWireMockSupport with ExternalServiceStub {
class ImportControlInboundSoapConnectorISpec extends AnyWordSpec with Matchers with GuiceOneAppPerSuite with ExternalWireMockSupport with ExternalServiceStub {
override implicit lazy val app: Application = appBuilder.build()
implicit val hc: HeaderCarrier = HeaderCarrier()

Expand All @@ -42,8 +42,8 @@ class InboundConnectorISpec extends AnyWordSpec with Matchers with GuiceOneAppPe
)

trait Setup {
val headers: Seq[(String, String)] = List("Authorization" -> "Bearer value")
val underTest: InboundConnector = app.injector.instanceOf[InboundConnector]
val headers: Seq[(String, String)] = List("Authorization" -> "Bearer value")
val underTest: ImportControlInboundSoapConnector = app.injector.instanceOf[ImportControlInboundSoapConnector]
}

"postMessage" should {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import play.api.test.Helpers._
import play.api.test.{FakeRequest, Helpers}
import uk.gov.hmrc.http.HeaderCarrier

import uk.gov.hmrc.apiplatforminboundsoap.connectors.OutboundConnector
import uk.gov.hmrc.apiplatforminboundsoap.connectors.ApiPlatformOutboundSoapConnector
import uk.gov.hmrc.apiplatforminboundsoap.controllers.actionBuilders.VerifyJwtTokenAction
import uk.gov.hmrc.apiplatforminboundsoap.models.{SendFail, SendSuccess}

Expand All @@ -45,7 +45,7 @@ class ConfirmationControllerSpec extends AnyWordSpec with Matchers with GuiceOne

trait Setup {
private val verifyJwtTokenAction = app.injector.instanceOf[VerifyJwtTokenAction]
val mockOutboundConnector = mock[OutboundConnector]
val mockOutboundConnector = mock[ApiPlatformOutboundSoapConnector]
val controller = new ConfirmationController(mockOutboundConnector, Helpers.stubControllerComponents(), verifyJwtTokenAction)

val xRequestIdHeaderValue = randomUUID.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import play.api.test.Helpers.{await, defaultAwaitTimeout}
import uk.gov.hmrc.http.HeaderCarrier

import uk.gov.hmrc.apiplatforminboundsoap.config.AppConfig
import uk.gov.hmrc.apiplatforminboundsoap.connectors.InboundConnector
import uk.gov.hmrc.apiplatforminboundsoap.connectors.ImportControlInboundSoapConnector
import uk.gov.hmrc.apiplatforminboundsoap.models.{SendFail, SendSuccess, SoapRequest}
import uk.gov.hmrc.apiplatforminboundsoap.xml.XmlHelper

Expand All @@ -46,9 +46,9 @@ class InboundMessageServiceSpec extends AnyWordSpec with Matchers with GuiceOneA
}

trait Setup {
val inboundConnectorMock: InboundConnector = mock[InboundConnector]
val bodyCaptor = ArgCaptor[SoapRequest]
val headerCaptor = ArgCaptor[Seq[(String, String)]]
val inboundConnectorMock: ImportControlInboundSoapConnector = mock[ImportControlInboundSoapConnector]
val bodyCaptor = ArgCaptor[SoapRequest]
val headerCaptor = ArgCaptor[Seq[(String, String)]]

val httpStatus: Int = Status.OK
val appConfigMock: AppConfig = mock[AppConfig]
Expand Down

0 comments on commit 2bd2e0b

Please sign in to comment.