aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/xyz/driver/pdsuicommon
diff options
context:
space:
mode:
authorvlad <vlad@driver.xyz>2017-06-13 16:15:07 -0700
committervlad <vlad@driver.xyz>2017-06-13 16:15:07 -0700
commit91a4120b4253dc4a1e9552ec39fcb25c303a21e1 (patch)
tree9173797ed8e3d780f98ac8d0f85507eeb10c8016 /src/test/scala/xyz/driver/pdsuicommon
parentcd1b635b2ae90d9ac2d8b1779183a1fbd8c5fd5c (diff)
downloadrest-query-91a4120b4253dc4a1e9552ec39fcb25c303a21e1.tar.gz
rest-query-91a4120b4253dc4a1e9552ec39fcb25c303a21e1.tar.bz2
rest-query-91a4120b4253dc4a1e9552ec39fcb25c303a21e1.zip
Scalafmtv0.1.2v0.1.1
Diffstat (limited to 'src/test/scala/xyz/driver/pdsuicommon')
-rw-r--r--src/test/scala/xyz/driver/pdsuicommon/BaseSuite.scala6
-rw-r--r--src/test/scala/xyz/driver/pdsuicommon/Mocks.scala25
-rw-r--r--src/test/scala/xyz/driver/pdsuicommon/concurrent/BridgeUploadQueueRepositoryAdapterSuite.scala59
-rw-r--r--src/test/scala/xyz/driver/pdsuicommon/db/QueryBuilderParametersSuite.scala323
-rw-r--r--src/test/scala/xyz/driver/pdsuicommon/db/SearchFilterExprSuite.scala20
-rw-r--r--src/test/scala/xyz/driver/pdsuicommon/logging/PhiStringContextSuite.scala2
-rw-r--r--src/test/scala/xyz/driver/pdsuicommon/utils/DiffUtils.scala4
7 files changed, 252 insertions, 187 deletions
diff --git a/src/test/scala/xyz/driver/pdsuicommon/BaseSuite.scala b/src/test/scala/xyz/driver/pdsuicommon/BaseSuite.scala
index 78a9168..656ee24 100644
--- a/src/test/scala/xyz/driver/pdsuicommon/BaseSuite.scala
+++ b/src/test/scala/xyz/driver/pdsuicommon/BaseSuite.scala
@@ -16,11 +16,9 @@ import scala.concurrent.Future
trait BaseSuite extends FreeSpecLike with DiffUtils with ScalaFutures {
implicit val defaultPatience = PatienceConfig(timeout = Span(1000, Millis), interval = Span(20, Millis))
- implicit val sqlContext = new MockSqlContext(global)
+ implicit val sqlContext = new MockSqlContext(global)
- def sampleUser(role: User.Role,
- email: String = "test@example.com",
- password: String = "123") = User(
+ def sampleUser(role: User.Role, email: String = "test@example.com", password: String = "123") = User(
id = LongId(2001),
email = Email(email),
name = "Test",
diff --git a/src/test/scala/xyz/driver/pdsuicommon/Mocks.scala b/src/test/scala/xyz/driver/pdsuicommon/Mocks.scala
index 2154e3d..d4b4d3c 100644
--- a/src/test/scala/xyz/driver/pdsuicommon/Mocks.scala
+++ b/src/test/scala/xyz/driver/pdsuicommon/Mocks.scala
@@ -17,13 +17,13 @@ class MockDataSource extends DataSource with Closeable {
override def getConnection(username: String, password: String): Connection = {
throw new NotImplementedError(s"MockDataSource.getConnection($username, $password)")
}
- override def close(): Unit = throw new NotImplementedError("MockDataSource.close")
- override def setLogWriter(out: PrintWriter): Unit = throw new NotImplementedError("MockDataSource.setLogWriter")
- override def getLoginTimeout: Int = throw new NotImplementedError("MockDataSource.getLoginTimeout")
- override def setLoginTimeout(seconds: Int): Unit = throw new NotImplementedError("MockDataSource.setLoginTimeout")
- override def getParentLogger: Logger = throw new NotImplementedError("MockDataSource.getParentLogger")
- override def getLogWriter: PrintWriter = throw new NotImplementedError("MockDataSource.getLogWriter")
- override def unwrap[T](iface: Class[T]): T = throw new NotImplementedError("MockDataSource.unwrap")
+ override def close(): Unit = throw new NotImplementedError("MockDataSource.close")
+ override def setLogWriter(out: PrintWriter): Unit = throw new NotImplementedError("MockDataSource.setLogWriter")
+ override def getLoginTimeout: Int = throw new NotImplementedError("MockDataSource.getLoginTimeout")
+ override def setLoginTimeout(seconds: Int): Unit = throw new NotImplementedError("MockDataSource.setLoginTimeout")
+ override def getParentLogger: Logger = throw new NotImplementedError("MockDataSource.getParentLogger")
+ override def getLogWriter: PrintWriter = throw new NotImplementedError("MockDataSource.getLogWriter")
+ override def unwrap[T](iface: Class[T]): T = throw new NotImplementedError("MockDataSource.unwrap")
override def isWrapperFor(iface: Class[_]): Boolean = throw new NotImplementedError("MockDataSource.isWrapperFor")
}
@@ -63,13 +63,13 @@ class MockFactory()(implicit val sqlContext: SqlContext) {
object MockQueryBuilder {
- type MockRunnerIn = (SearchFilterExpr, Sorting, Option[Pagination])
- type MockRunnerOut[T] = Future[Seq[T]]
+ type MockRunnerIn = (SearchFilterExpr, Sorting, Option[Pagination])
+ type MockRunnerOut[T] = Future[Seq[T]]
type MockCountRunnerOut = Future[QueryBuilder.CountResult]
- def apply[T](matcher: PartialFunction[MockRunnerIn, MockRunnerOut[T]])
- (countMatcher: PartialFunction[MockRunnerIn, MockCountRunnerOut])
- (implicit context: SqlContext): MysqlQueryBuilder[T] = {
+ def apply[T](matcher: PartialFunction[MockRunnerIn, MockRunnerOut[T]])(
+ countMatcher: PartialFunction[MockRunnerIn, MockCountRunnerOut])(
+ implicit context: SqlContext): MysqlQueryBuilder[T] = {
def runner(parameters: QueryBuilderParameters): MockRunnerOut[T] = {
matcher((parameters.filter, parameters.sorting, parameters.pagination))
}
@@ -86,4 +86,3 @@ object MockQueryBuilder {
)(context.executionContext)
}
}
-
diff --git a/src/test/scala/xyz/driver/pdsuicommon/concurrent/BridgeUploadQueueRepositoryAdapterSuite.scala b/src/test/scala/xyz/driver/pdsuicommon/concurrent/BridgeUploadQueueRepositoryAdapterSuite.scala
index c0bb1a2..48a4eaf 100644
--- a/src/test/scala/xyz/driver/pdsuicommon/concurrent/BridgeUploadQueueRepositoryAdapterSuite.scala
+++ b/src/test/scala/xyz/driver/pdsuicommon/concurrent/BridgeUploadQueueRepositoryAdapterSuite.scala
@@ -29,11 +29,11 @@ class BridgeUploadQueueRepositoryAdapterSuite extends BaseSuite {
"a new interval should be greater than the previous one if the limit not reached" in {
val previous = strategy.on(1)
- val current = strategy.on(2)
+ val current = strategy.on(2)
(previous, current) match {
case (OnAttempt.Continue(a), OnAttempt.Continue(b)) => assert(a < b)
- case x => fail(s"Unexpected result: $x")
+ case x => fail(s"Unexpected result: $x")
}
}
@@ -52,11 +52,12 @@ class BridgeUploadQueueRepositoryAdapterSuite extends BaseSuite {
"should return an updated item" in {
val repository = new BridgeUploadQueueRepository {
- override def update(draft: EntityT): EntityT = draft
- override def delete(id: IdT): Unit = {}
- override def add(draft: EntityT): EntityT = fail("add should not be used!")
+ override def update(draft: EntityT): EntityT = draft
+ override def delete(id: IdT): Unit = {}
+ override def add(draft: EntityT): EntityT = fail("add should not be used!")
override def getById(id: LongId[EntityT]): Option[EntityT] = fail("getById should not be used!")
- override def isCompleted(kind: String, tag: String): Future[Boolean] = fail("isCompleted should not be used!")
+ override def isCompleted(kind: String, tag: String): Future[Boolean] =
+ fail("isCompleted should not be used!")
override def getOne(kind: String): Future[Option[Item]] = fail("getOne should not be used!")
}
@@ -67,7 +68,7 @@ class BridgeUploadQueueRepositoryAdapterSuite extends BaseSuite {
)
val item = defaultItem
- val r = adapter.tryRetry(item).futureValue
+ val r = adapter.tryRetry(item).futureValue
assert(r.isDefined)
assert(!r.contains(item))
}
@@ -80,10 +81,11 @@ class BridgeUploadQueueRepositoryAdapterSuite extends BaseSuite {
assert(draft.attempts === (item.attempts + 1), "repository.add")
draft
}
- override def delete(id: IdT): Unit = {}
- override def add(draft: EntityT): EntityT = fail("add should not be used!")
+ override def delete(id: IdT): Unit = {}
+ override def add(draft: EntityT): EntityT = fail("add should not be used!")
override def getById(id: LongId[EntityT]): Option[EntityT] = fail("getById should not be used!")
- override def isCompleted(kind: String, tag: String): Future[Boolean] = fail("isCompleted should not be used!")
+ override def isCompleted(kind: String, tag: String): Future[Boolean] =
+ fail("isCompleted should not be used!")
override def getOne(kind: String): Future[Option[Item]] = fail("getOne should not be used!")
}
@@ -104,9 +106,10 @@ class BridgeUploadQueueRepositoryAdapterSuite extends BaseSuite {
override def delete(id: IdT): Unit = {
assert(id == item.id, "repository.delete")
}
- override def add(draft: EntityT): EntityT = fail("add should not be used!")
+ override def add(draft: EntityT): EntityT = fail("add should not be used!")
override def getById(id: LongId[EntityT]): Option[EntityT] = fail("getById should not be used!")
- override def isCompleted(kind: String, tag: String): Future[Boolean] = fail("isCompleted should not be used!")
+ override def isCompleted(kind: String, tag: String): Future[Boolean] =
+ fail("isCompleted should not be used!")
override def getOne(kind: String): Future[Option[Item]] = fail("getOne should not be used!")
}
@@ -127,10 +130,11 @@ class BridgeUploadQueueRepositoryAdapterSuite extends BaseSuite {
assert(draft.nextAttempt.isAfter(item.nextAttempt), "repository.add")
draft
}
- override def delete(id: IdT): Unit = {}
- override def add(draft: EntityT): EntityT = fail("add should not be used!")
+ override def delete(id: IdT): Unit = {}
+ override def add(draft: EntityT): EntityT = fail("add should not be used!")
override def getById(id: LongId[EntityT]): Option[EntityT] = fail("getById should not be used!")
- override def isCompleted(kind: String, tag: String): Future[Boolean] = fail("isCompleted should not be used!")
+ override def isCompleted(kind: String, tag: String): Future[Boolean] =
+ fail("isCompleted should not be used!")
override def getOne(kind: String): Future[Option[Item]] = fail("getOne should not be used!")
}
@@ -151,11 +155,12 @@ class BridgeUploadQueueRepositoryAdapterSuite extends BaseSuite {
"should not return an item" in {
val repository = new BridgeUploadQueueRepository {
- override def delete(id: IdT): Unit = {}
- override def update(entity: EntityT): EntityT = fail("update should not be used!")
- override def add(draft: EntityT): EntityT = fail("add should not be used!")
+ override def delete(id: IdT): Unit = {}
+ override def update(entity: EntityT): EntityT = fail("update should not be used!")
+ override def add(draft: EntityT): EntityT = fail("add should not be used!")
override def getById(id: LongId[EntityT]): Option[EntityT] = fail("getById should not be used!")
- override def isCompleted(kind: String, tag: String): Future[Boolean] = fail("isCompleted should not be used!")
+ override def isCompleted(kind: String, tag: String): Future[Boolean] =
+ fail("isCompleted should not be used!")
override def getOne(kind: String): Future[Option[Item]] = fail("getOne should not be used!")
}
@@ -171,11 +176,12 @@ class BridgeUploadQueueRepositoryAdapterSuite extends BaseSuite {
"should not add any item to the queue" in {
val repository = new BridgeUploadQueueRepository {
- override def update(draft: EntityT): EntityT = throw new IllegalAccessException("add should not be called")
- override def delete(id: IdT): Unit = {}
- override def add(draft: EntityT): EntityT = fail("add should not be used!")
+ override def update(draft: EntityT): EntityT = throw new IllegalAccessException("add should not be called")
+ override def delete(id: IdT): Unit = {}
+ override def add(draft: EntityT): EntityT = fail("add should not be used!")
override def getById(id: LongId[EntityT]): Option[EntityT] = fail("getById should not be used!")
- override def isCompleted(kind: String, tag: String): Future[Boolean] = fail("isCompleted should not be used!")
+ override def isCompleted(kind: String, tag: String): Future[Boolean] =
+ fail("isCompleted should not be used!")
override def getOne(kind: String): Future[Option[Item]] = fail("getOne should not be used!")
}
@@ -193,10 +199,11 @@ class BridgeUploadQueueRepositoryAdapterSuite extends BaseSuite {
override def delete(id: IdT): Unit = {
assert(id == defaultItem.id, "repository.delete")
}
- override def update(entity: EntityT): EntityT = fail("update should not be used!")
- override def add(draft: EntityT): EntityT = fail("add should not be used!")
+ override def update(entity: EntityT): EntityT = fail("update should not be used!")
+ override def add(draft: EntityT): EntityT = fail("add should not be used!")
override def getById(id: LongId[EntityT]): Option[EntityT] = fail("getById should not be used!")
- override def isCompleted(kind: String, tag: String): Future[Boolean] = fail("isCompleted should not be used!")
+ override def isCompleted(kind: String, tag: String): Future[Boolean] =
+ fail("isCompleted should not be used!")
override def getOne(kind: String): Future[Option[Item]] = fail("getOne should not be used!")
}
diff --git a/src/test/scala/xyz/driver/pdsuicommon/db/QueryBuilderParametersSuite.scala b/src/test/scala/xyz/driver/pdsuicommon/db/QueryBuilderParametersSuite.scala
index 0748e8a..df8e417 100644
--- a/src/test/scala/xyz/driver/pdsuicommon/db/QueryBuilderParametersSuite.scala
+++ b/src/test/scala/xyz/driver/pdsuicommon/db/QueryBuilderParametersSuite.scala
@@ -38,7 +38,7 @@ class QueryBuilderParametersSuite extends FreeSpecLike {
val queryBasis =
s"""select `$tableName`.*
- |from `$tableName`""".stripMargin.trim
+ |from `$tableName`""".stripMargin.trim
"toSql" - {
"should generate correct SQL query" - {
@@ -49,89 +49,120 @@ class QueryBuilderParametersSuite extends FreeSpecLike {
"with filtering: " - {
"single atom filter" in {
- val (sql, _) = queryBuilderParameters.copy(filter = Atom.Binary("name", Eq, "x")).toSql(namingStrategy = MysqlEscape)
- assert(sql ==
- s"""$queryBasis
- |where `$tableName`.`name` = ?""".stripMargin)
+ val (sql, _) =
+ queryBuilderParameters.copy(filter = Atom.Binary("name", Eq, "x")).toSql(namingStrategy = MysqlEscape)
+ assert(
+ sql ==
+ s"""$queryBasis
+ |where `$tableName`.`name` = ?""".stripMargin)
}
"single atom filter for optional field with NotEq operation" in {
- val (sql, _) = queryBuilderParameters.copy(filter = Atom.Binary("optionUser", NotEq, "x")).toSql(namingStrategy = MysqlEscape)
- assert(sql ==
- s"""$queryBasis
- |where (`$tableName`.`optionUser` is null or `$tableName`.`optionUser` != ?)""".stripMargin)
+ val (sql, _) = queryBuilderParameters
+ .copy(filter = Atom.Binary("optionUser", NotEq, "x"))
+ .toSql(namingStrategy = MysqlEscape)
+ assert(
+ sql ==
+ s"""$queryBasis
+ |where (`$tableName`.`optionUser` is null or `$tableName`.`optionUser` != ?)""".stripMargin)
}
"single atom filter for field with IN operation" in {
- val (sql, _) = queryBuilderParameters.copy(filter = Atom.NAry("date", In, Seq("x", "x", "x"))).toSql(namingStrategy = MysqlEscape)
- assert(sql ==
- s"""$queryBasis
- |where `$tableName`.`date` in (?, ?, ?)""".stripMargin)
+ val (sql, _) = queryBuilderParameters
+ .copy(filter = Atom.NAry("date", In, Seq("x", "x", "x")))
+ .toSql(namingStrategy = MysqlEscape)
+ assert(
+ sql ==
+ s"""$queryBasis
+ |where `$tableName`.`date` in (?, ?, ?)""".stripMargin)
}
"multiple intersected filters" in {
- val (sql, _) = queryBuilderParameters.copy(filter = Intersection(Seq(
- Atom.Binary("name", Gt, "x"),
- Atom.Binary("optionDate", GtEq, "x")
- ))).toSql(namingStrategy = MysqlEscape)
- assert(sql ==
- s"""$queryBasis
- |where (`$tableName`.`name` > ? and `$tableName`.`optionDate` >= ?)""".stripMargin)
+ val (sql, _) = queryBuilderParameters
+ .copy(
+ filter = Intersection(
+ Seq(
+ Atom.Binary("name", Gt, "x"),
+ Atom.Binary("optionDate", GtEq, "x")
+ )))
+ .toSql(namingStrategy = MysqlEscape)
+ assert(
+ sql ==
+ s"""$queryBasis
+ |where (`$tableName`.`name` > ? and `$tableName`.`optionDate` >= ?)""".stripMargin)
}
"multiple intersected nested filters" in {
- val (sql, _) = queryBuilderParameters.copy(filter = Intersection(Seq(
- Atom.Binary("name", Gt, "x"),
- Atom.Binary("optionDate", GtEq, "x"),
- Intersection(Seq(
- Atom.Binary("optionUser", Eq, "x"),
- Atom.Binary("date", LtEq, "x")
- ))
- ))).toSql(namingStrategy = MysqlEscape)
- assert(sql ==
- s"$queryBasis\nwhere (`$tableName`.`name` > ? and `$tableName`.`optionDate` >= ?" +
- s" and (`$tableName`.`optionUser` = ? and `$tableName`.`date` <= ?))")
+ val (sql, _) = queryBuilderParameters
+ .copy(
+ filter = Intersection(
+ Seq(
+ Atom.Binary("name", Gt, "x"),
+ Atom.Binary("optionDate", GtEq, "x"),
+ Intersection(Seq(
+ Atom.Binary("optionUser", Eq, "x"),
+ Atom.Binary("date", LtEq, "x")
+ ))
+ )))
+ .toSql(namingStrategy = MysqlEscape)
+ assert(
+ sql ==
+ s"$queryBasis\nwhere (`$tableName`.`name` > ? and `$tableName`.`optionDate` >= ?" +
+ s" and (`$tableName`.`optionUser` = ? and `$tableName`.`date` <= ?))")
}
"multiple unionized filters" in {
- val (sql, _) = queryBuilderParameters.copy(filter = Union(Seq(
- Atom.Binary("name", Gt, "x"),
- Atom.Binary("optionDate", GtEq, "x")
- ))).toSql(namingStrategy = MysqlEscape)
- assert(sql ==
- s"""$queryBasis
- |where (`$tableName`.`name` > ? or `$tableName`.`optionDate` >= ?)""".stripMargin.trim)
+ val (sql, _) = queryBuilderParameters
+ .copy(
+ filter = Union(
+ Seq(
+ Atom.Binary("name", Gt, "x"),
+ Atom.Binary("optionDate", GtEq, "x")
+ )))
+ .toSql(namingStrategy = MysqlEscape)
+ assert(
+ sql ==
+ s"""$queryBasis
+ |where (`$tableName`.`name` > ? or `$tableName`.`optionDate` >= ?)""".stripMargin.trim)
}
"multiple unionized nested filters" in {
- val (sql, _) = queryBuilderParameters.copy(filter = Union(Seq(
- Atom.Binary("name", Gt, "x"),
- Atom.Binary("optionDate", GtEq, "x"),
- Union(Seq(
- Atom.Binary("optionUser", Eq, "x"),
- Atom.Binary("date", LtEq, "x")
- ))
- ))).toSql(namingStrategy = MysqlEscape)
- assert(sql ==
- s"""$queryBasis
- |where (`$tableName`.`name` > ? or `$tableName`.`optionDate` >= ? or (`$tableName`.`optionUser` = ? or `$tableName`.`date` <= ?))""".stripMargin)
+ val (sql, _) = queryBuilderParameters
+ .copy(
+ filter = Union(
+ Seq(
+ Atom.Binary("name", Gt, "x"),
+ Atom.Binary("optionDate", GtEq, "x"),
+ Union(Seq(
+ Atom.Binary("optionUser", Eq, "x"),
+ Atom.Binary("date", LtEq, "x")
+ ))
+ )))
+ .toSql(namingStrategy = MysqlEscape)
+ assert(
+ sql ==
+ s"""$queryBasis
+ |where (`$tableName`.`name` > ? or `$tableName`.`optionDate` >= ? or (`$tableName`.`optionUser` = ? or `$tableName`.`date` <= ?))""".stripMargin)
}
"multiple unionized and intersected nested filters" in {
- val (sql, _) = queryBuilderParameters.copy(filter = Union(Seq(
- Intersection(Seq(
- Atom.Binary("name", Gt, "x"),
- Atom.Binary("optionDate", GtEq, "x")
- )),
- Intersection(Seq(
- Atom.Binary("optionUser", Eq, "x"),
- Atom.Binary("date", LtEq, "x")
- ))
- ))).toSql(namingStrategy = MysqlEscape)
-
- assert(sql ==
- s"$queryBasis\nwhere ((`$tableName`.`name` > ? and `$tableName`.`optionDate` >= ?) " +
- s"or (`$tableName`.`optionUser` = ? and `$tableName`.`date` <= ?))")
+ val (sql, _) = queryBuilderParameters
+ .copy(filter = Union(Seq(
+ Intersection(Seq(
+ Atom.Binary("name", Gt, "x"),
+ Atom.Binary("optionDate", GtEq, "x")
+ )),
+ Intersection(Seq(
+ Atom.Binary("optionUser", Eq, "x"),
+ Atom.Binary("date", LtEq, "x")
+ ))
+ )))
+ .toSql(namingStrategy = MysqlEscape)
+
+ assert(
+ sql ==
+ s"$queryBasis\nwhere ((`$tableName`.`name` > ? and `$tableName`.`optionDate` >= ?) " +
+ s"or (`$tableName`.`optionUser` = ? and `$tableName`.`date` <= ?))")
}
"single field from foreign table" in {
@@ -149,98 +180,128 @@ class QueryBuilderParametersSuite extends FreeSpecLike {
"with sorting:" - {
"single field sorting" in {
- val (sql, _) = queryBuilderParameters.copy(sorting = Dimension(None, "name", Ascending)).toSql(namingStrategy = MysqlEscape)
+ val (sql, _) = queryBuilderParameters
+ .copy(sorting = Dimension(None, "name", Ascending))
+ .toSql(namingStrategy = MysqlEscape)
- assert(sql ==
- s"""$queryBasis
- |order by `$tableName`.`name` asc""".stripMargin)
+ assert(
+ sql ==
+ s"""$queryBasis
+ |order by `$tableName`.`name` asc""".stripMargin)
}
"single foreign sorting field" in {
- val (sql, _) = queryBuilderParameters.copy(sorting = Dimension(Some("Kind"), "name", Ascending)).toSql(namingStrategy = MysqlEscape)
+ val (sql, _) = queryBuilderParameters
+ .copy(sorting = Dimension(Some("Kind"), "name", Ascending))
+ .toSql(namingStrategy = MysqlEscape)
- assert(sql ==
- s"""select `$tableName`.*
- |from `$tableName`
- |inner join `Kind` on `Entity`.`kindId` = `Kind`.`id`
- |order by `Kind`.`name` asc""".stripMargin)
+ assert(
+ sql ==
+ s"""select `$tableName`.*
+ |from `$tableName`
+ |inner join `Kind` on `Entity`.`kindId` = `Kind`.`id`
+ |order by `Kind`.`name` asc""".stripMargin)
}
"multiple fields sorting" in {
- val (sql, _) = queryBuilderParameters.copy(sorting = Sequential(Seq(
- Dimension(None, "name", Ascending),
- Dimension(None, "date", Descending)
- ))).toSql(namingStrategy = MysqlEscape)
- assert(sql ==
- s"""$queryBasis
- |order by `$tableName`.`name` asc, `$tableName`.`date` desc""".stripMargin)
+ val (sql, _) = queryBuilderParameters
+ .copy(
+ sorting = Sequential(
+ Seq(
+ Dimension(None, "name", Ascending),
+ Dimension(None, "date", Descending)
+ )))
+ .toSql(namingStrategy = MysqlEscape)
+ assert(
+ sql ==
+ s"""$queryBasis
+ |order by `$tableName`.`name` asc, `$tableName`.`date` desc""".stripMargin)
}
"multiple foreign sorting field" in {
- val (sql, _) = queryBuilderParameters.copy(sorting = Sequential(Seq(
- Dimension(Some("Kind"), "name", Ascending),
- Dimension(Some("User"), "name", Descending)
- ))).toSql(namingStrategy = MysqlEscape)
+ val (sql, _) = queryBuilderParameters
+ .copy(
+ sorting = Sequential(
+ Seq(
+ Dimension(Some("Kind"), "name", Ascending),
+ Dimension(Some("User"), "name", Descending)
+ )))
+ .toSql(namingStrategy = MysqlEscape)
- assert(sql ==
- s"""select `$tableName`.*
- |from `$tableName`
- |inner join `Kind` on `$tableName`.`kindId` = `Kind`.`id`
- |inner join `User` on `$tableName`.`optionUser` = `User`.`id`
- |order by `Kind`.`name` asc, `User`.`name` desc""".stripMargin)
+ assert(
+ sql ==
+ s"""select `$tableName`.*
+ |from `$tableName`
+ |inner join `Kind` on `$tableName`.`kindId` = `Kind`.`id`
+ |inner join `User` on `$tableName`.`optionUser` = `User`.`id`
+ |order by `Kind`.`name` asc, `User`.`name` desc""".stripMargin)
}
"multiple field sorting (including foreign tables)" in {
- val (sql, _) = queryBuilderParameters.copy(sorting = Sequential(Seq(
- Dimension(Some("Kind"), "name", Ascending),
- Dimension(None, "date", Descending)
- ))).toSql(namingStrategy = MysqlEscape)
+ val (sql, _) = queryBuilderParameters
+ .copy(
+ sorting = Sequential(
+ Seq(
+ Dimension(Some("Kind"), "name", Ascending),
+ Dimension(None, "date", Descending)
+ )))
+ .toSql(namingStrategy = MysqlEscape)
- assert(sql ==
- s"""select `$tableName`.*
- |from `$tableName`
- |inner join `Kind` on `$tableName`.`kindId` = `Kind`.`id`
- |order by `Kind`.`name` asc, `$tableName`.`date` desc""".stripMargin)
+ assert(
+ sql ==
+ s"""select `$tableName`.*
+ |from `$tableName`
+ |inner join `Kind` on `$tableName`.`kindId` = `Kind`.`id`
+ |order by `Kind`.`name` asc, `$tableName`.`date` desc""".stripMargin)
}
}
"with pagination" in {
- val (sql, _) = queryBuilderParameters.copy(pagination = Some(Pagination(5, 3))).toSql(namingStrategy = MysqlEscape)
- assert(sql ==
- s"""$queryBasis
- |limit 10, 5""".stripMargin)
+ val (sql, _) =
+ queryBuilderParameters.copy(pagination = Some(Pagination(5, 3))).toSql(namingStrategy = MysqlEscape)
+ assert(
+ sql ==
+ s"""$queryBasis
+ |limit 10, 5""".stripMargin)
}
"combined" in {
- val filter = Union(Seq(
- Intersection(Seq(
- Atom.Binary("name", Gt, "x"),
- Atom.Binary("optionDate", GtEq, "x")
- )),
- Intersection(Seq(
- Atom.Binary("optionUser", Eq, "x"),
- Atom.Binary("date", LtEq, "x")
+ val filter = Union(
+ Seq(
+ Intersection(
+ Seq(
+ Atom.Binary("name", Gt, "x"),
+ Atom.Binary("optionDate", GtEq, "x")
+ )),
+ Intersection(
+ Seq(
+ Atom.Binary("optionUser", Eq, "x"),
+ Atom.Binary("date", LtEq, "x")
+ ))
+ ))
+ val sorting = Sequential(
+ Seq(
+ Dimension(Some("Kind"), "name", Ascending),
+ Dimension(None, "name", Ascending),
+ Dimension(None, "date", Descending)
))
- ))
- val sorting = Sequential(Seq(
- Dimension(Some("Kind"), "name", Ascending),
- Dimension(None, "name", Ascending),
- Dimension(None, "date", Descending)
- ))
-
- val (sql, _) = queryBuilderParameters.copy(
- filter = filter,
- sorting = sorting,
- pagination = Some(Pagination(5, 3))
- ).toSql(namingStrategy = MysqlEscape)
-
- assert(sql ==
- s"""select `$tableName`.*
- |from `$tableName`
- |inner join `Kind` on `$tableName`.`kindId` = `Kind`.`id`
- |where ((`$tableName`.`name` > ? and `$tableName`.`optionDate` >= ?) or (`$tableName`.`optionUser` = ? and `$tableName`.`date` <= ?))
- |order by `Kind`.`name` asc, `$tableName`.`name` asc, `$tableName`.`date` desc
- |limit 10, 5""".stripMargin)
+
+ val (sql, _) = queryBuilderParameters
+ .copy(
+ filter = filter,
+ sorting = sorting,
+ pagination = Some(Pagination(5, 3))
+ )
+ .toSql(namingStrategy = MysqlEscape)
+
+ assert(
+ sql ==
+ s"""select `$tableName`.*
+ |from `$tableName`
+ |inner join `Kind` on `$tableName`.`kindId` = `Kind`.`id`
+ |where ((`$tableName`.`name` > ? and `$tableName`.`optionDate` >= ?) or (`$tableName`.`optionUser` = ? and `$tableName`.`date` <= ?))
+ |order by `Kind`.`name` asc, `$tableName`.`name` asc, `$tableName`.`date` desc
+ |limit 10, 5""".stripMargin)
}
}
diff --git a/src/test/scala/xyz/driver/pdsuicommon/db/SearchFilterExprSuite.scala b/src/test/scala/xyz/driver/pdsuicommon/db/SearchFilterExprSuite.scala
index ee467af..35c8d30 100644
--- a/src/test/scala/xyz/driver/pdsuicommon/db/SearchFilterExprSuite.scala
+++ b/src/test/scala/xyz/driver/pdsuicommon/db/SearchFilterExprSuite.scala
@@ -6,14 +6,16 @@ class SearchFilterExprSuite extends FreeSpecLike with MustMatchers {
"replace" - {
"all entities are changed" in {
- val ast = SearchFilterExpr.Union(Seq(
- SearchFilterExpr.Intersection(Seq(
- SearchFilterExpr.Atom.Binary("foo", SearchFilterBinaryOperation.Gt, "10"),
- SearchFilterExpr.Atom.Binary("foo", SearchFilterBinaryOperation.Lt, "20")
- )),
- SearchFilterExpr.Atom.NAry("bar", SearchFilterNAryOperation.In, Seq("x", "y", "z")),
- SearchFilterExpr.Atom.Binary("foo", SearchFilterBinaryOperation.Eq, "40")
- ))
+ val ast = SearchFilterExpr.Union(
+ Seq(
+ SearchFilterExpr.Intersection(
+ Seq(
+ SearchFilterExpr.Atom.Binary("foo", SearchFilterBinaryOperation.Gt, "10"),
+ SearchFilterExpr.Atom.Binary("foo", SearchFilterBinaryOperation.Lt, "20")
+ )),
+ SearchFilterExpr.Atom.NAry("bar", SearchFilterNAryOperation.In, Seq("x", "y", "z")),
+ SearchFilterExpr.Atom.Binary("foo", SearchFilterBinaryOperation.Eq, "40")
+ ))
val newAst = ast.replace {
case x: SearchFilterExpr.Atom.Binary if x.dimension.name == "foo" =>
@@ -22,7 +24,7 @@ class SearchFilterExprSuite extends FreeSpecLike with MustMatchers {
val result = newAst.find {
case x: SearchFilterExpr.Atom.Binary => x.dimension.name == "foo"
- case _ => false
+ case _ => false
}
result mustBe empty
diff --git a/src/test/scala/xyz/driver/pdsuicommon/logging/PhiStringContextSuite.scala b/src/test/scala/xyz/driver/pdsuicommon/logging/PhiStringContextSuite.scala
index f623b81..de1d1bf 100644
--- a/src/test/scala/xyz/driver/pdsuicommon/logging/PhiStringContextSuite.scala
+++ b/src/test/scala/xyz/driver/pdsuicommon/logging/PhiStringContextSuite.scala
@@ -23,7 +23,7 @@ class PhiStringContextSuite extends FreeSpecLike {
)
"should not contain private info" in {
- val foo = new Foo(42, "test")
+ val foo = new Foo(42, "test")
val result = phi"foo is $foo".text
assert(!result.contains("test"))
assert(!result.contains("42"))
diff --git a/src/test/scala/xyz/driver/pdsuicommon/utils/DiffUtils.scala b/src/test/scala/xyz/driver/pdsuicommon/utils/DiffUtils.scala
index d42bca6..5338173 100644
--- a/src/test/scala/xyz/driver/pdsuicommon/utils/DiffUtils.scala
+++ b/src/test/scala/xyz/driver/pdsuicommon/utils/DiffUtils.scala
@@ -9,9 +9,7 @@ import xyz.driver.pdsuicommon.domain.PasswordHash
import scala.io.AnsiColor
-trait DiffUtils {
-
- this: Assertions =>
+trait DiffUtils { this: Assertions =>
def assertIdentical[T: DiffShow](left: T, right: T): Unit = {
val diff = DiffShow.diff(left, right)