File tree Expand file tree Collapse file tree
main/kotlin/com/github/mgramin/sqlboot/sql/select/wrappers
test/kotlin/com/github/mgramin/sqlboot/sql/select/wrappers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 111111 <artifactId >spring-boot-starter-web</artifactId >
112112 </dependency >
113113
114+ <dependency >
115+ <groupId >org.springframework.boot</groupId >
116+ <artifactId >spring-boot-starter-webflux</artifactId >
117+ </dependency >
118+
119+ <dependency >
120+ <groupId >io.netty</groupId >
121+ <artifactId >netty-transport-native-epoll</artifactId >
122+ <version >4.0.27.Final</version >
123+ <classifier >linux-x86_64</classifier >
124+ </dependency >
125+
114126 <dependency >
115127 <groupId >org.springframework.boot</groupId >
116128 <artifactId >spring-boot-starter-jdbc</artifactId >
Original file line number Diff line number Diff line change 1+ package com.github.mgramin.sqlboot.sql.select.wrappers
2+
3+ import com.github.mgramin.sqlboot.sql.select.SelectQuery
4+ import com.google.gson.Gson
5+ import com.google.gson.reflect.TypeToken
6+ import org.springframework.http.MediaType
7+ import org.springframework.web.reactive.function.client.WebClient
8+ import reactor.core.publisher.Flux
9+ import reactor.core.publisher.toFlux
10+
11+
12+ class RestSelectQuery (
13+ private val origin : SelectQuery ,
14+ private val endpoint : String
15+ ) : SelectQuery {
16+
17+ override fun query () = origin.query()
18+
19+ override fun columns () = origin.columns()
20+
21+ override fun execute (variables : Map <String , Any >): Flux <Map <String , Any >> {
22+ val client: List <Map <String , Any >>? = WebClient
23+ .create(endpoint)
24+ .get()
25+ .uri(" /exec?query=${origin.query()} " )
26+ .accept(MediaType .APPLICATION_JSON )
27+ .retrieve()
28+ .bodyToMono(String ::class .java)
29+ .map {
30+ val resultType = object : TypeToken <List <Map <String , Any >>>() {}.type
31+ return @map Gson ().fromJson<List <Map <String , Any >>? > (it, resultType)
32+ }
33+ .block()
34+ return client!! .toFlux()
35+ }
36+
37+ }
Original file line number Diff line number Diff line change 1+ package com.github.mgramin.sqlboot.sql.select.wrappers
2+
3+ import com.github.mgramin.sqlboot.sql.select.SelectQuery
4+ import com.nhaarman.mockitokotlin2.doReturn
5+ import com.nhaarman.mockitokotlin2.mock
6+ import org.junit.jupiter.api.Test
7+ import kotlin.test.assertEquals
8+
9+ /* *
10+ * @author Maksim Gramin (mgramin@gmail.com)
11+ * @version $
12+ * @since 0.1
13+ */
14+ internal class RestSelectQueryTest {
15+
16+ @Test
17+ fun query () {
18+ }
19+
20+ @Test
21+ fun columns () {
22+ }
23+
24+ @Test
25+ fun execute () {
26+ val mockQuery = mock<SelectQuery > {
27+ on { query() } doReturn " select * from processes limit 10"
28+ }
29+ val rows = RestSelectQuery (mockQuery, " http://5.8.181.165:8082" )
30+ .execute(hashMapOf())
31+ .collectList()
32+ .block()
33+ assertEquals(10 , rows.size)
34+ }
35+
36+ }
You can’t perform that action at this time.
0 commit comments