diff options
Diffstat (limited to 'core/utils/provider/src/test')
-rw-r--r-- | core/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/common/EnvPropertiesTest.java | 59 | ||||
-rw-r--r-- | core/utils/provider/src/test/resources/svclogic.properties | 27 |
2 files changed, 86 insertions, 0 deletions
diff --git a/core/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/common/EnvPropertiesTest.java b/core/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/common/EnvPropertiesTest.java new file mode 100644 index 000000000..bee432577 --- /dev/null +++ b/core/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/common/EnvPropertiesTest.java @@ -0,0 +1,59 @@ +package org.onap.ccsdk.sli.core.utils.common; + +import static org.junit.Assert.*; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Properties; + +import org.junit.Before; +import org.junit.Test; + +public class EnvPropertiesTest { + + @Test + public void loadStreamTest() throws IOException { + InputStream testStr = getClass().getResourceAsStream("/svclogic.properties"); + + Properties props = new EnvProperties(); + props.load(testStr); + + assertEquals("jdbc", props.getProperty("org.onap.ccsdk.sli.dbtype")); + String dbUrl = "jdbc:derby:memory:"+System.getenv("MYSQL_DATABASE")+";create=true"; + assertEquals(dbUrl, props.getProperty("org.onap.ccsdk.sli.jdbc.url")); + assertEquals("org.apache.derby.jdbc.EmbeddedDriver", props.getProperty("org.onap.ccsdk.sli.jdbc.driver")); + assertEquals(System.getenv("MYSQL_DATABASE"), props.getProperty("org.onap.ccsdk.sli.jdbc.database")); + assertEquals(System.getenv("MYSQL_USER"), props.getProperty("org.onap.ccsdk.sli.jdbc.user") ); + assertEquals(System.getenv("MYSQL_PASSWORD"), props.getProperty("org.onap.ccsdk.sli.jdbc.password")); + } + + @Test + public void loadReaderTest() throws IOException { + InputStream testStr = getClass().getResourceAsStream("/svclogic.properties"); + BufferedReader testReader = new BufferedReader(new InputStreamReader(testStr)); + + Properties props = new EnvProperties(); + props.load(testReader); + + assertEquals("jdbc", props.getProperty("org.onap.ccsdk.sli.dbtype")); + String dbUrl = "jdbc:derby:memory:"+System.getenv("MYSQL_DATABASE")+";create=true"; + assertEquals(dbUrl, props.getProperty("org.onap.ccsdk.sli.jdbc.url")); + assertEquals("org.apache.derby.jdbc.EmbeddedDriver", props.getProperty("org.onap.ccsdk.sli.jdbc.driver")); + assertEquals(System.getenv("MYSQL_DATABASE"), props.getProperty("org.onap.ccsdk.sli.jdbc.database")); + assertEquals(System.getenv("MYSQL_USER"), props.getProperty("org.onap.ccsdk.sli.jdbc.user")); + assertEquals(System.getenv("MYSQL_PASSWORD"), props.getProperty("org.onap.ccsdk.sli.jdbc.password")); + } + + @Test + public void setPropertyTest() { + Properties props = new EnvProperties(); + + props.setProperty("path", "${PATH}"); + props.setProperty("dummy", "${UNSET_DUMMY:-dummyvalue}"); + assertEquals(System.getenv("PATH"), props.getProperty("path")); + assertEquals("dummyvalue", props.getProperty("dummy")); + } + +} diff --git a/core/utils/provider/src/test/resources/svclogic.properties b/core/utils/provider/src/test/resources/svclogic.properties new file mode 100644 index 000000000..0d62389f2 --- /dev/null +++ b/core/utils/provider/src/test/resources/svclogic.properties @@ -0,0 +1,27 @@ +### +# ============LICENSE_START======================================================= +# ONAP : CCSDK +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights +# reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +org.onap.ccsdk.sli.dbtype = jdbc +org.onap.ccsdk.sli.jdbc.url=jdbc:derby:memory:${MYSQL_DATABASE};create=true +org.onap.ccsdk.sli.jdbc.driver=${MYSQL_DRIVER:-org.apache.derby.jdbc.EmbeddedDriver} +org.onap.ccsdk.sli.jdbc.database = ${MYSQL_DATABASE} +org.onap.ccsdk.sli.jdbc.user = ${MYSQL_USER} +org.onap.ccsdk.sli.jdbc.password = ${MYSQL_PASSWORD} |