Skip to content

Commit b02bdfa

Browse files
committed
Add unit tests for ua interceptor in logging modules.
1 parent 43cfca2 commit b02bdfa

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

powertools-logging/powertools-logging-log4j/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@
9898
<type>test-jar</type>
9999
<scope>test</scope>
100100
</dependency>
101+
<dependency>
102+
<groupId>software.amazon.awssdk</groupId>
103+
<artifactId>s3</artifactId>
104+
<scope>test</scope>
105+
</dependency>
101106
</dependencies>
102107
<profiles>
103108
<profile>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates.
3+
* Licensed under the Apache License, Version 2.0 (the
4+
* "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*
13+
*/
14+
package software.amazon.lambda.powertools.logging.log4j.internal;
15+
16+
import org.junit.jupiter.api.Test;
17+
import software.amazon.awssdk.services.s3.S3Client;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
21+
class Log4jUserAgentInterceptorTest {
22+
23+
@Test
24+
void shouldConfigureUserAgentWhenCreatingAwsSdkClient() {
25+
// WHEN creating an AWS SDK client, the interceptor should be loaded
26+
// We use S3 client but it can be any arbitrary AWS SDK client
27+
S3Client.builder().build();
28+
29+
// THEN the user agent system property should be set
30+
String userAgent = System.getProperty("sdk.ua.appId");
31+
assertThat(userAgent).contains("PT/LOGGING-LOG4J/");
32+
}
33+
}

powertools-logging/powertools-logging-logback/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@
9595
<artifactId>junit-pioneer</artifactId>
9696
<scope>test</scope>
9797
</dependency>
98+
<dependency>
99+
<groupId>software.amazon.awssdk</groupId>
100+
<artifactId>s3</artifactId>
101+
<scope>test</scope>
102+
</dependency>
98103
</dependencies>
99104

100105
<profiles>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates.
3+
* Licensed under the Apache License, Version 2.0 (the
4+
* "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*
13+
*/
14+
package software.amazon.lambda.powertools.logging.logback.internal;
15+
16+
import org.junit.jupiter.api.Test;
17+
import software.amazon.awssdk.services.s3.S3Client;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
21+
class LogbackUserAgentInterceptorTest {
22+
23+
@Test
24+
void shouldConfigureUserAgentWhenCreatingAwsSdkClient() {
25+
// WHEN creating an AWS SDK client, the interceptor should be loaded
26+
// We use S3 client but it can be any arbitrary AWS SDK client
27+
S3Client.builder().build();
28+
29+
// THEN the user agent system property should be set
30+
String userAgent = System.getProperty("sdk.ua.appId");
31+
assertThat(userAgent).contains("PT/LOGGING-LOGBACK/");
32+
}
33+
}

0 commit comments

Comments
 (0)