Skip to content

Commit 2c10638

Browse files
committed
- Implement randomAlphanumeric() for dynamic variable Generators
- Doc edits Signed-off-by: Gopal S Akshintala <[email protected]>
1 parent 86c3eb7 commit 2c10638

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

README.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ ____
114114
** link:{sourcedir}/com/salesforce/revoman/internal/postman/DynamicVariableGenerator.kt[Dynamic variables], e.g., `{{$randomUUID}}`, `{{$randomEmail}}`
115115
** <<Custom Dynamic variables>>
116116

117+
[NOTE]
118+
====
119+
In the case of collision between variable keys, the precedence order to derive a value to replace any key is:
120+
121+
. Custom Dynamic variables
122+
. Generated Dynamic variables
123+
. Dynamic Environment supplied through config + Environment built during execution + Postman environment supplied as a file through config
124+
====
125+
117126
[.lead]
118127
You can _kick off_ this *Template-Driven Testing* by invoking `ReVoman.revUp()`,
119128
supplying your Postman templates and environments, and all your customizations through a configuration:

build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
id("revoman.kt-conventions")
1212
alias(libs.plugins.moshix)
1313
alias(libs.plugins.node.gradle)
14-
// alias(libs.plugins.kover)
14+
alias(libs.plugins.kover)
1515
alias(libs.plugins.nexus.publish)
1616
alias(libs.plugins.gradle.taskinfo)
1717
}
@@ -23,7 +23,6 @@ dependencies {
2323
api(libs.kotlin.vavr)
2424
api(libs.arrow.core)
2525
api(libs.kotlinx.datetime)
26-
implementation(libs.apache.commons.lang3)
2726
implementation(libs.bundles.kotlin.logging)
2827
implementation(libs.pprint)
2928
implementation(libs.graal.js)

libs.versions.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ kotlin-logging = "7.0.0"
1919
pprint = "3.0.0"
2020
underscore = "1.105"
2121
kotlin-faker = "1.16.0"
22-
apache-commons-lang3 = "3.17.0"
2322
mockito = "5.14.0"
2423
spring = "6.2.0"
2524
json-assert = "1.5.3"
@@ -70,7 +69,6 @@ mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockito" }
7069
spring-beans = { module = "org.springframework:spring-beans", version.ref = "spring" }
7170
json-assert = { module = "org.skyscreamer:jsonassert", version.ref = "json-assert" }
7271
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime-jvm", version.ref = "kotlinx-datetime" }
73-
apache-commons-lang3 = { module = "org.apache.commons:commons-lang3", version.ref = "apache-commons-lang3" }
7472
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
7573

7674
# Gradle plugins

src/main/kotlin/com/salesforce/revoman/internal/postman/DynamicVariableGenerator.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import kotlin.random.Random.Default.nextBoolean
1414
import kotlin.random.Random.Default.nextInt
1515
import kotlin.random.Random.Default.nextLong
1616
import kotlinx.datetime.Clock
17-
import org.apache.commons.lang3.RandomStringUtils
1817

1918
private val faker = faker {}
2019

@@ -31,7 +30,7 @@ private val dynamicVariableGenerators: Map<String, () -> String> =
3130
"\$isoTimestamp" to { Clock.System.now().toString() },
3231
"\$randomUUID" to { UUID.randomUUID().toString() },
3332
// Text, numbers, and colors
34-
"\$randomAlphaNumeric" to { RandomStringUtils.randomAlphanumeric(1) },
33+
"\$randomAlphaNumeric" to { randomAlphanumeric(1) },
3534
"\$randomBoolean" to { nextBoolean().toString() },
3635
"\$randomInt" to { nextInt(0, Int.MAX_VALUE).toString() },
3736
"\$randomColor" to faker.color::name,
@@ -40,7 +39,7 @@ private val dynamicVariableGenerators: Map<String, () -> String> =
4039
"\$randomIP" to faker.internet::iPv4Address,
4140
"\$randomIPV6" to faker.internet::iPv6Address,
4241
"\$randomMACAddress" to { faker.internet.macAddress() },
43-
"\$randomPassword" to { RandomStringUtils.randomAlphanumeric(15) },
42+
"\$randomPassword" to { randomAlphanumeric(15) },
4443
// Names
4544
"\$randomFirstName" to faker.name::firstName,
4645
"\$randomLastName" to faker.name::lastName,
@@ -64,6 +63,11 @@ private val dynamicVariableGenerators: Map<String, () -> String> =
6463

6564
fun getRandomHex() = nextInt(255).toString(16).uppercase()
6665

66+
private val charPool = ('a'..'z') + ('A'..'Z') + ('0'..'9')
67+
68+
fun randomAlphanumeric(length: Int) =
69+
(1..length).map { charPool[nextInt(0, charPool.size)] }.joinToString("")
70+
6771
private val dynamicVariableGeneratorsWithPM: Map<String, (PostmanSDK) -> String> =
6872
mapOf("\$currentRequestName" to { it.info.requestName })
6973

src/main/kotlin/com/salesforce/revoman/internal/postman/RegexReplacer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class RegexReplacer(
2525
* Order of Variable resolution
2626
* <ul>
2727
* <li>Custom Dynamic Variables</li>
28-
* <li>Dynamic variable supplied through config </li>
29-
* <li>Environment built during execution + Postman environment supplied as a file through
28+
* <li>Generated Dynamic variables</li>
29+
* <li>Dynamic Environment supplied through config + Environment built during execution + Postman environment supplied as a file through
3030
* config</li>
3131
* </ul>
3232
*/

0 commit comments

Comments
 (0)