diff --git a/src/main/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingReconciler.java b/src/main/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingReconciler.java index aaabf33ca6..d13334536f 100644 --- a/src/main/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingReconciler.java +++ b/src/main/java/io/github/hectorvent/floci/services/autoscaling/AutoScalingReconciler.java @@ -18,6 +18,7 @@ import io.github.hectorvent.floci.services.ec2.model.LaunchTemplate; import io.github.hectorvent.floci.services.ec2.model.LaunchTemplateData; import io.github.hectorvent.floci.services.ec2.model.Reservation; import io.github.hectorvent.floci.services.ec2.model.Subnet; +import io.github.hectorvent.floci.services.ec2.model.Tag; import io.github.hectorvent.floci.services.elb.ElbClassicService; import io.github.hectorvent.floci.services.elbv2.ElbV2Service; import io.github.hectorvent.floci.services.elbv2.model.TargetDescription; @@ -1063,7 +1064,7 @@ public class AutoScalingReconciler { String instanceType, String keyName, List securityGroupIds, - List instanceTags, + List instanceTags, String userData, String encodedUserData, String iamInstanceProfile, diff --git a/src/main/java/io/github/hectorvent/floci/services/backup/BackupController.java b/src/main/java/io/github/hectorvent/floci/services/backup/BackupController.java index 846132b8cc..8e869b3b28 100644 --- a/src/main/java/io/github/hectorvent/floci/services/backup/BackupController.java +++ b/src/main/java/io/github/hectorvent/floci/services/backup/BackupController.java @@ -19,6 +19,7 @@ import org.jboss.logging.Logger; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -586,7 +587,7 @@ public class BackupController { private Map readStringMap(JsonNode node, String field) { JsonNode mapNode = node.path(field); if (mapNode.isMissingNode() || mapNode.isNull()) { - return new java.util.HashMap<>(); + return new HashMap<>(); } return objectMapper.convertValue(mapNode, Map.class); } diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkCfnProvisioner.java index 97a83f1b02..6cd2400387 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkCfnProvisioner.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkCfnProvisioner.java @@ -32,6 +32,7 @@ import java.util.Objects; import java.util.Set; import java.util.function.Supplier; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * CloudFormation provisioning for the EC2 networking types: {@code AWS::EC2::Subnet}, @@ -527,7 +528,7 @@ public class Ec2NetworkCfnProvisioner implements CfnResourceProvisioner { String egressOnlyInternetGatewayId = ctx.resolveOptional(props, "EgressOnlyInternetGatewayId"); String vpcPeeringConnectionId = ctx.resolveOptional(props, "VpcPeeringConnectionId"); require(ROUTE, "RouteTableId", routeTableId); - long destinations = java.util.stream.Stream.of(destinationCidr, destinationIpv6Cidr, destinationPrefixListId) + long destinations = Stream.of(destinationCidr, destinationIpv6Cidr, destinationPrefixListId) .filter(value -> value != null && !value.isBlank()).count(); if (destinations != 1) { throw new AwsException("ValidationError", ROUTE + " requires exactly one of DestinationCidrBlock," diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontService.java b/src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontService.java index 066bebbb27..58ecc49a56 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontService.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontService.java @@ -827,7 +827,7 @@ public class CloudFrontService implements ServerCertificateReferenceProvider { public ResponseHeadersPolicy getResponseHeadersPolicy(String id) { return rhpStore.get(id) - .or(() -> java.util.Optional.ofNullable(MANAGED_RESPONSE_HEADERS_POLICIES.get(id))) + .or(() -> Optional.ofNullable(MANAGED_RESPONSE_HEADERS_POLICIES.get(id))) .orElseThrow(() -> new AwsException("NoSuchResponseHeadersPolicy", "The specified response headers policy does not exist.", 404)); } @@ -927,7 +927,7 @@ public class CloudFrontService implements ServerCertificateReferenceProvider { if (config == null) { return; } - Set policyIds = new java.util.LinkedHashSet<>(); + Set policyIds = new LinkedHashSet<>(); if (config.getDefaultCacheBehavior() != null) { addResponseHeadersPolicyId( policyIds, diff --git a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2ContainerManager.java b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2ContainerManager.java index 430f43ac48..e9c7c310ae 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2ContainerManager.java +++ b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2ContainerManager.java @@ -1232,7 +1232,7 @@ public class Ec2ContainerManager { * attachment unknown rather than known to be absent */ private String bridgeNetworkIp(String containerId) { - var inspect = dockerClient.inspectContainerCmd(containerId).exec(); + InspectContainerResponse inspect = dockerClient.inspectContainerCmd(containerId).exec(); if (inspect.getNetworkSettings() == null || inspect.getNetworkSettings().getNetworks() == null) { return null; } @@ -1735,9 +1735,9 @@ public class Ec2ContainerManager { private String getContainerBridgeIp(String containerId) { try { - var inspect = dockerClient.inspectContainerCmd(containerId).exec(); + InspectContainerResponse inspect = dockerClient.inspectContainerCmd(containerId).exec(); if (inspect.getNetworkSettings() != null) { - var networks = inspect.getNetworkSettings().getNetworks(); + Map networks = inspect.getNetworkSettings().getNetworks(); if (networks != null) { Optional preferredIp = preferredMetadataSourceIp(networks); if (preferredIp.isPresent()) { diff --git a/src/main/java/io/github/hectorvent/floci/services/firehose/FirehoseService.java b/src/main/java/io/github/hectorvent/floci/services/firehose/FirehoseService.java index 979c815c81..5f909220e7 100644 --- a/src/main/java/io/github/hectorvent/floci/services/firehose/FirehoseService.java +++ b/src/main/java/io/github/hectorvent/floci/services/firehose/FirehoseService.java @@ -49,6 +49,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.regex.Pattern; @ApplicationScoped public class FirehoseService implements ResourceProvider { @@ -65,7 +66,7 @@ public class FirehoseService implements ResourceProvider { * not a bare key id. Accepting anything else would let DescribeDeliveryStream report an * encryption key that could never exist, where real AWS rejects the call outright. */ - private static final java.util.regex.Pattern SSE_KEY_ARN_PATTERN = java.util.regex.Pattern.compile( + private static final Pattern SSE_KEY_ARN_PATTERN = Pattern.compile( "arn:.*:kms:[a-zA-Z0-9\\-]+:\\d{12}:key/[a-zA-Z_0-9+=,.@\\-_/]+"); private static final int SSE_KEY_ARN_MAX_LENGTH = 512; @@ -514,7 +515,7 @@ public class FirehoseService implements ResourceProvider { current.canonicalizeProcessors(); } stream.setVersionId(String.valueOf(parseVersionId(stream.getVersionId()) + 1)); - stream.setLastUpdateTimestamp(java.time.Instant.now()); + stream.setLastUpdateTimestamp(Instant.now()); streamPut(streamKey, stream); LOG.infov("Updated destination {0} of Firehose delivery stream {1}", destinationId, name); } diff --git a/src/main/java/io/github/hectorvent/floci/services/kinesis/KinesisJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/kinesis/KinesisJsonHandler.java index d1ff0ed470..a968392453 100644 --- a/src/main/java/io/github/hectorvent/floci/services/kinesis/KinesisJsonHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/kinesis/KinesisJsonHandler.java @@ -698,13 +698,13 @@ public class KinesisJsonHandler { if (request.has("Timestamp") && !request.path("Timestamp").isNull()) { JsonNode tsNode = request.path("Timestamp"); if (!tsNode.isNumber()) { - throw new io.github.hectorvent.floci.core.common.AwsException("InvalidArgumentException", + throw new AwsException("InvalidArgumentException", "Timestamp must be a number (epoch seconds)", 400); } timestampMillis = Math.round(tsNode.asDouble() * 1000); } if ("AT_TIMESTAMP".equals(type) && timestampMillis == null) { - throw new io.github.hectorvent.floci.core.common.AwsException("InvalidArgumentException", + throw new AwsException("InvalidArgumentException", "ShardIteratorType AT_TIMESTAMP requires a Timestamp", 400); } diff --git a/src/main/java/io/github/hectorvent/floci/services/kinesis/KinesisService.java b/src/main/java/io/github/hectorvent/floci/services/kinesis/KinesisService.java index 0c2137271f..39631ea02f 100644 --- a/src/main/java/io/github/hectorvent/floci/services/kinesis/KinesisService.java +++ b/src/main/java/io/github/hectorvent/floci/services/kinesis/KinesisService.java @@ -36,6 +36,7 @@ import java.util.PriorityQueue; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; +import java.util.regex.Pattern; @ApplicationScoped public class KinesisService implements ResourceProvider { @@ -464,12 +465,12 @@ public class KinesisService implements ResourceProvider { shard2.setSequenceNumberRange(new KinesisShard.SequenceNumberRange(shard2.getSequenceNumberRange().startingSequenceNumber(), seq)); // Combine hash ranges (assuming they are adjacent) - java.math.BigInteger s1Start = new java.math.BigInteger(shard1.getHashKeyRange().startingHashKey()); - java.math.BigInteger s2Start = new java.math.BigInteger(shard2.getHashKeyRange().startingHashKey()); + BigInteger s1Start = new BigInteger(shard1.getHashKeyRange().startingHashKey()); + BigInteger s2Start = new BigInteger(shard2.getHashKeyRange().startingHashKey()); String start = s1Start.min(s2Start).toString(); - java.math.BigInteger s1End = new java.math.BigInteger(shard1.getHashKeyRange().endingHashKey()); - java.math.BigInteger s2End = new java.math.BigInteger(shard2.getHashKeyRange().endingHashKey()); + BigInteger s1End = new BigInteger(shard1.getHashKeyRange().endingHashKey()); + BigInteger s2End = new BigInteger(shard2.getHashKeyRange().endingHashKey()); String end = s1End.max(s2End).toString(); KinesisShard child = new KinesisShard(nextShardId(stream), start, end, seq); @@ -836,7 +837,7 @@ public class KinesisService implements ResourceProvider { throw new AwsException("InvalidArgumentException", "Invalid shard iterator", 400); } // Use limit=-1 so trailing empty slots round-trip and old 5-part iterators still work. - String[] parts = new String(decoded, StandardCharsets.UTF_8).split(java.util.regex.Pattern.quote("|"), -1); + String[] parts = new String(decoded, StandardCharsets.UTF_8).split(Pattern.quote("|"), -1); if (parts.length < 5) { throw new AwsException("InvalidArgumentException", "Invalid shard iterator", 400); } diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/kubernetes/LambdaPodSpecFactory.java b/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/kubernetes/LambdaPodSpecFactory.java index 9346f39fd9..8b3b70b1b1 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/kubernetes/LambdaPodSpecFactory.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambda/launcher/kubernetes/LambdaPodSpecFactory.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Optional; +import java.util.regex.Pattern; /** * Builds the Pod manifest for one Lambda execution environment, as a plain JSON tree (see @@ -28,11 +29,11 @@ public class LambdaPodSpecFactory { private static final Logger LOG = Logger.getLogger(LambdaPodSpecFactory.class); /** Label key: optional DNS-subdomain prefix (dot-separated valid segments), then a 63-char-max name. */ - private static final java.util.regex.Pattern LABEL_KEY = - java.util.regex.Pattern.compile("([a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?[a-zA-Z0-9]([-a-zA-Z0-9_.]{0,61}[a-zA-Z0-9])?"); + private static final Pattern LABEL_KEY = + Pattern.compile("([a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?[a-zA-Z0-9]([-a-zA-Z0-9_.]{0,61}[a-zA-Z0-9])?"); /** Label value: empty, or 63-char-max alphanumeric-bounded. */ - private static final java.util.regex.Pattern LABEL_VALUE = - java.util.regex.Pattern.compile("([a-zA-Z0-9]([-a-zA-Z0-9_.]{0,61}[a-zA-Z0-9])?)?"); + private static final Pattern LABEL_VALUE = + Pattern.compile("([a-zA-Z0-9]([-a-zA-Z0-9_.]{0,61}[a-zA-Z0-9])?)?"); static final String MANAGED_BY_LABEL = "app.kubernetes.io/managed-by"; static final String MANAGED_BY_VALUE = "floci"; diff --git a/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayApiKeyRequiredIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayApiKeyRequiredIntegrationTest.java index 3a4584d02e..557c0a7911 100644 --- a/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayApiKeyRequiredIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayApiKeyRequiredIntegrationTest.java @@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.apigateway; import io.quarkus.test.junit.QuarkusTest; import io.restassured.http.ContentType; +import org.hamcrest.Matchers; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -94,14 +95,14 @@ class ApiGatewayApiKeyRequiredIntegrationTest { .body("{\"authorizationType\":\"NONE\",\"apiKeyRequired\":true}") .when().put("/restapis/" + apiId + "/resources/" + protectedResourceId + "/methods/GET") .then().statusCode(201) - .body("apiKeyRequired", org.hamcrest.Matchers.is(true)); + .body("apiKeyRequired", Matchers.is(true)); given() .contentType(ContentType.JSON) .body("{\"authorizationType\":\"NONE\"}") .when().put("/restapis/" + apiId + "/resources/" + openResourceId + "/methods/GET") .then().statusCode(201) - .body("apiKeyRequired", org.hamcrest.Matchers.is(false)); + .body("apiKeyRequired", Matchers.is(false)); String uri = "arn:aws:apigateway:" + REGION + ":lambda:path/2015-03-31/functions/" + "arn:aws:lambda:" + REGION + ":" + ACCOUNT + ":function:" + ECHO_FUNCTION + "/invocations"; @@ -169,7 +170,7 @@ class ApiGatewayApiKeyRequiredIntegrationTest { .when().get("/execute-api/" + apiId + "/prod/secret") .then().statusCode(403) .header("x-amzn-ErrorType", equalTo("ForbiddenException")) - .body("message", org.hamcrest.Matchers.is("Forbidden")); + .body("message", Matchers.is("Forbidden")); } @Test @Order(5) @@ -179,7 +180,7 @@ class ApiGatewayApiKeyRequiredIntegrationTest { .when().get("/execute-api/" + apiId + "/prod/secret") .then().statusCode(403) .header("x-amzn-ErrorType", equalTo("ForbiddenException")) - .body("message", org.hamcrest.Matchers.is("Forbidden")); + .body("message", Matchers.is("Forbidden")); } @Test @Order(6) @@ -188,7 +189,7 @@ class ApiGatewayApiKeyRequiredIntegrationTest { .header("x-api-key", keyValue) .when().get("/execute-api/" + apiId + "/prod/secret") .then().statusCode(200) - .body("ok", org.hamcrest.Matchers.is(true)); + .body("ok", Matchers.is(true)); } @Test @Order(7) @@ -196,7 +197,7 @@ class ApiGatewayApiKeyRequiredIntegrationTest { given() .when().get("/execute-api/" + apiId + "/prod/public") .then().statusCode(200) - .body("ok", org.hamcrest.Matchers.is(true)); + .body("ok", Matchers.is(true)); } @Test @Order(8) @@ -242,7 +243,7 @@ class ApiGatewayApiKeyRequiredIntegrationTest { """) .when().patch("/restapis/" + apiId + "/resources/" + protectedResourceId + "/methods/GET") .then().statusCode(200) - .body("apiKeyRequired", org.hamcrest.Matchers.is(false)); + .body("apiKeyRequired", Matchers.is(false)); given() .contentType(ContentType.JSON) @@ -255,7 +256,7 @@ class ApiGatewayApiKeyRequiredIntegrationTest { """) .when().patch("/restapis/" + apiId + "/resources/" + protectedResourceId + "/methods/GET") .then().statusCode(200) - .body("apiKeyRequired", org.hamcrest.Matchers.is(true)); + .body("apiKeyRequired", Matchers.is(true)); } @Test @Order(11) diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkCfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkCfnProvisionerTest.java index 43f9edf291..25707d7151 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkCfnProvisionerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkCfnProvisionerTest.java @@ -20,6 +20,7 @@ import io.github.hectorvent.floci.services.ec2.model.Subnet; import io.github.hectorvent.floci.services.ec2.model.Tag; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; import org.mockito.invocation.Invocation; import org.mockito.stubbing.OngoingStubbing; @@ -692,11 +693,11 @@ class Ec2NetworkCfnProvisionerTest { @SuppressWarnings("unchecked") ArgumentCaptor> removed = ArgumentCaptor.forClass(List.class); - verify(ec2, org.mockito.Mockito.times(2)).deleteTags(eq(REGION), eq(List.of(RTB_ID)), removed.capture()); + verify(ec2, Mockito.times(2)).deleteTags(eq(REGION), eq(List.of(RTB_ID)), removed.capture()); assertEquals(List.of("env=null"), pairs(removed.getAllValues().get(1)), "the key the update added is removed"); @SuppressWarnings("unchecked") ArgumentCaptor> written = ArgumentCaptor.forClass(List.class); - verify(ec2, org.mockito.Mockito.times(2)).createTags(eq(REGION), eq(List.of(RTB_ID)), written.capture()); + verify(ec2, Mockito.times(2)).createTags(eq(REGION), eq(List.of(RTB_ID)), written.capture()); assertEquals(List.of("Name=old", "team=net"), pairs(written.getAllValues().get(1)), "the prior tags are written back"); assertFalse(r.getAttributes().containsKey(Ec2NetworkCfnProvisioner.IN_PLACE_PRIOR_ATTR)); } @@ -788,7 +789,7 @@ class Ec2NetworkCfnProvisionerTest { provisioner.provision(updated, mapper.createObjectNode().put("RouteTableId", RTB_ID) .put("DestinationCidrBlock", "10.40.0.18/24").put("GatewayId", IGW_ID), ctx(RTB_ID + "|10.40.0.0/24")); verify(ec2).replaceRoute(REGION, RTB_ID, "10.40.0.18/24", null, null, IGW_ID, null, null); - verify(ec2, org.mockito.Mockito.times(1)).createRoute(any(), any(), any(), any(), any(), any(), any(), any(), any()); + verify(ec2, Mockito.times(1)).createRoute(any(), any(), any(), any(), any(), any(), any(), any(), any()); assertEquals(RTB_ID + "|10.40.0.0/24", updated.getPhysicalId()); } @@ -872,7 +873,7 @@ class Ec2NetworkCfnProvisionerTest { ReplacementCleanup.mergeDisplaced(previous, r); assertEquals("subnet-replacement", provisioner.updateCleanupPhysicalId(previous), "the replacement stays owed a delete"); provisioner.completeUpdate(previous); - verify(ec2, org.mockito.Mockito.times(2)).deleteSubnet(REGION, "subnet-replacement"); + verify(ec2, Mockito.times(2)).deleteSubnet(REGION, "subnet-replacement"); } @Test @@ -930,11 +931,11 @@ class Ec2NetworkCfnProvisionerTest { assertEquals("TagLimitExceeded", e.getErrorCode()); @SuppressWarnings("unchecked") ArgumentCaptor> written = ArgumentCaptor.forClass(List.class); - verify(ec2, org.mockito.Mockito.times(2)).createTags(eq(REGION), eq(List.of(RTB_ID)), written.capture()); + verify(ec2, Mockito.times(2)).createTags(eq(REGION), eq(List.of(RTB_ID)), written.capture()); assertEquals(List.of("Name=old", "team=net"), pairs(written.getAllValues().get(1)), "the prior tags are put back"); @SuppressWarnings("unchecked") ArgumentCaptor> removed = ArgumentCaptor.forClass(List.class); - verify(ec2, org.mockito.Mockito.times(2)).deleteTags(eq(REGION), eq(List.of(RTB_ID)), removed.capture()); + verify(ec2, Mockito.times(2)).deleteTags(eq(REGION), eq(List.of(RTB_ID)), removed.capture()); assertEquals(List.of("env=null"), pairs(removed.getAllValues().get(1)), "the key the failed update added is removed again"); assertFalse(r.getAttributes().containsKey(Ec2NetworkCfnProvisioner.IN_PLACE_PRIOR_ATTR)); assertFalse(r.getAttributes().containsKey(CfnRollback.UPDATE_ROLLBACK_FAILURE_ATTR), "a successful restore reports nothing"); @@ -956,11 +957,11 @@ class Ec2NetworkCfnProvisionerTest { @SuppressWarnings("unchecked") ArgumentCaptor> written = ArgumentCaptor.forClass(List.class); - verify(ec2, org.mockito.Mockito.times(2)).createTags(eq(REGION), eq(List.of(SUBNET_ID)), written.capture()); + verify(ec2, Mockito.times(2)).createTags(eq(REGION), eq(List.of(SUBNET_ID)), written.capture()); assertEquals(List.of("Name=old"), pairs(written.getAllValues().get(1))); // the snapshot recorded the prior value before the flip was attempted, so the restore writes it back verify(ec2).modifySubnetAttribute(REGION, SUBNET_ID, "mapPublicIpOnLaunch", "false"); - verify(ec2, org.mockito.Mockito.times(2)).modifySubnetAttribute(any(), any(), any(), any()); + verify(ec2, Mockito.times(2)).modifySubnetAttribute(any(), any(), any(), any()); verify(ec2, never()).deleteSubnet(any(), any()); } @@ -1002,7 +1003,7 @@ class Ec2NetworkCfnProvisionerTest { @SuppressWarnings("unchecked") ArgumentCaptor> written = ArgumentCaptor.forClass(List.class); - verify(ec2, org.mockito.Mockito.times(2)).createTags(eq(REGION), eq(List.of(NAT_ID)), written.capture()); + verify(ec2, Mockito.times(2)).createTags(eq(REGION), eq(List.of(NAT_ID)), written.capture()); assertEquals(List.of("Name=old"), pairs(written.getAllValues().get(1))); verify(ec2, never()).deleteNatGateway(any(), any()); } diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontServiceTest.java index 35752a4cb5..bba2d27431 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontServiceTest.java @@ -22,6 +22,7 @@ import io.github.hectorvent.floci.services.cloudfront.model.ResponseHeadersPolic import io.github.hectorvent.floci.services.cloudfront.model.StreamingDistribution; import jakarta.ws.rs.core.Response; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import org.mockito.Mockito; import java.security.KeyPairGenerator; @@ -1740,7 +1741,7 @@ class CloudFrontServiceTest { } private static AwsException assertAws( - String code, org.junit.jupiter.api.function.Executable action) { + String code, Executable action) { AwsException error = assertThrows(AwsException.class, action); assertEquals(code, error.getErrorCode()); return error; diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ContainerManagerTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ContainerManagerTest.java index 09c1222bfb..6cf893cfa8 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ContainerManagerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ContainerManagerTest.java @@ -39,12 +39,14 @@ import io.github.hectorvent.floci.services.ec2.model.Instance; import io.github.hectorvent.floci.services.ec2.model.InstanceNetworkInterface; import io.github.hectorvent.floci.services.ec2.net.VpcNetworkManager; import io.github.hectorvent.floci.services.ec2.portforward.Ec2PortForwardManager; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.mockito.ArgumentCaptor; +import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.InputStream; import java.nio.charset.StandardCharsets; @@ -53,6 +55,7 @@ import java.nio.file.Path; import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; +import java.util.Base64; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -71,6 +74,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.function.BooleanSupplier; +import java.util.zip.GZIPOutputStream; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -141,7 +145,7 @@ class Ec2ContainerManagerTest { private static final String TEST_LOG_STREAM_NAME = "yyyy/MM/dd/user-data"; private static final String TEST_SSH_PUBLIC_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAITest test@floci"; - @org.junit.jupiter.api.AfterEach + @AfterEach void resetBridgeIpPolling() { Ec2ContainerManager.containerBridgeIpAttempts = 30; Ec2ContainerManager.containerBridgeIpPollMillis = 500; @@ -716,11 +720,11 @@ class Ec2ContainerManagerTest { } private static String gzipBase64(String plain) throws Exception { - java.io.ByteArrayOutputStream bytes = new java.io.ByteArrayOutputStream(); - try (java.util.zip.GZIPOutputStream gzip = new java.util.zip.GZIPOutputStream(bytes)) { + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + try (GZIPOutputStream gzip = new GZIPOutputStream(bytes)) { gzip.write(plain.getBytes(StandardCharsets.UTF_8)); } - return java.util.Base64.getEncoder().encodeToString(bytes.toByteArray()); + return Base64.getEncoder().encodeToString(bytes.toByteArray()); } private static final String CLOUDINIT_MULTIPART = """ @@ -816,7 +820,7 @@ class Ec2ContainerManagerTest { @Test void userDataShellScriptsDecodesPlainBase64ShellScript() { String script = "#!/bin/bash\necho ready\n"; - String encoded = java.util.Base64.getEncoder().encodeToString(script.getBytes(StandardCharsets.UTF_8)); + String encoded = Base64.getEncoder().encodeToString(script.getBytes(StandardCharsets.UTF_8)); assertEquals(List.of(script), Ec2ContainerManager.userDataShellScripts(encoded)); } @@ -1128,7 +1132,7 @@ class Ec2ContainerManagerTest { @Test void localAwsEnvironmentProvidesCliCredentialsAndFlociEndpoint() { assertEquals( - java.util.List.of( + List.of( "AWS_EC2_METADATA_SERVICE_ENDPOINT=http://floci:9169", "AWS_ENDPOINT_URL=http://floci:4566", "AWS_DEFAULT_REGION=us-west-2", diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java index 3e07e1709c..225b1b7967 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java @@ -4,6 +4,8 @@ import io.quarkus.test.junit.QuarkusTest; import io.restassured.path.xml.XmlPath; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; +import io.restassured.specification.RequestSpecification; +import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -4124,7 +4126,7 @@ class Ec2IntegrationTest { .statusCode(200) .extract().body().asString(); - org.hamcrest.MatcherAssert.assertThat(body, not(containsString(""))); + MatcherAssert.assertThat(body, not(containsString(""))); } // ========================================================================= @@ -4202,14 +4204,14 @@ class Ec2IntegrationTest { int pageCount = 0; String nextToken = null; do { - io.restassured.specification.RequestSpecification req = given() + RequestSpecification req = given() .formParam("Action", "DescribeNetworkInterfaces") .formParam("MaxResults", "5") .header("Authorization", AUTH_HEADER); if (nextToken != null) { req = req.formParam("NextToken", nextToken); } - io.restassured.response.Response resp = req.when().post("/"); + Response resp = req.when().post("/"); resp.then().statusCode(200); pageCount++; @@ -4221,16 +4223,16 @@ class Ec2IntegrationTest { // Every page but the last must be a full page of 5. if (nextToken != null && !nextToken.isEmpty()) { - org.hamcrest.MatcherAssert.assertThat(ids.size(), equalTo(5)); + MatcherAssert.assertThat(ids.size(), equalTo(5)); } } while (nextToken != null && !nextToken.isEmpty()); - org.hamcrest.MatcherAssert.assertThat( + MatcherAssert.assertThat( "Expected " + expectedTotal + " ENIs across " + pageCount + " page(s)", collected, equalTo(expectedTotal)); // With 5 new ENIs and MaxResults=5, at least one truncated page // must have occurred (i.e. more than a single page was fetched). - org.hamcrest.MatcherAssert.assertThat(pageCount, greaterThanOrEqualTo(2)); + MatcherAssert.assertThat(pageCount, greaterThanOrEqualTo(2)); // ── Cleanup: terminate the 5 extra instances ── for (String id : batchIds) { @@ -4254,14 +4256,14 @@ class Ec2IntegrationTest { int total = 0; String nextToken = null; do { - io.restassured.specification.RequestSpecification req = given() + RequestSpecification req = given() .formParam("Action", "DescribeNetworkInterfaces") .formParam("MaxResults", "1000") .header("Authorization", AUTH_HEADER); if (nextToken != null) { req = req.formParam("NextToken", nextToken); } - io.restassured.response.Response resp = req.when().post("/"); + Response resp = req.when().post("/"); resp.then().statusCode(200); List ids = resp.xmlPath().getList( diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ServiceTest.java index 556f04c8ef..04c9ed1c24 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ServiceTest.java @@ -93,6 +93,7 @@ import java.time.Duration; import java.time.Instant; import java.util.ArrayList; import java.util.Base64; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -7537,11 +7538,11 @@ class Ec2ServiceTest { Ec2Service service = prefixListService(); String[] fixture = attachmentFixture(service); int threads = 6; - java.util.concurrent.CountDownLatch start = new java.util.concurrent.CountDownLatch(1); - java.util.concurrent.ExecutorService pool = - java.util.concurrent.Executors.newFixedThreadPool(threads); - List created = java.util.Collections.synchronizedList(new java.util.ArrayList<>()); - List errors = java.util.Collections.synchronizedList(new java.util.ArrayList<>()); + CountDownLatch start = new CountDownLatch(1); + ExecutorService pool = + Executors.newFixedThreadPool(threads); + List created = Collections.synchronizedList(new ArrayList<>()); + List errors = Collections.synchronizedList(new ArrayList<>()); for (int i = 0; i < threads; i++) { pool.submit(() -> { @@ -7559,7 +7560,7 @@ class Ec2ServiceTest { } start.countDown(); pool.shutdown(); - assertTrue(pool.awaitTermination(30, java.util.concurrent.TimeUnit.SECONDS)); + assertTrue(pool.awaitTermination(30, TimeUnit.SECONDS)); assertEquals(1, created.size(), "trial " + trial + ": exactly one create may win"); assertEquals(threads - 1, errors.size(), "every loser is told the VPC is already attached"); @@ -7581,9 +7582,9 @@ class Ec2ServiceTest { for (int trial = 0; trial < 10; trial++) { Ec2Service service = prefixListService(); String[] fixture = attachmentFixture(service); - java.util.concurrent.CountDownLatch start = new java.util.concurrent.CountDownLatch(1); - java.util.concurrent.ExecutorService pool = - java.util.concurrent.Executors.newFixedThreadPool(2); + CountDownLatch start = new CountDownLatch(1); + ExecutorService pool = + Executors.newFixedThreadPool(2); pool.submit(() -> { try { @@ -7609,7 +7610,7 @@ class Ec2ServiceTest { }); start.countDown(); pool.shutdown(); - assertTrue(pool.awaitTermination(30, java.util.concurrent.TimeUnit.SECONDS)); + assertTrue(pool.awaitTermination(30, TimeUnit.SECONDS)); List attachments = service.describeTransitGatewayVpcAttachments("us-east-1", List.of(), Map.of()); @@ -7646,9 +7647,9 @@ class Ec2ServiceTest { if (!attachment) { service.deleteTransitGatewayVpcAttachment("us-east-1", attachmentId); } - java.util.concurrent.CountDownLatch start = new java.util.concurrent.CountDownLatch(1); - java.util.concurrent.ExecutorService pool = - java.util.concurrent.Executors.newFixedThreadPool(2); + CountDownLatch start = new CountDownLatch(1); + ExecutorService pool = + Executors.newFixedThreadPool(2); pool.submit(() -> { try { @@ -7672,7 +7673,7 @@ class Ec2ServiceTest { }); start.countDown(); pool.shutdown(); - assertTrue(pool.awaitTermination(30, java.util.concurrent.TimeUnit.SECONDS)); + assertTrue(pool.awaitTermination(30, TimeUnit.SECONDS)); String what = attachment ? "attachment" : "gateway"; if (attachment) { @@ -8140,9 +8141,9 @@ class Ec2ServiceTest { String[] fixture = attachmentFixture(service); String spare = service.createTransitGatewayRouteTable("us-east-1", fixture[0], List.of()) .getTransitGatewayRouteTableId(); - java.util.concurrent.CountDownLatch start = new java.util.concurrent.CountDownLatch(1); - java.util.concurrent.ExecutorService pool = - java.util.concurrent.Executors.newFixedThreadPool(2); + CountDownLatch start = new CountDownLatch(1); + ExecutorService pool = + Executors.newFixedThreadPool(2); pool.submit(() -> { try { @@ -8165,7 +8166,7 @@ class Ec2ServiceTest { }); start.countDown(); pool.shutdown(); - assertTrue(pool.awaitTermination(30, java.util.concurrent.TimeUnit.SECONDS)); + assertTrue(pool.awaitTermination(30, TimeUnit.SECONDS)); boolean tableExists = service.describeTransitGatewayRouteTables("us-east-1", List.of(), Map.of()) .stream().anyMatch(rt -> rt.getTransitGatewayRouteTableId().equals(spare)); @@ -8561,7 +8562,7 @@ class Ec2ServiceTest { return (AccountAwareStorageBackend) override; } AccountAwareStorageBackend backend = requestContextInstance != null - ? new AccountAwareStorageBackend<>(new io.github.hectorvent.floci.core.storage.InMemoryStorage<>(), + ? new AccountAwareStorageBackend<>(new InMemoryStorage<>(), requestContextInstance, "000000000000") : AccountAwareStorageBackend.inMemory("000000000000"); created.add(backend); @@ -8580,7 +8581,7 @@ class Ec2ServiceTest { private int putCount; private DetachedImageStorage() { - super(new io.github.hectorvent.floci.core.storage.InMemoryStorage<>(), null, "000000000000"); + super(new InMemoryStorage<>(), null, "000000000000"); } @Override @@ -8634,8 +8635,8 @@ class Ec2ServiceTest { copy.setCreationSourceInstanceId(source.getCreationSourceInstanceId()); copy.setDockerImage(source.getDockerImage()); copy.setBlockDeviceMappings(source.getBlockDeviceMappings() == null - ? List.of() : new java.util.ArrayList<>(source.getBlockDeviceMappings())); - copy.setTags(source.getTags() == null ? List.of() : new java.util.ArrayList<>(source.getTags())); + ? List.of() : new ArrayList<>(source.getBlockDeviceMappings())); + copy.setTags(source.getTags() == null ? List.of() : new ArrayList<>(source.getTags())); return copy; } } diff --git a/src/test/java/io/github/hectorvent/floci/services/firehose/FirehoseServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/firehose/FirehoseServiceTest.java index 80b0e19b74..567857ca44 100644 --- a/src/test/java/io/github/hectorvent/floci/services/firehose/FirehoseServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/firehose/FirehoseServiceTest.java @@ -778,7 +778,7 @@ class FirehoseServiceTest { private void createSourcedDeliveryStream(String deliveryStream, String sourceStream) { kinesisService.createStream(sourceStream, 1, "us-east-1"); firehoseService.createDeliveryStream(deliveryStream, destination("arn:aws:s3:::sink", null), - java.util.List.of(), "KinesisStreamAsSource", kinesisSource(sourceStream)); + List.of(), "KinesisStreamAsSource", kinesisSource(sourceStream)); } private void closeSourceParent() { @@ -897,7 +897,7 @@ class FirehoseServiceTest { ArgumentCaptor body = ArgumentCaptor.forClass(byte[].class); verify(s3Service, Mockito.times(2)).putObject(anyString(), anyString(), body.capture(), anyString(), anyMap(), any(PutObjectOptions.class)); - assertEquals(java.util.List.of("first\n", "second\n"), + assertEquals(List.of("first\n", "second\n"), body.getAllValues().stream().map(b -> new String(b, StandardCharsets.UTF_8)).toList()); } @@ -910,7 +910,7 @@ class FirehoseServiceTest { // delivery starts at DeliveryStartTimestamp. source.setDeliveryStartTimestamp(Instant.now().plusSeconds(3600)); firehoseService.createDeliveryStream("sourced-stream", destination("arn:aws:s3:::sink", null), - java.util.List.of(), "KinesisStreamAsSource", source); + List.of(), "KinesisStreamAsSource", source); firehoseService.pollKinesisSources(); firehoseService.flush("sourced-stream"); @@ -1138,7 +1138,7 @@ class FirehoseServiceTest { void aMissingSourceStreamDoesNotStopOtherStreamsFromPolling() { // No createStream for "gone-stream": describeStream throws ResourceNotFound. firehoseService.createDeliveryStream("broken-stream", destination("arn:aws:s3:::sink", null), - java.util.List.of(), "KinesisStreamAsSource", kinesisSource("gone-stream")); + List.of(), "KinesisStreamAsSource", kinesisSource("gone-stream")); createSourcedDeliveryStream("sourced-stream", "src-stream"); kinesisService.putRecord("src-stream", "hello".getBytes(StandardCharsets.UTF_8), "pk", "us-east-1"); diff --git a/src/test/java/io/github/hectorvent/floci/services/kinesis/KinesisJsonHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/kinesis/KinesisJsonHandlerTest.java index db0c1dc6b0..a0cbcd9584 100644 --- a/src/test/java/io/github/hectorvent/floci/services/kinesis/KinesisJsonHandlerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/kinesis/KinesisJsonHandlerTest.java @@ -21,6 +21,7 @@ import java.nio.ByteBuffer; import java.time.Clock; import java.time.Instant; import java.time.ZoneOffset; +import java.util.ArrayList; import java.util.Base64; import java.util.List; import java.util.Map; @@ -1520,7 +1521,7 @@ class KinesisJsonHandlerTest { assertEquals(3, shards.size()); ObjectNode parent = (ObjectNode) shards.get(0); - List children = new java.util.ArrayList<>(); + List children = new ArrayList<>(); for (JsonNode s : shards) { if (s.has("ParentShardId") && s.get("ParentShardId").asText().equals(parent.get("ShardId").asText())) { children.add((ObjectNode) s); diff --git a/tools/checkstyle/suppressions.xml b/tools/checkstyle/suppressions.xml index 5a5c727159..4d219c28a9 100644 --- a/tools/checkstyle/suppressions.xml +++ b/tools/checkstyle/suppressions.xml @@ -7,7 +7,6 @@ - @@ -16,25 +15,15 @@ - - - - - - - - - - @@ -42,14 +31,8 @@ - - - - - -