diff options
2 files changed, 51 insertions, 16 deletions
diff --git a/sdnr/wt/devicemanager-core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/config/VESCollectorCfgImpl.java b/sdnr/wt/devicemanager-core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/config/VESCollectorCfgImpl.java index 105b915c7..0e88b8435 100644 --- a/sdnr/wt/devicemanager-core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/config/VESCollectorCfgImpl.java +++ b/sdnr/wt/devicemanager-core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/vescollectorconnector/impl/config/VESCollectorCfgImpl.java @@ -31,31 +31,37 @@ public class VESCollectorCfgImpl implements VESCollectorCfgService, Configuratio /** set to true if VES Collector is installed and configured */ private static final String PROPERTY_KEY_VES_COLLECTOR_ENABLED = "VES_COLLECTOR_ENABLED"; - private static final boolean DEFAULT_VALUE_VES_COLLECTOR_ENABLED = false; + private static final String DEFAULT_VALUE_VES_COLLECTOR_ENABLED = "${SDNR_VES_COLLECTOR_ENABLED}"; private static final String PROPERTY_KEY_VES_COLLECTOR_IP = "VES_COLLECTOR_IP"; - private static final String DEFAULT_VALUE_VES_COLLECTOR_IP = "127.0.0.1"; + private static final String DEFAULT_VALUE_VES_COLLECTOR_IP = "${SDNR_VES_COLLECTOR_IP}"; private static final String PROPERTY_KEY_VES_COLLECTOR_PORT = "VES_COLLECTOR_PORT"; - private static final String DEFAULT_VALUE_VES_COLLECTOR_PORT = "8080"; + private static final String DEFAULT_VALUE_VES_COLLECTOR_PORT = "${SDNR_VES_COLLECTOR_PORT}"; private static final String PROPERTY_KEY_VES_COLLECTOR_TLS_ENABLED = "VES_COLLECTOR_TLS_ENABLED"; + private static final String DEFAULT_VALUE_VES_COLLECTOR_TLS_ENABLED = "${SDNR_VES_COLLECTOR_TLS_ENABLED}"; + private static final String PROPERTY_KEY_VES_COLLECTOR_TRUST_ALL_CERTS = "VES_COLLECTOR_TRUST_ALL_CERTS"; + private static final String DEFAULT_VALUE_VES_COLLECTOR_TRUST_ALL_CERTS = "${SDNR_VES_COLLECTOR_TRUST_ALL_CERTS}"; private static final String PROPERTY_KEY_VES_COLLECTOR_USERNAME = "VES_COLLECTOR_USERNAME"; - private static final String DEFAULT_VALUE_VES_COLLECTOR_USERNAME = "sample1"; + private static final String DEFAULT_VALUE_VES_COLLECTOR_USERNAME = "${SDNR_VES_COLLECTOR_USERNAME}"; private static final String PROPERTY_KEY_VES_COLLECTOR_PASSWORD = "VES_COLLECTOR_PASSWORD"; - private static final String DEFAULT_VALUE_VES_COLLECTOR_PASSWORD = "sample1"; + private static final String DEFAULT_VALUE_VES_COLLECTOR_PASSWORD = "${SDNR_VES_COLLECTOR_PASSWORD}"; private static final String PROPERTY_KEY_VES_COLLECTOR_VERSION = "VES_COLLECTOR_VERSION"; - private static final String DEFAULT_VALUE_VES_COLLECTOR_VERSION = "v7"; + private static final String DEFAULT_VALUE_VES_COLLECTOR_VERSION = "${SDNR_VES_COLLECTOR_VERSION}"; + private static final String DEFAULT_VALUE_VES_COLLECTOR_VERSION_NA = "v7"; private static final String PROPERTY_KEY_REPORTING_ENTITY_NAME = "REPORTING_ENTITY_NAME"; - private static final String DEFAULT_VALUE_REPORTING_ENTITY_NAME = "ONAP SDN-R"; + private static final String DEFAULT_VALUE_REPORTING_ENTITY_NAME = "${SDNR_VES_COLLECTOR_REPORTING_ENTITY_NAME}"; + private static final String DEFAULT_VALUE_REPORTING_ENTITY_NAME_NA = "ONAP SDN-R"; private static final String PROPERTY_KEY_EVENTLOG_DETAIL = "EVENTLOG_MSG_DETAIL"; - private static final String DEFAULT_VALUE_EVENTLOG_DETAIL = "SHORT"; // "SHORT", "MEDIUM", "LONG" + private static final String DEFAULT_VALUE_EVENTLOG_DETAIL = "${SDNR_VES_COLLECTOR_EVENTLOG_MSG_DETAIL}"; + private static final String DEFAULT_VALUE_EVENTLOG_DETAIL_NA = "SHORT"; // "SHORT", "MEDIUM", "LONG" private static ConfigurationFileRepresentation configuration; @@ -73,12 +79,14 @@ public class VESCollectorCfgImpl implements VESCollectorCfgService, Configuratio @Override public String getReportingEntityName() { - return configuration != null ? configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_REPORTING_ENTITY_NAME) : "ONAP SDN-R"; + String v = configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_REPORTING_ENTITY_NAME); + return (v == null || v.isBlank()) ? DEFAULT_VALUE_REPORTING_ENTITY_NAME_NA : v; } @Override public String getEventLogMsgDetail() { - return configuration != null ?configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_EVENTLOG_DETAIL) : DEFAULT_VALUE_EVENTLOG_DETAIL; + String v = configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_EVENTLOG_DETAIL); + return (v == null || v.isBlank()) ? DEFAULT_VALUE_EVENTLOG_DETAIL_NA : v; } @Override @@ -107,7 +115,8 @@ public class VESCollectorCfgImpl implements VESCollectorCfgService, Configuratio } public String getVersion() { - return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_VERSION); + String v = configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_VERSION); + return (v == null || v.isBlank()) ? DEFAULT_VALUE_VES_COLLECTOR_VERSION_NA : v; } public boolean isTrustAllCerts() { @@ -116,9 +125,12 @@ public class VESCollectorCfgImpl implements VESCollectorCfgService, Configuratio @Override public synchronized void defaults() { - configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_ENABLED, DEFAULT_VALUE_VES_COLLECTOR_ENABLED); - configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_TLS_ENABLED, Boolean.FALSE); - configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_TRUST_ALL_CERTS, Boolean.FALSE); + configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_ENABLED, + DEFAULT_VALUE_VES_COLLECTOR_ENABLED); + configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_TLS_ENABLED, + DEFAULT_VALUE_VES_COLLECTOR_TLS_ENABLED); + configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_TRUST_ALL_CERTS, + DEFAULT_VALUE_VES_COLLECTOR_TRUST_ALL_CERTS); configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_USERNAME, DEFAULT_VALUE_VES_COLLECTOR_USERNAME); configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_VES_COLLECTOR_PASSWORD, diff --git a/sdnr/wt/devicemanager-core/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestVESCollectorClient.java b/sdnr/wt/devicemanager-core/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestVESCollectorClient.java index 1ff8efafb..9198e84fe 100644 --- a/sdnr/wt/devicemanager-core/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestVESCollectorClient.java +++ b/sdnr/wt/devicemanager-core/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestVESCollectorClient.java @@ -21,16 +21,20 @@ */ package org.onap.ccsdk.features.sdnr.wt.devicemanager.test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import com.google.common.io.Files; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.charset.StandardCharsets; import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESMessage; import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.VESCollectorServiceImpl; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.config.VESCollectorCfgImpl; public class TestVESCollectorClient { @@ -44,6 +48,7 @@ public class TestVESCollectorClient { private static final VESMessage message = new VESMessage("Test Message"); private static final String CONFIG_FILE = "test.properties"; + private static final String CONFIG_FILE2 = "test2.properties"; @Test public void testNoAuth() throws Exception { @@ -72,10 +77,26 @@ public class TestVESCollectorClient { vesClient.close(); } + @Test + public void testDefaultConfigValues() throws IOException { + Files.asCharSink(new File(CONFIG_FILE2), StandardCharsets.UTF_8).write(""); + ConfigurationFileRepresentation cfg = new ConfigurationFileRepresentation(CONFIG_FILE2); + VESCollectorCfgImpl vesConfig = new VESCollectorCfgImpl(cfg); + assertEquals("ONAP SDN-R", vesConfig.getReportingEntityName()); + assertEquals("SHORT", vesConfig.getEventLogMsgDetail()); + assertEquals("v7",vesConfig.getVersion()); + assertFalse(vesConfig.isVESCollectorEnabled()); + assertFalse(vesConfig.isTrustAllCerts()); + + } + + + @Before @After public void after() throws InterruptedException, IOException { delete(new File(CONFIG_FILE)); + delete(new File(CONFIG_FILE2)); } @@ -85,8 +106,10 @@ public class TestVESCollectorClient { delete(c); } } - if (!f.delete()) { - throw new FileNotFoundException("Failed to delete file: " + f); + if(f.exists()) { + if (!f.delete()) { + throw new FileNotFoundException("Failed to delete file: " + f); + } } } } |