This is an automated email from the ASF dual-hosted git repository.

jbertram pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new 304eb7ae6d ARTEMIS-5347 fix a few things for env vars in bootstrap.xml
304eb7ae6d is described below

commit 304eb7ae6d78d154fd3474b25d169bd5e40250c1
Author: Justin Bertram <[email protected]>
AuthorDate: Wed Mar 12 09:11:32 2025 -0500

    ARTEMIS-5347 fix a few things for env vars in bootstrap.xml
---
 .../org/apache/activemq/artemis/dto/XmlUtil.java   |  3 ++-
 .../apache/activemq/artemis/dto/XmlUtilTest.java   | 29 ++++++++++++++++++----
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git 
a/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/XmlUtil.java 
b/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/XmlUtil.java
index 60f9bfe4ea..bd0d71b55d 100644
--- a/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/XmlUtil.java
+++ b/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/XmlUtil.java
@@ -94,8 +94,9 @@ public class XmlUtil {
          "http://apache.org/xml/features/validation/schema-full-checking";, 
false));
       unmarshaller.setSchema(schema);
 
-      Properties props = new Properties(System.getProperties());
+      Properties props = new Properties();
       props.putAll(System.getenv());
+      props.putAll(System.getProperties());
       if (artemisHome != null) {
          props.put("artemis.home", artemisHome);
       }
diff --git 
a/artemis-dto/src/test/java/org/apache/activemq/artemis/dto/XmlUtilTest.java 
b/artemis-dto/src/test/java/org/apache/activemq/artemis/dto/XmlUtilTest.java
index b629ba02d7..c2dac26130 100644
--- a/artemis-dto/src/test/java/org/apache/activemq/artemis/dto/XmlUtilTest.java
+++ b/artemis-dto/src/test/java/org/apache/activemq/artemis/dto/XmlUtilTest.java
@@ -20,23 +20,43 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.StandardOpenOption;
 
+import org.apache.activemq.artemis.tests.util.ArtemisTestCase;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-public class XmlUtilTest {
+public class XmlUtilTest extends ArtemisTestCase {
 
    @Test
    public void testPropertySubstituion(@TempDir Path tempDir) throws Exception 
{
-      final String SYSTEM_PROP_NAME = "sysPropName";
-      final String SYSTEM_PROP_VALUE = "sysPropValue";
+      final String SYSTEM_PROP_NAME = getTestMethodName() + "SysPropName";
+      final String SYSTEM_PROP_VALUE = getTestMethodName() + "SysPropValue";
       System.setProperty(SYSTEM_PROP_NAME, SYSTEM_PROP_VALUE);
 
       // since System.getenv() returns an immutable Map we rely here on an 
environment variable that is likely to exist
       final String ENV_VAR_NAME = "HOME";
 
+      BrokerDTO brokerDTO = getBrokerDTO(tempDir, SYSTEM_PROP_NAME, 
ENV_VAR_NAME);
+      assertEquals(SYSTEM_PROP_VALUE, 
((JaasSecurityDTO)brokerDTO.security).domain);
+      assertEquals(System.getenv(ENV_VAR_NAME), 
brokerDTO.server.configuration);
+   }
+
+   @Test
+   public void testPropertySubstituionPrecedence(@TempDir Path tempDir) throws 
Exception {
+      final String SYSTEM_PROP_NAME = "HOME";
+      final String SYSTEM_PROP_VALUE = getTestMethodName() + "SysPropValue";
+      System.setProperty(SYSTEM_PROP_NAME, SYSTEM_PROP_VALUE);
+
+      final String ENV_VAR_NAME = SYSTEM_PROP_NAME;
+
+      BrokerDTO brokerDTO = getBrokerDTO(tempDir, SYSTEM_PROP_NAME, 
ENV_VAR_NAME);
+      assertEquals(SYSTEM_PROP_VALUE, 
((JaasSecurityDTO)brokerDTO.security).domain);
+      assertEquals(SYSTEM_PROP_VALUE, brokerDTO.server.configuration);
+   }
+
+   private static BrokerDTO getBrokerDTO(Path tempDir, String 
SYSTEM_PROP_NAME, String ENV_VAR_NAME) throws Exception {
       String data = """
          <broker xmlns="http://activemq.apache.org/schema";>
             <jaas-security domain="${%s}"/>
@@ -49,7 +69,6 @@ public class XmlUtilTest {
       assertTrue(Files.exists(tempFile));
 
       BrokerDTO brokerDTO = XmlUtil.decode(BrokerDTO.class, tempFile.toFile());
-      assertEquals(SYSTEM_PROP_VALUE, 
((JaasSecurityDTO)brokerDTO.security).domain);
-      assertEquals(System.getenv(ENV_VAR_NAME), 
brokerDTO.server.configuration);
+      return brokerDTO;
    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to