Skip to content

Commit ff9c9a7

Browse files
committed
Release 0.5.4
Fix TxnInfo bug Signed-off-by: Gopal S Akshintala <[email protected]>
1 parent 6f9b548 commit ff9c9a7

File tree

6 files changed

+59
-15
lines changed

6 files changed

+59
-15
lines changed

README.adoc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ endif::[]
1818
:pmtemplates: src/integrationTest/resources/pm-templates
1919
:imagesdir: docs/images
2020
:prewrap!:
21-
:revoman-version: 0.5.3
21+
:revoman-version: 0.5.4
2222

2323
'''
2424

@@ -409,7 +409,7 @@ The configuration offers methods through which the execution strategy can be con
409409
[#_pre_step_and_post_step_hooks]
410410
=== Pre-Step and Post-Step Hooks
411411

412-
A hook lets you fiddle with the execution by plugging in your code before or after a Step execution.
412+
A hook lets you fiddle with the execution by plugging in your custom code before or after a Step execution.
413413

414414
[#_step_picks]
415415
You can pass a `PreTxnStepPick/PostTxnStepPick` which is a `Predicate` used
@@ -442,9 +442,12 @@ Add them to the config as below:
442442
)
443443
----
444444

445-
You can do things like assertion on the rundown, response validation,
445+
* You can do things like assertion on the rundown, response validation,
446446
or even <<#_mutable_environment,mutate the environment>> with a value you programmatically derived,
447447
such that the execution of later steps picks up those changes.
448+
* Reserve hooks for plugging in your custom code or asserting and fail-fast in the middle of execution.
449+
If your assertions can wait till the final rundown,
450+
it's cleaner to write them after the `revUp()` returns the rundown instead of adding hooks for each step
448451

449452
[#_plug_in_your_java_code_in_between_postman_execution]
450453
==== Plug-in your Java code in-between Postman execution

buildSrc/src/main/kotlin/Config.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
* ************************************************************************************************
77
*/
88
const val GROUP_ID = "com.salesforce.revoman"
9-
const val VERSION = "0.5.3"
9+
const val VERSION = "0.5.4"
1010
const val ARTIFACT_ID = "revoman"
1111
const val STAGING_PROFILE_ID = "1ea0a23e61ba7d"

src/main/kotlin/com/salesforce/revoman/output/postman/PostmanEnvironment.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,18 @@ constructor(
108108
fun <T : Any> getTypedObj(key: String, objType: Type): T? {
109109
val value = mutableEnv[key]
110110
return when {
111+
value == null -> null
111112
objType.rawType.isInstance(value) -> value
112113
else -> moshiReVoman.asA(moshiReVoman.asFormatString(value as Any), objType.rawType.kotlin)
113114
}
114-
as T
115+
as T?
115116
}
116117

117118
inline fun <reified T : Any> getObj(key: String): T? {
118119
val value = mutableEnv[key]
119-
return when {
120-
value is T -> value
120+
return when (value) {
121+
null,
122+
is T -> value
121123
else -> moshiReVoman.asA(moshiReVoman.asFormatString(value as Any), T::class)
122124
}
123125
}

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ constructor(
3333
typesToIgnore: Set<Class<out Any>> = emptySet(),
3434
): T? =
3535
when {
36-
customAdapters.isEmpty() &&
37-
customAdaptersWithType.isEmpty() &&
38-
typesToIgnore.isEmpty() &&
39-
this.txnObjType == Any::class.java -> (txnObjType as? Class<T>)?.cast(txnObj)
36+
customAdapters.isEmpty() && customAdaptersWithType.isEmpty() && typesToIgnore.isEmpty() ->
37+
(txnObjType as? Class<T>)?.cast(txnObj)
4038
else ->
4139
jsonToPojo(
4240
txnObjType,
@@ -55,10 +53,8 @@ constructor(
5553
typesToIgnore: Set<Class<out Any>> = emptySet(),
5654
): T? =
5755
when {
58-
customAdapters.isEmpty() &&
59-
customAdaptersWithType.isEmpty() &&
60-
typesToIgnore.isEmpty() &&
61-
txnObjType == Any::class.java -> txnObj as? T
56+
customAdapters.isEmpty() && customAdaptersWithType.isEmpty() && typesToIgnore.isEmpty() ->
57+
txnObj as? T
6258
else ->
6359
jsonToPojo(
6460
T::class.java,

src/test/java/com/salesforce/revoman/output/postman/PostmanEnvironmentTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import static com.google.common.truth.Truth.assertThat;
1111

12+
import com.squareup.moshi.Types;
13+
import java.util.List;
1214
import java.util.Map;
1315
import java.util.Set;
1416
import org.junit.jupiter.api.DisplayName;
@@ -34,4 +36,24 @@ void multiLevelFiltering() {
3436
assertThat(filteredEnv)
3537
.containsExactlyEntriesIn(Map.of("mockTaxAdapterId", "mockTaxAdapterId"));
3638
}
39+
40+
@Test
41+
@DisplayName("get Typed Obj")
42+
void getTypedObj() {
43+
final var env =
44+
io.vavr.collection.HashMap.of(
45+
"key1", 1, "key2", "2", "key3", List.of(1, 2, 3), "key4", Map.of("4", 4), "key5", null);
46+
final var pm = new PostmanEnvironment<>(env.toJavaMap());
47+
assertThat(pm.<Integer>getTypedObj("key1", Integer.class)).isEqualTo(env.get("key1").get());
48+
assertThat(pm.<String>getTypedObj("key2", String.class)).isEqualTo(env.get("key2").get());
49+
assertThat(
50+
pm.<List<Integer>>getTypedObj(
51+
"key3", Types.newParameterizedType(List.class, Integer.class)))
52+
.containsExactlyElementsIn((Iterable<?>) env.get("key3").get());
53+
assertThat(
54+
pm.<Map<String, Integer>>getTypedObj(
55+
"key4", Types.newParameterizedType(Map.class, String.class, Integer.class)))
56+
.containsExactlyEntriesIn((Map<?, ?>) env.get("key4").get());
57+
assertThat(pm.<Object>getTypedObj("key5", Object.class)).isNull();
58+
}
3759
}

src/test/kotlin/com/salesforce/revoman/output/report/PostmanEnvironmentKtTest.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ package com.salesforce.revoman.output.report
99

1010
import com.salesforce.revoman.input.readFileInResourcesToString
1111
import com.salesforce.revoman.output.postman.PostmanEnvironment
12+
import io.kotest.matchers.equals.shouldBeEqual
13+
import io.kotest.matchers.maps.shouldContainExactly
14+
import io.kotest.matchers.shouldBe
1215
import org.junit.jupiter.api.Test
1316
import org.skyscreamer.jsonassert.JSONAssert
1417
import org.skyscreamer.jsonassert.JSONCompareMode
@@ -32,4 +35,22 @@ class PostmanEnvironmentKtTest {
3235
JSONCompareMode.STRICT,
3336
)
3437
}
38+
39+
@Test
40+
fun `get Typed Obj`() {
41+
val env =
42+
mutableMapOf(
43+
"key1" to 1,
44+
"key2" to "2",
45+
"key3" to listOf(1, 2, 3),
46+
"key4" to mapOf("4" to 4),
47+
"key5" to null,
48+
)
49+
val pm = PostmanEnvironment<Any?>(env)
50+
pm.getObj<Int>("key1")!! shouldBeEqual env["key1"] as Int
51+
pm.getObj<String>("key2")!! shouldBeEqual env["key2"] as String
52+
pm.getObj<List<Int>>("key3")!! shouldBeEqual env["key3"] as List<Int>
53+
pm.getObj<Map<String, Int>>("key4")!! shouldContainExactly env["key4"] as Map<String, Int>
54+
pm.getObj<Any>("key5") shouldBe null
55+
}
3556
}

0 commit comments

Comments
 (0)