summaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src
diff options
context:
space:
mode:
authorrb7147 <rb7147@att.com>2018-02-09 14:30:14 -0500
committerrb7147 <rb7147@att.com>2018-02-09 16:27:02 -0500
commita09137c40e602197cbf3b1430d8e33d085357730 (patch)
tree5f2fec8489097fc702103df51209b29388294099 /ONAP-PAP-REST/src
parent7f09be3758d5797c22682686bad9281516cfe5a1 (diff)
Added Junits for ONAP-PAP-REST
Cleaned up unused imports. Cleaned up unused code. Added Junits for Dictionary controllers. Issue-ID: POLICY-338 Change-Id: If29b934e95fdaf60dcf82300a95a23ac3c980419 Signed-off-by: rb7147 <rb7147@att.com>
Diffstat (limited to 'ONAP-PAP-REST/src')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java28
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java6
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java41
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/EnforcerDictionaryController.java143
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java8
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/DictionaryService.java16
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryControllerTest.java157
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java584
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryControllerTest.java163
9 files changed, 947 insertions, 199 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java
index 5c9b2b883..02b0707b6 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PAP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -61,6 +61,10 @@ public class ActionPolicyDictionaryController {
public ActionPolicyDictionaryController(CommonClassDao commonClassDao){
ActionPolicyDictionaryController.commonClassDao = commonClassDao;
}
+
+ public void setCommonClassDao(CommonClassDao commonClassDao){
+ ActionPolicyDictionaryController.commonClassDao = commonClassDao;
+ }
/*
* This is an empty constructor
*/
@@ -124,8 +128,8 @@ public class ActionPolicyDictionaryController {
String userId = null;
if(fromAPI) {
- actionPolicyDict = (ActionPolicyDict)mapper.readValue(root.get("dictionaryFields").toString(), ActionPolicyDict.class);
- adapter = (ActionAdapter)mapper.readValue(root.get("dictionaryFields").toString(), ActionAdapter.class);
+ actionPolicyDict = mapper.readValue(root.get("dictionaryFields").toString(), ActionPolicyDict.class);
+ adapter = mapper.readValue(root.get("dictionaryFields").toString(), ActionAdapter.class);
userId = "API";
//check if update operation or create, get id for data to be updated and update attributeData
@@ -142,11 +146,11 @@ public class ActionPolicyDictionaryController {
actionPolicyDict.setUserCreatedBy(this.getUserInfo(userId));
}
} else {
- actionPolicyDict = (ActionPolicyDict)mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionPolicyDict.class);
+ actionPolicyDict = mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionPolicyDict.class);
adapter = mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionAdapter.class);
userId = root.get("userid").textValue();
}
- String header = "";
+ StringBuilder header = new StringBuilder();
int counter = 0;
if(!adapter.getHeaders().isEmpty()){
for(Object attribute : adapter.getHeaders()){
@@ -154,15 +158,14 @@ public class ActionPolicyDictionaryController {
String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
String value = ((LinkedHashMap<?, ?>) attribute).get("number").toString();
if(counter>0){
- header = header + ":";
+ header.append(":");
}
- header = header + key + "=";
- header = header + value;
+ header.append(key).append("=").append(value);
counter ++;
}
}
}
- actionPolicyDict.setHeader(header);
+ actionPolicyDict.setHeader(header.toString());
if(actionPolicyDict.getId() == 0){
List<Object> duplicateData = commonClassDao.checkDuplicateEntry(actionPolicyDict.getAttributeName(), attributeName, ActionPolicyDict.class);
if(!duplicateData.isEmpty()){
@@ -222,12 +225,12 @@ public class ActionPolicyDictionaryController {
}
@RequestMapping(value={"/action_dictionary/remove_actionPolicyDict"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView removeActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ public void removeActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
try{
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JsonNode root = mapper.readTree(request.getReader());
- ActionPolicyDict actionPolicyDict = (ActionPolicyDict)mapper.readValue(root.get("data").toString(), ActionPolicyDict.class);
+ ActionPolicyDict actionPolicyDict = mapper.readValue(root.get("data").toString(), ActionPolicyDict.class);
commonClassDao.delete(actionPolicyDict);
response.setCharacterEncoding(utf8);
response.setContentType("application / json");
@@ -238,8 +241,6 @@ public class ActionPolicyDictionaryController {
String responseString = mapper.writeValueAsString(ActionPolicyDictionaryController.commonClassDao.getData(ActionPolicyDict.class));
JSONObject j = new JSONObject("{actionPolicyDictionaryDatas: " + responseString + "}");
out.write(j.toString());
-
- return null;
}
catch (Exception e){
LOGGER.error(e);
@@ -248,7 +249,6 @@ public class ActionPolicyDictionaryController {
PrintWriter out = response.getWriter();
out.write(e.getMessage());
}
- return null;
}
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java
index f359ca2cb..a55ed4004 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PAP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -88,6 +88,10 @@ public class ClosedLoopDictionaryController{
public ClosedLoopDictionaryController(CommonClassDao commonClassDao){
ClosedLoopDictionaryController.commonClassDao = commonClassDao;
}
+
+ public void setCommonClassDao(CommonClassDao commonClassDao){
+ ClosedLoopDictionaryController.commonClassDao = commonClassDao;
+ }
/*
* This is an empty constructor
*/
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java
index a12f17b50..b38351806 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PAP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -64,15 +64,20 @@ public class DescriptiveDictionaryController {
DescriptiveDictionaryController.commonClassDao = commonClassDao;
}
- public DescriptiveDictionaryController(){}
+ public void setCommonClassDao(CommonClassDao commonClassDao){
+ DescriptiveDictionaryController.commonClassDao = commonClassDao;
+ }
+
+ public DescriptiveDictionaryController(){
+ //Empty Constructor
+ }
public UserInfo getUserInfo(String loginId){
- UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
- return name;
+ return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
}
@RequestMapping(value={"/get_DescriptiveScopeByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getDescriptiveDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
+ public void getDescriptiveDictionaryByNameEntityData(HttpServletResponse response){
try{
Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
@@ -121,8 +126,8 @@ public class DescriptiveDictionaryController {
GridData data;
String userId = null;
if (fromAPI) {
- descriptiveScope = (DescriptiveScope)mapper.readValue(root.get("dictionaryFields").toString(), DescriptiveScope.class);
- data = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class);
+ descriptiveScope = mapper.readValue(root.get("dictionaryFields").toString(), DescriptiveScope.class);
+ data = mapper.readValue(root.get("dictionaryFields").toString(), GridData.class);
userId = "API";
//check if update operation or create, get id for data to be updated and update attributeData
@@ -140,27 +145,26 @@ public class DescriptiveDictionaryController {
descriptiveScope.setUserCreatedBy(this.getUserInfo(userId));
}
} else {
- descriptiveScope = (DescriptiveScope)mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), DescriptiveScope.class);
- data = (GridData)mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), GridData.class);
+ descriptiveScope = mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), DescriptiveScope.class);
+ data = mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), GridData.class);
userId = root.get("userid").textValue();
}
- String header = "";
+ StringBuilder header = new StringBuilder();
int counter = 0;
- if(data.getAttributes().size() > 0){
+ if(!data.getAttributes().isEmpty()){
for(Object attribute : data.getAttributes()){
if(attribute instanceof LinkedHashMap<?, ?>){
String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
String value = ((LinkedHashMap<?, ?>) attribute).get("number").toString();
if(counter>0){
- header = header + "AND";
+ header.append("AND");
}
- header = header + key + ":";
- header = header + value;
+ header.append(key).append(":").append(value);
counter ++;
}
}
}
- descriptiveScope.setSearch(header);
+ descriptiveScope.setSearch(header.toString());
if(descriptiveScope.getId() == 0){
List<Object> duplicateData = commonClassDao.checkDuplicateEntry(descriptiveScope.getScopeName(), "descriptiveScopeName", DescriptiveScope.class);
if(!duplicateData.isEmpty()){
@@ -217,12 +221,12 @@ public class DescriptiveDictionaryController {
}
@RequestMapping(value={"/descriptive_dictionary/remove_descriptiveScope"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView removeDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
+ public void removeDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
try{
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JsonNode root = mapper.readTree(request.getReader());
- DescriptiveScope descriptiveScope = (DescriptiveScope)mapper.readValue(root.get("data").toString(), DescriptiveScope.class);
+ DescriptiveScope descriptiveScope = mapper.readValue(root.get("data").toString(), DescriptiveScope.class);
commonClassDao.delete(descriptiveScope);
response.setCharacterEncoding("UTF-8");
response.setContentType("application / json");
@@ -233,8 +237,6 @@ public class DescriptiveDictionaryController {
String responseString = mapper.writeValueAsString(commonClassDao.getData(DescriptiveScope.class));
JSONObject j = new JSONObject("{descriptiveScopeDictionaryDatas: " + responseString + "}");
out.write(j.toString());
-
- return null;
}
catch (Exception e){
LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
@@ -243,7 +245,6 @@ public class DescriptiveDictionaryController {
PrintWriter out = response.getWriter();
out.write(PolicyUtils.CATCH_EXCEPTION);
}
- return null;
}
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/EnforcerDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/EnforcerDictionaryController.java
deleted file mode 100644
index 9e248bf62..000000000
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/EnforcerDictionaryController.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP-PAP-REST
- * ================================================================================
- * 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.pap.xacml.rest.controller;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.json.JSONObject;
-import org.onap.policy.common.logging.flexlogger.FlexLogger;
-import org.onap.policy.common.logging.flexlogger.Logger;
-import org.onap.policy.pap.xacml.rest.util.JsonMessage;
-import org.onap.policy.rest.dao.CommonClassDao;
-import org.onap.policy.rest.jpa.EnforcingType;
-import org.onap.policy.utils.PolicyUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.MediaType;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.servlet.ModelAndView;
-
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-@Controller
-public class EnforcerDictionaryController {
-
- private static final Logger LOGGER = FlexLogger.getLogger(EnforcerDictionaryController.class);
-
- @Autowired
- CommonClassDao commonClassDao;
-
- @RequestMapping(value={"/get_EnforcerTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getEnforcerDictionaryEntityData(HttpServletResponse response){
- try{
- Map<String, Object> model = new HashMap<>();
- ObjectMapper mapper = new ObjectMapper();
- List<Object> list = commonClassDao.getData(EnforcingType.class);
- List<String> dictList = new ArrayList<>();
- for(int i = 0; i < list.size(); i++){
- EnforcingType dict = (EnforcingType) list.get(i);
- dictList.add(dict.getEnforcingType());
- }
- model.put("enforcerDictionaryDatas", mapper.writeValueAsString(dictList));
- org.onap.policy.pap.xacml.rest.util.JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
- JSONObject j = new JSONObject(msg);
- response.getWriter().write(j.toString());
- }
- catch (Exception e){
- LOGGER.error("Exception Occured"+e);
- }
- }
-
- @RequestMapping(value={"/enforcer_dictionary/save_enforcerType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView saveEnforcerDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
- try {
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- JsonNode root = mapper.readTree(request.getReader());
- EnforcingType enforcingType = (EnforcingType)mapper.readValue(root.get("enforcerDictionaryData").toString(), EnforcingType.class);
- if(enforcingType.getId() == 0){
- commonClassDao.save(enforcingType);
- }else{
- commonClassDao.update(enforcingType);
- }
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
-
- PrintWriter out = response.getWriter();
- String responseString = mapper.writeValueAsString(commonClassDao.getData(EnforcingType.class));
- JSONObject j = new JSONObject("{enforcerDictionaryDatas: " + responseString + "}");
-
- out.write(j.toString());
-
- return null;
- }
- catch (Exception e){
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
- PrintWriter out = response.getWriter();
- out.write(PolicyUtils.CATCH_EXCEPTION);
- LOGGER.error(e);
- }
- return null;
- }
-
- @RequestMapping(value={"/enforcer_dictionary/remove_enforcer"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView removeEnforcerDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
- try{
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- JsonNode root = mapper.readTree(request.getReader());
- EnforcingType enforcingType = (EnforcingType)mapper.readValue(root.get("data").toString(), EnforcingType.class);
- commonClassDao.delete(enforcingType);
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
-
- PrintWriter out = response.getWriter();
-
- String responseString = mapper.writeValueAsString(commonClassDao.getData(EnforcingType.class));
- JSONObject j = new JSONObject("{enforcerDictionaryDatas: " + responseString + "}");
- out.write(j.toString());
-
- return null;
- }
- catch (Exception e){
- System.out.println(e);
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
- PrintWriter out = response.getWriter();
- out.write(PolicyUtils.CATCH_EXCEPTION);
- }
- return null;
- }
-}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java
index ae749adb5..a6d740e62 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PAP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -75,9 +75,6 @@ public class DictionaryHandlerImpl implements DictionaryHandler{
case "DescriptiveScope":
dictionary.getDescriptiveDictionary(response);
break;
- case "Enforcer":
- dictionary.getEnforcerDictionary(response);
- break;
case "ActionList":
dictionary.getActionListDictionary(response);
break;
@@ -221,9 +218,6 @@ public class DictionaryHandlerImpl implements DictionaryHandler{
case "DescriptiveScope":
result = dictionary.saveDescriptiveDictionary(request, response);
break;
- case "Enforcer":
- result = dictionary.saveEnforcerDictionary(request, response);
- break;
case "ActionList":
result = dictionary.saveActionListDictionary(request, response);
break;
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/DictionaryService.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/DictionaryService.java
index 6e19b9b1c..20bd9463b 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/DictionaryService.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/DictionaryService.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PAP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -23,13 +23,13 @@ import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
import org.onap.policy.pap.xacml.rest.controller.ActionPolicyDictionaryController;
import org.onap.policy.pap.xacml.rest.controller.BRMSDictionaryController;
import org.onap.policy.pap.xacml.rest.controller.ClosedLoopDictionaryController;
import org.onap.policy.pap.xacml.rest.controller.DecisionPolicyDictionaryController;
import org.onap.policy.pap.xacml.rest.controller.DescriptiveDictionaryController;
import org.onap.policy.pap.xacml.rest.controller.DictionaryController;
-import org.onap.policy.pap.xacml.rest.controller.EnforcerDictionaryController;
import org.onap.policy.pap.xacml.rest.controller.FirewallDictionaryController;
import org.onap.policy.pap.xacml.rest.controller.MicroServiceDictionaryController;
import org.onap.policy.pap.xacml.rest.controller.PolicyScopeDictionaryController;
@@ -135,13 +135,6 @@ public class DictionaryService {
return result.getViewName();
}
- public String saveEnforcerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-
- EnforcerDictionaryController dictionary = new EnforcerDictionaryController();
- ModelAndView result = dictionary.saveEnforcerDictionary(request, response);
- return result.getViewName();
- }
-
public String saveActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
FirewallDictionaryController dictionary = new FirewallDictionaryController();
@@ -360,11 +353,6 @@ public class DictionaryService {
dictionary.getDescriptiveDictionaryEntityData(response);
}
- public void getEnforcerDictionary(HttpServletResponse response){
- EnforcerDictionaryController dictionary = new EnforcerDictionaryController();
- dictionary.getEnforcerDictionaryEntityData(response);
- }
-
public void getActionListDictionary(HttpServletResponse response){
FirewallDictionaryController dictionary = new FirewallDictionaryController();
dictionary.getActionListDictionaryEntityData(response);
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryControllerTest.java
new file mode 100644
index 000000000..0191acf23
--- /dev/null
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryControllerTest.java
@@ -0,0 +1,157 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PAP-REST
+ * ================================================================================
+ * Copyright (C) 2018 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.pap.xacml.rest.controller;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.when;
+
+import java.io.BufferedReader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+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.ActionPolicyDict;
+import org.onap.policy.rest.jpa.UserInfo;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+public class ActionPolicyDictionaryControllerTest {
+
+ private static Logger logger = FlexLogger.getLogger(ActionPolicyDictionaryControllerTest.class);
+ private static CommonClassDao commonClassDao;
+ private String jsonString = null;
+ private HttpServletRequest request = null;
+ private ActionPolicyDictionaryController controller = null;
+ private MockHttpServletResponse response = null;
+
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+ commonClassDao = Mockito.mock(CommonClassDao.class);
+ List<String> data = new ArrayList<>();
+ List<Object> objectData = new ArrayList<>();
+ data.add("Test");
+
+ UserInfo userInfo = new UserInfo();
+ userInfo.setUserLoginId("Test");
+ userInfo.setUserName("Test");
+
+ ActionPolicyDict actionData = new ActionPolicyDict();
+ actionData.setAttributeName("Test");
+ assertTrue("Test".equals(actionData.getAttributeName()));
+ actionData.setBody("Test");
+ assertTrue("Test".equals(actionData.getBody()));
+ actionData.setCreatedDate(new Date());
+ assertTrue(actionData.getCreatedDate()!= null);
+ actionData.setModifiedDate(new Date());
+ assertTrue(actionData.getModifiedDate()!= null);
+ actionData.setHeader("Test");
+ assertTrue("Test".equals(actionData.getHeader()));
+ actionData.setMethod("POST");
+ assertTrue("POST".equals(actionData.getMethod()));
+ actionData.setType("Test");
+ assertTrue("Test".equals(actionData.getType()));
+ actionData.setUrl("http://test.com");
+ assertTrue("http://test.com".equals(actionData.getUrl()));
+ actionData.setUserCreatedBy(userInfo);
+ assertTrue(actionData.getUserCreatedBy()!= null);
+ actionData.setUserModifiedBy(userInfo);
+ assertTrue(actionData.getUserModifiedBy()!= null);
+
+ objectData.add(actionData);
+ when(commonClassDao.getDataByColumn(ActionPolicyDict.class, "attributeName")).thenReturn(data);
+ when(commonClassDao.getData(ActionPolicyDict.class)).thenReturn(objectData);
+ doNothing().when(commonClassDao).delete(new ActionPolicyDict());
+ doNothing().when(commonClassDao).save(new ActionPolicyDict());
+ controller = new ActionPolicyDictionaryController();
+ controller.setCommonClassDao(commonClassDao);
+ request = Mockito.mock(HttpServletRequest.class);
+ response = new MockHttpServletResponse();
+ logger.info("setUp: exit");
+ }
+
+ @Test
+ public void testGetActionEntitybyName(){
+ controller.getActionEntitybyName(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetActionPolicyDictionaryEntityData(){
+ controller.getActionPolicyDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testSaveActionPolicyDictionary(){
+ jsonString = "{\"actionPolicyDictionaryData\":{\"attributeName\":\"Test\",\"body\":\"{}\",\"description\":\"test\",\"headers\":[{\"$$hashKey\":\"object:548\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"method\":\"GET\",\"type\":\"REST\",\"url\":\"http://test.com\"},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveActionPolicyDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryData"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdateActionPolicyDictionary(){
+ jsonString = "{\"actionPolicyDictionaryData\":{\"id\":1,\"attributeName\":\"Test\",\"body\":\"{}\",\"description\":\"test\",\"headers\":[{\"$$hashKey\":\"object:548\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"method\":\"GET\",\"type\":\"REST\",\"url\":\"http://test.com\"},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveActionPolicyDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryData"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemoveActionPolicyDictionary(){
+ jsonString = "{\"data\":{\"$$hashKey\":\"uiGrid-003S\",\"attributeName\":\"Test\",\"body\":\"{}\",\"createdDate\":1518195117000,\"description\":\"test\",\"header\":\"test=12\",\"id\":1,\"method\":\"GET\",\"modifiedDate\":1518195489000,\"type\":\"REST\",\"url\":\"http://test.com\",\"userCreatedBy\":{\"userLoginId\":\"demo\",\"userName\":\"Demo\"},\"userModifiedBy\":{\"userLoginId\":\"demo\",\"userName\":\"Demo\"}}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeActionPolicyDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java
new file mode 100644
index 000000000..d1af82c93
--- /dev/null
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java
@@ -0,0 +1,584 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PAP-REST
+ * ================================================================================
+ * Copyright (C) 2018 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.pap.xacml.rest.controller;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.when;
+
+import java.io.BufferedReader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+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.ClosedLoopD2Services;
+import org.onap.policy.rest.jpa.ClosedLoopSite;
+import org.onap.policy.rest.jpa.PEPOptions;
+import org.onap.policy.rest.jpa.UserInfo;
+import org.onap.policy.rest.jpa.VNFType;
+import org.onap.policy.rest.jpa.VSCLAction;
+import org.onap.policy.rest.jpa.VarbindDictionary;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+public class ClosedLoopDictionaryControllerTest {
+
+ private static Logger logger = FlexLogger.getLogger(ClosedLoopDictionaryControllerTest.class);
+ private static CommonClassDao commonClassDao;
+ private String jsonString = null;
+ private HttpServletRequest request = null;
+ private ClosedLoopDictionaryController controller = null;
+ private MockHttpServletResponse response = null;
+ private UserInfo userInfo;
+ private List<String> data;
+
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+ commonClassDao = Mockito.mock(CommonClassDao.class);
+
+ data = new ArrayList<>();
+ data.add("Test");
+
+ userInfo = new UserInfo();
+ userInfo.setUserLoginId("Test");
+ userInfo.setUserName("Test");
+
+ doNothing().when(commonClassDao).delete(new VSCLAction());
+ doNothing().when(commonClassDao).save(new VSCLAction());
+
+ controller = new ClosedLoopDictionaryController();
+ controller.setCommonClassDao(commonClassDao);
+
+ request = Mockito.mock(HttpServletRequest.class);
+ response = new MockHttpServletResponse();
+ logger.info("setUp: exit");
+ }
+
+ public List<Object> testVSCLAction(){
+ List<Object> objectData = new ArrayList<>();
+
+ VSCLAction data = new VSCLAction();
+ data.setId(1);
+ assertTrue(1 == data.getId());
+ data.setVsclaction("Test");
+ assertTrue("Test".equals(data.getVsclaction()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
+ data.setCreatedDate(new Date());
+ assertTrue(data.getCreatedDate()!= null);
+ data.setModifiedDate(new Date());
+ assertTrue(data.getModifiedDate()!= null);
+ data.setUserCreatedBy(userInfo);
+ assertTrue(data.getUserCreatedBy()!= null);
+ data.setUserModifiedBy(userInfo);
+ assertTrue(data.getUserModifiedBy()!= null);
+ objectData.add(data);
+
+ return objectData;
+ }
+
+ public List<Object> testVNFType(){
+ List<Object> objectData = new ArrayList<>();
+
+ VNFType data = new VNFType();
+ data.setId(1);
+ assertTrue(1 == data.getId());
+ data.setVnftype("Test");
+ assertTrue("Test".equals(data.getVnftype()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
+ data.setCreatedDate(new Date());
+ assertTrue(data.getCreatedDate()!= null);
+ data.setModifiedDate(new Date());
+ assertTrue(data.getModifiedDate()!= null);
+ data.setUserCreatedBy(userInfo);
+ assertTrue(data.getUserCreatedBy()!= null);
+ data.setUserModifiedBy(userInfo);
+ assertTrue(data.getUserModifiedBy()!= null);
+ objectData.add(data);
+
+ return objectData;
+ }
+
+ public List<Object> testPEPOptions(){
+ List<Object> objectData = new ArrayList<>();
+
+ PEPOptions data = new PEPOptions();
+ data.setId(1);
+ assertTrue(1 == data.getId());
+ data.setPepName("Test");
+ assertTrue("Test".equals(data.getPepName()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
+ data.setCreatedDate(new Date());
+ assertTrue(data.getCreatedDate()!= null);
+ data.setModifiedDate(new Date());
+ assertTrue(data.getModifiedDate()!= null);
+ data.setUserCreatedBy(userInfo);
+ assertTrue(data.getUserCreatedBy()!= null);
+ data.setUserModifiedBy(userInfo);
+ assertTrue(data.getUserModifiedBy()!= null);
+ objectData.add(data);
+
+ return objectData;
+ }
+
+ public List<Object> testVarbindDictionary(){
+ List<Object> objectData = new ArrayList<>();
+
+ VarbindDictionary data = new VarbindDictionary();
+ data.setId(1);
+ assertTrue(1 == data.getId());
+ data.setVarbindName("Test");
+ assertTrue("Test".equals(data.getVarbindName()));
+ data.setVarbindDescription("Test");
+ assertTrue("Test".equals(data.getVarbindDescription()));
+ data.setVarbindOID("Test");
+ assertTrue("Test".equals(data.getVarbindOID()));
+ data.setCreatedDate(new Date());
+ assertTrue(data.getCreatedDate()!= null);
+ data.setModifiedDate(new Date());
+ assertTrue(data.getModifiedDate()!= null);
+ data.setUserCreatedBy(userInfo);
+ assertTrue(data.getUserCreatedBy()!= null);
+ data.setUserModifiedBy(userInfo);
+ assertTrue(data.getUserModifiedBy()!= null);
+ objectData.add(data);
+
+ return objectData;
+ }
+
+ public List<Object> testClosedLoopD2Services(){
+ List<Object> objectData = new ArrayList<>();
+
+ ClosedLoopD2Services data = new ClosedLoopD2Services();
+ data.setId(1);
+ assertTrue(1 == data.getId());
+ data.setServiceName("Test");
+ assertTrue("Test".equals(data.getServiceName()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
+ data.setCreatedDate(new Date());
+ assertTrue(data.getCreatedDate()!= null);
+ data.setModifiedDate(new Date());
+ assertTrue(data.getModifiedDate()!= null);
+ data.setUserCreatedBy(userInfo);
+ assertTrue(data.getUserCreatedBy()!= null);
+ data.setUserModifiedBy(userInfo);
+ assertTrue(data.getUserModifiedBy()!= null);
+ objectData.add(data);
+
+ return objectData;
+ }
+
+
+ public List<Object> testClosedLoopSite(){
+ List<Object> objectData = new ArrayList<>();
+
+ ClosedLoopSite data = new ClosedLoopSite();
+ data.setId(1);
+ assertTrue(1 == data.getId());
+ data.setSiteName("Test");
+ assertTrue("Test".equals(data.getSiteName()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
+ data.setCreatedDate(new Date());
+ assertTrue(data.getCreatedDate()!= null);
+ data.setModifiedDate(new Date());
+ assertTrue(data.getModifiedDate()!= null);
+ data.setUserCreatedBy(userInfo);
+ assertTrue(data.getUserCreatedBy()!= null);
+ data.setUserModifiedBy(userInfo);
+ assertTrue(data.getUserModifiedBy()!= null);
+ objectData.add(data);
+
+ return objectData;
+ }
+
+ @Test
+ public void testGetVSCLActionDictionaryByNameEntityData(){
+ when(commonClassDao.getDataByColumn(VSCLAction.class, "vsclaction")).thenReturn(data);
+ controller.getVSCLActionDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetVSCLActionDictionaryEntityData(){
+ when(commonClassDao.getData(VSCLAction.class)).thenReturn(testVSCLAction());
+ controller.getVSCLActionDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetVNFTypeDictionaryByNameEntityData(){
+ when(commonClassDao.getDataByColumn(VNFType.class, "vnftype")).thenReturn(data);
+ controller.getVNFTypeDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetVNFTypeDictionaryEntityData(){
+ when(commonClassDao.getData(VNFType.class)).thenReturn(testVNFType());
+ controller.getVNFTypeDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetPEPOptionsDictionaryByNameEntityData(){
+ when(commonClassDao.getDataByColumn(PEPOptions.class, "pepName")).thenReturn(data);
+ controller.getPEPOptionsDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetPEPOptionsDictionaryEntityData(){
+ when(commonClassDao.getData(PEPOptions.class)).thenReturn(testPEPOptions());
+ controller.getPEPOptionsDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetVarbindDictionaryByNameEntityData(){
+ when(commonClassDao.getDataByColumn(VarbindDictionary.class, "varbindName")).thenReturn(data);
+ controller.getVarbindDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetVarbindDictionaryEntityData(){
+ when(commonClassDao.getData(VarbindDictionary.class)).thenReturn(testVarbindDictionary());
+ controller.getVarbindDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetClosedLoopServiceDictionaryByNameEntityData(){
+ when(commonClassDao.getDataByColumn(ClosedLoopD2Services.class, "serviceName")).thenReturn(data);
+ controller.getClosedLoopServiceDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetClosedLoopServiceDictionaryEntityData(){
+ when(commonClassDao.getData(ClosedLoopD2Services.class)).thenReturn(testClosedLoopD2Services());
+ controller.getClosedLoopServiceDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetClosedLoopSiteDictionaryByNameEntityData(){
+ when(commonClassDao.getDataByColumn(ClosedLoopSite.class, "siteName")).thenReturn(data);
+ controller.getClosedLoopSiteDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetClosedLoopSiteDictionaryEntityData(){
+ when(commonClassDao.getData(ClosedLoopSite.class)).thenReturn(testClosedLoopSite());
+ controller.getClosedLoopSiteDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testSaveVSCLAction(){
+ jsonString = "{\"userid\":\"demo\",\"vsclActionDictionaryData\":{\"description\":\"test\",\"vsclaction\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveVSCLAction(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdateVSCLAction(){
+ jsonString = "{\"userid\":\"demo\",\"vsclActionDictionaryData\":{\"id\":1,\"description\":\"test\",\"vsclaction\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveVSCLAction(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemoveVSCLAction(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"vsclaction\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeVSCLAction(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testSaveVnfType(){
+ jsonString = "{\"userid\":\"demo\",\"vnfTypeDictionaryData\":{\"description\":\"test\",\"vnftype\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveVnfType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryData"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdateVnfType(){
+ jsonString = "{\"userid\":\"demo\",\"vnfTypeDictionaryData\":{\"id\":1,\"description\":\"test\",\"vnftype\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveVnfType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryData"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemoveVnfType(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"vnftype\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeVnfType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryData"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testSavePEPOptions(){
+ jsonString = "{\"pepOptionsDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\"},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.savePEPOptions(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdatePEPOptions(){
+ jsonString = "{\"pepOptionsDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\",\"id\":1},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.savePEPOptions(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemovePEPOptions(){
+ jsonString = "{\"data\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\"},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removePEPOptions(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testSaveServiceType(){
+ jsonString = "{\"userid\":\"demo\",\"closedLoopServiceDictionaryData\":{\"description\":\"test\",\"serviceName\":\"Test\",\"id\":1}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveServiceType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryData"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdateServiceType(){
+ jsonString = "{\"userid\":\"demo\",\"closedLoopServiceDictionaryData\":{\"id\":1,\"description\":\"test\",\"serviceName\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveServiceType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryData"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemoveServiceType(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"serviceName\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeServiceType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryData"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testSaveSiteType(){
+ jsonString = "{\"userid\":\"demo\",\"closedLoopSiteDictionaryData\":{\"description\":\"test\",\"siteName\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveSiteType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdateSiteType(){
+ jsonString = "{\"userid\":\"demo\",\"closedLoopSiteDictionaryData\":{\"id\":1,\"description\":\"test\",\"siteName\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveSiteType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemoveSiteType(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"siteName\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeSiteType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testSaveVarbind(){
+ jsonString = "{\"userid\":\"demo\",\"varbindDictionaryData\":{\"description\":\"test\",\"varbindName\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveVarbind(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdateVarbind(){
+ jsonString = "{\"userid\":\"demo\",\"varbindDictionaryData\":{\"id\":1,\"description\":\"test\",\"varbindName\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveVarbind(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemoveVarbind(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"varbindName\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeVarbind(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryControllerTest.java
new file mode 100644
index 000000000..185410532
--- /dev/null
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryControllerTest.java
@@ -0,0 +1,163 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PAP-REST
+ * ================================================================================
+ * Copyright (C) 2018 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.pap.xacml.rest.controller;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.when;
+
+import java.io.BufferedReader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+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.DescriptiveScope;
+import org.onap.policy.rest.jpa.UserInfo;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+public class DescriptiveDictionaryControllerTest {
+
+ private static Logger logger = FlexLogger.getLogger(DescriptiveDictionaryControllerTest.class);
+ private static CommonClassDao commonClassDao;
+ private String jsonString = null;
+ private HttpServletRequest request = null;
+ private DescriptiveDictionaryController controller = null;
+ private MockHttpServletResponse response = null;
+ private UserInfo userInfo;
+ private List<String> data;
+
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+ commonClassDao = Mockito.mock(CommonClassDao.class);
+
+ data = new ArrayList<>();
+ data.add("Test");
+
+ userInfo = new UserInfo();
+ userInfo.setUserLoginId("Test");
+ userInfo.setUserName("Test");
+
+ doNothing().when(commonClassDao).delete(new DescriptiveScope());
+ doNothing().when(commonClassDao).save(new DescriptiveScope());
+
+ controller = new DescriptiveDictionaryController();
+ controller.setCommonClassDao(commonClassDao);
+
+ request = Mockito.mock(HttpServletRequest.class);
+ response = new MockHttpServletResponse();
+ logger.info("setUp: exit");
+ }
+
+ public List<Object> testDescriptiveScope(){
+ List<Object> objectData = new ArrayList<>();
+
+ DescriptiveScope data = new DescriptiveScope();
+ data.setId(1);
+ assertTrue(1 == data.getId());
+ data.setScopeName("Test");
+ assertTrue("Test".equals(data.getScopeName()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
+ data.setSearch("Test");
+ assertTrue("Test".equals(data.getSearch()));
+ data.setCreatedDate(new Date());
+ assertTrue(data.getCreatedDate()!= null);
+ data.setModifiedDate(new Date());
+ assertTrue(data.getModifiedDate()!= null);
+ data.setUserCreatedBy(userInfo);
+ assertTrue(data.getUserCreatedBy()!= null);
+ data.setUserModifiedBy(userInfo);
+ assertTrue(data.getUserModifiedBy()!= null);
+ objectData.add(data);
+
+ return objectData;
+ }
+
+ @Test
+ public void testGetDescriptiveDictionaryByNameEntityData(){
+ when(commonClassDao.getDataByColumn(DescriptiveScope.class, "descriptiveScopeName")).thenReturn(data);
+ controller.getDescriptiveDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetDescriptiveDictionaryEntityData(){
+ when(commonClassDao.getData(DescriptiveScope.class)).thenReturn(testDescriptiveScope());
+ controller.getDescriptiveDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testSaveDescriptiveDictionary(){
+ jsonString = "{\"descriptiveScopeDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"descriptiveScopeName\":\"Test\",\"search\":\"Test\"},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveDescriptiveDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdateDescriptiveDictionary(){
+ jsonString = "{\"descriptiveScopeDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"descriptiveScopeName\":\"Test\",\"id\":1,\"search\":\"Test\"},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveDescriptiveDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemoveDescriptiveDictionary(){
+ jsonString = "{\"data\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"descriptiveScopeName\":\"Test\",\"id\":1,\"search\":\"Test\"},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeDescriptiveDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+} \ No newline at end of file