From 3712e6472f8d9dcc173250219d52730d9bec7f78 Mon Sep 17 00:00:00 2001 From: "siva.isikella" <7499500+sivaprakashiv@users.noreply.github.com> Date: Tue, 6 Jul 2021 12:11:21 +0100 Subject: [PATCH] APID-208 - review comments addressed --- .../services/OutboundServiceSpec.scala | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/test/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundServiceSpec.scala b/test/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundServiceSpec.scala index b6a574b..ae16d6e 100644 --- a/test/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundServiceSpec.scala +++ b/test/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundServiceSpec.scala @@ -85,7 +85,8 @@ class OutboundServiceSpec extends AnyWordSpec with Matchers with GuiceOneAppPerS val to = "CCN2" val from = "HMRC" val addressing = Addressing(from , to , "ReplyTo", "FaultTo", messageId, Some("RelatesTo")) - val addressingOnlyMandatoryFields = Addressing(from = from, to = to, replyTo = "ReplyTo", faultTo = "FaultTo", messageId = messageId) + // mixin refers to mandatory and default addressing fields + val addressingMixinFields = Addressing(from = from, to = to, replyTo = "ReplyTo", faultTo = "FaultTo", messageId = messageId) val messageRequestFullAddressing = MessageRequest( "test/resources/definitions/CCN2.Service.Customs.Default.ICS.RiskAnalysisOrchestrationBAS_1.0.0_CCN2_1.0.0.wsdl", "IE4N03notifyERiskAnalysisHit", @@ -114,7 +115,7 @@ class OutboundServiceSpec extends AnyWordSpec with Matchers with GuiceOneAppPerS ) val messageRequestMinimalAddressing = messageRequestFullAddressing - .copy(addressing = addressingOnlyMandatoryFields) + .copy(addressing = addressingMixinFields) val expectedStatus: Int = OK val allAddressingHeaders = @@ -125,7 +126,7 @@ class OutboundServiceSpec extends AnyWordSpec with Matchers with GuiceOneAppPerS |123 |RelatesTo""".stripMargin.replaceAll("\n", "") - val mandatoryAddressingHeaders = + val mixinAddressingHeaders = """HMRC |CCN2 |ReplyTo @@ -291,36 +292,36 @@ class OutboundServiceSpec extends AnyWordSpec with Matchers with GuiceOneAppPerS "send the expected SOAP envelope to the security service which adds username token" in new Setup { val messageCaptor: ArgumentCaptor[SOAPEnvelope] = ArgumentCaptor.forClass(classOf[SOAPEnvelope]) - when(wsSecurityServiceMock.addUsernameToken(messageCaptor.capture())).thenReturn(expectedSoapEnvelope(mandatoryAddressingHeaders)) + when(wsSecurityServiceMock.addUsernameToken(messageCaptor.capture())).thenReturn(expectedSoapEnvelope(mixinAddressingHeaders)) when(outboundConnectorMock.postMessage(*)).thenReturn(successful(expectedStatus)) when(outboundMessageRepositoryMock.persist(*)).thenReturn(Future(InsertOneResult.acknowledged(BsonNumber(1)))) await(underTest.sendMessage(messageRequestMinimalAddressing)) - getXmlDiff(messageCaptor.getValue.toString, expectedSoapEnvelope(mandatoryAddressingHeaders)).build().hasDifferences shouldBe false + getXmlDiff(messageCaptor.getValue.toString, expectedSoapEnvelope(mixinAddressingHeaders)).build().hasDifferences shouldBe false } "send the expected SOAP envelope to the security service which adds signature" in new Setup { val messageCaptor: ArgumentCaptor[SOAPEnvelope] = ArgumentCaptor.forClass(classOf[SOAPEnvelope]) when(appConfigMock.enableMessageSigning).thenReturn(true) - when(wsSecurityServiceMock.addSignature(messageCaptor.capture())).thenReturn(expectedSoapEnvelope(mandatoryAddressingHeaders)) + when(wsSecurityServiceMock.addSignature(messageCaptor.capture())).thenReturn(expectedSoapEnvelope(mixinAddressingHeaders)) when(outboundConnectorMock.postMessage(*)).thenReturn(successful(expectedStatus)) when(outboundMessageRepositoryMock.persist(*)).thenReturn(Future(InsertOneResult.acknowledged(BsonNumber(1)))) await(underTest.sendMessage(messageRequestMinimalAddressing)) - getXmlDiff(messageCaptor.getValue.toString, expectedSoapEnvelope(mandatoryAddressingHeaders)).build().hasDifferences shouldBe false + getXmlDiff(messageCaptor.getValue.toString, expectedSoapEnvelope(mixinAddressingHeaders)).build().hasDifferences shouldBe false } "send the optional addressing headers if present in the request" in new Setup { val messageCaptor: ArgumentCaptor[SOAPEnvelope] = ArgumentCaptor.forClass(classOf[SOAPEnvelope]) val persistCaptor: ArgumentCaptor[OutboundSoapMessage] = ArgumentCaptor.forClass(classOf[OutboundSoapMessage]) - when(wsSecurityServiceMock.addUsernameToken(messageCaptor.capture())).thenReturn(expectedSoapEnvelope(mandatoryAddressingHeaders)) + when(wsSecurityServiceMock.addUsernameToken(messageCaptor.capture())).thenReturn(expectedSoapEnvelope(mixinAddressingHeaders)) when(outboundConnectorMock.postMessage(*)).thenReturn(successful(expectedStatus)) when(outboundMessageRepositoryMock.persist(persistCaptor.capture())).thenReturn(Future(InsertOneResult.acknowledged(BsonNumber(1)))) await(underTest.sendMessage(messageRequestMinimalAddressing)) - persistCaptor.getValue.soapMessage shouldBe expectedSoapEnvelope(mandatoryAddressingHeaders) - getXmlDiff(messageCaptor.getValue.toString, expectedSoapEnvelope(mandatoryAddressingHeaders)).build().hasDifferences shouldBe false + persistCaptor.getValue.soapMessage shouldBe expectedSoapEnvelope(mixinAddressingHeaders) + getXmlDiff(messageCaptor.getValue.toString, expectedSoapEnvelope(mixinAddressingHeaders)).build().hasDifferences shouldBe false } "persist message ID if present in the request for success" in new Setup {