Added Junits for POLICY-SDK-APP 27/14327/3
authorrb7147 <rb7147@att.com>
Thu, 21 Sep 2017 17:51:10 +0000 (13:51 -0400)
committerrb7147 <rb7147@att.com>
Thu, 21 Sep 2017 18:33:50 +0000 (14:33 -0400)
Issue-Id: POLICY-52
Change-Id: I439c95736f50fe9140e71cad5a598c5b5239161b
Signed-off-by: rb7147 <rb7147@att.com>
30 files changed:
BRMSGateway/config.properties
LogParser/parserlog.properties
LogParser/src/test/java/org/onap/xacml/parser/ParseLogTest.java
LogParser/src/test/resources/test_config.properties
ONAP-PAP-REST/policyelk.properties
ONAP-PAP-REST/xacml.pap.properties
ONAP-PDP-REST/pom.xml
ONAP-PDP-REST/src/test/resources/fail.xacml.pdp.properties
ONAP-PDP-REST/src/test/resources/notification.xacml.pdp.properties
ONAP-PDP-REST/src/test/resources/pass.xacml.pdp.properties
ONAP-PDP-REST/xacml.pdp.properties
ONAP-SDK-APP/src/main/webapp/WEB-INF/conf/system.properties
ONAP-SDK-APP/xacml.admin.properties
POLICY-SDK-APP/src/main/java/org/onap/policy/admin/CheckPDP.java
POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java
POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyNotificationMail.java
POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java
POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java
POLICY-SDK-APP/src/main/java/org/onap/policy/daoImp/SystemLogDbDaoImpl.java
POLICY-SDK-APP/src/main/webapp/WEB-INF/conf/system.properties
POLICY-SDK-APP/src/test/java/org/onap/policy/admin/CheckPDPTest.java [new file with mode: 0644]
POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java
POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java [new file with mode: 0644]
POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyRestControllerTest.java [new file with mode: 0644]
POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyUserInfoControllerTest.java
POLICY-SDK-APP/src/test/java/org/onap/policy/daoImp/CommonClassDaoImplTest.java
POLICY-SDK-APP/src/test/resources/test.properties [new file with mode: 0644]
POLICY-SDK-APP/src/test/resources/xacml.admin.properties
PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/testBackUpMonitor.java
packages/install/src/files/base.conf

index 762f0ff..fa5f919 100644 (file)
@@ -57,9 +57,9 @@ vDNS.artifactID= policy-vDNS-rules
 
 #Integrity Monitor values
 #database driver for Integrity Monitor
-javax.persistence.jdbc.driver=com.mysql.jdbc.Driver
+javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver
 #database URL for Integrity Monitor
-javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/xacml
+javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk
 #database username for Integrity Monitor
 javax.persistence.jdbc.user=policy_user
 #database password for Integrity Monitor
index 4a5ecdb..66ce34d 100644 (file)
 
 #Health Check Values
 RESOURCE_NAME=logparser_pap01
-javax.persistence.jdbc.driver=com.mysql.jdbc.Driver
-javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/onap_sdk
+javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver
+javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk
 javax.persistence.jdbc.user=policy_user
 javax.persistence.jdbc.password=policy_user
 
 #Log Parser application values
-JDBC_DRIVER=com.mysql.jdbc.Driver
-JDBC_URL=jdbc:mysql://localhost:3306/log
+JDBC_DRIVER=org.mariadb.jdbc.Driver
+JDBC_URL=jdbc:mariadb://localhost:3306/log
 JDBC_USER=policy_user
 JDBC_PASSWORD=policy_user
 SERVER=https://localhost:9091/pap/
index c12797f..1f42ac3 100644 (file)
@@ -122,8 +122,8 @@ public class ParseLogTest {
                
                config = new Properties();
                config.put("RESOURCE_NAME", "logparser_pap01");
-               config.put("JDBC_DRIVER" ,"com.mysql.jdbc.Driver");
-               config.put("JDBC_URL", "jdbc:mysql://localhost:3306/");
+               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");
index 6512184..ca2b9ed 100644 (file)
@@ -20,8 +20,8 @@
 
 
 RESOURCE_NAME=logparser_pap01
-JDBC_DRIVER=com.mysql.jdbc.Driver
-JDBC_URL=jdbc:mysql://localhost:3306/
+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
index 386008c..d07fab9 100644 (file)
@@ -24,7 +24,7 @@ policy.elk.url=http://localhost:9200
  
  
 #Policy Database properties
-policy.database.driver=com.mysql.jdbc.Driver
-policy.database.url=jdbc:mysql://localhost:3306/onap_sdk?autoReconnect=true&useSSL=false
+policy.database.driver=org.mariadb.jdbc.Driver
+policy.database.url=jdbc:mariadb://localhost:3306/onap_sdk?autoReconnect=true&useSSL=false
 policy.database.username=policy_user
 policy.database.password=policy_user
\ No newline at end of file
index 2517ebd..dc8300d 100644 (file)
@@ -88,8 +88,8 @@ xacml.rest.pdp.idfile=test.properties
 
 #Properties for db access
 #properties for MySql xacml database:  PLEASE DO NOT REMOVE... NEEDED FOR APIs
-javax.persistence.jdbc.driver=com.mysql.jdbc.Driver
-javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/onap_sdk?failOverReadOnly=false&autoReconnect=true
+javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver
+javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk?failOverReadOnly=false&autoReconnect=true
 javax.persistence.jdbc.user=policy_user
 javax.persistence.jdbc.password=policy_user
 
index a2f7f72..fb957f0 100644 (file)
                                        <groupId>javax.persistence</groupId>
                                        <artifactId>persistence-api</artifactId>
                                </exclusion>
+                               <exclusion>
+                                       <groupId>com.att.aft</groupId>
+                                       <artifactId>dme2</artifactId>
+                               </exclusion>
                        </exclusions>
                </dependency>
        </dependencies>
index a16b422..fdc7798 100644 (file)
@@ -122,8 +122,8 @@ xacml.rest.notification.delay=30
 REQUEST_BUFFER_SIZE=15
 
 #properties for MySql xacml database:  PLEASE DO NOT REMOVE... NEEDED FOR APIs
-javax.persistence.jdbc.driver=com.mysql.jdbc.Driver
-javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/xacml
+javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver
+javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk
 javax.persistence.jdbc.user=policy_user
 javax.persistence.jdbc.password=policy_user
 
index 9ca1bba..2a36005 100644 (file)
@@ -122,8 +122,8 @@ xacml.rest.notification.delay=30
 REQUEST_BUFFER_SIZE=15
 
 #properties for MySql xacml database:  PLEASE DO NOT REMOVE... NEEDED FOR APIs
-javax.persistence.jdbc.driver=com.mysql.jdbc.Driver
-javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/xacml
+javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver
+javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk
 javax.persistence.jdbc.user=policy_user
 javax.persistence.jdbc.password=policy_user
 
index c9a1110..c3eda59 100644 (file)
@@ -122,8 +122,8 @@ xacml.rest.notification.delay=30
 REQUEST_BUFFER_SIZE=15
 
 #properties for MySql xacml database:  PLEASE DO NOT REMOVE... NEEDED FOR APIs
-javax.persistence.jdbc.driver=com.mysql.jdbc.Driver
-javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/xacml
+javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver
+javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk
 javax.persistence.jdbc.user=policy_user
 javax.persistence.jdbc.password=policy_user
 
index 6cf2e94..4d12004 100644 (file)
@@ -126,8 +126,8 @@ CLIENT_INTERVAL=15000
 REQUEST_BUFFER_SIZE=15
 
 #properties for MySql xacml database:  PLEASE DO NOT REMOVE... NEEDED FOR APIs
-javax.persistence.jdbc.driver=com.mysql.jdbc.Driver
-javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/onap_sdk
+javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver
+javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk
 javax.persistence.jdbc.user=policy_user
 javax.persistence.jdbc.password=policy_user
 
index 304bcbd..991cb8a 100644 (file)
@@ -23,8 +23,8 @@ decryption_key                                  = AGLDdG4D04BKm2IxIWEr8o==
 # The following properties MAY require changes by partner applications.
 ##########################################################################
 #Mysql
-db.driver = com.mysql.jdbc.Driver
-db.connectionURL = jdbc:mysql://localhost:3306/onap_sdk
+db.driver = org.mariadb.jdbc.Driver
+db.connectionURL = jdbc:mariadb://localhost:3306/onap_sdk
 db.userName = policy_user
 db.password = policy_user
 db.hib.dialect = org.hibernate.dialect.MySQLDialect
index 0f285b6..333da49 100644 (file)
@@ -87,8 +87,8 @@ xacml.log.db.password=policy_user
 
 xacml.att.log.timeframe=150
 
-javax.persistence.jdbc.driver=com.mysql.jdbc.Driver
-javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/onap_sdk
+javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver
+javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk
 javax.persistence.jdbc.user=policy_user
 javax.persistence.jdbc.password=policy_user
 
index 3febbed..7ac9ca3 100644 (file)
@@ -34,6 +34,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 
 import org.onap.policy.common.logging.flexlogger.FlexLogger;
@@ -49,9 +50,14 @@ public class CheckPDP {
        private static HashMap<String, String> pdpMap = null;
        private static final Logger LOGGER = FlexLogger.getLogger(CheckPDP.class);
        
-       private CheckPDP(){
+       public static Map<String, String> getPdpMap() {
+               return pdpMap;
+       }
+
+       public CheckPDP(){
                //default constructor
        }
+       
        public static boolean validateID(String id) {
                // ReadFile
                try {
index 4f42023..c94c14d 100644 (file)
@@ -92,16 +92,6 @@ public class PolicyManagerServlet extends HttpServlet {
        private static final Logger LOGGER      = FlexLogger.getLogger(PolicyManagerServlet.class);
        private static final long serialVersionUID = -8453502699403909016L;
        
-       private static boolean jUnit = false;
-
-       public static boolean isjUnit() {
-               return jUnit;
-       }
-
-       public static void setjUnit(boolean jUnit) {
-               PolicyManagerServlet.jUnit = jUnit;
-       }
-
        private enum Mode {
                LIST, RENAME, COPY, DELETE, EDITFILE, ADDFOLDER, DESCRIBEPOLICYFILE, VIEWPOLICY, ADDSUBSCOPE, SWITCHVERSION, EXPORT, SEARCHLIST
        }
@@ -542,7 +532,7 @@ public class PolicyManagerServlet extends HttpServlet {
                peParams.put("split_1", split[1]);
                peParams.put("split_0", split[0]);
                List<Object> queryData = null;
-               if(jUnit){
+               if(PolicyController.isjUnit()){
                        queryData = controller.getDataByQuery(query, null);
                }else{
                        queryData = controller.getDataByQuery(query, peParams);
@@ -684,7 +674,7 @@ public class PolicyManagerServlet extends HttpServlet {
                }
                PolicyController controller = getPolicyControllerInstance();
                List<Object> scopesList = null;
-               if(jUnit){
+               if(PolicyController.isjUnit()){
                        scopesList = controller.getDataByQuery(scopeNamequery, null);
                }else{
                        scopesList = controller.getDataByQuery(scopeNamequery, params);
@@ -709,7 +699,7 @@ public class PolicyManagerServlet extends HttpServlet {
                
                List<Object> activePolicies = null;
                List<Object> scopesList = null;
-               if(jUnit){
+               if(PolicyController.isjUnit()){
                        activePolicies = controller.getDataByQuery(query, null);
                        scopesList = controller.getDataByQuery(scopeNamequery, null);
                }else{
@@ -1422,7 +1412,7 @@ public class PolicyManagerServlet extends HttpServlet {
                        peParams.put("split_1", split[1]);
                        peParams.put("split_0", split[0]);
                        List<Object> queryData = null;
-                       if(jUnit){
+                       if(PolicyController.isjUnit()){
                                queryData = controller.getDataByQuery(query, null);
                        }else{
                                queryData = controller.getDataByQuery(query, peParams);
index a4e4762..2326a9f 100644 (file)
@@ -122,7 +122,12 @@ public class PolicyNotificationMail{
                boolean sendFlag = false;
                SimpleBindings params = new SimpleBindings();
                params.put("policyFileName", policyFileName);
-               List<Object> watchList = policyNotificationDao.getDataByQuery(query, params);
+               List<Object> watchList = null;
+               if(PolicyController.isjUnit()){
+                       watchList = policyNotificationDao.getDataByQuery(query, null);
+               }else{
+                       watchList = policyNotificationDao.getDataByQuery(query, params);
+               }
                if(watchList != null && !watchList.isEmpty()){
                        for(Object watch : watchList){
                                WatchPolicyNotificationTable list = (WatchPolicyNotificationTable) watch;
index 7234a3b..08f8030 100644 (file)
@@ -82,8 +82,24 @@ public class PolicyRestController extends RestrictedBaseController{
        private static final String modal = "model";
        private static final String importDictionary = "import_dictionary";
        
+       private static CommonClassDao commonClassDao;
+       
+       public static CommonClassDao getCommonClassDao() {
+               return commonClassDao;
+       }
+
+       public static void setCommonClassDao(CommonClassDao commonClassDao) {
+               PolicyRestController.commonClassDao = commonClassDao;
+       }
+       
        @Autowired
-       CommonClassDao commonClassDao;
+       private PolicyRestController(CommonClassDao commonClassDao){
+               PolicyRestController.commonClassDao = commonClassDao;
+       }
+       
+       public PolicyRestController(){
+               //default constructor
+       }
 
        @RequestMapping(value={"/policycreation/save_policy"}, method={RequestMethod.POST})
        public void policyCreationController(HttpServletRequest request, HttpServletResponse response) {
index ed0bf4c..9832f58 100644 (file)
@@ -90,6 +90,14 @@ public class CreateFirewallController extends RestrictedBaseController {
        
        private static CommonClassDao commonClassDao;
 
+       public static CommonClassDao getCommonClassDao() {
+               return commonClassDao;
+       }
+
+       public static void setCommonClassDao(CommonClassDao commonClassDao) {
+               CreateFirewallController.commonClassDao = commonClassDao;
+       }
+       
        private List<String> tagCollectorList;
        private String jsonBody;
        List<String> expandablePrefixIPList = new ArrayList<>();
index 49024ba..c96da50 100644 (file)
@@ -43,16 +43,6 @@ import org.onap.policy.common.logging.flexlogger.Logger;
 public class SystemLogDbDaoImpl implements SystemLogDbDao {
        private static final Logger logger = FlexLogger.getLogger(SystemLogDbDaoImpl.class);
        
-       private static boolean jUnit = false;
-       
-       public static boolean isjUnit() {
-               return jUnit;
-       }
-
-       public static void setjUnit(boolean jUnit) {
-               SystemLogDbDaoImpl.jUnit = jUnit;
-       }
-
        @SuppressWarnings("unchecked")
        @Override
        public List<SystemLogDB> getLoggingData() {
@@ -61,7 +51,7 @@ public class SystemLogDbDaoImpl implements SystemLogDbDao {
                List<SystemLogDB> system = null;
         try {
                String sqlWhere = null;
-               if(jUnit){
+               if(PolicyController.isjUnit()){
                        sqlWhere = "";
                }else{
                        sqlWhere = "date > DATE_SUB(curdate(), INTERVAL 5 DAY) ORDER BY date DESC limit "+PolicyController.getLogTableLimit()+"";
@@ -90,7 +80,7 @@ public class SystemLogDbDaoImpl implements SystemLogDbDao {
                List<SystemLogDB> system = null;
         try {
                String sqlWhere = null;
-               if(jUnit){
+               if(PolicyController.isjUnit()){
                        sqlWhere = "";
                }else{
                        sqlWhere = "date > DATE_SUB(curdate(), INTERVAL 5 DAY) and logtype = 'error' ORDER BY date DESC limit "+PolicyController.getSystemAlertTableLimit()+"";
index 43b2de7..84c5dc5 100644 (file)
@@ -23,8 +23,8 @@ decryption_key                                  = AGLDdG4D04BKm2IxIWEr8o==
 # The following properties MAY require changes by partner applications.
 ##########################################################################
 #Mysql
-db.driver = com.mysql.jdbc.Driver
-db.connectionURL = jdbc:mysql://localhost:3306/onapsdk1707
+db.driver = org.mariadb.jdbc.Driver
+db.connectionURL = jdbc:mariadb://localhost:3306/onapsdk1707
 db.userName = root
 db.password = 
 db.hib.dialect = org.hibernate.dialect.MySQLDialect
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/CheckPDPTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/CheckPDPTest.java
new file mode 100644 (file)
index 0000000..47358a8
--- /dev/null
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Engine
+ * ================================================================================
+ * 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=========================================================
+ */
+package org.onap.policy.admin;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+
+import org.junit.Test;
+
+public class CheckPDPTest {
+
+       @Test
+       public final void testCheckPDP() {
+               try {
+                       System.setProperty("xacml.rest.pdp.idfile", new File(".").getCanonicalPath() + File.separator + "src"+ File.separator + "test" + File.separator + "resources" + File.separator + "test.properties");
+                       CheckPDP.validateID("http://localhost:8082/pdp/");
+                       assertTrue(CheckPDP.getPdpMap().containsKey("http://localhost:8082/pdp/"));
+                       assertTrue(CheckPDP.getEncoding("http://localhost:8082/pdp/").equals("dGVzdHBkcDphbHBoYTQ1Ng=="));
+               } catch (Exception e) {
+                       fail("Error occured in CheckPDP test");
+               }
+       }
+
+}
index 970b678..22cc82a 100644 (file)
@@ -64,6 +64,7 @@ public class PolicyManagerServletTest extends Mockito{
        @Before
        public void setUp() throws Exception{
                logger.info("setUp: Entering");
+               PolicyController.setjUnit(true);
                UserInfo userinfo = new UserInfo();
                userinfo.setUserLoginId("Test");
                userinfo.setUserName("Test");
@@ -146,7 +147,6 @@ public class PolicyManagerServletTest extends Mockito{
                HttpServletRequest request = mock(HttpServletRequest.class);       
         HttpServletResponse response = mock(HttpServletResponse.class);  
         PolicyController controller = mock(PolicyController.class);
-        PolicyManagerServlet.setjUnit(true);
         BufferedReader reader = new BufferedReader(new StringReader("{params: { mode: 'DESCRIBEPOLICYFILE', path: 'com.Config_SampleTest1206.1.xml'}}"));
         try {
                        when(request.getReader()).thenReturn(reader);
@@ -168,7 +168,6 @@ public class PolicyManagerServletTest extends Mockito{
                HttpServletRequest request = mock(HttpServletRequest.class);       
         HttpServletResponse response = mock(HttpServletResponse.class); 
         PolicyController controller = mock(PolicyController.class);
-        PolicyManagerServlet.setjUnit(true);
         List<String> list = new ArrayList<>();
         list.add("{params: { mode: 'LIST', path: '/', onlyFolders: false}}");
         list.add("{params: { mode: 'LIST', path: '/com', onlyFolders: false}}");
@@ -197,7 +196,6 @@ public class PolicyManagerServletTest extends Mockito{
                HttpServletRequest request = mock(HttpServletRequest.class);       
         HttpServletResponse response = mock(HttpServletResponse.class); 
         PolicyController controller = mock(PolicyController.class);
-        PolicyManagerServlet.setjUnit(true);
         List<String> list = new ArrayList<>();
         list.add("{params: { mode: 'EDITFILE', path: '/com/Config_SampleTest1206.1.xml', onlyFolders: false}}");
         for(int i =0; i < list.size(); i++){
@@ -244,7 +242,6 @@ public class PolicyManagerServletTest extends Mockito{
                HttpServletRequest request = mock(HttpServletRequest.class);       
         HttpServletResponse response = mock(HttpServletResponse.class); 
         PolicyController controller = mock(PolicyController.class);
-        PolicyManagerServlet.setjUnit(true);
         List<String> list = new ArrayList<>();
         list.add("{params: { mode: 'EDITFILE', path: '/com/Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml', onlyFolders: false}}");
         for(int i =0; i < list.size(); i++){
@@ -291,7 +288,6 @@ public class PolicyManagerServletTest extends Mockito{
                HttpServletRequest request = mock(HttpServletRequest.class);       
         HttpServletResponse response = mock(HttpServletResponse.class); 
         PolicyController controller = mock(PolicyController.class);
-        PolicyManagerServlet.setjUnit(true);
         List<String> list = new ArrayList<>();
         list.add("{params: { mode: 'EDITFILE', path: '/com/Config_BRMS_Raw_TestBRMSRawPolicy.1.xml', onlyFolders: false}}");
         for(int i =0; i < list.size(); i++){
@@ -338,7 +334,6 @@ public class PolicyManagerServletTest extends Mockito{
                HttpServletRequest request = mock(HttpServletRequest.class);       
         HttpServletResponse response = mock(HttpServletResponse.class); 
         PolicyController controller = mock(PolicyController.class);
-        PolicyManagerServlet.setjUnit(true);
         List<String> list = new ArrayList<>();
         list.add("{params: { mode: 'EDITFILE', path: '/com/Config_Fault_TestClosedLoopPolicy.1.xml', onlyFolders: false}}");
         for(int i =0; i < list.size(); i++){
@@ -385,7 +380,6 @@ public class PolicyManagerServletTest extends Mockito{
                HttpServletRequest request = mock(HttpServletRequest.class);       
         HttpServletResponse response = mock(HttpServletResponse.class); 
         PolicyController controller = mock(PolicyController.class);
-        PolicyManagerServlet.setjUnit(true);
         List<String> list = new ArrayList<>();
         list.add("{params: { mode: 'EDITFILE', path: '/com/Config_PM_TestClosedLoopPMPolicy.1.xml', onlyFolders: false}}");
         for(int i =0; i < list.size(); i++){
@@ -439,7 +433,6 @@ public class PolicyManagerServletTest extends Mockito{
                HttpServletRequest request = mock(HttpServletRequest.class);       
         HttpServletResponse response = mock(HttpServletResponse.class); 
         PolicyController controller = mock(PolicyController.class);
-        PolicyManagerServlet.setjUnit(true);
         List<String> list = new ArrayList<>();
         list.add("{params: { mode: 'EDITFILE', path: '/com/Config_MS_vFirewall.1.xml', onlyFolders: false}}");
         for(int i =0; i < list.size(); i++){
@@ -487,7 +480,6 @@ public class PolicyManagerServletTest extends Mockito{
                HttpServletRequest request = mock(HttpServletRequest.class);       
         HttpServletResponse response = mock(HttpServletResponse.class); 
         PolicyController controller = mock(PolicyController.class);
-        PolicyManagerServlet.setjUnit(true);
         List<String> list = new ArrayList<>();
         list.add("{params: { mode: 'EDITFILE', path: '/com/Config_FW_TestFireWallPolicy.1.xml', onlyFolders: false}}");
         for(int i =0; i < list.size(); i++){
@@ -532,7 +524,6 @@ public class PolicyManagerServletTest extends Mockito{
                HttpServletRequest request = mock(HttpServletRequest.class);       
         HttpServletResponse response = mock(HttpServletResponse.class); 
         PolicyController controller = mock(PolicyController.class);
-        PolicyManagerServlet.setjUnit(true);
         List<String> list = new ArrayList<>();
         list.add("{params: { mode: 'EDITFILE', path: '/com/Action_TestActionPolicy.1.xml', onlyFolders: false}}");
         for(int i =0; i < list.size(); i++){
@@ -571,7 +562,6 @@ public class PolicyManagerServletTest extends Mockito{
                HttpServletRequest request = mock(HttpServletRequest.class);       
         HttpServletResponse response = mock(HttpServletResponse.class); 
         PolicyController controller = mock(PolicyController.class);
-        PolicyManagerServlet.setjUnit(true);
         List<String> list = new ArrayList<>();
         list.add("{params: { mode: 'EDITFILE', path: '/com/Decision_TestDecisionPolicyWithRuleAlgorithms.1.xml', onlyFolders: false}}");
         for(int i =0; i < list.size(); i++){
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java
new file mode 100644 (file)
index 0000000..2c56a8b
--- /dev/null
@@ -0,0 +1,94 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Engine
+ * ================================================================================
+ * 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=========================================================
+ */
+package org.onap.policy.admin;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import static org.mockito.Mockito.when;
+import org.onap.policy.controller.PolicyController;
+import org.onap.policy.rest.dao.CommonClassDao;
+import org.onap.policy.rest.jpa.PolicyVersion;
+import org.onap.policy.rest.jpa.WatchPolicyNotificationTable;
+
+public class PolicyNotificationMailTest {
+
+       private PolicyVersion version;
+       private String policyName = "com/Config_Test";
+       private CommonClassDao commonClassDao;
+       private List<Object> data = null;
+       
+       @Before
+       public void setUp() throws Exception {
+               PolicyController.setjUnit(true);
+               PolicyController.setSmtpApplicationName("Test");
+               PolicyController.setSmtpEmailExtension("test.com");
+               PolicyController.setSmtpHost("test");
+               PolicyController.setSmtpPort("23");
+               PolicyController.setSmtpPassword("test");
+               PolicyController.setSmtpUsername("test");
+               
+               version = new PolicyVersion();
+               version.setPolicyName("com/Config_Test");
+               version.setModifiedBy("xyz");
+               
+               WatchPolicyNotificationTable watch = new WatchPolicyNotificationTable();
+               watch.setPolicyName("com/Config_Test");
+               data = new ArrayList<>();
+               data.add(watch);
+               
+               commonClassDao = mock(CommonClassDao.class);
+        PolicyController.setCommonClassDao(commonClassDao);
+        when(commonClassDao.getDataByQuery("from WatchPolicyNotificationTable where policyName like:policyFileName", null)).thenReturn(data);
+       }
+
+       @Test
+       public final void testJavaMailSenderImpl() {
+               PolicyNotificationMail notificationMail = new PolicyNotificationMail();
+               try{
+                       assertTrue(notificationMail.javaMailSenderImpl() != null);
+               }catch(Exception e){
+                       fail();
+               }
+       }
+
+       @Test
+       public final void testSendMail() {
+               PolicyNotificationMail notificationMail = new PolicyNotificationMail();
+               try{
+                       notificationMail.sendMail(version, policyName, "EditPolicy", commonClassDao);
+                       notificationMail.sendMail(version, policyName, "Rename", commonClassDao);
+                       notificationMail.sendMail(version, policyName, "DeleteAll", commonClassDao);
+                       notificationMail.sendMail(version, policyName, "DeleteOne", commonClassDao);
+                       notificationMail.sendMail(version, policyName, "DeleteScope", commonClassDao);
+                       notificationMail.sendMail(version, policyName, "SwitchVersion", commonClassDao);
+                       notificationMail.sendMail(version, policyName, "Move", commonClassDao);
+               }catch(Exception e){
+                       fail();
+               }
+       }
+
+}
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyRestControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyRestControllerTest.java
new file mode 100644 (file)
index 0000000..1bda7cd
--- /dev/null
@@ -0,0 +1,232 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Engine
+ * ================================================================================
+ * 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=========================================================
+ */
+package org.onap.policy.admin;
+
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.policy.controller.CreateFirewallController;
+import org.onap.policy.rest.dao.CommonClassDao;
+import org.onap.policy.rest.jpa.ActionList;
+import org.onap.policy.rest.jpa.AddressGroup;
+import org.onap.policy.rest.jpa.FWTagPicker;
+import org.onap.policy.rest.jpa.GroupServiceList;
+import org.onap.policy.rest.jpa.PrefixList;
+import org.onap.policy.rest.jpa.SecurityZone;
+import org.onap.policy.rest.jpa.ServiceList;
+import org.onap.policy.rest.jpa.TermList;
+import org.openecomp.portalsdk.core.domain.User;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+public class PolicyRestControllerTest {
+
+       private String clRequestString;
+       private String fwRequestString;
+       private String fwViewRequestString;
+       private HttpServletRequest request;
+       private MockHttpServletResponse response;
+       private static CommonClassDao commonClassDao;
+       private List<Object> prefixListData;
+       private List<Object> actionListData;
+       private List<Object> serviceListData;
+       private List<Object> addressGroupData;
+       private List<Object> securityZoneData;
+       private List<Object> serviceGroupData;
+       private List<Object> tagListData;
+       private List<Object> termListData;
+       
+       @Before
+       public void setUp() throws Exception {
+               commonClassDao = mock(CommonClassDao.class);
+               HttpSession mockSession = mock(HttpSession.class);
+               request = mock(HttpServletRequest.class);  
+               response =  new MockHttpServletResponse();
+               User user = new User();
+               user.setOrgUserId("Test");
+               Mockito.when(mockSession.getAttribute(SystemProperties.getProperty("user_attribute_name"))).thenReturn(user);
+               Mockito.when(request.getSession(false)).thenReturn(mockSession);
+               clRequestString = "{\"policyData\":{\"error\":\"\",\"inprocess\":false,\"model\":{\"name\":\"com\","
+                               + "\"subScopename\":\"\",\"path\":[],\"type\":\"dir\",\"size\":0,\"date\":\"2017-06-01T15:45:36.000Z\","
+                               + "\"version\":\"\",\"createdBy\":\"Demo\",\"modifiedBy\":\"Demo\",\"content\":\"\",\"recursive\":false},"
+                               + "\"tempModel\":{\"name\":\"com\",\"subScopename\":\"\",\"path\":[],\"type\":\"dir\",\"size\":0,\"date\":\"2017-06-01T15:45:36.000Z\","
+                               + "\"version\":\"\",\"createdBy\":\"Demo\",\"modifiedBy\":\"Demo\",\"content\":\"\",\"recursive\":false},\"$$hashKey\":\"object:1439\","
+                               + "\"policy\":{\"policyType\":\"Config\",\"configPolicyType\":\"ClosedLoop_Fault\",\"triggerTrapSignatures\":[1,1,2,3],"
+                               + "\"triggerfaultSignatures\":[1,1,2,3],\"traptriggerSignatures\":[{\"id\":\"Trap1\",\"$$hashKey\":\"object:1526\"},"
+                               + "{\"id\":\"Trap2\",\"$$hashKey\":\"object:1534\"}],\"connecttriggerSignatures\":[{\"id\":\"C1\",\"$$hashKey\":\"object:1554\","
+                               + "\"notBox\":\"NOT\",\"connectTrap1\":\"Trap1\",\"trapCount1\":\"12\",\"operatorBox\":\"AND\",\"connectTrap2\":\"Trap2\","
+                               + "\"trapCount2\":\"14\"}],\"faulttriggerSignatures\":[{\"id\":\"Fault1\",\"$$hashKey\":\"object:1566\"},{\"id\":\"Fault2\","
+                               + "\"$$hashKey\":\"object:1575\"}],\"connectVerificationSignatures\":[{\"id\":\"C1\",\"$$hashKey\":\"object:1595\","
+                               + "\"notBox\":\"NOT\",\"connectTrap1\":\"Fault1\",\"trapCount1\":\"11\",\"operatorBox\":\"AND\",\"connectTrap2\":\"Fault2\","
+                               + "\"trapCount2\":\"12\"}],\"jsonBodyData\":{\"trapMaxAge\":\"300\",\"vnfType\":\"Test\",\"closedLoopPolicyStatus\":\"Active\","
+                               + "\"vUSP\":true,\"trinity\":true,\"vDNS\":true,\"mcr\":true,\"gamma\":true,\"actions\":\"Test\",\"timeInterval\":\"11\","
+                               + "\"timeOutvPRO\":\"11\",\"timeOutRuby\":\"11\",\"retrys\":\"1\",\"agingWindow\":\"12\",\"geoLink\":\"test\","
+                               + "\"emailAddress\":\"aa@test.com\",\"pepName\":\"Test\",\"pepAction\":\"test\",\"conditions\":\"SEND\"},"
+                               + "\"policyName\":\"SampleTest\",\"policyDescription\":\"SampleTest\",\"riskType\":\"SampleRiskType\",\"riskLevel\":\"1\","
+                               + "\"guard\":\"True\",\"onapName\":\"SampleDemo\",\"ttlDate\":\"14/09/2017\",\"clearTimeOut\":\"123\",\"trapMaxAge\":\"11\","
+                               + "\"verificationclearTimeOut\":\"13\"}},\"trapData\":{\"trap1\":[{\"id\":\"A1\",\"$$hashKey\":\"object:1528\","
+                               + "\"notBox\":\"NOT\",\"trigger1\":\"Test\",\"operatorBox\":\"AND\",\"trigger2\":\"Test\"}],\"trap2\":[{\"id\":\"A1\","
+                               + "\"$$hashKey\":\"object:1536\",\"notBox\":\"NOT\",\"trigger1\":\"Test\",\"operatorBox\":\"AND\",\"trigger2\":\"Test\"},"
+                               + "{\"id\":\"A2\",\"$$hashKey\":\"object:1542\",\"notBox\":\"NOT\",\"trigger1\":\"A1\",\"operatorBox\":\"AND\",\"trigger2\":"
+                               + "\"Test\"},{\"id\":\"A3\",\"$$hashKey\":\"object:1548\",\"notBox\":\"NOT\",\"trigger1\":\"A1\",\"operatorBox\":\"OR\","
+                               + "\"trigger2\":\"A2\"}]},\"faultData\":{\"trap1\":[{\"id\":\"A1\",\"$$hashKey\":\"object:1568\",\"notBox\":\"NOT\","
+                               + "\"trigger1\":\"Test\",\"operatorBox\":\"AND\",\"trigger2\":\"Test\"}],\"trap2\":[{\"id\":\"A1\",\"$$hashKey\":\"object:1577\","
+                               + "\"notBox\":\"NOT\",\"trigger1\":\"Test\",\"operatorBox\":\"AND\",\"trigger2\":\"Test\"},{\"id\":\"A2\",\"$$hashKey\":"
+                               + "\"object:1583\",\"notBox\":\"NOT\",\"trigger1\":\"Test\",\"operatorBox\":\"OR\",\"trigger2\":\"Test\"},{\"id\":\"A3"
+                               + "\",\"$$hashKey\":\"object:1589\",\"notBox\":\"NOT\",\"trigger1\":\"A1\",\"operatorBox\":\"AND\",\"trigger2\":\"A2\"}]}}";
+               
+               
+               fwRequestString = "{\"policyData\":{\"error\":\"\",\"inprocess\":false,\"model\":{\"name\":\"com\",\"subScopename\":\"\",\"path\":[],"
+                               + "\"type\":\"dir\",\"size\":0,\"date\":\"2017-06-01T15:45:36.000Z\",\"version\":\"\",\"createdBy\":\"Demo\",\"modifiedBy\":"
+                               + "\"Demo\",\"content\":\"\",\"recursive\":false},\"tempModel\":{\"name\":\"com\",\"subScopename\":\"\",\"path\":[],\"type\":"
+                               + "\"dir\",\"size\":0,\"date\":\"2017-06-01T15:45:36.000Z\",\"version\":\"\",\"createdBy\":\"Demo\",\"modifiedBy\":\"Demo\","
+                               + "\"content\":\"\",\"recursive\":false},\"$$hashKey\":\"object:260\",\"policy\":{\"policyType\":\"Config\",\"configPolicyType"
+                               + "\":\"Firewall Config\",\"attributes\":[{\"id\":\"choice1\",\"$$hashKey\":\"object:338\",\"key\":\"Test\",\"value\":\"Test\"}],"
+                               + "\"fwattributes\":[],\"policyName\":\"SampleTest\",\"policyDescription\":\"SampleTest\",\"riskType\":\"SampleRiskType\","
+                               + "\"riskLevel\":\"1\",\"guard\":\"True\",\"configName\":\"SampleTest\",\"ttlDate\":\"14/09/2017\",\"securityZone\":\"Test\"}}}";
+               
+               fwViewRequestString = "{\"policyData\":{\"policyType\":\"Config\",\"configPolicyType\":\"Firewall Config\",\"attributes\":[{\"id\":"
+                               + "\"choice1\",\"$$hashKey\":\"object:338\",\"key\":\"Test\",\"value\":\"Test\"}],\"fwattributes\":[],\"policyName\":"
+                               + "\"SampleTest\",\"policyDescription\":\"SampleTest\",\"riskType\":\"SampleRiskType\",\"riskLevel\":\"1\",\"guard\":\"True\","
+                               + "\"configName\":\"SampleTest\",\"ttlDate\":\"14/09/2017\",\"securityZone\":\"Test\"}}";
+
+
+
+               prefixListData = new ArrayList<>();
+               PrefixList prefixList = new PrefixList();
+               prefixList.setPrefixListName("Test");
+               prefixList.setPrefixListValue("10.10.10.10/12");
+               prefixListData.add(prefixList);
+               when(commonClassDao.getData(PrefixList.class)).thenReturn(prefixListData);
+               
+               actionListData = new ArrayList<>();
+               ActionList actionList = new ActionList();
+               actionList.setActionName("Test");
+               actionListData.add(actionList);
+               when(commonClassDao.getData(ActionList.class)).thenReturn(actionListData);
+                       
+               serviceListData = new ArrayList<>();
+               ServiceList serviceList = new ServiceList();
+               serviceList.setServiceName("Test");
+               serviceList.setServiceType("SERVICE");
+               serviceList.setServiceTransProtocol("Test");
+               serviceList.setServiceAppProtocol("Test");
+               serviceList.setServicePorts("8080");
+               serviceListData.add(serviceList);
+               when(commonClassDao.getData(ServiceList.class)).thenReturn(serviceListData);
+               
+               addressGroupData = new ArrayList<>();
+               AddressGroup addressGroup = new AddressGroup();
+               addressGroup.setGroupName("Group_Test");
+               addressGroup.setServiceList("Test");
+               addressGroupData.add(addressGroup);
+               when(commonClassDao.getData(AddressGroup.class)).thenReturn(addressGroupData);
+               
+               securityZoneData = new ArrayList<>();
+               SecurityZone securityZone = new SecurityZone();
+               securityZone.setZoneName("Test");
+               securityZone.setZoneValue("Test");
+               securityZoneData.add(securityZone);
+               when(commonClassDao.getData(SecurityZone.class)).thenReturn(securityZoneData);
+               
+               serviceGroupData = new ArrayList<>();
+               GroupServiceList serviceGroup = new GroupServiceList();
+               serviceGroup.setGroupName("Group_Test");
+               serviceGroup.setServiceList("Test");
+               serviceGroupData.add(serviceGroup);
+               when(commonClassDao.getData(GroupServiceList.class)).thenReturn(serviceGroupData);
+               
+               tagListData = new ArrayList<>();
+               FWTagPicker fwPicker = new FWTagPicker();
+               fwPicker.setTagPickerName("Test");
+               fwPicker.setTagValues("Test:8080");
+               tagListData.add(fwPicker);
+               when(commonClassDao.getData(FWTagPicker.class)).thenReturn(tagListData);
+               
+               termListData = new ArrayList<>();
+               TermList termList = new TermList();
+               termList.setTermName("Test");
+               termList.setFromZones("Test");
+               termList.setToZones("Test");
+               termList.setSrcIPList("Test");
+               termList.setDestIPList("Test");
+               termList.setSrcPortList("Test");
+               termList.setDestPortList("Test");
+               termList.setAction("Test");
+               termListData.add(termList);
+               when(commonClassDao.getData(TermList.class)).thenReturn(termListData);
+               when(commonClassDao.getDataById(TermList.class, "termName", "Test")).thenReturn(termListData);
+       }
+
+       @Test
+       public final void testPolicyCreationController() {
+               PolicyRestController controller = new PolicyRestController();
+               BufferedReader reader = new BufferedReader(new StringReader(clRequestString));
+               try {
+                       Mockito.when(request.getReader()).thenReturn(reader);
+                       controller.policyCreationController(request, response); 
+               } catch (IOException e) {
+                       fail();
+               }
+               PolicyRestController controller1 = new PolicyRestController();
+               CreateFirewallController.setCommonClassDao(commonClassDao);
+               BufferedReader reader1 = new BufferedReader(new StringReader(fwRequestString));
+               try {
+                       Mockito.when(request.getReader()).thenReturn(reader1);
+                       controller1.policyCreationController(request, response);        
+               } catch (IOException e) {
+                       fail();
+               }
+               
+               CreateFirewallController fwController = new CreateFirewallController();
+               CreateFirewallController.setCommonClassDao(commonClassDao);
+               BufferedReader reader2 = new BufferedReader(new StringReader(fwViewRequestString));
+               try {
+                       Mockito.when(request.getReader()).thenReturn(reader2);
+                       fwController.setFWViewRule(request, response);  
+               } catch (IOException e) {
+                       fail();
+               }
+       }
+
+       @Test
+       public final void testDeleteElasticData() {
+               PolicyRestController controller = new PolicyRestController();
+               try {
+                       controller.deleteElasticData("Test");
+               } catch (Exception e) {
+                       fail();
+               }
+       }
+
+}
index 4931d20..f4acaeb 100644 (file)
@@ -41,12 +41,12 @@ public class PolicyUserInfoControllerTest {
        @Before
        public void setUp() throws Exception {
                HttpSession mockSession = mock(HttpSession.class);
-                request = mock(HttpServletRequest.class);  
-                response =  new MockHttpServletResponse();
-                User user = new User();
-                user.setOrgUserId("Test");
-                Mockito.when(mockSession.getAttribute(SystemProperties.getProperty("user_attribute_name"))).thenReturn(user);
-                Mockito.when(request.getSession(false)).thenReturn(mockSession);
+               request = mock(HttpServletRequest.class);  
+               response =  new MockHttpServletResponse();
+               User user = new User();
+               user.setOrgUserId("Test");
+               Mockito.when(mockSession.getAttribute(SystemProperties.getProperty("user_attribute_name"))).thenReturn(user);
+               Mockito.when(request.getSession(false)).thenReturn(mockSession);
        }
 
        @Test
index d4b0c65..63ca29d 100644 (file)
 
 package org.onap.policy.daoImp;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Properties;
@@ -39,9 +43,9 @@ import org.onap.policy.common.logging.flexlogger.FlexLogger;
 import org.onap.policy.common.logging.flexlogger.Logger;
 import org.onap.policy.conf.HibernateSession;
 import org.onap.policy.controller.PolicyController;
-import org.onap.policy.daoImp.CommonClassDaoImpl;
 import org.onap.policy.rest.jpa.OnapName;
 import org.onap.policy.rest.jpa.PolicyEntity;
+import org.onap.policy.rest.jpa.PolicyRoles;
 import org.onap.policy.rest.jpa.PolicyVersion;
 import org.onap.policy.rest.jpa.SystemLogDB;
 import org.onap.policy.rest.jpa.UserInfo;
@@ -392,11 +396,49 @@ public class CommonClassDaoImplTest{
                        fail();
                }
        }
+       
+       @Test
+       public void testCommonClassDaoImplMethods(){
+               try{
+                       UserInfo userInfo = new UserInfo();
+                       userInfo.setUserLoginId("TestID");
+                       userInfo.setUserName("Test");
+                       commonClassDao.save(userInfo);
+                       List<Object> data = commonClassDao.getDataById(UserInfo.class, "userLoginId:userName", "TestID:Test");
+                       assertTrue(data.size() == 1);
+                       UserInfo userInfoUpdate = (UserInfo) data.get(0);
+                       userInfoUpdate.setUserName("Test1");
+                       commonClassDao.update(userInfoUpdate);
+                       List<String> data1 = commonClassDao.getDataByColumn(UserInfo.class, "userLoginId");
+                       assertTrue(data1.size() == 1);
+                       UserInfo data2 = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId:userName", "TestID:Test1");
+                       assertTrue("TestID".equals(data2.getUserLoginId()));
+                       List<Object> data3 = commonClassDao.checkDuplicateEntry("TestID:Test1", "userLoginId:userName", UserInfo.class);
+                       assertTrue(data3.size() == 1);
+                       PolicyRoles roles = new PolicyRoles();
+                       roles.setRole("admin");
+                       roles.setLoginId(userInfo);
+                       roles.setScope("test");
+                       commonClassDao.save(roles);
+                       List<PolicyRoles> roles1 = commonClassDao.getUserRoles();
+                       assertTrue(roles1.size() == 1);
+                       List<String> multipleData = new ArrayList<>();
+                       multipleData.add("TestID:Test1");
+                       List<Object> data4 = commonClassDao.getMultipleDataOnAddingConjunction(UserInfo.class, "userLoginId:userName", multipleData);
+                       assertTrue(data4.size() == 1);
+                       commonClassDao.delete(data2);
+               }catch(Exception e){
+                       logger.debug("Exception Occured"+e);
+                       fail();
+               }
+       }
+       
 
+       
        @Test
        public final void testGetLoggingData() {
                SystemLogDbDaoImpl system = new SystemLogDbDaoImpl();
-               SystemLogDbDaoImpl.setjUnit(true);
+               PolicyController.setjUnit(true);
                try{
                        assertTrue(system.getLoggingData() != null);
                }catch(Exception e){
@@ -407,7 +449,7 @@ public class CommonClassDaoImplTest{
        @Test
        public final void testGetSystemAlertData() {
                SystemLogDbDaoImpl system = new SystemLogDbDaoImpl();
-               SystemLogDbDaoImpl.setjUnit(true);
+               PolicyController.setjUnit(true);
                try{
                        assertTrue(system.getSystemAlertData() != null);
                }catch(Exception e){
diff --git a/POLICY-SDK-APP/src/test/resources/test.properties b/POLICY-SDK-APP/src/test/resources/test.properties
new file mode 100644 (file)
index 0000000..e882dfd
--- /dev/null
@@ -0,0 +1,21 @@
+###
+# ============LICENSE_START=======================================================
+# ONAP Policy Engine
+# ================================================================================
+# 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=========================================================
+###
+
+PDP_URL=http://localhost:8082/pdp/, testpdp, alpha456;http://localhost:8081/pdp/, testpdp, alpha456
index 0f285b6..333da49 100644 (file)
@@ -87,8 +87,8 @@ xacml.log.db.password=policy_user
 
 xacml.att.log.timeframe=150
 
-javax.persistence.jdbc.driver=com.mysql.jdbc.Driver
-javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/onap_sdk
+javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver
+javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk
 javax.persistence.jdbc.user=policy_user
 javax.persistence.jdbc.password=policy_user
 
index afc3d0d..c5187c0 100644 (file)
@@ -61,8 +61,8 @@ public class testBackUpMonitor {
        @Test (expected = PersistenceException.class)
        public void backUpMonitorTestFail() throws Exception{
                Properties properties = new Properties();
-               properties.setProperty("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
-               properties.setProperty("javax.persistence.jdbc.url", "jdbc:mysql://localhost:3306/xacml");
+               properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+               properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
                properties.setProperty("javax.persistence.jdbc.user", "policy_user");
                properties.setProperty("javax.persistence.jdbc.password", "");
                BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test" , properties, new Handler());
@@ -71,8 +71,8 @@ public class testBackUpMonitor {
        @Test
        public void backUpMonitorTestFailNoUser() throws Exception{
                Properties properties = new Properties();
-               properties.setProperty("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
-               properties.setProperty("javax.persistence.jdbc.url", "jdbc:mysql://localhost:3306/xacml");
+               properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+               properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
                properties.setProperty("javax.persistence.jdbc.user", "");
                properties.setProperty("javax.persistence.jdbc.password", "password");
                BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test" , properties, new Handler());
@@ -82,7 +82,7 @@ public class testBackUpMonitor {
        @Test
        public void backUpMonitorTestFailNoURL() throws Exception{
                Properties properties = new Properties();
-               properties.setProperty("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
+               properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
                properties.setProperty("javax.persistence.jdbc.url", "");
                properties.setProperty("javax.persistence.jdbc.user", "test");
                properties.setProperty("javax.persistence.jdbc.password", "password");
@@ -95,7 +95,7 @@ public class testBackUpMonitor {
        public void backUpMonitorTestFailNoDriver() throws Exception{
                Properties properties = new Properties();
                properties.setProperty("javax.persistence.jdbc.driver", "");
-               properties.setProperty("javax.persistence.jdbc.url", "jdbc:mysql://localhost:3306/xacml");
+               properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
                properties.setProperty("javax.persistence.jdbc.user", "test");
                properties.setProperty("javax.persistence.jdbc.password", "password");
                properties.setProperty("ping_interval", "500");
@@ -106,8 +106,8 @@ public class testBackUpMonitor {
        @Test
        public void backUpMonitorTestFailNoNode() throws Exception{
                Properties properties = new Properties();
-               properties.setProperty("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
-               properties.setProperty("javax.persistence.jdbc.url", "jdbc:mysql://localhost:3306/xacml");
+               properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+               properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
                properties.setProperty("javax.persistence.jdbc.user", "test");
                properties.setProperty("javax.persistence.jdbc.password", "password");
                properties.setProperty("ping_interval", "");
@@ -118,8 +118,8 @@ public class testBackUpMonitor {
        @Test
        public void backUpMonitorTestFailNoResource() throws Exception{
                Properties properties = new Properties();
-               properties.setProperty("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
-               properties.setProperty("javax.persistence.jdbc.url", "jdbc:mysql://localhost:3306/xacml");
+               properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+               properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
                properties.setProperty("javax.persistence.jdbc.user", "test");
                properties.setProperty("javax.persistence.jdbc.password", "password");
                BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), null , properties, new Handler());
@@ -135,8 +135,8 @@ public class testBackUpMonitor {
        @Test
        public void backUpMonitorTestFailNoHandler() throws Exception{
                Properties properties = new Properties();
-               properties.setProperty("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
-               properties.setProperty("javax.persistence.jdbc.url", "jdbc:mysql://localhost:3306/xacml");
+               properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+               properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
                properties.setProperty("javax.persistence.jdbc.user", "test");
                properties.setProperty("javax.persistence.jdbc.password", "password");
                properties.setProperty("ping_interval", "500");
index 92c6d90..cd08d4a 100644 (file)
@@ -2,9 +2,9 @@ JAVA_HOME=/usr/lib/jvm/java-8-oracle
 POLICY_HOME=/opt/app/policy
 KEYSTORE_PASSWD=PolicyR0ck$
 
-JDBC_DRIVER=com.mysql.jdbc.Driver
-JDBC_URL=jdbc:mysql://localhost:3306/xacml
-JDBC_LOG_URL=jdbc:mysql://localhost:3306/log
+JDBC_DRIVER=org.mariadb.jdbc.Driver
+JDBC_URL=jdbc:mariadb://localhost:3306/onap_sdk
+JDBC_LOG_URL=jdbc:mariadb://localhost:3306/log
 JDBC_USER=policy_user
 JDBC_PASSWORD=