-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kotlin): provide operators through extension functions
To use a more fluent syntax, we provide some extension functions in the kotlin context. All the code is just a bridge with real java implementation. Closes #11
- Loading branch information
1 parent
463900a
commit 5d1ba95
Showing
7 changed files
with
809 additions
and
0 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
178 changes: 178 additions & 0 deletions
178
integration-tests/src/test/kotlin/com/github/t9t/jooq/json/JsonDSLTestIT.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,178 @@ | ||
package com.github.t9t.jooq.json | ||
|
||
import org.jooq.Field | ||
import org.jooq.JSON | ||
import org.jooq.impl.DSL | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
/** | ||
* Created by kevin on 20/12/2020 | ||
*/ | ||
class JsonDSLTestIT { | ||
|
||
private val jsonField: Field<JSON> = DSL.field("foo.bar", JSON::class.java) | ||
|
||
@Test | ||
fun `should provide extension function for arrayElement`() { | ||
/* Given */ | ||
val index = 1 | ||
/* When */ | ||
val arrayElementField = JsonDSL.arrayElement(jsonField, index) | ||
val arrayElementFieldExt = jsonField.arrayElement(index) | ||
/* Then */ | ||
assertEquals(arrayElementField, arrayElementFieldExt) | ||
} | ||
|
||
@Test | ||
fun `should provide extension function for arrayElementText`() { | ||
/* Given */ | ||
val index = 1 | ||
/* When */ | ||
val arrayElementTextField = JsonDSL.arrayElementText(jsonField, index) | ||
val arrayElementTextFieldExt = jsonField.arrayElementText(index) | ||
/* Then */ | ||
assertEquals(arrayElementTextField, arrayElementTextFieldExt) | ||
} | ||
|
||
@Test | ||
fun `should provide extension function for fieldByKey`() { | ||
/* Given */ | ||
val key = "key" | ||
/* When */ | ||
val fieldByKeyField = JsonDSL.fieldByKey(jsonField, key) | ||
val fieldByKeyFieldExt = jsonField.fieldByKey(key) | ||
/* Then */ | ||
assertEquals(fieldByKeyField, fieldByKeyFieldExt) | ||
} | ||
|
||
@Test | ||
fun `should provide extension function for fieldByKeyText`() { | ||
/* Given */ | ||
val key = "key" | ||
/* When */ | ||
val fieldByKeyTextField = JsonDSL.fieldByKeyText(jsonField, key) | ||
val fieldByKeyTextFieldExt = jsonField.fieldByKeyText(key) | ||
/* Then */ | ||
assertEquals(fieldByKeyTextField, fieldByKeyTextFieldExt) | ||
} | ||
|
||
@Test | ||
fun `should provide extension function for objectAtPath with varargs`() { | ||
/* Given */ | ||
val path = arrayOf("path", "to", "key") | ||
/* When */ | ||
val objectAtPathField = JsonDSL.objectAtPath(jsonField, *path) | ||
val objectAtPathFieldExt = jsonField.objectAtPath(*path) | ||
/* Then */ | ||
assertEquals(objectAtPathField, objectAtPathFieldExt) | ||
} | ||
|
||
@Test | ||
fun `should provide extension function for objectAtPath with collection`() { | ||
/* Given */ | ||
val path = arrayOf("path", "to", "key") | ||
/* When */ | ||
val objectAtPathField = JsonDSL.objectAtPath(jsonField, path.toList()) | ||
val objectAtPathFieldExt = jsonField.objectAtPath(path.toList()) | ||
/* Then */ | ||
assertEquals(objectAtPathField, objectAtPathFieldExt) | ||
} | ||
|
||
@Test | ||
fun `should provide extension function for objectAtPathText with varargs`() { | ||
/* Given */ | ||
val path = arrayOf("path", "to", "key") | ||
/* When */ | ||
val objectAtPathTextField = JsonDSL.objectAtPathText(jsonField, *path) | ||
val objectAtPathTextFieldExt = jsonField.objectAtPathText(*path) | ||
/* Then */ | ||
assertEquals(objectAtPathTextField, objectAtPathTextFieldExt) | ||
} | ||
|
||
@Test | ||
fun `should provide extension function for objectAtPathText with collection`() { | ||
/* Given */ | ||
val path = arrayOf("path", "to", "key") | ||
/* When */ | ||
val objectAtPathTextField = JsonDSL.objectAtPathText(jsonField, path.toList()) | ||
val objectAtPathTextFieldExt = jsonField.objectAtPathText(path.toList()) | ||
/* Then */ | ||
assertEquals(objectAtPathTextField, objectAtPathTextFieldExt) | ||
} | ||
|
||
@Test | ||
fun `should provide function for arrayLength`() { | ||
/* Given */ | ||
/* When */ | ||
val arrayLengthField = JsonDSL.arrayLength(jsonField) | ||
val arrayLengthFieldExt = arrayLength(jsonField) | ||
/* Then */ | ||
assertEquals(arrayLengthField, arrayLengthFieldExt) | ||
} | ||
|
||
@Test | ||
fun `should provide function for extractPath with varargs`() { | ||
/* Given */ | ||
val path = arrayOf("path", "to", "key") | ||
/* When */ | ||
val extractPathField = JsonDSL.extractPath(jsonField, *path) | ||
val extractPathFieldExt = extractPath(jsonField, *path) | ||
/* Then */ | ||
assertEquals(extractPathField, extractPathFieldExt) | ||
} | ||
|
||
@Test | ||
fun `should provide function for extractPath with collection`() { | ||
/* Given */ | ||
val path = arrayOf("path", "to", "key") | ||
/* When */ | ||
val extractPathField = JsonDSL.extractPath(jsonField, path.toList()) | ||
val extractPathFieldExt = extractPath(jsonField, path.toList()) | ||
/* Then */ | ||
assertEquals(extractPathField, extractPathFieldExt) | ||
} | ||
|
||
@Test | ||
fun `should provide function for extractPathText with varargs`() { | ||
/* Given */ | ||
val path = arrayOf("path", "to", "key") | ||
/* When */ | ||
val extractPathTextField = JsonDSL.extractPathText(jsonField, *path) | ||
val extractPathTextFieldExt = extractPathText(jsonField, *path) | ||
/* Then */ | ||
assertEquals(extractPathTextField, extractPathTextFieldExt) | ||
} | ||
|
||
@Test | ||
fun `should provide function for extractPathText with collection`() { | ||
/* Given */ | ||
val path = arrayOf("path", "to", "key") | ||
/* When */ | ||
val extractPathTextField = JsonDSL.extractPathText(jsonField, path.toList()) | ||
val extractPathTextFieldExt = extractPathText(jsonField, path.toList()) | ||
/* Then */ | ||
assertEquals(extractPathTextField, extractPathTextFieldExt) | ||
} | ||
|
||
@Test | ||
fun `should provide function for typeOf`() { | ||
/* Given */ | ||
/* When */ | ||
val typeOfField = JsonDSL.typeOf(jsonField) | ||
val typeOfFieldExt = typeOf(jsonField) | ||
/* Then */ | ||
assertEquals(typeOfField, typeOfFieldExt) | ||
} | ||
|
||
@Test | ||
fun `should provide function for stripNulls`() { | ||
/* Given */ | ||
/* When */ | ||
val stripNullsField = JsonDSL.stripNulls(jsonField) | ||
val stripNullsFieldExt = stripNulls(jsonField) | ||
/* Then */ | ||
assertEquals(stripNullsField, stripNullsFieldExt) | ||
} | ||
|
||
} |
Oops, something went wrong.