mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(resourceexplorer2): add AWS Resource Explorer 2 with cross-service resource discovery (#2485)
* feat(resourceexplorer2): Add AWS Resource Explorer 2 with cross-service resource discovery Resource Explorer 2 lets AWS SDK clients discover resources across S3, RDS, DynamoDB, ElastiCache, and OpenSearch through a single query interface — the same way real AWS Resource Explorer aggregates resources from multiple services. Architecture: a ResourceProvider CDI interface in core/resource/ decouples Resource Explorer from individual services. Each service implements the interface to expose its resources. Resource Explorer discovers all providers via CDI Instance<ResourceProvider> and queries them live on every request — no intermediate store, no eventual consistency. New services become discoverable by implementing the interface; Resource Explorer never imports service packages directly. Query parsing: hand-written character-by-character tokenizer that implements the full Resource Explorer filter syntax — all 10 filter attributes (accountid, application, id, region, resourcetype, resourcetype.supports, service, tag, tag.key, tag.value), comma-OR within filters, negation (-), wildcard suffix (*), quoted strings, backslash escaping, and free-form text keywords. ListResources rejects free-form text (filter-only mode); Search accepts both. Tokens are classified by splitting on the first unescaped colon and looking the prefix up against the known attributes, matching the documented grammar. API surface: 20 REST JSON endpoints covering ListResources, Search, ListSupportedResourceTypes, full Index CRUD (CreateIndex always creates LOCAL — promote via UpdateIndexType, matching real AWS), full View CRUD with Scope and FilterString, BatchGetView with Errors for missing ARNs, default view association, and pagination with NextToken on all list operations. Tag operations use the existing SharedTagsController + TagHandler infrastructure. A default AGGREGATOR index and default view with tags included are auto-provisioned on startup so ListResources works without setup. AWS behavioral fidelity (matched against the API reference, not guessed): ListResources/Search with no view and no regional default return UnauthorizedException (401), not 404; the default view is scoped per region; CreateView requires a unique, regex-valid ViewName (ConflictException 409 / ValidationException 400) and only accepts "tags" as an included property; promoting a second aggregator index returns ConflictException; ListResources suppresses NextToken at MaxResults=1000; Search/ListResources cap results at the first 1000 matches; QueryString is required (empty string allowed) and MaxResults is range-validated. Pagination offsets are clamped so a stale NextToken against a shrunk live result set returns an empty page instead of a 500. All response JSON uses PascalCase field names built via Jackson ObjectNode (never valueToTree on domain models) to match the AWS SDK wire format exactly. Verified by decompiling every SDK model class with javap and comparing field-by-field, then running 16 read-only SDK tests against production resource-explorer-2 in us-east-1. ElastiCache ReplicationGroup gains arn and region fields so Resource Explorer can discover it. RDS resources get tags via ResourceGroupsTaggingService (the cross-service tagging API) since floci's RDS service doesn't implement AddTagsToResource. Indexes and views are persisted (hybrid storage) in production; tests pin the service to in-memory storage so runs stay isolated and idempotent. Testing: - 50 query parser unit tests covering the full grammar - 20 filter evaluation unit tests against synthetic resources - 9 pagination unit tests for the offset clamp and 1000-result cap - 73 integration tests (@QuarkusTest + RestAssured), grouped with @Nested by behavior class: conditional/stateful response fields, data provenance across services, edge/boundary pagination, cross-service data consistency, filter semantics, and AWS API fidelity (401 no-default-view, conflict on duplicate view name and second aggregator, view-name and included-property validation) - 28 SDK compatibility tests using real AWS SDK v2 ResourceExplorer2Client, asserting every field the SDK model exposes. Dual-mode: run against floci or real AWS via FLOCI_TARGET=aws (mutating tests skipped against real AWS). * feat(lambda): expose functions to Resource Explorer 2 Implement ResourceProvider so Lambda functions surface via the Resource Explorer 2 ListResources/Search APIs and lambda appears in ListSupportedResourceTypes. Iterates $LATEST versions only so published versions don't produce duplicate function entries. * feat(sns): expose topics to Resource Explorer 2 * feat(kms): expose keys to Resource Explorer 2 * feat(sqs): expose queues to Resource Explorer 2 Queue ARNs aren't persisted on the model; reconstruct them from the region (recovered from the storage key) plus the queue name via regionResolver.buildArn. * feat(ecr): expose repositories to Resource Explorer 2 * feat(stepfunctions): expose state machines to Resource Explorer 2 * feat(msk): expose clusters to Resource Explorer 2 * feat(pipes): expose pipes to Resource Explorer 2 * feat(acm): expose certificates to Resource Explorer 2 * feat(cognito): expose user pools to Resource Explorer 2 * feat(iam): expose users and roles to Resource Explorer 2 IAM is a global service: its ARNs carry no region, and Resource Explorer reports global resources with the region "global" (not an empty string), matching real AWS. Emit two resource types, iam:user and iam:role. * test(resourceexplorer2): parameterize per-service ListResources coverage The ten single-service resource tests were byte-for-byte identical except for the service name and resource type — the same service-filter/assert-no-foreign-service/assert-type-present shape copied ten times. Fold them into one @ParameterizedTest whose CsvSource carries the (service, resourceType) pairs, so adding a service is one row instead of a new @Nested class. IAM stays separate: it reports the global region and two resource types, which the shared shape can't express. * feat(amazonmq): expose brokers to Resource Explorer 2 Amazon MQ arrived on main after this branch was cut. Implement ResourceProvider so brokers surface via Search/ListResources and mq appears in ListSupportedResourceTypes, matching the other services already wired into Resource Explorer. Brokers carry an ARN and tags, so the mapping is the same shape as the rest: one mq:broker resource per stored broker. * feat(lightsail): expose resources to Resource Explorer 2 Lightsail landed upstream (#1583) after this branch began and models taggable, ARN-bearing resources (instances, disks, static IPs, key pairs) that AWS Resource Explorer indexes. Without a ResourceProvider its resources were invisible to Search/ListResources, unlike every other resource-owning service on this branch. LightsailService now implements ResourceProvider: getResources() maps each stored resource node to an ExplorerResource, deriving region and account from the ARN and resourceType as lightsail:<Type>; getSupportedResourceTypes() advertises the four stored types (static IPs flagged non-taggable, matching AWS). Coverage: a focused unit test asserts the node->ExplorerResource mapping (arn, type, region, account, tags) without Quarkus, plus the parameterized RE2 integration test seeds a Lightsail instance and disk and asserts both surface via ListResources. * feat(rum): expose app monitors to Resource Explorer 2 CloudWatch RUM (added upstream in #1797) owns taggable, ARN-addressable app monitors, so it fits the ResourceProvider extension point the rest of this branch uses to surface resources to Resource Explorer 2 Search, ListResources, and ListSupportedResourceTypes. RUM is the first RE2 provider whose API model carries neither an ARN nor a region (GetAppMonitor returns neither), so getResources() reconstructs the ARN: the region comes from the storage key, and the owning account is captured at creation time on the AppMonitor. That owner account is @JsonIgnore'd so it never leaks into the RUM API body and is not persisted; getResources() falls back to the default account for monitors reloaded from disk. Resolving the account at creation rather than at query time is what keeps a monitor's identity stable — an earlier draft read the account from the request context inside getResources(), which stamped every resource with the account of whoever called ListResources instead of its true owner. Injecting RegionResolver into RumService (threaded through the existing unit tests) and adding RegionResolver.getDefaultAccountId() support this. Adds RumResourceProviderTest, including a regression test proving the owner account is the creator's, not the querying caller's, plus a RumServiceTest assertion that the owner account never appears in the serialized API body. Extends ResourceExplorer2IntegrationTest to seed an app monitor and assert rum:appmonitor surfaces via ListResources and ListSupportedResourceTypes. * feat(resourceexplorer2): complete the API surface and close the AWS gaps Follow-up to the Resource Explorer 2 branch, addressing the gaps found reviewing it against the AWS API reference and search-syntax documentation. Wire-level corrections: - MaxResults ceilings are now per-operation, as AWS models them: 1000 for Search/ListResources/ListSupportedResourceTypes, 100 for indexes, 50 for views, 10 for member indexes. ListSupportedResourceTypes previously rejected page sizes AWS accepts, and ListViews accepted ones it rejects. - ListViews is scoped to the calling Region. AWS returns "the views available in the AWS Region in which you call this operation"; every Region's views were being listed. - Free-form keywords are OR'd rather than AND'd, which is how AWS reads them. The remaining deviation — AWS ranks a non-matching resource lower instead of excluding it — is documented rather than emulated, since a keyword-only search returning the whole account is not a useful local answer. - A tag filter against a view whose IncludedProperties omit `tags` is rejected with a ValidationException, as AWS documents for tag: / tag.key: / tag.value: / application:, instead of being evaluated on data the view may not expose. - Backslash escaping is honoured throughout the query grammar: escapes now survive tokenization and are resolved only where the character's meaning is decided, so `\-`, `\:`, `\,` and `\*` are literal text and a quoted phrase neutralises every operator inside it. - application: matches the application name as well as the resource-group ARN; resourcetype.supports:tags consults the provider's declared tag support instead of passing everything through; free-form keywords match tag keys and values. The remaining 12 operations are implemented, taking the service to all 32: the multi-Region setup lifecycle (CreateResourceExplorerSetup, DeleteResourceExplorerSetup, GetResourceExplorerSetup) provisions real indexes and views and records each Region's outcome independently, so one Region's failure is reported through its ErrorDetails rather than abandoning the task. The organization and trusted-service surfaces answer with the wire-accurate empty result, since floci models neither. Eleven more services expose their resources: EC2 (instances, VPCs, subnets, security groups, volumes, internet and NAT gateways, route tables), CloudFormation, CloudWatch Logs, EventBridge, Secrets Manager, SSM, ECS, EKS, Kinesis, Firehose, and ELB v2 — thirty providers in total. API Gateway and Route 53 stay out: RestApi carries no Region and Route53Service resolves no account id, so each needs a field added to an unrelated service first. Also documents the service, which a new service requires: docs/services/ resource-explorer.md with the generated action table, the deviations above, and the routing note, plus the mkdocs nav, README, and environment-variable entries. Seven existing tests asserted on the emulator's total resource count, which thirty providers push past Search's 1000-result cap; they are scoped to a bounded slice so their arithmetic stays meaningful. 24 tests added for the new behaviour. * fix(rum): keep a monitor's owning account across updates UpdateAppMonitor rebuilds the AppMonitor from its current state and never carried ownerAccountId over, so an update silently reassigned the monitor to whichever account next called ListResources. Resource Explorer then reported a wrong ARN and OwningAccountId for any monitor not owned by that caller. getResources' fallback for monitors reloaded from disk — where the transient owner account did not survive — was the configured default account. monitorStore.keys() is already scoped to the calling account by the account-aware backend, so a monitor reachable there is owned by that caller by construction; the caller's account is the correct fallback. Also addresses review findings on the Resource Explorer branch: braces in the compatibility test's cleanup, a synchronized override in the Lightsail provider test's storage stub, and four unread locals in the integration test. * chore: drop the stray local-dev Dockerfile docker/Dockerfile.localdev was carried in with the Resource Explorer work but is unrelated to it: nothing in the repo references it, and its header points at a CI pipeline and dev cluster that do not exist in this org. * fix(resourceexplorer2): order paginated results before slicing NextToken is a bare offset, but the list it indexes into is rebuilt on every call by iterating Instance<ResourceProvider> and StorageBackend.scan, neither of which promises an order. Offset pagination is only well defined over a stable order: page through Search or ListResources with MaxResults smaller than the result set and the second page indexes into a differently arranged list, silently dropping or repeating resources. Sort on a unique key before every paginate call: ARN for resources and indexes, the view ARN for ListViews, the resource type for ListSupportedResourceTypes. The regression test drives a provider that reshuffles its resources on each call, which is what an unordered map-backed store is free to do; without the sort a 25-resource set pages down to 16 distinct ARNs. This also makes ResourceProvider#getResources()'s "ordering is not significant" contract true rather than merely permitted. * docs: add the Resource Explorer row to the service matrix The downmerge picks up #2465's service-matrix gate, which fails `make docs-check` for any service registered in ResolvedServiceCatalog without a row in docs/services/index.md — resource-explorer-2 was one. The descriptor's external key carries the API version suffix while the page is resource-explorer.md, so it also needs an alias entry, the same way apigatewayv2 and cognito-idp do. * test(resourceexplorer2): scope the tag-provenance lookup to the caller's Region dynamoDbTagResourceUpdatesResourceExplorer took Resources[0] from an unfiltered ListResources and tagged it. ListResources spans every Region the view covers while DynamoDB TagResource resolves the table in the request's Region, so the ARN it picked only worked as long as the first result happened to be local. Deterministic ARN ordering makes that assumption fail reliably instead of by luck: the first table is now eu-west-2's and TagResource reports it as not found. Filter on region:us-east-1, the same way the region-scoping tests in this class already do. --------- Co-authored-by: Marius Volkhart <marius@volkhart.com> Co-authored-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
86 files changed
+8562
-69
No files matched your search
+593
@@ -0,0 +1,593 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.resourceexplorer2.ResourceExplorer2Client;
|
||||
import software.amazon.awssdk.services.resourceexplorer2.model.*;
|
||||
import software.amazon.awssdk.services.s3.S3Client;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
/**
|
||||
* SDK compatibility tests for Resource Explorer 2.
|
||||
*
|
||||
* <p>Every test deserializes the response through the real AWS SDK and asserts
|
||||
* on EVERY field. If the wire format is wrong (wrong casing, wrong structure,
|
||||
* missing fields), the SDK will return null for that field and the test fails.
|
||||
*
|
||||
* <p>This is the safety net that prevents wire format regressions.
|
||||
*/
|
||||
@DisplayName("Resource Explorer 2")
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class ResourceExplorer2Test {
|
||||
|
||||
private static ResourceExplorer2Client client;
|
||||
// The emulator auto-provisions an index only in the default region (us-east-1). CreateIndex
|
||||
// there is a no-op/conflict, so index create+delete is exercised against a second region
|
||||
// that starts with no index, matching AWS's one-index-per-region rule.
|
||||
private static ResourceExplorer2Client altRegionClient;
|
||||
private static S3Client s3;
|
||||
|
||||
private static String defaultViewArn;
|
||||
private static String autoProvisionedIndexArn;
|
||||
private static String createdViewArn;
|
||||
private static String createdIndexArn;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
client = TestFixtures.resourceExplorer2Client();
|
||||
altRegionClient = TestFixtures.resourceExplorer2Client(Region.US_WEST_2);
|
||||
s3 = TestFixtures.s3Client();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (client != null) {
|
||||
client.close();
|
||||
}
|
||||
if (altRegionClient != null) {
|
||||
altRegionClient.close();
|
||||
}
|
||||
if (s3 != null) {
|
||||
s3.close();
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// GetIndex — every field must deserialize
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void getIndexDeserializesAllFields() {
|
||||
GetIndexResponse response = client.getIndex(GetIndexRequest.builder().build());
|
||||
|
||||
// Every field the SDK model exposes must be non-null and correctly typed
|
||||
assertThat(response.arn()).as("GetIndex.Arn").isNotBlank();
|
||||
assertThat(response.type()).as("GetIndex.Type").isNotNull();
|
||||
assertThat(response.type()).isIn(IndexType.LOCAL, IndexType.AGGREGATOR);
|
||||
assertThat(response.state()).as("GetIndex.State").isNotNull();
|
||||
assertThat(response.state()).isEqualTo(IndexState.ACTIVE);
|
||||
assertThat(response.createdAt()).as("GetIndex.CreatedAt").isNotNull();
|
||||
assertThat(response.lastUpdatedAt()).as("GetIndex.LastUpdatedAt").isNotNull();
|
||||
assertThat(response.tags()).as("GetIndex.Tags").isNotNull();
|
||||
assertThat(response.replicatingFrom()).as("GetIndex.ReplicatingFrom").isNotNull();
|
||||
assertThat(response.replicatingTo()).as("GetIndex.ReplicatingTo").isNotNull();
|
||||
|
||||
autoProvisionedIndexArn = response.arn();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// GetDefaultView
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void getDefaultViewReturnsViewArn() {
|
||||
GetDefaultViewResponse response = client.getDefaultView(GetDefaultViewRequest.builder().build());
|
||||
assertThat(response.viewArn()).as("GetDefaultView.ViewArn").isNotBlank();
|
||||
defaultViewArn = response.viewArn();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// GetView — every field of the View object
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void getViewDeserializesAllFields() {
|
||||
GetViewResponse response = client.getView(GetViewRequest.builder()
|
||||
.viewArn(defaultViewArn).build());
|
||||
View view = response.view();
|
||||
|
||||
assertThat(view).as("GetView.View").isNotNull();
|
||||
assertThat(view.viewArn()).as("View.ViewArn").isEqualTo(defaultViewArn);
|
||||
assertThat(view.viewName()).as("View.ViewName").isNotBlank();
|
||||
assertThat(view.owner()).as("View.Owner").isNotBlank();
|
||||
assertThat(view.scope()).as("View.Scope").isNotBlank();
|
||||
assertThat(view.lastUpdatedAt()).as("View.LastUpdatedAt").isNotNull();
|
||||
assertThat(view.includedProperties()).as("View.IncludedProperties").isNotNull();
|
||||
assertThat(view.filters()).as("View.Filters").isNotNull();
|
||||
assertThat(view.filters().filterString()).as("View.Filters.FilterString").isNotNull();
|
||||
|
||||
// GetViewResponse has root-level Tags (separate from View)
|
||||
assertThat(response.tags()).as("GetViewResponse.Tags").isNotNull();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// ListSupportedResourceTypes — field-level assertions
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void listSupportedResourceTypesDeserializesAllFields() {
|
||||
ListSupportedResourceTypesResponse response = client.listSupportedResourceTypes(
|
||||
ListSupportedResourceTypesRequest.builder().maxResults(50).build());
|
||||
|
||||
assertThat(response.resourceTypes()).as("ResourceTypes").isNotEmpty();
|
||||
for (var rt : response.resourceTypes()) {
|
||||
assertThat(rt.resourceType()).as("SupportedResourceType.ResourceType").isNotBlank();
|
||||
assertThat(rt.service()).as("SupportedResourceType.Service").isNotBlank();
|
||||
// Verify format: "service:type"
|
||||
assertThat(rt.resourceType()).contains(":");
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Cross-service setup
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void createS3BucketForDiscovery() {
|
||||
assumeFalse(TestFixtures.isRealAws(), "Skip resource creation against real AWS");
|
||||
String bucketName = TestFixtures.uniqueName("re2");
|
||||
s3.createBucket(b -> b.bucket(bucketName));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// ListResources — every field of Resource objects
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void listResourcesDeserializesAllResourceFields() {
|
||||
ListResourcesResponse response = client.listResources(ListResourcesRequest.builder().build());
|
||||
|
||||
assertThat(response.viewArn()).as("ListResources.ViewArn").isNotBlank();
|
||||
assertThat(response.resources()).as("ListResources.Resources").isNotNull();
|
||||
|
||||
// Must have at least one resource (the S3 bucket we created)
|
||||
assertThat(response.resources()).isNotEmpty();
|
||||
|
||||
for (Resource resource : response.resources()) {
|
||||
assertThat(resource.arn()).as("Resource.Arn").isNotBlank();
|
||||
assertThat(resource.resourceType()).as("Resource.ResourceType").isNotBlank();
|
||||
assertThat(resource.service()).as("Resource.Service").isNotBlank();
|
||||
assertThat(resource.region()).as("Resource.Region").isNotBlank();
|
||||
assertThat(resource.owningAccountId()).as("Resource.OwningAccountId").isNotBlank();
|
||||
assertThat(resource.lastReportedAt()).as("Resource.LastReportedAt").isNotNull();
|
||||
assertThat(resource.properties()).as("Resource.Properties").isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void listResourcesWithFilterReturnsCorrectTypes() {
|
||||
ListResourcesResponse response = client.listResources(ListResourcesRequest.builder()
|
||||
.filters(SearchFilter.builder().filterString("service:s3").build())
|
||||
.build());
|
||||
|
||||
assertThat(response.resources()).isNotEmpty();
|
||||
for (Resource resource : response.resources()) {
|
||||
assertThat(resource.service()).as("Filtered resource service").isEqualTo("s3");
|
||||
assertThat(resource.resourceType()).startsWith("s3:");
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Search — Count object structure is critical
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void searchCountIsObjectWithTotalResourcesAndComplete() {
|
||||
SearchResponse response = client.search(SearchRequest.builder()
|
||||
.queryString("service:s3")
|
||||
.build());
|
||||
|
||||
// Count must be an object, not an integer
|
||||
assertThat(response.count()).as("Search.Count").isNotNull();
|
||||
assertThat(response.count().totalResources()).as("Count.TotalResources").isNotNull();
|
||||
assertThat(response.count().totalResources()).isGreaterThanOrEqualTo(0L);
|
||||
assertThat(response.count().complete()).as("Count.Complete").isNotNull();
|
||||
|
||||
assertThat(response.resources()).as("Search.Resources").isNotNull();
|
||||
assertThat(response.viewArn()).as("Search.ViewArn").isNotBlank();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
void searchCountTotalMatchesActualResourceCount() {
|
||||
SearchResponse response = client.search(SearchRequest.builder()
|
||||
.queryString("service:s3")
|
||||
.build());
|
||||
|
||||
// TotalResources should match the number of matching resources
|
||||
assertThat(response.count().totalResources())
|
||||
.as("Count.TotalResources matches filtered count")
|
||||
.isEqualTo((long) response.resources().size());
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// CreateView — response shape
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
void createViewResponseContainsViewObject() {
|
||||
assumeFalse(TestFixtures.isRealAws(), "Skip view mutation against real AWS");
|
||||
CreateViewResponse response = client.createView(CreateViewRequest.builder()
|
||||
.viewName("sdk-compat-view")
|
||||
.filters(SearchFilter.builder().filterString("service:s3").build())
|
||||
.includedProperties(IncludedProperty.builder().name("tags").build())
|
||||
.tags(Map.of("testKey", "testValue"))
|
||||
.build());
|
||||
|
||||
View view = response.view();
|
||||
assertThat(view).as("CreateView.View").isNotNull();
|
||||
assertThat(view.viewArn()).as("View.ViewArn").isNotBlank();
|
||||
assertThat(view.owner()).as("View.Owner").isNotBlank();
|
||||
assertThat(view.lastUpdatedAt()).as("View.LastUpdatedAt").isNotNull();
|
||||
assertThat(view.includedProperties()).as("View.IncludedProperties").isNotEmpty();
|
||||
|
||||
createdViewArn = view.viewArn();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// ListViews
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(21)
|
||||
void listViewsReturnsArns() {
|
||||
ListViewsResponse response = client.listViews(ListViewsRequest.builder().build());
|
||||
assertThat(response.views()).as("ListViews.Views").isNotEmpty();
|
||||
if (!TestFixtures.isRealAws()) {
|
||||
assertThat(response.views()).contains(createdViewArn);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// BatchGetView — must have both Views and Errors
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(22)
|
||||
void batchGetViewReturnsViewsAndErrorsForMissing() {
|
||||
assumeFalse(TestFixtures.isRealAws(), "Depends on created view");
|
||||
String bogusArn = "arn:aws:resource-explorer-2:us-east-1:000000000000:view/does-not-exist/00000000-0000-0000-0000-000000000000";
|
||||
|
||||
BatchGetViewResponse response = client.batchGetView(BatchGetViewRequest.builder()
|
||||
.viewArns(createdViewArn, bogusArn)
|
||||
.build());
|
||||
|
||||
// Found views
|
||||
assertThat(response.views()).as("BatchGetView.Views").isNotEmpty();
|
||||
assertThat(response.views().get(0).viewArn())
|
||||
.as("BatchGetView found view")
|
||||
.isEqualTo(createdViewArn);
|
||||
|
||||
// Errors for missing
|
||||
assertThat(response.errors()).as("BatchGetView.Errors").isNotEmpty();
|
||||
assertThat(response.errors().get(0).viewArn())
|
||||
.as("BatchGetView error ViewArn")
|
||||
.isEqualTo(bogusArn);
|
||||
assertThat(response.errors().get(0).errorMessage())
|
||||
.as("BatchGetView error message")
|
||||
.isNotBlank();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// UpdateView
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(23)
|
||||
void updateViewReturnsUpdatedView() {
|
||||
assumeFalse(TestFixtures.isRealAws(), "Depends on created view");
|
||||
UpdateViewResponse response = client.updateView(UpdateViewRequest.builder()
|
||||
.viewArn(createdViewArn)
|
||||
.includedProperties(IncludedProperty.builder().name("tags").build())
|
||||
.build());
|
||||
|
||||
assertThat(response.view()).as("UpdateView.View").isNotNull();
|
||||
assertThat(response.view().viewArn()).isEqualTo(createdViewArn);
|
||||
assertThat(response.view().lastUpdatedAt()).as("Updated.LastUpdatedAt").isNotNull();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// DeleteView
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(24)
|
||||
void deleteViewReturnsViewArn() {
|
||||
assumeFalse(TestFixtures.isRealAws(), "Depends on created view");
|
||||
DeleteViewResponse response = client.deleteView(DeleteViewRequest.builder()
|
||||
.viewArn(createdViewArn).build());
|
||||
assertThat(response.viewArn()).as("DeleteView.ViewArn").isEqualTo(createdViewArn);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// CreateIndex — response must be trimmed to {Arn, State, CreatedAt}
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(30)
|
||||
void createIndexReturnsArnStateCreatedAt() {
|
||||
assumeFalse(TestFixtures.isRealAws(), "Skip index mutation against real AWS");
|
||||
CreateIndexResponse response = altRegionClient.createIndex(CreateIndexRequest.builder()
|
||||
.tags(Map.of("env", "test"))
|
||||
.build());
|
||||
|
||||
assertThat(response.arn()).as("CreateIndex.Arn").isNotBlank();
|
||||
assertThat(response.state()).as("CreateIndex.State").isNotNull();
|
||||
assertThat(response.createdAt()).as("CreateIndex.CreatedAt").isNotNull();
|
||||
|
||||
createdIndexArn = response.arn();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// ListIndexes — each item has Arn, Region, Type
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(31)
|
||||
void listIndexesDeserializesItemFields() {
|
||||
ListIndexesResponse response = client.listIndexes(ListIndexesRequest.builder().build());
|
||||
|
||||
assertThat(response.indexes()).as("ListIndexes.Indexes").isNotEmpty();
|
||||
for (var idx : response.indexes()) {
|
||||
assertThat(idx.arn()).as("Index.Arn").isNotBlank();
|
||||
assertThat(idx.region()).as("Index.Region").isNotBlank();
|
||||
assertThat(idx.type()).as("Index.Type").isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// UpdateIndexType — PascalCase response fields
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(32)
|
||||
void updateIndexTypeDeserializesAllFields() {
|
||||
assumeFalse(TestFixtures.isRealAws(), "Skip index mutation against real AWS");
|
||||
UpdateIndexTypeResponse response = client.updateIndexType(UpdateIndexTypeRequest.builder()
|
||||
.arn(autoProvisionedIndexArn)
|
||||
.type(IndexType.AGGREGATOR)
|
||||
.build());
|
||||
|
||||
assertThat(response.arn()).as("UpdateIndexType.Arn").isNotBlank();
|
||||
assertThat(response.state()).as("UpdateIndexType.State").isNotNull();
|
||||
assertThat(response.type()).as("UpdateIndexType.Type").isNotNull();
|
||||
assertThat(response.lastUpdatedAt()).as("UpdateIndexType.LastUpdatedAt").isNotNull();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// DeleteIndex — must include LastUpdatedAt
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(33)
|
||||
void deleteIndexReturnsArnLastUpdatedAtState() {
|
||||
assumeFalse(TestFixtures.isRealAws(), "Depends on created index");
|
||||
DeleteIndexResponse response = altRegionClient.deleteIndex(DeleteIndexRequest.builder()
|
||||
.arn(createdIndexArn)
|
||||
.build());
|
||||
|
||||
assertThat(response.arn()).as("DeleteIndex.Arn").isEqualTo(createdIndexArn);
|
||||
assertThat(response.state()).as("DeleteIndex.State").isNotNull();
|
||||
assertThat(response.lastUpdatedAt()).as("DeleteIndex.LastUpdatedAt").isNotNull();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Error handling — invalid input must return proper error, not 500
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(40)
|
||||
void getMissingViewReturnsError() {
|
||||
// Real AWS: 401 UnauthorizedException (auth checked before existence for wrong-account ARN)
|
||||
// Floci: 404 ResourceNotFoundException
|
||||
assertThatThrownBy(() -> client.getView(GetViewRequest.builder()
|
||||
.viewArn("arn:aws:resource-explorer-2:us-east-1:000000000000:view/nope/00000000-0000-0000-0000-000000000000")
|
||||
.build()))
|
||||
.isInstanceOf(ResourceExplorer2Exception.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(41)
|
||||
void deleteMissingIndexReturnsError() {
|
||||
// Real AWS: 403 AccessDeniedException (auth checked before existence for wrong-account ARN)
|
||||
// Floci: 404 ResourceNotFoundException
|
||||
assertThatThrownBy(() -> client.deleteIndex(DeleteIndexRequest.builder()
|
||||
.arn("arn:aws:resource-explorer-2:us-east-1:000000000000:index/nonexistent")
|
||||
.build()))
|
||||
.isInstanceOf(ResourceExplorer2Exception.class);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// CLASS 3: Wire Format — Nested Structure Deserialization
|
||||
// Drills into nested objects to verify the SDK can parse every level.
|
||||
// If any nested field uses wrong casing or wrong structure, the SDK
|
||||
// returns null and these tests fail.
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Order(50)
|
||||
void viewFiltersFilterStringDeserializes() {
|
||||
assumeFalse(TestFixtures.isRealAws(), "Creates/deletes views");
|
||||
// Create view with filter, then get it and drill into nested Filters object
|
||||
CreateViewResponse createResp = client.createView(CreateViewRequest.builder()
|
||||
.viewName("nested-test-view")
|
||||
.filters(SearchFilter.builder().filterString("service:s3").build())
|
||||
.includedProperties(IncludedProperty.builder().name("tags").build())
|
||||
.build());
|
||||
String arn = createResp.view().viewArn();
|
||||
|
||||
GetViewResponse getResp = client.getView(GetViewRequest.builder().viewArn(arn).build());
|
||||
View view = getResp.view();
|
||||
|
||||
// Drill into nested Filters.FilterString
|
||||
assertThat(view.filters()).as("View.Filters").isNotNull();
|
||||
assertThat(view.filters().filterString()).as("Filters.FilterString").isEqualTo("service:s3");
|
||||
|
||||
// Drill into nested IncludedProperties[].Name
|
||||
assertThat(view.includedProperties()).as("View.IncludedProperties").hasSize(1);
|
||||
assertThat(view.includedProperties().get(0).name())
|
||||
.as("IncludedProperty.Name").isEqualTo("tags");
|
||||
|
||||
// Drill into scope
|
||||
assertThat(view.scope()).as("View.Scope").contains("arn:aws:iam:");
|
||||
|
||||
// Cleanup
|
||||
client.deleteView(DeleteViewRequest.builder().viewArn(arn).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(51)
|
||||
void resourcePropertiesTagDataDeserializes() {
|
||||
// List resources — S3 bucket should have tag Properties
|
||||
ListResourcesResponse response = client.listResources(ListResourcesRequest.builder()
|
||||
.filters(SearchFilter.builder().filterString("service:s3").build())
|
||||
.build());
|
||||
|
||||
assertThat(response.resources()).isNotEmpty();
|
||||
Resource s3Resource = response.resources().get(0);
|
||||
|
||||
// Properties is a list of ResourceProperty
|
||||
assertThat(s3Resource.properties()).as("Resource.Properties").isNotNull();
|
||||
// Note: Properties may be empty if no tags — we just verify the list itself deserializes.
|
||||
// The integration test handles tag-specific assertions.
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(52)
|
||||
void searchCountNestedFieldsDeserialize() {
|
||||
SearchResponse response = client.search(SearchRequest.builder()
|
||||
.queryString("")
|
||||
.maxResults(1)
|
||||
.build());
|
||||
|
||||
ResourceCount count = response.count();
|
||||
assertThat(count).as("Search.Count object").isNotNull();
|
||||
|
||||
// These would be null if Count was an integer instead of an object
|
||||
assertThat(count.totalResources()).as("Count.TotalResources").isNotNull();
|
||||
assertThat(count.totalResources()).isGreaterThanOrEqualTo(0L);
|
||||
|
||||
// Complete is a boolean — just verify it deserializes (not null)
|
||||
// Value depends on whether there are >1 matching resources
|
||||
assertThat(count.complete()).as("Count.Complete").isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(53)
|
||||
void searchCountCompleteIsTrueWhenAllResultsFit() {
|
||||
SearchResponse response = client.search(SearchRequest.builder()
|
||||
.queryString("")
|
||||
.maxResults(1000)
|
||||
.build());
|
||||
|
||||
assertThat(response.count().complete())
|
||||
.as("Count.Complete when not paginating").isTrue();
|
||||
assertThat(response.nextToken()).as("NextToken absent on last page").isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(54)
|
||||
void indexReplicatingFieldsAreEmptyLists() {
|
||||
GetIndexResponse response = client.getIndex(GetIndexRequest.builder().build());
|
||||
|
||||
// ReplicatingFrom and ReplicatingTo should deserialize as lists, not null
|
||||
assertThat(response.replicatingFrom())
|
||||
.as("GetIndex.ReplicatingFrom").isNotNull().isEmpty();
|
||||
assertThat(response.replicatingTo())
|
||||
.as("GetIndex.ReplicatingTo").isNotNull().isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(55)
|
||||
void batchGetViewErrorFieldsDeserialize() {
|
||||
assumeFalse(TestFixtures.isRealAws(), "Uses floci-specific bogus ARN format");
|
||||
String bogus = "arn:aws:resource-explorer-2:us-east-1:000000000000:view/x/00000000-0000-0000-0000-000000000000";
|
||||
|
||||
BatchGetViewResponse response = client.batchGetView(BatchGetViewRequest.builder()
|
||||
.viewArns(bogus)
|
||||
.build());
|
||||
|
||||
assertThat(response.errors()).as("Errors list").hasSize(1);
|
||||
BatchGetViewError error = response.errors().get(0);
|
||||
assertThat(error.viewArn()).as("Error.ViewArn").isEqualTo(bogus);
|
||||
assertThat(error.errorMessage()).as("Error.ErrorMessage").isNotBlank();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(56)
|
||||
void listResourcesPaginationTokenRoundTrips() {
|
||||
assumeFalse(TestFixtures.isRealAws(), "Floci-specific pagination behavior");
|
||||
// Page 1
|
||||
ListResourcesResponse page1 = client.listResources(ListResourcesRequest.builder()
|
||||
.maxResults(1)
|
||||
.build());
|
||||
assertThat(page1.resources()).hasSize(1);
|
||||
assertThat(page1.nextToken()).as("Page1 NextToken").isNotNull();
|
||||
|
||||
// Page 2 using token from page 1
|
||||
ListResourcesResponse page2 = client.listResources(ListResourcesRequest.builder()
|
||||
.maxResults(1)
|
||||
.nextToken(page1.nextToken())
|
||||
.build());
|
||||
assertThat(page2.resources()).hasSize(1);
|
||||
|
||||
// Page 1 and Page 2 should return different resources
|
||||
assertThat(page2.resources().get(0).arn())
|
||||
.as("Page 2 returns different resource")
|
||||
.isNotEqualTo(page1.resources().get(0).arn());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(57)
|
||||
void updateViewNestedFieldsDeserialize() {
|
||||
assumeFalse(TestFixtures.isRealAws(), "Creates/deletes views");
|
||||
// Create, update, verify nested fields roundtrip
|
||||
CreateViewResponse created = client.createView(CreateViewRequest.builder()
|
||||
.viewName("update-nested-test")
|
||||
.build());
|
||||
String arn = created.view().viewArn();
|
||||
|
||||
UpdateViewResponse updated = client.updateView(UpdateViewRequest.builder()
|
||||
.viewArn(arn)
|
||||
.filters(SearchFilter.builder().filterString("region:us-east-1").build())
|
||||
.includedProperties(IncludedProperty.builder().name("tags").build())
|
||||
.build());
|
||||
|
||||
View view = updated.view();
|
||||
assertThat(view.viewArn()).isEqualTo(arn);
|
||||
assertThat(view.filters()).as("Updated Filters").isNotNull();
|
||||
assertThat(view.filters().filterString())
|
||||
.as("Updated FilterString").isEqualTo("region:us-east-1");
|
||||
assertThat(view.includedProperties()).hasSize(1);
|
||||
assertThat(view.includedProperties().get(0).name()).isEqualTo("tags");
|
||||
|
||||
client.deleteView(DeleteViewRequest.builder().viewArn(arn).build());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user