Skip to content

Commit 01d08e1

Browse files
committed
Fix README and add test for MP Config Provider
1 parent 85bf672 commit 01d08e1

File tree

4 files changed

+138
-3
lines changed

4 files changed

+138
-3
lines changed

integrations/microprofile-config/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,18 @@ The `MicroProfileConfigProvider` implementation:
6363
```
6464
MicroProfile Config Sources (application.properties, env vars, -D flags)
6565
↓ (not found?)
66-
META-INF/a2a-defaults.properties (from server-common)
67-
↓ (not found?)
68-
META-INF/a2a-defaults.properties (from extras modules)
66+
DefaultValuesConfigProvider
67+
→ Scans classpath for ALL META-INF/a2a-defaults.properties files
68+
→ Merges all discovered properties together
69+
→ Throws exception if duplicate keys found
70+
↓ (property exists?)
71+
Return merged default value
6972
↓ (not found?)
7073
IllegalArgumentException
7174
```
7275

76+
**Note**: All `META-INF/a2a-defaults.properties` files (from server-common, extras modules, etc.) are loaded and merged together by `DefaultValuesConfigProvider` at startup. This is not a sequential fallback chain, but a single merged set of defaults.
77+
7378
## Available Configuration Properties
7479

7580
See the [main README](../../README.md#configuration-system) for a complete list of configuration properties.

integrations/microprofile-config/pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,22 @@
3838
<groupId>org.slf4j</groupId>
3939
<artifactId>slf4j-api</artifactId>
4040
</dependency>
41+
42+
<!-- Test dependencies -->
43+
<dependency>
44+
<groupId>io.quarkus</groupId>
45+
<artifactId>quarkus-arc</artifactId>
46+
<scope>test</scope>
47+
</dependency>
48+
<dependency>
49+
<groupId>io.quarkus</groupId>
50+
<artifactId>quarkus-junit5</artifactId>
51+
<scope>test</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.junit.jupiter</groupId>
55+
<artifactId>junit-jupiter-api</artifactId>
56+
<scope>test</scope>
57+
</dependency>
4158
</dependencies>
4259
</project>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package io.a2a.integrations.microprofile;
2+
3+
import io.a2a.server.config.A2AConfigProvider;
4+
import io.quarkus.test.junit.QuarkusTest;
5+
import jakarta.inject.Inject;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.util.Optional;
9+
10+
import static org.junit.jupiter.api.Assertions.*;
11+
12+
/**
13+
* CDI-based test to verify that MicroProfileConfigProvider is properly selected
14+
* and works correctly with MicroProfile Config and fallback to defaults.
15+
*/
16+
@QuarkusTest
17+
public class MicroProfileConfigProviderTest {
18+
19+
@Inject
20+
A2AConfigProvider configProvider;
21+
22+
@Test
23+
public void testIsMicroProfileConfigProvider() {
24+
// Verify that when microprofile-config module is on classpath,
25+
// the injected A2AConfigProvider is the MicroProfile implementation
26+
assertInstanceOf(MicroProfileConfigProvider.class, configProvider,
27+
"A2AConfigProvider should be MicroProfileConfigProvider when module is present");
28+
}
29+
30+
@Test
31+
public void testGetValueFromMicroProfileConfig() {
32+
// Test that values from application.properties override defaults
33+
// The test application.properties sets a2a.executor.core-pool-size=15
34+
String value = configProvider.getValue("a2a.executor.core-pool-size");
35+
assertEquals("15", value, "Should get value from MicroProfile Config (application.properties)");
36+
}
37+
38+
@Test
39+
public void testGetValueFallbackToDefaults() {
40+
// Test that values not in application.properties fall back to META-INF/a2a-defaults.properties
41+
// a2a.executor.max-pool-size is not in test application.properties, so should use default
42+
String value = configProvider.getValue("a2a.executor.max-pool-size");
43+
assertEquals("50", value, "Should fall back to default value from META-INF/a2a-defaults.properties");
44+
}
45+
46+
@Test
47+
public void testGetValueAnotherDefault() {
48+
// Test another default property to ensure fallback works
49+
String value = configProvider.getValue("a2a.executor.keep-alive-seconds");
50+
assertEquals("60", value, "Should fall back to default value");
51+
}
52+
53+
@Test
54+
public void testGetOptionalValueFromMicroProfileConfig() {
55+
// Test optional value that exists in application.properties
56+
Optional<String> value = configProvider.getOptionalValue("a2a.executor.core-pool-size");
57+
assertTrue(value.isPresent(), "Optional value should be present");
58+
assertEquals("15", value.get(), "Should get overridden value from MicroProfile Config");
59+
}
60+
61+
@Test
62+
public void testGetOptionalValueFallbackToDefaults() {
63+
// Test optional value that falls back to defaults
64+
Optional<String> value = configProvider.getOptionalValue("a2a.executor.max-pool-size");
65+
assertTrue(value.isPresent(), "Optional value should be present from defaults");
66+
assertEquals("50", value.get(), "Should get default value");
67+
}
68+
69+
@Test
70+
public void testGetOptionalValueNotFound() {
71+
// Test optional value that doesn't exist anywhere
72+
Optional<String> value = configProvider.getOptionalValue("non.existent.property");
73+
assertFalse(value.isPresent(), "Optional value should be empty for non-existent property");
74+
}
75+
76+
@Test
77+
public void testGetValueThrowsForNonExistent() {
78+
// Test that required getValue() throws for non-existent property
79+
assertThrows(IllegalArgumentException.class,
80+
() -> configProvider.getValue("non.existent.property"),
81+
"Should throw IllegalArgumentException for non-existent required property");
82+
}
83+
84+
@Test
85+
public void testSystemPropertyOverride() {
86+
// System properties should have higher priority than application.properties
87+
// Set a system property and verify it's used
88+
String originalValue = System.getProperty("a2a.test.system.property");
89+
try {
90+
System.setProperty("a2a.test.system.property", "from-system-property");
91+
String value = configProvider.getValue("a2a.test.system.property");
92+
assertEquals("from-system-property", value,
93+
"System property should override application.properties");
94+
} finally {
95+
if (originalValue != null) {
96+
System.setProperty("a2a.test.system.property", originalValue);
97+
} else {
98+
System.clearProperty("a2a.test.system.property");
99+
}
100+
}
101+
}
102+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Test configuration for MicroProfileConfigProviderTest
2+
# This overrides the default value to verify MicroProfile Config integration works
3+
4+
# Override default value (default is 5)
5+
a2a.executor.core-pool-size=15
6+
7+
# Note: a2a.executor.max-pool-size is NOT set here to test fallback to defaults
8+
# Default value should be 50 from META-INF/a2a-defaults.properties
9+
10+
# Exclude beans that aren't needed for config testing
11+
quarkus.arc.exclude-types=io.a2a.server.requesthandlers.*,io.a2a.server.agentexecution.*,io.a2a.server.tasks.*,io.a2a.server.events.*,io.a2a.server.util.*

0 commit comments

Comments
 (0)