fun canDownloadAndViewSchema()

in jetbrains-core/tst/software/aws/toolkits/jetbrains/services/schemas/SchemasViewerTest.kt [133:189]


    fun canDownloadAndViewSchema() {
        val schemaResponse = DescribeSchemaResponse.builder()
            .content(AWS_EVENT_SCHEMA_RAW)
            .schemaName(SCHEMA)
            .schemaVersion(VERSION)
            .build()

        val connectionSettings = ConnectionSettings(
            mockCredentialManager.createCredentialProvider(),
            mockRegionProvider.createAwsRegion()
        )
        mockSchemaCache(connectionSettings, schemaResponse)

        val mockSchemaDownloader = mock<SchemaDownloader> {
            on {
                getSchemaContent(
                    REGISTRY,
                    SCHEMA,
                    connectionSettings = connectionSettings
                )
            }.thenReturn(completedFuture(schemaResponse))
        }
        val mockSchemaFormatter = mock<SchemaFormatter> {
            on { prettySchemaContent(AWS_EVENT_SCHEMA_RAW) }.thenReturn(completedFuture(AWS_EVENT_SCHEMA_PRETTY))
        }
        val mockSchemaPreviewer = mock<SchemaPreviewer> {
            on {
                openFileInEditor(
                    REGISTRY,
                    SCHEMA,
                    AWS_EVENT_SCHEMA_PRETTY,
                    VERSION,
                    projectRule.project,
                    connectionSettings
                )
            }.thenReturn(completedFuture(null))
        }

        runInEdtAndGet {
            SchemaViewer(projectRule.project, mockSchemaDownloader, mockSchemaFormatter, mockSchemaPreviewer).downloadAndViewSchema(
                SCHEMA,
                REGISTRY,
                connectionSettings
            ).toCompletableFuture()
        }.get()

        // Assert no error notifications
        assertThat(notificationListener.notifications).isEmpty()

        verify(mockSchemaDownloader).getSchemaContent(
            REGISTRY,
            SCHEMA,
            connectionSettings = connectionSettings
        )
        verify(mockSchemaFormatter).prettySchemaContent(AWS_EVENT_SCHEMA_RAW)
        verify(mockSchemaPreviewer).openFileInEditor(REGISTRY, SCHEMA, AWS_EVENT_SCHEMA_PRETTY, VERSION, projectRule.project, connectionSettings)
    }