Skip to content

Commit

Permalink
test: try to fix ci test problem
Browse files Browse the repository at this point in the history
  • Loading branch information
QuadStingray committed Jan 30, 2025
1 parent a27e03d commit ee5ad9b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main_test_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
mongodb-version: ['4.4', '5.0', '6.0', '7.0']
mongodb-version: ['4.4', '5.0', '6.0', '7.0', '8.0']
java: [ '21', '23' ]
steps:
- uses: actions/checkout@main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/other_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
mongodb-version: [ '4.4', '5.0', '6.0', '7.0' ]
mongodb-version: [ '4.4', '5.0', '6.0', '7.0', '8.0' ]
java: [ '21', '23' ]
steps:
- uses: actions/checkout@main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import dev.mongocamp.driver.mongodb.exception.NotSupportedException
import org.apache.lucene.queryparser.classic.QueryParser
import org.apache.lucene.search._
import org.apache.lucene.search.BooleanClause.Occur
import org.joda.time.DateTime
import org.mongodb.scala.bson.conversions.Bson

import java.text.SimpleDateFormat
import java.util.Date
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.jdk.CollectionConverters._
import scala.util.Try

object LuceneQueryConverter extends LazyLogging {

Expand Down Expand Up @@ -217,25 +219,23 @@ object LuceneQueryConverter extends LazyLogging {
try {
val convertedValue: Option[Any] =
(List() ++ checkOrReturn(() => s.toDouble) ++ checkOrReturn(() => s.toLong) ++ checkOrReturn(() => s.toBoolean)).headOption
convertedValue.getOrElse({
val parsedOptions: Option[Date] = datePatters
.map(pattern => {
try {
val formatter = new SimpleDateFormat(pattern)
Option(formatter.parse(s))
}
catch {
case _: Exception =>
None
}
})
.find(_.nonEmpty)
.flatten
parsedOptions.getOrElse(s)
val response = convertedValue.getOrElse({
val parsedOptions: List[Date] = Try(new DateTime(s).toDate).toOption.toList ++ datePatters.flatMap(pattern => {
try {
val formatter = new SimpleDateFormat(pattern)
Option(formatter.parse(s))
}
catch {
case _: Exception =>
None
}
}).distinct
parsedOptions.headOption.getOrElse(s)
})
response
}
catch {
case _: Exception =>
case _: Throwable =>
s
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class JodaConverterPluginSpec extends Specification with BeforeAfterAll {
"JodaConverterPlugin" should {

"convert joda dates to bson dates" in {
val dateTime = new DateTime("2023-11-02")
val bsonDocument = BsonConverter.toBson(dateTime)
(bsonDocument.toString must be).equalTo("BsonDateTime{value=1698879600000}")
val dateTime = new DateTime("2023-11-02")
val bsonDocument = BsonConverter.toBson(dateTime)
val roundTripDate = new DateTime(bsonDocument.asDateTime().getValue)
(roundTripDate must be).equalTo(dateTime)
}

"convert joda duration to bson string" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,20 @@ class LuceneSearchSpec extends PersonSpecification {

"between filter for date value" in {
val luceneQuery = LuceneQueryConverter.parse("[2014-04-20T00:00:00Z TO 2014-04-22T23:59:59Z]", "registered")
val search = PersonDAO.find(LuceneQueryConverter.toDocument(luceneQuery), sortByBalance).resultList()
search must haveSize(10)
val luceneDocument = LuceneQueryConverter.toDocument(luceneQuery)
val expected = "Iterable((registered,{\"$lte\": {\"$date\": \"2014-04-22T23:59:59Z\"}, \"$gte\": {\"$date\": \"2014-04-20T00:00:00Z\"}}))"
println(luceneDocument.toString)
println(expected)
luceneDocument.toString must beEqualTo(expected)
val search = PersonDAO.find(luceneDocument, sortByBalance).resultList()
search must haveSize(7)
search.head.age mustEqual 25
search.head.name mustEqual "Allison Turner"
search.head.balance mustEqual 3961.0
}

"equals Query with Date" in {
val luceneQuery = LuceneQueryConverter.parse("registered:20140420T004427000+0200", "unbekannt")
val luceneQuery = LuceneQueryConverter.parse("registered:20140420T004427000\\+0200", "unbekannt")
val search = PersonDAO.find(LuceneQueryConverter.toDocument(luceneQuery), sortByBalance).resultList()
search must haveSize(1)
search.head.age mustEqual 31
Expand Down

0 comments on commit ee5ad9b

Please sign in to comment.