|
| 1 | +package com.github.t9t.jooq.json |
| 2 | + |
| 3 | +import org.jooq.Field |
| 4 | +import org.jooq.JSON |
| 5 | +import org.jooq.impl.DSL |
| 6 | +import org.junit.Assert.assertEquals |
| 7 | +import org.junit.Test |
| 8 | + |
| 9 | +/** |
| 10 | + * Created by kevin on 20/12/2020 |
| 11 | + */ |
| 12 | +class JsonDSLTestIT { |
| 13 | + |
| 14 | + private val jsonField: Field<JSON> = DSL.field("foo.bar", JSON::class.java) |
| 15 | + |
| 16 | + @Test |
| 17 | + fun `should provide extension function for arrayElement`() { |
| 18 | + /* Given */ |
| 19 | + val index = 1 |
| 20 | + /* When */ |
| 21 | + val arrayElementField = JsonDSL.arrayElement(jsonField, index) |
| 22 | + val arrayElementFieldExt = jsonField.arrayElement(index) |
| 23 | + /* Then */ |
| 24 | + assertEquals(arrayElementField, arrayElementFieldExt) |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + fun `should provide extension function for arrayElementText`() { |
| 29 | + /* Given */ |
| 30 | + val index = 1 |
| 31 | + /* When */ |
| 32 | + val arrayElementTextField = JsonDSL.arrayElementText(jsonField, index) |
| 33 | + val arrayElementTextFieldExt = jsonField.arrayElementText(index) |
| 34 | + /* Then */ |
| 35 | + assertEquals(arrayElementTextField, arrayElementTextFieldExt) |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + fun `should provide extension function for fieldByKey`() { |
| 40 | + /* Given */ |
| 41 | + val key = "key" |
| 42 | + /* When */ |
| 43 | + val fieldByKeyField = JsonDSL.fieldByKey(jsonField, key) |
| 44 | + val fieldByKeyFieldExt = jsonField.fieldByKey(key) |
| 45 | + /* Then */ |
| 46 | + assertEquals(fieldByKeyField, fieldByKeyFieldExt) |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + fun `should provide extension function for fieldByKeyText`() { |
| 51 | + /* Given */ |
| 52 | + val key = "key" |
| 53 | + /* When */ |
| 54 | + val fieldByKeyTextField = JsonDSL.fieldByKeyText(jsonField, key) |
| 55 | + val fieldByKeyTextFieldExt = jsonField.fieldByKeyText(key) |
| 56 | + /* Then */ |
| 57 | + assertEquals(fieldByKeyTextField, fieldByKeyTextFieldExt) |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + fun `should provide extension function for objectAtPath with varargs`() { |
| 62 | + /* Given */ |
| 63 | + val path = arrayOf("path", "to", "key") |
| 64 | + /* When */ |
| 65 | + val objectAtPathField = JsonDSL.objectAtPath(jsonField, *path) |
| 66 | + val objectAtPathFieldExt = jsonField.objectAtPath(*path) |
| 67 | + /* Then */ |
| 68 | + assertEquals(objectAtPathField, objectAtPathFieldExt) |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + fun `should provide extension function for objectAtPath with collection`() { |
| 73 | + /* Given */ |
| 74 | + val path = arrayOf("path", "to", "key") |
| 75 | + /* When */ |
| 76 | + val objectAtPathField = JsonDSL.objectAtPath(jsonField, path.toList()) |
| 77 | + val objectAtPathFieldExt = jsonField.objectAtPath(path.toList()) |
| 78 | + /* Then */ |
| 79 | + assertEquals(objectAtPathField, objectAtPathFieldExt) |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + fun `should provide extension function for objectAtPathText with varargs`() { |
| 84 | + /* Given */ |
| 85 | + val path = arrayOf("path", "to", "key") |
| 86 | + /* When */ |
| 87 | + val objectAtPathTextField = JsonDSL.objectAtPathText(jsonField, *path) |
| 88 | + val objectAtPathTextFieldExt = jsonField.objectAtPathText(*path) |
| 89 | + /* Then */ |
| 90 | + assertEquals(objectAtPathTextField, objectAtPathTextFieldExt) |
| 91 | + } |
| 92 | + |
| 93 | + @Test |
| 94 | + fun `should provide extension function for objectAtPathText with collection`() { |
| 95 | + /* Given */ |
| 96 | + val path = arrayOf("path", "to", "key") |
| 97 | + /* When */ |
| 98 | + val objectAtPathTextField = JsonDSL.objectAtPathText(jsonField, path.toList()) |
| 99 | + val objectAtPathTextFieldExt = jsonField.objectAtPathText(path.toList()) |
| 100 | + /* Then */ |
| 101 | + assertEquals(objectAtPathTextField, objectAtPathTextFieldExt) |
| 102 | + } |
| 103 | + |
| 104 | + @Test |
| 105 | + fun `should provide function for arrayLength`() { |
| 106 | + /* Given */ |
| 107 | + /* When */ |
| 108 | + val arrayLengthField = JsonDSL.arrayLength(jsonField) |
| 109 | + val arrayLengthFieldExt = arrayLength(jsonField) |
| 110 | + /* Then */ |
| 111 | + assertEquals(arrayLengthField, arrayLengthFieldExt) |
| 112 | + } |
| 113 | + |
| 114 | + @Test |
| 115 | + fun `should provide function for extractPath with varargs`() { |
| 116 | + /* Given */ |
| 117 | + val path = arrayOf("path", "to", "key") |
| 118 | + /* When */ |
| 119 | + val extractPathField = JsonDSL.extractPath(jsonField, *path) |
| 120 | + val extractPathFieldExt = extractPath(jsonField, *path) |
| 121 | + /* Then */ |
| 122 | + assertEquals(extractPathField, extractPathFieldExt) |
| 123 | + } |
| 124 | + |
| 125 | + @Test |
| 126 | + fun `should provide function for extractPath with collection`() { |
| 127 | + /* Given */ |
| 128 | + val path = arrayOf("path", "to", "key") |
| 129 | + /* When */ |
| 130 | + val extractPathField = JsonDSL.extractPath(jsonField, path.toList()) |
| 131 | + val extractPathFieldExt = extractPath(jsonField, path.toList()) |
| 132 | + /* Then */ |
| 133 | + assertEquals(extractPathField, extractPathFieldExt) |
| 134 | + } |
| 135 | + |
| 136 | + @Test |
| 137 | + fun `should provide function for extractPathText with varargs`() { |
| 138 | + /* Given */ |
| 139 | + val path = arrayOf("path", "to", "key") |
| 140 | + /* When */ |
| 141 | + val extractPathTextField = JsonDSL.extractPathText(jsonField, *path) |
| 142 | + val extractPathTextFieldExt = extractPathText(jsonField, *path) |
| 143 | + /* Then */ |
| 144 | + assertEquals(extractPathTextField, extractPathTextFieldExt) |
| 145 | + } |
| 146 | + |
| 147 | + @Test |
| 148 | + fun `should provide function for extractPathText with collection`() { |
| 149 | + /* Given */ |
| 150 | + val path = arrayOf("path", "to", "key") |
| 151 | + /* When */ |
| 152 | + val extractPathTextField = JsonDSL.extractPathText(jsonField, path.toList()) |
| 153 | + val extractPathTextFieldExt = extractPathText(jsonField, path.toList()) |
| 154 | + /* Then */ |
| 155 | + assertEquals(extractPathTextField, extractPathTextFieldExt) |
| 156 | + } |
| 157 | + |
| 158 | + @Test |
| 159 | + fun `should provide function for typeOf`() { |
| 160 | + /* Given */ |
| 161 | + /* When */ |
| 162 | + val typeOfField = JsonDSL.typeOf(jsonField) |
| 163 | + val typeOfFieldExt = typeOf(jsonField) |
| 164 | + /* Then */ |
| 165 | + assertEquals(typeOfField, typeOfFieldExt) |
| 166 | + } |
| 167 | + |
| 168 | + @Test |
| 169 | + fun `should provide function for stripNulls`() { |
| 170 | + /* Given */ |
| 171 | + /* When */ |
| 172 | + val stripNullsField = JsonDSL.stripNulls(jsonField) |
| 173 | + val stripNullsFieldExt = stripNulls(jsonField) |
| 174 | + /* Then */ |
| 175 | + assertEquals(stripNullsField, stripNullsFieldExt) |
| 176 | + } |
| 177 | + |
| 178 | +} |
0 commit comments