Skip to content

Commit 6d03dd5

Browse files
committed
tweak
1 parent 4571ff2 commit 6d03dd5

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

playtest-http/src/main/kotlin/com/uzabase/playtest2/http/ZoomJsonSteps.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ package com.uzabase.playtest2.http
33
import com.thoughtworks.gauge.Step
44
import com.thoughtworks.gauge.datastore.ScenarioDataStore
55
import com.uzabase.playtest2.core.K
6-
import com.uzabase.playtest2.core.ScenarioDataStoreExt.ensureGet
76
import com.uzabase.playtest2.http.proxy.JsonPathProxy
7+
import java.nio.file.Path
88

99
class ZoomJsonSteps {
1010
@Step("JSONのパス<jsonPath>に対応する値が")
1111
fun zoomJson(jsonPath: String): Any =
12-
ensureGet<String>(K.AssertionTarget)
13-
.let { JsonPathProxy.of(it, jsonPath) }
12+
ScenarioDataStore.get(K.AssertionTarget)
13+
.let {
14+
when (it) {
15+
is Path -> JsonPathProxy.of(it, jsonPath);
16+
is String -> JsonPathProxy.of(it, jsonPath);
17+
else -> throw IllegalArgumentException("AssertionTarget is not a Path or a String")
18+
}
19+
}
1420
.let { ScenarioDataStore.put(K.AssertionTarget, it) }
1521
}

playtest-http/src/main/kotlin/com/uzabase/playtest2/http/proxy/JsonPathProxy.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ package com.uzabase.playtest2.http.proxy
22

33
import com.jayway.jsonpath.JsonPath
44
import com.uzabase.playtest2.core.assertion.Assertable
5+
import java.nio.file.Path
56

67
class JsonPathProxy private constructor(val json: String, val path: String) : Assertable<Any> {
78
companion object {
89
fun of(json: String, path: String): JsonPathProxy {
910
return JsonPathProxy(json, path)
1011
}
12+
fun of(jsonFilePath: Path, path: String): JsonPathProxy {
13+
return JsonPathProxy.of(jsonFilePath.toFile().readText(Charsets.UTF_8), path)
14+
}
1115
}
1216

1317
override fun shouldBe(expected: Long): Boolean = JsonPath.read<Long>(json, path) == expected

0 commit comments

Comments
 (0)