Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref =
kotlin-stdLibJdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }
mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockito" }
mockito-junit-jupiter = { module = "org.mockito:mockito-junit-jupiter", version.ref = "mockito" }
mockito-kotlin = { module = "org.mockito.kotlin:mockito-kotlin", version.ref = "mockitoKotlin" }
mockk = { module = "io.mockk:mockk", version.ref="mockk" }
nimbus-jose-jwt = {module = "com.nimbusds:nimbus-jose-jwt", version.ref = "nimbus-jose-jwt"}
Expand All @@ -121,7 +122,7 @@ zjsonpatch = { module = "com.flipkart.zjsonpatch:zjsonpatch", version.ref = "zjs
[bundles]
jackson = ["jackson-datetime", "jackson-kotlin", "jackson-yaml", "jackson-xml"]
kotlin = ["kotlin-stdLibJdk8", "kotlin-reflect"]
mockito = ["mockito-core", "mockito-kotlin"]
mockito = ["mockito-core", "mockito-junit-jupiter", "mockito-kotlin"]
sshd = ["sshd-core", "sshd-scp", "sshd-sftp"]

[plugins]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
logger.info { "Attempt ${currentAttempt.get()} of $maxDownloadAttempts to download LSP artifacts" }

try {
withBackgroundProgress(
return withBackgroundProgress(

Check warning on line 115 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L115

Added line #L115 was not covered by tests
project,
AwsCoreBundle.message("amazonqFeatureDev.placeholder.downloading_and_extracting_lsp_artifacts"),
cancellable = true
Expand All @@ -123,9 +123,12 @@
.mapNotNull { it.filename }
.forEach { filename -> extractZipFile(downloadPath.resolve(filename), downloadPath) }
logger.info { "Successfully downloaded and moved LSP artifacts to $downloadPath" }

return@withBackgroundProgress downloadPath

Check warning on line 127 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L127

Added line #L127 was not covered by tests
}

return@withBackgroundProgress null

Check warning on line 130 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L130

Added line #L130 was not covered by tests
}
return downloadPath
} catch (e: Exception) {
when (e) {
is CancellationException -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class ManifestFetcher(
private val lspManifestUrl: String = DEFAULT_MANIFEST_URL,
private val manifestManager: ManifestManager = ManifestManager(),
private val lspManifestFilePath: Path = DEFAULT_MANIFEST_PATH,
private val manifestPath: Path = DEFAULT_MANIFEST_PATH,

Check warning on line 22 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ManifestFetcher.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ManifestFetcher.kt#L22

Added line #L22 was not covered by tests
) {
companion object {
private val logger = getLogger<ManifestFetcher>()
Expand All @@ -34,6 +34,10 @@
.resolve("jetbrains-lsp-manifest.json")
}

@get:VisibleForTesting
internal val lspManifestFilePath: Path
get() = manifestPath

Check warning on line 39 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ManifestFetcher.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ManifestFetcher.kt#L39

Added line #L39 was not covered by tests

/**
* Method which will be used to fetch latest manifest.
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package software.aws.toolkits.jetbrains.services.amazonq.lsp.artifacts

import com.intellij.openapi.project.Project
import com.intellij.testFramework.ApplicationExtension
import com.intellij.util.io.createDirectories
import com.intellij.util.text.SemVer
import io.mockk.Runs
Expand All @@ -14,16 +15,16 @@ import io.mockk.mockkStatic
import io.mockk.spyk
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.annotations.TestOnly
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.api.io.TempDir
import org.mockito.kotlin.mock
import software.aws.toolkits.jetbrains.services.amazonq.lsp.artifacts.ArtifactManager.SupportedManifestVersionRange
import software.aws.toolkits.jetbrains.services.amazonq.project.manifest.ManifestManager
import java.nio.file.Path

@TestOnly
@ExtendWith(ApplicationExtension::class)
class ArtifactHelperTest {
@TempDir
lateinit var tempDir: Path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@

package software.aws.toolkits.jetbrains.services.amazonq.lsp.artifacts

import com.intellij.testFramework.ApplicationExtension
import com.intellij.testFramework.utils.io.createFile
import io.mockk.every
import io.mockk.junit5.MockKExtension
import io.mockk.mockkStatic
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.annotations.TestOnly
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.api.io.TempDir
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.kotlin.atLeastOnce
import org.mockito.kotlin.never
import org.mockito.kotlin.reset
import org.mockito.kotlin.spy
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import software.aws.toolkits.jetbrains.core.getTextFromUrl
import software.aws.toolkits.jetbrains.services.amazonq.project.manifest.ManifestManager
import java.nio.file.Path
import java.nio.file.Paths

@TestOnly
@ExtendWith(ApplicationExtension::class, MockitoExtension::class, MockKExtension::class)
class ManifestFetcherTest {

private lateinit var manifestFetcher: ManifestFetcher
Expand All @@ -42,7 +48,6 @@ class ManifestFetcherTest {

@Test
fun `should return valid result from local should not execute remote method`() {
reset(manifestFetcher)
whenever(manifestFetcher.fetchManifestFromLocal()).thenReturn(manifest)

assertThat(manifestFetcher.fetch()).isNotNull().isEqualTo(manifest)
Expand All @@ -65,8 +70,6 @@ class ManifestFetcherTest {
mockkStatic("software.aws.toolkits.jetbrains.core.HttpUtilsKt")
every { getTextFromUrl(any()) } returns "ManifestContent"

whenever(manifestManager.readManifestFile("")).thenReturn(null)

assertThat(manifestFetcher.fetchManifestFromRemote()).isNull()
}

Expand All @@ -84,17 +87,36 @@ class ManifestFetcherTest {
@Test
fun `fetchManifestFromRemote should return null if manifest is deprecated`() {
mockkStatic("software.aws.toolkits.jetbrains.core.HttpUtilsKt")
every { getTextFromUrl(any()) } returns "ManifestContent"

val deprecatedManifest = ManifestManager.Manifest(isManifestDeprecated = true)

whenever(manifestManager.readManifestFile("")).thenReturn(deprecatedManifest)
every { getTextFromUrl(any()) } returns
// language=JSON
"""
{
"manifestSchemaVersion": "1.0",
"isManifestDeprecated": true
}
""".trimIndent()

assertThat(manifestFetcher.fetchManifestFromRemote()).isNull()
}

@Test
fun `fetchManifestFromLocal should return null`() {
fun `fetchManifestFromLocal should return null if path does not exist locally`() {
whenever(manifestFetcher.lspManifestFilePath).thenReturn(Paths.get("does", "not", "exist"))
assertThat(manifestFetcher.fetchManifestFromLocal()).isNull()
}

@Test
fun `fetchManifestFromLocal should return local path if exists locally`(@TempDir tempDir: Path) {
val manifestFile = tempDir.createFile("manifest.json")
manifestFile.toFile().writeText(
// language=JSON
"""
{
"manifestSchemaVersion": "1.0"
}
""".trimIndent()
)
whenever(manifestFetcher.lspManifestFilePath).thenReturn(manifestFile)
assertThat(manifestFetcher.fetchManifestFromLocal()).isNull()
}
}
Loading