This repository was archived by the owner on Jun 19, 2024. It is now read-only.
File tree 4 files changed +150
-0
lines changed
main/kotlin/org/springframework/data/r2dbc/core
test/kotlin/org/springframework/data/r2dbc/core
4 files changed +150
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2018-2019 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package org.springframework.data.r2dbc.core
17
+
18
+ import org.springframework.data.r2dbc.query.Criteria
19
+
20
+ /* *
21
+ * Extension for [Criteria.CriteriaStep.is] providing a
22
+ * `eq(value)` variant.
23
+ *
24
+ * @author Jonas Bark
25
+ */
26
+ infix fun Criteria.CriteriaStep.isEquals (value : Any ): Criteria =
27
+ `is `(value)
28
+
29
+ /* *
30
+ * Extension for [Criteria.CriteriaStep.in] providing a
31
+ * `isIn(value)` variant.
32
+ *
33
+ * @author Jonas Bark
34
+ */
35
+ fun Criteria.CriteriaStep.isIn (vararg value : Any ): Criteria =
36
+ `in `(value)
37
+
38
+
39
+ /* *
40
+ * Extension for [Criteria.CriteriaStep.in] providing a
41
+ * `isIn(value)` variant.
42
+ *
43
+ * @author Jonas Bark
44
+ */
45
+ fun Criteria.CriteriaStep.isIn (values : Collection <Any >): Criteria =
46
+ `in `(values)
Original file line number Diff line number Diff line change 16
16
package org.springframework.data.r2dbc.core
17
17
18
18
import kotlinx.coroutines.reactive.awaitFirstOrNull
19
+ import org.springframework.data.r2dbc.query.Criteria
19
20
20
21
/* *
21
22
* Coroutines variant of [DatabaseClient.GenericExecuteSpec.then].
@@ -80,3 +81,20 @@ suspend fun <T> DatabaseClient.InsertSpec<T>.await() {
80
81
inline fun <reified T : Any > DatabaseClient.InsertIntoSpec.into (): DatabaseClient .TypedInsertSpec <T > =
81
82
into(T ::class .java)
82
83
84
+ /* *
85
+ * Extension for [DatabaseClient.SelectFromSpec.from] providing a
86
+ * `from<Foo>()` variant.
87
+ *
88
+ * @author Jonas Bark
89
+ */
90
+ inline fun <reified T : Any > DatabaseClient.SelectFromSpec.from (): DatabaseClient .TypedSelectSpec <T > =
91
+ from(T ::class .java)
92
+
93
+ /* *
94
+ * Extension for [DatabaseClient.SelectFromSpec.from] providing a
95
+ * `from<Foo>()` variant.
96
+ *
97
+ * @author Jonas Bark
98
+ */
99
+ inline fun <reified T : Any > DatabaseClient.DeleteFromSpec.from (): DatabaseClient .TypedDeleteSpec <T > =
100
+ from(T ::class .java)
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2018-2019 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package org.springframework.data.r2dbc.core
17
+
18
+ import io.mockk.every
19
+ import io.mockk.mockk
20
+ import io.mockk.spyk
21
+ import io.mockk.verify
22
+ import kotlinx.coroutines.runBlocking
23
+ import org.assertj.core.api.Assertions.assertThat
24
+ import org.junit.Test
25
+ import org.springframework.data.r2dbc.query.Criteria
26
+ import reactor.core.publisher.Mono
27
+
28
+ /* *
29
+ * Unit tests for [Criteria.CriteriaStep] extensions.
30
+ *
31
+ * @author Jonas Bark
32
+ */
33
+ class CriteriaStepExtensionsTests {
34
+
35
+ @Test // gh-63
36
+ fun eqIsCriteriaStep () {
37
+
38
+ val spec = mockk<Criteria .CriteriaStep >()
39
+ val eqSpec = mockk<Criteria >()
40
+
41
+ every { spec.`is `(" test" ) } returns eqSpec
42
+
43
+ runBlocking {
44
+ assertThat(spec isEquals " test" ).isEqualTo(eqSpec)
45
+ }
46
+
47
+ verify {
48
+ spec.`is `(" test" )
49
+ }
50
+ }
51
+ }
Original file line number Diff line number Diff line change @@ -17,16 +17,19 @@ package org.springframework.data.r2dbc.core
17
17
18
18
import io.mockk.every
19
19
import io.mockk.mockk
20
+ import io.mockk.spyk
20
21
import io.mockk.verify
21
22
import kotlinx.coroutines.runBlocking
22
23
import org.assertj.core.api.Assertions.assertThat
23
24
import org.junit.Test
25
+ import org.springframework.data.r2dbc.query.Criteria
24
26
import reactor.core.publisher.Mono
25
27
26
28
/* *
27
29
* Unit tests for [DatabaseClient] extensions.
28
30
*
29
31
* @author Sebastien Deleuze
32
+ * @author Jonas Bark
30
33
*/
31
34
class DatabaseClientExtensionsTests {
32
35
@@ -137,4 +140,36 @@ class DatabaseClientExtensionsTests {
137
140
spec.into(String ::class .java)
138
141
}
139
142
}
143
+
144
+ @Test // gh-63
145
+ fun selectFromSpecInto () {
146
+
147
+ val spec = mockk<DatabaseClient .SelectFromSpec >()
148
+ val typedSpec: DatabaseClient .TypedSelectSpec <String > = mockk()
149
+ every { spec.from(String ::class .java) } returns typedSpec
150
+
151
+ runBlocking {
152
+ assertThat(spec.from<String >()).isEqualTo(typedSpec)
153
+ }
154
+
155
+ verify {
156
+ spec.from(String ::class .java)
157
+ }
158
+ }
159
+
160
+ @Test // gh-63
161
+ fun deleteFromSpecInto () {
162
+
163
+ val spec = mockk<DatabaseClient .DeleteFromSpec >()
164
+ val typedSpec: DatabaseClient .TypedDeleteSpec <String > = mockk()
165
+ every { spec.from(String ::class .java) } returns typedSpec
166
+
167
+ runBlocking {
168
+ assertThat(spec.from<String >()).isEqualTo(typedSpec)
169
+ }
170
+
171
+ verify {
172
+ spec.from(String ::class .java)
173
+ }
174
+ }
140
175
}
You can’t perform that action at this time.
0 commit comments