-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #609 from scireum/feature/mbo/OX-10357-1
JUnit: Migrates MongoExistsTest and MongoFilledTest to Kotlin
- Loading branch information
Showing
4 changed files
with
204 additions
and
152 deletions.
There are no files selected for viewing
77 changes: 0 additions & 77 deletions
77
src/test/java/sirius/db/mongo/properties/MongoExistsSpec.groovy
This file was deleted.
Oops, something went wrong.
75 changes: 0 additions & 75 deletions
75
src/test/java/sirius/db/mongo/properties/MongoFilledSpec.groovy
This file was deleted.
Oops, something went wrong.
109 changes: 109 additions & 0 deletions
109
src/test/kotlin/sirius/db/mongo/properties/MongoExistsTest.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,109 @@ | ||
/* | ||
* Made with all the love in the world | ||
* by scireum in Remshalden, Germany | ||
* | ||
* Copyright by scireum GmbH | ||
* http://www.scireum.de - [email protected] | ||
*/ | ||
|
||
package sirius.db.mongo.properties | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import sirius.db.KeyGenerator | ||
import sirius.db.mongo.Mango | ||
import sirius.db.mongo.Mongo | ||
import sirius.db.mongo.MongoEntity | ||
import sirius.db.mongo.QueryBuilder | ||
import sirius.kernel.SiriusExtension | ||
import sirius.kernel.di.std.Part | ||
import kotlin.test.assertEquals | ||
|
||
@ExtendWith(SiriusExtension::class) | ||
class MongoExistsTest { | ||
@Test | ||
fun `exists query works`() { | ||
|
||
val fieldMissing = mongo.insert().set(MongoEntity.ID, keyGen.generateId()).into(MongoExistsEntity::class.java) | ||
val fieldPresent = | ||
mongo.insert().set(MongoEntity.ID, keyGen.generateId()).set(MongoExistsEntity.TEST_FIELD, "test") | ||
.into(MongoExistsEntity::class.java) | ||
|
||
assertEquals( | ||
fieldMissing.getString(MongoEntity.ID), mango.select(MongoExistsEntity::class.java) | ||
.eq(MongoExistsEntity.TEST_FIELD, null) | ||
.queryFirst().getIdAsString() | ||
) | ||
assertEquals( | ||
1, mango.select(MongoExistsEntity::class.java) | ||
.eq(MongoExistsEntity.TEST_FIELD, null) | ||
.count() | ||
) | ||
|
||
assertEquals( | ||
fieldPresent.getString(MongoEntity.ID), mango.select(MongoExistsEntity::class.java) | ||
.ne(MongoExistsEntity.TEST_FIELD, null) | ||
.queryFirst().getIdAsString() | ||
) | ||
assertEquals( | ||
1, mango.select(MongoExistsEntity::class.java) | ||
.ne(MongoExistsEntity.TEST_FIELD, null) | ||
.count() | ||
) | ||
|
||
assertEquals( | ||
fieldPresent.getString(MongoEntity.ID), mango.select(MongoExistsEntity::class.java) | ||
.where(QueryBuilder.FILTERS.exists(MongoExistsEntity.TEST_FIELD)) | ||
.queryFirst().getIdAsString() | ||
) | ||
assertEquals( | ||
1, mango.select(MongoExistsEntity::class.java) | ||
.where(QueryBuilder.FILTERS.exists(MongoExistsEntity.TEST_FIELD)) | ||
.count() | ||
) | ||
|
||
assertEquals( | ||
fieldMissing.getString(MongoEntity.ID), mango.select(MongoExistsEntity::class.java) | ||
.where(QueryBuilder.FILTERS.notExists(MongoExistsEntity.TEST_FIELD)) | ||
.queryFirst().getIdAsString() | ||
) | ||
assertEquals( | ||
1, mango.select(MongoExistsEntity::class.java) | ||
.where(QueryBuilder.FILTERS.notExists(MongoExistsEntity.TEST_FIELD)) | ||
.count() | ||
) | ||
|
||
assertEquals( | ||
fieldPresent.getString(MongoEntity.ID), mango.select(MongoExistsEntity::class.java) | ||
.where(QueryBuilder.FILTERS.filled(MongoExistsEntity.TEST_FIELD)) | ||
.queryFirst().getIdAsString() | ||
) | ||
assertEquals( | ||
1, mango.select(MongoExistsEntity::class.java) | ||
.where(QueryBuilder.FILTERS.filled(MongoExistsEntity.TEST_FIELD)) | ||
.count() | ||
) | ||
|
||
assertEquals( | ||
fieldMissing.getString(MongoEntity.ID), mango.select(MongoExistsEntity::class.java) | ||
.where(QueryBuilder.FILTERS.notFilled(MongoExistsEntity.TEST_FIELD)) | ||
.queryFirst().getIdAsString() | ||
) | ||
assertEquals( | ||
1, mango.select(MongoExistsEntity::class.java) | ||
.where(QueryBuilder.FILTERS.notFilled(MongoExistsEntity.TEST_FIELD)) | ||
.count() | ||
) | ||
} | ||
|
||
companion object { | ||
@Part | ||
private lateinit var mango: Mango | ||
|
||
@Part | ||
private lateinit var mongo: Mongo | ||
|
||
@Part | ||
private lateinit var keyGen: KeyGenerator | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
src/test/kotlin/sirius/db/mongo/properties/MongoFilledTest.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,95 @@ | ||
/* | ||
* Made with all the love in the world | ||
* by scireum in Remshalden, Germany | ||
* | ||
* Copyright by scireum GmbH | ||
* http://www.scireum.de - [email protected] | ||
*/ | ||
|
||
package sirius.db.mongo.properties | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import sirius.db.mongo.Mango | ||
import sirius.db.mongo.Mongo | ||
import sirius.db.mongo.QueryBuilder | ||
import sirius.kernel.SiriusExtension | ||
import sirius.kernel.commons.Strings | ||
import sirius.kernel.di.std.Part | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
|
||
@ExtendWith(SiriusExtension::class) | ||
class MongoFilledTest { | ||
@Test | ||
fun `filled notFilled query works`() { | ||
val fieldFilled = MongoFilledEntity() | ||
fieldFilled.testField = "test" | ||
val fieldNotFilled = MongoFilledEntity() | ||
|
||
mango.update(fieldFilled) | ||
mango.update(fieldNotFilled) | ||
|
||
assertEquals( | ||
fieldNotFilled.getIdAsString(), | ||
mango.select(MongoFilledEntity::class.java).eq(MongoFilledEntity.TEST_FIELD, null).queryFirst() | ||
.getIdAsString() | ||
) | ||
assertEquals( | ||
1, mango.select(MongoFilledEntity::class.java).eq(MongoFilledEntity.TEST_FIELD, null).count() | ||
) | ||
|
||
assertEquals( | ||
fieldFilled.getIdAsString(), | ||
mango.select(MongoFilledEntity::class.java).ne(MongoFilledEntity.TEST_FIELD, null).queryFirst() | ||
.getIdAsString() | ||
) | ||
assertEquals(1, mango.select(MongoFilledEntity::class.java).ne(MongoFilledEntity.TEST_FIELD, null).count()) | ||
|
||
assertEquals( | ||
fieldFilled.getIdAsString(), | ||
mango.select(MongoFilledEntity::class.java) | ||
.where(QueryBuilder.FILTERS.filled(MongoFilledEntity.TEST_FIELD)).queryFirst().getIdAsString() | ||
) | ||
assertEquals( | ||
1, | ||
mango.select(MongoFilledEntity::class.java) | ||
.where(QueryBuilder.FILTERS.filled(MongoFilledEntity.TEST_FIELD)).count() | ||
) | ||
|
||
assertEquals( | ||
fieldNotFilled.getIdAsString(), | ||
mango.select(MongoFilledEntity::class.java) | ||
.where(QueryBuilder.FILTERS.notFilled(MongoFilledEntity.TEST_FIELD)).queryFirst() | ||
.getIdAsString() | ||
) | ||
assertEquals( | ||
1, | ||
mango.select(MongoFilledEntity::class.java) | ||
.where(QueryBuilder.FILTERS.notFilled(MongoFilledEntity.TEST_FIELD)).count() | ||
) | ||
|
||
assertTrue { | ||
mango.select(MongoFilledEntity::class.java).where(QueryBuilder.FILTERS.exists(MongoFilledEntity.TEST_FIELD)) | ||
.queryList().any { entity -> | ||
Strings.areEqual( | ||
entity.getIdAsString(), | ||
fieldNotFilled.getIdAsString() | ||
) || Strings.areEqual(entity.getIdAsString(), fieldFilled.getIdAsString()) | ||
} | ||
} | ||
assertEquals( | ||
0, | ||
mango.select(MongoFilledEntity::class.java) | ||
.where(QueryBuilder.FILTERS.notExists(MongoFilledEntity.TEST_FIELD)).count() | ||
) | ||
} | ||
|
||
companion object { | ||
@Part | ||
private lateinit var mango: Mango | ||
|
||
@Part | ||
private lateinit var mongo: Mongo | ||
} | ||
} |