diff options
author | 2017-09-19 22:06:26 -0400 | |
---|---|---|
committer | 2017-09-19 22:07:18 -0400 | |
commit | a342c15e49481499ee224c205227c28c370a0a27 (patch) | |
tree | a61e54050b18d50685d56a145c28c5a9875ae08f /POLICY-SDK-APP/src/main/java/org/onap | |
parent | e64508463caed53e661e4e02e1de971b21f642a7 (diff) |
Added Junits for POLICY-SDK-APP
Issue-Id: POLICY-52
Change-Id: Ic13cc5a6a32e65e301f1dcdc437f1de8ba6c00d8
Signed-off-by: rb7147 <rb7147@att.com>
Diffstat (limited to 'POLICY-SDK-APP/src/main/java/org/onap')
5 files changed, 83 insertions, 10 deletions
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java index a99d23ed5..4f42023c9 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java @@ -91,6 +91,16 @@ import com.fasterxml.jackson.databind.ObjectMapper; 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 @@ -531,7 +541,12 @@ public class PolicyManagerServlet extends HttpServlet { SimpleBindings peParams = new SimpleBindings(); peParams.put("split_1", split[1]); peParams.put("split_0", split[0]); - List<Object> queryData = controller.getDataByQuery(query, peParams); + List<Object> queryData = null; + if(jUnit){ + queryData = controller.getDataByQuery(query, null); + }else{ + queryData = controller.getDataByQuery(query, peParams); + } if(!queryData.isEmpty()){ PolicyEntity entity = (PolicyEntity) queryData.get(0); File temp = null; @@ -668,7 +683,12 @@ public class PolicyManagerServlet extends HttpServlet { params.put("scopeName", scopeName + "%"); } PolicyController controller = getPolicyControllerInstance(); - List<Object> scopesList = controller.getDataByQuery(scopeNamequery, params); + List<Object> scopesList = null; + if(jUnit){ + scopesList = controller.getDataByQuery(scopeNamequery, null); + }else{ + scopesList = controller.getDataByQuery(scopeNamequery, params); + } return scopesList; } @@ -687,8 +707,15 @@ public class PolicyManagerServlet extends HttpServlet { SimpleBindings params = new SimpleBindings(); params.put("scopeName", scopeName + "%"); - List<Object> activePolicies = controller.getDataByQuery(query, params); - List<Object> scopesList = controller.getDataByQuery(scopeNamequery, params); + List<Object> activePolicies = null; + List<Object> scopesList = null; + if(jUnit){ + activePolicies = controller.getDataByQuery(query, null); + scopesList = controller.getDataByQuery(scopeNamequery, null); + }else{ + activePolicies = controller.getDataByQuery(query, params); + scopesList = controller.getDataByQuery(scopeNamequery, params); + } for(Object list : scopesList){ PolicyEditorScopes scopeById = (PolicyEditorScopes) list; String scope = scopeById.getScopeName(); @@ -1394,7 +1421,12 @@ public class PolicyManagerServlet extends HttpServlet { SimpleBindings peParams = new SimpleBindings(); peParams.put("split_1", split[1]); peParams.put("split_0", split[0]); - List<Object> queryData = controller.getDataByQuery(query, peParams); + List<Object> queryData = null; + if(jUnit){ + queryData = controller.getDataByQuery(query, null); + }else{ + queryData = controller.getDataByQuery(query, peParams); + } PolicyEntity entity = (PolicyEntity) queryData.get(0); InputStream stream = new ByteArrayInputStream(entity.getPolicyData().getBytes(StandardCharsets.UTF_8)); diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyUserInfoController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyUserInfoController.java index 65312a957..5020662c8 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyUserInfoController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyUserInfoController.java @@ -44,7 +44,7 @@ public class PolicyUserInfoController extends RestrictedBaseController{ private static final Logger LOGGER = FlexLogger.getLogger(PolicyUserInfoController.class); @RequestMapping(value="/get_PolicyUserInfo", method = RequestMethod.GET) - private void getPolicyUserInfo(HttpServletRequest request, HttpServletResponse response){ + public void getPolicyUserInfo(HttpServletRequest request, HttpServletResponse response){ JsonMessage msg = null; try { String userId = UserUtils.getUserSession(request).getOrgUserId(); diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/conf/HibernateSession.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/conf/HibernateSession.java index d70f199f0..353e08a44 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/conf/HibernateSession.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/conf/HibernateSession.java @@ -59,5 +59,9 @@ public class HibernateSession{ public static Session getSession(){ return logSessionFactory.openSession(); } + + public static void setSession(SessionFactory logSessionFactory1){ + logSessionFactory = logSessionFactory1; + } } diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyController.java index eac06a7b4..321dc72d2 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyController.java @@ -143,6 +143,17 @@ public class PolicyController extends RestrictedBaseController { //WebApp directories private static String configHome; private static String actionHome; + + private static boolean jUnit = false; + + + public static boolean isjUnit() { + return jUnit; + } + + public static void setjUnit(boolean jUnit) { + PolicyController.jUnit = jUnit; + } @Autowired private PolicyController(CommonClassDao commonClassDao){ @@ -157,7 +168,12 @@ public class PolicyController extends RestrictedBaseController { Properties prop = new Properties(); InputStream input = null; try { - input = new FileInputStream("xacml.admin.properties"); + if(jUnit){ + File file = new File(new File(".").getCanonicalPath() + File.separator + "src"+ File.separator + "test" + File.separator + "resources" + File.separator + "JSONConfig.json"); + input = new FileInputStream(file); + }else{ + input = new FileInputStream("xacml.admin.properties"); + } // load a properties file prop.load(input); //pap url @@ -350,7 +366,7 @@ public class PolicyController extends RestrictedBaseController { } public static boolean getActivePolicy(String query) { - if(commonClassDao.getDataByQuery(query, new SimpleBindings()).size() > 0){ + if(!commonClassDao.getDataByQuery(query, new SimpleBindings()).isEmpty()){ return true; }else{ return false; diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/daoImp/SystemLogDbDaoImpl.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/daoImp/SystemLogDbDaoImpl.java index 4fa64ceb3..49024ba0d 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/daoImp/SystemLogDbDaoImpl.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/daoImp/SystemLogDbDaoImpl.java @@ -42,6 +42,17 @@ import org.onap.policy.common.logging.flexlogger.Logger; @Service("SystemLogDbDao") 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() { @@ -49,7 +60,12 @@ public class SystemLogDbDaoImpl implements SystemLogDbDao { Transaction tx = session.beginTransaction(); List<SystemLogDB> system = null; try { - String sqlWhere = "date > DATE_SUB(curdate(), INTERVAL 5 DAY) ORDER BY date DESC limit "+PolicyController.getLogTableLimit()+""; + String sqlWhere = null; + if(jUnit){ + sqlWhere = ""; + }else{ + sqlWhere = "date > DATE_SUB(curdate(), INTERVAL 5 DAY) ORDER BY date DESC limit "+PolicyController.getLogTableLimit()+""; + } Criteria cr = session.createCriteria(SystemLogDB.class); cr.add(Restrictions.sqlRestriction(sqlWhere)); system = cr.list(); @@ -73,7 +89,12 @@ public class SystemLogDbDaoImpl implements SystemLogDbDao { Transaction tx = session.beginTransaction(); List<SystemLogDB> system = null; try { - String sqlWhere = "date > DATE_SUB(curdate(), INTERVAL 5 DAY) and logtype = 'error' ORDER BY date DESC limit "+PolicyController.getSystemAlertTableLimit()+""; + String sqlWhere = null; + if(jUnit){ + sqlWhere = ""; + }else{ + sqlWhere = "date > DATE_SUB(curdate(), INTERVAL 5 DAY) and logtype = 'error' ORDER BY date DESC limit "+PolicyController.getSystemAlertTableLimit()+""; + } Criteria cr = session.createCriteria(SystemLogDB.class); cr.add(Restrictions.sqlRestriction(sqlWhere)); system = cr.list(); |