diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/HttpStubRequest.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/HttpStubRequest.scala index c3231434..bde24d6f 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/HttpStubRequest.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/HttpStubRequest.scala @@ -22,7 +22,7 @@ import ru.tinkoff.tcb.circe.bson.* import ru.tinkoff.tcb.predicatedsl.Keyword import ru.tinkoff.tcb.predicatedsl.form.FormPredicate import ru.tinkoff.tcb.predicatedsl.json.JsonPredicate -import ru.tinkoff.tcb.predicatedsl.xml.XmlPredicate2 +import ru.tinkoff.tcb.predicatedsl.xml.XmlPredicate import ru.tinkoff.tcb.protocol.bson.* import ru.tinkoff.tcb.protocol.json.* import ru.tinkoff.tcb.protocol.schema.* @@ -160,11 +160,11 @@ final case class JLensRequest( @derive(decoder, encoder) final case class XPathRequest( - headers: Map[String, String], - query: Map[JsonOptic, Map[Keyword.Json, Json]] = Map.empty, - body: XmlPredicate2, - extractors: Map[String, XmlExtractor] = Map.empty, - inlineCData: Boolean = false + headers: Map[String, String], + query: Map[JsonOptic, Map[Keyword.Json, Json]] = Map.empty, + body: XmlPredicate, + extractors: Map[String, XmlExtractor] = Map.empty, + inlineCData: Boolean = false ) extends HttpStubRequest { override def checkBody(rBody: RequestBody): Boolean = extractXML(rBody).map(body).getOrElse(false) @@ -333,7 +333,7 @@ final case class JLensPart(headers: Map[String, String], body: JsonPredicate) ex } @derive(decoder, encoder) -final case class XPathPart(headers: Map[String, String], body: XmlPredicate2) extends RequestPart { +final case class XPathPart(headers: Map[String, String], body: XmlPredicate) extends RequestPart { override def checkBody(value: String): Boolean = Try(SafeXML.loadString(value)).map(body).getOrElse(false) override def extractJson(body: String): Option[Json] = None diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/ResponseSpec.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/ResponseSpec.scala index 6f3a4a67..607e29a3 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/ResponseSpec.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/ResponseSpec.scala @@ -15,7 +15,7 @@ import ru.tinkoff.tcb.bson.derivation.bsonDecoder import ru.tinkoff.tcb.bson.derivation.bsonEncoder import ru.tinkoff.tcb.circe.bson.* import ru.tinkoff.tcb.predicatedsl.json.JsonPredicate -import ru.tinkoff.tcb.predicatedsl.xml.XmlPredicate2 +import ru.tinkoff.tcb.predicatedsl.xml.XmlPredicate import ru.tinkoff.tcb.protocol.schema.* import ru.tinkoff.tcb.utils.xml.SafeXML import ru.tinkoff.tcb.utils.xml.XMLString @@ -67,7 +67,7 @@ final case class JLensResponseSpec(code: Option[Int], body: Option[JsonPredicate } @derive(decoder, encoder) -final case class XPathResponseSpec(code: Option[Int], body: Option[XmlPredicate2]) extends ResponseSpec { +final case class XPathResponseSpec(code: Option[Int], body: Option[XmlPredicate]) extends ResponseSpec { override def checkBody(data: String): Boolean = Try(SafeXML.loadString(data)).exists(nx => body.forall(_(nx))) } diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/ScenarioInput.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/ScenarioInput.scala index 905ce708..32e04c0c 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/ScenarioInput.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/model/ScenarioInput.scala @@ -17,7 +17,7 @@ import ru.tinkoff.tcb.bson.derivation.bsonDecoder import ru.tinkoff.tcb.bson.derivation.bsonEncoder import ru.tinkoff.tcb.circe.bson.* import ru.tinkoff.tcb.predicatedsl.json.JsonPredicate -import ru.tinkoff.tcb.predicatedsl.xml.XmlPredicate2 +import ru.tinkoff.tcb.predicatedsl.xml.XmlPredicate import ru.tinkoff.tcb.protocol.schema.* import ru.tinkoff.tcb.utils.xml.SafeXML import ru.tinkoff.tcb.utils.xml.XMLString @@ -94,7 +94,7 @@ final case class JLensInput(payload: JsonPredicate) extends ScenarioInput { } @derive(decoder, encoder) -final case class XPathInput(payload: XmlPredicate2) extends ScenarioInput { +final case class XPathInput(payload: XmlPredicate) extends ScenarioInput { override def checkMessage(message: String): Boolean = extractXML(message).exists(payload(_)) diff --git a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicate2.scala b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicate.scala similarity index 88% rename from backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicate2.scala rename to backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicate.scala index a701e9b3..d3d72fbf 100644 --- a/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicate2.scala +++ b/backend/mockingbird/src/main/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicate.scala @@ -29,39 +29,39 @@ import ru.tinkoff.tcb.utils.circe.optics.JsonOptic import ru.tinkoff.tcb.utils.json.JObject import ru.tinkoff.tcb.xpath.SXpath -abstract class XmlPredicate2 extends (NodeSeq => Boolean) { - def definition: XmlPredicate2.Spec +abstract class XmlPredicate extends (NodeSeq => Boolean) { + def definition: XmlPredicate.Spec override def hashCode(): Int = definition.hashCode() override def equals(obj: Any): Boolean = obj match { - case xp: XmlPredicate2 => xp.definition == definition + case xp: XmlPredicate => xp.definition == definition case _ => false } } -object XmlPredicate2 { +object XmlPredicate { type Spec = Map[SXpath, Map[Keyword.Xml, Json]] - implicit val xmlPredicateDecoder: Decoder[XmlPredicate2] = + implicit val xmlPredicateDecoder: Decoder[XmlPredicate] = Decoder[Spec].emap(apply(_).toEither.leftMap(_.toList.mkString(", "))) - implicit val xmlPredicateEncoder: Encoder[XmlPredicate2] = + implicit val xmlPredicateEncoder: Encoder[XmlPredicate] = Encoder[Spec].contramap(_.definition) - implicit val xmlPredicateSchema: Schema[XmlPredicate2] = - implicitly[Schema[Spec]].as[XmlPredicate2] + implicit val xmlPredicateSchema: Schema[XmlPredicate] = + implicitly[Schema[Spec]].as[XmlPredicate] - implicit val xmlPredicateBsonDecoder: BsonDecoder[XmlPredicate2] = + implicit val xmlPredicateBsonDecoder: BsonDecoder[XmlPredicate] = BsonDecoder[Spec].afterReadTry( apply(_).toEither.leftMap(errs => new BsonInvalidOperationException(errs.toList.mkString(", "))).toTry ) - implicit val xmlPredicateBsonEncoder: BsonEncoder[XmlPredicate2] = + implicit val xmlPredicateBsonEncoder: BsonEncoder[XmlPredicate] = BsonEncoder[Spec].beforeWrite(_.definition) - implicit val xmlPredicateRootOptionFields: RootOptionFields[XmlPredicate2] = - RootOptionFields.mk[XmlPredicate2](RootOptionFields[Spec].fields, RootOptionFields[Spec].isOptionItself) + implicit val xmlPredicateRootOptionFields: RootOptionFields[XmlPredicate] = + RootOptionFields.mk[XmlPredicate](RootOptionFields[Spec].fields, RootOptionFields[Spec].isOptionItself) /** * @param description @@ -70,7 +70,7 @@ object XmlPredicate2 { */ def apply( description: Spec - ): ValidatedNel[PredicateConstructionError, XmlPredicate2] = + ): ValidatedNel[PredicateConstructionError, XmlPredicate] = description.toVector .map { case (xPath, spec) => spec.toVector @@ -83,7 +83,7 @@ object XmlPredicate2 { .reduceOption(_ |+| _) .getOrElse(Validated.valid((_: NodeSeq) => true)) .map(f => - new XmlPredicate2 { + new XmlPredicate { override val definition: Map[SXpath, Map[Keyword.Xml, Json]] = description override def apply(xml: NodeSeq): Boolean = f(xml) diff --git a/backend/mockingbird/src/test/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicateSpec2.scala b/backend/mockingbird/src/test/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicateSpec.scala similarity index 79% rename from backend/mockingbird/src/test/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicateSpec2.scala rename to backend/mockingbird/src/test/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicateSpec.scala index 8604714f..7ec9ec8c 100644 --- a/backend/mockingbird/src/test/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicateSpec2.scala +++ b/backend/mockingbird/src/test/scala/ru/tinkoff/tcb/predicatedsl/xml/XmlPredicateSpec.scala @@ -11,13 +11,13 @@ import ru.tinkoff.tcb.predicatedsl.Keyword import ru.tinkoff.tcb.predicatedsl.SpecificationError import ru.tinkoff.tcb.xpath.* -class XmlPredicateSpec2 extends AnyFunSuite with Matchers with EitherValues { +class XmlPredicateSpec extends AnyFunSuite with Matchers with EitherValues { test("XmlPredicate should produce validator from correct specification") { val spec = Json.obj( "/tag1" := Json.obj("==" := "test") ) - val sut = XmlPredicate2(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toEither + val sut = XmlPredicate(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toEither sut shouldBe Symbol("right") } @@ -27,7 +27,7 @@ class XmlPredicateSpec2 extends AnyFunSuite with Matchers with EitherValues { "/tag1" := Json.obj(">=" := "test") ) - val sut = XmlPredicate2(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toEither + val sut = XmlPredicate(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toEither sut shouldBe Left( NonEmptyList.one( @@ -42,7 +42,7 @@ class XmlPredicateSpec2 extends AnyFunSuite with Matchers with EitherValues { // "/root/tag2" := Json.obj("==" := 42) ) - val sut = XmlPredicate2(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption + val sut = XmlPredicate(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption sut.map(_(test42)) shouldBe Some(true) sut.map(_(peka42)) shouldBe Some(false) @@ -54,7 +54,7 @@ class XmlPredicateSpec2 extends AnyFunSuite with Matchers with EitherValues { "/root/tag2" := Json.obj("!=" := 42) ) - val sut = XmlPredicate2(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption + val sut = XmlPredicate(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption sut.map(_(test42)) shouldBe Some(false) sut.map(_(peka99)) shouldBe Some(true) @@ -65,7 +65,7 @@ class XmlPredicateSpec2 extends AnyFunSuite with Matchers with EitherValues { "/f" := Json.obj(">" := 42) ) - val sut = XmlPredicate2(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption + val sut = XmlPredicate(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption sut.map(_(43)) shouldBe Some(true) sut.map(_(42)) shouldBe Some(false) @@ -76,7 +76,7 @@ class XmlPredicateSpec2 extends AnyFunSuite with Matchers with EitherValues { "/f" := Json.obj(">=" := 42) ) - val sut = XmlPredicate2(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption + val sut = XmlPredicate(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption sut.map(_(43)) shouldBe Some(true) sut.map(_(42)) shouldBe Some(true) @@ -88,7 +88,7 @@ class XmlPredicateSpec2 extends AnyFunSuite with Matchers with EitherValues { "/f" := Json.obj("<" := 42) ) - val sut = XmlPredicate2(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption + val sut = XmlPredicate(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption sut.map(_(42)) shouldBe Some(false) sut.map(_(41)) shouldBe Some(true) @@ -99,7 +99,7 @@ class XmlPredicateSpec2 extends AnyFunSuite with Matchers with EitherValues { "/f" := Json.obj("<=" := 42) ) - val sut = XmlPredicate2(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption + val sut = XmlPredicate(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption sut.map(_(43)) shouldBe Some(false) sut.map(_(42)) shouldBe Some(true) @@ -111,7 +111,7 @@ class XmlPredicateSpec2 extends AnyFunSuite with Matchers with EitherValues { "/f" := Json.obj(">" := 40, "<=" := 45, "!=" := 43) ) - val sut = XmlPredicate2(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption + val sut = XmlPredicate(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption sut.map(_(39)) shouldBe Some(false) sut.map(_(40)) shouldBe Some(false) @@ -128,7 +128,7 @@ class XmlPredicateSpec2 extends AnyFunSuite with Matchers with EitherValues { "f" := Json.obj("~=" := "\\d{4,}") ) - val sut = XmlPredicate2(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption + val sut = XmlPredicate(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption sut.map(_(123)) shouldBe Some(false) sut.map(_(1234)) shouldBe Some(true) @@ -141,7 +141,7 @@ class XmlPredicateSpec2 extends AnyFunSuite with Matchers with EitherValues { "/f" := Json.obj("size" := 4) ) - val sut = XmlPredicate2(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption + val sut = XmlPredicate(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption sut.map(_(123)) shouldBe Some(false) sut.map(_(1234)) shouldBe Some(true) @@ -153,7 +153,7 @@ class XmlPredicateSpec2 extends AnyFunSuite with Matchers with EitherValues { "/f" := Json.obj("exists" := true) ) - val sut = XmlPredicate2(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption + val sut = XmlPredicate(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption sut.map(_(123)) shouldBe Some(true) sut.map(_()) shouldBe Some(true) @@ -165,7 +165,7 @@ class XmlPredicateSpec2 extends AnyFunSuite with Matchers with EitherValues { "/f" := Json.obj("exists" := false) ) - val sut = XmlPredicate2(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption + val sut = XmlPredicate(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption sut.map(_(123)) shouldBe Some(false) sut.map(_()) shouldBe Some(false) @@ -181,7 +181,7 @@ class XmlPredicateSpec2 extends AnyFunSuite with Matchers with EitherValues { ) ) - val sut = XmlPredicate2(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption + val sut = XmlPredicate(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption sut.map(_()) shouldBe Some(true) sut.map(_( )) shouldBe Some(false) @@ -197,7 +197,7 @@ class XmlPredicateSpec2 extends AnyFunSuite with Matchers with EitherValues { ) ) - val sut = XmlPredicate2(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption + val sut = XmlPredicate(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption sut.map(_()) shouldBe Some(true) sut.map(_()) shouldBe Some(false) @@ -215,7 +215,7 @@ class XmlPredicateSpec2 extends AnyFunSuite with Matchers with EitherValues { ) ) - val sut = XmlPredicate2(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption + val sut = XmlPredicate(spec.as[Map[SXpath, Map[Keyword.Xml, Json]]].value).toOption sut.map(_(