|
| 1 | +/* |
| 2 | + * Copyright 2023 https://github.com/openapi-processor/openapi-processor-intellij |
| 3 | + * PDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.openapiprocessor.intellij |
| 7 | + |
| 8 | +import com.intellij.openapi.application.runReadAction |
| 9 | +import com.intellij.openapi.vfs.VfsUtil |
| 10 | +import com.intellij.psi.PsiMethod |
| 11 | +import com.intellij.psi.impl.java.stubs.index.JavaMethodNameIndex |
| 12 | +import com.intellij.psi.search.GlobalSearchScope |
| 13 | +import com.intellij.testFramework.TestDataPath |
| 14 | +import com.intellij.testFramework.junit5.TestApplication |
| 15 | +import com.intellij.testFramework.junit5.fixture.* |
| 16 | +import com.intellij.testFramework.runInEdtAndGet |
| 17 | +import io.openapiprocessor.intellij.support.codeInsightFixture |
| 18 | +import io.openapiprocessor.intellij.support.methods |
| 19 | +import org.junit.jupiter.api.Assertions.assertEquals |
| 20 | +import org.junit.jupiter.api.Test |
| 21 | +import java.nio.file.Path |
| 22 | + |
| 23 | +@TestApplication |
| 24 | +@TestDataPath($$"$PROJECT_ROOT/src/test/testdata/openapi-to-interface/paths") |
| 25 | +class OpenApiPathLineMarkerSpec { |
| 26 | + val tempPathFixture = tempPathFixture() |
| 27 | + val projectFixture = projectFixture(tempPathFixture, openAfterCreation = true) |
| 28 | + val moduleFixture = projectFixture.moduleFixture("main") |
| 29 | + |
| 30 | + val sourceRootFixture = moduleFixture.sourceRootFixture( |
| 31 | + pathFixture = tempPathFixture, |
| 32 | + blueprintResourcePath = Path.of("src/test/testdata/openapi-to-interface/paths") |
| 33 | + ) |
| 34 | + |
| 35 | + val codeInsightFixture = codeInsightFixture(projectFixture, tempPathFixture) |
| 36 | + val disposableFixture = disposableFixture() |
| 37 | + |
| 38 | + fun getMethod(name: String): PsiMethod { |
| 39 | + val project = projectFixture.get() |
| 40 | + |
| 41 | + return JavaMethodNameIndex |
| 42 | + .getInstance() |
| 43 | + .getMethods(name, project, GlobalSearchScope.allScope(project)) |
| 44 | + .first() |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + fun `adds navigation gutter icon to OpenAPI paths`() { |
| 49 | + val fixture = codeInsightFixture.get() |
| 50 | + |
| 51 | + val gutters = runInEdtAndGet { |
| 52 | + val file = VfsUtil.findRelativeFile(sourceRootFixture.get().virtualFile, "openapi.yaml")!! |
| 53 | + fixture.configureFromExistingVirtualFile(file) |
| 54 | + |
| 55 | + return@runInEdtAndGet fixture.findAllGutters("openapi.yaml") |
| 56 | + } |
| 57 | + |
| 58 | + runReadAction { |
| 59 | + val expected = listOf( |
| 60 | + getMethod("postFoo"), |
| 61 | + getMethod("postBar") |
| 62 | + ) |
| 63 | + |
| 64 | + val methods = gutters.flatMap { it.methods } |
| 65 | + |
| 66 | + assertEquals(expected, methods) |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments