Skip to content

Commit 37cadef

Browse files
Moved composable annotation test to compose module
Also improved some core route invocation extensions
1 parent 234fa76 commit 37cadef

File tree

7 files changed

+852
-107
lines changed

7 files changed

+852
-107
lines changed

core/common/src/dev/programadorthi/routing/core/RoutingExt.kt

Lines changed: 186 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ package dev.programadorthi.routing.core
22

33
import io.ktor.http.Parameters
44

5+
public fun Routing.push(path: String) {
6+
push(path = path, parameters = Parameters.Empty)
7+
}
8+
59
public fun Routing.push(
610
path: String,
7-
parameters: Parameters = Parameters.Empty,
11+
parameters: Parameters,
812
) {
913
call(
1014
uri = path,
@@ -13,9 +17,13 @@ public fun Routing.push(
1317
)
1418
}
1519

20+
public fun Routing.pushNamed(name: String) {
21+
pushNamed(name = name, parameters = Parameters.Empty)
22+
}
23+
1624
public fun Routing.pushNamed(
1725
name: String,
18-
parameters: Parameters = Parameters.Empty,
26+
parameters: Parameters,
1927
) {
2028
call(
2129
name = name,
@@ -24,9 +32,64 @@ public fun Routing.pushNamed(
2432
)
2533
}
2634

35+
public fun <T : Any> Routing.pushWithBody(
36+
path: String,
37+
body: T,
38+
) {
39+
pushWithBody(
40+
path = path,
41+
parameters = Parameters.Empty,
42+
body = body,
43+
)
44+
}
45+
46+
public fun <T : Any> Routing.pushWithBody(
47+
path: String,
48+
parameters: Parameters,
49+
body: T,
50+
) {
51+
callWithBody(
52+
uri = path,
53+
parameters = parameters,
54+
routeMethod = RouteMethod.Push,
55+
body = body,
56+
)
57+
}
58+
59+
public fun <T : Any> Routing.pushNamedWithBody(
60+
name: String,
61+
body: T,
62+
) {
63+
pushNamedWithBody(
64+
name = name,
65+
parameters = Parameters.Empty,
66+
body = body,
67+
)
68+
}
69+
70+
public fun <T : Any> Routing.pushNamedWithBody(
71+
name: String,
72+
parameters: Parameters,
73+
body: T,
74+
) {
75+
callWithBody(
76+
name = name,
77+
parameters = parameters,
78+
routeMethod = RouteMethod.Push,
79+
body = body,
80+
)
81+
}
82+
83+
public fun Routing.replace(path: String) {
84+
replace(
85+
path = path,
86+
parameters = Parameters.Empty,
87+
)
88+
}
89+
2790
public fun Routing.replace(
2891
path: String,
29-
parameters: Parameters = Parameters.Empty,
92+
parameters: Parameters,
3093
) {
3194
call(
3295
uri = path,
@@ -35,9 +98,16 @@ public fun Routing.replace(
3598
)
3699
}
37100

101+
public fun Routing.replaceNamed(name: String) {
102+
replaceNamed(
103+
name = name,
104+
parameters = Parameters.Empty,
105+
)
106+
}
107+
38108
public fun Routing.replaceNamed(
39109
name: String,
40-
parameters: Parameters = Parameters.Empty,
110+
parameters: Parameters,
41111
) {
42112
call(
43113
name = name,
@@ -46,9 +116,64 @@ public fun Routing.replaceNamed(
46116
)
47117
}
48118

119+
public fun <T : Any> Routing.replaceWithBody(
120+
path: String,
121+
body: T,
122+
) {
123+
replaceWithBody(
124+
path = path,
125+
parameters = Parameters.Empty,
126+
body = body,
127+
)
128+
}
129+
130+
public fun <T : Any> Routing.replaceWithBody(
131+
path: String,
132+
parameters: Parameters,
133+
body: T,
134+
) {
135+
callWithBody(
136+
uri = path,
137+
parameters = parameters,
138+
routeMethod = RouteMethod.Replace,
139+
body = body,
140+
)
141+
}
142+
143+
public fun <T : Any> Routing.replaceNamedWithBody(
144+
name: String,
145+
body: T,
146+
) {
147+
replaceNamedWithBody(
148+
name = name,
149+
parameters = Parameters.Empty,
150+
body = body,
151+
)
152+
}
153+
154+
public fun <T : Any> Routing.replaceNamedWithBody(
155+
name: String,
156+
parameters: Parameters,
157+
body: T,
158+
) {
159+
callWithBody(
160+
name = name,
161+
parameters = parameters,
162+
routeMethod = RouteMethod.Replace,
163+
body = body,
164+
)
165+
}
166+
167+
public fun Routing.replaceAll(path: String) {
168+
replaceAll(
169+
path = path,
170+
parameters = Parameters.Empty,
171+
)
172+
}
173+
49174
public fun Routing.replaceAll(
50175
path: String,
51-
parameters: Parameters = Parameters.Empty,
176+
parameters: Parameters,
52177
) {
53178
call(
54179
uri = path,
@@ -57,13 +182,68 @@ public fun Routing.replaceAll(
57182
)
58183
}
59184

185+
public fun Routing.replaceAllNamed(name: String) {
186+
replaceAllNamed(
187+
name = name,
188+
parameters = Parameters.Empty,
189+
)
190+
}
191+
60192
public fun Routing.replaceAllNamed(
61193
name: String,
62-
parameters: Parameters = Parameters.Empty,
194+
parameters: Parameters,
63195
) {
64196
call(
65197
name = name,
66198
parameters = parameters,
67199
routeMethod = RouteMethod.ReplaceAll,
68200
)
69201
}
202+
203+
public fun <T : Any> Routing.replaceAllWithBody(
204+
path: String,
205+
body: T,
206+
) {
207+
replaceAllWithBody(
208+
path = path,
209+
parameters = Parameters.Empty,
210+
body = body,
211+
)
212+
}
213+
214+
public fun <T : Any> Routing.replaceAllWithBody(
215+
path: String,
216+
parameters: Parameters,
217+
body: T,
218+
) {
219+
callWithBody(
220+
uri = path,
221+
parameters = parameters,
222+
routeMethod = RouteMethod.ReplaceAll,
223+
body = body,
224+
)
225+
}
226+
227+
public fun <T : Any> Routing.replaceAllNamedWithBody(
228+
name: String,
229+
body: T,
230+
) {
231+
replaceAllNamedWithBody(
232+
name = name,
233+
parameters = Parameters.Empty,
234+
body = body,
235+
)
236+
}
237+
238+
public fun <T : Any> Routing.replaceAllNamedWithBody(
239+
name: String,
240+
parameters: Parameters,
241+
body: T,
242+
) {
243+
callWithBody(
244+
name = name,
245+
parameters = parameters,
246+
routeMethod = RouteMethod.ReplaceAll,
247+
body = body,
248+
)
249+
}

core/common/test/dev/programadorthi/routing/core/Routes.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import io.ktor.http.Parameters
99
import io.ktor.util.Attributes
1010
import kotlin.to
1111

12-
val invoked = mutableMapOf<String, List<Any?>>()
12+
internal val invoked = mutableMapOf<String, List<Any?>>()
1313

14-
data class User(
14+
internal data class User(
1515
val id: Int,
1616
val name: String,
1717
)
@@ -59,14 +59,14 @@ fun regex2(number: Int) {
5959
}
6060

6161
@Route("/with-body")
62-
fun withBody(
62+
internal fun withBody(
6363
@Body user: User
6464
) {
6565
invoked += "/with-body" to listOf(user)
6666
}
6767

6868
@Route("/with-null-body")
69-
fun withNullBody(
69+
internal fun withNullBody(
7070
@Body user: User?
7171
) {
7272
invoked += "/with-null-body" to listOf(user)

core/jvm/test/dev/programadorthi/routing/core/RoutingByAnnotationsTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import dev.programadorthi.routing.generated.configure
66
import io.ktor.http.Parameters
77
import io.ktor.http.parametersOf
88
import io.ktor.util.Attributes
9+
import kotlinx.coroutines.ExperimentalCoroutinesApi
10+
import kotlinx.coroutines.Job
11+
import kotlinx.coroutines.test.advanceTimeBy
12+
import kotlinx.coroutines.test.runTest
913
import kotlin.random.Random
1014
import kotlin.test.Test
1115
import kotlin.test.assertEquals
1216
import kotlin.test.assertIs
1317
import kotlin.test.assertNotNull
14-
import kotlinx.coroutines.ExperimentalCoroutinesApi
15-
import kotlinx.coroutines.Job
16-
import kotlinx.coroutines.test.advanceTimeBy
17-
import kotlinx.coroutines.test.runTest
1818

1919
@OptIn(ExperimentalCoroutinesApi::class)
2020
class RoutingByAnnotationsTest {
@@ -268,11 +268,11 @@ class RoutingByAnnotationsTest {
268268
}
269269

270270
// WHEN
271-
routing.call(uri = "/path", routeMethod = RouteMethod.Push)
271+
routing.push(path = "/path")
272272
advanceTimeBy(99)
273273

274274
// THEN
275-
assertEquals(listOf("PUSH"), invoked.remove("/path"))
275+
assertEquals(listOf(RouteMethod.Push.value), invoked.remove("/path"))
276276
}
277277

278278
@Test

integration/compose/build.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
kotlin("plugin.serialization")
44
alias(libs.plugins.jetbrains.compose)
55
alias(libs.plugins.compose.compiler)
6+
alias(libs.plugins.ksp)
67
id("org.jetbrains.kotlinx.kover")
78
alias(libs.plugins.maven.publish)
89
}
@@ -19,5 +20,18 @@ kotlin {
1920
implementation(libs.serialization.json)
2021
}
2122
}
23+
commonTest {
24+
dependencies {
25+
implementation(projects.ksp.coreAnnotations)
26+
}
27+
}
2228
}
2329
}
30+
31+
dependencies {
32+
add("kspJvmTest", projects.ksp.coreProcessor)
33+
}
34+
35+
ksp {
36+
arg("Routing_Module_Name", "Compose")
37+
}

0 commit comments

Comments
 (0)