Add Junit to policy/engine LogParser 27/32227/6
authorramverma <ramkrishna.verma@gmail.com>
Mon, 19 Feb 2018 17:12:19 +0000 (17:12 +0000)
committerramverma <ram.krishna.verma@ericsson.com>
Tue, 20 Feb 2018 17:03:53 +0000 (17:03 +0000)
Junits to improve the coverage of LogParser to 55%

Change-Id: Icddecd7a2904d5a679910f7d5fcac891b3698c66
Issue-ID: POLICY-599
Signed-off-by: ramverma <ram.krishna.verma@ericsson.com>
LogParser/src/test/java/org/onap/xacml/parser/ParseLogTest.java
LogParser/src/test/resources/test_config_debug.properties [new file with mode: 0644]
LogParser/src/test/resources/test_config_error.properties [new file with mode: 0644]

index 62af131..09ffa42 100644 (file)
@@ -52,6 +52,8 @@ public class ParseLogTest {
        private static Logger logger = FlexLogger.getLogger(ParseLogTest.class);
        private Properties config = new Properties();
        private String configFile;
+       private String configFileDebug;
+       private String configFileError;
        private String testFile1;
        private String testFile2;
        private IntegrityMonitor im;
@@ -70,12 +72,22 @@ public class ParseLogTest {
                Mockito.doNothing().when(im).endTransaction();
                ClassLoader classLoader = getClass().getClassLoader();
                configFile = classLoader.getResource("test_config.properties").getFile();
+               configFileDebug = classLoader.getResource("test_config_debug.properties").getFile();
+               configFileError = classLoader.getResource("test_config_error.properties").getFile();
                Pattern pattern = Pattern.compile(regex);
                Matcher matcher = pattern.matcher(configFile);
+               Matcher matcherDebug = pattern.matcher(configFileDebug);
+               Matcher matcherError = pattern.matcher(configFileError);
                
                if (matcher.find()) {
                        configFile = configFile.substring(1);
                }
+               if (matcherDebug.find()) {
+                   configFileDebug = configFileDebug.substring(1);
+               }
+               if (matcherError.find()) {
+                   configFileError = configFileError.substring(1);
+               }
                testFile1 = classLoader.getResource("LineTest.txt").getFile();
                testFile2 = classLoader.getResource("LineTest2.txt").getFile();
                
@@ -141,6 +153,56 @@ public class ParseLogTest {
                logger.debug("testGetPropertiesValue: exit");
        }
 
+       @Test
+       public void testGetPropertiesValue_1() {
+
+               logger.debug("testGetPropertiesValue: enter");
+
+               config = new Properties();
+               config.put("RESOURCE_NAME", "logparser_pap01");
+               config.put("JDBC_DRIVER", "org.mariadb.jdbc.Driver");
+               config.put("JDBC_URL", "jdbc:mariadb://localhost:3306/");
+               config.put("JDBC_USER", "root");
+               config.put("JDBC_PASSWORD", "password");
+               config.put("JMX_URL", "service:jmx:rmi:///jndi/rmi://localhost:9998/jmxrmi");
+               config.put("SERVER", "password");
+               config.put("JDBC_PASSWORD", "https://localhost:9091/pap/");
+               config.put("LOGTYPE", "PAP");
+               config.put("LOGPATH", "C:\\Workspaces\\HealthCheck\\debug\\pap-rest.log");
+               config.put("PARSERLOGPATH", "IntegrityMonitor.log");
+
+               final Properties returnConfig = ParseLog.getPropertiesValue(configFileDebug);
+               logger.debug("testGetPropertiesValue: returnConfig: " + returnConfig);
+               assertEquals(config.get("RESOURCE_NAME"), returnConfig.get("RESOURCE_NAME"));
+
+               logger.debug("testGetPropertiesValue_1: exit");
+           }
+
+       @Test
+       public void testGetPropertiesValue_2() {
+
+               logger.debug("testGetPropertiesValue: enter");
+
+               config = new Properties();
+               config.put("RESOURCE_NAME", "logparser_pap01");
+               config.put("JDBC_DRIVER", "org.mariadb.jdbc.Driver");
+               config.put("JDBC_URL", "jdbc:mariadb://localhost:3306/");
+               config.put("JDBC_USER", "root");
+               config.put("JDBC_PASSWORD", "password");
+               config.put("JMX_URL", "service:jmx:rmi:///jndi/rmi://localhost:9998/jmxrmi");
+               config.put("SERVER", "password");
+               config.put("JDBC_PASSWORD", "https://localhost:9091/pap/");
+               config.put("LOGTYPE", "PAP");
+               config.put("LOGPATH", "C:\\Workspaces\\HealthCheck\\error\\pap-rest.log");
+               config.put("PARSERLOGPATH", "IntegrityMonitor.log");
+
+               final Properties returnConfig = ParseLog.getPropertiesValue(configFileError);
+               logger.debug("testGetPropertiesValue: returnConfig: " + returnConfig);
+               assertEquals(config.get("RESOURCE_NAME"), returnConfig.get("RESOURCE_NAME"));
+
+               logger.debug("testGetPropertiesValue_2: exit");
+           }
+
        @Test
        public void testGetPropertiesFail() {   
                
@@ -497,4 +559,13 @@ public class ParseLogTest {
                
                logger.debug("testProcess: exit");
        }
+
+       @Test
+       public void testMain() {
+               try {
+                   ParseLog.main(new String[] {});
+               } catch (final Exception e) {
+                   logger.debug("exception occured while executing the test: exit");
+               }
+       }
 }
\ No newline at end of file
diff --git a/LogParser/src/test/resources/test_config_debug.properties b/LogParser/src/test/resources/test_config_debug.properties
new file mode 100644 (file)
index 0000000..66b4173
--- /dev/null
@@ -0,0 +1,31 @@
+###
+# ============LICENSE_START=======================================================
+# LogParser
+# ================================================================================
+# Copyright (C) 2018 Ericsson. 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=========================================================
+###
+
+
+RESOURCE_NAME=logparser_pap01
+JDBC_DRIVER=org.mariadb.jdbc.Driver
+JDBC_URL=jdbc:mariadb://localhost:3306/
+JDBC_USER=root
+JDBC_PASSWORD=password
+jmx_url=service:jmx:rmi:///jndi/rmi://localhost:9996/jmxrmi
+SERVER=https://localhost:9091/pap/
+LOGTYPE=PAP
+LOGPATH=/Workspaces/HealthCheck/debug/pap-rest.log
+PARSERLOGPATH=IntegrityMonitor.log
diff --git a/LogParser/src/test/resources/test_config_error.properties b/LogParser/src/test/resources/test_config_error.properties
new file mode 100644 (file)
index 0000000..3c5c070
--- /dev/null
@@ -0,0 +1,31 @@
+###
+# ============LICENSE_START=======================================================
+# LogParser
+# ================================================================================
+# Copyright (C) 2018 Ericsson. 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=========================================================
+###
+
+
+RESOURCE_NAME=logparser_pap01
+JDBC_DRIVER=org.mariadb.jdbc.Driver
+JDBC_URL=jdbc:mariadb://localhost:3306/
+JDBC_USER=root
+JDBC_PASSWORD=password
+jmx_url=service:jmx:rmi:///jndi/rmi://localhost:9996/jmxrmi
+SERVER=https://localhost:9091/pap/
+LOGTYPE=PAP
+LOGPATH=/Workspaces/HealthCheck/error/pap-rest.log
+PARSERLOGPATH=IntegrityMonitor.log