Increase JUnit Code Coverage for PolicyDBDao 95/76095/2
authorMichael Mokry <michael.mokry@att.com>
Mon, 21 Jan 2019 22:21:28 +0000 (16:21 -0600)
committerMichael Mokry <michael.mokry@att.com>
Tue, 22 Jan 2019 15:10:58 +0000 (09:10 -0600)
Added Junit tests for PolicyDBDao methods that were not covered after
observing that the code coverage dropped below 50% in SONAR.

Modified license headers with correct copywrite

Change-Id: Iad8e18d978236f4391363d963eb4624744f45099
Issue-ID: POLICY-1448
Signed-off-by: Michael Mokry <michael.mokry@att.com>
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDaoTest.java

index 75d7645..c9c4972 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP-PAP-REST
  * ================================================================================
  * ============LICENSE_START=======================================================
  * ONAP-PAP-REST
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -2870,6 +2870,18 @@ public class PolicyDBDao {
         String[] getPolicyNameAndVersionFromPolicyFileName(String originalPolicyName) throws PolicyDBException {
             return PolicyDBDao.this.getPolicyNameAndVersionFromPolicyFileName(originalPolicyName);
         }
         String[] getPolicyNameAndVersionFromPolicyFileName(String originalPolicyName) throws PolicyDBException {
             return PolicyDBDao.this.getPolicyNameAndVersionFromPolicyFileName(originalPolicyName);
         }
+        
+        String[] getNameScopeAndVersionFromPdpPolicy(String fileName) {
+            return PolicyDBDao.this.getNameScopeAndVersionFromPdpPolicy(fileName);
+        }
+        
+        String getPdpPolicyName(String name, String scope) {
+            return PolicyDBDao.this.getPdpPolicyName(name, scope);
+        }
+        
+        Path getPolicySubFile(String inputFileName, String subFileType) {
+            return PolicyDBDao.this.getPolicySubFile(inputFileName, subFileType);
+        }
     }
 
 }
     }
 
 }
index 89ddf84..f7dd92a 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP-PAP-REST
  * ================================================================================
  * ============LICENSE_START=======================================================
  * ONAP-PAP-REST
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 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.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -143,6 +143,47 @@ public class PolicyDBDaoTest extends Mockito{
         configFile = d.getConfigFile("Action_mypolicy.xml", "org.onap", pra);
         Assert.assertEquals("org.onap.Action_mypolicy.json", configFile);
     }
         configFile = d.getConfigFile("Action_mypolicy.xml", "org.onap", pra);
         Assert.assertEquals("org.onap.Action_mypolicy.json", configFile);
     }
+    
+    @Test
+    public void getPolicyNameAndVersionFromPolicyFileNameTest() throws PolicyDBException {
+        String policyName = "com.Decision_testname.1.xml";
+        String[] expectedNameAndVersion = new String[2];
+        expectedNameAndVersion[0] = "com.Decision_testname";
+        expectedNameAndVersion[1] = "1";
+        String[] actualNameAndVersion = d.getPolicyNameAndVersionFromPolicyFileName(policyName);
+        Assert.assertArrayEquals(expectedNameAndVersion, actualNameAndVersion);
+    }
+    
+    @Test
+    public void getNameScopeAndVersionFromPdpPolicyTest() {
+        String fileName = "com.Decision_testname.1.xml";
+        String[] expectedArray = new String[3];
+        expectedArray[0] = "Decision_testname.1.xml";
+        expectedArray[2] = "1";
+        expectedArray[1] = "com";
+        String[] returnArray = d.getNameScopeAndVersionFromPdpPolicy(fileName);
+        Assert.assertArrayEquals(expectedArray, returnArray);
+    }
+    
+    @Test
+    public void getPdpPolicyNameTest() {
+        String name = "Decision_testname.1.json";
+        String scope = "com";
+        String expectedFinalname = "com.Decision_testname.1.xml";
+        
+        String finalname = d.getPdpPolicyName(name, scope);
+        Assert.assertEquals(expectedFinalname, finalname);
+    }
+    
+    @Test
+    public void getPolicySubFileTest() {
+        String name = "Config_testname.1.json";
+        String subFileType = "Config";
+        
+        Path path = d.getPolicySubFile(name, subFileType);
+        Assert.assertNull(path);
+    }
 
     @Test
     public void createFromPolicyObject(){
 
     @Test
     public void createFromPolicyObject(){