Skip to content

Commit 832274a

Browse files
committed
- Refactor pre and post step hooks
- Add javadocs to few steps Signed-off-by: Gopal S Akshintala <[email protected]>
1 parent 13c1bdc commit 832274a

File tree

6 files changed

+37
-20
lines changed

6 files changed

+37
-20
lines changed

src/main/kotlin/com/salesforce/revoman/input/config/KickDef.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ internal interface KickDef {
6060

6161
@Value.Derived fun postHooks(): List<HookConfig> = hooks().filter { it.pick is PostTxnStepPick }
6262

63-
// * NOTE 29/10/23 gopala.akshintala: requestConfig/responseConfig are decoupled from pre- /
64-
// post-hook to allow setting up unmarshalling to strong types on the final rundown for
63+
// * NOTE 29/10/23 gopala.akshintala: requestConfig/responseConfig are decoupled from pre-step /
64+
// post-step hook to allow setting up unmarshalling to strong types on the final rundown for
6565
// post-execution assertions agnostic of whether the step has any hooks
6666

6767
fun requestConfig(): Set<RequestConfig>

src/main/kotlin/com/salesforce/revoman/input/config/StepPick.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ sealed interface StepPick {
3535
fun pick(currentStep: Step, currentRequestInfo: TxnInfo<Request>, rundown: Rundown): Boolean
3636

3737
companion object PickUtils {
38+
/**
39+
* If there are steps with the same name, you may pass the stepName along with the folderPath,
40+
* where each folder is seperated by FOLDER_DELIMITER {@see com.salesforce.revoman.output.report.Folder.FOLDER_DELIMITER}
41+
* You may not have to pass the entire path,
42+
* you can pass the path from the Least common Ancestor
43+
* to uniquely identify the step of your interest to add this Hook
44+
*/
3845
@JvmStatic
3946
fun beforeStepName(vararg stepNameSubstrings: String) = PreTxnStepPick { currentStep, _, _ ->
4047
stepNameSubstrings.any { currentStep.stepNameMatches(it) }
@@ -50,6 +57,9 @@ sealed interface StepPick {
5057
requestInfo.containsHeader(key)
5158
}
5259

60+
/**
61+
* Provide either a full URI path or a partial URI path that can uniquely identify the request
62+
*/
5363
@JvmStatic
5464
fun beforeStepContainingURIPathOfAny(vararg paths: String) =
5565
PreTxnStepPick { _, requestInfo, _ ->
@@ -62,6 +72,13 @@ sealed interface StepPick {
6272
@Throws(Throwable::class) fun pick(currentStepReport: StepReport, rundown: Rundown): Boolean
6373

6474
companion object PickUtils {
75+
/**
76+
* If there are steps with the same name, you may pass the stepName along with the folderPath,
77+
* where each folder is seperated by FOLDER_DELIMITER {@see com.salesforce.revoman.output.report.Folder.FOLDER_DELIMITER}
78+
* You may not have to pass the entire path,
79+
* you can pass the path from the Least common Ancestor
80+
* to uniquely identify the step of your interest to add this Hook
81+
*/
6582
@JvmStatic
6683
fun afterStepName(vararg stepNameSubstrings: String) = PostTxnStepPick { stepReport, _ ->
6784
stepNameSubstrings.any { stepReport.step.stepNameMatches(it) }
@@ -77,6 +94,9 @@ sealed interface StepPick {
7794
stepReport.requestInfo.containsHeader(key)
7895
}
7996

97+
/**
98+
* Provide either a full URI path or a partial URI path that can uniquely identify the request
99+
*/
80100
@JvmStatic
81101
fun afterStepContainingURIPathOfAny(vararg paths: String) = PostTxnStepPick { stepReport, _ ->
82102
paths.any { stepReport.requestInfo.uriPathContains(it) }

src/main/kotlin/com/salesforce/revoman/internal/exe/PostStepHook.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import io.github.oshai.kotlinlogging.KotlinLogging
2020

2121
internal fun postHookExe(kick: Kick, pm: PostmanSDK): PostStepHookFailure? =
2222
pickPostHooks(kick.postHooks(), pm.currentStepReport, pm.rundown)
23-
.asSequence()
2423
.map { postHook ->
2524
runChecked(pm.currentStepReport.step, POST_STEP_HOOK) {
2625
postHook.accept(pm.currentStepReport, pm.rundown)
@@ -34,16 +33,15 @@ private fun pickPostHooks(
3433
postHooks: List<HookConfig>,
3534
currentStepReport: StepReport,
3635
rundown: Rundown,
37-
): List<PostStepHook> =
36+
): Sequence<PostStepHook> =
3837
postHooks
3938
.asSequence()
4039
.filter { (it.pick as PostTxnStepPick).pick(currentStepReport, rundown) }
4140
.map { it.stepHook as PostStepHook }
42-
.toList()
4341
.also {
44-
if (it.isNotEmpty()) {
45-
logger.info { "${currentStepReport.step} Picked Post hook count : ${it.size}" }
46-
currentStepReport.step.postHookCount = it.size
42+
if (it.iterator().hasNext()) {
43+
logger.info { "${currentStepReport.step} Picked Post hook count : ${it.count()}" }
44+
currentStepReport.step.postHookCount = it.count()
4745
}
4846
}
4947

src/main/kotlin/com/salesforce/revoman/internal/exe/PreStepHook.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ internal fun preHookExe(
2727
pm: PostmanSDK,
2828
): PreStepHookFailure? =
2929
pickPreHooks(kick.preHooks(), currentStep, requestInfo, pm.rundown)
30-
.asSequence()
3130
.map { preHook ->
3231
runChecked(currentStep, PRE_STEP_HOOK) {
3332
preHook.accept(currentStep, requestInfo, pm.rundown)
@@ -42,16 +41,15 @@ private fun pickPreHooks(
4241
currentStep: Step,
4342
requestInfo: TxnInfo<Request>,
4443
rundown: Rundown,
45-
): List<PreStepHook> =
44+
): Sequence<PreStepHook> =
4645
preHooks
4746
.asSequence()
4847
.filter { (it.pick as PreTxnStepPick).pick(currentStep, requestInfo, rundown) }
4948
.map { it.stepHook as PreStepHook }
50-
.toList()
5149
.also {
52-
if (it.isNotEmpty()) {
53-
logger.info { "$currentStep Picked Pre hook count : ${it.size}" }
54-
currentStep.preHookCount = it.size
50+
if (it.iterator().hasNext()) {
51+
logger.info { "$currentStep Picked Pre hook count : ${it.count()}" }
52+
currentStep.preHookCount = it.count()
5553
}
5654
}
5755

src/main/kotlin/com/salesforce/revoman/internal/exe/UnmarshallRequest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ internal fun unmarshallRequest(
4141
?.objType ?: Any::class.java
4242
return when {
4343
isJson(httpRequest) ->
44-
runChecked<Any?>(currentStep, UNMARSHALL_REQUEST) {
44+
runChecked(currentStep, UNMARSHALL_REQUEST) {
4545
pmRequest.body?.let { body -> moshiReVoman.asA(body.raw, requestType.rawType.kotlin) }
4646
}
4747
.mapLeft { UnmarshallRequestFailure(it, TxnInfo(requestType, null, httpRequest)) }

src/main/kotlin/com/salesforce/revoman/output/report/Step.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ constructor(
6969
@JvmField val path: List<Folder> = parentPath + this
7070

7171
override fun toString(): String =
72-
if (isRoot) name
73-
else
74-
parentPath.joinToString(separator = FOLDER_DELIMITER, postfix = FOLDER_DELIMITER) {
75-
it.name
76-
} + name
72+
when {
73+
isRoot -> name
74+
else -> parentPath.joinToString(separator = FOLDER_DELIMITER, postfix = FOLDER_DELIMITER) {
75+
it.name
76+
} + name
77+
}
7778

7879
companion object {
7980
const val FOLDER_DELIMITER = "|>"

0 commit comments

Comments
 (0)