Skip to content

Commit

Permalink
NOD-818: [FDR] Anomalia nel recupero dei flussi presenti su Nexi
Browse files Browse the repository at this point in the history
  • Loading branch information
fparisitas committed May 2, 2024
1 parent 73d5fec commit f95f605
Show file tree
Hide file tree
Showing 8 changed files with 474 additions and 11 deletions.
5 changes: 4 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,10 @@ lazy val `fdr` = (project in file("fdr"))
"org.scalaj" %% "scalaj-http" % scalaj % Test,
"com.h2database" % "h2" % "1.4.200" % Test,
"org.liquibase" % "liquibase-core" % "4.10.0" % Test,
"org.scala-lang.modules" %% "scala-xml" % scalaXmlVersion % Test
"org.scala-lang.modules" %% "scala-xml" % scalaXmlVersion % Test,
"org.mockito" %% s"mockito-scala" % "1.17.30" % Test,
"com.softwaremill.sttp.client4" %% "core" % "4.0.0-M11" % Test,
"org.mock-server" % s"mockserver-netty" % "5.14.0" % Test
)
}
)
16 changes: 12 additions & 4 deletions fdr/src/main/scala/eu/sia/pagopa/TestDData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ object TestDData {
"77777777777" -> basePA.copy(creditorInstitutionCode = "77777777777", true, description = Some("77777777777"), businessName = Some("77777777777")),
TestItems.PA_FTP -> basePA.copy(creditorInstitutionCode = TestItems.PA_FTP, reportingFtp = true),
TestItems.PA_old -> basePA.copy(creditorInstitutionCode = TestItems.PA_old),
TestItems.PA_2 -> basePA.copy(creditorInstitutionCode = TestItems.PA_2)
TestItems.PA_2 -> basePA.copy(creditorInstitutionCode = TestItems.PA_2),
TestItems.PA_DISABLED -> basePA.copy(creditorInstitutionCode = TestItems.PA_DISABLED, enabled = false)
),
Map(
TestItems.testIntPA -> BrokerCreditorInstitution(TestItems.testIntPA, true, Some("INTPAT"), false),
TestItems.testIntPA_DISABLED -> BrokerCreditorInstitution(TestItems.testIntPA_DISABLED, false, Some("INTPAT_dis"), false)
),
Map(TestItems.testIntPA -> BrokerCreditorInstitution(TestItems.testIntPA, true, Some("INTPAT"), false)),
Map(
TestItems.stazione -> baseStazione.copy(stationCode = TestItems.stazione, version = 2),
TestItems.stazione_DISABLED -> baseStazione.copy(stationCode = TestItems.stazione_DISABLED, version = 2,enabled = false),
TestItems.stazioneOld -> baseStazione.copy(stationCode = TestItems.stazioneOld, version = 1),
TestItems.stazioneNonIstantanea -> baseStazione.copy(stationCode = TestItems.stazioneNonIstantanea, version = 2, invioRtIstantaneo = false),
TestItems.stazionePV2 -> baseStazione.copy(stationCode = TestItems.stazionePV2, version = 2, invioRtIstantaneo = false, primitiveVersion = 2),
Expand Down Expand Up @@ -100,12 +105,14 @@ object TestDData {
"idPsp1" -> basePSP.copy(pspCode = "idPsp1", taxCode = Some("idPsp1")),
TestItems.PSPMod3New -> basePSP.copy(pspCode = TestItems.PSPMod3New, taxCode = Some(TestItems.PSPMod3New)),
TestItems.PSPAgid -> basePSP.copy(pspCode = TestItems.PSPAgid, taxCode = Some(TestItems.PSPAgid)),
TestItems.PSPECOMMERCE -> basePSP.copy(pspCode = TestItems.PSPECOMMERCE, taxCode = Some(TestItems.PSPECOMMERCE))
TestItems.PSPECOMMERCE -> basePSP.copy(pspCode = TestItems.PSPECOMMERCE, taxCode = Some(TestItems.PSPECOMMERCE)),
TestItems.PSP_DISABLED -> basePSP.copy(pspCode = TestItems.PSP_DISABLED, taxCode = Some(TestItems.PSP_DISABLED),enabled = false)
),
Map(
TestItems.intPSP -> BrokerPsp(TestItems.intPSP, Some("INTPSPT"), true, true),
TestItems.intPSPMod3New -> BrokerPsp(TestItems.intPSPMod3New, Some(TestItems.intPSPMod3New), true, true),
TestItems.intPSPAgid -> BrokerPsp(TestItems.intPSPAgid, Some(TestItems.intPSPAgid), true, true)
TestItems.intPSPAgid -> BrokerPsp(TestItems.intPSPAgid, Some(TestItems.intPSPAgid), true, true),
TestItems.intPSP_DISABLED -> BrokerPsp(TestItems.intPSP_DISABLED, Some(TestItems.intPSP_DISABLED), false, true),
),
Map(
"AD" -> PaymentType("AD", Some("Addebito diretto")),
Expand Down Expand Up @@ -157,6 +164,7 @@ object TestDData {
Map(),
Map(
TestItems.canale -> baseCanale.copy(channelCode = TestItems.canale, paymentModel = "ATTIVATO_PRESSO_PSP"),
TestItems.canale_DISABLED -> baseCanale.copy(channelCode = TestItems.canale_DISABLED, paymentModel = "ATTIVATO_PRESSO_PSP",enabled = false),
TestItems.canaleImmediato -> baseCanale.copy(channelCode = TestItems.canaleImmediato, paymentModel = "IMMEDIATO"),
TestItems.canaleAgid -> baseCanale.copy(channelCode = TestItems.canaleAgid, brokerPspCode = TestItems.intPSPAgid, paymentModel = "IMMEDIATO_MULTIBENEFICIARIO"),
TestItems.canaleMod3new -> baseCanale.copy(channelCode = TestItems.canaleMod3new, brokerPspCode = TestItems.intPSPMod3New, paymentModel = "IMMEDIATO"),
Expand Down
12 changes: 9 additions & 3 deletions fdr/src/main/scala/eu/sia/pagopa/TestUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import scala.concurrent.duration.{FiniteDuration, _}
import scala.util.{Success, Try}
object TestItems {

val PA = "15376371009"
val PA = "44444444444"
val PA_2 = "12345678902"
val PA_old = "12345678901"
val PA_FTP = "90000000002"
val PA_DISABLED = "90000000099"
val prefixNew = "001"
val stazione = "15376371009_03"
val stazione = "44444444444_01"
val stazione_DISABLED = "stazioneTest_dis"
val stazioneNonIstantanea = "stazioneTestNonIstantanea"
val stazionePV2 = "stazionePV2"
val stazionePV2Broadcast = "stazionePV2BroadCast"
Expand All @@ -27,19 +29,23 @@ object TestItems {
val PAUnknown = "01010101010"

val PSP = "60000000001"
val PSP_DISABLED = "pspTest_dis"
val PSPAgid = "AGID_01"
val PSPCD = "AGID_01"
val PSPECOMMERCE = "PSP_ECOMMERCE"
val PSPMod3New = "15376371009"

val testIntPA = "15376371009"
val testIntPA = "44444444444"
val testIntPA_DISABLED = "intPaTest_dis"

val intPSP = "60000000001"
val intPSP_DISABLED = "intPspTest_dis"
val intPSPAgid = "97735020584"
val intPSPCD = "97735020584"
val intPSPMod3New = "15376371009"

val canale = "15376371009_04"
val canale_DISABLED = "canaleTest_dis"
val canaleImmediato = "canaleImmediato"
val canaleDifferito = "canaleDifferito"
val canaleAgid = "97735020584_02"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ object Appfunction {
}
}

private def formatHeaders(headersOpt: Option[Seq[(String, String)]]): String = {
def formatHeaders(headersOpt: Option[Seq[(String, String)]]): String = {
headersOpt
.map(d => {
if (d.isEmpty) {
Expand All @@ -97,7 +97,7 @@ object Appfunction {
s"[${s.getOrElse(Constant.UNKNOWN)}]"
}

private def fmtMessage(re: Re, reExtra: Option[ReExtra]): Try[String] = {
def fmtMessage(re: Re, reExtra: Option[ReExtra]): Try[String] = {
Try({
if (re.categoriaEvento == CategoriaEvento.INTERFACCIA.toString) {
val mod = if (re.esito.isDefined) {
Expand Down Expand Up @@ -136,7 +136,7 @@ object Appfunction {
})
}

private def fmtMessageJson(re: Re, reExtra: Option[ReExtra], data: ConfigData): Try[String] = {
def fmtMessageJson(re: Re, reExtra: Option[ReExtra], data: ConfigData): Try[String] = {
Try({
val nd = "nd"
val (isServerRequest, isServerResponse, isClientRequest, isClientResponse, caller, httpType, subject, subjectDescr, isKO) = if (re.categoriaEvento == CategoriaEvento.INTERFACCIA.toString) {
Expand Down
143 changes: 143 additions & 0 deletions fdr/src/test/scala/eu/sia/pagopa/ChecksUnitTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package eu.sia.pagopa

import akka.actor.ActorSystem
import akka.stream.Materializer
import com.typesafe.config.Config
import eu.sia.pagopa.common.exception.{DigitPaErrorCodes, DigitPaException}
import eu.sia.pagopa.common.repo.fdr.FdrRepository
import eu.sia.pagopa.common.util.azurehubevent.Appfunction.ReEventFunc
import eu.sia.pagopa.common.util.web.NodoRoute
import eu.sia.pagopa.common.util.xml.XmlUtil.StringBase64Binary
import eu.sia.pagopa.common.util.xml.XsdValid
import eu.sia.pagopa.common.util.{DDataChecks, NodoLogger, StringUtils}
import eu.sia.pagopa.commonxml.XmlEnum
import eu.sia.pagopa.testutil.SpecsUtils
import it.pagopa.config.PaymentType
import org.mockito.Mockito.when
import org.mockito.MockitoSugar.mock
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should

import scala.concurrent.ExecutionContext
import scala.util.Try

class ChecksUnitTests extends AnyFlatSpec with should.Matchers {

val log = mock[NodoLogger]

"route errors" should "ok" in {
val settings = mock[ActorSystem.Settings]
val config = mock[Config]
val as = mock[ActorSystem]
val fdrRepository = mock[FdrRepository]
when(as.settings).thenReturn(settings)
when(settings.config).thenReturn(config)
when(config.getInt("config.http.server-request-timeout")).thenReturn(10)
val ec = mock[ExecutionContext]
val log = mock[NodoLogger]
val nr = new NodoRoute(as,fdrRepository,Map(),"",200,mock[ReEventFunc],mock[ActorProps])(ec,log,mock[Materializer])
val timeout = nr.akkaHttpTimeout("sid")
val enc = nr.akkaErrorEncoding("sid","UTF-8")
assert(timeout.status.isFailure())
assert(enc.status.isFailure())
}

"getConfigurationKeys" should "ok" in {
val t = Try(DDataChecks.getConfigurationKeys(TestDData.ddataMap,"aaaa","bbb"))
assert(t.isFailure)
}

"checkPspCanaleTipoVersamento" should "ok" in {
val t = DDataChecks.checkPspCanaleTipoVersamento(log,TestDData.ddataMap,TestDData.ddataMap.psps.head._2,TestDData.ddataMap.channels.head._2,
None)
assert(t.isFailure)
assert(t.failed.get.asInstanceOf[DigitPaException].code == DigitPaErrorCodes.PPT_AUTORIZZAZIONE)
assert(t.failed.get.asInstanceOf[DigitPaException].message == "Configurazione psp-canale non corretta")
}
"checkPspCanaleTipoVersamento 2" should "ok" in {
val t = DDataChecks.checkPspCanaleTipoVersamento(log,TestDData.ddataMap,TestDData.ddataMap.psps(TestItems.PSP),TestDData.ddataMap.channels(TestItems.canale),
Some(new PaymentType("DDD",None)))
assert(t.isFailure)
assert(t.failed.get.asInstanceOf[DigitPaException].code == DigitPaErrorCodes.PPT_AUTORIZZAZIONE)
assert(t.failed.get.asInstanceOf[DigitPaException].message == "Configurazione psp-canale-tipoVersamento non corretta")
}

"StringUtils" should "getStringDecodedByString" in {
assert("test" == StringUtils.getStringDecodedByString(StringBase64Binary.encodeBase64ToString("test".getBytes),true).get)
}

"XSD" should "success" in {
val p = SpecsUtils.loadTestXML(s"/requests/nodoInviaFlussoRendicontazione.xml")
assert(XsdValid.checkOnly(p,XmlEnum.NODO_INVIA_FLUSSO_RENDICONTAZIONE_NODOPERPSP, true).isFailure)
}

"PA" should "success" in {
val t1 = DDataChecks.checkPA(log,TestDData.ddataMap,TestItems.PA)
assert(t1.isSuccess)
val t2 = DDataChecks.checkPA(log,TestDData.ddataMap,TestItems.PA_DISABLED)
assert(t2.isFailure)
assert(t2.failed.get.asInstanceOf[DigitPaException].code == DigitPaErrorCodes.PPT_DOMINIO_DISABILITATO)
val t3 = DDataChecks.checkPA(log,TestDData.ddataMap,"#")
assert(t3.isFailure)
assert(t3.failed.get.asInstanceOf[DigitPaException].code == DigitPaErrorCodes.PPT_DOMINIO_SCONOSCIUTO)
}
"PSP" should "success" in {
val t1 = DDataChecks.checkPsp(log,TestDData.ddataMap,TestItems.PSP)
assert(t1.isSuccess)
val t2 = DDataChecks.checkPsp(log,TestDData.ddataMap,TestItems.PSP_DISABLED)
assert(t2.isFailure)
assert(t2.failed.get.asInstanceOf[DigitPaException].code == DigitPaErrorCodes.PPT_PSP_DISABILITATO)
val t3 = DDataChecks.checkPsp(log,TestDData.ddataMap,"#")
assert(t3.isFailure)
assert(t3.failed.get.asInstanceOf[DigitPaException].code == DigitPaErrorCodes.PPT_PSP_SCONOSCIUTO)
}
"INT_PSP" should "success" in {
val t1 = DDataChecks.checkIntermediarioPSP(log,TestDData.ddataMap,TestItems.intPSP)
assert(t1.isSuccess)
val t2 = DDataChecks.checkIntermediarioPSP(log,TestDData.ddataMap,TestItems.intPSP_DISABLED)
assert(t2.isFailure)
assert(t2.failed.get.asInstanceOf[DigitPaException].code == DigitPaErrorCodes.PPT_INTERMEDIARIO_PSP_DISABILITATO)
val t3 = DDataChecks.checkIntermediarioPSP(log,TestDData.ddataMap,"#")
assert(t3.isFailure)
assert(t3.failed.get.asInstanceOf[DigitPaException].code == DigitPaErrorCodes.PPT_INTERMEDIARIO_PSP_SCONOSCIUTO)
}
"INT_PA" should "success" in {
val t1 = DDataChecks.checkIntermediarioPA(log,TestDData.ddataMap,TestItems.testIntPA)
assert(t1.isSuccess)
val t2 = DDataChecks.checkIntermediarioPA(log,TestDData.ddataMap,TestItems.testIntPA_DISABLED)
assert(t2.isFailure)
assert(t2.failed.get.asInstanceOf[DigitPaException].code == DigitPaErrorCodes.PPT_INTERMEDIARIO_PA_DISABILITATO)
val t3 = DDataChecks.checkIntermediarioPA(log,TestDData.ddataMap,"#")
assert(t3.isFailure)
assert(t3.failed.get.asInstanceOf[DigitPaException].code == DigitPaErrorCodes.PPT_INTERMEDIARIO_PA_SCONOSCIUTO)
}
"CANALE" should "success" in {
val t1 = DDataChecks.checkCanale(log,TestDData.ddataMap,TestItems.canale,Some(TestItems.canalePwd), false)
assert(t1.isSuccess)
val t2 = DDataChecks.checkCanale(log,TestDData.ddataMap,TestItems.canale_DISABLED,Some(""), false)
assert(t2.isFailure)
assert(t2.failed.get.asInstanceOf[DigitPaException].code == DigitPaErrorCodes.PPT_CANALE_DISABILITATO)
val t3 = DDataChecks.checkCanale(log,TestDData.ddataMap,"#",None, false)
assert(t3.isFailure)
assert(t3.failed.get.asInstanceOf[DigitPaException].code == DigitPaErrorCodes.PPT_CANALE_SCONOSCIUTO)
val t4 = DDataChecks.checkCanale(log,TestDData.ddataMap,TestItems.canale,Some("wrongpass"), true)
assert(t4.isFailure)
assert(t4.failed.get.asInstanceOf[DigitPaException].code == DigitPaErrorCodes.PPT_AUTENTICAZIONE)
}
"STAZIONE" should "success" in {
val t1 = DDataChecks.checkStazione(log,TestDData.ddataMap,TestItems.stazione,Some(TestItems.stazionePwd), true)
assert(t1.isSuccess)
val t2 = DDataChecks.checkStazione(log,TestDData.ddataMap,TestItems.stazione_DISABLED,Some(""), false)
assert(t2.isFailure)
assert(t2.failed.get.asInstanceOf[DigitPaException].code == DigitPaErrorCodes.PPT_STAZIONE_INT_PA_DISABILITATA)
val t3 = DDataChecks.checkStazione(log,TestDData.ddataMap,"#",None, false)
assert(t3.isFailure)
assert(t3.failed.get.asInstanceOf[DigitPaException].code == DigitPaErrorCodes.PPT_STAZIONE_INT_PA_SCONOSCIUTA)
val t4 = DDataChecks.checkStazione(log,TestDData.ddataMap,TestItems.stazione,Some("wrongpass"), true)
assert(t4.isFailure)
assert(t4.failed.get.asInstanceOf[DigitPaException].code == DigitPaErrorCodes.PPT_AUTENTICAZIONE)
}
"ALTRI CHECK" should "success" in {
}

}
25 changes: 25 additions & 0 deletions fdr/src/test/scala/eu/sia/pagopa/ConfigUnitTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package eu.sia.pagopa

import akka.http.scaladsl.marshalling.ToResponseMarshallable
import akka.http.scaladsl.model.HttpResponse
import akka.http.scaladsl.server.RequestContext
import org.mockito.MockitoSugar.mock
import org.mockito.invocation.InvocationOnMock
import org.mockito.stubbing.Answer
import org.scalatest.BeforeAndAfterAll

import scala.concurrent.Future

//@org.scalatest.Ignore
class ConfigUnitTests() extends BaseUnitTest with BeforeAndAfterAll{

def toAnswerWithArgs[T](f: InvocationOnMock => T) = new Answer[T] {
override def answer(i: InvocationOnMock): T = f(i)
}
val requestContext = mock[RequestContext](toAnswerWithArgs((i)=>{
val res = i.getArgument(0).asInstanceOf[ToResponseMarshallable].value.asInstanceOf[HttpResponse]
Future.successful(akka.http.scaladsl.server.RouteResult.Complete.apply(res))
})
)

}
Loading

0 comments on commit f95f605

Please sign in to comment.