aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java')
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java90
1 files changed, 50 insertions, 40 deletions
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java
index dd355d948..5e0b7ce28 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java
@@ -4,12 +4,14 @@
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (C) 2019 Samsung
+ * ================================================================================
* 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.
@@ -24,15 +26,12 @@ import static org.junit.Assert.fail;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-
import java.io.BufferedReader;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
-
import javax.servlet.http.HttpServletRequest;
-
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -55,7 +54,7 @@ public class OptimizationDictionaryControllerTest {
private String jsonString = null;
private HttpServletRequest request = null;
private OptimizationDictionaryController controller = null;
- BufferedReader br = null;
+ BufferedReader br = null;
@Before
public void setUp() throws Exception {
@@ -64,33 +63,39 @@ public class OptimizationDictionaryControllerTest {
UserInfo userInfo = new UserInfo();
userInfo.setUserLoginId("testUserId");
userInfo.setUserName("John");
- when(commonClassDao.getEntityItem(UserInfo.class, "userLoginId", "testing")).thenReturn(userInfo);
-
+ when(commonClassDao.getEntityItem(UserInfo.class, "userLoginId", "testing"))
+ .thenReturn(userInfo);
+
OptimizationModels optimziationModels = new OptimizationModels();
-
+
doNothing().when(commonClassDao).delete(optimziationModels);
- OptimizationDictionaryController.setCommonClassDao(commonClassDao);
+ OptimizationDictionaryController.setCommonClassDao(commonClassDao);
controller = new OptimizationDictionaryController();
-
+
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
-
- jsonString = "{\"optimizationModelsDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
-
+
+ jsonString =
+ "{\"optimizationModelsDictionaryData\": {\"modelName\": \"test\",\"inprocess\": false,\"model\":"
+ + " {\"name\": \"testingdata\",\"subScopename\": \"\",\"path\": [],\"type\": \"dir\","
+ + "\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", \"version\": \"\","
+ + "\"createdBy\": \"someone\",\"modifiedBy\": \"someone\",\"content\": \"\","
+ + "\"recursive\": false},"
+ + "\"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"},"
+ + "\"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\","
+ + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\","
+ + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\","
+ + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\","
+ + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}},"
+ + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}";
+
br = new BufferedReader(new StringReader(jsonString));
- //--- mock the getReader() call
- when(request.getReader()).thenReturn(br);
+ // --- mock the getReader() call
+ when(request.getReader()).thenReturn(br);
new DictionaryUtils(commonClassDao);
DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
- mock(DictionaryUtils.class);
+ mock(DictionaryUtils.class);
logger.info("setUp: exit");
}
@@ -98,7 +103,7 @@ public class OptimizationDictionaryControllerTest {
public void testGetOptimizationModelsDictionaryEntityData() {
logger.info("testGetOptimizationModelsDictionaryEntityData: Entering");
- MockHttpServletResponse response = new MockHttpServletResponse();
+ MockHttpServletResponse response = new MockHttpServletResponse();
String modelJson = "{\"optimizationModelsDictionaryData\":[\"modelName\"]}";
BufferedReader br = new BufferedReader(new StringReader(modelJson));
@@ -109,7 +114,8 @@ public class OptimizationDictionaryControllerTest {
when(request.getReader()).thenReturn(br);
controller.getOptimizationModelsDictionaryEntityData(response);
logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("optimizationModelsDictionaryDatas"));
+ assertTrue(response.getContentAsString() != null
+ && response.getContentAsString().contains("optimizationModelsDictionaryDatas"));
} catch (Exception e) {
fail("Exception: " + e);
@@ -122,7 +128,7 @@ public class OptimizationDictionaryControllerTest {
public void testSaveOptimizationModelsDictionary() {
logger.info("testSaveOptimizationModelsDictionary: Entering");
- MockHttpServletResponse response = new MockHttpServletResponse();
+ MockHttpServletResponse response = new MockHttpServletResponse();
request = mock(HttpServletRequest.class);
try {
@@ -130,7 +136,8 @@ public class OptimizationDictionaryControllerTest {
when(request.getReader()).thenReturn(br);
controller.saveOptimizationModelsDictionary(request, response);
logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("optimizationModelsDictionaryDatas"));
+ assertTrue(response.getContentAsString() != null
+ && response.getContentAsString().contains("optimizationModelsDictionaryDatas"));
} catch (Exception e) {
fail("Exception: " + e);
@@ -143,31 +150,34 @@ public class OptimizationDictionaryControllerTest {
public void testRemoveOptimizationModelsDictionary() {
logger.info("testRemoveOptimizationModelsDictionary: Entering");
- MockHttpServletResponse response = new MockHttpServletResponse();
+ MockHttpServletResponse response = new MockHttpServletResponse();
request = mock(HttpServletRequest.class);
try {
// mock the getReader() call
- jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+ jsonString =
+ "{\"data\": {\"modelName\": \"test\",\"inprocess\": false,\"model\": {\"name\": \"testingdata\","
+ + "\"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,"
+ + "\"date\": \"2017-04-12T21:26:57.000Z\",\"version\": \"\",\"createdBy\": \"someone\","
+ + "\"modifiedBy\": \"someone\",\"content\": \"\",\"recursive\": false},"
+ + "\"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"},"
+ + "\"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\","
+ + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\","
+ + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\","
+ + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\","
+ + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}},"
+ + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}";
BufferedReader br = new BufferedReader(new StringReader(jsonString));
when(request.getReader()).thenReturn(br);
controller.removeOptimizationModelsDictionary(request, response);
logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("optimizationModelsDictionaryDatas"));
+ assertTrue(response.getContentAsString() != null
+ && response.getContentAsString().contains("optimizationModelsDictionaryDatas"));
} catch (Exception e) {
fail("Exception: " + e);
}
-
logger.info("testRemoveOptimizationModelsDictionary: exit");
}
-
}