-
Notifications
You must be signed in to change notification settings - Fork 1k
Convert groovy config tests to java #14912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e7a2b6b
convert to java
zeitlinger 2e9eb2c
convert to java
zeitlinger aaa1833
convert to java
zeitlinger 5fd6bf1
convert to java
zeitlinger 05fc07b
convert to java
zeitlinger 3e34eb3
fix
zeitlinger f230cb5
fix
zeitlinger 2b94192
remove now unused and unmaintained lib
zeitlinger 626b489
review
laurit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 0 additions & 90 deletions
90
...ng/src/test/groovy/io/opentelemetry/javaagent/tooling/config/ConfigurationFileTest.groovy
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
...st/groovy/io/opentelemetry/javaagent/tooling/config/MethodsConfigurationParserTest.groovy
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
...c/test/java/io/opentelemetry/javaagent/tooling/config/MethodsConfigurationParserTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.tooling.config; | ||
|
|
||
| import static java.util.Collections.emptyMap; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.stream.Stream; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| class MethodsConfigurationParserTest { | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("configurationTestData") | ||
| void testConfiguration(String value, Map<String, Set<String>> expected) { | ||
| Map<String, Set<String>> result = MethodsConfigurationParser.parse(value); | ||
|
|
||
| assertThat(result).isEqualTo(expected); | ||
| } | ||
|
|
||
| static Stream<Arguments> configurationTestData() { | ||
| return Stream.of( | ||
| Arguments.of(null, emptyMap()), | ||
| Arguments.of(" ", emptyMap()), | ||
| Arguments.of( | ||
| "some.package.ClassName", | ||
| Collections.<String, Set<String>>singletonMap( | ||
| "some.package.ClassName", Collections.emptySet())), | ||
| Arguments.of("some.package.ClassName[ , ]", emptyMap()), | ||
| Arguments.of("some.package.ClassName[ , method]", emptyMap()), | ||
| Arguments.of( | ||
| "some.package.Class$Name[ method , ]", | ||
| Collections.singletonMap("some.package.Class$Name", createSet("method"))), | ||
| Arguments.of( | ||
| "ClassName[ method1,]", Collections.singletonMap("ClassName", createSet("method1"))), | ||
| Arguments.of( | ||
| "ClassName[method1 , method2]", | ||
| Collections.singletonMap("ClassName", createSet("method1", "method2"))), | ||
| Arguments.of( | ||
| "Class$1[method1 ] ; Class$2[ method2];", | ||
| createTwoEntryMap("Class$1", createSet("method1"), "Class$2", createSet("method2"))), | ||
| Arguments.of( | ||
| "Duplicate[method1] ; Duplicate[method2] ;Duplicate[method3];", | ||
| Collections.singletonMap("Duplicate", createSet("method3")))); | ||
| } | ||
|
|
||
| private static Map<String, Set<String>> createTwoEntryMap( | ||
| String key1, Set<String> value1, String key2, Set<String> value2) { | ||
| Map<String, Set<String>> map = new HashMap<>(); | ||
| map.put(key1, value1); | ||
| map.put(key2, value2); | ||
| return map; | ||
| } | ||
|
|
||
| private static Set<String> createSet(String... elements) { | ||
| Set<String> set = new HashSet<>(); | ||
| for (String element : elements) { | ||
| set.add(element); | ||
| } | ||
| return set; | ||
| } | ||
| } |
90 changes: 90 additions & 0 deletions
90
.../testConfigFile/java/io/opentelemetry/javaagent/tooling/config/ConfigurationFileTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.tooling.config; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.io.OutputStreamWriter; | ||
| import java.io.Writer; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.util.Map; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
| import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; | ||
| import uk.org.webcompere.systemstubs.jupiter.SystemStub; | ||
| import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; | ||
| import uk.org.webcompere.systemstubs.properties.SystemProperties; | ||
|
|
||
| @ExtendWith(SystemStubsExtension.class) | ||
| class ConfigurationFileTest { | ||
|
|
||
| @TempDir File tmpDir; | ||
|
|
||
| @SystemStub private EnvironmentVariables environmentVariables; | ||
|
|
||
| @SystemStub private SystemProperties systemProperties; | ||
|
|
||
| @Test | ||
| void shouldUseEnvVar() throws IOException { | ||
| String path = createFile("config", "property1=val-env"); | ||
| environmentVariables.set("OTEL_JAVAAGENT_CONFIGURATION_FILE", path); | ||
|
|
||
| Map<String, String> properties = ConfigurationFile.loadConfigFile(); | ||
|
|
||
| assertThat(properties).containsEntry("property1", "val-env"); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldUseSystemProperty() throws IOException { | ||
| String path = createFile("config", "property1=val-sys"); | ||
| systemProperties.set("otel.javaagent.configuration-file", path); | ||
|
|
||
| Map<String, String> properties = ConfigurationFile.loadConfigFile(); | ||
|
|
||
| assertThat(properties).containsEntry("property1", "val-sys"); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldUseSystemPropertyOverEnvVar() throws IOException { | ||
| String pathEnv = createFile("configEnv", "property1=val-env"); | ||
| String path = createFile("config", "property1=val-sys"); | ||
| systemProperties.set("otel.javaagent.configuration-file", path); | ||
| environmentVariables.set("OTEL_JAVAAGENT_CONFIGURATION_FILE", pathEnv); | ||
|
|
||
| Map<String, String> properties = ConfigurationFile.loadConfigFile(); | ||
|
|
||
| assertThat(properties).containsEntry("property1", "val-sys"); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldReturnEmptyPropertiesIfFileDoesNotExist() { | ||
| systemProperties.set("otel.javaagent.configuration-file", "somePath"); | ||
|
|
||
| Map<String, String> properties = ConfigurationFile.loadConfigFile(); | ||
|
|
||
| assertThat(properties).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldReturnEmptyPropertiesIfPropertyIsNotSet() { | ||
| Map<String, String> properties = ConfigurationFile.loadConfigFile(); | ||
|
|
||
| assertThat(properties).isEmpty(); | ||
| } | ||
|
|
||
| private String createFile(String name, String contents) throws IOException { | ||
| File file = new File(tmpDir, name); | ||
| try (Writer writer = | ||
| new OutputStreamWriter(Files.newOutputStream(file.toPath()), StandardCharsets.UTF_8)) { | ||
| writer.write(contents); | ||
| } | ||
| return file.getAbsolutePath(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.