|
| 1 | +// Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package software.aws.toolkits.jetbrains.services.dynamic.explorer |
| 5 | + |
| 6 | +import com.intellij.testFramework.ProjectRule |
| 7 | +import org.assertj.core.api.Assertions.assertThat |
| 8 | +import org.junit.Rule |
| 9 | +import org.junit.Test |
| 10 | +import software.amazon.awssdk.services.cloudcontrol.model.UnsupportedActionException |
| 11 | +import software.aws.toolkits.core.utils.test.aString |
| 12 | +import software.aws.toolkits.core.utils.test.hasOnlyOneElementOfType |
| 13 | +import software.aws.toolkits.jetbrains.core.MockResourceCacheRule |
| 14 | +import software.aws.toolkits.jetbrains.core.explorer.nodes.AwsExplorerEmptyNode |
| 15 | +import software.aws.toolkits.jetbrains.core.explorer.nodes.AwsExplorerErrorNode |
| 16 | +import software.aws.toolkits.jetbrains.services.dynamic.CloudControlApiResources |
| 17 | +import software.aws.toolkits.jetbrains.services.dynamic.DynamicResource |
| 18 | +import software.aws.toolkits.jetbrains.services.dynamic.ResourceType |
| 19 | +import software.aws.toolkits.resources.message |
| 20 | +import java.util.concurrent.CompletableFuture |
| 21 | + |
| 22 | +class DynamicResourceResourceTypeNodeTest { |
| 23 | + |
| 24 | + @Rule |
| 25 | + @JvmField |
| 26 | + val projectRule = ProjectRule() |
| 27 | + |
| 28 | + @Rule |
| 29 | + @JvmField |
| 30 | + val resourceCache = MockResourceCacheRule() |
| 31 | + |
| 32 | + @Test |
| 33 | + fun returnsListFromProvider() { |
| 34 | + val type = aString() |
| 35 | + val identifier = aString() |
| 36 | + val resources = listOf(DynamicResource(ResourceType(type, "foo", "bah"), identifier)) |
| 37 | + resourceCache.addEntry(projectRule.project, CloudControlApiResources.listResources(type), resources) |
| 38 | + |
| 39 | + val sut = DynamicResourceResourceTypeNode(projectRule.project, type) |
| 40 | + |
| 41 | + assertThat(sut.children).hasOnlyOneElementOfType<DynamicResourceNode>().satisfies { |
| 42 | + assertThat(it.displayName()).isEqualTo(identifier) |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + fun unsupportedExceptionResultsInEmptyNode() { |
| 48 | + val type = aString() |
| 49 | + resourceCache.addEntry( |
| 50 | + projectRule.project, |
| 51 | + CloudControlApiResources.listResources(type), |
| 52 | + CompletableFuture.failedFuture(UnsupportedActionException.builder().build()) |
| 53 | + ) |
| 54 | + |
| 55 | + val sut = DynamicResourceResourceTypeNode(projectRule.project, type) |
| 56 | + |
| 57 | + assertThat(sut.children).hasOnlyOneElementOfType<AwsExplorerEmptyNode>().satisfies { |
| 58 | + assertThat(it.displayName()).startsWith(message("dynamic_resources.unavailable_in_region", "")) |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + fun otherExceptionsBubble() { |
| 64 | + val type = aString() |
| 65 | + resourceCache.addEntry(projectRule.project, CloudControlApiResources.listResources(type), CompletableFuture.failedFuture(RuntimeException())) |
| 66 | + |
| 67 | + val sut = DynamicResourceResourceTypeNode(projectRule.project, type) |
| 68 | + |
| 69 | + assertThat(sut.children).hasOnlyOneElementOfType<AwsExplorerErrorNode>() |
| 70 | + } |
| 71 | +} |
0 commit comments