|
| 1 | +// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | +package software.aws.toolkits.jetbrains.uitests |
| 4 | + |
| 5 | +import com.intellij.driver.sdk.openFile |
| 6 | +import com.intellij.driver.sdk.ui.ui |
| 7 | +import com.intellij.driver.sdk.waitForProjectOpen |
| 8 | +import com.intellij.ide.starter.ci.CIServer |
| 9 | +import com.intellij.ide.starter.di.di |
| 10 | +import com.intellij.ide.starter.driver.engine.runIdeWithDriver |
| 11 | +import com.intellij.ide.starter.ide.IdeProductProvider |
| 12 | +import com.intellij.ide.starter.junit5.hyphenateWithClass |
| 13 | +import com.intellij.ide.starter.models.TestCase |
| 14 | +import com.intellij.ide.starter.project.LocalProjectInfo |
| 15 | +import com.intellij.ide.starter.runner.CurrentTestMethod |
| 16 | +import com.intellij.ide.starter.runner.Starter |
| 17 | +import org.junit.jupiter.api.Test |
| 18 | +import org.junit.jupiter.api.condition.DisabledIfSystemProperty |
| 19 | +import org.kodein.di.DI |
| 20 | +import org.kodein.di.bindSingleton |
| 21 | +import java.io.File |
| 22 | +import java.nio.file.Path |
| 23 | +import java.nio.file.Paths |
| 24 | +import kotlin.io.path.createParentDirectories |
| 25 | +import kotlin.io.path.writeText |
| 26 | + |
| 27 | +@DisabledIfSystemProperty(named = "org.gradle.project.ideProfileName", matches = "2024.2", disabledReason = "Logging API not present for 242") |
| 28 | +class OfflineAmazonQInlineCompletionTest { |
| 29 | + init { |
| 30 | + di = DI { |
| 31 | + extend(di) |
| 32 | + bindSingleton<CIServer>(overrides = true) { TestCIServer } |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + fun `completion request with expired credentials does not freeze EDT`() { |
| 38 | + val testCase = TestCase( |
| 39 | + IdeProductProvider.IC, |
| 40 | + LocalProjectInfo( |
| 41 | + Paths.get("tstData", "Hello") |
| 42 | + ) |
| 43 | + ).useRelease("2024.2") |
| 44 | + Paths.get(System.getProperty("user.home"), ".aws", "sso", "cache", "ee1d2538cb8d358377d7661466c866af747a8a3f.json") |
| 45 | + .createParentDirectories() |
| 46 | + .writeText( |
| 47 | + """ |
| 48 | + { |
| 49 | + "clientId": "DummyId", |
| 50 | + "clientSecret": "DummySecret", |
| 51 | + "expiresAt": "3070-01-01T00:00:00Z", |
| 52 | + "scopes": [ |
| 53 | + "scope1", |
| 54 | + "scope2" |
| 55 | + ], |
| 56 | + "issuerUrl": "1", |
| 57 | + "region": "2", |
| 58 | + "clientType": "public", |
| 59 | + "grantTypes": [ |
| 60 | + "authorization_code", |
| 61 | + "refresh_token" |
| 62 | + ], |
| 63 | + "redirectUris": [ |
| 64 | + "http://127.0.0.1/oauth/callback" |
| 65 | + ] |
| 66 | + } |
| 67 | + """.trimIndent() |
| 68 | + ) |
| 69 | + Paths.get(System.getProperty("user.home"), ".aws", "sso", "cache", "d3b447f809607422aac1470dd17fbb32e358cdb3.json") |
| 70 | + .writeText( |
| 71 | + """ |
| 72 | + { |
| 73 | + "issuerUrl": "https://example.awsapps.com/start", |
| 74 | + "region": "us-east-1", |
| 75 | + "accessToken": "DummyAccessToken", |
| 76 | + "refreshToken": "RefreshToken", |
| 77 | + "createdAt": "1970-01-01T00:00:00Z", |
| 78 | + "expiresAt": "1970-01-01T00:00:00Z" |
| 79 | + } |
| 80 | + """.trimIndent() |
| 81 | + ) |
| 82 | + Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply { |
| 83 | + System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path -> |
| 84 | + pluginConfigurator.installPluginFromPath( |
| 85 | + Path.of(path) |
| 86 | + ) |
| 87 | + } |
| 88 | + |
| 89 | + copyExistingConfig(Paths.get("tstData", "config")) |
| 90 | + updateGeneralSettings() |
| 91 | + }.runIdeWithDriver() |
| 92 | + .useDriverAndCloseIde { |
| 93 | + waitForProjectOpen() |
| 94 | + openFile("Example.java") |
| 95 | + ui.keyboard { |
| 96 | + // left meta + c |
| 97 | + repeat(5) { hotKey(18, 67) } |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | +} |
0 commit comments