diff --git a/app/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundService.scala b/app/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundService.scala index 08ab696..005cec4 100644 --- a/app/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundService.scala +++ b/app/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundService.scala @@ -21,7 +21,6 @@ import java.util.UUID import javax.inject.{Inject, Singleton} import javax.wsdl._ import javax.wsdl.extensions.soap12.SOAP12Address -import javax.wsdl.xml.WSDLReader import javax.xml.namespace.QName import scala.concurrent.{ExecutionContext, Future} import scala.jdk.CollectionConverters._ @@ -32,7 +31,6 @@ import org.apache.axiom.om.util.AXIOMUtil.stringToOM import org.apache.axiom.soap.SOAPEnvelope import org.apache.axis2.addressing.AddressingConstants.Final.{WSAW_NAMESPACE, WSA_NAMESPACE} import org.apache.axis2.addressing.AddressingConstants._ -import org.apache.axis2.wsdl.WSDLUtil import org.apache.pekko.Done import org.apache.pekko.stream.Materializer import org.apache.pekko.stream.scaladsl.Sink diff --git a/app/uk/gov/hmrc/apiplatformoutboundsoap/services/WsdlParser.scala b/app/uk/gov/hmrc/apiplatformoutboundsoap/services/WsdlParser.scala index c62bdee..0114b35 100644 --- a/app/uk/gov/hmrc/apiplatformoutboundsoap/services/WsdlParser.scala +++ b/app/uk/gov/hmrc/apiplatformoutboundsoap/services/WsdlParser.scala @@ -16,12 +16,12 @@ package uk.gov.hmrc.apiplatformoutboundsoap.services -import org.apache.axis2.wsdl.WSDLUtil - import javax.wsdl.Definition import javax.wsdl.xml.WSDLReader import scala.concurrent.Future +import org.apache.axis2.wsdl.WSDLUtil + // Turned off coverage for this as it was just one line and no need to test WSDLUtil code as it is not // ours. However if this ever expands in future, tests will be needed and scoverage ignore removed. // $COVERAGE-OFF$ @@ -34,4 +34,4 @@ class WsdlParser { } } -// $COVERAGE-ON$ \ No newline at end of file +// $COVERAGE-ON$ diff --git a/test/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundServiceSpec.scala b/test/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundServiceSpec.scala index 39044d5..1370860 100644 --- a/test/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundServiceSpec.scala +++ b/test/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundServiceSpec.scala @@ -20,12 +20,15 @@ import java.time.Instant import java.util.UUID import java.util.UUID.randomUUID import javax.wsdl.WSDLException +import javax.wsdl.xml.WSDLReader import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future import scala.concurrent.Future.{failed, successful} import scala.concurrent.duration.Duration + import com.mongodb.client.result.InsertOneResult import org.apache.axiom.soap.SOAPEnvelope +import org.apache.axis2.wsdl.WSDLUtil import org.apache.pekko.stream.Materializer import org.apache.pekko.stream.scaladsl.Source.{fromIterator, single} import org.mockito.{ArgumentCaptor, ArgumentMatchersSugar, MockitoSugar} @@ -37,10 +40,12 @@ import org.xmlunit.builder.DiffBuilder import org.xmlunit.builder.DiffBuilder.compare import org.xmlunit.diff.DefaultNodeMatcher import org.xmlunit.diff.ElementSelectors.byName + import play.api.cache.AsyncCacheApi import play.api.http.Status.OK import play.api.test.Helpers._ import uk.gov.hmrc.http.{HeaderCarrier, NotFoundException} + import uk.gov.hmrc.apiplatformoutboundsoap.config.AppConfig import uk.gov.hmrc.apiplatformoutboundsoap.connectors.{NotificationCallbackConnector, OutboundConnector} import uk.gov.hmrc.apiplatformoutboundsoap.models._ @@ -73,6 +78,12 @@ class OutboundServiceSpec extends AnyWordSpec with Matchers with GuiceOneAppPerS when(appConfigMock.proxyRequiredForThisEnvironment).thenReturn(false) + val reader: WSDLReader = WSDLUtil.newWSDLReaderWithPopulatedExtensionRegistry + reader.setFeature("javax.wsdl.importDocuments", true) + val definition = reader.readWSDL("test/resources/definitions/CCN2.Service.Customs.Default.ICS.RiskAnalysisOrchestrationBAS_1.0.0_CCN2_1.0.0.wsdl") + val definitionUrlResolver = reader.readWSDL("test/resources/definitions/CCN2.Service.Customs.Default.ICS.RiskAnalysisOrchestrationBAS_1.0.0_CCN2_URLResolver.wsdl") + when(wsdlParser.parseWsdl(*)).thenReturn(successful(definition)) + val underTest: OutboundService = new OutboundService(outboundConnectorMock, wsSecurityServiceMock, outboundMessageRepositoryMock, notificationCallbackConnectorMock, wsdlParser, appConfigMock, cacheSpy) { override def now: Instant = expectedInstantNow @@ -310,6 +321,7 @@ class OutboundServiceSpec extends AnyWordSpec with Matchers with GuiceOneAppPerS } "resolve destination url not having port when sending the SOAP envelope returned from the security service to the connector" in new Setup { + when(wsdlParser.parseWsdl(*)).thenReturn(successful(definitionUrlResolver)) when(wsSecurityServiceMock.addUsernameToken(*)).thenReturn(expectedSoapEnvelope()) when(outboundMessageRepositoryMock.persist(*)).thenReturn(Future(InsertOneResult.acknowledged(BsonNumber(1)))) val messageCaptor: ArgumentCaptor[SoapRequest] = ArgumentCaptor.forClass(classOf[SoapRequest])