2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 package org.onap.policy.pap.xacml.rest.controller;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26 import static org.junit.Assert.fail;
27 import static org.mockito.Mockito.doNothing;
28 import static org.mockito.Mockito.mock;
29 import static org.mockito.Mockito.when;
31 import java.io.BufferedReader;
32 import java.io.StringReader;
33 import java.io.UnsupportedEncodingException;
34 import java.util.ArrayList;
35 import java.util.List;
37 import javax.servlet.http.HttpServletRequest;
39 import org.junit.After;
40 import org.junit.Before;
41 import org.junit.Test;
42 import org.mockito.Mockito;
43 import org.onap.policy.common.logging.flexlogger.FlexLogger;
44 import org.onap.policy.common.logging.flexlogger.Logger;
45 import org.onap.policy.rest.dao.CommonClassDao;
46 import org.onap.policy.rest.jpa.DCAEuuid;
47 import org.onap.policy.rest.jpa.MicroServiceLocation;
48 import org.onap.policy.rest.jpa.MicroServiceModels;
49 import org.onap.policy.rest.jpa.UserInfo;
50 import org.springframework.mock.web.MockHttpServletResponse;
53 * The class <code>MicroServiceDictionaryControllerTest</code> contains tests
54 * for the class {@link <code>MicroServiceDictionaryController</code>}*
56 * All JUnits are designed to run in the local development environment
57 * where they have write privileges and can execute time-sensitive
61 public class MicroServiceDictionaryControllerTest {
63 private static Logger logger = FlexLogger.getLogger(MicroServiceDictionaryControllerTest.class);
64 private static CommonClassDao commonClassDao;
65 private String jsonString = null;
66 private String configBodyString = null;
67 private HttpServletRequest request = null;
68 private MicroServiceDictionaryController controller = null;
69 BufferedReader br = null;
72 public void setUp() throws Exception {
73 logger.info("setUp: Entering");
74 commonClassDao = Mockito.mock(CommonClassDao.class);
75 UserInfo userInfo = new UserInfo();
76 userInfo.setUserLoginId("testUserId");
77 userInfo.setUserName("John");
78 when(commonClassDao.getEntityItem(UserInfo.class, "userLoginId", "testing")).thenReturn(userInfo);
80 List<String> listIds = new ArrayList<String>();
82 when(commonClassDao.getDataByColumn(DCAEuuid.class, "name")).thenReturn(listIds);
84 List<String> microList = new ArrayList<String>();
85 microList.add("MC-Model");
86 when(commonClassDao.getDataByColumn(MicroServiceLocation.class, "name")).thenReturn(microList);
88 List<Object> listId = new ArrayList<Object>();
90 when(commonClassDao.getData(DCAEuuid.class)).thenReturn(listId);
91 MicroServiceModels microServiceModels = new MicroServiceModels();
93 doNothing().when(commonClassDao).delete(microServiceModels);
95 MicroServiceDictionaryController.setCommonClassDao(commonClassDao);
97 controller = new MicroServiceDictionaryController();
99 HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
101 jsonString = "{\"microServiceModelsDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
102 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
103 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
104 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
105 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
106 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
107 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
108 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
110 configBodyString = "{\"service\":\"SniroPolicyEntityTest\",\"policyName\":\"someone\",\"description\":\"test\",\"templateVersion\":\"1607\",\"version\":\"HD\","
111 + "\"priority\":\"2\",\"content\":{\"lastPolled\":\"1\",\"boolen-test\":\"true\",\"created\":\"test\",\"retiredDate\":\"test\",\"scope\":\"SNIRO_PLACEMENT_VDHV\","
112 + "\"name\":\"test\",\"lastModified\":\"test\",\"state\":\"CREATED\",\"type\":\"CONFIG\",\"intent\":\"test\",\"target\":\"SNIRO\"}}";
114 br = new BufferedReader(new StringReader(jsonString));
115 //--- mock the getReader() call
116 when(request.getReader()).thenReturn(br);
118 logger.info("setUp: exit");
122 public void tearDown() throws Exception {
127 public void testGetUserInfo() {
129 logger.info("testGetUserInfo: Entering");
131 UserInfo userInfo = controller.getUserInfo("testing");
132 logger.info("userInfo.getUserName() : " + userInfo.getUserName());
134 assertEquals("John", userInfo.getUserName());
136 logger.info("testGetUserInfo: exit");
140 public void testGetDCAEUUIDDictionaryByNameEntityData() {
142 logger.info("testGetDCAEUUIDDictionaryByNameEntityData: Entering");
144 MockHttpServletResponse response = new MockHttpServletResponse();
146 controller.getDCAEUUIDDictionaryByNameEntityData(request, response);
149 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
150 logger.info("response.getContentAsString(): " + response.getContentAsString());
151 } catch (UnsupportedEncodingException e) {
152 fail("Exception: " + e);
155 logger.info("testGetDCAEUUIDDictionaryByNameEntityData: exit");
159 public void testGetDCAEUUIDDictionaryEntityData() {
161 logger.info("testGetDCAEUUIDDictionaryEntityData: Entering");
163 MockHttpServletResponse response = new MockHttpServletResponse();
165 controller.getDCAEUUIDDictionaryEntityData(request, response);
168 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
169 logger.info("response.getContentAsString(): " + response.getContentAsString());
170 } catch (UnsupportedEncodingException e) {
171 fail("Exception: " + e);
174 logger.info("testGetDCAEUUIDDictionaryEntityData: exit");
178 public void testSaveDCAEUUIDDictionary() {
179 logger.info("testSaveDCAEUUIDDictionary: Entering");
181 MockHttpServletResponse response = new MockHttpServletResponse();
182 request = mock(HttpServletRequest.class);
185 // mock the getReader() call
186 jsonString = "{\"dcaeUUIDDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
187 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
188 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
189 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
190 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
191 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
192 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
193 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
194 BufferedReader br = new BufferedReader(new StringReader(jsonString));
195 when(request.getReader()).thenReturn(br);
196 controller.saveDCAEUUIDDictionary(request, response);
197 logger.info("response.getContentAsString(): " + response.getContentAsString());
198 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
200 } catch (Exception e) {
201 fail("Exception: " + e);
204 logger.info("testSaveDCAEUUIDDictionary: exit");
208 public void testRemoveDCAEUUIDDictionary() {
209 logger.info("testRemoveDCAEUUIDDictionary: Entering");
211 MockHttpServletResponse response = new MockHttpServletResponse();
212 request = mock(HttpServletRequest.class);
215 // mock the getReader() call
216 jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
217 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
218 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
219 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
220 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
221 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
222 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
223 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
224 BufferedReader br = new BufferedReader(new StringReader(jsonString));
225 when(request.getReader()).thenReturn(br);
226 controller.removeMicroServiceConfigNameDictionary(request, response);
227 logger.info("response.getContentAsString(): " + response.getContentAsString());
228 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceCongigNameDictionaryDatas"));
230 } catch (Exception e) {
231 fail("Exception: " + e);
234 logger.info("testRemoveDCAEUUIDDictionary: exit");
238 public void testGetMicroServiceConfigNameByNameDictionaryEntityData() {
239 logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: Entering");
241 MockHttpServletResponse response = new MockHttpServletResponse();
243 controller.getMicroServiceConfigNameByNameDictionaryEntityData(request, response);
246 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceCongigNameDictionaryDatas"));
247 logger.info("response.getContentAsString(): " + response.getContentAsString());
248 } catch (UnsupportedEncodingException e) {
249 fail("Exception: " + e);
252 logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: exit");
256 public void testGetMicroServiceConfigNameDictionaryEntityData() {
257 logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: Entering");
259 MockHttpServletResponse response = new MockHttpServletResponse();
261 controller.getMicroServiceConfigNameDictionaryEntityData(request, response);
264 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceCongigNameDictionaryDatas"));
265 logger.info("response.getContentAsString(): " + response.getContentAsString());
266 } catch (UnsupportedEncodingException e) {
267 fail("Exception: " + e);
270 logger.info("testGetMicroServiceConfigNameDictionaryEntityData: exit");
274 public void testSaveMicroServiceConfigNameDictionary() {
275 logger.info("testSaveMicroServiceConfigNameDictionary: Entering");
277 MockHttpServletResponse response = new MockHttpServletResponse();
278 request = mock(HttpServletRequest.class);
281 // mock the getReader() call
282 jsonString = "{\"microServiceCongigNameDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
283 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
284 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
285 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
286 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
287 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
288 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
289 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
290 BufferedReader br = new BufferedReader(new StringReader(jsonString));
291 when(request.getReader()).thenReturn(br);
292 controller.saveMicroServiceConfigNameDictionary(request, response);
293 logger.info("response.getContentAsString(): " + response.getContentAsString());
294 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceCongigNameDictionaryDatas"));
296 } catch (Exception e) {
297 fail("Exception: " + e);
300 logger.info("testSaveMicroServiceConfigNameDictionary: exit");
304 public void testRemoveMicroServiceConfigNameDictionary() {
305 logger.info("testRemoveMicroServiceConfigNameDictionary: Entering");
307 MockHttpServletResponse response = new MockHttpServletResponse();
308 request = mock(HttpServletRequest.class);
311 // mock the getReader() call
312 jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
313 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
314 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
315 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
316 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
317 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
318 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
319 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
320 BufferedReader br = new BufferedReader(new StringReader(jsonString));
321 when(request.getReader()).thenReturn(br);
322 controller.removeMicroServiceConfigNameDictionary(request, response);
323 logger.info("response.getContentAsString(): " + response.getContentAsString());
324 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceCongigNameDictionaryDatas"));
326 } catch (Exception e) {
327 fail("Exception: " + e);
330 logger.info("testRemoveMicroServiceConfigNameDictionary: exit");
334 public void testGetMicroServiceLocationByNameDictionaryEntityData() {
336 logger.info("testGetMicroServiceLocationByNameDictionaryEntityData: Entering");
338 MockHttpServletResponse response = new MockHttpServletResponse();
340 controller.getMicroServiceLocationByNameDictionaryEntityData(request, response);
343 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
344 logger.info("response.getContentAsString(): " + response.getContentAsString());
345 } catch (UnsupportedEncodingException e) {
346 fail("Exception: " + e);
349 logger.info("testGetMicroServiceLocationByNameDictionaryEntityData: exit");
353 public void testGetMicroServiceLocationDictionaryEntityData() {
354 logger.info("testGetMicroServiceLocationDictionaryEntityData: Entering");
356 MockHttpServletResponse response = new MockHttpServletResponse();
358 controller.getMicroServiceLocationDictionaryEntityData(request, response);
361 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
362 logger.info("response.getContentAsString(): " + response.getContentAsString());
363 } catch (UnsupportedEncodingException e) {
364 fail("Exception: " + e);
367 logger.info("testGetMicroServiceLocationDictionaryEntityData: exit");
371 public void testSaveMicroServiceLocationDictionary() {
372 logger.info("testSaveMicroServiceLocationDictionary: Entering");
374 MockHttpServletResponse response = new MockHttpServletResponse();
375 request = mock(HttpServletRequest.class);
378 // mock the getReader() call
379 jsonString = "{\"microServiceLocationDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
380 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
381 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
382 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
383 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
384 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
385 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
386 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
387 BufferedReader br = new BufferedReader(new StringReader(jsonString));
388 when(request.getReader()).thenReturn(br);
389 controller.saveMicroServiceLocationDictionary(request, response);
390 logger.info("response.getContentAsString(): " + response.getContentAsString());
391 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
393 } catch (Exception e) {
394 fail("Exception: " + e);
397 logger.info("testSaveMicroServiceLocationDictionary: exit");
401 public void testRemoveMicroServiceLocationDictionary() {
402 logger.info("testRemoveMicroServiceLocationDictionary: Entering");
404 MockHttpServletResponse response = new MockHttpServletResponse();
405 request = mock(HttpServletRequest.class);
408 // mock the getReader() call
409 jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
410 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
411 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
412 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
413 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
414 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
415 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
416 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
417 BufferedReader br = new BufferedReader(new StringReader(jsonString));
419 when(request.getReader()).thenReturn(br);
420 controller.removeMicroServiceLocationDictionary(request, response);
421 logger.info("response.getContentAsString(): " + response.getContentAsString());
422 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
424 } catch (Exception e) {
425 fail("Exception: " + e);
428 logger.info("testRemoveMicroServiceLocationDictionary: exit");
432 public void testGetMicroServiceAttributeByNameDictionaryEntityData() {
433 logger.info("testGetMicroServiceAttributeByNameDictionaryEntityData: Entering");
435 MockHttpServletResponse response = new MockHttpServletResponse();
437 controller.getMicroServiceAttributeByNameDictionaryEntityData(request, response);
440 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
441 logger.info("response.getContentAsString(): " + response.getContentAsString());
442 } catch (UnsupportedEncodingException e) {
443 fail("Exception: " + e);
446 logger.info("testGetMicroServiceAttributeByNameDictionaryEntityData: exit");
450 public void testGetMicroServiceAttributeDictionaryEntityData() {
451 logger.info("testGetMicroServiceAttributeDictionaryEntityData: Entering");
453 MockHttpServletResponse response = new MockHttpServletResponse();
455 controller.getMicroServiceAttributeDictionaryEntityData(request, response);
458 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
459 logger.info("response.getContentAsString(): " + response.getContentAsString());
460 } catch (UnsupportedEncodingException e) {
461 fail("Exception: " + e);
464 logger.info("testGetMicroServiceAttributeDictionaryEntityData: exit");
468 public void testSaveMicroServiceAttributeDictionary() {
469 logger.info("testSaveMicroServiceAttributeDictionary: Entering");
471 MockHttpServletResponse response = new MockHttpServletResponse();
472 request = mock(HttpServletRequest.class);
475 // mock the getReader() call
476 jsonString = "{\"modelAttributeDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
477 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
478 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
479 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
480 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
481 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
482 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
483 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
484 BufferedReader br = new BufferedReader(new StringReader(jsonString));
485 when(request.getReader()).thenReturn(br);
486 controller.saveMicroServiceAttributeDictionary(request, response);
487 logger.info("response.getContentAsString(): " + response.getContentAsString());
488 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
490 } catch (Exception e) {
491 fail("Exception: " + e);
494 logger.info("testSaveMicroServiceAttributeDictionary: exit");
498 public void testRemoveMicroServiceAttributeDictionary() {
499 logger.info("testRemoveMicroServiceAttributeDictionary: Entering");
501 MockHttpServletResponse response = new MockHttpServletResponse();
502 request = mock(HttpServletRequest.class);
505 // mock the getReader() call
506 jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
507 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
508 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
509 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
510 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
511 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
512 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
513 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
514 BufferedReader br = new BufferedReader(new StringReader(jsonString));
515 when(request.getReader()).thenReturn(br);
516 controller.removeMicroServiceAttributeDictionary(request, response);
517 logger.info("response.getContentAsString(): " + response.getContentAsString());
518 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
520 } catch (Exception e) {
521 fail("Exception: " + e);
524 logger.info("testRemoveMicroServiceAttributeDictionary: exit");
528 public void testGetMicroServiceModelsDictionaryByNameEntityData() {
529 logger.info("testGetMicroServiceModelsDictionaryByNameEntityData: Entering");
531 MockHttpServletResponse response = new MockHttpServletResponse();
533 controller.getMicroServiceModelsDictionaryByNameEntityData(request, response);
536 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
537 logger.info("response.getContentAsString(): " + response.getContentAsString());
538 } catch (UnsupportedEncodingException e) {
539 fail("Exception: " + e);
542 logger.info("testGetMicroServiceModelsDictionaryByNameEntityData: exit");
546 public void testGetMicroServiceModelsDictionaryByVersionEntityData() {
547 logger.info("testGetMicroServiceModelsDictionaryByVersionEntityData: Entering");
549 MockHttpServletResponse response = new MockHttpServletResponse();
550 String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
552 BufferedReader br = new BufferedReader(new StringReader(msModelJson));
553 request = mock(HttpServletRequest.class);
556 // mock the getReader() call
557 when(request.getReader()).thenReturn(br);
558 controller.getMicroServiceModelsDictionaryByVersionEntityData(request, response);
559 logger.info("response.getContentAsString(): " + response.getContentAsString());
560 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("No model name given"));
562 } catch (Exception e) {
563 fail("Exception: " + e);
566 logger.info("testGetMicroServiceModelsDictionaryByVersionEntityData: exit");
570 public void testGetMicroServiceModelsDictionaryEntityData() {
571 logger.info("testGetMicroServiceModelsDictionaryEntityData: Entering");
573 MockHttpServletResponse response = new MockHttpServletResponse();
574 String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
576 BufferedReader br = new BufferedReader(new StringReader(msModelJson));
577 request = mock(HttpServletRequest.class);
580 // mock the getReader() call
581 when(request.getReader()).thenReturn(br);
582 controller.getMicroServiceModelsDictionaryEntityData(request, response);
583 logger.info("response.getContentAsString(): " + response.getContentAsString());
584 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
586 } catch (Exception e) {
587 fail("Exception: " + e);
590 logger.info("testGetMicroServiceModelsDictionaryEntityData: exit");
594 public void testGetMicroServiceModelsDictionaryEntityDataServiceVersion() {
595 logger.info("testGetMicroServiceModelsDictionaryEntityDataServiceVersion: Entering");
597 MockHttpServletResponse response = new MockHttpServletResponse();
598 String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
600 BufferedReader br = new BufferedReader(new StringReader(msModelJson));
601 request = mock(HttpServletRequest.class);
604 // mock the getReader() call
605 when(request.getReader()).thenReturn(br);
606 controller.getMicroServiceModelsDictionaryEntityDataServiceVersion(request, response);
607 logger.info("response.getContentAsString(): " + response.getContentAsString());
608 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
610 } catch (Exception e) {
611 fail("Exception: " + e);
614 logger.info("testGetMicroServiceModelsDictionaryEntityDataServiceVersion: exit");
618 public void testGetMicroServiceModelsDictionaryClassEntityData() {
619 logger.info("testGetMicroServiceModelsDictionaryClassEntityData: Entering");
621 MockHttpServletResponse response = new MockHttpServletResponse();
622 String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
624 BufferedReader br = new BufferedReader(new StringReader(msModelJson));
625 request = mock(HttpServletRequest.class);
628 // mock the getReader() call
629 when(request.getReader()).thenReturn(br);
630 controller.getMicroServiceModelsDictionaryClassEntityData(request, response);
631 logger.info("response.getContentAsString(): " + response.getContentAsString());
632 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryClassDatas"));
634 } catch (Exception e) {
635 fail("Exception: " + e);
638 logger.info("testGetMicroServiceModelsDictionaryClassEntityData: exit");
642 public void testSaveMicroServiceModelsDictionary() {
643 logger.info("testSaveMicroServiceModelsDictionary: Entering");
645 MockHttpServletResponse response = new MockHttpServletResponse();
646 request = mock(HttpServletRequest.class);
649 // mock the getReader() call
650 when(request.getReader()).thenReturn(br);
651 controller.saveMicroServiceModelsDictionary(request, response);
652 logger.info("response.getContentAsString(): " + response.getContentAsString());
653 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
655 } catch (Exception e) {
656 fail("Exception: " + e);
659 logger.info("testSaveMicroServiceModelsDictionary: exit");
663 public void testRemoveMicroServiceModelsDictionary() {
664 logger.info("testRemoveMicroServiceModelsDictionary: Entering");
666 MockHttpServletResponse response = new MockHttpServletResponse();
667 request = mock(HttpServletRequest.class);
670 // mock the getReader() call
671 jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
672 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
673 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
674 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
675 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
676 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
677 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
678 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
680 BufferedReader br = new BufferedReader(new StringReader(jsonString));
681 when(request.getReader()).thenReturn(br);
682 controller.removeMicroServiceModelsDictionary(request, response);
683 logger.info("response.getContentAsString(): " + response.getContentAsString());
684 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
686 } catch (Exception e) {
687 fail("Exception: " + e);
690 logger.info("testRemoveMicroServiceModelsDictionary: exit");