diff --git a/src/main/scala/dev/code_n_roll/gatling/jdbc/Predef.scala b/src/main/scala/dev/code_n_roll/gatling/jdbc/Predef.scala index c26c0fa..1c08ec9 100644 --- a/src/main/scala/dev/code_n_roll/gatling/jdbc/Predef.scala +++ b/src/main/scala/dev/code_n_roll/gatling/jdbc/Predef.scala @@ -5,6 +5,7 @@ package dev.code_n_roll.gatling.jdbc */ object Predef extends JdbcDsl { + @Deprecated type ManyAnyResult = List[Map[String, Any]] } diff --git a/src/main/scala/dev/code_n_roll/gatling/jdbc/check/JdbcCheckSupport.scala b/src/main/scala/dev/code_n_roll/gatling/jdbc/check/JdbcCheckSupport.scala index 1215b30..c32c638 100644 --- a/src/main/scala/dev/code_n_roll/gatling/jdbc/check/JdbcCheckSupport.scala +++ b/src/main/scala/dev/code_n_roll/gatling/jdbc/check/JdbcCheckSupport.scala @@ -13,29 +13,34 @@ trait JdbcCheckSupport { def simpleCheck = JdbcSimpleCheck + @Deprecated val jdbcSingleResponse = singleResponse[Map[String, Any]] def singleResponse[T]: DefaultFindCheckBuilder[JdbcSingleTCheck.JdbcSingleTCheckType, T, T] = JdbcSingleTCheck.singleTResult[T] implicit def jdbcSingleTCheckMaterializer[T]: CheckMaterializer[JdbcSingleTCheck.JdbcSingleTCheckType, JdbcCheck[T], List[T], T] = JdbcSingleTCheck.singleTCheckMaterializer[T] - val jdbcManyResponse = JdbcManyAnyCheck.ManyAnyResults - implicit val jdbcManyCheckMaterializer: CheckMaterializer[JdbcManyAnyCheck.JdbcManyAnyCheckType, JdbcCheck[Map[String, Any]], ManyAnyResult, ManyAnyResult] = JdbcManyAnyCheck.ManyAnyCheckMaterializer + @Deprecated + val jdbcManyResponse = manyResponse[Map[String, Any]] - @implicitNotFound("Could not find a CheckMaterializer. This check might not be valid for JDBC.") - implicit def findCheckBuilder2JdbcCheck[A, P, X](findCheckBuilder: FindCheckBuilder[A, P, X])(implicit CheckMaterializer: CheckMaterializer[A, JdbcCheck[Map[String, Any]], ManyAnyResult, P]): JdbcCheck[Map[String, Any]] = - findCheckBuilder.find.exists + def manyResponse[T]: DefaultFindCheckBuilder[JdbcManyTCheck.JdbcManyTCheckType, List[T], List[T]] = JdbcManyTCheck.manyTResults[T] + + implicit def jdbcTCheckMaterializer[T]: CheckMaterializer[JdbcManyTCheck.JdbcManyTCheckType, JdbcCheck[T], List[T], List[T]] = JdbcManyTCheck.manyTCheckMaterializer[T] @implicitNotFound("Could not find a CheckMaterializer. This check might not be valid for JDBC.") - implicit def findTypedCheckBuilder2JdbcCheck[A, P, X](findCheckBuilder: FindCheckBuilder[A, P, X])(implicit CheckMaterializer: CheckMaterializer[A, JdbcCheck[P], List[P], P]): JdbcCheck[P] = + implicit def findCheckBuilder2JdbcCheck[A, P, X](findCheckBuilder: FindCheckBuilder[A, P, X])(implicit CheckMaterializer: CheckMaterializer[A, JdbcCheck[P], List[P], P]): JdbcCheck[P] = findCheckBuilder.find.exists @implicitNotFound("Could not find a CheckMaterializer. This check might not be valid for JDBC.") - implicit def checkBuilder2JdbcCheck[A, P, X](checkBuilder: CheckBuilder[A, P, X])(implicit materializer: CheckMaterializer[A, JdbcCheck[Map[String, Any]], ManyAnyResult, P]): JdbcCheck[Map[String, Any]] = + implicit def checkBuilder2JdbcCheck[A, P, X](checkBuilder: CheckBuilder[A, P, X])(implicit materializer: CheckMaterializer[A, JdbcCheck[P], List[P], P]): JdbcCheck[P] = checkBuilder.build(materializer) @implicitNotFound("Could not find a CheckMaterializer. This check might not be valid for JDBC.") - implicit def typedCheckBuilder2JdbcCheck[A, P, X](checkBuilder: CheckBuilder[A, P, X])(implicit materializer: CheckMaterializer[A, JdbcCheck[P], List[P], P]): JdbcCheck[P] = + implicit def findManyCheckBuilder2JdbcCheck[A, P, X](findCheckBuilder: FindCheckBuilder[A, List[P], X])(implicit CheckMaterializer: CheckMaterializer[A, JdbcCheck[P], List[P], List[P]]): JdbcCheck[P] = + findCheckBuilder.find.exists + + @implicitNotFound("Could not find a CheckMaterializer. This check might not be valid for JDBC.") + implicit def checkManyBuilder2JdbcCheck[A, P, X](checkBuilder: CheckBuilder[A, List[P], X])(implicit materializer: CheckMaterializer[A, JdbcCheck[P], List[P], List[P]]): JdbcCheck[P] = checkBuilder.build(materializer) } \ No newline at end of file diff --git a/src/main/scala/dev/code_n_roll/gatling/jdbc/check/JdbcManyAnyCheck.scala b/src/main/scala/dev/code_n_roll/gatling/jdbc/check/JdbcManyAnyCheck.scala deleted file mode 100644 index 8efc578..0000000 --- a/src/main/scala/dev/code_n_roll/gatling/jdbc/check/JdbcManyAnyCheck.scala +++ /dev/null @@ -1,35 +0,0 @@ -package dev.code_n_roll.gatling.jdbc.check - -import java.util - -import dev.code_n_roll.gatling.jdbc.JdbcCheck -import dev.code_n_roll.gatling.jdbc.Predef.ManyAnyResult -import io.gatling.commons.validation.{Validation, _} -import io.gatling.core.check.extractor.{Extractor, FindAllArity} -import io.gatling.core.check._ -import io.gatling.core.session.{Expression, _} - -object JdbcManyAnyCheck { - - trait JdbcManyAnyCheckType - - val ManyAnyPreparer: Preparer[ManyAnyResult, ManyAnyResult] = something => something.success - - val ManyAnyCheckMaterializer: CheckMaterializer[JdbcManyAnyCheckType, JdbcCheck[Map[String, Any]], ManyAnyResult, ManyAnyResult] = new CheckMaterializer[JdbcManyAnyCheckType, JdbcCheck[Map[String, Any]], ManyAnyResult, ManyAnyResult] { - override protected def preparer: Preparer[ManyAnyResult, ManyAnyResult] = ManyAnyPreparer - - override protected def specializer: Specializer[JdbcCheck[Map[String, Any]], ManyAnyResult] = identity - } - - val ManyAnyExtractor: Expression[Extractor[ManyAnyResult, ManyAnyResult] with FindAllArity] = - new Extractor[ManyAnyResult, ManyAnyResult] with FindAllArity { - override def name: String = "manyAny" - - override def apply(prepared: ManyAnyResult): Validation[Option[ManyAnyResult]] = Some(prepared).success - }.expressionSuccess - - val ManyAnyResults = new DefaultFindCheckBuilder[JdbcManyAnyCheckType, ManyAnyResult, ManyAnyResult]( - ManyAnyExtractor, - displayActualValue = true - ) -} diff --git a/src/main/scala/dev/code_n_roll/gatling/jdbc/check/JdbcManyTCheck.scala b/src/main/scala/dev/code_n_roll/gatling/jdbc/check/JdbcManyTCheck.scala new file mode 100644 index 0000000..7368adf --- /dev/null +++ b/src/main/scala/dev/code_n_roll/gatling/jdbc/check/JdbcManyTCheck.scala @@ -0,0 +1,33 @@ +package dev.code_n_roll.gatling.jdbc.check + +import dev.code_n_roll.gatling.jdbc.JdbcCheck +import dev.code_n_roll.gatling.jdbc.Predef.ManyAnyResult +import io.gatling.commons.validation.{Validation, _} +import io.gatling.core.check._ +import io.gatling.core.check.extractor.{Extractor, FindAllArity} +import io.gatling.core.session.{Expression, _} + +object JdbcManyTCheck { + + trait JdbcManyTCheckType + + def manyTPreparer[T]: Preparer[List[T], List[T]] = something => something.success + + def manyTCheckMaterializer[T]: CheckMaterializer[JdbcManyTCheckType, JdbcCheck[T], List[T], List[T]] = new CheckMaterializer[JdbcManyTCheckType, JdbcCheck[T], List[T], List[T]] { + override protected def preparer: Preparer[List[T], List[T]] = manyTPreparer + + override protected def specializer: Specializer[JdbcCheck[T], List[T]] = identity + } + + def manyTExtractor[T]: Expression[Extractor[List[T], List[T]] with FindAllArity] = + new Extractor[List[T], List[T]] with FindAllArity { + override def name: String = "manyT" + + override def apply(prepared: List[T]): Validation[Option[List[T]]] = Some(prepared).success + }.expressionSuccess + + def manyTResults[T] = new DefaultFindCheckBuilder[JdbcManyTCheckType, List[T], List[T]]( + manyTExtractor, + displayActualValue = true + ) +} diff --git a/src/main/scala/dev/code_n_roll/gatling/jdbc/check/JdbcSingleTCheck.scala b/src/main/scala/dev/code_n_roll/gatling/jdbc/check/JdbcSingleTCheck.scala index 9fc9ed7..4b26afd 100644 --- a/src/main/scala/dev/code_n_roll/gatling/jdbc/check/JdbcSingleTCheck.scala +++ b/src/main/scala/dev/code_n_roll/gatling/jdbc/check/JdbcSingleTCheck.scala @@ -13,7 +13,7 @@ object JdbcSingleTCheck { trait JdbcSingleTCheckType - def singleTPreparer[T]: Preparer[List[T], T] = something => something.head.asInstanceOf[T].success + def singleTPreparer[T]: Preparer[List[T], T] = something => something.head.success def singleTCheckMaterializer[T]: CheckMaterializer[JdbcSingleTCheckType, JdbcCheck[T], List[T], T] = new CheckMaterializer[JdbcSingleTCheckType, JdbcCheck[T], List[T], T] { override protected def preparer: Preparer[List[T], T] = singleTPreparer[T] @@ -23,7 +23,7 @@ object JdbcSingleTCheck { def singleTExtractor[T]: Expression[Extractor[T, T] with SingleArity] = new Extractor[T, T] with SingleArity { - override def name: String = "singleAny" + override def name: String = "singleT" override def apply(prepared: T): Validation[Option[T]] = Some(prepared).success }.expressionSuccess diff --git a/src/test/scala/dev/code_n_roll/gatling/jdbc/simulation/SelectTypedCheckSimulation.scala b/src/test/scala/dev/code_n_roll/gatling/jdbc/simulation/SelectTypedCheckSimulation.scala index 7984357..e19d5c0 100644 --- a/src/test/scala/dev/code_n_roll/gatling/jdbc/simulation/SelectTypedCheckSimulation.scala +++ b/src/test/scala/dev/code_n_roll/gatling/jdbc/simulation/SelectTypedCheckSimulation.scala @@ -42,16 +42,17 @@ class SelectTypedCheckSimulation extends Simulation { .from("bar") .where("abc=4") .mapResult(rs => Stored(rs.int("abc"), rs.int("foo"))) - .check(singleResponse[Stored].is(Stored(4,4)) + .check(singleResponse[Stored].is(Stored(4, 4)) .saveAs("myResult")) ).pause(1). exec(jdbc("selectionManyCheck") .select("*") .from("bar") .where("abc=4 OR abc=5") - .check(jdbcManyResponse.is(List( - Map("ABC" -> 4, "FOO" -> 4), - Map("ABC" -> 5, "FOO" -> 5))) + .mapResult(rs => Stored(rs.int("abc"), rs.int("foo"))) + .check(manyResponse[Stored].is(List( + Stored(4, 4), + Stored(5, 5))) ) ) //.exec(session => session("something").as[List[Map[String, Any]]])