Skip to content

Commit

Permalink
API-6858 - Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anjumabbas5 committed Mar 1, 2024
1 parent fd0b5c0 commit abe50a7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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$
Expand All @@ -34,4 +34,4 @@ class WsdlParser {
}

}
// $COVERAGE-ON$
// $COVERAGE-ON$
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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._
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit abe50a7

Please sign in to comment.