Skip to content

Commit 333f367

Browse files
committed
Add a scenario to pass custom adapter via getTypedTxnObj
Signed-off-by: Gopal S Akshintala <[email protected]>
1 parent e5a1585 commit 333f367

File tree

9 files changed

+35
-20
lines changed

9 files changed

+35
-20
lines changed

README.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ POKEMON_COMMON_CONFIG.overrideHooks(kotlin.collections.CollectionsKt.plus(POKEMO
364364
Kick.configure().from(configInstance1).from(configInstance2)...off();
365365
----
366366

367+
CAUTION: Iterable attributes (like `List`, `Map` etc) accept an `Iterable`. If you are particular about the order, make sure to pass an Ordered instance of `Iterable` (like `ArrayList`)
368+
367369
[#_debugging_dx]
368370
== Troubleshooting DX
369371

@@ -580,7 +582,7 @@ Instead, you have a Java utility to generate/create it.
580582
You can invoke the utility in a pre-hook of a step and set the value in `rundown.mutableEnv`,
581583
so the later steps can pick up value for `+{{xyzId}}+` variable from the environment.
582584

583-
CAUTION: When a Step qualifies for more than one hook, hooks are executed in the same sequence they are configured, either using `hooks()` or `overrideHooks()`. Both these methods accept an `iterable`. Make sure to pass an Ordered Iterable (like `ArrayList<>`), if you are particular about Order in which hooks should execute for a Step.
585+
CAUTION: When a Step qualifies for more than one hook, hooks are executed in the same sequence they are configured, either using `hooks()` or `overrideHooks()`. Both these methods accept an `iterable`. Make sure to pass an Ordered Iterable (like `ArrayList`), if you are particular about Order in which hooks should execute for a Step.
584586

585587
[#_response_validations]
586588
==== Response Validations

src/integrationTest/java/com/salesforce/revoman/integration/core/adapters/IDAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ ID fromJson(String id) {
2222

2323
@ToJson
2424
String toJson(ID id) {
25-
return id.getId();
25+
return id.id();
2626
}
2727
}

src/integrationTest/java/com/salesforce/revoman/integration/core/pq/connect/response/ID.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,4 @@
77

88
package com.salesforce.revoman.integration.core.pq.connect.response;
99

10-
public class ID {
11-
private final String id;
12-
13-
public ID(String id) {
14-
this.id = id;
15-
}
16-
17-
public String getId() {
18-
return id;
19-
}
20-
}
10+
public record ID(String id) {}

src/integrationTest/java/com/salesforce/revoman/integration/pokemon/PokemonTest.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424
import com.salesforce.revoman.input.config.HookConfig.StepHook.PostStepHook;
2525
import com.salesforce.revoman.input.config.HookConfig.StepHook.PreStepHook;
2626
import com.salesforce.revoman.input.config.Kick;
27+
import com.salesforce.revoman.integration.core.adapters.IDAdapter;
28+
import com.salesforce.revoman.integration.core.pq.connect.response.ID;
2729
import com.salesforce.revoman.output.Rundown;
2830
import com.salesforce.revoman.output.report.Step;
2931
import com.salesforce.revoman.output.report.StepReport;
3032
import com.salesforce.revoman.output.report.TxnInfo;
3133
import com.salesforce.revoman.output.report.failure.HookFailure.PostStepHookFailure;
34+
import com.squareup.moshi.Json;
3235
import java.util.List;
3336
import java.util.Map;
3437
import org.http4k.core.Request;
@@ -113,6 +116,14 @@ public void accept(@NotNull StepReport stepReport, @NotNull Rundown rundown) {
113116
"Picked `postHookAfterURIPath` after stepName: {} with raw URI: {}",
114117
stepReport.step.displayName,
115118
stepReport.step.rawPMStep.getRequest().url);
119+
final var id =
120+
stepReport
121+
.responseInfo
122+
.map(
123+
ri ->
124+
ri.<Color>getTypedTxnObj(Color.class, List.of(new IDAdapter())).id)
125+
.getOrNull();
126+
assertThat(id.id()).isEqualTo(rundown.mutableEnv.get("id"));
116127
}
117128
});
118129
final var pokeRundown =
@@ -124,7 +135,7 @@ public void accept(@NotNull StepReport stepReport, @NotNull Rundown rundown) {
124135
.hooks(
125136
pre(beforeStepName("all-pokemon"), preHook),
126137
post(afterStepName("all-pokemon"), postHook),
127-
post(afterStepContainingURIPathOfAny("nature"), postHookAfterURIPath),
138+
post(afterStepContainingURIPathOfAny("pokemon-color"), postHookAfterURIPath),
128139
pre(beforeStepContainingHeader("preLog"), preLogHook),
129140
post(afterStepContainingHeader("postLog"), postLogHook))
130141
.dynamicEnvironment(dynamicEnvironment)
@@ -155,4 +166,16 @@ public void accept(@NotNull StepReport stepReport, @NotNull Rundown rundown) {
155166
public record AllPokemon(int count, String next, String previous, List<Result> results) {
156167
public record Result(String name, String url) {}
157168
}
169+
170+
public record Color(
171+
ID id,
172+
String name,
173+
List<Name> names,
174+
@Json(name = "pokemon_species") List<PokemonSpecies> pokemonSpecies) {
175+
public record Name(Language language, String name) {
176+
public record Language(String name, String url) {}
177+
}
178+
179+
public record PokemonSpecies(String name, String url) {}
180+
}
158181
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ internal interface KickDef {
7070
fun customTypeAdaptersFromRequestConfig(): Map<Type, Either<JsonAdapter<out Any>, Factory>> =
7171
requestConfig()
7272
.filter { it.customTypeAdapter != null }
73-
.associate { it.objType to it.customTypeAdapter!! }
73+
.associate { it.requestType to it.customTypeAdapter!! }
7474

7575
fun responseConfig(): Set<ResponseConfig>
7676

@@ -82,7 +82,7 @@ internal interface KickDef {
8282
fun customTypeAdaptersFromResponseConfig(): Map<Type, Either<JsonAdapter<out Any>, Factory>> =
8383
responseConfig()
8484
.filter { it.customTypeAdapter != null }
85-
.associate { it.objType to it.customTypeAdapter!! }
85+
.associate { it.responseType to it.customTypeAdapter!! }
8686

8787
fun globalCustomTypeAdapters(): List<Any>
8888

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import java.lang.reflect.Type
1717
data class RequestConfig
1818
internal constructor(
1919
val preTxnStepPick: PreTxnStepPick,
20-
val objType: Type,
20+
val requestType: Type,
2121
val customTypeAdapter: Either<JsonAdapter<out Any>, JsonAdapter.Factory>? = null,
2222
) {
2323
companion object {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ data class ResponseConfig
1818
internal constructor(
1919
val postTxnStepPick: PostTxnStepPick,
2020
val ifSuccess: Boolean?,
21-
val objType: Type,
21+
val responseType: Type,
2222
val customTypeAdapter: Either<JsonAdapter<out Any>, JsonAdapter.Factory>? = null,
2323
) {
2424
companion object {

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
)
4242
}
4343
?.also { logger.info { "$currentStep RequestConfig found : ${pprint(it)}" } }
44-
?.objType ?: Any::class.java
44+
?.requestType ?: Any::class.java
4545
return when {
4646
isJson(httpRequest) ->
4747
runCatching(currentStep, UNMARSHALL_REQUEST) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal fun unmarshallResponse(
4040
val responseType: Type =
4141
responseConfig
4242
?.also { logger.info { "$currentStep ResponseConfig found : ${pprint(it)}" } }
43-
?.objType ?: Any::class.java
43+
?.responseType ?: Any::class.java
4444
val requestInfo = pm.currentStepReport.requestInfo!!.get()
4545
runCatching(currentStep, UNMARSHALL_RESPONSE) {
4646
moshiReVoman.fromJson<Any>(httpResponse.bodyString(), responseType)

0 commit comments

Comments
 (0)