Skip to content

Commit 8511a13

Browse files
committed
text: PsiFileXPath v3
1 parent e849d3b commit 8511a13

File tree

4 files changed

+135
-22
lines changed

4 files changed

+135
-22
lines changed

src/test/kotlin/com/asyncapi/plugin/idea/_core/xpath/JsonFileXPathTest.kt renamed to src/test/kotlin/com/asyncapi/plugin/idea/_core/xpath/v2/JsonFileXPathTest.kt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
package com.asyncapi.plugin.idea._core.xpath
1+
package com.asyncapi.plugin.idea._core.xpath.v2
22

3+
import com.asyncapi.plugin.idea._core.xpath.JsonFileXPath
34
import com.intellij.json.psi.JsonFile
45
import com.intellij.lang.Language
56
import com.intellij.psi.PsiFileFactory
@@ -12,40 +13,40 @@ import junit.framework.TestCase
1213
class JsonFileXPathTest: BasePlatformTestCase() {
1314

1415
fun `test - 2_0_0`() {
15-
test("asyncapi", "2.0.0")
16+
run("asyncapi", "2.0.0")
1617
}
1718

1819
fun `test - 2_1_0`() {
19-
test("asyncapi", "2.1.0")
20+
run("asyncapi", "2.1.0")
2021
}
2122

2223
fun `test - 2_2_0`() {
23-
test("asyncapi", "2.2.0")
24+
run("asyncapi", "2.2.0")
2425
}
2526

2627
fun `test - 2_3_0`() {
27-
test("asyncapi", "2.3.0")
28+
run("asyncapi", "2.3.0")
2829
}
2930

3031
fun `test - 2_4_0`() {
31-
test("asyncapi", "2.4.0")
32+
run("asyncapi", "2.4.0")
3233
}
3334

3435
fun `test - 2_5_0`() {
35-
test("asyncapi", "2.5.0")
36+
run("asyncapi", "2.5.0")
3637
}
3738

3839
fun `test - 2_6_0`() {
39-
test("asyncapi", "2.6.0")
40+
run("asyncapi", "2.6.0")
4041
}
4142

42-
fun test(asyncapi: String, version: String) {
43+
private fun run(asyncapi: String, version: String) {
4344
val psiFileFactory = PsiFileFactory.getInstance(project)
44-
val asyncAPISchema = this.javaClass.getResource("/$asyncapi-$version.json").readText()
45+
val asyncAPISpecification = this.javaClass.getResource("/$asyncapi-$version.json").readText()
4546
val asyncAPIPSI = psiFileFactory.createFileFromText(
4647
"$asyncapi-$version.json",
4748
Language.findLanguageByID("JSON")!!,
48-
asyncAPISchema
49+
asyncAPISpecification
4950
) as JsonFile
5051

5152
collectReferencesToMessages(asyncAPIPSI)

src/test/kotlin/com/asyncapi/plugin/idea/_core/xpath/YamlFileXPathTest.kt renamed to src/test/kotlin/com/asyncapi/plugin/idea/_core/xpath/v2/YamlFileXPathTest.kt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
package com.asyncapi.plugin.idea._core.xpath
1+
package com.asyncapi.plugin.idea._core.xpath.v2
22

3+
import com.asyncapi.plugin.idea._core.xpath.YamlFileXPath
34
import com.intellij.lang.Language
45
import com.intellij.psi.PsiFileFactory
56
import com.intellij.testFramework.fixtures.BasePlatformTestCase
@@ -13,40 +14,40 @@ import org.jetbrains.yaml.psi.YAMLFile
1314
class YamlFileXPathTest: BasePlatformTestCase() {
1415

1516
fun `test - 2_0_0`() {
16-
test("asyncapi", "2.0.0")
17+
run("asyncapi", "2.0.0")
1718
}
1819

1920
fun `test - 2_1_0`() {
20-
test("asyncapi", "2.1.0")
21+
run("asyncapi", "2.1.0")
2122
}
2223

2324
fun `test - 2_2_0`() {
24-
test("asyncapi", "2.2.0")
25+
run("asyncapi", "2.2.0")
2526
}
2627

2728
fun `test - 2_3_0`() {
28-
test("asyncapi", "2.3.0")
29+
run("asyncapi", "2.3.0")
2930
}
3031

3132
fun `test - 2_4_0`() {
32-
test("asyncapi", "2.4.0")
33+
run("asyncapi", "2.4.0")
3334
}
3435

3536
fun `test - 2_5_0`() {
36-
test("asyncapi", "2.5.0")
37+
run("asyncapi", "2.5.0")
3738
}
3839

3940
fun `test - 2_6_0`() {
40-
test("asyncapi", "2.6.0")
41+
run("asyncapi", "2.6.0")
4142
}
4243

43-
fun test(asyncapi: String, version: String) {
44+
fun run(asyncapi: String, version: String) {
4445
val psiFileFactory = PsiFileFactory.getInstance(project)
45-
val asyncAPISchema = this.javaClass.getResource("/$asyncapi-$version.yaml").readText()
46+
val asyncAPISpecification = this.javaClass.getResource("/$asyncapi-$version.yaml").readText()
4647
val asyncAPIPSI = psiFileFactory.createFileFromText(
4748
"$asyncapi-$version.yaml",
4849
Language.findInstance(YAMLLanguage::class.java),
49-
asyncAPISchema
50+
asyncAPISpecification
5051
) as YAMLFile
5152

5253
collectReferencesToMessages(asyncAPIPSI)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.asyncapi.plugin.idea._core.xpath.v3
2+
3+
import com.asyncapi.plugin.idea._core.xpath.JsonFileXPath
4+
import com.intellij.json.psi.JsonFile
5+
import com.intellij.lang.Language
6+
import com.intellij.psi.PsiFileFactory
7+
import com.intellij.testFramework.fixtures.BasePlatformTestCase
8+
import junit.framework.TestCase
9+
10+
/**
11+
* @author Pavel Bodiachevskii
12+
*/
13+
class JsonFileXPathTest: BasePlatformTestCase() {
14+
15+
fun `test - 3_0_0`() {
16+
run("asyncapi", "3.0.0")
17+
}
18+
19+
private fun run(asyncapi: String, version: String) {
20+
val psiFileFactory = PsiFileFactory.getInstance(project)
21+
val asyncAPISpecification = this.javaClass.getResource("/$asyncapi-$version.json").readText()
22+
val asyncAPIPSI = psiFileFactory.createFileFromText(
23+
"$asyncapi-$version.json",
24+
Language.findLanguageByID("JSON")!!,
25+
asyncAPISpecification
26+
) as JsonFile
27+
28+
collectReferencesToMessages(asyncAPIPSI)
29+
collectReferencesToChannels(asyncAPIPSI)
30+
collectAsyncAPI(asyncAPIPSI, version)
31+
}
32+
33+
private fun collectReferencesToMessages(asyncAPI: JsonFile) {
34+
val userSignedUp = listOf(
35+
"#/components/messages/UserSignedUp",
36+
)
37+
38+
TestCase.assertEquals(userSignedUp, JsonFileXPath.findText(asyncAPI, "$.channels.*.messages.*.\$ref"))
39+
TestCase.assertEquals(userSignedUp, JsonFileXPath.findText(asyncAPI, "$.channels.userSignedup.messages.*.\$ref"))
40+
}
41+
42+
private fun collectReferencesToChannels(asyncAPI: JsonFile) {
43+
val userSignedup = listOf(
44+
"#/channels/userSignedup",
45+
)
46+
47+
TestCase.assertEquals(userSignedup, JsonFileXPath.findText(asyncAPI, "$.operations.*.channel.\$ref"))
48+
TestCase.assertEquals(userSignedup, JsonFileXPath.findText(asyncAPI, "$.operations.processUserSignups.channel.\$ref"))
49+
}
50+
51+
private fun collectAsyncAPI(asyncAPI: JsonFile, version: String) {
52+
TestCase.assertEquals(listOf(version), JsonFileXPath.findText(asyncAPI, "$.asyncapi"))
53+
}
54+
55+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.asyncapi.plugin.idea._core.xpath.v3
2+
3+
import com.asyncapi.plugin.idea._core.xpath.YamlFileXPath
4+
import com.intellij.lang.Language
5+
import com.intellij.psi.PsiFileFactory
6+
import com.intellij.testFramework.fixtures.BasePlatformTestCase
7+
import junit.framework.TestCase
8+
import org.jetbrains.yaml.YAMLLanguage
9+
import org.jetbrains.yaml.psi.YAMLFile
10+
11+
/**
12+
* @author Pavel Bodiachevskii
13+
*/
14+
class YamlFileXPathTest: BasePlatformTestCase() {
15+
16+
fun `test - 3_0_0`() {
17+
run("asyncapi", "3.0.0")
18+
}
19+
20+
fun run(asyncapi: String, version: String) {
21+
val psiFileFactory = PsiFileFactory.getInstance(project)
22+
val asyncAPISpecification = this.javaClass.getResource("/$asyncapi-$version.yaml").readText()
23+
val asyncAPIPSI = psiFileFactory.createFileFromText(
24+
"$asyncapi-$version.yaml",
25+
Language.findInstance(YAMLLanguage::class.java),
26+
asyncAPISpecification
27+
) as YAMLFile
28+
29+
collectReferencesToMessages(asyncAPIPSI)
30+
collectReferencesToChannels(asyncAPIPSI)
31+
collectAsyncAPI(asyncAPIPSI, version)
32+
}
33+
34+
private fun collectReferencesToMessages(asyncAPI: YAMLFile) {
35+
val userSignedUp = listOf(
36+
"#/components/messages/UserSignedUp",
37+
)
38+
39+
TestCase.assertEquals(userSignedUp, YamlFileXPath.findText(asyncAPI, "$.channels.*.messages.*.\$ref"))
40+
TestCase.assertEquals(userSignedUp, YamlFileXPath.findText(asyncAPI, "$.channels.userSignedup.messages.*.\$ref"))
41+
}
42+
43+
private fun collectReferencesToChannels(asyncAPI: YAMLFile) {
44+
val userSignedup = listOf(
45+
"#/channels/userSignedup",
46+
)
47+
48+
TestCase.assertEquals(userSignedup, YamlFileXPath.findText(asyncAPI, "$.operations.*.channel.\$ref"))
49+
TestCase.assertEquals(userSignedup, YamlFileXPath.findText(asyncAPI, "$.operations.processUserSignups.channel.\$ref"))
50+
}
51+
52+
private fun collectAsyncAPI(asyncAPI: YAMLFile, version: String) {
53+
TestCase.assertEquals(listOf(version), YamlFileXPath.findText(asyncAPI, "$.asyncapi"))
54+
}
55+
56+
}

0 commit comments

Comments
 (0)