2
2
3
3
package dev.openfeature.kotlin.contrib.providers.ofrep
4
4
5
+ import INVALID_CONTEXT_PAYLOAD
6
+ import PARSE_ERROR_PAYLOAD
7
+ import VALID_1_FLAG_IN_PARSE_ERROR_PAYLOAD
8
+ import VALID_API_RESPONSE2_PAYLOAD
9
+ import VALID_API_RESPONSE_PAYLOAD
10
+ import VALID_API_SHORT_RESPONSE_PAYLOAD
5
11
import dev.openfeature.kotlin.contrib.providers.ofrep.bean.OfrepOptions
6
12
import dev.openfeature.kotlin.sdk.Client
7
13
import dev.openfeature.kotlin.sdk.EvaluationContext
@@ -86,7 +92,7 @@ class OfrepProviderTest {
86
92
runTest {
87
93
val mockEngine =
88
94
mockEngineWithOneResponse(
89
- getResourceAsString( " ofrep/valid_api_response.json " ) ,
95
+ VALID_API_RESPONSE_PAYLOAD ,
90
96
status = HttpStatusCode .fromValue(401 ),
91
97
)
92
98
@@ -114,7 +120,7 @@ class OfrepProviderTest {
114
120
runTest {
115
121
val mockEngine =
116
122
mockEngineWithOneResponse(
117
- getResourceAsString( " ofrep/valid_api_response.json " ) ,
123
+ VALID_API_RESPONSE_PAYLOAD ,
118
124
status = HttpStatusCode .fromValue(403 ),
119
125
)
120
126
@@ -142,7 +148,7 @@ class OfrepProviderTest {
142
148
runTest {
143
149
val mockEngine =
144
150
mockEngineWithOneResponse(
145
- getResourceAsString( " ofrep/valid_api_response.json " ) ,
151
+ VALID_API_RESPONSE_PAYLOAD ,
146
152
status = HttpStatusCode .fromValue(429 ),
147
153
additionalHeaders = headersOf(HttpHeaders .RetryAfter , " 3" ),
148
154
)
@@ -174,7 +180,7 @@ class OfrepProviderTest {
174
180
fun `should be in Error status if error targeting key is empty` (): Unit =
175
181
runTest {
176
182
val mockEngine =
177
- mockEngineWithOneResponse(getResourceAsString( " ofrep/valid_api_response.json " ) )
183
+ mockEngineWithOneResponse(VALID_API_RESPONSE_PAYLOAD )
178
184
179
185
val provider = createOfrepProvider(mockEngine)
180
186
var providerErrorReceived = false
@@ -205,7 +211,7 @@ class OfrepProviderTest {
205
211
fun `should be in Error status if error targeting key is missing` (): Unit =
206
212
runTest {
207
213
val mockEngine =
208
- mockEngineWithOneResponse(getResourceAsString( " ofrep/valid_api_response.json " ) )
214
+ mockEngineWithOneResponse(VALID_API_RESPONSE_PAYLOAD )
209
215
210
216
val provider = createOfrepProvider(mockEngine)
211
217
var providerErrorReceived = false
@@ -237,7 +243,7 @@ class OfrepProviderTest {
237
243
runTest {
238
244
val mockEngine =
239
245
mockEngineWithOneResponse(
240
- getResourceAsString( " ofrep/invalid_context.json " ) ,
246
+ INVALID_CONTEXT_PAYLOAD ,
241
247
status = HttpStatusCode .fromValue(400 ),
242
248
)
243
249
val provider = createOfrepProvider(mockEngine)
@@ -267,7 +273,7 @@ class OfrepProviderTest {
267
273
runTest {
268
274
val mockEngine =
269
275
mockEngineWithOneResponse(
270
- getResourceAsString( " ofrep/parse_error.json " ) ,
276
+ PARSE_ERROR_PAYLOAD ,
271
277
status = HttpStatusCode .fromValue(400 ),
272
278
)
273
279
@@ -297,7 +303,7 @@ class OfrepProviderTest {
297
303
fun `should return a flag not found error if the flag does not exist` (): Unit =
298
304
runTest {
299
305
val mockEngine =
300
- mockEngineWithOneResponse(getResourceAsString( " ofrep/valid_api_response.json " ) )
306
+ mockEngineWithOneResponse(VALID_API_RESPONSE_PAYLOAD )
301
307
val provider = createOfrepProvider(mockEngine)
302
308
withClient(provider, defaultEvalCtx, Dispatchers .IO ) { client ->
303
309
val got = client.getBooleanDetails(" non-existent-flag" , false )
@@ -319,7 +325,7 @@ class OfrepProviderTest {
319
325
runTest {
320
326
val mockEngine =
321
327
mockEngineWithOneResponse(
322
- getResourceAsString( " ofrep/valid_api_short_response.json " ) ,
328
+ VALID_API_SHORT_RESPONSE_PAYLOAD ,
323
329
)
324
330
val provider = createOfrepProvider(mockEngine)
325
331
withClient(provider, defaultEvalCtx, Dispatchers .IO ) { client ->
@@ -348,7 +354,7 @@ class OfrepProviderTest {
348
354
runTest {
349
355
val mockEngine =
350
356
mockEngineWithOneResponse(
351
- getResourceAsString( " ofrep/valid_1_flag_in_parse_error.json " ) ,
357
+ VALID_1_FLAG_IN_PARSE_ERROR_PAYLOAD ,
352
358
)
353
359
val provider = createOfrepProvider(mockEngine)
354
360
withClient(provider, defaultEvalCtx, Dispatchers .IO ) { client ->
@@ -371,8 +377,8 @@ class OfrepProviderTest {
371
377
runTest {
372
378
val mockEngine =
373
379
mockEngineWithTwoResponses(
374
- firstContent = getResourceAsString( " ofrep/valid_api_response.json " ) ,
375
- secondContent = getResourceAsString( " ofrep/valid_api_response_2.json " ) ,
380
+ firstContent = VALID_API_RESPONSE_PAYLOAD ,
381
+ secondContent = VALID_API_RESPONSE2_PAYLOAD ,
376
382
)
377
383
val provider = createOfrepProvider(mockEngine)
378
384
withClient(provider, defaultEvalCtx, Dispatchers .IO ) { client ->
@@ -432,7 +438,7 @@ class OfrepProviderTest {
432
438
fun `should return a valid evaluation for Boolean` (): Unit =
433
439
runTest {
434
440
val mockEngine =
435
- mockEngineWithOneResponse(getResourceAsString( " ofrep/valid_api_response.json " ) )
441
+ mockEngineWithOneResponse(VALID_API_RESPONSE_PAYLOAD )
436
442
val provider = createOfrepProvider(mockEngine)
437
443
withClient(provider, defaultEvalCtx, Dispatchers .IO ) { client ->
438
444
val got = client.getBooleanDetails(" bool-flag" , false )
@@ -460,7 +466,7 @@ class OfrepProviderTest {
460
466
fun `should return a valid evaluation for Int` (): Unit =
461
467
runTest {
462
468
val mockEngine =
463
- mockEngineWithOneResponse(getResourceAsString( " ofrep/valid_api_response.json " ) )
469
+ mockEngineWithOneResponse(VALID_API_RESPONSE_PAYLOAD )
464
470
val provider = createOfrepProvider(mockEngine)
465
471
withClient(provider, defaultEvalCtx, Dispatchers .IO ) { client ->
466
472
val got = client.getIntegerDetails(" int-flag" , 1 )
@@ -488,7 +494,7 @@ class OfrepProviderTest {
488
494
fun `should return a valid evaluation for Double` (): Unit =
489
495
runTest {
490
496
val mockEngine =
491
- mockEngineWithOneResponse(getResourceAsString( " ofrep/valid_api_response.json " ) )
497
+ mockEngineWithOneResponse(VALID_API_RESPONSE_PAYLOAD )
492
498
val provider = createOfrepProvider(mockEngine)
493
499
withClient(provider, defaultEvalCtx, Dispatchers .IO ) { client ->
494
500
val got = client.getDoubleDetails(" double-flag" , 1.1 )
@@ -516,7 +522,7 @@ class OfrepProviderTest {
516
522
fun `should return a valid evaluation for String` (): Unit =
517
523
runTest {
518
524
val mockEngine =
519
- mockEngineWithOneResponse(getResourceAsString( " ofrep/valid_api_response.json " ) )
525
+ mockEngineWithOneResponse(VALID_API_RESPONSE_PAYLOAD )
520
526
val provider = createOfrepProvider(mockEngine)
521
527
withClient(provider, defaultEvalCtx, Dispatchers .IO ) { client ->
522
528
val got = client.getStringDetails(" string-flag" , " default" )
@@ -544,7 +550,7 @@ class OfrepProviderTest {
544
550
fun `should return a valid evaluation for List` (): Unit =
545
551
runTest {
546
552
val mockEngine =
547
- mockEngineWithOneResponse(getResourceAsString( " ofrep/valid_api_response.json " ) )
553
+ mockEngineWithOneResponse(VALID_API_RESPONSE_PAYLOAD )
548
554
val provider = createOfrepProvider(mockEngine)
549
555
withClient(provider, defaultEvalCtx, Dispatchers .IO ) { client ->
550
556
val got =
@@ -577,7 +583,7 @@ class OfrepProviderTest {
577
583
fun `should return a valid evaluation for Map` (): Unit =
578
584
runTest {
579
585
val mockEngine =
580
- mockEngineWithOneResponse(getResourceAsString( " ofrep/valid_api_response.json " ) )
586
+ mockEngineWithOneResponse(VALID_API_RESPONSE_PAYLOAD )
581
587
val provider = createOfrepProvider(mockEngine)
582
588
withClient(provider, defaultEvalCtx, Dispatchers .IO ) { client ->
583
589
val got =
@@ -624,7 +630,7 @@ class OfrepProviderTest {
624
630
fun `should return TypeMismatch Bool` (): Unit =
625
631
runTest {
626
632
val mockEngine =
627
- mockEngineWithOneResponse(getResourceAsString( " ofrep/valid_api_response.json " ) )
633
+ mockEngineWithOneResponse(VALID_API_RESPONSE_PAYLOAD )
628
634
val provider = createOfrepProvider(mockEngine)
629
635
withClient(provider, defaultEvalCtx, Dispatchers .IO ) { client ->
630
636
val got = client.getBooleanDetails(" object-flag" , false )
@@ -647,7 +653,7 @@ class OfrepProviderTest {
647
653
fun `should return TypeMismatch String` (): Unit =
648
654
runTest {
649
655
val mockEngine =
650
- mockEngineWithOneResponse(getResourceAsString( " ofrep/valid_api_response.json " ) )
656
+ mockEngineWithOneResponse(VALID_API_RESPONSE_PAYLOAD )
651
657
val provider = createOfrepProvider(mockEngine)
652
658
withClient(provider, defaultEvalCtx, Dispatchers .IO ) { client ->
653
659
val got = client.getStringDetails(" object-flag" , " default" )
@@ -670,7 +676,7 @@ class OfrepProviderTest {
670
676
fun `should return TypeMismatch Double` (): Unit =
671
677
runTest {
672
678
val mockEngine =
673
- mockEngineWithOneResponse(getResourceAsString( " ofrep/valid_api_response.json " ) )
679
+ mockEngineWithOneResponse(VALID_API_RESPONSE_PAYLOAD )
674
680
val provider = createOfrepProvider(mockEngine)
675
681
withClient(provider, defaultEvalCtx, Dispatchers .IO ) { client ->
676
682
val got = client.getDoubleDetails(" object-flag" , 1.233 )
@@ -697,8 +703,8 @@ class OfrepProviderTest {
697
703
) {
698
704
val mockEngine =
699
705
mockEngineWithTwoResponses(
700
- firstContent = getResourceAsString( " ofrep/valid_api_short_response.json " ) ,
701
- secondContent = getResourceAsString( " ofrep/valid_api_response_2.json " ) ,
706
+ firstContent = VALID_API_SHORT_RESPONSE_PAYLOAD ,
707
+ secondContent = VALID_API_RESPONSE2_PAYLOAD ,
702
708
)
703
709
704
710
val provider = createOfrepProvider(mockEngine)
0 commit comments