From f8d6cf7adfea0bc91bfd894c2aab4a389ac1d281 Mon Sep 17 00:00:00 2001 From: Mark Kuhn Date: Tue, 23 Aug 2022 16:47:50 -0700 Subject: [PATCH] Move buildspecs to S3 bucket (#113) * rm buildspecs * style improvements & code debt --- buildspecs/buildspec.canary.yml | 21 ------------ buildspecs/buildspec.release.yml | 17 ---------- buildspecs/buildspec.yml | 21 ------------ examples/lambda/src/main/java/Handler.java | 4 +-- .../emf/config/SystemWrapper.java | 3 ++ .../environment/AgentBasedEnvironment.java | 2 +- .../emf/model/MetricsContext.java | 4 +-- .../emf/serializers/InstantSerializer.java | 4 +-- .../emf/serializers/UnitDeserializer.java | 8 ++--- .../emf/serializers/UnitSerializer.java | 4 +-- .../cloudwatchlogs/emf/util/IOUtils.java | 4 +++ .../cloudwatchlogs/emf/util/Jackson.java | 3 ++ .../cloudwatchlogs/emf/util/StringUtils.java | 3 ++ .../emf/config/ConfigurationTest.java | 20 +++++------ .../EnvironmentConfigurationProviderTest.java | 14 ++++---- .../environment/DefaultEnvironmentTest.java | 16 ++++----- .../emf/environment/EC2EnvironmentTest.java | 16 ++++----- .../emf/environment/ECSEnvironmentTest.java | 28 +++++++-------- .../environment/LambdaEnvironmentTest.java | 14 ++++---- .../emf/environment/LocalEnvironmentTest.java | 16 ++++----- .../emf/environment/ResourceFetcherTest.java | 14 ++++---- .../emf/logger/MetricsLoggerTest.java | 34 +++++++++---------- .../emf/model/MetadataTest.java | 14 ++++---- .../emf/model/MetricDefinitionTest.java | 10 +++--- .../emf/model/MetricDirectiveTest.java | 34 +++++++++---------- .../emf/model/MetricsContextTest.java | 9 +++-- .../emf/model/RootNodeTest.java | 27 +++++++-------- .../emf/sinks/AgentSinkTest.java | 8 ++--- .../emf/sinks/EndpointTest.java | 4 +-- .../emf/sinks/ProtocolTest.java | 12 +++---- .../cloudwatchlogs/emf/util/IOUtilsTest.java | 4 +-- 31 files changed, 166 insertions(+), 226 deletions(-) delete mode 100644 buildspecs/buildspec.canary.yml delete mode 100644 buildspecs/buildspec.release.yml delete mode 100644 buildspecs/buildspec.yml diff --git a/buildspecs/buildspec.canary.yml b/buildspecs/buildspec.canary.yml deleted file mode 100644 index 35e33c5f..00000000 --- a/buildspecs/buildspec.canary.yml +++ /dev/null @@ -1,21 +0,0 @@ -version: 0.2 - -env: - variables: - AWS_REGION: us-west-2 - parameter-store: - AWS_ACCESS_KEY_ID: AccessKey - AWS_SECRET_ACCESS_KEY: SecretKey -phases: - install: - runtime-versions: - java: corretto11 - commands: - # start docker - # https://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker-custom-image.html#sample-docker-custom-image-files - - nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay2& - - timeout 15 sh -c "until docker info; do echo .; sleep 1; done" - build: - commands: - - ./gradlew build - - ./bin/deploy-canary.sh diff --git a/buildspecs/buildspec.release.yml b/buildspecs/buildspec.release.yml deleted file mode 100644 index 6ac0735d..00000000 --- a/buildspecs/buildspec.release.yml +++ /dev/null @@ -1,17 +0,0 @@ -version: 0.2 - -env: - variables: - AWS_REGION: us-west-2 - parameter-store: - ORG_GRADLE_PROJECT_signingKey: emf_java_signing_key - ORG_GRADLE_PROJECT_signingPassword: emf_java_signing_password - mavenUserName: mavenUserName - mavenPassword: mavenPassword -phases: - install: - runtime-versions: - java: corretto11 - build: - commands: - - ./gradlew publish diff --git a/buildspecs/buildspec.yml b/buildspecs/buildspec.yml deleted file mode 100644 index 31b5b135..00000000 --- a/buildspecs/buildspec.yml +++ /dev/null @@ -1,21 +0,0 @@ -version: 0.2 - -env: - variables: - AWS_REGION: us-west-2 - parameter-store: - AWS_ACCESS_KEY_ID: AccessKey - AWS_SECRET_ACCESS_KEY: SecretKey -phases: - install: - runtime-versions: - java: corretto11 - commands: - # start docker - # https://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker-custom-image.html#sample-docker-custom-image-files - - nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay2& - - timeout 15 sh -c "until docker info; do echo .; sleep 1; done" - build: - commands: - - ./gradlew build - - ./gradlew integ diff --git a/examples/lambda/src/main/java/Handler.java b/examples/lambda/src/main/java/Handler.java index 2c24d653..913dc06a 100644 --- a/examples/lambda/src/main/java/Handler.java +++ b/examples/lambda/src/main/java/Handler.java @@ -7,10 +7,10 @@ import java.util.HashMap; import java.util.Map; -public class Handler implements RequestHandler, String> { +public class Handler implements RequestHandler, String> { @Override - public String handleRequest(Map event, Context context) { + public String handleRequest(Map event, Context context) { String response = "200 OK"; MetricsLogger logger = new MetricsLogger(); diff --git a/src/main/java/software/amazon/cloudwatchlogs/emf/config/SystemWrapper.java b/src/main/java/software/amazon/cloudwatchlogs/emf/config/SystemWrapper.java index 91ef3069..4e2716fc 100644 --- a/src/main/java/software/amazon/cloudwatchlogs/emf/config/SystemWrapper.java +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/config/SystemWrapper.java @@ -18,6 +18,9 @@ /** A wrapper class that can be used to mock 'System.getenv' with PowerMock. */ public class SystemWrapper { + private SystemWrapper() { + throw new IllegalStateException("Utility class"); + } public static String getenv(String name) { return System.getenv(name); diff --git a/src/main/java/software/amazon/cloudwatchlogs/emf/environment/AgentBasedEnvironment.java b/src/main/java/software/amazon/cloudwatchlogs/emf/environment/AgentBasedEnvironment.java index 4306eaa0..5c6f69d1 100644 --- a/src/main/java/software/amazon/cloudwatchlogs/emf/environment/AgentBasedEnvironment.java +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/environment/AgentBasedEnvironment.java @@ -30,7 +30,7 @@ public abstract class AgentBasedEnvironment implements Environment { private final Configuration config; private ISink sink; - public AgentBasedEnvironment(Configuration config) { + protected AgentBasedEnvironment(Configuration config) { this.config = config; } diff --git a/src/main/java/software/amazon/cloudwatchlogs/emf/model/MetricsContext.java b/src/main/java/software/amazon/cloudwatchlogs/emf/model/MetricsContext.java index 65df89d3..18cd5015 100644 --- a/src/main/java/software/amazon/cloudwatchlogs/emf/model/MetricsContext.java +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/model/MetricsContext.java @@ -91,7 +91,7 @@ public void setDefaultDimensions(DimensionSet dimensionSet) { } public boolean hasDefaultDimensions() { - return getDefaultDimensions().getDimensionKeys().size() > 0; + return !getDefaultDimensions().getDimensionKeys().isEmpty(); } /** @@ -258,7 +258,7 @@ public List serialize() throws JsonProcessingException { Map metrics = new HashMap<>(); Queue metricDefinitions = new LinkedList<>(rootNode.metrics().values()); - while (metricDefinitions.size() > 0) { + while (!metricDefinitions.isEmpty()) { MetricDefinition metric = metricDefinitions.poll(); if (metrics.size() == Constants.MAX_METRICS_PER_EVENT diff --git a/src/main/java/software/amazon/cloudwatchlogs/emf/serializers/InstantSerializer.java b/src/main/java/software/amazon/cloudwatchlogs/emf/serializers/InstantSerializer.java index 854a07c6..f2297e15 100644 --- a/src/main/java/software/amazon/cloudwatchlogs/emf/serializers/InstantSerializer.java +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/serializers/InstantSerializer.java @@ -17,7 +17,6 @@ package software.amazon.cloudwatchlogs.emf.serializers; import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import java.io.IOException; @@ -35,8 +34,7 @@ public class InstantSerializer extends StdSerializer { @Override public void serialize(Instant value, JsonGenerator jgen, SerializerProvider provider) - throws IOException, JsonProcessingException { - + throws IOException { jgen.writeNumber(value.toEpochMilli()); } } diff --git a/src/main/java/software/amazon/cloudwatchlogs/emf/serializers/UnitDeserializer.java b/src/main/java/software/amazon/cloudwatchlogs/emf/serializers/UnitDeserializer.java index 0a54cbdb..8ef87531 100644 --- a/src/main/java/software/amazon/cloudwatchlogs/emf/serializers/UnitDeserializer.java +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/serializers/UnitDeserializer.java @@ -17,7 +17,6 @@ package software.amazon.cloudwatchlogs.emf.serializers; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import java.io.IOException; @@ -34,11 +33,8 @@ public class UnitDeserializer extends StdDeserializer { } @Override - public Unit deserialize(JsonParser jp, DeserializationContext ctxt) - throws IOException, JsonProcessingException { - + public Unit deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { String value = jp.getValueAsString(); - Unit unit = Unit.fromValue(value); - return unit; + return Unit.fromValue(value); } } diff --git a/src/main/java/software/amazon/cloudwatchlogs/emf/serializers/UnitSerializer.java b/src/main/java/software/amazon/cloudwatchlogs/emf/serializers/UnitSerializer.java index 99afffac..f9f823a7 100644 --- a/src/main/java/software/amazon/cloudwatchlogs/emf/serializers/UnitSerializer.java +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/serializers/UnitSerializer.java @@ -17,7 +17,6 @@ package software.amazon.cloudwatchlogs.emf.serializers; import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import java.io.IOException; @@ -35,8 +34,7 @@ public class UnitSerializer extends StdSerializer { @Override public void serialize(Unit value, JsonGenerator jgen, SerializerProvider provider) - throws IOException, JsonProcessingException { - + throws IOException { String str = value.toString(); jgen.writeString(str); } diff --git a/src/main/java/software/amazon/cloudwatchlogs/emf/util/IOUtils.java b/src/main/java/software/amazon/cloudwatchlogs/emf/util/IOUtils.java index 3bfe0e6f..ea3cef63 100644 --- a/src/main/java/software/amazon/cloudwatchlogs/emf/util/IOUtils.java +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/util/IOUtils.java @@ -24,6 +24,10 @@ import org.slf4j.Logger; public class IOUtils { + private IOUtils() { + throw new IllegalStateException("Utility class"); + } + private static final int BUFFER_SIZE = 1024 * 4; /** diff --git a/src/main/java/software/amazon/cloudwatchlogs/emf/util/Jackson.java b/src/main/java/software/amazon/cloudwatchlogs/emf/util/Jackson.java index 369b608f..6b0a9e0f 100644 --- a/src/main/java/software/amazon/cloudwatchlogs/emf/util/Jackson.java +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/util/Jackson.java @@ -22,6 +22,9 @@ import software.amazon.cloudwatchlogs.emf.exception.EMFClientException; public class Jackson { + private Jackson() { + throw new IllegalStateException("Utility class"); + } private static final ObjectMapper objectMapper = new ObjectMapper(); private static final ObjectWriter writer = objectMapper.writer(); diff --git a/src/main/java/software/amazon/cloudwatchlogs/emf/util/StringUtils.java b/src/main/java/software/amazon/cloudwatchlogs/emf/util/StringUtils.java index 1465135c..9d26c4e1 100644 --- a/src/main/java/software/amazon/cloudwatchlogs/emf/util/StringUtils.java +++ b/src/main/java/software/amazon/cloudwatchlogs/emf/util/StringUtils.java @@ -17,6 +17,9 @@ package software.amazon.cloudwatchlogs.emf.util; public class StringUtils { + private StringUtils() { + throw new IllegalStateException("Utility class"); + } public static boolean isNullOrEmpty(String value) { return value == null || value.isEmpty(); diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/config/ConfigurationTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/config/ConfigurationTest.java index 1859190a..e5a4bd65 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/config/ConfigurationTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/config/ConfigurationTest.java @@ -42,8 +42,8 @@ public void testReturnEmptyOrDefaultIfNotSet() { assertFalse(config.getServiceType().isPresent()); assertFalse(config.getServiceName().isPresent()); - assertEquals(config.getEnvironmentOverride(), Environments.Unknown); - assertEquals(config.getAsyncBufferSize(), 100); + assertEquals(Environments.Unknown, config.getEnvironmentOverride()); + assertEquals(100, config.getAsyncBufferSize()); } @Test @@ -60,7 +60,7 @@ public void testReturnEmptyIfStringValueIsBlank() { assertFalse(config.getLogStreamName().isPresent()); assertFalse(config.getServiceType().isPresent()); assertFalse(config.getServiceName().isPresent()); - assertEquals(config.getEnvironmentOverride(), Environments.Unknown); + assertEquals(Environments.Unknown, config.getEnvironmentOverride()); } @Test @@ -81,12 +81,12 @@ public void testReturnCorrectValueAfterSet() { config.setEnvironmentOverride(expectedEnvironment); config.setAsyncBufferSize(expectedAsyncBufferSize); - assertEquals(config.getAgentEndpoint().get(), expectedEndpoint); - assertEquals(config.getLogGroupName().get(), expectedLogGroupName); - assertEquals(config.getLogStreamName().get(), expectedLogStreamName); - assertEquals(config.getServiceType().get(), expectedServiceType); - assertEquals(config.getServiceName().get(), expectedServiceName); - assertEquals(config.getEnvironmentOverride(), expectedEnvironment); - assertEquals(config.getAsyncBufferSize(), expectedAsyncBufferSize); + assertEquals(expectedEndpoint, config.getAgentEndpoint().get()); + assertEquals(expectedLogGroupName, config.getLogGroupName().get()); + assertEquals(expectedLogStreamName, config.getLogStreamName().get()); + assertEquals(expectedServiceType, config.getServiceType().get()); + assertEquals(expectedServiceName, config.getServiceName().get()); + assertEquals(expectedEnvironment, config.getEnvironmentOverride()); + assertEquals(expectedAsyncBufferSize, config.getAsyncBufferSize()); } } diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/config/EnvironmentConfigurationProviderTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/config/EnvironmentConfigurationProviderTest.java index 28c3b017..9e686070 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/config/EnvironmentConfigurationProviderTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/config/EnvironmentConfigurationProviderTest.java @@ -43,13 +43,13 @@ public void getGetConfig() { Configuration config = EnvironmentConfigurationProvider.createConfig(); - assertEquals(config.getServiceName().get(), "TestServiceName"); - assertEquals(config.getServiceType().get(), "TestServiceType"); - assertEquals(config.getLogGroupName().get(), "TestLogGroup"); - assertEquals(config.getLogStreamName().get(), "TestLogStream"); - assertEquals(config.getAgentEndpoint().get(), "Endpoint"); - assertEquals(config.getEnvironmentOverride(), Environments.Agent); - assertEquals(config.getAsyncBufferSize(), 9999); + assertEquals("TestServiceName", config.getServiceName().get()); + assertEquals("TestServiceType", config.getServiceType().get()); + assertEquals("TestLogGroup", config.getLogGroupName().get()); + assertEquals("TestLogStream", config.getLogStreamName().get()); + assertEquals("Endpoint", config.getAgentEndpoint().get()); + assertEquals(Environments.Agent, config.getEnvironmentOverride()); + assertEquals(9999, config.getAsyncBufferSize()); } @Test diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/environment/DefaultEnvironmentTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/environment/DefaultEnvironmentTest.java index ecbd6c66..e0aaf9d3 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/environment/DefaultEnvironmentTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/environment/DefaultEnvironmentTest.java @@ -39,33 +39,33 @@ public void setUp() { public void testGetName() { String serviceName = "TestService"; when(configuration.getServiceName()).thenReturn(Optional.of(serviceName)); - assertEquals(environment.getName(), serviceName); + assertEquals(serviceName, environment.getName()); } @Test public void testGetNameWhenNotConfigured() { when(configuration.getServiceName()).thenReturn(Optional.empty()); - assertEquals(environment.getName(), "Unknown"); + assertEquals("Unknown", environment.getName()); } @Test public void testGetType() { String serviceType = "TestServiceType"; when(configuration.getServiceType()).thenReturn(Optional.of(serviceType)); - assertEquals(environment.getType(), serviceType); + assertEquals(serviceType, environment.getType()); } @Test public void testGetTypeWhenNotConfigured() { when(configuration.getServiceType()).thenReturn(Optional.empty()); - assertEquals(environment.getType(), "Unknown"); + assertEquals("Unknown", environment.getType()); } @Test public void testGetLogStreamName() { String logStream = "TestLogStream"; when(configuration.getLogStreamName()).thenReturn(Optional.of(logStream)); - assertEquals(environment.getLogStreamName(), logStream); + assertEquals(logStream, environment.getLogStreamName()); } @Test @@ -73,14 +73,14 @@ public void testGetLogStreamNameWhenNotConfigured() { String serviceName = "TestService"; when(configuration.getLogStreamName()).thenReturn(Optional.empty()); when(configuration.getServiceName()).thenReturn(Optional.of(serviceName)); - assertEquals(environment.getLogStreamName(), ""); + assertEquals("", environment.getLogStreamName()); } @Test public void testGetLogGroupName() { String logGroup = "TestLogGroup"; when(configuration.getLogGroupName()).thenReturn(Optional.of(logGroup)); - assertEquals(environment.getLogGroupName(), logGroup); + assertEquals(logGroup, environment.getLogGroupName()); } @Test @@ -88,6 +88,6 @@ public void testGetLogLogNameWhenNotConfigured() { String serviceName = "TestService"; when(configuration.getLogGroupName()).thenReturn(Optional.empty()); when(configuration.getServiceName()).thenReturn(Optional.of(serviceName)); - assertEquals(environment.getLogGroupName(), serviceName + "-metrics"); + assertEquals(serviceName + "-metrics", environment.getLogGroupName()); } } diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/environment/EC2EnvironmentTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/environment/EC2EnvironmentTest.java index bab2f2d6..a68cbb79 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/environment/EC2EnvironmentTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/environment/EC2EnvironmentTest.java @@ -69,7 +69,7 @@ public void testProbeReturnTrue() { public void testGetTypeWhenNoMetadata() { when(fetcher.fetch(any(), any())).thenThrow(new EMFClientException("Invalid URL")); environment.probe(); - assertEquals(environment.getType(), Constants.UNKNOWN); + assertEquals(Constants.UNKNOWN, environment.getType()); } @Test @@ -78,7 +78,7 @@ public void testGetTypeReturnDefined() { when(fetcher.fetch(any(), any(), (Class) any(), any())) .thenReturn(new EC2Environment.EC2Metadata()); environment.probe(); - assertEquals(environment.getType(), "AWS::EC2::Instance"); + assertEquals("AWS::EC2::Instance", environment.getType()); } @Test @@ -87,7 +87,7 @@ public void testGetTypeFromConfiguration() { environment.probe(); String testType = faker.letterify("???"); when(config.getServiceType()).thenReturn(Optional.of(testType)); - assertEquals(environment.getType(), testType); + assertEquals(testType, environment.getType()); } @Test @@ -101,11 +101,11 @@ public void testConfigureContext() { MetricsContext context = new MetricsContext(); environment.configureContext(context); - assertEquals(context.getProperty("imageId"), metadata.getImageId()); - assertEquals(context.getProperty("instanceId"), metadata.getInstanceId()); - assertEquals(context.getProperty("instanceType"), metadata.getInstanceType()); - assertEquals(context.getProperty("privateIp"), metadata.getPrivateIp()); - assertEquals(context.getProperty("availabilityZone"), metadata.getAvailabilityZone()); + assertEquals(metadata.getImageId(), context.getProperty("imageId")); + assertEquals(metadata.getInstanceId(), context.getProperty("instanceId")); + assertEquals(metadata.getInstanceType(), context.getProperty("instanceType")); + assertEquals(metadata.getPrivateIp(), context.getProperty("privateIp")); + assertEquals(metadata.getAvailabilityZone(), context.getProperty("availabilityZone")); } private void getRandomMetadata(EC2Environment.EC2Metadata metadata) { diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/environment/ECSEnvironmentTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/environment/ECSEnvironmentTest.java index eef757c7..22e80a86 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/environment/ECSEnvironmentTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/environment/ECSEnvironmentTest.java @@ -85,7 +85,7 @@ public void testFormatImageName() { when(fetcher.fetch(any(), (ObjectMapper) any(), any())).thenReturn(metadata); assertTrue(environment.probe()); - assertEquals(environment.getName(), "testImage:latest"); + assertEquals("testImage:latest", environment.getName()); } @Test @@ -93,25 +93,25 @@ public void testGetNameFromConfig() { String serviceName = "testService"; when(config.getServiceName()).thenReturn(Optional.of(serviceName)); - assertEquals(environment.getName(), serviceName); + assertEquals(serviceName, environment.getName()); } @Test public void testGetNameReturnsUnknown() { when(config.getServiceName()).thenReturn(Optional.empty()); - assertEquals(environment.getName(), Constants.UNKNOWN); + assertEquals(Constants.UNKNOWN, environment.getName()); } @Test public void testGetType() { - assertEquals(environment.getType(), "AWS::ECS::Container"); + assertEquals("AWS::ECS::Container", environment.getType()); } @Test public void testGetTypeFromConfig() { String type = faker.letterify("????"); when(config.getServiceType()).thenReturn(Optional.of(type)); - assertEquals(environment.getType(), type); + assertEquals(type, environment.getType()); } @Test @@ -128,7 +128,7 @@ public void testSetFluentBit() { ArgumentCaptor argument = ArgumentCaptor.forClass(String.class); Mockito.verify(config, times(1)).setAgentEndpoint(argument.capture()); assertEquals( - argument.getValue(), "tcp://" + fluentHost + ":" + Constants.DEFAULT_AGENT_PORT); + "tcp://" + fluentHost + ":" + Constants.DEFAULT_AGENT_PORT, argument.getValue()); } @Test @@ -141,13 +141,12 @@ public void testGetLogGroupNameReturnEmpty() { environment.probe(); - assertEquals(environment.getLogGroupName(), ""); + assertEquals("", environment.getLogGroupName()); } @Test public void testGetLogGroupNameReturnNonEmpty() { - - assertEquals(environment.getLogGroupName(), Constants.UNKNOWN + "-metrics"); + assertEquals(Constants.UNKNOWN + "-metrics", environment.getLogGroupName()); } @Test @@ -172,17 +171,16 @@ public void testConfigureContext() throws UnknownHostException { MetricsContext context = new MetricsContext(); environment.configureContext(context); - assertEquals(context.getProperty("containerId"), InetAddress.getLocalHost().getHostName()); - assertEquals(context.getProperty("createdAt"), metadata.getCreatedAt()); - assertEquals(context.getProperty("startedAt"), metadata.getStartedAt()); + assertEquals(InetAddress.getLocalHost().getHostName(), context.getProperty("containerId")); + assertEquals(metadata.getCreatedAt(), context.getProperty("createdAt")); + assertEquals(metadata.getStartedAt(), context.getProperty("startedAt")); assertEquals( - context.getProperty("cluster"), metadata.labels.get("com.amazonaws.ecs.cluster")); + metadata.labels.get("com.amazonaws.ecs.cluster"), context.getProperty("cluster")); assertEquals( - context.getProperty("taskArn"), metadata.labels.get("com.amazonaws.ecs.task-arn")); + metadata.labels.get("com.amazonaws.ecs.task-arn"), context.getProperty("taskArn")); } private void getRandomMetadata(ECSEnvironment.ECSMetadata metadata) { - metadata.createdAt = faker.date().past(1, TimeUnit.DAYS).toString(); metadata.startedAt = faker.date().past(1, TimeUnit.DAYS).toString(); metadata.image = faker.letterify("?????"); diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/environment/LambdaEnvironmentTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/environment/LambdaEnvironmentTest.java index 9d7cf73f..7733662a 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/environment/LambdaEnvironmentTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/environment/LambdaEnvironmentTest.java @@ -47,12 +47,12 @@ public void testGetNameReturnFunctionsName() { String expectedName = faker.name().name(); when(SystemWrapper.getenv("AWS_LAMBDA_FUNCTION_NAME")).thenReturn(expectedName); - assertEquals(lambda.getName(), expectedName); + assertEquals(expectedName, lambda.getName()); } @Test public void testGetTypeReturnCFNLambdaName() { - assertEquals(lambda.getType(), "AWS::Lambda::Function"); + assertEquals("AWS::Lambda::Function", lambda.getType()); } @Test @@ -60,7 +60,7 @@ public void testGetLogGroupNameReturnFunctionName() { String expectedName = faker.name().name(); when(SystemWrapper.getenv("AWS_LAMBDA_FUNCTION_NAME")).thenReturn(expectedName); - assertEquals(lambda.getLogGroupName(), expectedName); + assertEquals(expectedName, lambda.getLogGroupName()); } @Test @@ -78,9 +78,9 @@ public void testConfigureContextAddProperties() { lambda.configureContext(mc); - assertEquals(mc.getProperty("executionEnvironment"), expectedEnv); - assertEquals(mc.getProperty("functionVersion"), expectedVersion); - assertEquals(mc.getProperty("logStreamId"), expectedLogName); + assertEquals(expectedEnv, mc.getProperty("executionEnvironment")); + assertEquals(expectedVersion, mc.getProperty("functionVersion")); + assertEquals(expectedLogName, mc.getProperty("logStreamId")); assertNull(mc.getProperty("traceId")); } @@ -93,7 +93,7 @@ public void testContextWithTraceId() { lambda.configureContext(mc); - assertEquals(mc.getProperty("traceId"), expectedTraceId); + assertEquals(expectedTraceId, mc.getProperty("traceId")); } @Test diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/environment/LocalEnvironmentTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/environment/LocalEnvironmentTest.java index 22a8407f..6705beec 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/environment/LocalEnvironmentTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/environment/LocalEnvironmentTest.java @@ -41,48 +41,46 @@ public void setUp() { @Test public void testProbeReturnFalse() { - assertFalse(environment.probe()); } @Test public void testGetName() { when(config.getServiceName()).thenReturn(Optional.empty()); - assertEquals(environment.getName(), Constants.UNKNOWN); + assertEquals(Constants.UNKNOWN, environment.getName()); String name = faker.letterify("?????"); when(config.getServiceName()).thenReturn(Optional.of(name)); - assertEquals(environment.getName(), name); + assertEquals(name, environment.getName()); } @Test public void testGetType() { when(config.getServiceType()).thenReturn(Optional.empty()); - assertEquals(environment.getType(), Constants.UNKNOWN); + assertEquals(Constants.UNKNOWN, environment.getType()); String type = faker.letterify("?????"); when(config.getServiceType()).thenReturn(Optional.of(type)); - assertEquals(environment.getType(), type); + assertEquals(type, environment.getType()); } @Test public void testGetLogGroupName() { when(config.getLogGroupName()).thenReturn(Optional.empty()); - assertEquals(environment.getLogGroupName(), Constants.UNKNOWN + "-metrics"); + assertEquals(Constants.UNKNOWN + "-metrics", environment.getLogGroupName()); when(config.getLogGroupName()).thenReturn(Optional.empty()); String serviceName = faker.letterify("?????"); when(config.getServiceName()).thenReturn(Optional.of(serviceName)); - assertEquals(environment.getLogGroupName(), serviceName + "-metrics"); + assertEquals(serviceName + "-metrics", environment.getLogGroupName()); String logGroupName = faker.letterify("?????"); when(config.getLogGroupName()).thenReturn(Optional.of(logGroupName)); - assertEquals(environment.getLogGroupName(), logGroupName); + assertEquals(logGroupName, environment.getLogGroupName()); } @Test public void testGetSink() { - assertTrue(environment.getSink() instanceof ConsoleSink); assertSame(environment.getSink(), environment.getSink()); } diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/environment/ResourceFetcherTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/environment/ResourceFetcherTest.java index 92e20f5a..d3fa53bf 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/environment/ResourceFetcherTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/environment/ResourceFetcherTest.java @@ -92,8 +92,8 @@ public void testReadDataWith200Response() { generateStub(200, "{\"name\":\"test\",\"size\":10}"); TestData data = fetcher.fetch(endpoint, TestData.class); - assertEquals(data.name, "test"); - assertEquals(data.size, 10); + assertEquals("test", data.name); + assertEquals(10, data.size); } @Test @@ -107,8 +107,8 @@ public void testReadDataWithHeaders200Response() { verify( getRequestedFor(urlEqualTo(endpoint_path)) .withHeader("X-mock-header-key", equalTo("headerValue"))); - assertEquals(data.name, "test"); - assertEquals(data.size, 10); + assertEquals("test", data.name); + assertEquals(10, data.size); } @Test @@ -120,7 +120,7 @@ public void testWithProvidedMethodAndHeadersWith200Response() { verify( putRequestedFor(urlEqualTo(endpoint_path)) .withHeader("X-mock-header-key", equalTo("headerValue"))); - assertEquals(data, "putResponseData"); + assertEquals("putResponseData", data); } @Test @@ -130,8 +130,8 @@ public void testReadCaseInsensitiveDataWith200Response() { objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); TestData data = fetcher.fetch(endpoint, objectMapper, TestData.class); - assertEquals(data.name, "test"); - assertEquals(data.size, 10); + assertEquals("test", data.name); + assertEquals(10, data.size); } @Test diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/logger/MetricsLoggerTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/logger/MetricsLoggerTest.java index 332fde84..5756dab9 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/logger/MetricsLoggerTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/logger/MetricsLoggerTest.java @@ -58,7 +58,7 @@ public void testPutProperty() { logger.putProperty(propertyName, propertyValue); logger.flush(); - Assert.assertEquals(sink.getContext().getProperty(propertyName), propertyValue); + Assert.assertEquals(propertyValue, sink.getContext().getProperty(propertyName)); } @Test @@ -68,10 +68,10 @@ public void testPutDimension() { logger.putDimensions(DimensionSet.of(dimensionName, dimensionValue)); logger.flush(); - Assert.assertEquals(sink.getContext().getDimensions().size(), 1); + Assert.assertEquals(1, sink.getContext().getDimensions().size()); Assert.assertEquals( - sink.getContext().getDimensions().get(0).getDimensionValue(dimensionName), - dimensionValue); + dimensionValue, + sink.getContext().getDimensions().get(0).getDimensionValue(dimensionName)); } @Test @@ -88,9 +88,9 @@ public void testOverrideDefaultDimensions() { logger.setDimensions(DimensionSet.of(dimensionName, dimensionValue)); logger.flush(); - Assert.assertEquals(sink.getContext().getDimensions().size(), 1); - Assert.assertEquals( - sink.getContext().getDimensions().get(0).getDimensionValue(defaultDimName), null); + Assert.assertEquals(1, sink.getContext().getDimensions().size()); + Assert.assertNull( + sink.getContext().getDimensions().get(0).getDimensionValue(defaultDimName)); } @Test @@ -134,11 +134,11 @@ public void testOverridePreviousDimensions() { logger.setDimensions(DimensionSet.of(dimensionName, dimensionValue)); logger.flush(); - Assert.assertEquals(sink.getContext().getDimensions().size(), 1); - Assert.assertEquals(sink.getContext().getDimensions().get(0).getDimensionKeys().size(), 1); + Assert.assertEquals(1, sink.getContext().getDimensions().size()); + Assert.assertEquals(1, sink.getContext().getDimensions().get(0).getDimensionKeys().size()); Assert.assertEquals( - sink.getContext().getDimensions().get(0).getDimensionValue(dimensionName), - dimensionValue); + dimensionValue, + sink.getContext().getDimensions().get(0).getDimensionValue(dimensionName)); } @Test @@ -163,7 +163,7 @@ public void testSetNamespace() { logger.setNamespace(namespace); logger.flush(); - Assert.assertEquals(sink.getContext().getNamespace(), namespace); + Assert.assertEquals(namespace, sink.getContext().getNamespace()); } @Test @@ -178,7 +178,7 @@ public void testSetTimestamp() { logger.setTimestamp(now); logger.flush(); - Assert.assertEquals(sink.getContext().getTimestamp(), now); + Assert.assertEquals(now, sink.getContext().getTimestamp()); } @Test @@ -249,8 +249,8 @@ public void testNoDefaultDimensions() { logger.flush(); List dimensions = sink.getContext().getDimensions(); - assertTrue(dimensions.size() == 0); - assertTrue(sink.getLogEvents().size() == 1); + assertEquals(0, dimensions.size()); + assertEquals(1, sink.getLogEvents().size()); String logEvent = sink.getLogEvents().get(0); assertTrue(logEvent.contains("\"Dimensions\":[]")); @@ -328,7 +328,7 @@ public void testNoDimensionsAfterSetEmptyDimensionSetWithMultipleFlush() { private void expectDimension(String dimension, String value) { List dimensions = sink.getContext().getDimensions(); - assertEquals(dimensions.size(), 1); - assertEquals(dimensions.get(0).getDimensionValue(dimension), value); + assertEquals(1, dimensions.size()); + assertEquals(value, dimensions.get(0).getDimensionValue(dimension)); } } diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetadataTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetadataTest.java index 3d1c3c1e..a45bdb7f 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetadataTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetadataTest.java @@ -39,9 +39,9 @@ public void testSerializeMetadata() throws JsonProcessingException { Map metadata_map = objectMapper.readValue(output, new TypeReference>() {}); - assertEquals(metadata_map.keySet().size(), 2); - assertEquals(metadata_map.get("Timestamp"), now.toEpochMilli()); - assertEquals(metadata_map.get("CloudWatchMetrics"), new ArrayList()); + assertEquals(2, metadata_map.keySet().size()); + assertEquals(now.toEpochMilli(), metadata_map.get("Timestamp")); + assertEquals(new ArrayList<>(), metadata_map.get("CloudWatchMetrics")); } @Test @@ -59,9 +59,9 @@ public void testSerializeMetadataWithCustomValue() throws JsonProcessingExceptio Map metadata_map = objectMapper.readValue(output, new TypeReference>() {}); - assertEquals(metadata_map.keySet().size(), 3); - assertEquals(metadata_map.get("Timestamp"), now.toEpochMilli()); - assertEquals(metadata_map.get("CloudWatchMetrics"), new ArrayList()); - assertEquals(metadata_map.get(property), expectedValue); + assertEquals(3, metadata_map.keySet().size()); + assertEquals(now.toEpochMilli(), metadata_map.get("Timestamp")); + assertEquals(new ArrayList<>(), metadata_map.get("CloudWatchMetrics")); + assertEquals(expectedValue, metadata_map.get(property)); } } diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricDefinitionTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricDefinitionTest.java index 2524eab4..496262ae 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricDefinitionTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricDefinitionTest.java @@ -20,7 +20,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.Arrays; +import java.util.List; import org.junit.Test; public class MetricDefinitionTest { @@ -36,7 +36,7 @@ public void testSerializeMetricDefinitionWithoutUnit() throws JsonProcessingExce MetricDefinition metricDefinition = new MetricDefinition("Time"); String metricString = objectMapper.writeValueAsString(metricDefinition); - assertEquals(metricString, "{\"Name\":\"Time\",\"Unit\":\"None\"}"); + assertEquals("{\"Name\":\"Time\",\"Unit\":\"None\"}", metricString); } @Test @@ -45,15 +45,15 @@ public void testSerializeMetricDefinition() throws JsonProcessingException { MetricDefinition metricDefinition = new MetricDefinition("Time", Unit.MILLISECONDS, 10); String metricString = objectMapper.writeValueAsString(metricDefinition); - assertEquals(metricString, "{\"Name\":\"Time\",\"Unit\":\"Milliseconds\"}"); + assertEquals("{\"Name\":\"Time\",\"Unit\":\"Milliseconds\"}", metricString); } @Test public void testAddValue() { MetricDefinition md = new MetricDefinition("Time", Unit.MICROSECONDS, 10); - assertEquals(Arrays.asList(10d), md.getValues()); + assertEquals(List.of(10d), md.getValues()); md.addValue(20); - assertEquals(Arrays.asList(10d, 20d), md.getValues()); + assertEquals(List.of(10d, 20d), md.getValues()); } } diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricDirectiveTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricDirectiveTest.java index 31ab8d94..8234f369 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricDirectiveTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricDirectiveTest.java @@ -35,8 +35,8 @@ public void testDefaultNamespace() throws JsonProcessingException { String serializedMetricDirective = objectMapper.writeValueAsString(metricDirective); assertEquals( - serializedMetricDirective, - "{\"Dimensions\":[[]],\"Metrics\":[],\"Namespace\":\"aws-embedded-metrics\"}"); + "{\"Dimensions\":[[]],\"Metrics\":[],\"Namespace\":\"aws-embedded-metrics\"}", + serializedMetricDirective); } @Test @@ -47,8 +47,8 @@ public void testSetNamespace() throws JsonProcessingException { String serializedMetricDirective = objectMapper.writeValueAsString(metricDirective); assertEquals( - serializedMetricDirective, - "{\"Dimensions\":[[]],\"Metrics\":[],\"Namespace\":\"test-lambda-metrics\"}"); + "{\"Dimensions\":[[]],\"Metrics\":[],\"Namespace\":\"test-lambda-metrics\"}", + serializedMetricDirective); } @Test @@ -59,8 +59,8 @@ public void testPutMetric() throws JsonProcessingException { String serializedMetricDirective = objectMapper.writeValueAsString(metricDirective); assertEquals( - serializedMetricDirective, - "{\"Dimensions\":[[]],\"Metrics\":[{\"Name\":\"Time\",\"Unit\":\"None\"}],\"Namespace\":\"aws-embedded-metrics\"}"); + "{\"Dimensions\":[[]],\"Metrics\":[{\"Name\":\"Time\",\"Unit\":\"None\"}],\"Namespace\":\"aws-embedded-metrics\"}", + serializedMetricDirective); } @Test @@ -71,21 +71,21 @@ public void testPutSameMetricMultipleTimes() { assertEquals(1, metricDirective.getAllMetrics().size()); MetricDefinition[] mds = metricDirective.getAllMetrics().toArray(new MetricDefinition[0]); - assertEquals(mds[0].getValues(), Arrays.asList(10d, 20d)); + assertEquals(Arrays.asList(10d, 20d), mds[0].getValues()); } @Test public void testPutMetricWithoutUnit() { MetricDirective metricDirective = new MetricDirective(); metricDirective.putMetric("Time", 10); - assertEquals(metricDirective.getMetrics().get("Time").getUnit(), Unit.NONE); + assertEquals(Unit.NONE, metricDirective.getMetrics().get("Time").getUnit()); } @Test public void testPutMetricWithUnit() { MetricDirective metricDirective = new MetricDirective(); metricDirective.putMetric("Time", 10, Unit.MILLISECONDS); - assertEquals(metricDirective.getMetrics().get("Time").getUnit(), Unit.MILLISECONDS); + assertEquals(Unit.MILLISECONDS, metricDirective.getMetrics().get("Time").getUnit()); } @Test @@ -97,8 +97,8 @@ public void testPutDimensions() throws JsonProcessingException { String serializedMetricDirective = objectMapper.writeValueAsString(metricDirective); assertEquals( - serializedMetricDirective, - "{\"Dimensions\":[[\"Region\",\"Instance\"]],\"Metrics\":[],\"Namespace\":\"aws-embedded-metrics\"}"); + "{\"Dimensions\":[[\"Region\",\"Instance\"]],\"Metrics\":[],\"Namespace\":\"aws-embedded-metrics\"}", + serializedMetricDirective); } @Test @@ -110,8 +110,8 @@ public void testPutDimensionSetWhenMultipleDimensionSets() throws JsonProcessing String serializedMetricDirective = objectMapper.writeValueAsString(metricDirective); assertEquals( - serializedMetricDirective, - "{\"Dimensions\":[[\"Region\"],[\"Instance\"]],\"Metrics\":[],\"Namespace\":\"aws-embedded-metrics\"}"); + "{\"Dimensions\":[[\"Region\"],[\"Instance\"]],\"Metrics\":[],\"Namespace\":\"aws-embedded-metrics\"}", + serializedMetricDirective); } @Test @@ -184,8 +184,8 @@ public void testPutDimensionsWhenDefaultDimensionsDefined() throws JsonProcessin String serializedMetricDirective = objectMapper.writeValueAsString(metricDirective); assertEquals( - serializedMetricDirective, - "{\"Dimensions\":[[\"Version\",\"Region\"],[\"Version\",\"Instance\"]],\"Metrics\":[],\"Namespace\":\"aws-embedded-metrics\"}"); + "{\"Dimensions\":[[\"Version\",\"Region\"],[\"Version\",\"Instance\"]],\"Metrics\":[],\"Namespace\":\"aws-embedded-metrics\"}", + serializedMetricDirective); } @Test @@ -198,7 +198,7 @@ public void testPutDimensionsAfterSetDimensions() throws JsonProcessingException String serializedMetricDirective = objectMapper.writeValueAsString(metricDirective); assertEquals( - serializedMetricDirective, - "{\"Dimensions\":[[\"Version\"],[\"Region\"],[\"Instance\"]],\"Metrics\":[],\"Namespace\":\"aws-embedded-metrics\"}"); + "{\"Dimensions\":[[\"Version\"],[\"Region\"],[\"Instance\"]],\"Metrics\":[],\"Namespace\":\"aws-embedded-metrics\"}", + serializedMetricDirective); } } diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricsContextTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricsContextTest.java index 703a87c5..2b832c02 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricsContextTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/model/MetricsContextTest.java @@ -25,7 +25,6 @@ import com.fasterxml.jackson.databind.json.JsonMapper; import java.time.Instant; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; import org.junit.Test; @@ -100,7 +99,7 @@ public void testSerializeAMetricWith101DataPoints() throws JsonProcessingExcepti expectedValues.add((double) i); } assertEquals(expectedValues, allMetrics.get(0).getValues()); - assertTrue(allMetrics.get(1).getValues().equals(Arrays.asList(100.0))); + assertEquals(List.of(100.0), allMetrics.get(1).getValues()); } @Test @@ -126,10 +125,10 @@ public void testSerializeMetricsWith101DataPoints() throws JsonProcessingExcepti expectedValues.add((double) i); } assertEquals(expectedValues, metricsFromEvent1.get(0).getValues()); - assertEquals(Arrays.asList(2.0), metricsFromEvent1.get(1).getValues()); + assertEquals(List.of(2.0), metricsFromEvent1.get(1).getValues()); assertEquals(1, metricsFromEvent2.size()); - assertEquals(Arrays.asList(100.0), metricsFromEvent2.get(0).getValues()); + assertEquals(List.of(100.0), metricsFromEvent2.get(0).getValues()); } @Test @@ -165,7 +164,7 @@ public void testSetTimestamp() throws JsonProcessingException { Map metadata = (Map) rootNode.get("_aws"); assertTrue(metadata.containsKey("Timestamp")); - assertEquals(metadata.get("Timestamp"), now.toEpochMilli()); + assertEquals(now.toEpochMilli(), metadata.get("Timestamp")); } @SuppressWarnings("unchecked") diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/model/RootNodeTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/model/RootNodeTest.java index 0e91f544..d72e8d71 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/model/RootNodeTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/model/RootNodeTest.java @@ -22,7 +22,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.Arrays; import java.util.List; import java.util.Map; import org.junit.Test; @@ -34,7 +33,7 @@ public void testPutProperty() { RootNode rootNode = new RootNode(); rootNode.putProperty("Property", "Value"); - assertEquals(rootNode.getTargetMembers().get("Property"), "Value"); + assertEquals("Value", rootNode.getTargetMembers().get("Property")); } @Test @@ -43,7 +42,7 @@ public void testPutSamePropertyMultipleTimes() { rootNode.putProperty("Property", "Value"); rootNode.putProperty("Property", "NewValue"); - assertEquals(rootNode.getTargetMembers().get("Property"), "NewValue"); + assertEquals("NewValue", rootNode.getTargetMembers().get("Property")); } @Test @@ -52,7 +51,7 @@ public void testGetDimension() { MetricDirective metricDirective = rootNode.getAws().createMetricDirective(); metricDirective.putDimensionSet(DimensionSet.of("Dim1", "DimValue1")); - assertEquals(rootNode.getTargetMembers().get("Dim1"), "DimValue1"); + assertEquals("DimValue1", rootNode.getTargetMembers().get("Dim1")); } @Test @@ -70,10 +69,10 @@ public void testGetTargetMembers() { mc.putProperty("Prop1", "PropValue1"); - assertEquals(rootNode.getTargetMembers().get("Count"), Arrays.asList(10.0, 20.0)); - assertEquals(rootNode.getTargetMembers().get("Latency"), 100.0); - assertEquals(rootNode.getTargetMembers().get("Dim1"), "DimVal1"); - assertEquals(rootNode.getTargetMembers().get("Prop1"), "PropValue1"); + assertEquals(List.of(10.0, 20.0), rootNode.getTargetMembers().get("Count")); + assertEquals(100.0, rootNode.getTargetMembers().get("Latency")); + assertEquals("DimVal1", rootNode.getTargetMembers().get("Dim1")); + assertEquals("PropValue1", rootNode.getTargetMembers().get("Prop1")); } @SuppressWarnings("unchecked") @@ -92,11 +91,11 @@ public void testSerializeRootNode() throws JsonProcessingException { objectMapper.readValue( emf_logs.get(0), new TypeReference>() {}); - assertEquals(emf_map.keySet().size(), 5); - assertEquals(emf_map.get("Region"), "us-east-1"); - assertEquals(emf_map.get("Property"), "PropertyValue"); - assertEquals(emf_map.get("DefaultDim"), "DefaultDimValue"); - assertEquals(emf_map.get("Count"), 10.0); + assertEquals(5, emf_map.keySet().size()); + assertEquals("us-east-1", emf_map.get("Region")); + assertEquals("PropertyValue", emf_map.get("Property")); + assertEquals("DefaultDimValue", emf_map.get("DefaultDim")); + assertEquals(10.0, emf_map.get("Count")); Map metadata = (Map) emf_map.get("_aws"); assertTrue(metadata.containsKey("Timestamp")); @@ -110,6 +109,6 @@ public void testSerializeRootNodeWithoutAnyMetrics() throws JsonProcessingExcept String value = "bar"; root.putProperty(property, value); - assertEquals(root.serialize(), "{\"foo\":\"bar\"}"); + assertEquals("{\"foo\":\"bar\"}", root.serialize()); } } diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/sinks/AgentSinkTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/sinks/AgentSinkTest.java index 54efb24a..4970ca42 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/sinks/AgentSinkTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/sinks/AgentSinkTest.java @@ -72,10 +72,10 @@ public void testAccept() throws JsonProcessingException { new TypeReference>() {}); Map metadata = (Map) emf_map.get("_aws"); - assertEquals(emf_map.get(prop), propValue); - assertEquals(emf_map.get("Time"), 10.0); - assertEquals(metadata.get("LogGroupName"), logGroupName); - assertEquals(metadata.get("LogStreamName"), logStreamName); + assertEquals(propValue, emf_map.get(prop)); + assertEquals(10.0, emf_map.get("Time")); + assertEquals(logGroupName, metadata.get("LogGroupName")); + assertEquals(logStreamName, metadata.get("LogStreamName")); } @Test diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/sinks/EndpointTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/sinks/EndpointTest.java index 62af645e..77f4de42 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/sinks/EndpointTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/sinks/EndpointTest.java @@ -44,7 +44,7 @@ public void testReturnDefaultEndpointForInvalidURI() { Endpoint endpoint = Endpoint.fromURL(unsupportedEndpoint); Endpoint endpointFromEmptyString = Endpoint.fromURL(""); - assertEquals(endpoint, Endpoint.DEFAULT_TCP_ENDPOINT); - assertEquals(endpointFromEmptyString, Endpoint.DEFAULT_TCP_ENDPOINT); + assertEquals(Endpoint.DEFAULT_TCP_ENDPOINT, endpoint); + assertEquals(Endpoint.DEFAULT_TCP_ENDPOINT, endpointFromEmptyString); } } diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/sinks/ProtocolTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/sinks/ProtocolTest.java index d694c0e4..2e96a66e 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/sinks/ProtocolTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/sinks/ProtocolTest.java @@ -24,16 +24,16 @@ public class ProtocolTest { @Test public void testParseTCP() { - assertEquals(Protocol.getProtocol("TCP"), Protocol.TCP); - assertEquals(Protocol.getProtocol("tcp"), Protocol.TCP); - assertEquals(Protocol.getProtocol("Tcp"), Protocol.TCP); + assertEquals(Protocol.TCP, Protocol.getProtocol("TCP")); + assertEquals(Protocol.TCP, Protocol.getProtocol("tcp")); + assertEquals(Protocol.TCP, Protocol.getProtocol("Tcp")); } @Test public void testParseUDP() { - assertEquals(Protocol.getProtocol("UDP"), Protocol.UDP); - assertEquals(Protocol.getProtocol("udp"), Protocol.UDP); - assertEquals(Protocol.getProtocol("Udp"), Protocol.UDP); + assertEquals(Protocol.UDP, Protocol.getProtocol("UDP")); + assertEquals(Protocol.UDP, Protocol.getProtocol("udp")); + assertEquals(Protocol.UDP, Protocol.getProtocol("Udp")); } @Test(expected = IllegalArgumentException.class) diff --git a/src/test/java/software/amazon/cloudwatchlogs/emf/util/IOUtilsTest.java b/src/test/java/software/amazon/cloudwatchlogs/emf/util/IOUtilsTest.java index 8b6170c0..662e9497 100644 --- a/src/test/java/software/amazon/cloudwatchlogs/emf/util/IOUtilsTest.java +++ b/src/test/java/software/amazon/cloudwatchlogs/emf/util/IOUtilsTest.java @@ -36,7 +36,7 @@ public void testToString() throws IOException { String str = faker.letterify("?????"); ByteArrayInputStream is = new ByteArrayInputStream(str.getBytes()); - assertEquals(IOUtils.toString(is), str); + assertEquals(str, IOUtils.toString(is)); } @Test @@ -44,7 +44,7 @@ public void testToByteArray() throws IOException { String str = faker.letterify("?????"); ByteArrayInputStream is = new ByteArrayInputStream(str.getBytes()); - assertArrayEquals(IOUtils.toByteArray(is), str.getBytes()); + assertArrayEquals(str.getBytes(), IOUtils.toByteArray(is)); } @Test