You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/03/07 14:01:11 UTC

[camel] branch master updated: CAMEL-13297 Pick env: variable at random for test

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

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new a612d51  CAMEL-13297 Pick env: variable at random for test
a612d51 is described below

commit a612d516c7994d39951aa7e93034a772d2c346f8
Author: Marc Carter <dr...@gmail.com>
AuthorDate: Thu Mar 7 12:15:38 2019 +0000

    CAMEL-13297 Pick env: variable at random for test
    
    Was assuming JAVA_HOME exists which is standard but not mandatory.
---
 .../PropertiesComponentDefaultFunctionsTest.java       | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDefaultFunctionsTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDefaultFunctionsTest.java
index 3897d34..2f320b9 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDefaultFunctionsTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDefaultFunctionsTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.properties;
 
+import java.util.Map;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.Test;
@@ -27,25 +29,33 @@ public class PropertiesComponentDefaultFunctionsTest extends ContextTestSupport
         return false;
     }
 
+    private static Map.Entry<String, String> anyNonEmptyEnvironmentVariable() {
+        for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
+            if (entry.getValue() != null && !"".equals(entry.getValue())) {
+                return entry;
+            }
+        }
+        throw new IllegalStateException();
+    }
+
     @Test
     public void testFunction() throws Exception {
         System.setProperty("FOO", "mock:foo");
+        Map.Entry<String, String> env = anyNonEmptyEnvironmentVariable();
 
         context.addRoutes(new RouteBuilder() {
             @Override
             public void configure() throws Exception {
                 from("direct:start")
                         .to("{{sys:FOO}}")
-                        .transform().constant("{{env:JAVA_HOME}}")
+                        .transform().constant("{{env:" + env.getKey() + "}}")
                         .to("mock:bar");
             }
         });
         context.start();
 
-        String body = System.getenv("JAVA_HOME");
-
         getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
-        getMockEndpoint("mock:bar").expectedBodiesReceived(body);
+        getMockEndpoint("mock:bar").expectedBodiesReceived(env.getValue());
 
         template.sendBody("direct:start", "Hello World");