BUG-5006: Reduce usage of PowerMock
[ovsdb.git] / utils / config / src / main / java / org / opendaylight / ovsdb / utils / config / ConfigProperties.java
index 6cdb99283e3a61c8634bfc6a5301fb9cf16a6658..6017cc292478b852b353367abdac7e4dfb92a44f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015 Red Hat, Inc. and others.  All rights reserved.
+ * Copyright (c) 2014, 2016 Red Hat, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -8,12 +8,17 @@
 
 package org.opendaylight.ovsdb.utils.config;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.FrameworkUtil;
 
 public final class ConfigProperties {
 
+    private static final Map<String, String> OVERRIDES = new HashMap<>();
+
     private ConfigProperties() {
         // empty
     }
@@ -23,7 +28,11 @@ public final class ConfigProperties {
     }
 
     public static String getProperty(Class<?> classParam, final String propertyStr, final String defaultValue) {
-        String value = null;
+        String value = ConfigProperties.OVERRIDES.get(propertyStr);
+        if (value != null) {
+            return value;
+        }
+
         Bundle bundle = FrameworkUtil.getBundle(classParam);
 
         if (bundle != null) {
@@ -35,6 +44,15 @@ public final class ConfigProperties {
         if (value == null) {
             value = System.getProperty(propertyStr, defaultValue);
         }
+
+        if (value == null) {
+            System.err.println("ConfigProperties missing a value for " + propertyStr);
+        }
+
         return value;
     }
+
+    public static void overrideProperty(String property, String value) {
+        ConfigProperties.OVERRIDES.put(property, value);
+    }
 }