Skip to content

Commit

Permalink
text: PsiFileXPath v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed Dec 11, 2023
1 parent e849d3b commit 8511a13
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.asyncapi.plugin.idea._core.xpath
package com.asyncapi.plugin.idea._core.xpath.v2

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

fun `test - 2_0_0`() {
test("asyncapi", "2.0.0")
run("asyncapi", "2.0.0")
}

fun `test - 2_1_0`() {
test("asyncapi", "2.1.0")
run("asyncapi", "2.1.0")
}

fun `test - 2_2_0`() {
test("asyncapi", "2.2.0")
run("asyncapi", "2.2.0")
}

fun `test - 2_3_0`() {
test("asyncapi", "2.3.0")
run("asyncapi", "2.3.0")
}

fun `test - 2_4_0`() {
test("asyncapi", "2.4.0")
run("asyncapi", "2.4.0")
}

fun `test - 2_5_0`() {
test("asyncapi", "2.5.0")
run("asyncapi", "2.5.0")
}

fun `test - 2_6_0`() {
test("asyncapi", "2.6.0")
run("asyncapi", "2.6.0")
}

fun test(asyncapi: String, version: String) {
private fun run(asyncapi: String, version: String) {
val psiFileFactory = PsiFileFactory.getInstance(project)
val asyncAPISchema = this.javaClass.getResource("/$asyncapi-$version.json").readText()
val asyncAPISpecification = this.javaClass.getResource("/$asyncapi-$version.json").readText()
val asyncAPIPSI = psiFileFactory.createFileFromText(
"$asyncapi-$version.json",
Language.findLanguageByID("JSON")!!,
asyncAPISchema
asyncAPISpecification
) as JsonFile

collectReferencesToMessages(asyncAPIPSI)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.asyncapi.plugin.idea._core.xpath
package com.asyncapi.plugin.idea._core.xpath.v2

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

fun `test - 2_0_0`() {
test("asyncapi", "2.0.0")
run("asyncapi", "2.0.0")
}

fun `test - 2_1_0`() {
test("asyncapi", "2.1.0")
run("asyncapi", "2.1.0")
}

fun `test - 2_2_0`() {
test("asyncapi", "2.2.0")
run("asyncapi", "2.2.0")
}

fun `test - 2_3_0`() {
test("asyncapi", "2.3.0")
run("asyncapi", "2.3.0")
}

fun `test - 2_4_0`() {
test("asyncapi", "2.4.0")
run("asyncapi", "2.4.0")
}

fun `test - 2_5_0`() {
test("asyncapi", "2.5.0")
run("asyncapi", "2.5.0")
}

fun `test - 2_6_0`() {
test("asyncapi", "2.6.0")
run("asyncapi", "2.6.0")
}

fun test(asyncapi: String, version: String) {
fun run(asyncapi: String, version: String) {
val psiFileFactory = PsiFileFactory.getInstance(project)
val asyncAPISchema = this.javaClass.getResource("/$asyncapi-$version.yaml").readText()
val asyncAPISpecification = this.javaClass.getResource("/$asyncapi-$version.yaml").readText()
val asyncAPIPSI = psiFileFactory.createFileFromText(
"$asyncapi-$version.yaml",
Language.findInstance(YAMLLanguage::class.java),
asyncAPISchema
asyncAPISpecification
) as YAMLFile

collectReferencesToMessages(asyncAPIPSI)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.asyncapi.plugin.idea._core.xpath.v3

import com.asyncapi.plugin.idea._core.xpath.JsonFileXPath
import com.intellij.json.psi.JsonFile
import com.intellij.lang.Language
import com.intellij.psi.PsiFileFactory
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import junit.framework.TestCase

/**
* @author Pavel Bodiachevskii
*/
class JsonFileXPathTest: BasePlatformTestCase() {

fun `test - 3_0_0`() {
run("asyncapi", "3.0.0")
}

private fun run(asyncapi: String, version: String) {
val psiFileFactory = PsiFileFactory.getInstance(project)
val asyncAPISpecification = this.javaClass.getResource("/$asyncapi-$version.json").readText()
val asyncAPIPSI = psiFileFactory.createFileFromText(
"$asyncapi-$version.json",
Language.findLanguageByID("JSON")!!,
asyncAPISpecification
) as JsonFile

collectReferencesToMessages(asyncAPIPSI)
collectReferencesToChannels(asyncAPIPSI)
collectAsyncAPI(asyncAPIPSI, version)
}

private fun collectReferencesToMessages(asyncAPI: JsonFile) {
val userSignedUp = listOf(
"#/components/messages/UserSignedUp",
)

TestCase.assertEquals(userSignedUp, JsonFileXPath.findText(asyncAPI, "$.channels.*.messages.*.\$ref"))
TestCase.assertEquals(userSignedUp, JsonFileXPath.findText(asyncAPI, "$.channels.userSignedup.messages.*.\$ref"))
}

private fun collectReferencesToChannels(asyncAPI: JsonFile) {
val userSignedup = listOf(
"#/channels/userSignedup",
)

TestCase.assertEquals(userSignedup, JsonFileXPath.findText(asyncAPI, "$.operations.*.channel.\$ref"))
TestCase.assertEquals(userSignedup, JsonFileXPath.findText(asyncAPI, "$.operations.processUserSignups.channel.\$ref"))
}

private fun collectAsyncAPI(asyncAPI: JsonFile, version: String) {
TestCase.assertEquals(listOf(version), JsonFileXPath.findText(asyncAPI, "$.asyncapi"))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.asyncapi.plugin.idea._core.xpath.v3

import com.asyncapi.plugin.idea._core.xpath.YamlFileXPath
import com.intellij.lang.Language
import com.intellij.psi.PsiFileFactory
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import junit.framework.TestCase
import org.jetbrains.yaml.YAMLLanguage
import org.jetbrains.yaml.psi.YAMLFile

/**
* @author Pavel Bodiachevskii
*/
class YamlFileXPathTest: BasePlatformTestCase() {

fun `test - 3_0_0`() {
run("asyncapi", "3.0.0")
}

fun run(asyncapi: String, version: String) {
val psiFileFactory = PsiFileFactory.getInstance(project)
val asyncAPISpecification = this.javaClass.getResource("/$asyncapi-$version.yaml").readText()
val asyncAPIPSI = psiFileFactory.createFileFromText(
"$asyncapi-$version.yaml",
Language.findInstance(YAMLLanguage::class.java),
asyncAPISpecification
) as YAMLFile

collectReferencesToMessages(asyncAPIPSI)
collectReferencesToChannels(asyncAPIPSI)
collectAsyncAPI(asyncAPIPSI, version)
}

private fun collectReferencesToMessages(asyncAPI: YAMLFile) {
val userSignedUp = listOf(
"#/components/messages/UserSignedUp",
)

TestCase.assertEquals(userSignedUp, YamlFileXPath.findText(asyncAPI, "$.channels.*.messages.*.\$ref"))
TestCase.assertEquals(userSignedUp, YamlFileXPath.findText(asyncAPI, "$.channels.userSignedup.messages.*.\$ref"))
}

private fun collectReferencesToChannels(asyncAPI: YAMLFile) {
val userSignedup = listOf(
"#/channels/userSignedup",
)

TestCase.assertEquals(userSignedup, YamlFileXPath.findText(asyncAPI, "$.operations.*.channel.\$ref"))
TestCase.assertEquals(userSignedup, YamlFileXPath.findText(asyncAPI, "$.operations.processUserSignups.channel.\$ref"))
}

private fun collectAsyncAPI(asyncAPI: YAMLFile, version: String) {
TestCase.assertEquals(listOf(version), YamlFileXPath.findText(asyncAPI, "$.asyncapi"))
}

}

0 comments on commit 8511a13

Please sign in to comment.