aboutsummaryrefslogtreecommitdiffstats
path: root/POLICY-SDK-APP/src
diff options
context:
space:
mode:
Diffstat (limited to 'POLICY-SDK-APP/src')
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java42
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyUserInfoController.java2
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyController.java20
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/daoImp/SystemLogDbDaoImpl.java25
-rw-r--r--POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java40
-rw-r--r--POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyUserInfoControllerTest.java64
-rw-r--r--POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java29
-rw-r--r--POLICY-SDK-APP/src/test/java/org/onap/policy/daoImp/CommonClassDaoImplTest.java47
-rw-r--r--POLICY-SDK-APP/src/test/resources/xacml.admin.properties203
9 files changed, 440 insertions, 32 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/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();
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java
index a034c8ae9..970b67878 100644
--- a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java
+++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java
@@ -28,7 +28,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import javax.script.SimpleBindings;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -147,11 +146,12 @@ 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);
- when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_SampleTest1206.1.xml' and scope ='com'", new SimpleBindings())).thenReturn(basePolicyData);
+ String query = "FROM PolicyEntity where policyName = :split_1 and scope = :split_0";
+ when(controller.getDataByQuery(query, null)).thenReturn(basePolicyData);
servlet.setPolicyController(controller);
servlet.doPost(request, response);
} catch (Exception e1) {
@@ -168,6 +168,7 @@ 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}}");
@@ -176,9 +177,9 @@ public class PolicyManagerServletTest extends Mockito{
try {
when(request.getReader()).thenReturn(reader);
when(controller.getRoles("Test")).thenReturn(rolesdata);
- when(controller.getDataByQuery("from PolicyEditorScopes", new SimpleBindings())).thenReturn(policyEditorScopes);
- when(controller.getDataByQuery("from PolicyEditorScopes where SCOPENAME like 'com%'", new SimpleBindings())).thenReturn(policyEditorScopes);
- when(controller.getDataByQuery("from PolicyVersion where POLICY_NAME like 'com%'", new SimpleBindings())).thenReturn(policyVersion);
+ when(controller.getDataByQuery("from PolicyEditorScopes", null)).thenReturn(policyEditorScopes);
+ when(controller.getDataByQuery("from PolicyEditorScopes where SCOPENAME like :scopeName", null)).thenReturn(policyEditorScopes);
+ when(controller.getDataByQuery("from PolicyVersion where POLICY_NAME like :scopeName", null)).thenReturn(policyVersion);
servlet.setPolicyController(controller);
servlet.setTestUserId("Test");
servlet.doPost(request, response);
@@ -196,6 +197,7 @@ 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++){
@@ -203,7 +205,7 @@ public class PolicyManagerServletTest extends Mockito{
try {
when(request.getReader()).thenReturn(reader);
when(controller.getRoles("Test")).thenReturn(rolesdata);
- when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_SampleTest1206.1.xml' and scope ='com'", new SimpleBindings())).thenReturn(basePolicyData);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = :split_1 and scope = :split_0", null)).thenReturn(basePolicyData);
servlet.setPolicyController(controller);
servlet.setTestUserId("Test");
servlet.doPost(request, response);
@@ -242,6 +244,7 @@ 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++){
@@ -249,7 +252,7 @@ public class PolicyManagerServletTest extends Mockito{
try {
when(request.getReader()).thenReturn(reader);
when(controller.getRoles("Test")).thenReturn(rolesdata);
- when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml' and scope ='com'", new SimpleBindings())).thenReturn(policyData);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = :split_1 and scope = :split_0", null)).thenReturn(policyData);
servlet.setPolicyController(controller);
servlet.setTestUserId("Test");
servlet.doPost(request, response);
@@ -288,6 +291,7 @@ 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++){
@@ -295,7 +299,7 @@ public class PolicyManagerServletTest extends Mockito{
try {
when(request.getReader()).thenReturn(reader);
when(controller.getRoles("Test")).thenReturn(rolesdata);
- when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_BRMS_Raw_TestBRMSRawPolicy.1.xml' and scope ='com'", new SimpleBindings())).thenReturn(policyData);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = :split_1 and scope = :split_0", null)).thenReturn(policyData);
servlet.setPolicyController(controller);
servlet.setTestUserId("Test");
servlet.doPost(request, response);
@@ -334,6 +338,7 @@ 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++){
@@ -341,7 +346,7 @@ public class PolicyManagerServletTest extends Mockito{
try {
when(request.getReader()).thenReturn(reader);
when(controller.getRoles("Test")).thenReturn(rolesdata);
- when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_Fault_TestClosedLoopPolicy.1.xml' and scope ='com'", new SimpleBindings())).thenReturn(policyData);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = :split_1 and scope = :split_0", null)).thenReturn(policyData);
servlet.setPolicyController(controller);
servlet.setTestUserId("Test");
servlet.doPost(request, response);
@@ -380,6 +385,7 @@ 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++){
@@ -387,7 +393,7 @@ public class PolicyManagerServletTest extends Mockito{
try {
when(request.getReader()).thenReturn(reader);
when(controller.getRoles("Test")).thenReturn(rolesdata);
- when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_PM_TestClosedLoopPMPolicy.1.xml' and scope ='com'", new SimpleBindings())).thenReturn(policyData);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = :split_1 and scope = :split_0", null)).thenReturn(policyData);
servlet.setPolicyController(controller);
servlet.setTestUserId("Test");
servlet.doPost(request, response);
@@ -433,6 +439,7 @@ 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++){
@@ -441,7 +448,7 @@ public class PolicyManagerServletTest extends Mockito{
when(request.getReader()).thenReturn(reader);
when(commonClassDao.getDataById(GroupPolicyScopeList.class, "groupList", "resource=SampleResource,service=SampleService,type=SampleType,closedLoopControlName=SampleClosedLoop")).thenReturn(groupListData);
when(controller.getRoles("Test")).thenReturn(rolesdata);
- when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_MS_vFirewall.1.xml' and scope ='com'", new SimpleBindings())).thenReturn(policyData);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = :split_1 and scope = :split_0", null)).thenReturn(policyData);
servlet.setPolicyController(controller);
servlet.setTestUserId("Test");
servlet.doPost(request, response);
@@ -480,6 +487,7 @@ 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++){
@@ -487,7 +495,7 @@ public class PolicyManagerServletTest extends Mockito{
try {
when(request.getReader()).thenReturn(reader);
when(controller.getRoles("Test")).thenReturn(rolesdata);
- when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_FW_TestFireWallPolicy.1.xml' and scope ='com'", new SimpleBindings())).thenReturn(policyData);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = :split_1 and scope = :split_0", null)).thenReturn(policyData);
servlet.setPolicyController(controller);
servlet.setTestUserId("Test");
servlet.doPost(request, response);
@@ -524,6 +532,7 @@ 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++){
@@ -531,7 +540,7 @@ public class PolicyManagerServletTest extends Mockito{
try {
when(request.getReader()).thenReturn(reader);
when(controller.getRoles("Test")).thenReturn(rolesdata);
- when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Action_TestActionPolicy.1.xml' and scope ='com'", new SimpleBindings())).thenReturn(policyData);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = :split_1 and scope = :split_0", null)).thenReturn(policyData);
servlet.setPolicyController(controller);
servlet.setTestUserId("Test");
servlet.doPost(request, response);
@@ -562,6 +571,7 @@ 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++){
@@ -569,7 +579,7 @@ public class PolicyManagerServletTest extends Mockito{
try {
when(request.getReader()).thenReturn(reader);
when(controller.getRoles("Test")).thenReturn(rolesdata);
- when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Decision_TestDecisionPolicyWithRuleAlgorithms.1.xml' and scope ='com'", new SimpleBindings())).thenReturn(policyData);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = :split_1 and scope = :split_0", null)).thenReturn(policyData);
servlet.setPolicyController(controller);
servlet.setTestUserId("Test");
servlet.doPost(request, response);
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyUserInfoControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyUserInfoControllerTest.java
new file mode 100644
index 000000000..4931d20d7
--- /dev/null
+++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyUserInfoControllerTest.java
@@ -0,0 +1,64 @@
+/*-
+ * ============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 javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.portalsdk.core.domain.User;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+public class PolicyUserInfoControllerTest {
+
+ private HttpServletRequest request;
+ private MockHttpServletResponse response;
+
+ @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);
+ }
+
+ @Test
+ public final void testGetPolicyUserInfo() {
+ PolicyUserInfoController controller = new PolicyUserInfoController();
+ controller.getPolicyUserInfo(request, response);
+ try{
+ assertTrue(response.getStatus() == 200);
+ }catch(Exception e){
+ fail();
+ }
+
+ }
+
+}
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java
index 382637c1b..6f20a6770 100644
--- a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java
+++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java
@@ -19,6 +19,8 @@
*/
package org.onap.policy.controller;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -33,6 +35,8 @@ import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.rest.dao.CommonClassDao;
+import org.onap.policy.rest.jpa.Datatype;
+import org.onap.policy.rest.jpa.FunctionDefinition;
import org.onap.policy.rest.jpa.PolicyEntity;
public class PolicyControllerTest {
@@ -44,6 +48,7 @@ public class PolicyControllerTest {
public void setUp() throws Exception{
logger.info("setUp: Entering");
commonClassDao = mock(CommonClassDao.class);
+ PolicyController.setCommonClassDao(commonClassDao);
List<Object> data = new ArrayList<>();
String policyData = "";
try {
@@ -57,12 +62,30 @@ public class PolicyControllerTest {
entity.setPolicyData(policyData);
entity.setScope("com");
data.add(entity);
-
+
when(commonClassDao.getDataByQuery("FROM PolicyEntity where policyName = 'Config_SampleTest1206.1.xml' and scope ='com'", new SimpleBindings())).thenReturn(data);
+
+ FunctionDefinition fnDefinition = new FunctionDefinition();
+ fnDefinition.setXacmlid("Test");
+ fnDefinition.setShortname("Test");
+ Datatype dataType = new Datatype();
+ dataType.setXacmlId("Test");
+ fnDefinition.setDatatypeBean(dataType);
+ List<Object> fnObjects = new ArrayList<>();
+ fnObjects.add(fnDefinition);
+ when(commonClassDao.getData(FunctionDefinition.class)).thenReturn(fnObjects);
}
@Test
- public void dummy(){
- System.out.println("Dummy");
+ public void testInit(){
+ PolicyController controller = new PolicyController();
+ PolicyController.setjUnit(true);
+ controller.init();
+ try{
+ assertTrue(PolicyController.dropDownMap.size() > 0);
+ }catch(Exception e){
+ logger.error("Exception Occured"+e);
+ fail();
+ }
}
}
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/daoImp/CommonClassDaoImplTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/daoImp/CommonClassDaoImplTest.java
index 78dd20af2..d4b0c650b 100644
--- a/POLICY-SDK-APP/src/test/java/org/onap/policy/daoImp/CommonClassDaoImplTest.java
+++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/daoImp/CommonClassDaoImplTest.java
@@ -37,10 +37,13 @@ import org.junit.Before;
import org.junit.Test;
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.PolicyVersion;
+import org.onap.policy.rest.jpa.SystemLogDB;
import org.onap.policy.rest.jpa.UserInfo;
import org.onap.policy.rest.jpa.WatchPolicyNotificationTable;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
@@ -79,7 +82,22 @@ public class CommonClassDaoImplTest{
// Set up dao with SessionFactory
commonClassDao = new CommonClassDaoImpl();
CommonClassDaoImpl.setSessionfactory(sessionFactory);
-
+ PolicyController.setLogTableLimit("1");
+ HibernateSession.setSession(sessionFactory);
+ SystemLogDB data1 = new SystemLogDB();
+ data1.setDate(new Date());
+ data1.setLogtype("INFO");
+ data1.setRemote("Test");
+ data1.setSystem("Test");
+ data1.setType("Test");
+ SystemLogDB data2 = new SystemLogDB();
+ data2.setDate(new Date());
+ data2.setLogtype("error");
+ data2.setRemote("Test");
+ data2.setSystem("Test");
+ data2.setType("Test");
+ HibernateSession.getSession().save(data1);
+ HibernateSession.getSession().save(data2);
// Create TCP server for troubleshooting
server = Server.createTcpServer("-tcpAllowOthers").start();
System.out.println("URL: jdbc:h2:" + server.getURL() + "/mem:test");
@@ -329,10 +347,10 @@ public class CommonClassDaoImplTest{
}
}
- /*
- * Test for SQL Injection Protection
- *
+
+ /* Test for SQL Injection Protection
*/
+
@Test
@Transactional
@Rollback(true)
@@ -375,6 +393,27 @@ public class CommonClassDaoImplTest{
}
}
+ @Test
+ public final void testGetLoggingData() {
+ SystemLogDbDaoImpl system = new SystemLogDbDaoImpl();
+ SystemLogDbDaoImpl.setjUnit(true);
+ try{
+ assertTrue(system.getLoggingData() != null);
+ }catch(Exception e){
+ fail();
+ }
+ }
+
+ @Test
+ public final void testGetSystemAlertData() {
+ SystemLogDbDaoImpl system = new SystemLogDbDaoImpl();
+ SystemLogDbDaoImpl.setjUnit(true);
+ try{
+ assertTrue(system.getSystemAlertData() != null);
+ }catch(Exception e){
+ fail();
+ }
+ }
@After
public void deleteDB(){
diff --git a/POLICY-SDK-APP/src/test/resources/xacml.admin.properties b/POLICY-SDK-APP/src/test/resources/xacml.admin.properties
new file mode 100644
index 000000000..0f285b694
--- /dev/null
+++ b/POLICY-SDK-APP/src/test/resources/xacml.admin.properties
@@ -0,0 +1,203 @@
+###
+# ============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=========================================================
+###
+
+#
+# This file is set to the defaults one can use to run the XACML-PAP-ADMIN for testing and development.
+#
+# It is not recommended to modify this file directly, but rather copy it to another location and make any modifications
+# necessary to run the application in a development or a production environment. You can set the Java VM System
+# property to change where the application can find the file. For example:
+#
+#-Dxacml.properties=/opt/app/xacml/etc/xacml.admin.properties
+#
+#
+# Standard API Factories
+#
+xacml.dataTypeFactory=com.att.research.xacml.std.StdDataTypeFactory
+xacml.pdpEngineFactory=com.att.research.xacmlatt.pdp.ATTPDPEngineFactory
+xacml.pepEngineFactory=com.att.research.xacml.std.pep.StdEngineFactory
+xacml.pipFinderFactory=com.att.research.xacml.std.pip.StdPIPFinderFactory
+#
+# AT&T PDP Implementation Factories
+#
+xacml.att.evaluationContextFactory=com.att.research.xacmlatt.pdp.std.StdEvaluationContextFactory
+xacml.att.combiningAlgorithmFactory=com.att.research.xacmlatt.pdp.std.StdCombiningAlgorithmFactory
+xacml.att.functionDefinitionFactory=org.onap.policy.xacml.custom.OnapFunctionDefinitionFactory
+xacml.att.policyFinderFactory=com.att.research.xacmlatt.pdp.std.StdPolicyFinderFactory
+
+#
+# This is an extremely simple policy to demonstrate authorization
+# within the Admin Console.
+#
+xacml.rootPolicies=admin
+#
+# PAP Servlet properties
+#
+xacml.PAP.papEngineFactory=org.onap.policy.xacml.std.pap.StdEngineFactory
+
+#
+# Admin Console properties
+#
+xacml.AC.papEngineFactory=org.onap.policy.xacml.admin.util.RESTfulPAPFactory
+
+# Set your domain here:
+xacml.rest.admin.domain=com
+#
+#
+# Property to declare the max time frame for logs.
+#
+xacml.log.timeframe=30
+#
+#
+#
+xacml.rest.admin.closedLoopJSON =JSONConfig.json
+xacml.rest.admin.microServiceModel=model.properties
+xacm.restful.interface.file=RESTful.interface.properties
+#
+#If the Audit is set false, then Audit function will not work at the Server Run time.
+#This will Syncronize the data between Roles and Userinfo Table
+xacml.audit.userInfo = true
+#
+#The Test Environment User Login LoginIU Should provide below on seperating with Comma
+#
+xacml.testEnvironment.loginId =
+
+#Log DB properties
+xacml.log.db.driver=org.mariadb.jdbc.Driver
+xacml.log.db.url=jdbc:mariadb://localhost:3306/log?failOverReadOnly=false&autoReconnect=true
+xacml.log.db.user=policy_user
+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.user=policy_user
+javax.persistence.jdbc.password=policy_user
+
+# Dashboard refresh rate in miliseconds
+xacml.refresh.rate=40000
+xacml.user.column.count=3
+xacml.sqlcontainer.page.length=75
+xacm.xcor.required.pattern=1,1
+xacm.cache.live.time=2
+xacml.max.priority.count=10
+
+#
+# These can be set so the Admin Console knows who is logged on. Ideally, you can run the console in a J2EE
+# container and setup authentication as you please. Setting HttpSession attribute values will override these
+# values set in the properties files.
+#
+# ((HttpServletRequest) request).getSession().setAttribute("xacml.rest.admin.user.name", "Homer");
+#
+# The default policy: Policy-Admin.xml is extremely simple.
+#
+# You can test authorization within the Admin Console by changing the user id.
+# There are 3 supported user ids:
+# guest - Read only access
+# editor - Read/Write access
+# admin - Read/Write/Admin access
+#
+# An empty or null value for xacml.rest.admin.user.id results in no access to the application at all.
+#
+# This is for development/demonstration purposes only. A production environment should provide authentication which is
+# outside the scope of this application. This application can be used to develop a XACML policy for user authorization
+# within this application.
+#
+#xacml.rest.admin.user.name=Guest
+#xacml.rest.admin.user.id=guest
+#xacml.rest.admin.user.name=Editor
+#xacml.rest.admin.user.id=editor
+xacml.rest.admin.user.name=Administrator
+xacml.rest.admin.user.id=super-admin
+xacml.rest.admin.user.email=
+
+#
+# URL location for the PAP servlet.
+#
+xacml.rest.pap.url=http://localhost:8070/pap/
+
+# id PAP
+xacml.rest.pap.userid=testpap
+# pass PAP
+xacml.rest.pap.password=alpha123
+
+# new Property Please mention your PAP-REST webapps Location here.
+
+xacml.rest.config.webapps=/home/users/PolicyEngine/webapps/ConfigPAP/
+
+# pdps file - Needs to have the location of the PDPs File of the PAP-REST
+xacml.rest.pdp.idfile=test.properties
+
+#Template Versions
+xacml.rest.closedLoopFault=OpenSource.version.1
+xacml.rest.closedLoopPM=OpenSource.version.1
+xacml.rest.microServices=OpenSource.version.1
+xacml.rest.gocPolicy=OpenSource.version.1
+xacml.rest.firewallPolicy=OpenSource.version.1
+
+#***Properties for IntegrityMonitor integration defined in XACMLRestProperties.java***
+
+#The name of the Admin. Must be unique across the system
+xacml.rest.admin.resource.name=site_1.admin_1
+
+#The site name for the Admin
+site_name=site_1
+
+#Has to be one of pdp_xacml, pdp_drools, pap, pap_admin, logparser, brms_gateway, astra_gateway, elk_server
+node_type=pap_admin
+
+# The (optional) period of time in seconds between executions of the integrity audit.
+# Value < 0 : Audit does not run (default value if property is not present = -1)
+# Value = 0 : Audit runs continuously
+# Value > 0 : The period of time in seconds between execution of the audit on a particular node
+integrity_audit_period_seconds=-1
+
+#Automatic Policy Distribution
+xacml.att.automatic.push = false
+
+
+#Dashboard Tab Limit
+xacml.onap.dashboard.logTableLimit = 5000
+xacml.onap.dashboard.systemAlertTableLimit = 2000
+
+
+#Diff of policies for Firewall feature
+FW_GETURL=https://todo_enter_the_firewallurl
+FW_AUTHOURL=https://todo_enter_the_firewallAuthurl
+FW_PROXY=todo_enter_the_proxy
+FW_PORT=8080
+
+#SMTP Server Details for Java Mail
+onap.smtp.host = smtp_host
+onap.smtp.port = smtp_port
+onap.smtp.userName = smtp_username
+onap.smtp.password = smtp_password
+onap.smtp.emailExtension=smtp_emailExtension
+onap.application.name = smtp_AppName
+
+#Dialect for Database
+onap.dialect = org.hibernate.dialect.MySQLDialect
+
+policyAdapter.impl.className = org.onap.policy.admin.PolicyAdapter
+
+#Micro Service Model Properties
+xacml.policy.msOnapName=http://org.onap
+xacml.policy.msPolicyName=http://org.onap.policy \ No newline at end of file