-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5588bf
commit 630dd4a
Showing
8 changed files
with
139 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/test/kotlin/no/liflig/documentstore/DomainfilterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package no.liflig.documentstore | ||
|
||
import io.kotest.matchers.collections.shouldHaveSize | ||
import io.kotest.matchers.ints.exactly | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import kotlinx.coroutines.runBlocking | ||
import no.liflig.documentstore.dao.CrudDaoJdbi | ||
import no.liflig.documentstore.dao.SearchRepositoryWithCountJdbi | ||
import no.liflig.documentstore.testexamples.ExampleEntity | ||
import no.liflig.documentstore.testexamples.ExampleId | ||
import no.liflig.documentstore.testexamples.ExampleQueryObject | ||
import no.liflig.documentstore.testexamples.ExampleSearchRepository | ||
import no.liflig.documentstore.testexamples.ExampleSerializationAdapter | ||
import no.liflig.documentstore.testexamples.ExampleTextSearchQuery | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
class DomainPredicateTest { | ||
val jdbi = createTestDatabase() | ||
|
||
val serializationAdapter = ExampleSerializationAdapter() | ||
|
||
val dao = CrudDaoJdbi(jdbi, "example", serializationAdapter) | ||
|
||
val searchRepository = ExampleSearchRepository(jdbi, "example", serializationAdapter) | ||
|
||
val searchRepositoryWithCountJdbi = SearchRepositoryWithCountJdbi<ExampleId, ExampleEntity, ExampleTextSearchQuery>( | ||
jdbi, "example", serializationAdapter, | ||
) | ||
|
||
@BeforeEach | ||
fun clearDatabase(){ | ||
searchRepository.listAll().forEach { | ||
dao.delete(it.item.id, it.version) | ||
} | ||
} | ||
@Test | ||
fun domainPredicateWorks() { | ||
runBlocking { | ||
dao.create(ExampleEntity.create("Hello Tes")) | ||
dao.create(ExampleEntity.create("Hello Alfred")) | ||
dao.create(ExampleEntity.create("Bye Ted")) | ||
dao.create(ExampleEntity.create("Bye Alfred")) | ||
|
||
searchRepository.search( | ||
ExampleQueryObject( | ||
domainPredicate = { it.text.contains("Hello") }, | ||
) | ||
) shouldHaveSize 2 | ||
} | ||
} | ||
|
||
@Test | ||
fun limitWorks() { | ||
runBlocking { | ||
val mockAdapter: ExampleSerializationAdapter = mockk { | ||
every { fromJson(any()) } returns ExampleEntity.create("") | ||
} | ||
val searchRepository = ExampleSearchRepository(jdbi, "example", mockAdapter) | ||
dao.create(ExampleEntity.create("Hello Tes")) | ||
dao.create(ExampleEntity.create("Hello Alfred")) | ||
dao.create(ExampleEntity.create("Bye Ted")) | ||
dao.create(ExampleEntity.create("Bye Alfred")) | ||
|
||
val result = searchRepository.search( | ||
ExampleQueryObject( | ||
limit = 1 | ||
) | ||
) | ||
|
||
result shouldHaveSize 1 | ||
verify(exactly = 1) { mockAdapter.fromJson(any()) } | ||
} | ||
} | ||
|
||
@Test | ||
fun offSetWorks() { | ||
runBlocking { | ||
val mockAdapter: ExampleSerializationAdapter = mockk { | ||
every { fromJson(any()) } returns ExampleEntity.create("") | ||
} | ||
val searchRepository = ExampleSearchRepository(jdbi, "example", mockAdapter) | ||
dao.create(ExampleEntity.create("Hello Tes")) | ||
dao.create(ExampleEntity.create("Hello Alfred")) | ||
dao.create(ExampleEntity.create("Bye Ted")) | ||
dao.create(ExampleEntity.create("Bye Alfred")) | ||
|
||
val result = searchRepository.search( | ||
ExampleQueryObject( | ||
offset = 3 | ||
) | ||
) | ||
|
||
result shouldHaveSize 1 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../no/liflig/documentstore/ExampleEntity.kt → ...cumentstore/testexamples/ExampleEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...umentstore/ExampleSerializationAdapter.kt → ...stexamples/ExampleSerializationAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...liflig/documentstore/InstantSerializer.kt → ...ntstore/testexamples/InstantSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters