* 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
+ * 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,
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Properties;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DataRouterProperties {
- private static final Logger logger = LoggerFactory.getLogger(DataRouterProperties.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(DataRouterProperties.class);
+
+ private static Properties properties;
- private static Properties properties;
+ static {
+ File file = new File(DataRouterConstants.DR_CONFIG_FILE);
+ loadProperties(file);
+ }
- static {
- properties = new Properties();
- File file = new File(DataRouterConstants.DR_CONFIG_FILE);
- try {
- properties.load(new FileInputStream(file));
- } catch (FileNotFoundException e) {
- logger.error("FileNotFoundException: ", e);
- } catch (IOException e) {
- logger.error("IOException: ", e);
+ static void loadProperties(File file) {
+ properties = new Properties();
+ try (InputStream props = new FileInputStream(file)) {
+ properties.load(props);
+ } catch (FileNotFoundException e) {
+ LOGGER.error("FileNotFoundException: ", e);
+ } catch (IOException e) {
+ LOGGER.error("IOException: ", e);
+ }
}
- }
- public static String get(String key) {
- return properties.getProperty(key);
- }
+ public static String get(String key) {
+ return properties.getProperty(key);
+ }
}
* Removes a document from the Search Service.\r
* \r
* @param index - The index to create the document in.\r
- * @param id - The identifier for the document.\r
- * @param payload - The document contents.\r
+ * @param documentId - The identifier for the document.\r
* @param headers - HTTP headers.\r
*/\r
public void deleteDocument(String index, String documentId, Map<String, List<String>> headers) {\r
*/\r
protected String loadFileData(String filename) throws Exception {\r
StringBuilder data = new StringBuilder();\r
- try {\r
- BufferedReader in = new BufferedReader(new InputStreamReader(\r
- EntityEventPolicy.class.getClassLoader().getResourceAsStream("/" + filename),\r
- StandardCharsets.UTF_8));\r
- String line;\r
\r
+ try (InputStreamReader inputStreamReader = new InputStreamReader(EntityEventPolicy.class.getClassLoader()\r
+ .getResourceAsStream("/" + filename), StandardCharsets.UTF_8); BufferedReader in = new BufferedReader(\r
+ inputStreamReader)\r
+ ) {\r
+\r
+ String line;\r
while ((line = in.readLine()) != null) {\r
data.append(line);\r
}\r
* org.onap.aai\r
* ================================================================================\r
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.\r
- * Copyright © 2017-2018 Amdocs\r
+ * Copyright © 2017-2018 Nokia\r
* ================================================================================\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
* You may obtain a copy of the License at\r
*\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
*\r
* Unless required by applicable law or agreed to in writing, software\r
* distributed under the License is distributed on an "AS IS" BASIS,\r
*/\r
package org.onap.aai.datarouter.util;\r
\r
+import java.io.File;\r
+import java.net.URISyntaxException;\r
+import org.junit.Assert;\r
import org.junit.Test;\r
\r
-import static org.junit.Assert.*;\r
-\r
+/**\r
+ * @author Bogumil Zebek\r
+ */\r
public class DataRouterPropertiesTest {\r
\r
@Test\r
- public void testGet(){\r
- DataRouterProperties.get("key");\r
+ public void shouldLoadDataRouterPropertiesProperlyWhenSpecifiedFileExists() throws URISyntaxException {\r
+ // given\r
+ ClassLoader classLoader = getClass().getClassLoader();\r
+\r
+ File file = new File(\r
+ classLoader.getResource("data-router.properties").getFile()\r
+ );\r
+\r
+ // when\r
+ DataRouterProperties.loadProperties(file);\r
+\r
+ //then\r
+ Assert.assertEquals("value1", DataRouterProperties.get("key1"));\r
+ Assert.assertEquals("value2", DataRouterProperties.get("key2"));\r
+ Assert.assertNull(DataRouterProperties.get("nonExistingKey"));\r
+ }\r
+\r
+ @Test\r
+ public void shouldCreateEmptyDataRouterPropertiesContainerWhenSpecifiedFileDoesNotExist() {\r
+ // given\r
+ File nonExistingFile = new File("nonExistingFile.properties");\r
+\r
+ // when\r
+ DataRouterProperties.loadProperties(nonExistingFile);\r
+\r
+ // then\r
+ Assert.assertNull(DataRouterProperties.get("key"));\r
}\r
}
\ No newline at end of file
--- /dev/null
+key1=value1
+key2=value2
\ No newline at end of file